0

I am using a plugin Chargebee WP Membership to connect up to their API to process payments. At the moment they are only using shortcodes to restrict content.

What I am trying to do, is output the functions of these shortcodes inside the page template. So far I've attempted the do_shortcode method but would rather access the function directly.

Github file: https://github.com/brendenplugin/chargebee-wp-membership-plugin/blob/master/admin/helper/class-chargebee-membership-shortcodes.php

For cb_content_show the shortcode format is currently:

[cb_content_show level="1"] This content will be shown to any users who have plan associated with Level 1 [/cb_content_show] 

What is the best method to access this function directly? I believe it derives from the function render_content_show_hide() - Line 707

public function render_content_show_hide( $attr, $content = null, $shortcode_name = '' ) { ...

Ideally I'd like to access as the function for example:

<?php
if (cb_content_show('level') == 1) :
//do something
endif; 
?>

2 Answers 2

1

Looks like function render_content_show_hide() is a method of class. If you want access this function directly - you can create new class instance.

If your plugin code looks like:

class Shortcode_Builder{
    //...methods
    public function render_content_show_hide( $attr, $content = null, $shortcode_name = '' ) { 
        //...
    }

    //...other methods.


}

Create new instance

$builder = new Shortcode_Builder();

And access to your function $builder->render_content_show_hide()

2
  • 2
    To prevent the theme from breaking in case the plugin is not active, don't forget to wrap this in a conditional if ( class_exists ( 'Shortcode_Builder' ) ) :
    – Iceable
    Commented Feb 9, 2018 at 9:37
  • Thanks for that. I managed to access the data by using get_user_meta instead... much easier :)
    – scopeak
    Commented Feb 9, 2018 at 18:56
0

Managed to get it working by accessing the get_user_meta values.

<?php    
$user_id = get_current_user_id();
$key = 'chargebee_user_subscriptions';
$all_meta_for_user = get_user_meta( $user_id, $key, true  );
print_r($all_meta_for_user);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.