Posts Tagged ‘PHP’

April 22nd, 2012

Add blog link to admin nav

WP Static Pages and Sites Link

With the newer versions of WordPress the admin nav bar is great. But when you have a static page site for home and blog, then the site link always brings you to the home page, when most of the time you want the blog page.

This snippet will add a Blog link to the Admin Nav Bar when in the Admin area.

Select All
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function add_blog_menu()
{
	/** @var $wp_admin_bar WP_Admin_Bar */
	global $wp_admin_bar;
	if (!is_super_admin() || !is_admin_bar_showing())
		return;
 
	if (is_admin())
	{
		$wp_admin_bar->add_menu(array(
				'id'     => 'blog',
				'title'   => 'Blog',
				'href'   => site_url() . '/blog'
			)
		);
	}
}
 
add_action('wp_before_admin_bar_render', 'add_blog_menu');

Note: the Blog link.
This alows you to quickly return the sites blog from the admin panel when having a static home page that is not the blog or post list.

April 21st, 2012

WordPress Benchmark Dev Tool

WP BenchmrkII is a tool that I made for profiling, benchmarking and development.

It has many key features that can significantly help with these tasks.
This tool is in development itself, but I use it almost daily for my work.

Its very powerful and helps me greatly in my day 2 day WordPress work.

Features

  • Database Query Count
  • PHP Load Time
  • Memory Usage
  • Peak Memory
  • Include Count
  • Hook Count
  • Current Template
  • List Queries (Query, Time, Functions)
  • List Includes (With filters)
  • List Hooks
  • List Constants (user)
  • Show in admin also

Currently some of the biggest issues I am asked from WordPress clients are about performance. I use this tool to locate and remove performance bottlenecks.

I also use it when developing client sites in WordPress so that I can keep track of how my code performs. This way if something goes high, like memory after adding the code, I know it needs refactoring.

This plugin is Open Source and can be downloaded from my GitHub account. Get the code here.
If you use it, you should follow this project, I change it adding new features constantly.

Or, download directly the latest version from the git repository. Download Zip
Rename the parent folder to WP-Benchmark after unzipping.

LIke I said, this is in development and may have some bugs. Please let me know if you find some.

WordPress Theme Development Controversies and what some say can be not only wrong but hurt your site and its performance.

Just to name a few…

  • Don’t add custom stuff that should be a plugin.
  • Clearly separate all of the src resource files.
  • Minimal Admin Options

Read More…

March 4th, 2012

PHP Hash Algorithms

So I was playing with some hashing and upon reading up on available hashes decided to do some benchmarks.
PHP Hash Algorithms
Read More…

phpStorm Logo As I mentioned in a previous phpStorm post, phpStorm is my favourite PHP IDE.
Since I do a lot of work with phpBB3, I have a couple tips for code completion.

There are basically 2 main phpBB3 code libs that do not have completion and are used a lot.
The DBAL and ACM, though the DBAL is used the most, I put the caching in as well, just in case its needed.

Select All
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Open phpBB3 root/common.php
 
// Add doc blocks above
$cache = new cache();
$db = new $sql_db();
 
// So they look like this
/** @var $cache acm */
$cache = new cache();
 
/** @var $db dbal_mysql */
$db = new $sql_db();
 
// This should provide code completion for most if not all query functions in phpBB3 and also cache functions

What we are doing is setting the reference for the class to the global var using the @var annotation.
This will give you almost complete code completion for any SQL query functions you need to use from the DBAL.
Also including the phpBB3 caching mechanism ACM.

There are others that require class assigning annotations as well.
Like the custom profile field class to name one.

So when you work with these, just annotate your instance var referencing it to the class like we did in the above code.
Then you should have full completion for your phpBB3 project.

Stay tuned for more phpStorm tips.