functions.gallery.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Renders extra controls in the Gallery Settings section of the new media UI. |
| 5 | */ |
| 6 | class Jetpack_Gallery_Settings { |
| 7 | function __construct() { |
| 8 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
| 9 | } |
| 10 | |
| 11 | function admin_init() { |
| 12 | $this->gallery_types = apply_filters( 'jetpack_gallery_types', array( 'default' => __( 'Thumbnail Grid', 'jetpack' ) ) ); |
| 13 | |
| 14 | // Enqueue the media UI only if needed. |
| 15 | if ( count( $this->gallery_types ) > 1 ) { |
| 16 | add_action( 'wp_enqueue_media', array( $this, 'wp_enqueue_media' ) ); |
| 17 | add_action( 'print_media_templates', array( $this, 'print_media_templates' ) ); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Registers/enqueues the gallery settings admin js. |
| 23 | */ |
| 24 | function wp_enqueue_media() { |
| 25 | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) |
| 26 | wp_register_script( 'jetpack-gallery-settings', plugins_url( 'gallery-settings/gallery-settings.js', __FILE__ ), array( 'media-views' ), '20121225' ); |
| 27 | |
| 28 | wp_enqueue_script( 'jetpack-gallery-settings' ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Outputs a view template which can be used with wp.media.template |
| 33 | */ |
| 34 | function print_media_templates() { |
| 35 | $default_gallery_type = apply_filters( 'jetpack_default_gallery_type', 'default' ); |
| 36 | |
| 37 | ?> |
| 38 | <script type="text/html" id="tmpl-jetpack-gallery-settings"> |
| 39 | <label class="setting"> |
| 40 | <span><?php _e( 'Type', 'jetpack' ); ?></span> |
| 41 | <select class="type" name="type" data-setting="type"> |
| 42 | <?php foreach ( $this->gallery_types as $value => $caption ) : ?> |
| 43 | <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $default_gallery_type ); ?>><?php echo esc_html( $caption ); ?></option> |
| 44 | <?php endforeach; ?> |
| 45 | </select> |
| 46 | </label> |
| 47 | </script> |
| 48 | <?php |
| 49 | } |
| 50 | } |
| 51 | new Jetpack_Gallery_Settings; |
| 52 |