Codex Wordpress Org Widgets API

December 19, 2016 | Author: ramrayssablue | Category: N/A
Share Embed Donate


Short Description

Download Codex Wordpress Org Widgets API...

Description

Have you taken the WordPress 2013 Survey yet? Search WordPress.org

Showcase

Themes

Plugins

Mobile

Support

Get Involved

About

Blog

Hosting

Codex

Download WordPress

Codex tools: Log in

Widgets API

Home Page WordPress Lessons

Languages: English • Español • 日本語 • 中文(简体) • (Add your language)

Getting Started Working with WordPress

This article is marked as in need of editing. You can help Codex by editing it.

Design and Layout

Widgets API This page contains the technical documentation for the WordPress Widgets API and is written for developers. If you're not a developer you may want to review the Widgets page. In technical terms: a WordPress Widget is a PHP object that echoes string data to STDOUT when its widget() method is called. It's located in wp-includes/widgets.php.

Function Reference

Contents

Advanced Topics

[hide]

Troubleshooting

1 Widgets API 2 Function Reference 3 Developing Widgets

3.2 Example

Codex Resources

3.3 Example With Namespaces

Community portal

4 Displaying Widgets and Widget Areas

6 Independent Widgets

Are you a developer? Try out the HTML to PDF API

About WordPress

3.1 Default Usage

5 Widget Areas

open in browser PRO version

Developer Docs

Current events Recent changes

6.1 Resources

Random page

6.2 Related

Help

pdfcrowd.com

Widget Functions

internal Functions

is_active_widget()

wp_register_widget_control()

the_widget()

wp_unregister_widget_control()

register_widget()

wp_convert_widget_settings()

unregister_widget()

wp_get_widget_defaults() wp_widget_description()

Developing Widgets To create a widget, you only need to extend the standard WP_Widget class and some of its functions. That base class also contains information about the functions that must be extended to get a working widget. The WP_Widget class is located in wp-includes/widgets.php.

Default Usage class My_Widget extends WP_Widget { public function __construct() { // widget actual processes } public function widget( $args, $instance ) { // outputs the content of the widget } public function form( $instance ) { // outputs the options form on admin }

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

public function update( $new_instance, $old_instance ) { // processes widget options to be saved } }

The widget can then be registered using the widgets_init hook:

add_action( 'widgets_init', function(){ register_widget( 'My_Widget' ); });

Example This sample code creates a Widget named Foo_Widget that has a settings form to change the display title.

/** * Adds Foo_Widget widget. */ class Foo_Widget extends WP_Widget { /** * Register widget with WordPress. */ function __construct() { parent::__construct( 'foo_widget', // Base ID 'Foo_Widget', // Name array( 'description' => __( 'A Foo Widget', 'text_domain' ), ) // Args ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

* @param array $instance Saved values from database. */ public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); echo $args['before_widget']; if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title']; echo __( 'Hello, World!', 'text_domain' ); echo $args['after_widget']; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form( $instance ) { if ( isset( $instance[ 'title' ] ) ) { $title = $instance[ 'title' ]; } else { $title = __( 'New title', 'text_domain' ); } ?>
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF