Articles of plugin development

How do I improve this admin query snippet to avoid generating duplicate results on non-meta searches?

I’ve been playing around with code snippets which add meta data to admin searches. The best snippet I’ve found was written by Stefano on this question. However, it appears to have 1, annoying bug when searching non-meta terms. Here are some grabs from my local dev install. I’ve printed the 2 MySQL queries onto the […]

How to check uniqueness of plugin prefix?

To avoid collisions with other plugins, one should prefix all global functions, actions and plugins with a unique prefix, e.g.: function xyz_function_name() { … } The question is, how do I verify that xyz is indeed unique? For instance, Yoast SEO uses wpseo_ which I can imagine other SEO plugin could easily use as well. […]

Strategy On Building Plugin Using Eclipse

Anyone who has experience in building wordpress plugin using eclipse PDT? My situation is: I need to build plugin that extend another plugin (look at it as premium version from another plugin) I already created project plugin core(the original plugin) by importing from svn repository I created eclipse library called wordpress and added it to […]

dbDelta not creating tables

I went through a lot of threads, codex page and tried messing with a lot of things but my code doesn’t seem to be creating the tables. And I am not able to figure out where I am going wrong. I checked booking_db_version in the database, it gets updated when I update it in the […]

Which hook should be used to add an action containing a redirect?

I want to build a plugin that grabs certain url params from the query string to build a new query string for the same page. I’m following the excellent the Professional WordPress Plugin Development book, but I’m not sure which hook to use for this action. Here is my action function: add_action( ‘init’, ‘tccl_redirect’ ); […]

Adding Widget form fields dynamically

I am trying to add form field to a WordPress widget dynamically. So if the user want to add another date to an event they can click a button to get more fields. The question is: How do save newly created input fields to my database? Do i need to write a custom update function? […]

Unit testing for plugin development

I need to apply unit testing for one of my plugins. I recently re designed it into classes, so unit testing should be easier to apply now. What are some effective strategies to unit test my plugin? I need a way to use WordPress’ functions used in the plugin, but I shouldn’t need a running […]

WP_Query leaking absurd amounts of memory

Every time I call WP_Query() in the function below, WordPress leaks 8 megs of memory. And since I call this function a lot, things get hairy pretty quickly… 🙁 I’ve tried unsetting the resulting $queryObject as well as periodically calling wp_cache_flush(), but neither seems to have any effect. Any thoughts? function get_post_ids_in_taxonomies($taxonomies, &$terms=array()) { $post_ids […]

Add self-closing shortcode button to TinyMCE in WP 4.6

I’m familiar with creating self-closing shortcodes like: // shortcode function wpse_shortcode_example( $wpse_atts ) { // Attributes $wpse_atts = shortcode_atts( array( ‘foo’ => ‘bar’, ‘width’ => ‘100%’, ‘height’ => ‘auto’, ), $wpse_atts, ‘wpse’ ); // Return return ‘<embed src=”‘ . $wpse_atts[‘src’] . ‘” width=”‘ . $wpse_atts[‘width’] . ‘” height=”‘ . $wpse_atts[‘height’] . ‘”; } add_shortcode( ‘wpse’, […]

Custom Post Type Plugin: Where Do I Put The Template?

I’m writing a custom post type plugin. Part of it I’m outputting to the template via shortcodes. But other parts need a custom post template, and I figured out how to use the template hierarchy for CPT’s. But the custom template is in the theme, and I’m thinking the plugin should be self-contained, at least […]