• Resolved dreadedhamish

    (@dreadedhamish)


    I’m having trouble with using the filters – I’m not that experienced with PHP so sorry if this is just a noob mistake.

    Here is the code I’m using – it’s a basic regex function with arrays to allow multiple replacements:

    add_filter( 'rwstripe_restricted_content_message', 'example_callback' );
    function example_callback( $restricted_content_message ) {
    	$patterns = array();
    	$patterns[0] = '/Purchase Access/';
    	$replacements = array();
    	$replacements[0] = 'Start your Subscription';
    	ksort($patterns);
    	ksort($replacements);
    	preg_replace($patterns, $replacements, $restricted_content_message);
    	return $restricted_content_message;
       }

    If I echo $restricted_content_message in the function then it prints with the correct replacement, but when I return it the replacement doesn’t work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author David Parker

    (@dlparker1005)

    Hi @dreadedhamish, thank you for using Restrict With Stripe!

    Can you please try adding the following code recipe to your website and letting me know if the restricted content message then filters correctly?

    function my_rwstripe_restricted_content_message( $restricted_content_message ) {
    	return str_replace( 'Purchase Access', 'Start your Subscription', $restricted_content_message );
    }
    add_filter( 'rwstripe_restricted_content_message', 'my_rwstripe_restricted_content_message' );
    Thread Starter dreadedhamish

    (@dreadedhamish)

    yeah that works perfectly – so I muched it up somewhere in my convoluted multi-find-replace scheme. Sorry – i should have stripped it bare before posting.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help with filters’ is closed to new replies.