• Hi wordpress friends ??
    This function has the ability to detect when a word in the post title is listed in one of the arrays of this function, when it finds one that contains the arrays, this function makes a “rand” of the words of this array having the word in the title and makes random replacement of these detected words, keeping the other title of words that do not have private in arrays. but I have a problem if I manually type in the title and click publish at the time the title is properly changed, but when I do auto post by plugins, only that variable is sent to the title: $ addToTitle = ‘any word ‘; then all my posts are under the name of ‘Anyword’ .. because it seems that when my function executes, it does not take the value of $ post_title, or function of the import plugin that writes the title has not written in post_title, and when I delete this variable $ addToTitle = ‘Anyword’ ;. my posts are simply without titles, as though that my function cancel writing action in post_title by the import plugin. or is missing I call the values ??of post_title? how to do this?

    /*
    Plugin name: my rewrite title
    Description: my plugin to my problem
    Version: 1.0
    Author: anyone
    Author URI: anyone.com
    */
    function rewrite2( $text, $theWords )
    {
    	if( is_string($text) && strlen($text) > 0 )
    	{
    		$text = strtolower($text);
    		$wordArray = explode( ' ', $text);
    		$i = 0;
    		foreach($wordArray as $word)
    		{
    			$arrayPosition = inWhichArray($word, $theWords);
    			if( $arrayPosition !== false)
    			{
    				$wordArray[$i] = getRandomElement($theWords[$arrayPosition]);
    			}
    			$i++;
    		}
    		return implode(' ', $wordArray);
    	}
    }
    function inWhichArray($needle, $haystack)
    {
    	$firstKey = 0;
    	foreach( $haystack as $subHaystack)
    	{
    		if(in_array($needle, $subHaystack)){
    			return $firstKey;
    		}
    		$firstKey++;
    	}
    	return false;
    }
    function getRandomElement($wordList)
    {
    	$length = count($wordList);
    	$random = rand(0, $length-1);
    	return $wordList[$random];
    }
    //*******I believe the problem starts here ********
    add_filter( 'wp_insert_post_data' , 'add_string_on_publish_four' , '998', 2 );
    function add_string_on_publish_four( $data,  $postarr='' ){
    $post_title = $_POST['post_title'];
    $addToTitle = 'anyword';
    				$myWords=array(array('word35','word13','word14'),array('word33','word1'),array('word23','word24'),array('word16','word25','word56','word54','word19'),array('word41','word18','word25'),array('word16','word42'),array('word15','banged','word34','word20'),array('word52','word53','word27'),array('word4','word5','word36','word11','word51'),array('word26','word2','word3'),array('word7','word8','word40'),array('word6','word9','word38'),array('word10','word50','word31 word2','word44','word31 word3'),array('word2','word22','word58','word21','word32'),array('word28','bword59'),array('word7','wird39','need','addiction'),array('wird37','wordt36','word17','word35'),array('word46','word17'),array('word47','big','word7','word60'),array('word48','word49'),array('word29','word60 word45','word17'),);
    				$post_title = rewrite2($post_title, $myWords);
                            $data['post_title'] = "$post_title $addToTitle";
                            return $data;
    			}

    help me please. thank you all.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Function detects when a title term is equal to the terms of the array and replac’ is closed to new replies.