background preloader

Writing a Plugin

Writing a Plugin
Languages: English • العربية • বাংলা • Español • Italiano • a Plugin 日本語 한국어 • Português do Brasil • Русский • ไทย • 中文(简体) • (Add your language) WordPress Plugins allow you to easily modify, customize, and enhance a WordPress site. Instead of changing the core program code of WordPress, you can add functionality with WordPress Plugins. Here is a basic definition. A WordPress Plugin is a program or a set of one or more functions written in the PHP scripting language, that adds a specific set of features or services to the WordPress site. Wish that WordPress had some new or modified functionality? This article assumes you are already familiar with the basic functionality of WordPress and with PHP programming. Resources To understand how WordPress Plugins work and how to install them on your WordPress blog, see Plugins. This section of the article goes through the steps you need to follow – and some things you need to to consider – when creating a well-structured WordPress Plugin. Plugin Name

Managing Plugins Managing Plugins Languages: English • Français • 日本語 • Português do Brasil • 中文(简体) • (Add your language) WordPress Plugins are composed of php scripts that extend the functionality of WordPress. They offer new additions to your blog that either enhance features that were already available or add otherwise unavailable new features to your site. The majority of WordPress users don't require Plugins, or only require a few, such as Plugins dealing with comment spam or customized post listings. Other users enjoy the varied options Plugins provide such as frequently updated weather reports, post word counts, rating systems, and more. Plugins available via the WordPress Plugins Directory site are designed by volunteers and are usually free to the public. If you want to develop your own Plugins, there is a comprehensive list of resources at Plugin Resources. Finding Plugins Plugin Compatibility and Updates Installing Plugins Automatic Plugin Installation WordPress Plugins Panel Plugin Favorites <?

7 Simple Rules: WordPress Plugin Development Best Practices We've been talking a lot about "Best Practices" here on Wptuts lately. Today, we'll cover some important best practices for creating a WordPress plugin. From security tips to namespacing tricks, follow these rules and you'll do no wrong. Whether you're a budding new plugin developer or a time-tested veteran, these simple rules and suggestions will make you a better developer (and the community will thank you for it!) Rule 01: Have a Strategy Yes, a strategy. Is my plugin just for fun/demonstration purposes or for everyday use in the real world? These questions are important because they impact on how seriously you need to take issues such as coding standards, updates, security, support and documentation. Rule 02: Use Consistent and Clear Coding Standards Which do you prefer, this? Or this? Simple things like consistent spacing, indenting, informative variable naming and succinct comments are a good place to start. Use Namespacing Rule 03: Take Security Seriously Sanitize inputs, escape outputs

Plugin API Plugin API Languages: বাংলা • English • Español • Français • 日本語 • 한국어 • Português do Brasil • ไทย • 中文(简体) • Русский • (Add your language) Introduction This page documents the API (Application Programming Interface) hooks available to WordPress plugin developers, and how to use them. This article assumes you have already read Writing a Plugin, which gives an overview (and many details) of how to develop a plugin. These hooks may also be used in themes, as described here. Hooks, Actions and Filters Hooks are provided by WordPress to allow your plugin to 'hook into' the rest of WordPress; that is, to call functions in your plugin at specific times, and thereby set your plugin in motion. You can sometimes accomplish the same goal with either an action or a filter. For a thorough listing of all action and filter hooks in WP see Adam Brown's WordPress Hooks Database. Function Reference Actions Modify database data. The basic steps to make this happen (described in more detail below) are: where:

Advertisement Plugins are a major part of why WordPress powers millions of blogs and websites around the world. The ability to extend WordPress to meet just about any need is a powerful motivator for choosing WordPress over other alternatives. Having written several plugins myself, I’ve come to learn many (but certainly not all) of the ins-and-outs of WordPress plugin development, and this article is a culmination of the things I think every WordPress plugin developer should know. Oh, and keep in mind everything you see here is compatible with WordPress 3.0+. Don’t Develop Without Debugging The first thing you should do when developing a WordPress plugin is to enable debugging, and I suggest leaving it on the entire time you’re writing plugin code. Enabling debugging also turns on WordPress notices, which is important because that’s how you’ll know if you’re using any deprecated functions. How to Enable Debugging define('WP_DEBUG', false); Replace that line with the following: if (! if (!

Creating Tables with Plugins Creating Tables with Plugins Languages: English • 日本語 • Русский • (Add your language) If you are writing a plugin for WordPress, you will almost certainly find that you need to store some information in the WordPress database. There are two types of information you could store: Setup information -- user choices that are entered when the user first sets up your plugin, and don't tend to grow much beyond that (for example, in a tag-related plugin, the user's choices regarding the format of the tag cloud in the sidebar).Setup information will generally be stored using the WordPress options mechanism. This article describes how to have your plugin automatically create a MySQL table to store its data. So, it is recommended that you follow the steps below to have your plugin automatically create its database tables: Write a PHP function that creates the table. Create Database Tables Database Table Prefix In the wp-config.php file, a WordPress site owner can define a database table prefix.

Créer un thème de A à Z - Tutoriel WordPress Function Reference/wpdb Class Languages: English • Italiano • 日本語 • Русский • 中文(简体) • 中文(繁體) • (Add your language) Talking to the Database: The wpdb Class WordPress defines a class called wpdb, which contains a set of functions used to interact with a database. Its primary purpose is to provide an interface with the WordPress database, but can be used to communicate with any other appropriate database. Using the $wpdb Object Warning: Methods in the wpdb() class should not be called directly. WordPress provides a global object variable, $wpdb, which is an instantiation of the wpdb class defined in /wp-includes/wp-db.php. // 1st Method - Declaring $wpdb as global and using it to execute an SQL query statement that returns a PHP object global $wpdb; $results = $wpdb->get_results( 'SELECT * FROM wp_options WHERE option_id = 1', OBJECT ); // 2nd Method - Utilizing the $GLOBALS superglobal. $myrows = $wpdb->get_results( "SELECT id, name FROM mytable" ); A Warning SELECT a Variable <? query (string) The query you wish to run. <?

WordPress hooks database - action and filter hooks for wp plugin developers -- Adam Brown, BYU Political Science What is a hook? In brief, WordPress hooks enable you to change how WordPress behaves without editing any core files. Because you leave the WordPress files untouched, you can painlessly upgrade your blog with each new version of WordPress. If you don't know what WordPress hooks are for, read the Plugin API or this tutorial. What is this directory? If you're a plugin or theme developer, you know how difficult it can be to figure out which hooks are available. What is this good for? See what new hooks are available with each new version of WordPress See which hooks have been deprecated or renamed (use the "view all hooks" option) Easily learn exactly which WP file(s) use each hook. How to help? Update and improve the official action and filter references.

Related: