wp_json_encode example

$date_format = get_option( 'date_format' );
        $date_format = preg_replace( '/(?<!\\\\)[Yyo]/', '%1$s', $date_format );
        $date_format = preg_replace( '/(?<!\\\\)[FmMn]/', '%2$s', $date_format );
        $date_format = preg_replace( '/(?<!\\\\)[jd]/', '%3$s', $date_format );

        // Fallback to ISO date format if year, month, or day are missing from the date format.         if ( 1 !== substr_count( $date_format, '%1$s' ) || 1 !== substr_count( $date_format, '%2$s' ) || 1 !== substr_count( $date_format, '%3$s' ) ) {
            $date_format = '%1$s-%2$s-%3$s';
        }
        ?> <# _.defaults( data, <?php echo wp_json_encode( $data ); ?> ); #> <# var idPrefix = _.uniqueId( 'el' ) + '-'; #> <# if ( data.label ) { #> <span class="customize-control-title"> {{ data.label }} </span> <# } #> <div class="customize-control-notifications-container"></div> <# if ( data.description ) { #> <span class="description customize-control-description">{{ data.description }}</span> <# } #> <div class="date-time-fields {{ data.includeTime ? 'includes-time' : '' }}"> <fieldset class="day-row"> <legend class="title-day {{ ! data.includeTime ? 'screen-reader-text' : '' }}">
/** * Display JavaScript on the page. * * @since 3.5.0 */
function options_general_add_js() {
    ?> <script type="text/javascript"> jQuery( function($) { var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(), homeURL = ( <?php echo wp_json_encode( get_home_url() ); ?> || '' ).replace( /^(https?:\/\/)?(www\.)?/, '' ); $( '#blogname' ).on( 'input', function() { var title = $.trim( $( this ).val() ) || homeURL; // Truncate to 40 characters. if ( 40 < title.length ) { title = title.substring( 0, 40 ) + '\u2026'; } $siteName.text( title ); }); $( 'input[name="date_format"]' ).on( 'click', function() { if ( 'date_format_custom_radio' !== $(this).attr( 'id' ) ) $( 'input[name="date_format_custom"]' ).val( $( this ).val() ).closest( 'fieldset' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() ); }); $( 'input[name="date_format_custom"]' ).on( 'click input', function() { $( '#date_format_custom_radio' ).prop( 'checked', true ); }); $( 'input[name="time_format"]' ).on( 'click', function() { if ( 'time_format_custom_radio' !== $(this).attr( 'id' ) ) $( 'input[name="time_format_custom"]' ).val( $( this ).val() ).closest( 'fieldset' ).find( '.example' ).text( $( this ).parent( 'label' ).children( '.format-i18n' ).text() ); }); $( 'input[name="time_format_custom"]' ).on( 'click input', function() { $( '#time_format_custom_radio' ).prop( 'checked', true ); }); $( 'input[name="date_format_custom"], input[name="time_format_custom"]' ).on( 'input', function() { var format = $( this ), fieldset = format.closest( 'fieldset' ), example = fieldset.find( '.example' ), spinner = fieldset.find( '.spinner' ); // Debounce the event callback while users are typing. clearTimeout( $.data( this, 'timer' ) ); $( this ).data( 'timer', setTimeout( function() { // If custom date is not empty. if ( format.val() ) { spinner.addClass( 'is-active' ); $.post( ajaxurl, { action: 'date_format_custom' === format.attr( 'name' ) ? 'date_format' : 'time_format', date : format.val() }, function( d ) { spinner.removeClass( 'is-active' ); example.text( d ); } ); } }, 500 ) ); } ); var languageSelect = $( '#WPLANG' ); $( 'form' ).on( 'submit', function() { /* * Don't show a spinner for English and installed languages, * as there is nothing to download. */ if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) { $( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' ); } }); } ); </script>
array( rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ),
    array( rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' ),
    sprintf( '%s/autosaves?context=edit', $rest_path ),
    '/wp/v2/settings',
    array( '/wp/v2/settings', 'OPTIONS' ),
);

block_editor_rest_api_preload( $preload_paths$block_editor_context );

wp_add_inline_script(
    'wp-blocks',
    sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ),
    'after'
);

/* * Assign initial edits, if applicable. These are not initially assigned to the persisted post, * but should be included in its save payload. */
$initial_edits = array();
$is_new_post   = false;
if ( 'auto-draft' === $post->post_status ) {
    $is_new_post = true;
    
$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(
                ' 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 ); ',
                

function wp_attach_theme_preview_middleware() {
    // Don't allow non-admins to preview themes.     if ( ! current_user_can( 'switch_themes' ) ) {
        return;
    }

    wp_add_inline_script(
        'wp-api-fetch',
        sprintf(
            'wp.apiFetch.use( wp.apiFetch.createThemePreviewMiddleware( %s ) );',
            wp_json_encode( sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ) )
        ),
        'after'
    );
}

/** * Set a JavaScript constant for theme activation. * * Sets the JavaScript global WP_BLOCK_THEME_ACTIVATE_NONCE containing the nonce * required to activate a theme. For use within the site editor. * * @see https://github.com/WordPress/gutenberg/pull/41836. * * @since 6.3.0 * @private */
/** * Adds image HTML to editor. * * @since 2.5.0 * * @param string $html */
function media_send_to_editor( $html ) {
    ?> <script type="text/javascript"> var win = window.dialogArguments || opener || parent || top; win.send_to_editor( <?php echo wp_json_encode( $html ); ?> ); </script> <?php     exit;
}

/** * Saves a file submitted from a POST request and create an attachment post for it. * * @since 2.5.0 * * @param string $file_id Index of the `$_FILES` array that the file was sent. * @param int $post_id The post ID of a post to attach the media item to. Required, but can * be set to 0, creating a media item that has no relationship to a post. * @param array $post_data Optional. Overwrite some of the attachment. * @param array $overrides Optional. Override the wp_handle_upload() behavior. * @return int|WP_Error ID of the attachment or a WP_Error object on failure. */
if ( $switched_locale ) {
            restore_previous_locale();
        }

        $exports = array(
            'partials'       => $partials,
            'renderQueryVar' => self::RENDER_QUERY_VAR,
            'l10n'           => $l10n,
        );

        // Export data to JS.         printf( '<script>var _customizePartialRefreshExports = %s;</script>', wp_json_encode( $exports ) );
    }

    /** * Registers dynamically-created partials. * * @since 4.5.0 * * @see WP_Customize_Manager::add_dynamic_settings() * * @param string[] $partial_ids Array of the partial IDs to add. * @return WP_Customize_Partial[] Array of added WP_Customize_Partial instances. */
if ( $schedule ) {
                $result = wp_reschedule_event( $timestamp$schedule$hook$v['args'], true );

                if ( is_wp_error( $result ) ) {
                    error_log(
                        sprintf(
                            /* translators: 1: Hook name, 2: Error code, 3: Error message, 4: Event data. */
                            __( 'Cron reschedule event error for hook: %1$s, Error code: %2$s, Error message: %3$s, Data: %4$s' ),
                            $hook,
                            $result->get_error_code(),
                            $result->get_error_message(),
                            wp_json_encode( $v )
                        )
                    );

                    /** * Fires when an error happens rescheduling a cron event. * * @since 6.1.0 * * @param WP_Error $result The WP_Error object. * @param string $hook Action hook to execute when the event is run. * @param array $v Event data. */
$response['total_items_i18n'] = sprintf(
                /* translators: Number of items. */
                _n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
                number_format_i18n( $this->_pagination_args['total_items'] )
            );
        }
        if ( isset( $this->_pagination_args['total_pages'] ) ) {
            $response['total_pages']      = $this->_pagination_args['total_pages'];
            $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
        }

        die( wp_json_encode( $response ) );
    }

    /** * Sends required variables to JavaScript land. * * @since 3.1.0 */
    public function _js_vars() {
        $args = array(
            'class'  => get_class( $this ),
            'screen' => array(
                
$nonces       = $wp_customize->get_nonces();
        $request_args = array(
            'nonce'                      => $nonces['save'],
            'customize_changeset_uuid'   => $wp_customize->changeset_uuid(),
            'wp_customize'               => 'on',
            'customize_changeset_status' => 'publish',
        );
        ob_start();
        ?> <?php wp_print_scripts( array( 'wp-util' ) ); ?> <script> wp.ajax.post( 'customize_save', <?php echo wp_json_encode( $request_args ); ?> ); </script> <?php         $script = ob_get_clean();

        wp_die(
            '<h1>' . __( 'Your scheduled changes just published' ) . '</h1>' .
            '<p><a href="' . esc_url( remove_query_arg( 'changeset_uuid' ) ) . '">' . __( 'Customize New Changes' ) . '</a></p>' . $script,
            200
        );
    }

    
if (
        JSON_ERROR_NONE === $json_decoding_error &&
        is_array( $decoded_data ) &&
        isset( $decoded_data['isGlobalStylesUserThemeJSON'] ) &&
        $decoded_data['isGlobalStylesUserThemeJSON']
    ) {
        unset( $decoded_data['isGlobalStylesUserThemeJSON'] );

        $data_to_encode = WP_Theme_JSON::remove_insecure_properties( $decoded_data );

        $data_to_encode['isGlobalStylesUserThemeJSON'] = true;
        return wp_slash( wp_json_encode( $data_to_encode ) );
    }
    return $data;
}

/** * Sanitizes content for allowed HTML tags for post content. * * Post content refers to the page contents of the 'post' type and not `$_POST` * data from forms. * * This function expects unslashed data. * * @since 2.9.0 * * @param string $data Post content to filter. * @return string Filtered post content with allowed HTML tags and attributes intact. */

            'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(),
        );

        foreach ( $settings['registeredWidgets'] as &$registered_widget ) {
            unset( $registered_widget['callback'] ); // May not be JSON-serializeable.         }

        $wp_scripts->add_data(
            'customize-widgets',
            'data',
            sprintf( 'var _wpCustomizeWidgetsSettings = %s;', wp_json_encode( $settings ) )
        );

        /* * TODO: Update 'wp-customize-widgets' to not rely so much on things in * 'customize-widgets'. This will let us skip most of the above and not * enqueue 'customize-widgets' which saves bytes. */

        if ( wp_use_widgets_block_editor() ) {
            $block_editor_context = new WP_Block_Editor_Context(
                array(
                    


    /** * 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. */
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 = '';
$classes .= ' hidden';
            }

            printf( '<td class="%s" data-colname="%s">', esc_attr( $classes )esc_attr( wp_strip_all_tags( $display_name ) ) );

            switch ( $column_name ) {
                case 'name':
                    echo '{{ data.name }}';
                    break;
                case 'created':
                    // JSON encoding automatically doubles backslashes to ensure they don't get lost when printing the inline JS.                     echo '<# print( wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ', data.created ) ) #>';
                    break;
                case 'last_used':
                    echo '<# print( data.last_used !== null ? wp.date.dateI18n( ' . wp_json_encode( __( 'F j, Y' ) ) . ", data.last_used ) : '—' ) #>";
                    break;
                case 'last_ip':
                    echo "{{ data.last_ip || '—' }}";
                    break;
                case 'revoke':
                    printf(
                        '<button type="button" class="button delete" aria-label="%1$s">%2$s</button>',
                        /* translators: %s: the application password's given name. */
                        
Home | Imprint | This part of the site doesn't use cookies.