'', // Show this when blank. 'label' => '', // Add label. ); /** * Constructor. * * @return void * */ function __construct( $settings, $owner ) { parent::__construct( $settings, $owner ); add_filter( 'mm_generate_css_upload_mobmenu' , array( $this, 'generateCSS' ), 10, 2 ); add_action( 'mm_livepreview_pre_mobmenu' , array( $this, 'preLivePreview' ), 10, 3 ); add_action( 'mm_livepreview_post_mobmenu', array( $this, 'postLivePreview' ), 10, 3 ); } /** * Generates CSS for the font, this is used in MobileMenuCSS. * * @param String $css The CSS generated. * @param MobileMenuOption $option The current option being processed. * @return String The CSS generated. * */ public function generateCSS( $css, $option ) { if ( $this->settings['id'] != $option->settings['id'] ) { return $css; } $value = $this->getValue(); if ( empty( $value ) ) { return $css; } $css .= '$' . $option->settings['id'] . ': url(' . $value . ');'; if ( ! empty( $option->settings['css'] ) ) { // In the css parameter, we accept the term `value` as our current value, // translate it into the SaSS variable for the current option. $css .= str_replace( 'value', '#{$' . $option->settings['id'] . '}', $option->settings['css'] ); } return $css; } /** * The upload option gives out an attachment ID. Live previews will not work since we cannot get. * the upload URL from an ID easily. Use a specially created Ajax Handler for just getting the URL. * * @see tf_file_upload_option_customizer_get_value() */ public function preLivePreview( $optionID, $optionType, $option ) { if ( $optionID != $this->settings['id'] ) { return; } $nonce = wp_create_nonce( 'tf_file_upload_option_nonce' ); ?> wp.ajax.send( 'tf_file_upload_option_customizer_get_value', { data: { nonce: '', id: value }, success: function( data ) { var $ = jQuery; var value = data; settings['id'] ) { return; } // Close the ajax call. ?> } }); echoOptionHeader(); // Display the preview file name. $value = $this->getValue(); if ( ! is_array( $value ) ) { $value = $this->getValue(); } $previewFile = ''; if ( ! empty( $value ) ) { $previewFile = "

". basename( get_attached_file( $value ) ) . "

"; } else { $previewFile = $this->settings['label']; } echo "
" . $previewFile . '
'; printf('', $this->getID(), $this->settings['placeholder'], $this->getID(), esc_attr( $this->getValue() ) ); $this->echoOptionFooter(); } public static function createUploaderScript() { if ( ! self::$firstLoad ) { return; } self::$firstLoad = false; ?>