class-wp-customize-background-position-control.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Customize API: WP_Customize_Background_Position_Control class
  4. *
  5. * @package WordPress
  6. * @subpackage Customize
  7. * @since 4.7.0
  8. */
  9. /**
  10. * Customize Background Position Control class.
  11. *
  12. * @since 4.7.0
  13. *
  14. * @see WP_Customize_Control
  15. */
  16. class WP_Customize_Background_Position_Control extends WP_Customize_Control {
  17. /**
  18. * Type.
  19. *
  20. * @since 4.7.0
  21. * @access public
  22. * @var string
  23. */
  24. public $type = 'background_position';
  25. /**
  26. * Don't render the control content from PHP, as it's rendered via JS on load.
  27. *
  28. * @since 4.7.0
  29. * @access public
  30. */
  31. public function render_content() {}
  32. /**
  33. * Render a JS template for the content of the position control.
  34. *
  35. * @since 4.7.0
  36. * @access public
  37. */
  38. public function content_template() {
  39. $options = array(
  40. array(
  41. 'left top' => array( 'label' => __( 'Top Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ),
  42. 'center top' => array( 'label' => __( 'Top' ), 'icon' => 'dashicons dashicons-arrow-up-alt' ),
  43. 'right top' => array( 'label' => __( 'Top Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ),
  44. ),
  45. array(
  46. 'left center' => array( 'label' => __( 'Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ),
  47. 'center center' => array( 'label' => __( 'Center' ), 'icon' => 'background-position-center-icon' ),
  48. 'right center' => array( 'label' => __( 'Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ),
  49. ),
  50. array(
  51. 'left bottom' => array( 'label' => __( 'Bottom Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ),
  52. 'center bottom' => array( 'label' => __( 'Bottom' ), 'icon' => 'dashicons dashicons-arrow-down-alt' ),
  53. 'right bottom' => array( 'label' => __( 'Bottom Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ),
  54. ),
  55. );
  56. ?>
  57. <# if ( data.label ) { #>
  58. <span class="customize-control-title">{{{ data.label }}}</span>
  59. <# } #>
  60. <# if ( data.description ) { #>
  61. <span class="description customize-control-description">{{{ data.description }}}</span>
  62. <# } #>
  63. <div class="customize-control-content">
  64. <fieldset>
  65. <legend class="screen-reader-text"><span><?php _e( 'Image Position' ); ?></span></legend>
  66. <div class="background-position-control">
  67. <?php foreach ( $options as $group ) : ?>
  68. <div class="button-group">
  69. <?php foreach ( $group as $value => $input ) : ?>
  70. <label>
  71. <input class="screen-reader-text" name="background-position" type="radio" value="<?php echo esc_attr( $value ); ?>">
  72. <span class="button display-options position"><span class="<?php echo esc_attr( $input['icon'] ); ?>" aria-hidden="true"></span></span>
  73. <span class="screen-reader-text"><?php echo $input['label']; ?></span>
  74. </label>
  75. <?php endforeach; ?>
  76. </div>
  77. <?php endforeach; ?>
  78. </div>
  79. </fieldset>
  80. </div>
  81. <?php
  82. }
  83. }