Categories
Wordpress

Disable Admin Bar

Lots of ways to skin this cat, but this is the easiest for wp 3.3+

in functions.php
show_admin_bar(false);

Categories
News

adding jquery to wordpress

jQuery is already in wordpress so if you need to use it, there is no need to pull it in from elsewhere.
Use:
wp_enqueue_script(‘jquery’);
to access jQuery. However, you will not be able to use $(). The right way is to

Categories
Development Web

VirtualDocumentRoot for local development

If you want to develop locally on your machine, its a pain to have to write a virtualhost container and restart apache every time. There is a simple way to do this by using VirtualDocumentRoot directive.

1) use localhost as the domain and create subdomains in /etc/hosts ie
127.0.0.1 devsite.localhost

2) Put this into your httpd-vhosts.conf file

VirtualDocumentRoot /my_home_dir/Sites/%0

AllowOverride All

Order allow,deny
Allow from all
All your development sites need to be in /my_home_dir/Sites and the directories must have the same name as the entry in /etc/hosts ( ie /my_home_dir/Sites/devsite.localhost/ )

Categories
Development

Xdebug and Phpstorm

Phpstorm is an IDE made by Intellij. I’ve never really used an IDE for php before. I have tried Aptana and Eclipse but didn’t really like them. My coworker Alex really loves Intellij so I thought I would give it a try. One of the reasons I’m giving in is due to having to work on Magento.
Magento is so large that without an IDE, it would be difficult to navigate. Instead of grepping, I would like to use something that can find the definition/declaration of functions and trace through the stack.

First, my impressions of Phpstorm: I like it! It doesn’t have as many of the mystery buttons of Aptana, and pretty much everything is configurable. I was able to find an editor theme that I liked ( http://elis.ws/phpstorm-dark-theme/ ).

My next task was to get Magento working on my local machine ( Mac OSX Lion). This is the first hiccup as mcrypt is not compiled. There are a few ways to fix this but coupled with the fact that xdebug is also not compiled for OSX, I’ll save you the time and tell you that MAMP is the easiest option.

By default, MAMP runs apache on port 8888 and mysql on 8887, you can set the preferences in MAMP to change them back to port 80 for apache and 6667 for mysql provided that you are not running web sharing or mysql server on the mac. If you are, simply disable in your System Preferences.

The next thing to do is to turn on vhosts config for MAMP. Edit /Applications/MAMP/conf/apache/httpd.conf and uncomment
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

You can set local vhosts for development and modify /etc/hosts so that your mac responds to a domain for development. I’ll write about how to make all this easy to deploy using VirtualDocumentRoot later.

The last step is to turn on xdebug. Edit your php.ini ( ie /Applications/MAMP/bin/php/php5.3.6/conf/php.ini ) and add the following lines:
*** make sure the path to your zend_extension matches what you installed from MAMP ***
zend_extension=”/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so”
xdebug.default_enable = On
xdebug.show_exception_trace = On
xdebug.show_local_vars = 1
xdebug.var_display_max_depth = 6
xdebug.remote_enable = 1

xdebug.dump_once = On
xdebug.dump_globals = On
xdebug.dump_undefined = On
xdebug.dump.REQUEST = *
xdebug.dump.SERVER = REQUEST_METHOD,REQUEST_URI,HTTP_USER_AGENT

To debug from Intellij you can either set up the PHP processor ( CLI ) to your MAMP php binary, or you can have Phpstorm listen to port 9000 for xdebug messages. Xdebug does this by
1) set a cookie in your browser so that when xdebug.so module intercepts the request and sees the cookie, it will:
2) stop at the break points in debugger window.

Use the bookmarklet generator link on this page.

Navigate to your local development site, turn on the listening in Phpstorm for this project and set the break points in Phpstorm. Click on the bookmarket to set the cookie for Xdebug. Reload the page and watch Phpstorm debug window.

Enjoy!

Categories
Wordpress

Add a theme options page

http://codex.wordpress.org/Function_Reference/add_theme_page

function theme_admin_setup() {

add_theme_page(
__( ‘Theme Options’),   // Name of page
__( ‘Theme Options’),   // Label in menu
‘edit_theme_options’,                    // Capability required
‘theme_options’,                         // Menu slug, used to uniquely identify the page
‘theme_options_page’ // Function that renders the options page
);
}

add_action(‘admin_menu’, ‘theme_admin_setup’); // must be wrapped in admin_menu
function theme_options_page() {

if ($_POST) { .. update .. }

// page for the form

}

 

Categories
Wordpress

Easy way to add embed code to your site

If you want to embed from popular video sites, rather than copying and pasting embed codes, use oembed and the built int wordpress oembed functions.

http://codex.wordpress.org/Function_Reference/wp_oembed_get

Call it from your template and it will create the embed code for you. The only drawback is that it may be slower.