A blend of programming and seo

Anatomy of a wordpress plugin

This article is the first in a series of how-to articles which will go through all the steps required to create a wordpress plugin.

At the end of the article, there will be a download link to a working plugin that you can download and use as a template for building your own plugins. The latest version of Wordpress is required (2.8.5), which is the version I used when writing this article. Earlier versions might also work, but I can’t guarantee it.

The first step is to create a new php file called testplugin.php

<?php
/*
Plugin Name: Rawseo - test plugin template
Plugin URI: http://www.rawseo.com
Description: A great plugin template
Version: 1.0
Author: Rawseo
Author URI: http://www.rawseo.com
*/


?>

The comment headers in your main plugin file (everything above between (/* and */) give wordpress information about your plugin which is displayed on the plugin information screen.

If you were to upload our template plugin file right now to your Wordpress plugins directory (wp-content/plugins), you would see the following in your plugin manager:

plugin install Anatomy of a wordpress plugin

Now, we are going to add a settings page for our new plugin.

<?php
/*
Plugin Name: Rawseo - test plugin template
Plugin URI: http://www.rawseo.com
Description: A great plugin template
Version: 1.0
Author: Rawseo
Author URI: http://www.rawseo.com
*/


function checkAuth()
{
    return current_user_can('activate_plugins');
}

function settings_subpanel()
{
    global $wpdb; //this gives us access to the wordpress database
   
    if (isset($_POST['new_email_address']))
    {
        update_option("admin_email",$wpdb->escape($_POST['new_email_address']));
    }
   
    echo '<div class="wrap">';
    echo '<h2>Rawseo test plugin</h2>';
    echo '<form action="" method="post">
    <p>This plugin allows you to edit and save the wordpress admin email address</p>
    Admin Email Address: <input type="text" size="20" name="new_email_address" value="'
.get_option("admin_email").'"><br/>
    <input type="submit" value="Save" /></form>'
;
}

function settings_page()
{
    if (checkAuth())
    {
        if (function_exists('add_options_page'))
        {
   
       
            //add_options_page(page_title, menu_title, capability, file, [function])
            add_options_page('Rawseo options','Rawseo test plugin','administrator', basename(__FILE__),

'settings_subpanel');
        }
    }
}

add_action('admin_menu', 'settings_page');
?>

Understanding how to create your own plugin first requires an explaination of some built-in wordpress functions that are required to properly communicate with various sections of your administration panel and blog.

Even though it’s at the end of the file, add_action starts the process rolling for the settings page. Wordpress allows you to hook into different events with your own functions, which can execute and process code at various times. Since we are adding a new settings page onto the administrative menu, ‘admin_menu’ is passed as the first parameter (which is the event) and ’settings page’ is passed as the second (this is our function that will be called for that event).

function checkAuth()
{
    return current_user_can('activate_plugins');
}

CheckAuth() checks to see if the user has the correct permission to view or edit our plugin settings through a function called current_user_can.

The following is a list of all of the possible permissions that you can check:

  • install_themes
  • update_themes
  • switch_themes
  • edit_themes
  • install_plugins
  • activate_plugins
  • edit_plugins
  • update_plugins
  • delete_plugins
  • create_users
  • edit_users
  • delete_users
  • edit_files
  • manage_options
  • import
  • unfiltered_upload
  • edit_dashboard
  • moderate_comments
  • manage_categories
  • manage_links
  • unfiltered_html
  • edit_published_posts
  • edit_others_posts
  • edit_pages
  • edit_others_pages
  • edit_published_pages
  • publish_pages
  • delete_pages
  • delete_others_pages
  • delete_published_pages
  • delete_others_posts
  • delete_private_posts
  • edit_private_posts
  • read_private_posts
  • delete_private_pages
  • edit_private_pages
  • read_private_pages
  • upload_files
  • publish_posts
  • delete_published_posts
  • edit_posts
  • delete_posts
  • read
add_options_page('Rawseo options','Rawseo test plugin','administrator', basename(__FILE__),'settings_subpanel');

add_options_page adds our new options page to the settings menu.

add_options_page(page_title, menu_title, capability, file, [function])

page-title: Text that will go into the HTML page title for the page when the menu is active.
menu-title: The on-screen name text for the menu.
capability: The minimum role required to display and use this menu page.
examples: Editor,Author,Contributor,Editor,Administrator
file: If the function parameter is omitted, this should be the PHP file that handles the display of the menu page content.
function: function that displays the page content for the menu page

plugin settings Anatomy of a wordpress plugin

settings_subpanel() displays all of the HTML that will be contained in the new settings page. I also used a couple of built-in functions that may help you when you build your own plugins.

update_option(): Update an option in the wp_options table.
get_option(): Get an option from the wp_options table
$wpdb->escape(): Used to prevent injection attacks by encoding certain characters. You should be ussing this function (or some other type of escaping) on any data sent into a database.

Download

This example plugin will display an input form which will allow you to update the current wordpress admin email address. If you would like to download the plugin example from this article, it can be found here.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

November 17, 2009   Comments Off

rawtracker 1.1 released

usps rawtracker 1.1 released

Rawtracker is an application written in PHP that you can add to your website that allows your users to track their United States Postal Service (USPS) packages.

Installation

Step 1: Upload all files from the rawtracker download to your website.
Step 2: Open plugins/configure.php and add your USPS account information.

define("USPS_SERVER","http://production.shippingapis.com/ShippingAPI.dll");
define("USPS_USERNAME","***Your usps username goes here***");
define("USPS_TIMEOUT",'5');

You will need to get a USPS web services account (available for free here).

When you register for an account, it will only have access to the USPS test servers. The variable above can be changed to the following for testing:

define("USPS_SERVER","http://testing.shippingapis.com/ShippingAPITest.dll");

After a few test requests are sent out, your account can then be upgraded to production level (and the URL will need to be changed back to the production servers).

Step 3: Adding rawtracker to your site is pretty easy.

In the header of your page, add the following:

<script type="text/javascript" src="rawtracker/js/rawtracker.js"></script>
<script type="text/javascript" src="rawtracker/js/rawtracker_popup.js></script>
<link rel="
stylesheet" href="rawtracker/css/rawtracker.css" type="text/css" media="screen">

In the body add:

<input type="text" size="16" id="trackingNumber">
<input type="button" value="Track" onclick='trackLaunch()'>

Download

Rawtracker 1.1 can be downloaded Here.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

October 31, 2009   2 Comments

Must-have tools for php developers

The following are tools that are invaluable to any php developer:

1) PHP Development Tools Project (eclipse)

Link: http://www.eclipse.org/pdt/

The PDT project provides a PHP Development Tools framework for the Eclipse platform. This project encompasses all development components necessary to develop PHP and facilitate extensibility. It leverages the existing Web Tools Platform (WTP) and Dynamic Languages Toolkit (DLTK) in providing developers with PHP capabilities.

2) ez_sql/ez_results – mysql wrapper library (Free)

Location: http://www.jvmultimedia.com/portal/

A great mysql library that features:

-Disk caching
-It is one php file that you include at the top of your script. Then, instead of using standard php database functions listed in the php manual, you use a much smaller (and easier) set of ezSQL functions
-It has excellent debug functions making it lightning-fast to see what’s going on in your SQL code
-Most ezSQL functions can return results as Objects, Associative Arrays, or Numerical Arrays
-Works with Smarty templating language

3) Smarty Template Engine (Free)

Location: http://smarty.php.net/

An excellent template engine for php.

One of Smartys primary design goals is to facilitate the separation of application code from presentation. Typically, the application code contains the business logic of your application, written and maintained in PHP code. This code is maintained by programmers. The presentation is the way your content is presented to the end user, which is written and maintained in template files. The templates are maintained by template designers.

4) mysql gui bundle 5.0 (Free)

Link: http://dev.mysql.com/downloads/gui-tools/5.0.html

A suite of GUI tools that includes: MySQL Administrator, MySQL Query Browser, MySQL Migration Toolkit, and MySQL Workbench.

Here is a list of some more tools that can be very helpful for php developers.

Editors

Pnotepad: http://www.pnotepad.org/

Pspad: http://www.pspad.com/

notetab: http://www.notetab.com/

notepad++: http://notepad-plus.sourceforge.net/uk/site.htm

conTEXT: http://www.context.cx/

php Designer: http://www.mpsoftware.dk/

Dev-PHP: http://devphp.sourceforge.net/

notepad2: http://www.flos-freeware.ch/notepad2.html

crimson editor: http://www.crimsoneditor.com/

textpad: http://www.textpad.com/

ultraedit (commercial): http://www.ultraedit.com/

Mysql GUI clients

Navicat (commercial) : http://www.navicat.com/

phpmyadmin: http://sourceforge.net/projects/phpmyadmin/

sqlyog: http://code.google.com/p/sqlyog/

Libraries

Propel: http://propel.phpdb.org/trac/wiki/Users/Introduction

Html purifier (Great for preventing XSS attacks): http://htmlpurifier.org/

Templates/Frameworks

phptal: http://phptal.motion-twin.com/

cakePHP: http://www.cakephp.org/

prado: http://www.xisc.com/

codeIgniter: http://codeigniter.com/

savant: http://phpsavant.com/

bTemplate: http://www.massassi.com/bTemplate/

vLibTemplate: http://vlib.clausvb.de/

Blitz (a php extension): http://alexeyrybak.com/blitz/blitz_en.html

php template engine:
http://www.phpte.com/

fryPHP: http://fry.sourceforge.net/

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

October 21, 2009   3 Comments

Zencart local seo reports mod

zenlogo Zencart local seo reports mod

Introduction

This module allows you track all of the keywords used to search you website. This can be helpful because it can give you an insight into what your customers actually need.

keyword box Zencart local seo reports mod


Installation

Step 1: Open admin/includes/boxes/report_dhtml.php

at line 20 where it says:

$za_contents[] = array('text' => BOX_REPORTS_CUSTOMERS_REFERRALS, 'link' => zen_href_link(FILENAME_STATS_CUSTOMERS_REFERRALS, '', 'NONSSL'));

add right after:

$za_contents[] = array('text' => 'Rawseo Local Keyword Reports', 'link' => zen_href_link('rawseo_keyword_reports.php', '', 'NONSSL'));

step 2: open includes/modules/pages/advanced_search/header_php.php

at the end, add the following:

//log keywords
$keywordQuery = sprintf("INSERT INTO rawseo_keyword_reports (keyword,timestamp) VALUES('%s',now())",mysql_escape_string($_GET['keyword']));
@mysql_query($keywordQuery);
//end logging keywords

step 3: open includes/modules/pages/advanced_search_result/header_php.php

find the following line (around line 54):

if (isset($_GET['keyword']) && $_GET['keyword'] != HEADER_SEARCH_DEFAULT_TEXT  && $_GET['keyword'] != KEYWORD_FORMAT_STRING) {
    $keywords = $_GET['keyword'];

add right after:

//log keywords
$keywordQuery = sprintf("INSERT INTO rawseo_keyword_reports (keyword,timestamp) VALUES('%s',now())",mysql_escape_string($keywords));
@mysql_query($keywordQuery);
//end logging keywords

step 4: Upload all files included in this zip file to your catalog

step 5: import db/rawseo_keyword_reports.sql into your database

You should now have another menu item under reports called “Rawseo Local Keyword Reports”.

Download

All files for this module can be download here.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

October 20, 2009   No Comments

How to create a multi-file uploader for your website

If you own a website of any kind and have ever wanted to allow your users to upload multiple files from a single screen, you have a few choices:

  • a java applet
  • an active X control
  • A Flash app
  • multiple file input elements (which is messy and not very efficient)

The following is a much easier way to allow multiple file uploads. Using DOM (The Document object Model), one file upload box can be created making it much easier and more user-friendly.

multiple uploads How to create a multi file uploader for your website

Installation and usage

Installation is pretty easy. The download includes sample code that you can use on your website.

All files and example of usage can be downloaded Here

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

October 15, 2009   No Comments