Jump to content

Recommended Posts

Well technically by "global" it means they were created in the global scope, i.e. outside of any class or function. Adding the global keyword allows you to reference that original variable instead of the one that would be created within the scope of your class method / function. To remove the global keyword you'd need to pass those values to the function (or find another way of making them available). Is this a class method?

Link to comment
https://forums.phpfreaks.com/topic/186694-rewriting-globals/#findComment-986008
Share on other sites

It is a method here is all of the code which includes this page.

 

include ABSPATH."optindb.php";

$optout=ABSPATH."optout.php";

$rows=file($optout);

$syn_donot = " ";
foreach ($rows as $row_num => $row) {
    $syn_donot = $syn_donot.$row." ";
}

function rewrite_text( $article, $case_sensitive=false ) {
global $optindb;
global $syn_donot;

$dorewrite=strpos($article,"<optout>");
if($dorewrite>0)
	{
	$article=str_replace("<optout>","",$article);
	}
else
{
	$synlist=$article;
	 $synchar = array("(", ")", "[", "]", "?", ".", ",", "|", "\$", "*", "+", "^", "{", "}");
	 $synlist=str_replace($synchar," ",$synlist);
	 $synlist=str_replace("  "," ",$synlist);
	 $my_synlist = explode(" ",$synlist);

	if (sizeof($my_synlist)>0)
	{
	for($i=0;$i<sizeof($my_synlist);$i++)
		{
		$syn_replace=$my_synlist[$i];
		$syn_replace=str_replace(" ","",$syn_replace);

		$syn_avoid="no";
		if($syn_replace!="")
			{
			$pos=strpos($syn_donot, $syn_replace);
			if($pos>0)
				{
				$syn_avoid="yes";
				}
			}

		$syn_replace=" ".$syn_replace." ";
		$syn_replace_target=$optindb[$syn_replace];
		if(($syn_replace!="")&&($syn_replace!=" ")&&($syn_replace_target!="")&&($syn_avoid=="no"))
			{
			$article = str_replace($syn_replace,$syn_replace_target,$article);
			}
		}
	}
}
return $article;
}

add_filter('the_excerpt', 'rewrite_text', 2);
add_filter('the_content', 'rewrite_text', 2);

As for why this is even a global for the life of me I can not figure out.

Link to comment
https://forums.phpfreaks.com/topic/186694-rewriting-globals/#findComment-986016
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.