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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * @var string
  22. */
  23. public $type = 'background_position';
  24. /**
  25. * Don't render the control content from PHP, as it's rendered via JS on load.
  26. *
  27. * @since 4.7.0
  28. */
  29. public function render_content() {}
  30. /**
  31. * Render a JS template for the content of the position control.
  32. *
  33. * @since 4.7.0
  34. */
  35. public function content_template() {
  36. $options = array(
  37. array(
  38. 'left top' => array(
  39. 'label' => __( 'Top Left' ),
  40. 'icon' => 'dashicons dashicons-arrow-left-alt',
  41. ),
  42. 'center top' => array(
  43. 'label' => __( 'Top' ),
  44. 'icon' => 'dashicons dashicons-arrow-up-alt',
  45. ),
  46. 'right top' => array(
  47. 'label' => __( 'Top Right' ),
  48. 'icon' => 'dashicons dashicons-arrow-right-alt',
  49. ),
  50. ),
  51. array(
  52. 'left center' => array(
  53. 'label' => __( 'Left' ),
  54. 'icon' => 'dashicons dashicons-arrow-left-alt',
  55. ),
  56. 'center center' => array(
  57. 'label' => __( 'Center' ),
  58. 'icon' => 'background-position-center-icon',
  59. ),
  60. 'right center' => array(
  61. 'label' => __( 'Right' ),
  62. 'icon' => 'dashicons dashicons-arrow-right-alt',
  63. ),
  64. ),
  65. array(
  66. 'left bottom' => array(
  67. 'label' => __( 'Bottom Left' ),
  68. 'icon' => 'dashicons dashicons-arrow-left-alt',
  69. ),
  70. 'center bottom' => array(
  71. 'label' => __( 'Bottom' ),
  72. 'icon' => 'dashicons dashicons-arrow-down-alt',
  73. ),
  74. 'right bottom' => array(
  75. 'label' => __( 'Bottom Right' ),
  76. 'icon' => 'dashicons dashicons-arrow-right-alt',
  77. ),
  78. ),
  79. );
  80. ?>
  81. <# if ( data.label ) { #>
  82. <span class="customize-control-title">{{{ data.label }}}</span>
  83. <# } #>
  84. <# if ( data.description ) { #>
  85. <span class="description customize-control-description">{{{ data.description }}}</span>
  86. <# } #>
  87. <div class="customize-control-content">
  88. <fieldset>
  89. <legend class="screen-reader-text"><span><?php _e( 'Image Position' ); ?></span></legend>
  90. <div class="background-position-control">
  91. <?php foreach ( $options as $group ) : ?>
  92. <div class="button-group">
  93. <?php foreach ( $group as $value => $input ) : ?>
  94. <label>
  95. <input class="ui-helper-hidden-accessible" name="background-position" type="radio" value="<?php echo esc_attr( $value ); ?>">
  96. <span class="button display-options position"><span class="<?php echo esc_attr( $input['icon'] ); ?>" aria-hidden="true"></span></span>
  97. <span class="screen-reader-text"><?php echo $input['label']; ?></span>
  98. </label>
  99. <?php endforeach; ?>
  100. </div>
  101. <?php endforeach; ?>
  102. </div>
  103. </fieldset>
  104. </div>
  105. <?php
  106. }
  107. }