Site_Logo_Image_Control

Custom logo uploader control for the Customizer.

Defined (1)

The class is defined in the following location(s).

/core/third-party/site-logo/inc/class-site-logo-control.php  
  1. class Site_Logo_Image_Control extends WP_Customize_Control { 
  2. /** 
  3. * Constructor for our custom control. 
  4. * @param object $wp_customize 
  5. * @param string $control_id 
  6. * @param array $args 
  7. * @uses Site_Logo_Image_Control::l10n() 
  8. */ 
  9. public function __construct( $wp_customize, $control_id, $args = array() ) { 
  10. // declare these first so they can be overridden 
  11. $this->l10n = array( 
  12. 'upload' => __( 'Add logo', 'layerswp' ),  
  13. 'set' => __( 'Set as logo', 'layerswp' ),  
  14. 'choose' => __( 'Choose logo', 'layerswp' ),  
  15. 'change' => __( 'Change logo', 'layerswp' ),  
  16. 'remove' => __( 'Remove logo', 'layerswp' ),  
  17. 'placeholder' => __( 'No logo set', 'layerswp' ),  
  18. ); 
  19.  
  20. parent::__construct( $wp_customize, $control_id, $args ); 
  21.  
  22. /** 
  23. * This will be critical for our JS constructor. 
  24. */ 
  25. public $type = 'site_logo'; 
  26.  
  27. /** 
  28. * Allows overriding of global labels by a specific control. 
  29. */ 
  30. public $l10n = array(); 
  31.  
  32. /** 
  33. * The type of files that should be allowed by the media modal. 
  34. */ 
  35. public $mime_type = 'image'; 
  36.  
  37. /** 
  38. * Enqueue our media manager resources, scripts, and styles. 
  39. * @uses wp_enqueue_media() 
  40. * @uses wp_enqueue_style() 
  41. * @uses wp_enqueue_script() 
  42. * @uses plugins_url() 
  43. */ 
  44. public function enqueue() { 
  45. // Enqueues all needed media resources. 
  46. wp_enqueue_media(); 
  47.  
  48. // Enqueue our control script and styles. 
  49. wp_enqueue_style( 'site-logo-control', LAYERS_TEMPLATE_URI . '/core/third-party/site-logo/css/site-logo-control.css' ); 
  50. wp_enqueue_script( 'site-logo-control', LAYERS_TEMPLATE_URI . '/core/third-party/site-logo/js/site-logo-control.js', array( 'media-views', 'customize-controls', 'underscore' ), '', true ); 
  51.  
  52. /** 
  53. * Check if we have an active site logo. 
  54. * @uses get_option() 
  55. * @return boolean 
  56. */ 
  57. public function has_site_logo() { 
  58. $logo = get_option( 'site_logo' ); 
  59.  
  60. if ( empty( $logo['url'] ) ) { 
  61. return false; 
  62. } else { 
  63. return true; 
  64.  
  65. /** 
  66. * Display our custom control in the Customizer. 
  67. * @uses Site_Logo_Image_Control::l10n() 
  68. * @uses Site_Logo_Image_Control::mime_type() 
  69. * @uses Site_Logo_Image_Control::label() 
  70. * @uses Site_Logo_Image_Control::description() 
  71. * @uses esc_attr() 
  72. * @uses esc_html() 
  73. */ 
  74. public function render_content() { 
  75. // We do this to allow the upload control to specify certain labels 
  76. $l10n = json_encode( $this->l10n ); 
  77.  
  78. // Control title 
  79. printf( 
  80. '<span class="customize-control-title" data-l10n="%s" data-mime="%s">%s</span>',  
  81. esc_attr( $l10n ),  
  82. esc_attr( $this->mime_type ),  
  83. esc_html( $this->label ) 
  84. ); 
  85.  
  86. // Control description 
  87. if ( ! empty( $this->description ) ) : ?> 
  88. <span class="description customize-control-description"><?php echo $this->description; ?></span> 
  89. <?php endif; ?> 
  90.  
  91. <div class="current"></div> 
  92. <div class="actions"></div> 
  93. <?php }