functions.gallery.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Renders extra controls in the Gallery Settings section of the new media UI.
  4. */
  5. class Jetpack_Gallery_Settings {
  6. function __construct() {
  7. add_action( 'admin_init', array( $this, 'admin_init' ) );
  8. }
  9. function admin_init() {
  10. /**
  11. * Filter the available gallery types.
  12. *
  13. * @module shortcodes, tiled-gallery
  14. *
  15. * @since 2.5.1
  16. *
  17. * @param array $value Array of the default thumbnail grid gallery type. Default array contains one key, ‘default’.
  18. *
  19. */
  20. $this->gallery_types = apply_filters( 'jetpack_gallery_types', array( 'default' => __( 'Thumbnail Grid', 'jetpack' ) ) );
  21. // Enqueue the media UI only if needed.
  22. if ( count( $this->gallery_types ) > 1 ) {
  23. add_action( 'wp_enqueue_media', array( $this, 'wp_enqueue_media' ) );
  24. add_action( 'print_media_templates', array( $this, 'print_media_templates' ) );
  25. }
  26. }
  27. /**
  28. * Registers/enqueues the gallery settings admin js.
  29. */
  30. function wp_enqueue_media() {
  31. if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) {
  32. /**
  33. * This only happens if we're not in Jetpack, but on WPCOM instead.
  34. * This is the correct path for WPCOM.
  35. */
  36. wp_register_script( 'jetpack-gallery-settings', plugins_url( 'gallery-settings/gallery-settings.js', __FILE__ ), array( 'media-views' ), '20121225' );
  37. }
  38. wp_enqueue_script( 'jetpack-gallery-settings' );
  39. }
  40. /**
  41. * Outputs a view template which can be used with wp.media.template
  42. */
  43. function print_media_templates() {
  44. /**
  45. * Filter the default gallery type.
  46. *
  47. * @module tiled-gallery
  48. *
  49. * @since 2.5.1
  50. *
  51. * @param string $value A string of the gallery type. Default is ‘default’.
  52. *
  53. */
  54. $default_gallery_type = apply_filters( 'jetpack_default_gallery_type', 'default' );
  55. ?>
  56. <script type="text/html" id="tmpl-jetpack-gallery-settings">
  57. <label class="setting">
  58. <span><?php _e( 'Type', 'jetpack' ); ?></span>
  59. <select class="type" name="type" data-setting="type">
  60. <?php foreach ( $this->gallery_types as $value => $caption ) : ?>
  61. <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $default_gallery_type ); ?>><?php echo esc_html( $caption ); ?></option>
  62. <?php endforeach; ?>
  63. </select>
  64. </label>
  65. </script>
  66. <?php
  67. }
  68. }
  69. new Jetpack_Gallery_Settings;