Edit File by line
/home/zeestwma/richards.../wp-admin...
File: edit-form-blocks.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* The block editor page.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 5.0.0
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
* @subpackage Administration
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
// Don't load directly.
[10] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[11] Fix | Delete
die( '-1' );
[12] Fix | Delete
}
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* @global string $post_type Global post type.
[16] Fix | Delete
* @global WP_Post_Type $post_type_object Global post type object.
[17] Fix | Delete
* @global WP_Post $post Global post object.
[18] Fix | Delete
* @global string $title The title of the current screen.
[19] Fix | Delete
* @global array $wp_meta_boxes Global meta box state.
[20] Fix | Delete
*/
[21] Fix | Delete
global $post_type, $post_type_object, $post, $title, $wp_meta_boxes;
[22] Fix | Delete
[23] Fix | Delete
$block_editor_context = new WP_Block_Editor_Context( array( 'post' => $post ) );
[24] Fix | Delete
[25] Fix | Delete
// Flag that we're loading the block editor.
[26] Fix | Delete
$current_screen = get_current_screen();
[27] Fix | Delete
$current_screen->is_block_editor( true );
[28] Fix | Delete
[29] Fix | Delete
// Default to is-fullscreen-mode to avoid jumps in the UI.
[30] Fix | Delete
add_filter(
[31] Fix | Delete
'admin_body_class',
[32] Fix | Delete
static function ( $classes ) {
[33] Fix | Delete
return "$classes is-fullscreen-mode";
[34] Fix | Delete
}
[35] Fix | Delete
);
[36] Fix | Delete
[37] Fix | Delete
/*
[38] Fix | Delete
* Emoji replacement is disabled for now, until it plays nicely with React.
[39] Fix | Delete
*/
[40] Fix | Delete
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
[41] Fix | Delete
[42] Fix | Delete
/*
[43] Fix | Delete
* Block editor implements its own Options menu for toggling Document Panels.
[44] Fix | Delete
*/
[45] Fix | Delete
add_filter( 'screen_options_show_screen', '__return_false' );
[46] Fix | Delete
[47] Fix | Delete
wp_enqueue_script( 'heartbeat' );
[48] Fix | Delete
wp_enqueue_script( 'wp-edit-post' );
[49] Fix | Delete
[50] Fix | Delete
$rest_path = rest_get_route_for_post( $post );
[51] Fix | Delete
[52] Fix | Delete
// Preload common data.
[53] Fix | Delete
$preload_paths = array(
[54] Fix | Delete
'/wp/v2/types?context=view',
[55] Fix | Delete
'/wp/v2/taxonomies?context=view',
[56] Fix | Delete
add_query_arg(
[57] Fix | Delete
array(
[58] Fix | Delete
'context' => 'edit',
[59] Fix | Delete
'per_page' => -1,
[60] Fix | Delete
),
[61] Fix | Delete
rest_get_route_for_post_type_items( 'wp_block' )
[62] Fix | Delete
),
[63] Fix | Delete
add_query_arg( 'context', 'edit', $rest_path ),
[64] Fix | Delete
sprintf( '/wp/v2/types/%s?context=edit', $post_type ),
[65] Fix | Delete
'/wp/v2/users/me',
[66] Fix | Delete
array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ),
[67] Fix | Delete
array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ),
[68] Fix | Delete
array( rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ),
[69] Fix | Delete
array( rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' ),
[70] Fix | Delete
sprintf( '%s/autosaves?context=edit', $rest_path ),
[71] Fix | Delete
'/wp/v2/settings',
[72] Fix | Delete
array( '/wp/v2/settings', 'OPTIONS' ),
[73] Fix | Delete
'/wp/v2/global-styles/themes/' . get_stylesheet(),
[74] Fix | Delete
'/wp/v2/themes?context=edit&status=active',
[75] Fix | Delete
'/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=edit',
[76] Fix | Delete
);
[77] Fix | Delete
[78] Fix | Delete
block_editor_rest_api_preload( $preload_paths, $block_editor_context );
[79] Fix | Delete
[80] Fix | Delete
wp_add_inline_script(
[81] Fix | Delete
'wp-blocks',
[82] Fix | Delete
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ),
[83] Fix | Delete
'after'
[84] Fix | Delete
);
[85] Fix | Delete
[86] Fix | Delete
/*
[87] Fix | Delete
* Assign initial edits, if applicable. These are not initially assigned to the persisted post,
[88] Fix | Delete
* but should be included in its save payload.
[89] Fix | Delete
*/
[90] Fix | Delete
$initial_edits = array();
[91] Fix | Delete
$is_new_post = false;
[92] Fix | Delete
if ( 'auto-draft' === $post->post_status ) {
[93] Fix | Delete
$is_new_post = true;
[94] Fix | Delete
// Override "(Auto Draft)" new post default title with empty string, or filtered value.
[95] Fix | Delete
if ( post_type_supports( $post->post_type, 'title' ) ) {
[96] Fix | Delete
$initial_edits['title'] = $post->post_title;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
if ( post_type_supports( $post->post_type, 'editor' ) ) {
[100] Fix | Delete
$initial_edits['content'] = $post->post_content;
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
[104] Fix | Delete
$initial_edits['excerpt'] = $post->post_excerpt;
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
// Preload server-registered block schemas.
[109] Fix | Delete
wp_add_inline_script(
[110] Fix | Delete
'wp-blocks',
[111] Fix | Delete
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
[112] Fix | Delete
);
[113] Fix | Delete
[114] Fix | Delete
// Get admin url for handling meta boxes.
[115] Fix | Delete
$meta_box_url = admin_url( 'post.php' );
[116] Fix | Delete
$meta_box_url = add_query_arg(
[117] Fix | Delete
array(
[118] Fix | Delete
'post' => $post->ID,
[119] Fix | Delete
'action' => 'edit',
[120] Fix | Delete
'meta-box-loader' => true,
[121] Fix | Delete
'meta-box-loader-nonce' => wp_create_nonce( 'meta-box-loader' ),
[122] Fix | Delete
),
[123] Fix | Delete
$meta_box_url
[124] Fix | Delete
);
[125] Fix | Delete
wp_add_inline_script(
[126] Fix | Delete
'wp-editor',
[127] Fix | Delete
sprintf( 'var _wpMetaBoxUrl = %s;', wp_json_encode( $meta_box_url ) ),
[128] Fix | Delete
'before'
[129] Fix | Delete
);
[130] Fix | Delete
[131] Fix | Delete
/*
[132] Fix | Delete
* Get all available templates for the post/page attributes meta-box.
[133] Fix | Delete
* The "Default template" array element should only be added if the array is
[134] Fix | Delete
* not empty so we do not trigger the template select element without any options
[135] Fix | Delete
* besides the default value.
[136] Fix | Delete
*/
[137] Fix | Delete
$available_templates = wp_get_theme()->get_page_templates( get_post( $post->ID ) );
[138] Fix | Delete
$available_templates = ! empty( $available_templates ) ? array_replace(
[139] Fix | Delete
array(
[140] Fix | Delete
/** This filter is documented in wp-admin/includes/meta-boxes.php */
[141] Fix | Delete
'' => apply_filters( 'default_page_template_title', __( 'Default template' ), 'rest-api' ),
[142] Fix | Delete
),
[143] Fix | Delete
$available_templates
[144] Fix | Delete
) : $available_templates;
[145] Fix | Delete
[146] Fix | Delete
// Lock settings.
[147] Fix | Delete
$user_id = wp_check_post_lock( $post->ID );
[148] Fix | Delete
if ( $user_id ) {
[149] Fix | Delete
$locked = false;
[150] Fix | Delete
[151] Fix | Delete
/** This filter is documented in wp-admin/includes/post.php */
[152] Fix | Delete
if ( apply_filters( 'show_post_locked_dialog', true, $post, $user_id ) ) {
[153] Fix | Delete
$locked = true;
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
$user_details = null;
[157] Fix | Delete
if ( $locked ) {
[158] Fix | Delete
$user = get_userdata( $user_id );
[159] Fix | Delete
$user_details = array(
[160] Fix | Delete
'avatar' => get_avatar_url( $user_id, array( 'size' => 128 ) ),
[161] Fix | Delete
'name' => $user->display_name,
[162] Fix | Delete
);
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
$lock_details = array(
[166] Fix | Delete
'isLocked' => $locked,
[167] Fix | Delete
'user' => $user_details,
[168] Fix | Delete
);
[169] Fix | Delete
} else {
[170] Fix | Delete
// Lock the post.
[171] Fix | Delete
$active_post_lock = wp_set_post_lock( $post->ID );
[172] Fix | Delete
if ( $active_post_lock ) {
[173] Fix | Delete
$active_post_lock = esc_attr( implode( ':', $active_post_lock ) );
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
$lock_details = array(
[177] Fix | Delete
'isLocked' => false,
[178] Fix | Delete
'activePostLock' => $active_post_lock,
[179] Fix | Delete
);
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Filters the body placeholder text.
[184] Fix | Delete
*
[185] Fix | Delete
* @since 5.0.0
[186] Fix | Delete
* @since 5.8.0 Changed the default placeholder text.
[187] Fix | Delete
*
[188] Fix | Delete
* @param string $text Placeholder text. Default 'Type / to choose a block'.
[189] Fix | Delete
* @param WP_Post $post Post object.
[190] Fix | Delete
*/
[191] Fix | Delete
$body_placeholder = apply_filters( 'write_your_story', __( 'Type / to choose a block' ), $post );
[192] Fix | Delete
[193] Fix | Delete
$editor_settings = array(
[194] Fix | Delete
'availableTemplates' => $available_templates,
[195] Fix | Delete
'disablePostFormats' => ! current_theme_supports( 'post-formats' ),
[196] Fix | Delete
/** This filter is documented in wp-admin/edit-form-advanced.php */
[197] Fix | Delete
'titlePlaceholder' => apply_filters( 'enter_title_here', __( 'Add title' ), $post ),
[198] Fix | Delete
'bodyPlaceholder' => $body_placeholder,
[199] Fix | Delete
'autosaveInterval' => AUTOSAVE_INTERVAL,
[200] Fix | Delete
'richEditingEnabled' => user_can_richedit(),
[201] Fix | Delete
'postLock' => $lock_details,
[202] Fix | Delete
'postLockUtils' => array(
[203] Fix | Delete
'nonce' => wp_create_nonce( 'lock-post_' . $post->ID ),
[204] Fix | Delete
'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ),
[205] Fix | Delete
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
[206] Fix | Delete
),
[207] Fix | Delete
'supportsLayout' => wp_theme_has_theme_json(),
[208] Fix | Delete
'supportsTemplateMode' => current_theme_supports( 'block-templates' ),
[209] Fix | Delete
[210] Fix | Delete
// Whether or not to load the 'postcustom' meta box is stored as a user meta
[211] Fix | Delete
// field so that we're not always loading its assets.
[212] Fix | Delete
'enableCustomFields' => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
[213] Fix | Delete
);
[214] Fix | Delete
[215] Fix | Delete
// Add additional back-compat patterns registered by `current_screen` et al.
[216] Fix | Delete
$editor_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true );
[217] Fix | Delete
$editor_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true );
[218] Fix | Delete
[219] Fix | Delete
$autosave = wp_get_post_autosave( $post->ID );
[220] Fix | Delete
if ( $autosave ) {
[221] Fix | Delete
if ( mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) {
[222] Fix | Delete
$editor_settings['autosave'] = array(
[223] Fix | Delete
'editLink' => get_edit_post_link( $autosave->ID ),
[224] Fix | Delete
);
[225] Fix | Delete
} else {
[226] Fix | Delete
wp_delete_post_revision( $autosave->ID );
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
if ( ! empty( $post_type_object->template ) ) {
[231] Fix | Delete
$editor_settings['template'] = $post_type_object->template;
[232] Fix | Delete
$editor_settings['templateLock'] = ! empty( $post_type_object->template_lock ) ? $post_type_object->template_lock : false;
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
// If there's no template set on a new post, use the post format, instead.
[236] Fix | Delete
if ( $is_new_post && ! isset( $editor_settings['template'] ) && 'post' === $post->post_type ) {
[237] Fix | Delete
$post_format = get_post_format( $post );
[238] Fix | Delete
if ( in_array( $post_format, array( 'audio', 'gallery', 'image', 'quote', 'video' ), true ) ) {
[239] Fix | Delete
$editor_settings['template'] = array( array( "core/$post_format" ) );
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
if ( wp_is_block_theme() && $editor_settings['supportsTemplateMode'] ) {
[244] Fix | Delete
$editor_settings['defaultTemplatePartAreas'] = get_allowed_block_template_part_areas();
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
/**
[248] Fix | Delete
* Scripts
[249] Fix | Delete
*/
[250] Fix | Delete
wp_enqueue_media(
[251] Fix | Delete
array(
[252] Fix | Delete
'post' => $post->ID,
[253] Fix | Delete
)
[254] Fix | Delete
);
[255] Fix | Delete
wp_tinymce_inline_scripts();
[256] Fix | Delete
wp_enqueue_editor();
[257] Fix | Delete
[258] Fix | Delete
/**
[259] Fix | Delete
* Styles
[260] Fix | Delete
*/
[261] Fix | Delete
wp_enqueue_style( 'wp-edit-post' );
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Fires after block assets have been enqueued for the editing interface.
[265] Fix | Delete
*
[266] Fix | Delete
* Call `add_action` on any hook before 'admin_enqueue_scripts'.
[267] Fix | Delete
*
[268] Fix | Delete
* In the function call you supply, simply use `wp_enqueue_script` and
[269] Fix | Delete
* `wp_enqueue_style` to add your functionality to the block editor.
[270] Fix | Delete
*
[271] Fix | Delete
* @since 5.0.0
[272] Fix | Delete
*/
[273] Fix | Delete
do_action( 'enqueue_block_editor_assets' );
[274] Fix | Delete
[275] Fix | Delete
// In order to duplicate classic meta box behavior, we need to run the classic meta box actions.
[276] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
[277] Fix | Delete
register_and_do_post_meta_boxes( $post );
[278] Fix | Delete
[279] Fix | Delete
// Check if the Custom Fields meta box has been removed at some point.
[280] Fix | Delete
$core_meta_boxes = $wp_meta_boxes[ $current_screen->id ]['normal']['core'];
[281] Fix | Delete
if ( ! isset( $core_meta_boxes['postcustom'] ) || ! $core_meta_boxes['postcustom'] ) {
[282] Fix | Delete
unset( $editor_settings['enableCustomFields'] );
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
$editor_settings = get_block_editor_settings( $editor_settings, $block_editor_context );
[286] Fix | Delete
[287] Fix | Delete
$init_script = <<<JS
[288] Fix | Delete
( function() {
[289] Fix | Delete
window._wpLoadBlockEditor = new Promise( function( resolve ) {
[290] Fix | Delete
wp.domReady( function() {
[291] Fix | Delete
resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, %s, %s ) );
[292] Fix | Delete
} );
[293] Fix | Delete
} );
[294] Fix | Delete
} )();
[295] Fix | Delete
JS;
[296] Fix | Delete
[297] Fix | Delete
$script = sprintf(
[298] Fix | Delete
$init_script,
[299] Fix | Delete
$post->post_type,
[300] Fix | Delete
$post->ID,
[301] Fix | Delete
wp_json_encode( $editor_settings ),
[302] Fix | Delete
wp_json_encode( $initial_edits )
[303] Fix | Delete
);
[304] Fix | Delete
wp_add_inline_script( 'wp-edit-post', $script );
[305] Fix | Delete
[306] Fix | Delete
if ( (int) get_option( 'page_for_posts' ) === $post->ID ) {
[307] Fix | Delete
add_action( 'admin_enqueue_scripts', '_wp_block_editor_posts_page_notice' );
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-header.php';
[311] Fix | Delete
?>
[312] Fix | Delete
[313] Fix | Delete
<div class="block-editor">
[314] Fix | Delete
<h1 class="screen-reader-text hide-if-no-js"><?php echo esc_html( $title ); ?></h1>
[315] Fix | Delete
<div id="editor" class="block-editor__container hide-if-no-js"></div>
[316] Fix | Delete
<div id="metaboxes" class="hidden">
[317] Fix | Delete
<?php the_block_editor_meta_boxes(); ?>
[318] Fix | Delete
</div>
[319] Fix | Delete
[320] Fix | Delete
<?php // JavaScript is disabled. ?>
[321] Fix | Delete
<div class="wrap hide-if-js block-editor-no-js">
[322] Fix | Delete
<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
[323] Fix | Delete
<?php
[324] Fix | Delete
if ( file_exists( WP_PLUGIN_DIR . '/classic-editor/classic-editor.php' ) ) {
[325] Fix | Delete
// If Classic Editor is already installed, provide a link to activate the plugin.
[326] Fix | Delete
$installed = true;
[327] Fix | Delete
$plugin_activate_url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=classic-editor/classic-editor.php', 'activate-plugin_classic-editor/classic-editor.php' );
[328] Fix | Delete
$message = sprintf(
[329] Fix | Delete
/* translators: %s: Link to activate the Classic Editor plugin. */
[330] Fix | Delete
__( 'The block editor requires JavaScript. Please enable JavaScript in your browser settings, or activate the <a href="%s">Classic Editor plugin</a>.' ),
[331] Fix | Delete
esc_url( $plugin_activate_url )
[332] Fix | Delete
);
[333] Fix | Delete
} else {
[334] Fix | Delete
// If Classic Editor is not installed, provide a link to install it.
[335] Fix | Delete
$installed = false;
[336] Fix | Delete
$plugin_install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=classic-editor' ), 'install-plugin_classic-editor' );
[337] Fix | Delete
$message = sprintf(
[338] Fix | Delete
/* translators: %s: Link to install the Classic Editor plugin. */
[339] Fix | Delete
__( 'The block editor requires JavaScript. Please enable JavaScript in your browser settings, or install the <a href="%s">Classic Editor plugin</a>.' ),
[340] Fix | Delete
esc_url( $plugin_install_url )
[341] Fix | Delete
);
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
/**
[345] Fix | Delete
* Filters the message displayed in the block editor interface when JavaScript is
[346] Fix | Delete
* not enabled in the browser.
[347] Fix | Delete
*
[348] Fix | Delete
* @since 5.0.3
[349] Fix | Delete
* @since 6.4.0 Added `$installed` parameter.
[350] Fix | Delete
*
[351] Fix | Delete
* @param string $message The message being displayed.
[352] Fix | Delete
* @param WP_Post $post The post being edited.
[353] Fix | Delete
* @param bool $installed Whether the classic editor is installed.
[354] Fix | Delete
*/
[355] Fix | Delete
$message = apply_filters( 'block_editor_no_javascript_message', $message, $post, $installed );
[356] Fix | Delete
wp_admin_notice(
[357] Fix | Delete
$message,
[358] Fix | Delete
array(
[359] Fix | Delete
'type' => 'error',
[360] Fix | Delete
)
[361] Fix | Delete
);
[362] Fix | Delete
?>
[363] Fix | Delete
</div>
[364] Fix | Delete
</div>
[365] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function