Articles of plugin development

configuration of .htaccess for add_rewrite_rule to make sense

I am trying this code from codex wordpress site function custom_rewrite_basic() { add_rewrite_rule(‘^leaf/([0-9]+)/?’, ‘index.php?page_id=$matches[1]’, ‘top’); } add_action(‘init’, ‘custom_rewrite_basic’); How must by .htaccess file must be configured for above code to make sense? If I put the basic wordpress .htaccess configuration file then I get redirected to same page. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule […]

How can I allow the user to press enter without creating a new element in the editor?

I wrote a tinymce button to place a special div on my editor (I didn’t use the format dropdown because the client was unsure of it). When the user presses enter inside the div it creates another instance of that div. I want it create a paragraph inside that div. I’m using a similar plugin […]

what is the point of telling add_filter how many parameters you want passed to the function?

In wp-includes/plugin.php (apply_filters) there’s this: foreach( (array) current($wp_filter[$tag]) as $the_ ) if ( !is_null($the_[‘function’]) ){ $args[1] = $value; $value = call_user_func_array($the_[‘function’], array_slice($args, 1, (int) $the_[‘accepted_args’])); } So if you do 9999 the function will get past more arguments than it needs? How is that a problem? If you don’t need the arguments don’t put them […]

How to add multiple custom URL variables?

I am building a WordPress plugin that looks for different custom variables in the URL. The way I am able to achieve that right now is with this code: function add_custom_query_var( $vars){ $vars[] = “variable1”; return $vars; } function add_custom_query_var1( $vars1){ $vars1[] = “variable2”; return $vars1; } add_filter( ‘query_vars’, ‘add_custom_query_var’ ); add_filter( ‘query_vars1’, ‘add_custom_query_var1’ ); […]

Retrieving plugin options value saved through setting

Looking at this code below it work add options perfectly and saved them. However I will like to use those data at front page in my plugin short code. class MySettingsPage { /** * Holds the values to be used in the fields callbacks */ private $options; /** * Start up */ public function __construct() […]

How to rewrite URL and get the values?

I created a shortcode by add_shortcode. where the shortcode placed in a wordpress page to display dynamic content. The dynamic content is based on the URL value. Example If URL is wordpress/sample-page/?user=john in my shortcode content I get the url value by $_GET[‘user’] Now I would like to rewrite the url like wordpress/sample-page/john. And want […]

wpdb->get_var always returning 0

I am trying to run this statement: global $wpdb; $amt = $wpdb->get_var($wpdb->prepare(“SELECT SUM(amount) as amt FROM wp_pay_table WHERE postid = %i”, $pid)); …but $amt always comes out as 0. I have checked that $pid is the correct value. I have also run the sql statement in my db and it returns the correct value (should […]

Return Value of load_plugin_textdomain

Good Day, I’m trying to translate my plugin but it doesn’t seems to work. I read that I should check the return value of “load_plugin_textdomain” to see if it’s false (meaning it doesn’t find my translation file), but I cannot find how to find this value. Can someone point me in the right direction? Thanks […]

Create a custom page template inside my wordpress plugin

I’m developing a WordPress plugin and I want to create a file to where I want to redirect the user to show some information. I know that a perfect solution for this is using WordPress custom pages. I’ve used it in the past and it was very useful. The problem is I can not use […]

Plugin Development – Class Constructor Not Firing wp_enqueue_style action hook

Writing my first WordPress plugin that uses a Class approach. It is being called on a page via a shortcode. In testing, the shortcode is working and the shortcode specific php file is being loaded. However, the 2 add_action calls are not firing: //Register Styles add_action( ‘wp_enqueue_style’, array( $this, ‘register_styles’ ) ); //Register Scripts add_action( […]