Is it ever okay to include inline CSS in plugins?

TL;DR; Enqueue Using external stylesheet PRO: All your styles are in one spot. PRO: Reduces web page coding. PRO: Easier to maintain the plugin. PRO: Can use hooks to alter location of the file. PRO: Can use hooks to unqueue the file. PRO: Can use minify styles automatically. CON: Might add extra HTTP request (can … Read more

How many times will this code run? (or, how rich is grandma?)

Here are some random thoughts on this: Question #1 How much money did we send to grandma? For 100 page loads, we sent her 100 x $1 = $100. Here we actually mean 100 x do_action( ‘init’ ) calls. It didn’t matter that we added it twice with: add_action( ‘init’,’send_money_to_grandma’ ); add_action( ‘init’,’send_money_to_grandma’ ); because … Read more

How to make a WordPress plugin translation ready?

1. Write with localization in mind Don’t use echo or print() to produce text output, instead use the WordPress functions __() and _e(): /** Not localization friendly */ echo “Welcome to my plugin”; // OR print(“Welcome to my plugin”); /** Localization friendly */ _e(‘Welcome to my plugin’, ‘my-plugin’); // OR $my_text = __(‘Welcome to my … Read more

What is the advantage of using wp_mail?

wp_mail() is a pluggable function: It can be replaced by plugins. That’s useful in cases where the regular mail() doesn’t work (good enough), for example when you need extra authentication details. Example: WP Mail SMTP wp_mail() uses PHPMailer by default, a sophisticated PHP class which offers a lot of useful preprocessing and workarounds for cases … Read more

Adding Custom Text Patterns in the WP 4.5 Visual Editor

Here’s a way to test the core patch #33300.6 by Andew Ozz, through a test plugin in WP 4.5.2, to try out the text pattern filter. Demo Here’s a strikethrough example using ~ $init[‘wpsetextpattern_inline_patterns’] = ‘{ strong: { start: “*”, end: “*”, format: “bold” }, strong2: { start: “**”, end: “**”, format: “bold” }, em: … Read more

How do I add CSS options to my plugin without using inline styles?

Use wp_register_style and wp_enqueue_style to add the stylesheet. DO NOT simply add a stylesheet link to wp_head. Queuing styles allows other plugins or themes to modify the stylesheet if necessary. Your stylesheet can be a .php file: wp_register_style(‘myStyleSheet’, ‘my-stylesheet.php’); wp_enqueue_style( ‘myStyleSheet’); my-stylesheet.php would look like this: <?php // We’ll be outputting CSS header(‘Content-type: text/css’); include(‘my-plugin-data.php’); … Read more