• Resolved ricardl

    (@ricardl)


    Hello,

    I have been doing good with the spin formula posted here: https://paste.ee/p/GluOL

    But, in my case I need to spin more words (synonyms) inside spintax, so I’d need to implement a nested spin. However, the formula I usually apply in php is not working in Wp All Import.
    This is the formula:

    <?PHP
    class Spintax
    {
    public function process($text)
    {
    return preg_replace_callback(
    ‘/\{(((?>[^\{\}]+)|(?R))*)\}/x’,
    array($this, ‘replace’),
    $text
    );
    }
    public function replace($text)
    {
    $text = $this->process($text[1]);
    $parts = explode(‘|’, $text);
    return $parts[array_rand($parts)];
    }
    }

    How can I adapt it to WP All Import??

    Thank you for this awesome Plugin. Best Regards,

Viewing 1 replies (of 1 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @ricardl

    How can I adapt it to WP All Import??

    You can make the functions outside of a class, e.g.:

    function my_process_spintax( $text ) {
    	return preg_replace_callback( '/\{(((?>[^\{\}]+)|(?R))*)\}/x', 'my_replace_spintax', $text );
    }
    	
    function my_replace_spintax( $text ) {
    	$text = my_process_spintax( $text[1] );
    	$parts = explode( '|', $text );
    	return $parts[ array_rand( $parts ) ];
    }

    Then pass the spintax to the my_process_spintax function:

    [my_process_spintax({spintax[1]})]

Viewing 1 replies (of 1 total)
  • The topic ‘Nested Spin function’ is closed to new replies.