Edit File by line
/home/zeestwma/richards.../wp-admin
File: site-editor.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Site Editor administration screen.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
global $editor_styles;
[8] Fix | Delete
[9] Fix | Delete
/** WordPress Administration Bootstrap */
[10] Fix | Delete
require_once __DIR__ . '/admin.php';
[11] Fix | Delete
[12] Fix | Delete
if ( ! current_user_can( 'edit_theme_options' ) ) {
[13] Fix | Delete
wp_die(
[14] Fix | Delete
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
[15] Fix | Delete
'<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
[16] Fix | Delete
403
[17] Fix | Delete
);
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Maps old site editor urls to the new updated ones.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 6.8.0
[24] Fix | Delete
* @access private
[25] Fix | Delete
*
[26] Fix | Delete
* @global string $pagenow The filename of the current screen.
[27] Fix | Delete
*
[28] Fix | Delete
* @return string|false The new URL to redirect to, or false if no redirection is needed.
[29] Fix | Delete
*/
[30] Fix | Delete
function _wp_get_site_editor_redirection_url() {
[31] Fix | Delete
global $pagenow;
[32] Fix | Delete
if ( 'site-editor.php' !== $pagenow || isset( $_REQUEST['p'] ) || empty( $_SERVER['QUERY_STRING'] ) ) {
[33] Fix | Delete
return false;
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
// The following redirects are for the new permalinks in the site editor.
[37] Fix | Delete
if ( isset( $_REQUEST['postType'] ) && 'wp_navigation' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) {
[38] Fix | Delete
return add_query_arg( array( 'p' => '/wp_navigation/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) );
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
if ( isset( $_REQUEST['postType'] ) && 'wp_navigation' === $_REQUEST['postType'] && empty( $_REQUEST['postId'] ) ) {
[42] Fix | Delete
return add_query_arg( array( 'p' => '/navigation' ), remove_query_arg( 'postType' ) );
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
if ( isset( $_REQUEST['path'] ) && '/wp_global_styles' === $_REQUEST['path'] ) {
[46] Fix | Delete
return add_query_arg( array( 'p' => '/styles' ), remove_query_arg( 'path' ) );
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
if ( isset( $_REQUEST['postType'] ) && 'page' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) {
[50] Fix | Delete
return add_query_arg( array( 'p' => '/page' ), remove_query_arg( 'postType' ) );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
if ( isset( $_REQUEST['postType'] ) && 'page' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) {
[54] Fix | Delete
return add_query_arg( array( 'p' => '/page/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) );
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
if ( isset( $_REQUEST['postType'] ) && 'wp_template' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) {
[58] Fix | Delete
return add_query_arg( array( 'p' => '/template' ), remove_query_arg( 'postType' ) );
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
if ( isset( $_REQUEST['postType'] ) && 'wp_template' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) {
[62] Fix | Delete
return add_query_arg( array( 'p' => '/wp_template/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) );
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
if ( isset( $_REQUEST['postType'] ) && 'wp_block' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) {
[66] Fix | Delete
return add_query_arg( array( 'p' => '/pattern' ), remove_query_arg( 'postType' ) );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
if ( isset( $_REQUEST['postType'] ) && 'wp_block' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) {
[70] Fix | Delete
return add_query_arg( array( 'p' => '/wp_block/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
if ( isset( $_REQUEST['postType'] ) && 'wp_template_part' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) {
[74] Fix | Delete
return add_query_arg( array( 'p' => '/pattern' ) );
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
if ( isset( $_REQUEST['postType'] ) && 'wp_template_part' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) {
[78] Fix | Delete
return add_query_arg( array( 'p' => '/wp_template_part/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
// The following redirects are for backward compatibility with the old site editor URLs.
[82] Fix | Delete
if ( isset( $_REQUEST['path'] ) && '/wp_template_part/all' === $_REQUEST['path'] ) {
[83] Fix | Delete
return add_query_arg(
[84] Fix | Delete
array(
[85] Fix | Delete
'p' => '/pattern',
[86] Fix | Delete
'postType' => 'wp_template_part',
[87] Fix | Delete
),
[88] Fix | Delete
remove_query_arg( 'path' )
[89] Fix | Delete
);
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
if ( isset( $_REQUEST['path'] ) && '/page' === $_REQUEST['path'] ) {
[93] Fix | Delete
return add_query_arg( array( 'p' => '/page' ), remove_query_arg( 'path' ) );
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
if ( isset( $_REQUEST['path'] ) && '/wp_template' === $_REQUEST['path'] ) {
[97] Fix | Delete
return add_query_arg( array( 'p' => '/template' ), remove_query_arg( 'path' ) );
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
if ( isset( $_REQUEST['path'] ) && '/patterns' === $_REQUEST['path'] ) {
[101] Fix | Delete
return add_query_arg( array( 'p' => '/pattern' ), remove_query_arg( 'path' ) );
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
if ( isset( $_REQUEST['path'] ) && '/navigation' === $_REQUEST['path'] ) {
[105] Fix | Delete
return add_query_arg( array( 'p' => '/navigation' ), remove_query_arg( 'path' ) );
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
return add_query_arg( array( 'p' => '/' ) );
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
// Redirect to the site editor to the new URLs if needed.
[112] Fix | Delete
$redirection = _wp_get_site_editor_redirection_url();
[113] Fix | Delete
if ( false !== $redirection ) {
[114] Fix | Delete
wp_safe_redirect( $redirection );
[115] Fix | Delete
exit;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
// Used in the HTML title tag.
[119] Fix | Delete
$title = _x( 'Editor', 'site editor title tag' );
[120] Fix | Delete
$parent_file = 'themes.php';
[121] Fix | Delete
[122] Fix | Delete
// Flag that we're loading the block editor.
[123] Fix | Delete
$current_screen = get_current_screen();
[124] Fix | Delete
$current_screen->is_block_editor( true );
[125] Fix | Delete
[126] Fix | Delete
// Default to is-fullscreen-mode to avoid jumps in the UI.
[127] Fix | Delete
add_filter(
[128] Fix | Delete
'admin_body_class',
[129] Fix | Delete
static function ( $classes ) {
[130] Fix | Delete
return "$classes is-fullscreen-mode";
[131] Fix | Delete
}
[132] Fix | Delete
);
[133] Fix | Delete
[134] Fix | Delete
$indexed_template_types = array();
[135] Fix | Delete
foreach ( get_default_block_template_types() as $slug => $template_type ) {
[136] Fix | Delete
$template_type['slug'] = (string) $slug;
[137] Fix | Delete
$indexed_template_types[] = $template_type;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
$context_settings = array( 'name' => 'core/edit-site' );
[141] Fix | Delete
[142] Fix | Delete
if ( ! empty( $_GET['postId'] ) && is_numeric( $_GET['postId'] ) ) {
[143] Fix | Delete
$context_settings['post'] = get_post( (int) $_GET['postId'] );
[144] Fix | Delete
} elseif ( isset( $_GET['p'] ) && preg_match( '/^\/page\/(\d+)$/', $_GET['p'], $matches ) ) {
[145] Fix | Delete
$context_settings['post'] = get_post( (int) $matches[1] );
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
$block_editor_context = new WP_Block_Editor_Context( $context_settings );
[149] Fix | Delete
$custom_settings = array(
[150] Fix | Delete
'siteUrl' => site_url(),
[151] Fix | Delete
'postsPerPage' => get_option( 'posts_per_page' ),
[152] Fix | Delete
'styles' => get_block_editor_theme_styles(),
[153] Fix | Delete
'defaultTemplateTypes' => $indexed_template_types,
[154] Fix | Delete
'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(),
[155] Fix | Delete
'supportsLayout' => wp_theme_has_theme_json(),
[156] Fix | Delete
'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ),
[157] Fix | Delete
);
[158] Fix | Delete
[159] Fix | Delete
// Add additional back-compat patterns registered by `current_screen` et al.
[160] Fix | Delete
$custom_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true );
[161] Fix | Delete
$custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true );
[162] Fix | Delete
[163] Fix | Delete
$editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context );
[164] Fix | Delete
[165] Fix | Delete
if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) {
[166] Fix | Delete
$post_type = get_post_type_object( $_GET['postType'] );
[167] Fix | Delete
if ( ! $post_type ) {
[168] Fix | Delete
wp_die( __( 'Invalid post type.' ) );
[169] Fix | Delete
}
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
[173] Fix | Delete
$active_theme = get_stylesheet();
[174] Fix | Delete
[175] Fix | Delete
$navigation_rest_route = rest_get_route_for_post_type_items(
[176] Fix | Delete
'wp_navigation'
[177] Fix | Delete
);
[178] Fix | Delete
[179] Fix | Delete
$preload_paths = array(
[180] Fix | Delete
array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ),
[181] Fix | Delete
array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ),
[182] Fix | Delete
'/wp/v2/types?context=view',
[183] Fix | Delete
'/wp/v2/types/wp_template?context=edit',
[184] Fix | Delete
'/wp/v2/types/wp_template_part?context=edit',
[185] Fix | Delete
'/wp/v2/templates?context=edit&per_page=-1',
[186] Fix | Delete
'/wp/v2/template-parts?context=edit&per_page=-1',
[187] Fix | Delete
'/wp/v2/themes?context=edit&status=active',
[188] Fix | Delete
'/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit',
[189] Fix | Delete
array( '/wp/v2/global-styles/' . $active_global_styles_id, 'OPTIONS' ),
[190] Fix | Delete
'/wp/v2/global-styles/themes/' . $active_theme . '?context=view',
[191] Fix | Delete
'/wp/v2/global-styles/themes/' . $active_theme . '/variations?context=view',
[192] Fix | Delete
array( $navigation_rest_route, 'OPTIONS' ),
[193] Fix | Delete
array(
[194] Fix | Delete
add_query_arg(
[195] Fix | Delete
array(
[196] Fix | Delete
'context' => 'edit',
[197] Fix | Delete
'per_page' => 100,
[198] Fix | Delete
'order' => 'desc',
[199] Fix | Delete
'orderby' => 'date',
[200] Fix | Delete
// array indices are required to avoid query being encoded and not matching in cache.
[201] Fix | Delete
'status[0]' => 'publish',
[202] Fix | Delete
'status[1]' => 'draft',
[203] Fix | Delete
),
[204] Fix | Delete
$navigation_rest_route
[205] Fix | Delete
),
[206] Fix | Delete
'GET',
[207] Fix | Delete
),
[208] Fix | Delete
'/wp/v2/settings',
[209] Fix | Delete
array( '/wp/v2/settings', 'OPTIONS' ),
[210] Fix | Delete
// Used by getBlockPatternCategories in useBlockEditorSettings.
[211] Fix | Delete
'/wp/v2/block-patterns/categories',
[212] Fix | Delete
// @see packages/core-data/src/entities.js
[213] Fix | Delete
'/?_fields=' . implode(
[214] Fix | Delete
',',
[215] Fix | Delete
array(
[216] Fix | Delete
'description',
[217] Fix | Delete
'gmt_offset',
[218] Fix | Delete
'home',
[219] Fix | Delete
'name',
[220] Fix | Delete
'site_icon',
[221] Fix | Delete
'site_icon_url',
[222] Fix | Delete
'site_logo',
[223] Fix | Delete
'timezone_string',
[224] Fix | Delete
'url',
[225] Fix | Delete
'page_for_posts',
[226] Fix | Delete
'page_on_front',
[227] Fix | Delete
'show_on_front',
[228] Fix | Delete
)
[229] Fix | Delete
),
[230] Fix | Delete
);
[231] Fix | Delete
[232] Fix | Delete
if ( $block_editor_context->post ) {
[233] Fix | Delete
$route_for_post = rest_get_route_for_post( $block_editor_context->post );
[234] Fix | Delete
if ( $route_for_post ) {
[235] Fix | Delete
$preload_paths[] = add_query_arg( 'context', 'edit', $route_for_post );
[236] Fix | Delete
if ( 'page' === $block_editor_context->post->post_type ) {
[237] Fix | Delete
$preload_paths[] = add_query_arg(
[238] Fix | Delete
'slug',
[239] Fix | Delete
// @see https://github.com/WordPress/gutenberg/blob/e093fefd041eb6cc4a4e7f67b92ab54fd75c8858/packages/core-data/src/private-selectors.ts#L244-L254
[240] Fix | Delete
empty( $block_editor_context->post->post_name ) ? 'page' : 'page-' . $block_editor_context->post->post_name,
[241] Fix | Delete
'/wp/v2/templates/lookup'
[242] Fix | Delete
);
[243] Fix | Delete
}
[244] Fix | Delete
}
[245] Fix | Delete
} else {
[246] Fix | Delete
$preload_paths[] = '/wp/v2/templates/lookup?slug=front-page';
[247] Fix | Delete
$preload_paths[] = '/wp/v2/templates/lookup?slug=home';
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
block_editor_rest_api_preload( $preload_paths, $block_editor_context );
[251] Fix | Delete
[252] Fix | Delete
wp_add_inline_script(
[253] Fix | Delete
'wp-edit-site',
[254] Fix | Delete
sprintf(
[255] Fix | Delete
'wp.domReady( function() {
[256] Fix | Delete
wp.editSite.initializeEditor( "site-editor", %s );
[257] Fix | Delete
} );',
[258] Fix | Delete
wp_json_encode( $editor_settings )
[259] Fix | Delete
)
[260] Fix | Delete
);
[261] Fix | Delete
[262] Fix | Delete
// Preload server-registered block schemas.
[263] Fix | Delete
wp_add_inline_script(
[264] Fix | Delete
'wp-blocks',
[265] Fix | Delete
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
[266] Fix | Delete
);
[267] Fix | Delete
[268] Fix | Delete
// Preload server-registered block bindings sources.
[269] Fix | Delete
$registered_sources = get_all_registered_block_bindings_sources();
[270] Fix | Delete
if ( ! empty( $registered_sources ) ) {
[271] Fix | Delete
$filtered_sources = array();
[272] Fix | Delete
foreach ( $registered_sources as $source ) {
[273] Fix | Delete
$filtered_sources[] = array(
[274] Fix | Delete
'name' => $source->name,
[275] Fix | Delete
'label' => $source->label,
[276] Fix | Delete
'usesContext' => $source->uses_context,
[277] Fix | Delete
);
[278] Fix | Delete
}
[279] Fix | Delete
$script = sprintf( 'for ( const source of %s ) { wp.blocks.registerBlockBindingsSource( source ); }', wp_json_encode( $filtered_sources ) );
[280] Fix | Delete
wp_add_inline_script(
[281] Fix | Delete
'wp-blocks',
[282] Fix | Delete
$script
[283] Fix | Delete
);
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
wp_add_inline_script(
[287] Fix | Delete
'wp-blocks',
[288] Fix | Delete
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( isset( $editor_settings['blockCategories'] ) ? $editor_settings['blockCategories'] : array() ) ),
[289] Fix | Delete
'after'
[290] Fix | Delete
);
[291] Fix | Delete
[292] Fix | Delete
wp_enqueue_script( 'wp-edit-site' );
[293] Fix | Delete
wp_enqueue_script( 'wp-format-library' );
[294] Fix | Delete
wp_enqueue_style( 'wp-edit-site' );
[295] Fix | Delete
wp_enqueue_style( 'wp-format-library' );
[296] Fix | Delete
wp_enqueue_media();
[297] Fix | Delete
[298] Fix | Delete
if (
[299] Fix | Delete
current_theme_supports( 'wp-block-styles' ) &&
[300] Fix | Delete
( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 )
[301] Fix | Delete
) {
[302] Fix | Delete
wp_enqueue_style( 'wp-block-library-theme' );
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
/** This action is documented in wp-admin/edit-form-blocks.php */
[306] Fix | Delete
do_action( 'enqueue_block_editor_assets' );
[307] Fix | Delete
[308] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-header.php';
[309] Fix | Delete
?>
[310] Fix | Delete
[311] Fix | Delete
<div class="edit-site" id="site-editor">
[312] Fix | Delete
<?php // JavaScript is disabled. ?>
[313] Fix | Delete
<div class="wrap hide-if-js site-editor-no-js">
[314] Fix | Delete
<h1 class="wp-heading-inline"><?php _e( 'Edit Site' ); ?></h1>
[315] Fix | Delete
<?php
[316] Fix | Delete
/**
[317] Fix | Delete
* Filters the message displayed in the site editor interface when JavaScript is
[318] Fix | Delete
* not enabled in the browser.
[319] Fix | Delete
*
[320] Fix | Delete
* @since 6.3.0
[321] Fix | Delete
*
[322] Fix | Delete
* @param string $message The message being displayed.
[323] Fix | Delete
* @param WP_Post $post The post being edited.
[324] Fix | Delete
*/
[325] Fix | Delete
$message = apply_filters( 'site_editor_no_javascript_message', __( 'The site editor requires JavaScript. Please enable JavaScript in your browser settings.' ), $post );
[326] Fix | Delete
wp_admin_notice(
[327] Fix | Delete
$message,
[328] Fix | Delete
array(
[329] Fix | Delete
'type' => 'error',
[330] Fix | Delete
'additional_classes' => array( 'hide-if-js' ),
[331] Fix | Delete
)
[332] Fix | Delete
);
[333] Fix | Delete
?>
[334] Fix | Delete
</div>
[335] Fix | Delete
</div>
[336] Fix | Delete
[337] Fix | Delete
<?php
[338] Fix | Delete
[339] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-footer.php';
[340] Fix | Delete
[341] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function