• Resolved John McCarthy

    (@john-lion)


    Hi Nate,

    I’m adding the grfwp_print_reviews function in my theme’s function.php file. I’m receiving the “cannot re-declare’ error.

    To my knowledge as the function in the plugin is wrapped in if ( !function_exists( ) ) my function should be the one called.

    Can you advise, ie see where I may be going wrong?

    Note
    —-

    Have tested with a clean install of WooThemes Storefront.

    Thanks in advance

    https://www.ads-software.com/plugins/good-reviews-wp/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi John,

    Although the function is technically “pluggable”, it’s defined early before the theme is loaded. The plugin should probably hook these functions in during the init hook instead.

    Ideally, I’ll get a proper template in place for the review output so you can just drop a template file into your theme. But this plugin’s been a bit on the backburner while I focus on other plugins in my pack (not forgotten, just not a lot of active feature development).

    In the meantime, you can use a filter to override the output and do effectively the same thing as your function override. If you need some help figuring out how to use that filter let me know.

    Thread Starter John McCarthy

    (@john-lion)

    Hi Nate,

    Thanks for this, I understand, again the plugin is great. If I could help I would but I feel my developer skills are still a bit under par to do so.

    None the less, I do plan to use the plugin for my clients and personal projects and therefore see myself customising at least the output and style quite a bit. If there is anything I can foresee my assistance being beneficial, I’ll give you a shout ??

    As for using the filter; hopefully I’ve got this right. I’d call the filter on my function with a value of true and ensure that I return $output. I would essentially just copy the original template and re-order elements.

    When the check if ( $output !== false ) { returns true it returns my function rather than carrying on within the original template function to return the original output.

    It’s taken me some time to wrap my head around filters, I haven’t fully mastered all scenarios. Any guidance would be appreciated.

    Cheers

    Hi John,

    Here’s an example filter and function that overwrites the HTML output:

    add_filter( 'grfwp_print_reviews_output', 'johnmccarthy_custom_review_output', 10, 2 );
    function johnmccarthy_custom_review_output( $output, $args ) {
    
    	// Generate whatever HTML markup you want and assign it to $output
    	$output = '<div class="my-gr-review">This is the review</div>';
    
    	// Return the html markup
    	return $output;
    }

    Of course, you’ll want to look at the grfwp_print_reviews() to see how the $args array is used to generate the HTML output, and then generate your own. But that function demonstrates how you use a filter to enter your own HTML.

    (I haven’t tested the function above so if it breaks just look for syntax errors that may need to be fixed.)

    Thread Starter John McCarthy

    (@john-lion)

    Thanks Nate,

    that’s what I hoped. All good for now, as you said works just like template override.

    I really appreciate your help, all the best with everything.

    No problem! If you get a chance, I always appreciate reviews for the plugin here.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Replace the print reviews function in theme’ is closed to new replies.