Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/js/_enqueues/admin/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,46 @@ jQuery( function($) {
copyAttachmentURLSuccessTimeout,
__ = wp.i18n.__, _x = wp.i18n._x;

/**
* Show a warning in the classic editor when the post content includes
* serialized block comments, which may not be visible in the Visual tab.
*/
function maybeShowBlockMarkupWarning() {
var hasBlockMarkup, $warning, $editorWrapper;

if ( ! $textarea.length ) {
return;
}

hasBlockMarkup = /<!--\s*wp:[^>]*-->/.test( $textarea.val() );
if ( ! hasBlockMarkup ) {
return;
}

$warning = $( '#classic-editor-block-markup-notice' );
if ( $warning.length ) {
return;
}

$warning = $( '<div>', {
id: 'classic-editor-block-markup-notice',
'class': 'notice notice-warning inline'
} ).append(
$( '<p>' ).text(
__(
'This content includes Gutenberg block markup that may be visible in the Code editor but not in the Visual editor. The page may not be empty. Review the content carefully before overwriting or deleting it.'
)
)
);

$editorWrapper = $( '#wp-content-wrap' );
if ( $editorWrapper.length ) {
$editorWrapper.before( $warning );
}
}

postboxes.add_postbox_toggles(pagenow);
maybeShowBlockMarkupWarning();

/*
* Clear the window name. Otherwise if this is a former preview window where the user navigated to edit another post,
Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/includes/admin-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
// Misc hooks.
add_action( 'admin_init', 'wp_admin_headers' );
add_action( 'admin_init', 'send_frame_options_header', 10, 0 );
add_action( 'admin_init', 'wp_maybe_register_performance_optimization_settings' );
add_action( 'admin_head', 'wp_admin_canonical_url' );
add_action( 'admin_head', 'wp_site_icon' );
add_action( 'admin_head', 'wp_admin_viewport_meta' );
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@ function wp_ajax_widgets_order() {
unset( $_POST['savewidgets'], $_POST['action'] );

// Save widgets order for all sidebars.
if ( is_array( $_POST['sidebars'] ) ) {
if ( isset( $_POST['sidebars'] ) && is_array( $_POST['sidebars'] ) ) {
$sidebars = array();

foreach ( wp_unslash( $_POST['sidebars'] ) as $key => $val ) {
Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ function _add_plugin_file_editor_to_tools() {
$submenu['options-general.php'][20] = array( __( 'Reading' ), 'manage_options', 'options-reading.php' );
$submenu['options-general.php'][25] = array( __( 'Discussion' ), 'manage_options', 'options-discussion.php' );
$submenu['options-general.php'][30] = array( __( 'Media' ), 'manage_options', 'options-media.php' );
$submenu['options-general.php'][35] = array( __( 'Performance' ), 'manage_options', 'options-performance.php' );
$submenu['options-general.php'][40] = array( __( 'Permalinks' ), 'manage_options', 'options-permalink.php' );
$submenu['options-general.php'][45] = array( __( 'Privacy' ), 'manage_privacy_options', 'options-privacy.php' );

Expand Down
145 changes: 145 additions & 0 deletions src/wp-admin/options-performance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php
/**
* Performance settings administration panel.
*
* @package WordPress
* @subpackage Administration
*/

/** WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';

if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'Sorry, you are not allowed to manage options for this site.' ) );
}

global $wpdb;

$title = __( 'Performance Settings' );
$parent_file = 'options-general.php';

wp_register_performance_optimization_settings();

if ( isset( $_POST['performance_action'] ) ) {
check_admin_referer( 'performance-tools' );

if ( 'clear_cache' === $_POST['performance_action'] ) {
wp_delete_performance_cache();
add_settings_error( 'performance', 'performance_cache_cleared', __( 'Performance caches cleared.' ), 'success' );
} elseif ( 'database_cleanup' === $_POST['performance_action'] ) {
$deleted = 0;
$deleted += (int) $wpdb->query( "DELETE FROM $wpdb->posts WHERE post_type = 'revision'" );
$deleted += (int) $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'" );
$deleted += (int) $wpdb->query( "DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'" );
$deleted += (int) $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_edit_lock' OR meta_key = '_edit_last'" );
wp_clean_performance_page_cache();

/* translators: %d: Number of database rows deleted. */
add_settings_error( 'performance', 'performance_database_cleaned', sprintf( __( 'Database cleanup complete. %d rows were removed.' ), $deleted ), 'success' );
}
}

get_current_screen()->add_help_tab(
array(
'id' => 'overview',
'title' => __( 'Overview' ),
'content' => '<p>' . __( 'Performance settings provide native controls for front-end caching, asset minification, critical CSS generation, lazy loading, image optimization, and database cleanup.' ) . '</p>',
)
);

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

$settings = wp_get_performance_optimization_settings();

?>

<div class="wrap">
<h1><?php echo esc_html( $title ); ?></h1>

<?php settings_errors( 'performance' ); ?>

<form action="options.php" method="post">
<?php settings_fields( 'performance' ); ?>

<h2 class="title"><?php _e( 'Optimization features' ); ?></h2>
<p><?php _e( 'Choose which native optimization features WordPress should apply.' ); ?></p>

<table class="form-table" role="presentation">
<tr>
<th scope="row"><?php _e( 'Page caching' ); ?></th>
<td>
<label for="performance_optimization_page_cache">
<input name="performance_optimization[page_cache]" type="checkbox" id="performance_optimization_page_cache" value="1" <?php checked( $settings['page_cache'] ); ?> />
<?php _e( 'Cache anonymous front-end pages for faster repeat visits.' ); ?>
</label>
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'CSS and JavaScript minification' ); ?></th>
<td>
<label for="performance_optimization_minify_assets">
<input name="performance_optimization[minify_assets]" type="checkbox" id="performance_optimization_minify_assets" value="1" <?php checked( $settings['minify_assets'] ); ?> />
<?php _e( 'Minify front-end HTML output and inline CSS and JavaScript.' ); ?>
</label>
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Critical CSS' ); ?></th>
<td>
<label for="performance_optimization_critical_css">
<input name="performance_optimization[critical_css]" type="checkbox" id="performance_optimization_critical_css" value="1" <?php checked( $settings['critical_css'] ); ?> />
<?php _e( 'Generate a compact critical CSS block from early inline styles.' ); ?>
</label>
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Lazy loading' ); ?></th>
<td>
<label for="performance_optimization_lazy_loading">
<input name="performance_optimization[lazy_loading]" type="checkbox" id="performance_optimization_lazy_loading" value="1" <?php checked( $settings['lazy_loading'] ); ?> />
<?php _e( 'Automatically lazy-load eligible images and iframes.' ); ?>
</label>
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Image optimization' ); ?></th>
<td>
<label for="performance_optimization_image_optimization">
<input name="performance_optimization[image_optimization]" type="checkbox" id="performance_optimization_image_optimization" value="1" <?php checked( $settings['image_optimization'] ); ?> />
<?php _e( 'Convert generated JPEG and PNG image sizes to AVIF or WebP when supported.' ); ?>
</label>
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Database cleanup tools' ); ?></th>
<td>
<label for="performance_optimization_database_cleanup">
<input name="performance_optimization[database_cleanup]" type="checkbox" id="performance_optimization_database_cleanup" value="1" <?php checked( $settings['database_cleanup'] ); ?> />
<?php _e( 'Show cleanup controls for revisions, spam, trash, and temporary editing metadata.' ); ?>
</label>
</td>
</tr>
</table>

<?php submit_button(); ?>
</form>

<hr />

<h2 class="title"><?php _e( 'Maintenance tools' ); ?></h2>
<form method="post">
<?php wp_nonce_field( 'performance-tools' ); ?>
<input type="hidden" name="performance_action" value="clear_cache" />
<?php submit_button( __( 'Clear performance caches' ), 'secondary', 'submit', false ); ?>
</form>

<?php if ( $settings['database_cleanup'] ) : ?>
<form method="post" style="margin-top: 1em;">
<?php wp_nonce_field( 'performance-tools' ); ?>
<input type="hidden" name="performance_action" value="database_cleanup" />
<?php submit_button( __( 'Clean up database' ), 'secondary', 'submit', false ); ?>
</form>
<?php endif; ?>
</div>

<?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>
14 changes: 14 additions & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
add_action( 'wp_footer', 'wp_print_footer_scripts', 20 );
add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' );
add_action( 'template_redirect', 'wp_start_performance_page_cache', 0 );
add_action( 'init', '_register_core_block_patterns_and_categories' );
add_action( 'init', 'check_theme_switched', 99 );
add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 );
Expand Down Expand Up @@ -537,6 +538,7 @@
add_action( 'init', 'rest_api_init' );
add_action( 'rest_api_init', 'rest_api_default_filters', 10, 1 );
add_action( 'rest_api_init', 'register_initial_settings', 10 );
add_action( 'rest_api_init', 'wp_register_performance_optimization_settings', 10 );
add_action( 'rest_api_init', 'create_initial_rest_routes', 99 );
add_action( 'parse_request', 'rest_api_loaded' );

Expand Down Expand Up @@ -795,6 +797,18 @@
add_action( 'before_delete_post', '_wp_before_delete_font_face', 10, 2 );
add_action( 'init', '_wp_register_default_font_collections' );

// Collaboration.
add_action( 'admin_init', 'wp_collaboration_inject_setting' );

// Performance optimization.
add_action( 'save_post', 'wp_clean_performance_page_cache' );
add_action( 'deleted_post', 'wp_clean_performance_page_cache' );
add_action( 'clean_post_cache', 'wp_clean_performance_page_cache' );
add_action( 'transition_comment_status', 'wp_clean_performance_page_cache' );
add_filter( 'wp_get_loading_optimization_attributes', 'wp_performance_filter_loading_optimization_attributes', 10, 2 );
add_filter( 'image_editor_output_format', 'wp_performance_filter_image_editor_output_format' );

// Add ignoredHookedBlocks metadata attribute to the template and template part post types.
// Add ignoredHookedBlocks metadata attribute to the template and template part post types.
add_filter( 'rest_pre_insert_wp_template', 'inject_ignored_hooked_blocks_metadata_attributes' );
add_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes' );
Expand Down
Loading
Loading