Archive

Posts Tagged ‘WordPress’

How to Setup a Basic WordPress Development Environment

May 7th, 2011 No comments


One of the most common things I get asked about when talking about developing WordPress plugins is my tools and development environment. Now, developers have all kind of tools and setups that they feel is the ‘Best’ way to do things. It’s all a matter of opinion really. It all boils down to needing a few things though, an Integrated Development Environment (IDE) that you are comfortable with, an LAMP, MAMP, WAMP stack (Apache, MySQL, PHP), SVN, and a download of WordPress. I’ll go through these 1 by 1 and show you how to get setup.

First off, a good book on development with your desired platform is NEVER a bad thing to have. I recommend Professional WordPress Plugin Development. They just released a new version of it and it’s a fantastic resource.
Continue reading “How to Setup a Basic WordPress Development Environment” »

WordPress Dev 101: Creating your own Hooks

December 15th, 2010 No comments

I had previously talked about using WordPress’ built in “Hooks” to make WordPress do your bidding through Plugins or Themes. Did you know it’s possible to create your own “Hooks” within your Theme or Plugin? You can create a hook by inserting the following line of code where you want to execute your function:

do_action( 'my_hook' );

Now you just need to supply your function to run at this hook juncture. This is typically done in a functions.php file or within a plugin you are writing:
Continue reading “WordPress Dev 101: Creating your own Hooks” »

Dropbox CDN Updates to come

December 2nd, 2010 5 comments

Some of you may have read this post over at Lifehacker about the bandwidth limitations that Dropbox puts on the public folder a user shares. Well, since my Dropbox CDN plugin uses the public folder of your Dropbox account, I’m going to be including a feature that will seamlessly check to make sure that you haven’t hit your Dropbox limit before using the plugin settings.

I hope to have this feature released sometime this weekend. I’ll keep you posted.

Custom Mystique Login updated

November 21st, 2010 2 comments

I updated the post about how to create a custom theme for the DigitalNature Mystique theme for WordPess. It’s been updated to reflect new versions of WordPress and the Mystique theme. Let me know in the post comments if you have any other issues with this. Here’s a snapshot of what it looks like.

A Preview of the Login Screen

Visit the original post
Get the Mystique theme

Categories: Updates Tags: , , ,

WordPress Dev 101: Replacing post content in-line

November 18th, 2010 No comments

Something I did recently when I updated the Better AdSense Targeting plugin, was create the ability to allow users to specify certain sections of each post that Google should ignore when determining what ads to display. I did this by using the str_replace() function in PHP and a little thing called ‘add_filter’ from the WordPress hooks. It’s rather simple and looks a little like the following.

First let’s think of something we might want to replace. Let’s say we want to make every instance of the string ‘[my other site]‘ turn into a link to your another website you run. Typically you’d need to code that out or use all the tools in the editing screen to do this, but instead, we cause use the power of str_replace() to do that for us.

We’ll need to include this fix in a plugin or the functions.php of your theme. First let’s make sure we’re adding the ‘filter’ on the content that we are taking from the post loop.

add_filter( 'the_content', 'url_replace' );

This line simply runs the function url_replace() whenever the_content() is run.

Next we’ll need to create the actual function that does the replacing:

function url_replace($content='') {
return str_replace( '[my other site]', '<a href="http://myothersite.com">My Other Site</a>', $content);
}

A little explanation here, we are running the function and are looking for instances of ‘[my other site]‘ and replacing it with the full HTML anchor tag and text in the string $content.

If you are wanting to replace multiple words or phrases you’ll need to do something like the following:

function multi_replace($content='') {
$content = str_replace( '[my other site]', '<a href="http://myothersite.com">My Other Site</a>', $content);
$content = str_replace( '[WordPress]', '<a href="http://www.wordpress.org/">WordPress.org</a>', $content);

return $content;
}

I don’t think I have to explain much here now, but we’re simply replacing any instance of ‘[my other site]‘ with the full HTML link and we are also looking for ‘[WordPress]‘ and making it link to WordPress.org. Easy enough, it creates links for you quickly, and allows you to focus more on writing. I find it common practice to put things like [WordPress] in and then later look for these strings in my drafts and replace them with links. Anytime I can avoid breaking my writing flow, I do, and shorthand notes are the way to go.

There you have it, you’ve successfully replaced content. Where this is useful is if you wish to include specific code wherever need be. You don’t have to replace this text with visible text. For instance, my AdSense Plugin replaces the string ‘‘ and ‘‘ with the proper HTML that I need to use to have Google AdSense ignore the content between these tags when selecting ads.

In this practice I used the str_replace() function, which is great for unique strings like [my other site] and [WordPress] however it can cause some issues when simply replacing normal text by including parts of other words as long as they meet the requirements of the replacement. For example, the word ‘and’ would be replaced in the words ‘brand‘, ‘sand‘, or ‘stand‘. If you are looking for a more indepth and intensive replace you might want to try using preg_replace() which uses Regular Expressions for it’s replacement rules

For more information on WordPress development check out the other posts in my ‘WordPress Dev 101′ series:

Happy Coding!

Categories: WordPress Tags: , , ,