WordPress how to create a plugin guide


If you advanced WordPress, you should always disconnect your own code and the WordPress core by programming a plugin. Another advantage is, that your crazy plugin can be published very easy in the WordPress Plugin Directory for others.

Follgende carry out steps:

Plugin Name: Name des Plugins
Plugin URI: http:// Plugin Webseite
Description: kurze Beschreibung des Plugin.
Version: Plugin's Versions Nummer, bspw.: 1.0
Author: Name des Plugin Autors
Author URI: http:// Autor URL
License: Lizens bspw. GPL2

The file has to be saved under the following path to be recognized by wordpress::
/wp-content/plugins/{pluginname}/{Plugin}.php

In the plugin section of the backend should now be an inactive plugin with your name.

Connecting between WordPress and the Plugin

Yo ucan simply register for hooks for certain events of the blog, where the plugin

  1. should examine changes, e.g.. is heading to blog articles loaded (Filter-Hook auf the_title)
  2. Or when certain data is generated, as e.g.. der Footer (Action-Hook to wp_footer)
  3. own Template Tags invest, which then "parsed" and the plugin will be taken from the place

A complete list can be found with Hooks here.

For example, if the plug. should generate its own page, you should create pages in the back under a new page and paste it as text only the plugin name in square brackets, e.g.[SuperPlugin] and enter an appropriate title.

Then you have to register lurking on the right hook to load pages and its code and output with echo:

add_shortcode( 'threedeenavigation', 'threeDeeNavigation_convertShortcodeToNavigation' );
function threeDeeNavigation_convertShortcodeToNavigation( $atts ){   
    return "<b>Hallo</b><br>";
}

//add JS and css
add_action('wp_enqueue_scripts', 'enqueue_threedeenavigation_scripts');
function enqueue_threedeenavigation_scripts()
{
    $threeDeeNavigationClass = new threeDeeNavigationClass();
    $categories = get_categories();
    $threeDeeNavigationClass->insertJavascriptAddCategories($categories);
    foreach ($categories as $category) {
    var_dump($categories);
    }
}

 

class threeDeeNavigationClass {

    public function getPluginPath() {
        return trailingslashit(trailingslashit(WP_PLUGIN_URL) . plugin_basename(dirname(__FILE__)));
    }
    public function insertJavascriptAddCategories($categories)
    {
        //http://www.prelovac.com/vladimir/best-practice-for-adding-javascript-code-to-wordpress-plugin
        wp_enqueue_script('threeDeeNavigationScript', $this->getPluginPath() .  'js/threeDeeNavigation.js', array('jquery'));
        wp_localize_script( 'threeDeeNavigationScript', 'threeDeeNavigationData', array(
        'categories' => json_encode($categories)

        ));

    }
}

Bsp for clean passing parameters by WordPress PHP to JavaScript (threeDeeNavigation.js):

//muss bei wordpress so mit rein leider, wegen coflicts mit WordPress, jquery statt mit $("#id").val() mit jQuery("#id").val() nutzen
 console.log("Test Log");
var $j = jQuery.noConflict();

 $j(document).ready(function() {
     categories = threeDeeNavigationData.categories;
     categories = categories.replace(/&quot;/g, '"');
     categories = jQuery.parseJSON(categories);
      console.log(categories);
});
  1. A good tutorial, at least as a first overview. I want to kneel me ever since a long time in this subject in, but somehow I lack the time again and again. There are a few books, really deeply WordPress dealing with the. You describe only the basic things.