Tagsnippets

Encode Entities Inside PRE Tags

Here’s a little Python script that searches through a given file for pre tags and encodes anything in between. This is useful for when escaping from syntax highlighting plugins and replacing every occurrence of the code shortcode with a pre tag. import re, sys # First argument is the filename, output is filename.encoded filename = sys.argv[1] f = file(filename) output = open('%s.encoded' %...

How To: List Filters That You Are About to Apply

I was working on a project where I had to find out all the registered filters that I was about to apply, so here’s a WordPress quickie for you! I found this out by inspecting the apply_filters function inside the plugin.php core file, and apparently there’s a $wp_filter global that contains them all in an associative array where keys are tags. So by doing a print_r at a certain time...

A Thought on WordPress Page Templates

I was looking into more premium themes for WordPress the other day, and I see that most of them simply love to give users different page templates. Not all of them are doing it the correct way, but it still is a value add to a WordPress theme. If you recall from the Codex pages, Page Templates in WordPress are defined with a special comment header in the template files. They can then be chosen at...

Snippet: Using jQuery 1.5 in WordPress

Yes! jQuery 1.5 was released and I’m sure some of you can’t wait to start using it in their WordPress themes and plugins. So, with a few filters magic, we can get jQuery 1.5 up and running. Add the following code to your theme’s function.php file: add_filter( 'script_loader_src', 'my_script_loader_src', 10, 2 ); function my_script_loader_src( $src, $handle ) { if ( $handle ==...

Snippet: A "Feed Only" Shortcode for WordPress

This might be valuable for banner ads, pitches to get people on to your website rather than simply reading stuff in their RSS feeds. You can address your RSS subscribers differently in each and every post, just by using this WordPress shortcode trick! I’m not and ad-guy myself and I don’t care much if people read my feed or browse my website, as long as they’re reading my...

Using Google's URL Shortener (goo.gl) in WordPress

The Google URL Shortener API has been released this week so I came up with a short snippet that generates short goo.gl URLs. The script is quite simple, you can paste it in your theme’s functions.php file or create a plugin out of it, so without further ado: function googl_shortlink($url, $post_id) { global $post; if (!$post_id && $post) $post_id = $post->ID; if ($post...

Counting Facebook Fans in PHP: The Graph API Way

In a previous blog post called How to Count Facebook Fans in PHP I’ve shown a code snippet of how to count the number of fans on a fan page using PHP. Times have changed, the Graph API has been introduced, and due to some responses I introduce here the new way of retrieving your fans count using the new Graph API and php. Before you copy and paste, flush my comments with ‘my code is...

WordPress: Oh Those Actions and Filters!

Reading Joost de Valk’s quick post about Simple WordPress Debugging with a query variable made me think for a while. Really, how often do you come across a white screen with no clue of what’s happening? Very effective indeed, and good note about the security issue, but anyways, what came into my mind is a life-saver for all WordPress themes and plugins developers. I came accross this...

How To: Retrieve a User ID via SOAP in SugarCRM

Following the Lead Generation Forms with WordPress and SugarCRM post, I came across the need to assign the generated lead to some person in the CRM. It would be easy if you could do it by simply using usernames in the system, but unfortunately usernames may change, but user IDs do not. User IDs in SugarCRM are stored in a 36-byte alphanumeric string with symbols, which is easy to capture from the...

WordPress Snippet: List Authors/Contributors

We were playing around with Brian (@bkmacdaddy) today on a WordPress blog with a few over 50 authors, then bumped into an issue where we had to output a list of all contributors. It’s quite easy at first sight, and functions such as wp_list_authors are quite good at it, but not good enough. The main issue was that the authors had to be paged and sorted by their names. Moreover, each entry...