• I’ve been working for 4 days on what would take 10 minutes if I knew PHP better. It’s really simple, I bought a theme which has some positions for ads. One of them is set to appear between the two parts of each entry – (where “<!– more –>” comes into play)

    First of all, I want to get rid of the damn thing. Here’s the relevant code from my single.php page:

    <div class="entry">
    
    <?php $single = sdac_triple_p_ad_code('single');?>
    
    <?php the_content(''. $single.''); ?>
    <?php edit_post_link();?>
    <div class="tagzone">
    <p class="tags"><span>Categorized:</span> <?php the_category(', ') ?><span class="sep">|</span><?php if (function_exists('sharethis_button')) { sharethis_button(); } ?></p>
    </div>
    </div>

    That second line with the ‘sdac’ variable is obviously pulling the ad. But if I delete that line, not a blasted thing happens. Why? What in the world is it doing if it makes no difference if it’s there or not?

    The source of that actual variable is coming from a custom widget. I can paste that too, but it would be great if someone could first decifer why in the name of god nothing whatsoever happens when I delete the line.

    Many thanks!

Viewing 15 replies - 1 through 15 (of 16 total)
  • It’s probably a filter of some kind.

    Have a look at the file functions.php in your theme directory, and see if you find a function called add_filter (maybe more than one).

    copy and paste them (it?) here.

    Peter

    Thread Starter nickaster

    (@nickaster)

    Thaks! Yeah, there’s only one, and it’s associated with comments somehow. Pasted below:

    I assume that something about that widget/plugin is sneaking into whatever code generates the post body and slapping the ad code into it right at the point where the “<!– more –>” tag would sit. It’s just totally blowing my mind as to how/where it is coming from. I think I want to totaly recode it and get rid of this madnesss, but understanding it a little better would help!

    // Comments
    if (function_exists('wp_list_comments')) {
    	// comment count
    	add_filter('get_comments_number', 'comment_count', 0);
    	function comment_count( $commentcount ) {
    		global $id;
    		$_commnets = get_comments('status=approve&post_id=' . $id);
    		$comments_by_type = &separate_comments($_commnets);
    		return count($comments_by_type['comment']);
    	}
    }
    
    function sdac_comment($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment;
       ?>
       <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
         <div id="comment-<?php comment_ID(); ?>" class="completeComment">
         		<div class="gravatar">
    			<?php if (function_exists('get_avatar') && get_option('show_avatars')) { echo get_avatar($comment, 32); } ?>
    			</div>
    			<div class="commentBox">
    				<p class="commentMeta"><?php comment_time('F d, Y');?> at <?php comment_time('G:i a T');?> | <?php comment_author_link();?> writes:</p>
    				<?php if ($comment->comment_approved == '0') : ?>
             		<p><?php _e('Your comment is awaiting moderation.') ?></p>
          			<?php endif; ?>
    				<?php comment_text(); ?>
    				<p class="reply"> <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?> <?php edit_comment_link();?></p>
    			</div>
    		</div>
    	</li>
    <?php
            }
    
    ?>

    In the above snippet no sneaking is done ??

    Are there no strange plugins installed?
    Is it possible to show the entire functions.php via pastebin?

    Peter

    Thread Starter nickaster

    (@nickaster)

    You got it:
    https://wordpress.pastebin.ca/1578317

    Thanks for taking a look. Yeah, there’s a custom plugin for those ads. I really don’t know why she went to the trouble of making a custom plugin for it – perhaps it has to be that way to insert the ad in an odd place like that?

    I’m thinking about just deleting that plugin, then manually slapping in the ad code in the correct places, but I’m afraid it might be so deeply emnbedded it’ll massively mess things up. I don’t have a backup copy to tinker with right now.

    Thread Starter nickaster

    (@nickaster)

    If it makes any difference, deactivating the plugin nukes the entire site, so this clown I hired really buried it in there some place!

    sdac_triple_p_ad_code isnt defined in any of the source youve provided.

    share the theme. or grep the files for that string and find where its defined.

    oh, and this,

    <div class="entry">
    
    <?php $single = sdac_triple_p_ad_code('single');?>
    
    <?php the_content(''. $single.''); ?>
    <?php edit_post_link();?>
    <div class="tagzone">
    <p class="tags"><span>Categorized:</span> <?php the_category(', ') ?><span class="sep">|</span><?php if (function_exists('sharethis_button')) { sharethis_button(); } ?></p>
    </div>
    </div>

    you need this:

    <div class="entry">
    	<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
    <?php edit_post_link();?>
    <div class="tagzone">
    <p class="tags"><span>Categorized:</span> <?php the_category(', ') ?><span class="sep">|</span><?php if (function_exists('sharethis_button')) { sharethis_button(); } ?></p>
    </div>
    </div>
    Thread Starter nickaster

    (@nickaster)

    Hey, thanks. So, first, let me ask this:

    I changed the single.php code to be exactly what you suggest above, and STILL, that ad code somehow sneaks its way into the post. It’s totally insane! I want to get rid of it, but more importantly I really just want to understand what the hell is going on.

    I grepped all the theme files and the only place where that ‘sdac_triple_p_ad_code’ comes from is single.php and functions.php which I pasted above.

    My head is just totally spinning. I know the core of WP is not hacked, but that’s what it feels like. How in the world can the totally default code you suggested STILL pull that ad? It’s nuts!

    You can see the sucker in action here: https://www.triplepundit.com/2009/09/pge-quits-us-chamber-protesting-its-climate-change-stance/ (and all other article pages)

    Thread Starter nickaster

    (@nickaster)

    Here’s another quick question… this code you suggested:

    <?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>

    What is the HTML in there supposed to do? I assume “the_content” is just whatever is in the body of the post, with whatever HTML and everything else is in that body field. But what happens if I type “yankee doodle” in there between the quotes? Does that stuff just go between the first and second part of the body, if “<!– more –>” is present? Since this is the single.php page, why would anyuthing show? Maybe that’s why nothing’s showing now?

    Thread Starter nickaster

    (@nickaster)

    Finally, if it matters, the plugin itelf is pasted here:

    https://wordpress.pastebin.ca/1578557

    It’s a pretty simple, one file plugin. Is there anything you see there that’s somehow re-writing, or over-writing what a default single page should show?

    nick, $single isnt a wordpress vcariable. Its set up above in the theme :

    <?php $single = sdac_triple_p_ad_code('single');?>

    thats all processed in the last file you pasted.

    its applied to your single page because its utilized inside single.php

    See this:

    #
    function sdac_insert_ad_code_filter( $content ) {
    #
            global $id;
    #
            if ( !is_single() ) {
    #
                    return $content;
    #
            }
    #
            $html = '<div id="singleAd"><h5><span class="sponsor">Our Sponsor Message</span><span class="continue"><a href="#">Continue Reading Below  &raquo;</a></span></h5>'.sdac_triple_p_ad_code('single').'</div>';
    #
            return preg_replace("#\<(a|span) id\=\"more-$id\"\>\</\\1\>#", $html."$0", $content, 1);
    #
            return $content;
    #
    }
    #
    
    #
    add_filter('the_content', 'sdac_insert_ad_code_filter', 50);
    #
    ?>

    its filtering the_content

    You can safely comment out this command from the plugin:

    add_filter('the_content', 'sdac_insert_ad_code_filter', 50);

    Peter

    Thread Starter nickaster

    (@nickaster)

    Fascinating…. but…. I also tried it by getting rid of any reference to $single in the single.php page itself – by using verbatim the code you suggested:

    <div class="entry">
    	<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
    <?php edit_post_link();?>
    <div class="tagzone">
    <p class="tags"><span>Categorized:</span> <?php the_category(', ') ?><span class="sep">|</span><?php if (function_exists('sharethis_button')) { sharethis_button(); } ?></p>
    </div>
    </div>

    How does that plugin attack the page when it’s not even called for any more?

    The plugin is a filter using a hook in the the_content() function.

    Everything that passes the_content(), passes that particular function. You could call it sneaky, but that’s by design ??

    Peter

    Thread Starter nickaster

    (@nickaster)

    Okay thanks very much! This is helping me understand things a lot better.

    So… In other words, the plugin changes the behavior of “the_content()” to slap in that ad code at the “more” spot.

    So… regardless of how you construct the single.php page, as long as that plugin is active, it’s going to insert the code?

    Why would single.php have originally included this?

    <?php $single = sdac_triple_p_ad_code('single');?>
    <?php the_content(''. $single.''); ?>

    And again, why wouldn’t removing/editing that stop the plugin from affecting posts?

    And finally, what’s the purpose of the HTML here?

    <?php the_content(‘<p class=”serif”>Read the rest of this entry »</p>’); ?>

    That’ll never show up because you’re already on the single page right? Why is there anything there? Does it have a purpose? I could just make it:

    <?php the_content(‘WHAT IS THE POINT OF THIS’); ?>

    And it wouldn’t make any difference?

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Php help – mystery code’ is closed to new replies.