Close

Home » Posts tagged 'wordpress'

Posts Tagged ‘wordpress’

February 2nd, 2012

Slow WordPress Issues and Related Reasons

I see a lot of people complain about their WordPress site being slow to load.

The Internet is full of complaints about this issue and people asking for help to fix it.

Then you do simple profiling of their site and see stuff like
215 requests
2.7 MB downloaded
(1.2 MB from cache)
20.85s (onload: 14.35s)

Those are ridiculous numbers!
(more…)

January 26th, 2012

Code completion in phpStorm with WordPress

phpStorm Logo I use phpStorm pretty much exclusively for PHP development, for over a year.
It simply has some awesome features.

But there are some things that people tend to complain about.
One of the biggest I am going to show you how to fix.

phpStorm by Jetbrains uses a stricter approach for code completion than most PHP IDE’s.
They index all constructs but for everything else phpStorm requires proper phpDoc annotations.

The reason behind this I think is simply for performance to keep it a bit litter and to have faster start-ups.

I will be doing a few of these examples for popular open source projects that have code completion issues do to their standards or simply not having phpDocs at all.

Once you get the hand of this, its pretty easy to do and works quite well.
Some of these issues are seen in all IDE’s not just phpStorm

So here we go, digging into the code.
The comments explain just about everything you need to know.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* @see https://gist.github.com/1105126
*/
 
// Also some more hints and fixes
 
// WP functions for adding to the admin bar
// This will provide code completion for admin_bar functions like add_menu()
/** @var $wp_admin_bar WP_Admin_Bar */
global $wp_admin_bar;
 
// Fixing dynamic includes, also so they link properly in the editors environment
require_once(get_template_directory() . '/inc/base.php');
//As is the above require will show an error in phpStorm "Cant resolve target....."
 
//To fix this is easy, this fixes the error and also allows control click on the base.php and opens it
/** @define "get_template_directory()" "/var/www/wp-dev/wp-content/themes/tridium" This is just for the IDE */
require_once(get_template_directory() . '/inc/base.php');
 
// These same methods can be used to fix most errors and completion in phpStorm

Basically for accessing WordPress’s functions and methods that are mostly used eg wpdb, you add this file to the WP root https://gist.github.com/1105126.

I prefer as in the comments of the file to have the class named wpdb and remove the extends.
Like this,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
 * @property wpdb  $ID
 * @property wpdb  $post_author
 * @property wpdb  $post_date
 * @property wpdb  $post_date_gmt
 * @property wpdb  $post_content
 * @property wpdb  $post_title
 * @property wpdb  $post_excerpt
 * @property wpdb  $post_status
 * @property wpdb  $comment_status
 * @property wpdb  $ping_status
 * @property wpdb  $post_password
 * @property wpdb  $post_name
 * @property wpdb  $to_ping
 * @property wpdb  $pinged
 * @property wpdb  $post_modified
 * @property wpdb  $post_modified_gmt
 * @property wpdb  $post_content_filtered
 * @property wpdb  $post_parent
 * @property wpdb  $guid
 * @property wpdb  $menu_order
 * @property wpdb  $post_type
 * @property wpdb  $post_mime_type
 * @property wpdb  $comment_count
 * @property wpdb  $filter
 * @property wpdb  $term_id
 * @property wpdb  $name
 *
 */
class wpdb {}

Then I drop that file in the WP root.
phpStorm will index the construct and use the listed properties in that file for code completion within the wpdb class.

You should not get duplicate class errors because we are not instantiating it.
Its just there for phpStorm.

I will be doing one of these for phpBB3 and also CodeIgniter so you may want to subscribe and follow future posts.

April 29th, 2010

Some VW Pro Theme Additions

VW Pro Theme Options Page

I added some tweaks to the VW Pro Theme options page.
It really looks awesome now and is quite a bit easier to navigate with collapsing blocks for each of the many theme options categories.
Also each category has it’s own save button.

The New VW Pro Contact Form

I added another option to the form allowing you to set a priority field with configurable drop down options.
DEMO
I absolutely love the reCaptcha :)

Some FeedBurner Changes

I recoded the FeedBurner feature entirely with error checking and statistics included.
Basically if it fails, it will tell you with the FeedBurner error message.

Side Note:
Future customers, you can add this code to your .htaccess file and redirect all WordPress RSS links to your FeedBurner Feed.
Make sure you change the Your_Id

1
2
3
4
5
6
7
# temp redirect wordpress content feeds to feedburner
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC]
 RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
 RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/Your_Id [R=302,NC,L]
</IfModule>
VW Pro Twitter Features

I coded a completely new twitter options for the sidebar.
It now shows all of the stats, options to show the profile picture and up to 20 of the latest tweets.
Also configurable height so you can have a scroll bar instead of a long list of tweets.
Absolutely no javascript or external javascripts required. This is entirely PHP and cached for an hour.
You can view these changes in the sidebar here to the right.

New FaceBook Like Options

Added the newest FaceBook feature, FaceBook Like.
This feature has options to show or not show the profile pictures of the users that liked the post.
It also has options to show the like button on the blog and/or single post page.

I will be adding even more features, if I can come up with some. Running out of ideas………

The first WP Pro Theme should be for sale very soon!

Full Browser Support