Fatal error: Call to a member function get_page_permastruct() on a non-object

The WordPress environment is not yet fully initialized when your plugin files are loaded, it’s almost always too early to safely run code that interacts with core at that point. WordPress achieves its initial state through a process which contains its own set of actions and filters, so plugins load before that happens to allow … Read more

How should I go about registering JavaScript that isn’t a file? [duplicate]

You can hook the wp_footer action to output arbitrary JavaScript. This the same action that WordPress uses to output footer enqueued scripts. Here’s an example that encapsulates the shortcode, data, and script output in a class: <?php /* Plugin Name: WPD_Example */ class WPD_Example_Plugin { public $data = array(); function __construct() { add_shortcode( ‘wpd_example’, array( … Read more

How to Move the Comments Bubble to the Right Side of the Toolbar

After you have removed the comments bubble, you add it again. The trick is that in the $args of add_node you have to set parent to top-secondary. So it will look like this: add_action( ‘admin_bar_menu’, ‘wpse227079_toolbar_link_to_bubble’, 999 ); function wpse227079_toolbar_link_to_bubble ( $wp_admin_bar ) { $args = array( ‘id’ => ‘wp-admin-bar-comments’, ‘parent’=> ‘top-secondary’, ‘title’ => ‘QQ’, … Read more

Check if plugin exists/active “class_exists()” does not work on plugin territory

Woo Commerce provides code to check to see if WooCommerce is installed : /** * Check if WooCommerce is active **/ if ( in_array( ‘woocommerce/woocommerce.php’, apply_filters( ‘active_plugins’, get_option( ‘active_plugins’ ) ) ) ) { // Put your plugin code here } If no idea where WooCommerece install then : $all_plugins = get_plugins(); $active_plugins = get_option( … Read more