Make WordPress Core

Ticket #25618: test-control.php

File test-control.php, 1.4 KB (added by westonruter, 12 years ago)

Customizer Control which demonstrates patched fix

Line 
1<?php
2/**
3 * Drop into mu-plugins to test Media Manager in Customizer
4 * @link https://core.trac.wordpress.org/ticket/25618
5 */
6
7require_once ABSPATH . WPINC . '/class-wp-customize-control.php';
8
9add_action( 'customize_register', function ( $wp_customize ) {
10
11        $wp_customize->add_section( 'test', array(
12                'title' => 'Test',
13        ) );
14
15        $wp_customize->add_setting(
16                'media_manager',
17                array(
18                        'type' => 'option',
19                        'capability' => 'edit_theme_options',
20                        'transport' => 'refresh',
21                )
22        );
23        $control = new WP_Media_Manager_Control(
24                $wp_customize,
25                'media_manager',
26                array(
27                        'section' => 'test',
28                        'label' => 'Media Manager',
29                )
30        );
31        $wp_customize->add_control( $control );
32
33} );
34
35class WP_Media_Manager_Control extends WP_Customize_Control {
36        public $type = 'media_manager';
37
38        public function enqueue() {
39                wp_enqueue_media();
40        }
41
42        public function render_content() {
43                ?>
44                <label>
45                        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
46                        <div class="customize-control-content">
47                                <button id="temp-click-me" type="button" class='button'>Open Media Manager</button>
48                                <script>
49                                jQuery(function ($) {
50                                        $('#temp-click-me').click(function () {
51                                                var manager = wp.media({
52                                                        frame: 'select',
53                                                        title: 'Test',
54                                                        button: {
55                                                                text: 'Test'
56                                                        }
57                                                })
58                                                manager.open();
59                                        });
60                                });
61                                </script>
62                        </div>
63                </label>
64        <?php
65        }
66}