how to display a string in admin_notices hook from a class plugin

Take a look at what happens when you activate a plugin. That is, watch the event with something like HttpFox or Wireshark. After activation the page is redirected back to itself with $_GET parameters appended. For example: wp-admin/plugins.php?activate=true&plugin_status=all&paged=1&s= Notice, activate=true?. Your code isn’t working, I am pretty sure, because there are two requests involved. You … Read more

jQuery code didn’t run on my plugin

Check the DOM for the theboxjs.js and see if it is loaded correctly (check the output path). If not then you have path issues. Try using admin_enqueue_scripts instead of admin_init for loading scripts. You might also have conflict in your script. When writing scripts for WP try to avoid $ and use jQuery instead.

$wpdb in php 5.5

There is no difference in this respect between PHP 5.3 and 5.5. The code doesn’t need to change. However, you should still use prepare properly. Like so: $query = $wpdb->prepare( ‘UPDATE wp_building_plan SET sale_price = %s, available = %s, broker_name = %s, broker_email = %s, broker_phone = %s WHERE id = %s’, $sale_price, $available, $broker_name, … Read more

Stop post submission without losing data?

I had to do the exact same thing with a custom post type that would be useless and cause theme problems without metadata. You’ll have to either A. Check the post for metadata AFTER it has been published using the transition_post_status hook, and if the metadata isn’t there, change the status to “draft” and throw … Read more

How to use add_action for multiple instances of the same class

When you call add_meta_box() you must provide a unique ID as the first parameter. Consider this case: add_meta_box( ‘foobox’, ‘Foo Title’, ‘foo_callback’ ); add_meta_box( ‘foobox’, ‘Bar Title’, ‘bar_callback’ ); You will just get the Bar Title metabox now, because it will overwrite the first one. What you need is a new ID for each box: … Read more

Including template in shortcodes

I’m not quite sure this is what you are trying to do, however, this is one way to use an external template file for your shortcode output. This is your shortcode function (e.g., in functions.php): function qt_shortcodez() { return include ‘template/shortcode.php’; } // function qt_shortcodez And that is the very output (i.e., shortcode.php): <?php ob_start(); … Read more