1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

WordPress Link Control Plugin

Discussion in 'PHP' started by kazimn, Dec 13, 2009.

  1. #1
    Hi there guys, I'm working on a wordpress plugin. Which gives user the control to manage keywords in the post by linking. It's that easy just give keyword and it's link it will be linked using Php function Preg_replace. What now i want to do in it is that preg_replace should only be executed when $pregurl == $currenturl
    such as if you've the link of the post in the plugin, where you added words to be linked. Replace the words with with the link ONLY ON THAT POST. I need a wordpress coder help in it. Okay well, here's what I'm using..
    
    function re_place_content_filter($content) {
    	global $user_ID;
            global $wpdb;
    	$pairs = get_re_pairs();
    
    	$search = array();
    	$place  = array();
    $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    
    
    	foreach ($pairs as $re_place) {
    		$search[] = "/" . $re_place->re_search . "/";
    
    		if ( $re_place->restriction == 'auth' && !$user_ID ) {
    				$place[] = $re_place->restr_otherwise;
    
    		} else if ( $re_place->restriction == 'page' && !is_page() ) {
    				$place[] = $re_place->restr_otherwise;
    
    		} else if ( $re_place->restriction == 'post' && is_page() ) {
    				$place[] = $re_place->restr_otherwise;
    
    		} else {
    			$place[] = $re_place->re_place;
    		}
    	}
    
    
    		
    		$sql = "SELECT re_url FROM `wa_re_place` WHERE re_url like '$url' "; 
    		$replaces = $wpdb->get_results($sql);
     		echo $replaces;
    		
    
    if ($replaces == $url) {
    echo 'a'; // just having that for testing purpose 
    	$content = preg_replace($search, $place, $content, 1); // replacing every word only 1 time
    	return $content;
    }
    
    else {
    
    return $content; }
    
    }
    PHP:
    What might be the problem?
     
    kazimn, Dec 13, 2009 IP