Dev4Press» hooks Tag Archives, page 1 of 1 | Dev4Press http://www.dev4press.com Premium Plugins and Themes for WordPress Sat, 18 May 2013 13:19:28 +0000 en-US hourly 1 Measuring impact of plugins on WordPress loading http://www.dev4press.com/2011/blog/benchmark/measuring-impact-of-plugins-on-wordpress-loading/ http://www.dev4press.com/2011/blog/benchmark/measuring-impact-of-plugins-on-wordpress-loading/#comments Wed, 07 Dec 2011 17:30:12 +0000 MillaN http://www.dev4press.com/?p=11630 One of the best things about WordPress are plugins. With plugins you can expand WordPress and make it into anything you need it to be. But, each plugin requires time for loading and processing and it takes up additional resources. How much exactly one plugin need?

Measurement Process

For this article I have tested 35 plugins. This includes both free and commercial plugins, big and small plugins and all of them are tested on the admin side and on the website frontend. All tests are done with a single installation, and WordPress 3.3 RC1 was used. Tests are done on the local server with PHP 5.3.8.

Testing exact impact of plugins on WordPress is not easy, since there are two things that happen during the loading process. First part is WordPress loading the plugin (using PHP include function). Second part is done through actions and filters added by plugin to WordPress during loading stage. First part is not to complicated to measure and that is what you have in the table below. Second part is very complicated to measure because it would need tracking of each action or filter executed. This second part is even more complex if you take into account that different actions and filters are executed only on some of the pages or panels.

All measurements are done using GD Press Tools Pro 4.3.1 plugin. Plugin has a tracker class that can be loaded from wp-config.php file to accurately capture snapshots of different loading stages (among other things). To allow capturing plugins snapshots, I made small change to WordPress core files: added snapshot call into loop that loads plugins.

Measurement Results

35 tested plugins are listed in the table below. You can see how much memory each plugin needs during loading, how many SQL queries are run and how many hooks attached to WordPress, as well as the total time needed for this loading stage. All this is done on the admin side (dashboard) and on the frontend (home page).

Administration Frontend
Plugin Mem. SQL Time Hooks Mem. SQL Time Hooks
After The Deadline 0.1M 0 0.004 10 0.1M 0 0.005 10
Akismet 0.2M 2 0.006 19 0.1M 1 0.004 7
All In One SEO Pack 0.7M 1 0.010 12 0.7M 1 0.012 12
Antispam Bee 0.3M 1 0.004 2 0.2M 0 0.005 6
BackupBuddy 1.0M 1 0.099 30 0.6M 0 0.009 9
BackupWP 0.5M 0 0.007 9 0.5M 0 0.008 9
bbPress 4.0M 0 0.047 216 3.8M 0 0.061 205
Better WordPress Google
XML Sitemaps
0.6M 2 0.010 12 0.7M 2 0.013 12
Contact Form 7 0.5M 0 0.007 16 0.4M 0 0.008 16
Dev4Press Updater 0.3M 2 0.007 5 0.3M 2 0.010 5
Events Manager 4.2M 1 0.051 60 3.0M 1 0.042 54
gdHeadSpace 4 0.7M 1 0.013 20 0.7M 1 0.013 8
GD Affiliate Center Pro 1.1M 0 0.017 16 0.7M 0 0.013 9
GD bbPress Attachments 0.2M 0 0.003 1 0.2M 0 0.004 1
GD Pages Navigator 0.5M 0 0.008 3 0.5M 0 0.009 3
GD Press Tools Pro 2.9M 0 0.032 78 2M 0 0.027 38
GD Products Center Pro 2.4M 0 0.029 28 2.2M 0 0.032 17
GD Star Rating 3.8M 0 0.043 12 3.8M 0 0.047 14
GD Custom Posts And
Taxonomies Tools Pro
2.8M 0 0.039 61 1.7M 0 0.027 23
GD Unit Converter 0.5M 0 0.007 4 0.4M 0 0.010 4
GravityForms 2.9M 0 0.025 4 2.8M 0 0.030 4
JetPack 0.7M 0 0.008 5 0.7M 0 0.009 5
Lightbox Plus 0.7M 0 0.011 8 0.7M 0 0.013 7
Regenerate Thumbnails 0.1M 0 0.002 1 0.1M 0 0.002 1
Subscribe2 1.4M 0 0.013 5 1.4M 0 0.016 5
Subscribe to Comments Reloaded 0.3M 2 0.005 17 0.3M 2 0.006 3
SyntaxHighlighter Evolved 0.3M 0 0.004 1 0.3M 0 0.005 1
The Google+ plugin 1.6M 1 0.032 10 1.6M 1 0.032 6
TinyMCE Advanced 0.1M 0 0.002 13 0.1M 0 0.002 13
W3 Total Cache 1.4M 0 0.019 46 0.2M 0 0.008 19
WooCommerce 3.9M 0 0.056 164 3.7M 0 0.059 148
WordPress Download Monitor 1.5M 1 0.036 7 1M 1 0.033 7
WordPress SEO by Yoast 1.2M 4 0.018 21 0.7M 4 0.014 16
WP e-Commerce 0.8M 1 0.012 5 0.9M 1 0.011 5
YOURLS WordPress to Twitter 1.7M 0 0.022 60 1.5M 0 0.025 53
Average 1.3M 0.57 0.020 28 1.1M 0.49 0.018 22
Total 45.9M 20 0.708 981 38.6 17 0.624 755

This data can change depending on the page used to do the testing since plugins can loading different things based on the page. But, these numbers are good reference point to see how the loading of plugins affect the WordPress. Also, you can see on average (and total) how much each plugin adds to the WordPress loading. What each row color means:

Colors: Average optimization results
Bad optimization results, must be improved
Not good, should be improved
Good optimization, some space for improvement
Excellent optimization results

I have mentioned the second part of loading that happens after all plugins are loaded, and WordPress runs actions and filters after that. Table below shows the difference between the WordPress with 35 plugins and WordPress with no plugins. Before plugins loader results are same for clean WordPress and WordPress with plugins.

Interesting thing is that you can have all 35 plugins active, and I had some WordPress setups with more than 70 active plugins. But, be ready for the WordPress using much more resources. The more plugins you have active, the more server power is needed. Plugins will have negative impact on website speed. To fix that you must use a caching plugin (W3 Total Cache for caching pages and minify the JS and CSS files) and some sort of server based optimization (eAccelerate or similar extension for PHP).

Clean WordPress will work with 32MB set for PHP to use. You can have less, but some internal operations might need a bit more, so 32MB is safe minimal value. If you have a couple of plugins, 32MB should be enough. If you have more than 10 plugins, at least 64MB is needed. As you can see from this test, for 35 plugins I had here, you need more, and 96MB or 128MB is safe value. Some shared hosting companies will not let you have more than 64MB or 80MB, so you might have issues with many plugins if you are on some restrictive hosting companies. Consult hosting support to make sure you will get enough resources. You can use average values above to get some orientation value for memory needed.

Administration Frontend
Test Mem. SQL Time Hooks Mem. SQL Time Hooks
Clean WP: Before plugins loader 13.2M 1 0.146 344 13.1M 1 0.172 307
Clean WP: After plugins loader 4.7M 32 0.236 137 1.0M 20 0.121 43
Clean WP: Total loading results 17.9M 32 0.381 481 14.1M 21 0.121 350
WP with plugins: After plugins loader 23.0M 235 1.206 893 9.7M 183 0.575 305
WP with plugins: Total loading results 81.3M 255 2.055 2221 60.2M 200 1.354 1364
Total 35 Plugins Impact 63.4M 223 1.674 1740 46.1M 179 1.233 1014

Optimization Analysis

As you can see in the plugins table on the top, some plugins results are in different colors. Green colors are for plugins with good optimization, red colors are for plugins with bad optimization. Badly optimized plugins are always loading everything on front-end and on admin side and they take a lot of memory. Smaller plugins with less than 0.8MB of memory used are not a big problem and they usually can’t be much optimized considering number of plugin files.

Since most plugins are behaving different on admin side and front-end, they should be taking care of what will be loaded in both cases. Only files that are actually needed should be loaded. This is not always possible, but with little extra work, code can be separated to allow for better loading optimization. Considering how much memory some of the plugins use, it is essential to try and lower required resources. Most WordPress users are on shared hosting servers, and they need plugins that are optimized.

The Bad

Plugins with worst loading stats and worst optimization from this test are: bbPress, GD Star Rating, Subscribe2, The Google+ Plugin, WooCommerce and YOURLS WordPress to Twitter. bbPress should be loading parts of the plugin only when needed, considering that forum is usually separated from normal WP pages. You can have some core parts always loaded, but most things are not needed on every page. My own GD Star Rating is old plugin, and I made some optimizations in some versions, but I need to do more, and GD Star Rating 2.0 will be highly optimized to use resources. The Google+ Plugin loads many libraries that are not needed for the most part, and for a simple plugin that this should be, it uses a lot of memory. I can’t judge quality of WooCommerce plugin, but I couldn’t believe how bad loading for this plugin is, and its main file loads 32 other files always. I have noticed some other things done bad in this plugin only from first few files, but loading is really bad.

Few plugins are a bit better than this, and they have lighter red color: BackupWP, Events Manager, gdHeadSpace4, GD Products Center Pro, GD Unit Converter, GravityForms. BackupWP doesn’t need anything on front end but it still loads things always. Events Manager has some loading optimizations, but I see potential to make it much better. I have modded plugin into gdHeadSpace4 and I didn’t make changes in loading. This plugin doesn’t have big memory footprint, but some changes can be done. My GD Products Center Pro is still in beta, and I plan to finish loading optimization before releasing 1.0 version. Another of my plugin GD Unit Converter is 100% admin side plugin, yet some things are loaded always, and I will improve this soon. GravityForms requires a lot of things on both admin and front end side, but there are some things that can be optimized much better that they are now.

The Good

Contact Form 7 and WP e-Commerce could benefit from some minor changes, but they are good as far as optimization goes. Light green and good optimization is done with: Antispam Bee and BackupBuddy. BackupBuddy would benefit greatly with better main loader file that is now too big. With fragmentation of this file, will help with optimization further.

Best optimized plugins, considering plugin size and features are: GD Affiliate Center Pro, GD Press Tools Pro, GD Custom Posts And Taxonomies Tools Pro, W3 Total Cache, WordPress Download Monitor, WordPress SEO. My 3 Pro plugins all have advanced loaders and modular structure to load things need for admin side or front end. Even the code used for Ajax or saving data is separated and loaded only when needed. W3TC does a great job in loading of different plugin modules and same goes for WordPress SEO by Yoast has loader that loads different files on both sides, minimizing the impact on WordPress.

My GD Press Tools Pro and GD Custom Posts And Taxonomies Tools Pro can replace great many other plugins, and that alone can save you a lot of resources. If you can have 10 plugins and if each one uses 1.3MB on average, that is 13MB, you can replace with GD Press Tools Pro only (and it can replace much more than just 10, maybe 60 or more plugins), that will use only 2.9MB.

Loading used in my plugins

Process of loading for my GD Press Tools Pro plugin is controlled by main plugin file. First, it loads parts of gdr2 shared library (used by all my plugins). Public functions and classes are loaded next (they are used on both admin and front end side). Some parts of internal code are loaded next. Main plugin class is loaded after that, and this class is used to initialize the plugin and load plugin settings. Than, loader checks if its loaded on admin side. If it is, admin core class is loaded as well as some extra functions. And if the plugin is loaded to save settings or through AJAX call, it loads separate settings saving or AJAX classes. This all improves loading on front end side by some 30%. This loading method is changed over time, and I think that it works great right now.

Two plugins I ALWAYS use

I can’t imagine running WordPress website without my GD Press Tools Pro. It is truly ultimate administration plugin, and it does so many things that you simply need on any website: backup, sitemaps, SEO, optimization and integration… Second plugin is W3 Total Cache. Page caching, external files minify and support for CDN are something each website should use to improve website speed.

Cached Pages

If you use W3 Total Cache or some other similar caching plugin, and you have page cache enabled, it is important to know that when cached page is served to a visitor, WordPress (and plugins) are not loaded at all. All these tests are made when there is no page caching active.

Conclusion

As you can see, plugins can have big impact on WordPress. While you can have as many plugins as you like, there are things to consider:

  • Compatibility: the more plugins you have, there is more chance to have some of them causing problems. Always test plugins when adding new plugin, it is rare, but it can happen. I always have local copies of all my websites, and when new things are added, I always test locally before moving to live server.
  • Resources: the more plugins you have, the more server resources will be used. If you are on the shared hosting, I recommend that you review if you really need all plugins you might have already. Test different plugins you can use, because with too many of them active, you can easily hit the limits imposed by your hosting company. My GD Press Tools Pro can do many things, one of them is to measure data like this, and you can see exact impact of a new plugin added on memory, mySQL server or WordPress.
  • Loading Speed: more plugins == less speed. It is very important to use cache plugins to optimize front end loading, to minify external files and use CDN to load external resources.

I hope that other plugin developers will consider the results from this article, and my recommendations to improve loading for own plugins to optimize them so that end users get faster plugins that are not needing too much resources. Lets make plugins even better.

]]>
http://www.dev4press.com/2011/blog/benchmark/measuring-impact-of-plugins-on-wordpress-loading/feed/ 87
Add rich text editor to your plugin http://www.dev4press.com/2010/tutorials/wordpress/tips/add-rich-text-editor-to-your-plugin/ http://www.dev4press.com/2010/tutorials/wordpress/tips/add-rich-text-editor-to-your-plugin/#comments Wed, 21 Jul 2010 22:15:03 +0000 MillaN http://www.dev4press.com/?p=2651 Editor Example

Editor Example

Sometimes is very useful to be able and use existing WordPress rich editor within your plugins. TinyMCE editor built in WP can be easily reused and you can even set some elements. Following example will work in WordPress 2.8 and newer including latest WP 3.0.

There are two parts to this procedure. One is to load needed JS and CSS files, and other to call the editor where you want it displayed.

Loading Editor

To load TinyMCE you need to use the following code. First two lines attach hooks to init and head actions. Two functions hooked follow after. One loads JavaScript needed, and second actually loads the editor. Line that enqueues the media upload element is needed only if you use media buttons.

<?php
add_action('admin_init', 'editor_admin_init');
add_action('admin_head', 'editor_admin_head');

function editor_admin_init() {
  wp_enqueue_script('word-count');
  wp_enqueue_script('post');
  wp_enqueue_script('editor');
  wp_enqueue_script('media-upload');
}

function editor_admin_head() {
  wp_tiny_mce();
}
?>

Display editor

Editor is displayed using one function. This function is defined as follows:

the_editor($content, $id = ‘content’, $prev_id = ‘title’, $media_buttons = true, $tab_index = 2)

First parameter, $content will be displayed inside the editor. Next is $id, and the textarea element created will have that ID. You can use it to get the content from the editor. Next parameter can be used the specify previous element in the form for tab moving (last parameter). And, $media_buttons allow you to display or hide media upload buttons above the editor.

Here is an example:

<div id="poststuff">
<?php
  the_editor("", "content", "", true);
?>
</div>

This you need to add on your panel where you want editor displayed. It will fit into any DIV you want so that you can limit the size and dimenzions. Using “poststuff” DIV is important so that all elements are styled properly.

Content of the editor is available as part of the form on submit named as content, or whatever you set as ID in the code above. If you want to access to content from JavaScript use this:

tinyMCE.activeEditor.getContent();

That’s all you need to know (for now), you can use anything tinyMCE object offers from JavaScript. If you need more help, leave a comment.

]]>
http://www.dev4press.com/2010/tutorials/wordpress/tips/add-rich-text-editor-to-your-plugin/feed/ 79
GD Press Tools 3.4 http://www.dev4press.com/2010/blog/plugins-news/gd-press-tools-3-4/ http://www.dev4press.com/2010/blog/plugins-news/gd-press-tools-3-4/#comments Sun, 09 May 2010 12:31:26 +0000 MillaN http://www.dev4press.com/?p=2117 GD Press Tools 3.4 Pro is now released. We are well under way to 3.5 and more importantly to 4.0 release, that is in development. This time, several bugs are fixed and you will see first changes to the plugin panels organization, and few minor new features.

User Columns

User Columns

Users panel grid is expanded with one more column for last recorded user activity. This tracking is added few weeks ago, so you might not have too much data recorded yet, but over time you will have clear picture when users have been active on the website.

GDP_R print function and CSS and JS it uses are now embedded into the page. Both these are very small, and it’s not really good to link two additional files, it’s better to move them into the page.

WP Hooks panel is gone, and added to Environment panel. Hooks will be improved soon with more debug usage and added to footer like SQL queries. Dashboard widget is updated and styled better, and number of minor bugs are fixed.

In about 2 weeks time, 3.5 will be released, that’s a bit later than I first expected, but it will be worth the wait.

]]>
http://www.dev4press.com/2010/blog/plugins-news/gd-press-tools-3-4/feed/ 2
GD Press Tools 3.2 http://www.dev4press.com/2010/blog/plugins-news/gd-press-tools-3-2/ http://www.dev4press.com/2010/blog/plugins-news/gd-press-tools-3-2/#comments Mon, 12 Apr 2010 16:32:53 +0000 MillaN http://www.dev4press.com/?p=1726 Another major release for GD Press Tools, again with some very interesting new features. Yesterday Lite version of GD Press Tools 2.4.2 was released with added support for multi site or MU versions of WordPress. That is also part of this latest Pro edition.

For multi sites, new panel is added for site admin to set what panels can be accessed by the individual blogs. This includes database, server info, wordpress hooks and cron scheduler. More elements will be added if needed. At this point, this is tested with WordPress 3.0 with multi site enabled and also with WordPressMU 2.9.2.

Database backup is improved, and additional options are added to allow partial backup and select only some tables in the database. This works with immediate backup and for scheduled jobs. All individual blogs installations now have own backup locations. And, another debug tool is added that will allow you to visualize the JSON strings. JSON will be converted into PHP object, and this object displayed using print_r or gdp_r functions. To ensure that this works on every version of PHP, JSON code is added into the plugin to be included if PHP is older than 5.2.

In the next day or two Lite version 2.4.3 will be released with few more improvements (already part of this 3.2 Pro) for backup in multi site environments.

Since WP 3.0 is still in development, some changes can potentially break GD Press Tools. So, please, report any problems so that I can fix them before WP 3.0 is released.

]]>
http://www.dev4press.com/2010/blog/plugins-news/gd-press-tools-3-2/feed/ 0