WordPress – Directories and URLs

Home page of the web site:

$siteurl = site_url('/');
   => https://web20bp.com/kb/

URL of the current theme:

$template_url = get_bloginfo(‘template_url’);
   => CAGE Knowledge Base

Current CHILD theme directory:

$template_dir = get_template_directory();
   => /home1/webtwoze/public_html/kb/wp-content/themes/twentyeleven

Current CHILD theme URL:

$template_url = get_template_directory_uri();
   => https://web20bp.com/kb/wp-content/themes/twentyeleven

Physical path to the current directory:

$file = dirname(__FILE__);
   => /home1/webtwoze/public_html/kb/wp-content/plugins/rvg-all-tags

Plugins URL:

$url = plugins_url();
    => http://localhost/wp-content/plugin

Plugins directory:

$dir = plugin_dir_path(__FILE__);
    => C:\Rolf\wp-content\plugins\rvg-float-to-top-button/

Load a javascript file:

wp_enqueue_script('fttb-script',
plugin_dir_url( __FILE__ ).'/js/jquery.scrollUp.min.js',
array('jquery'), $this->fttb_version, true);


WordPress – Create your own WordPress Plugin

This is a basic example of how to create your own WordPress plugin.

Create a file called my-plugin.php and save it to a new folder /wp-content/plugins/my-plugin:

<?php
/**
 * @package Show all the tags in a web site
 * @version 0.1
 */
/*
Plugin Name: Show all the tags used in a web site
Plugin URI: http://cagewebdev.com/
Description: Show all the tags, used in a web site
Author: Rolf van Gelder
Version: 0.1
Author URI: http://cagewebdev.com
*/
?>
<?php
function rvg_show_all_tags()
{   $arr = wp_tag_cloud('format=array&smallest=10&largest=10&number=0');
    $output  = '<h3>All Tags ('.count($arr).')</h3>';
    $output .= '<div style="border: solid 1px #ccc; padding:10px;">';
    for($i=0; $i<count($arr); $i++)
    {   if($i) $output .= ', ';
        $output .= $arr[$i];
    }
    $output .= '</div><br />';
    return $output;
}
add_shortcode('rvg-show-all-tags', 'rvg_show_all_tags');
?>

Note: don’t use the ‘echo’ command but store the output in a variable and return that variable!

See the plugin at work HERE!


WordPress – Adding a new plugin to the WP repository

How to add a new plugin to the WordPress plugin  repository?

Download and install subversion (svn) from:
http://subversion.apache.org/source-code.html

Ask for approval for the new plugin at:
http://wordpress.org/plugins/add/
(upload the zipped version of the plugin)

Directory structure for this example:

wordpress\wp-plugins
     my-new-plugin         (plugin sources)
     my-new-plugin-svn     (subversion data)

After being approved by WordPress (via email), upload the first version of the plugin by opening a command prompt and typing the following lines:

cd c:\wordpress\wp-plugins
svn co http://plugins.svn.wordpress.org/my-new-plugin my-new-plugin-svn
cd my-new-plugin-svn
svn up
copy ..\my-new-plugin\*.* trunk
rem also add subdirs if any!
svn add trunk/*
svn stat
svn cp trunk tags/0.1
svn ci -m "INITIAL RELEASE"

Leave the line ‘svn add trunk/*‘-line out when updating the plugin!

Resources:
http://digwp.com/2010/03/add-plugin-to-wordpress-plugin-repository/
http://wordpress.org/plugins/about/validator/
http://wordpress.org/plugins/about/svn/
http://codex.wordpress.org/Plugin_Submission_and_Promotion