Расширение Медиа Виджета
-
Здравствуйте! Не хочу ставить лишние плагины — по этому решил расширить стандартный медиа виджет изображений. Вот пхп код
class WPLB_Widget_Image extends WP_Widget_Media_Image { function __construct() { parent::__construct(); add_filter( 'widget_media_image_instance_schema', array( $this, 'schema' ) ); } function schema( $schema ) { return array_merge( array( 'template' => array( 'type' => 'string', 'enum' => array( 'default', 'parallax' ), 'default' => 'default', ), ), $schema ); } public function enqueue_admin_scripts() { wp_enqueue_script( 'lazucrub-image-widgets', WPLB_URL . '/js/image-widget.js' ); parent::enqueue_admin_scripts(); } public function render_control_template_scripts() { parent::render_control_template_scripts(); ?> <script type="text/html" id="tmpl-lazucrub-image-setting"> <h2><?php _e( 'Attachment Display Settings' ); ?></h2> <# if ( 'image' === data.type ) { #> <span class="setting align"> <label for="attachment-display-settings-alignment" class="name"><?php _e( 'Alignment' ); ?></label> <select id="attachment-display-settings-alignment" class="alignment" data-setting="align" <# if ( data.userSettings ) { #> data-user-setting="align" <# } #>> <option value="left"> <?php esc_html_e( 'Left' ); ?> </option> <option value="center"> <?php esc_html_e( 'Center' ); ?> </option> <option value="right"> <?php esc_html_e( 'Right' ); ?> </option> <option value="none" selected> <?php esc_html_e( 'None' ); ?> </option> </select> </span> <# } #> <span class="setting"> <label for="attachment-display-settings-link-to" class="name"> <# if ( data.model.canEmbed ) { #> <?php _e( 'Embed or Link' ); ?> <# } else { #> <?php _e( 'Link To' ); ?> <# } #> </label> <select id="attachment-display-settings-link-to" class="link-to" data-setting="link" <# if ( data.userSettings && ! data.model.canEmbed ) { #> data-user-setting="urlbutton" <# } #>> <# if ( data.model.canEmbed ) { #> <option value="embed" selected> <?php esc_html_e( 'Embed Media Player' ); ?> </option> <option value="file"> <# } else { #> <option value="none" selected> <?php esc_html_e( 'None' ); ?> </option> <option value="file"> <# } #> <# if ( data.model.canEmbed ) { #> <?php esc_html_e( 'Link to Media File' ); ?> <# } else { #> <?php esc_html_e( 'Media File' ); ?> <# } #> </option> <option value="post"> <# if ( data.model.canEmbed ) { #> <?php esc_html_e( 'Link to Attachment Page' ); ?> <# } else { #> <?php esc_html_e( 'Attachment Page' ); ?> <# } #> </option> <# if ( 'image' === data.type ) { #> <option value="custom"> <?php esc_html_e( 'Custom URL' ); ?> </option> <# } #> </select> </span> <span class="setting"> <label for="attachment-display-settings-link-to-custom" class="name"><?php _e( 'URL' ); ?></label> <input type="text" id="attachment-display-settings-link-to-custom" class="link-to-custom" data-setting="linkUrl" /> </span> <# if ( 'undefined' !== typeof data.sizes ) { #> <span class="setting"> <label for="attachment-display-settings-size" class="name"><?php _e( 'Size' ); ?></label> <select id="attachment-display-settings-size" class="size" name="size" data-setting="size" <# if ( data.userSettings ) { #> data-user-setting="imgsize" <# } #>> <?php /** This filter is documented in wp-admin/includes/media.php */ $sizes = apply_filters( 'image_size_names_choose', array( 'thumbnail' => __( 'Thumbnail' ), 'medium' => __( 'Medium' ), 'large' => __( 'Large' ), 'full' => __( 'Full Size' ), ) ); foreach ( $sizes as $value => $name ) : ?> <# var size = data.sizes['<?php echo esc_js( $value ); ?>']; if ( size ) { #> <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, 'full' ); ?>> <?php echo esc_html( $name ); ?> – {{ size.width }} × {{ size.height }} </option> <# } #> <?php endforeach; ?> </select> </span> <# } #> <label class="setting template"> <span><?php _e( 'Template' ); ?></span> <select name="temlate" data-setting="template"> <?php $templates = array( 'default' => __( 'Default' ), 'parallax' => __( 'Parallax' ) ); foreach ( $templates as $key => $label ) : ?> <option value="<?php echo esc_attr( $key ); ?>"> <?php echo esc_html( $label ); ?> </option> <?php endforeach; ?> </select> </label> </script> <?php } }
но, что должно быть в image-widget.js не знаю. Цель расширения — заменить стандартные оба блок «НАСТРОЙКИ ОТОБРАЖЕНИЯ ФАЙЛА» на свои настройки. Кто знает как — помогите!
- Тема «Расширение Медиа Виджета» закрыта для новых ответов.