Home Disable shortcode if status of value changes?
Reply: 0

Disable shortcode if status of value changes?

user1073
1#
user1073 Published in May 24, 2018, 11:17 pm

Looking to do enable or disable shortcode in a function, depending on a value. For instance, if someone says purchases a license key to use some shortcode on their site, I'd like to have the shortcode become disabled if they license expires. Example function I've been working on below:

my_premium_shortcodes(); // Fires early in my php file

function my_premium_shortcodes(){
    $status     = get_option( 'key_status' );

    if( $status !== false && $status == 'valid' ) { 

        add_shortcode('shortcode_handle_1','shortcode_function_1');
        add_shortcode('shortcode_handle_2','shortcode_function_2');

    } else {

        remove_shortcode('shortcode_handle_1','shortcode_function_1');
        remove_shortcode('shortcode_handle_2','shortcode_function_2');
    }

}

Any input on my approach or if the function should be handled in a separate way would be appreciated. As it stands, the shortcodes are working when everything is enabled, but stay enabled even after the 'status' changes to 'invalid'.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.369736 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO