wp_add_inline_script example

get_current_screen()->set_help_sidebar(
    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    '<p>' . __( '<a href="https://wordpress.org/documentation/article/plugins-editor-screen/">Documentation on Editing Plugins</a>' ) . '</p>' .
    '<p>' . __( '<a href="https://developer.wordpress.org/plugins/">Documentation on Writing Plugins</a>' ) . '</p>' .
    '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
);

$settings = array(
    'codeEditor' => wp_enqueue_code_editor( array( 'file' => $real_file ) ),
);
wp_enqueue_script( 'wp-theme-plugin-editor' );
wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) );
wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.themeOrPlugin = "plugin";' ) );

require_once ABSPATH . 'wp-admin/admin-header.php';

update_recently_edited( WP_PLUGIN_DIR . '/' . $file );

if ( ! empty( $posted_content ) ) {
    $content = $posted_content;
} else {
    $content = file_get_contents( $real_file );
}

$editor_settings = get_block_editor_settings(
    array_merge( get_legacy_widget_block_editor_settings(), array( 'styles' => get_block_editor_theme_styles() ) ),
    $block_editor_context
);

// The widgets editor does not support the Block Directory, so don't load any of // its assets. This also prevents 'wp-editor' from being enqueued which we // cannot load in the widgets screen because many widget scripts rely on `wp.editor`. remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );

wp_add_inline_script(
    'wp-edit-widgets',
    sprintf(
        'wp.domReady( function() { wp.editWidgets.initialize( "widgets-editor", %s ); } );',
        wp_json_encode( $editor_settings )
    )
);

// Preload server-registered block schemas. wp_add_inline_script(
    
$message = __( 'Need help putting together your new Privacy Policy page? Check out our guide for recommendations on what content to include, along with policies suggested by your plugins and theme.' );
        $url     = esc_url( admin_url( 'options-privacy.php?tab=policyguide' ) );
        $label   = __( 'View Privacy Policy Guide.' );

        if ( get_current_screen()->is_block_editor() ) {
            wp_enqueue_script( 'wp-notices' );
            $action = array(
                'url'   => $url,
                'label' => $label,
            );
            wp_add_inline_script(
                'wp-notices',
                sprintf(
                    'wp.data.dispatch( "core/notices" ).createWarningNotice( "%s", { actions: [ %s ], isDismissible: false } )',
                    $message,
                    wp_json_encode( $action )
                ),
                'after'
            );
        } else {
            ?> <div class="notice notice-warning inline wp-pp-notice"> <p>
wp_enqueue_style( 'wp-mediaelement' );
        wp_enqueue_script( 'wp-mediaelement' );

        $handle = 'media-audio-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 ),
                wp_json_encode( $exported_schema )
            )
        );

        wp_add_inline_script(
            $handle,
            sprintf(
                
$block_editor_context = new WP_Block_Editor_Context(
                array(
                    'name' => 'core/customize-widgets',
                )
            );

            $editor_settings = get_block_editor_settings(
                get_legacy_widget_block_editor_settings(),
                $block_editor_context
            );

            wp_add_inline_script(
                'wp-customize-widgets',
                sprintf(
                    'wp.domReady( function() { wp.customizeWidgets.initialize( "widgets-customizer", %s ); } );',
                    wp_json_encode( $editor_settings )
                )
            );

            // Preload server-registered block schemas.             wp_add_inline_script(
                
admin_url( 'theme-editor.php' )
            )
        );
        exit;
    }
}

$settings = array(
    'codeEditor' => wp_enqueue_code_editor( compact( 'file' ) ),
);
wp_enqueue_script( 'wp-theme-plugin-editor' );
wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) );
wp_add_inline_script( 'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";' );

require_once ABSPATH . 'wp-admin/admin-header.php';

update_recently_edited( $file );

if ( ! is_file( $file ) ) {
    $error = true;
}

$content = '';
case 'application/javascript':
                case 'application/ld+json':
                case 'text/typescript':
                case 'application/typescript':
                    wp_enqueue_script( 'jshint' );
                    wp_enqueue_script( 'jsonlint' );
                    break;
            }
        }
    }

    wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) );

    /** * Fires when scripts and styles are enqueued for the code editor. * * @since 4.9.0 * * @param array $settings Settings for the enqueued code editor. */
    do_action( 'wp_enqueue_code_editor', $settings );

    return $settings;
}
$settings = wp_enqueue_code_editor(
            array(
                'type'       => 'text/html',
                'codemirror' => array(
                    'indentUnit' => 2,
                    'tabSize'    => 2,
                ),
            )
        );

        wp_enqueue_script( 'custom-html-widgets' );
        wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );

        if ( empty( $settings ) ) {
            $settings = array(
                'disabled' => true,
            );
        }
        wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.init( %s );', wp_json_encode( $settings ) ), 'after' );

        $l10n = array(
            'errorNotice' => array(
                /* translators: %d: Error count. */
                

    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 ),
                wp_json_encode( $exported_schema )
            )
        );

        wp_add_inline_script(
            $handle,
            sprintf(
                


    /** * Loads the required scripts and styles for the widget control. * * @since 4.8.0 */
    public function enqueue_admin_scripts() {
        wp_enqueue_editor();
        wp_enqueue_media();
        wp_enqueue_script( 'text-widgets' );
        wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
        wp_add_inline_script( 'text-widgets', 'wp.textWidgets.init();', 'after' );
    }

    /** * Outputs the Text widget settings form. * * @since 2.8.0 * @since 4.8.0 Form only contains hidden inputs which are synced with JS template. * @since 4.8.1 Restored original form to be displayed when in legacy mode. * * @see WP_Widget_Text::render_control_template_scripts() * @see _WP_Editors::editor() * * @param array $instance Current settings. */

    public function enqueue_admin_scripts() {
        parent::enqueue_admin_scripts();

        $handle = 'media-video-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 ),
                wp_json_encode( $exported_schema )
            )
        );

        wp_add_inline_script(
            $handle,
            sprintf(
                
$preload_data = array_reduce(
        $preload_paths,
        'rest_preload_api_request',
        array()
    );

    // Restore the global $post, $wp_scripts, and $wp_styles as they were before API preloading.     $post       = $backup_global_post;
    $wp_scripts = $backup_wp_scripts;
    $wp_styles  = $backup_wp_styles;

    wp_add_inline_script(
        'wp-api-fetch',
        sprintf(
            'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
            wp_json_encode( $preload_data )
        ),
        'after'
    );
}

/** * Creates an array of theme styles to load into the block editor. * * @since 5.8.0 * * @global array $editor_styles * * @return array An array of theme styles for the block editor. */
/* * Sadly we probably cannot add this data directly into editor settings. * * Some meta boxes need `admin_head` to fire for meta box registry. * `admin_head` fires after `admin_enqueue_scripts`, which is where we create * our editor instance. */
    $script = 'window._wpLoadBlockEditor.then( function() { wp.data.dispatch( \'core/edit-post\' ).setAvailableMetaBoxesPerLocation( ' . wp_json_encode( $meta_boxes_per_location ) . ' ); } );';

    wp_add_inline_script( 'wp-edit-post', $script );

    /* * When `wp-edit-post` is output in the `<head>`, the inline script needs to be manually printed. * Otherwise, meta boxes will not display because inline scripts for `wp-edit-post` * will not be printed again after this point. */
    if ( wp_script_is( 'wp-edit-post', 'done' ) ) {
        printf( "<script type='text/javascript'>\n%s\n</script>\n", trim( $script ) );
    }

    /* * If the 'postcustom' meta box is enabled, then we need to perform * some extra initialization on it. */
                'status[0]' => 'publish',
                'status[1]' => 'draft',
            ),
            $navigation_rest_route
        ),
        'GET',
    ),
);

block_editor_rest_api_preload( $preload_paths$block_editor_context );

wp_add_inline_script(
    'wp-edit-site',
    sprintf(
        'wp.domReady( function() { wp.editSite.initializeEditor( "site-editor", %s ); } );',
        wp_json_encode( $editor_settings )
    )
);

// Preload server-registered block schemas. wp_add_inline_script(
    

    public function enqueue_admin_scripts() {
        parent::enqueue_admin_scripts();

        $handle = 'media-gallery-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', 'items' ) );
        }
        wp_add_inline_script(
            $handle,
            sprintf(
                'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
                wp_json_encode( $this->id_base ),
                wp_json_encode( $exported_schema )
            )
        );

        wp_add_inline_script(
            $handle,
            sprintf(
                
Home | Imprint | This part of the site doesn't use cookies.