Articles of plugin development

Preferred way to include Advanced Custom Fields in a plugin?

So I am building a plugin for a site that is already using Advanced Custom Fields (ACF). I wonder what would be the best way to include ACF in my plugin? The site is already using ACF, so is it possible to include ACF from the plugin directory or should I include ACF again?

how to set context in WordPress for unit testing

I have created a wordpress plugin which converts shortcodes to content based on the entry saved on the dataase: global $wpdb; $post_id = get_the_ID(); $post_content = get_the_content(); $pattern = ‘/\[zam_tweets page=([0-9])\]/’; preg_match($pattern, $post_content, $matches); if(!empty($matches)){ $tweets_table = $wpdb->prefix . ‘zam_tweets’; $result = $wpdb->get_var(“SELECT tweet FROM $tweets_table WHERE post_id = ‘$post_id'”); $content = $result; } return […]

A better way to include localized labels in WordPress plugins

is there a better way to include labels to be localized in WordPress plugins and themes? My current setup involves calling the method below to get the labels: public function plug_get_labels(){ $labels = array( ‘details’ => __( ‘Details’, ‘plug’ ), ‘specs’ => __( ‘Specifications’, ‘plug’ ), ); return $labels; } But for widgets for example […]

Odd behaviour with submenu link creation

I’m trying to develop a plugin that needs to add two pages to the dashboard side-bar menu. One of these being a main category. Everything is fine, except for the second submenu item for the settings page. After perusing just about as much of the codex and searching the web for similar issues I’ve come […]

Read text defined under __()

I am new to WP Plugin development. I have a theme where texts are included inside __() function for translations, like: __(‘This is text to be translated’); I want to create a plugin which would get the value from __() functions and run through my own defined functions. Suppose the text inside __() contains __(“This […]

How to filter the_content() & include content from template

I am trying to filter the_content() on single page, but it looks like it is creating an infinite loop. I want to know how to fix this. I want to override the_content(). Is there any other way to override single page content from plugin? add_filter( ‘the_content’, ‘change_single_content’ ); function change_single_content($content){ global $post; if ( ‘my-CPT’ […]

How to cancel WordPress' action/filter when using OOP with anonymous callback

Most of the wordpress plugins I found is functions based, for example, the offical akismet plugin function akismet_init() { global $wpcom_api_key, $akismet_api_host, $akismet_api_port; // … } add_action(‘init’, ‘akismet_init’); There are a few issues with this approach: you cannot share state between function, so you must use global variables hard to do unit test, i.e. no […]

Adding functions to hooks from within a class

Below is a trimmed down version of my plugin, to keep it simple. My setup function is being called, but when I go to the login page, it’s not dying like it should. I had the plugin working earlier, however I’m trying to re-write it into a class structure to make it more self-contained. if […]

Adding Dropbox dropin js using wp_enqueue_script

I want to add a new Dropbox Drop In Chooser button to my site. To include the code in a simple page you use <script type = “text/javascript” src = “https://www.dropbox.com/static/api/1/dropins.js” id = “dropboxjs” data-app-key = “xxxxxxxx”> Where xxxxxxx is the dropbox supplied key for the app using the option. I know how to add […]

Is license need for free wordpress plugin

I’m developing a new WordPress, So i’m a beginner. I’m referring a plugin to create a readme.txt file. I’ve seen that two lines. License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html one question raised in my mind. How to create wordpress license and is license need?