WordPress.org

Ready to get started?Download WordPress

Forums

WP-Table Reloaded
[resolved] How can I use code to check if WP-Table is installed? (6 posts)

  1. EivindFS
    Member
    Posted 3 years ago #

    Hi there,

    I'm doing some admin dashboard configuration of different plugins and need to check if WP-Table reloaded is installed to determine if I should run some code. I've tried using function_exists() on several WP-Table reloaded functions and it returns false every time. This works fine on all the other plugins, including cForms and NextGen Gallery, but it doesn't work for WP-Table for some reason.

    Can anyone tell me how I can test if WP-Table Reloaded is installed or not?

    Thanks,
    Eivind

  2. Leon
    Member
    Posted 3 years ago #

    How about:
    if ( class_exists( "CheckPlugin" ) )

  3. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    Hi,

    the function_exists() likely fails, because WP-Table Reloaded has its functions inside classes. So, you will need to use a different syntax.

    It could also be possible that your plugin is run before WP-Table Reloaded has been included. When are you performing the function checks? You should at least wait until the action "plugins_loaded" is fired. Then, you could check for a function inside a class, or (which even works with function_exists(), you can check for the template tag function wp_table_reloaded_print_table().

    The best way, in my opinion, would be to read the array of active plugins from WordPress (a global variable), that way you get a direct list of all activated plugins.

    Best wishes,
    Tobias

  4. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    Hi,

    thanks or the suggestion, Leon. Yes, you could of course simply check for the plugin's class. However, the same applies: The point of time when you perform the check is important!

    Best wishes,
    Tobias

  5. Leon
    Member
    Posted 3 years ago #

    (double post) because of server timeout

  6. EivindFS
    Member
    Posted 3 years ago #

    Thank you for the info, Tobias.

    For now, I will go with Leon's solution which worked beautifully.

    Thanks to the both of you

    Eivind

  7. Leon
    Member
    Posted 3 years ago #

    Well Tobias did have a point.

    You can also do the following:

    add_action( 'plugins_loaded', 'check_plugin' );

    function check_plugin(){
    if ( class_exists( "CheckPlugin" ) ){
    define( 'WP-Table-Active', 'true' );
    }
    }

    and then check

    if( defined( 'WP-Table-Active' ) ) {
    //do actions
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic