WP_Widget_Media_Image::enqueue_admin_scripts
Loads the required media files for the media manager and scripts for media widgets.
Method of the class: WP_Widget_Media_Image{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WP_Widget_Media_Image = new WP_Widget_Media_Image(); $WP_Widget_Media_Image->enqueue_admin_scripts();
Changelog
| Since 4.8.0 | Introduced. |
WP_Widget_Media_Image::enqueue_admin_scripts() WP Widget Media Image::enqueue admin scripts code WP 6.9.1
public function enqueue_admin_scripts() {
parent::enqueue_admin_scripts();
$handle = 'media-image-widget';
wp_enqueue_script( $handle );
$exported_schema = array();
foreach ( $this->get_instance_schema() as $field => $field_schema ) {
$exported_schema[ $field ] = wp_array_slice_assoc( $field_schema, array( 'type', 'default', 'enum', 'minimum', 'format', 'media_prop', 'should_preview_update' ) );
}
wp_add_inline_script(
$handle,
sprintf(
'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
wp_json_encode( $exported_schema, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
)
);
wp_add_inline_script(
$handle,
sprintf(
'
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.mime_type = %2$s;
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n = _.extend( {}, wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n, %3$s );
',
wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
wp_json_encode( $this->widget_options['mime_type'], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
wp_json_encode( $this->l10n, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
)
);
}