Make WordPress Core

Ticket #26633: demo-plugin-19910.php

File demo-plugin-19910.php, 2.0 KB (added by westonruter, 13 years ago)

Plugin which demonstrates the keyboard-accessibility problem

Line 
1<?php
2/**
3 * Plugin Name: Demo Plugin for #26633
4 * Description: Registers a new setting for a non-scalar value (i.e. an assoc array) and a control which allows the setting to be updated by pressing a button.
5 * Author: Weston Ruter, X-Team
6 * Author URI: http://x-team.com/profile/weston-ruter/
7 */
8
9function wp26633_customize_register( $wp_customize ) {
10
11 class WP26633_Customize_Control extends WP_Customize_Control {
12
13 public $type = 'wp26633';
14 public $label = 'Click Count';
15
16 public function render_content() {
17 ?>
18 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
19 <div class="customize-control-content">
20 <p>
21 <span class="click-count"></span>
22 </p>
23 <p>
24 <a href="#" class=button>a.button</a>
25 </p>
26 <p>
27 <button class=button type=button>button[type=button]</button>
28 </p>
29 <p>
30 <input class=button type=button value="input[type=button]">
31 </p>
32 </div>
33 <?php
34 }
35 }
36
37 $wp_customize->add_section( 'wp26633', array(
38 'title' => '#26633',
39 ) );
40
41 $wp_customize->add_setting( 'wp26633', array(
42 'default' => 0,
43 'transport' => 'postMessage',
44 ) );
45
46 $control = new WP26633_Customize_Control(
47 $wp_customize,
48 'wp26633',
49 array(
50 'section' => 'wp26633',
51 )
52 );
53
54 $wp_customize->add_control( $control );
55 add_action( 'customize_controls_print_footer_scripts', 'wp26633_control_js' );
56}
57
58add_action( 'customize_register', 'wp26633_customize_register' );
59
60
61function wp26633_control_js() {
62 wp_print_scripts( array( 'jquery', 'customize-controls' ) );
63 ?>
64 <script>
65 (function() {
66 wp.customize.controlConstructor.wp26633 = wp.customize.Control.extend({
67 ready: function() {
68 var control = this;
69 control.container.find( '.button, button' ).on( 'click', function () {
70 var count = control.setting();
71 count += 1;
72 control.setting( count );
73 } );
74 control.setting.bind( function ( to ) {
75 control.container.find( '.click-count' ).text( to );
76 } );
77 control.container.find( '.click-count' ).text( control.setting() );
78 }
79 });
80 }());
81 </script>
82 <?php
83}