OOP and WordPress shortcode

That is not the way you add an object method as a callback. function make_shortcode() { add_shortcode(‘ShowMsg’, array($this,’ShowMsg’)); } This is explained in the Codex as it pertains to actions and filters, but the principle is the same. I should add that anonymous classes make for painful debugging. Instantiate that class to a variable. It … Read more

Object method calling for global $wpdb in header.php

I think the problem might lie in: $wpdbinfo = $wpdb->get_results(“SELECT * FROM bo_mytable WHERE id=3”); $wpdb->get_results() returns an array of objects, yet you are referencing a property on $wpdbinfo (->nameinfo). You’ll either want to loop through the $wpdbinfo array, or if you’re certain you’ll get only a single record (possibly a safe assumption if id … Read more

Register jQuery – OOP WP

You are setting your script to be added at the wp_head action. jQuery, along with most other scripts, are loaded as part of the wp_enqueue_scripts action. Care to guess which of those comes first? 😉 Edit This is actually not true. jQuery is loaded as part of wp_default_scripts which does take place before wp_head I … Read more

accessing parent variables in child construct without executing action in parent

I think your problem is the pattern. You should not create a child class of your controller (the main class), and the controller should not handle action callbacks. Let the controller assign the callbacks to actions. The action handlers should be separate classes. Basic example: namespace WPSE; add_action( ‘plugins_loaded’, function() { new Controller; }); class … Read more

Using plugin functions/methods within templates

Premature optimization is the root of all evil (ok, waste of programing time). Why would you care how many times a function is called? it is not like the memory or CPU is getting “weaker” by overusing it. It is more important that the code you produce will be self documenting as much as possible … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)