Conditional activation of wordpress plugin
-
I want a plugin to work only if it passes a sudden condition and the condition is WordPress Post’s Custom Field or its Value. I can get the custom field value outside the WordPress Loop() but it is not working when I’m using it on the plugin’s page. Here is the code to get the Custom Field Value:
<?php global $wp_query; $postID = $wp_query->post->ID; $pluginactivate = get_post_meta($postID, 'my-custom-field', true); if ($pluginactivate == "yes"){ echo $pluginactivate; //plugin code here } else { echo $pluginactivate; //plugin bypassed } ?>This code is working fine on Single page or Homepage but not working on plugin’s *.php page.
I found this topic where Aaron replied what he said is
That wont work, but if you edit the file as follows, it will:
Find:
public function gallery($content = ”, $attr) {
global $post;Add after:
if ( !get_post_meta($post->ID, ‘gallery’, true) ) return;
Unfortunately I’m not smart enough to elaborate what he said. Any help will be highly appreciated.
One more thing is this plugin will be triggered only in single post pages like if (is_single())
The topic ‘Conditional activation of wordpress plugin’ is closed to new replies.