Skip to content
Closed
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
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@
"wp-coding-standards/wpcs": "^2.2",
"sirbrillig/phpcs-variable-analysis": "^2.8",
"spatie/phpunit-watcher": "^1.23",
"yoast/phpunit-polyfills": "^1.0"
"yoast/phpunit-polyfills": "^1.0",
"gutenberg-coding-standards/gbcs": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/anton-vlasenko/Gutenberg-Coding-Standards.git"
}
],
"require": {
"composer/installers": "~1.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @since 6.2.0
*/

if ( class_exists( 'WP_HTML_Attribute_Token' ) ) {
return;
}

/**
* Data structure for the attribute token that allows to drastically improve performance.
*
Expand Down
4 changes: 4 additions & 0 deletions lib/compat/wordpress-6.2/html-api/class-wp-html-span.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @since 6.2.0
*/

if ( class_exists( 'WP_HTML_Span' ) ) {
return;
}

/**
* Represents a textual span inside an HTML document.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
* @since 6.2.0
*/

if ( class_exists( 'WP_HTML_Tag_Processor' ) ) {
return;
}

/**
* Modifies attributes in an HTML document for tags matching a query.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @since 6.2.0
*/

if ( class_exists( 'WP_HTML_Text_Replacement' ) ) {
return;
}

/**
* Data structure used to replace existing content from start to end that allows to drastically improve performance.
*
Expand Down
70 changes: 37 additions & 33 deletions lib/compat/wordpress-6.2/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,42 +100,46 @@ function gutenberg_modify_rest_sidebars_response( $response ) {
}
add_filter( 'rest_prepare_sidebar', 'gutenberg_modify_rest_sidebars_response' );


/**
* Add the `block_types` value to the `pattern-directory-item` schema.
*
* @since 6.2.0 Added 'block_types' property.
*/
function add_block_pattern_block_types_schema() {
register_rest_field(
'pattern-directory-item',
'block_types',
array(
'schema' => array(
'description' => __( 'The block types which can use this pattern.', 'gutenberg' ),
'type' => 'array',
'uniqueItems' => true,
'items' => array( 'type' => 'string' ),
'context' => array( 'view', 'embed' ),
),
)
);
if ( ! function_exists( 'add_block_pattern_block_types_schema' ) ) {
/**
* Add the `block_types` value to the `pattern-directory-item` schema.
*
* @since 6.2.0 Added 'block_types' property.
*/
function add_block_pattern_block_types_schema() {
register_rest_field(
'pattern-directory-item',
'block_types',
array(
'schema' => array(
'description' => __( 'The block types which can use this pattern.', 'gutenberg' ),
'type' => 'array',
'uniqueItems' => true,
'items' => array( 'type' => 'string' ),
'context' => array( 'view', 'embed' ),
),
)
);
}
}
add_filter( 'rest_api_init', 'add_block_pattern_block_types_schema' );


/**
* Add the `block_types` value into the API response.
*
* @since 6.2.0 Added 'block_types' property.
*
* @param WP_REST_Response $response The response object.
* @param object $raw_pattern The unprepared pattern.
*/
function filter_block_pattern_response( $response, $raw_pattern ) {
$data = $response->get_data();
$data['block_types'] = array_map( 'sanitize_text_field', $raw_pattern->meta->wpop_block_types );
$response->set_data( $data );
return $response;
if ( ! function_exists( 'filter_block_pattern_response' ) ) {
/**
* Add the `block_types` value into the API response.
*
* @param WP_REST_Response $response The response object.
* @param object $raw_pattern The unprepared pattern.
*
* @since 6.2.0 Added 'block_types' property.
*/
function filter_block_pattern_response( $response, $raw_pattern ) {
$data = $response->get_data();
$data['block_types'] = array_map( 'sanitize_text_field', $raw_pattern->meta->wpop_block_types );
$response->set_data( $data );

return $response;
}
}
add_filter( 'rest_prepare_block_pattern', 'filter_block_pattern_response', 10, 2 );
110 changes: 57 additions & 53 deletions lib/compat/wordpress-6.3/theme-previews.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,65 +51,69 @@ function gutenberg_attach_theme_preview_middleware() {
);
}

/**
* Temporary function to add a live preview button to block themes.
* Remove when https://core.trac.wordpress.org/ticket/58190 lands.
*/
function add_live_preview_button() {
global $pagenow;
if ( 'themes.php' === $pagenow ) {
?>
<script type="text/javascript">
jQuery( document ).ready( function() {
addLivePreviewButton();
//themes are loaded as we scroll so we need to add the button to the newer ones.
jQuery('.themes').on('DOMSubtreeModified', function(){
if ( ! function_exists( 'add_live_preview_button' ) ) {
/**
* Temporary function to add a live preview button to block themes.
* Remove when https://core.trac.wordpress.org/ticket/58190 lands.
*/
function add_live_preview_button() {
global $pagenow;
if ( 'themes.php' === $pagenow ) {
?>
<script type="text/javascript">
jQuery( document ).ready( function() {
addLivePreviewButton();
//themes are loaded as we scroll so we need to add the button to the newer ones.
jQuery('.themes').on('DOMSubtreeModified', function(){
addLivePreviewButton();
});
});
});
function addLivePreviewButton() {
document.querySelectorAll('.theme').forEach((el, index) => {
const themeInfo = el.querySelector('.theme-id-container');
const canAddButton =
!themeInfo ||
el.classList.contains('active') ||
themeInfo.querySelector('.theme-actions')?.childElementCount > 1;
if ( canAddButton ) {
return;
}
const themePath = themeInfo.querySelector('h2.theme-name').id.replace('-name', '');
const themeName = themeInfo.querySelector('h2.theme-name').innerText;
const livePreviewButton = document.createElement('a');
function addLivePreviewButton() {
document.querySelectorAll('.theme').forEach((el, index) => {
const themeInfo = el.querySelector('.theme-id-container');
const canAddButton =
!themeInfo ||
el.classList.contains('active') ||
themeInfo.querySelector('.theme-actions')?.childElementCount > 1;
if ( canAddButton ) {
return;
}
const themePath = themeInfo.querySelector('h2.theme-name').id.replace('-name', '');
const themeName = themeInfo.querySelector('h2.theme-name').innerText;
const livePreviewButton = document.createElement('a');
<?php
/* translators: %s: theme name */
$button_label = esc_attr_x( 'Live Preview %s', 'theme' );
?>
livePreviewButton.setAttribute('aria-label', '<?php echo $button_label; ?>'.replace('%s', themeName));
livePreviewButton.setAttribute('class', 'button button-primary');
livePreviewButton.setAttribute(
'href',
`/wp-admin/site-editor.php?theme_preview=${themePath}&return=themes.php`
);
livePreviewButton.innerHTML = '<?php echo esc_html_e( 'Live Preview' ); ?>';
themeInfo.querySelector('.theme-actions').appendChild(livePreviewButton);
});
}
</script>
<?php
/* translators: %s: theme name */
$button_label = esc_attr_x( 'Live Preview %s', 'theme' );
?>
livePreviewButton.setAttribute('aria-label', '<?php echo $button_label; ?>'.replace('%s', themeName));
livePreviewButton.setAttribute('class', 'button button-primary');
livePreviewButton.setAttribute(
'href',
`/wp-admin/site-editor.php?theme_preview=${themePath}&return=themes.php`
);
livePreviewButton.innerHTML = '<?php echo esc_html_e( 'Live Preview' ); ?>';
themeInfo.querySelector('.theme-actions').appendChild(livePreviewButton);
});
}
</script>
<?php
}
}

}
}

/**
* Adds a nonce for the theme activation link.
*/
function block_theme_activate_nonce() {
$nonce_handle = 'switch-theme_' . gutenberg_theme_preview_stylesheet();
?>
<script type="text/javascript">
window.BLOCK_THEME_ACTIVATE_NONCE = '<?php echo wp_create_nonce( $nonce_handle ); ?>';
</script>
<?php
if ( ! function_exists( 'block_theme_activate_nonce' ) ) {
/**
* Adds a nonce for the theme activation link.
*/
function block_theme_activate_nonce() {
$nonce_handle = 'switch-theme_' . gutenberg_theme_preview_stylesheet();
?>
<script type="text/javascript">
window.BLOCK_THEME_ACTIVATE_NONCE = '<?php echo wp_create_nonce( $nonce_handle ); ?>';
</script>
<?php
}
}

// Hide this feature behind an experiment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* @since 6.3.0
*/

if ( class_exists( 'WP_Classic_To_Block_Menu_Converter' ) ) {
return;
}

/**
* Converts a Classic Menu to Block Menu blocks.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* @subpackage REST_API
*/

if ( class_exists( 'WP_REST_Block_Editor_Settings_Controller' ) ) {
return;
}

/**
* Core class used to retrieve the block editor settings via the REST API.
*
Expand Down
4 changes: 4 additions & 0 deletions lib/experimental/class-wp-rest-customizer-nonces.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* @package gutenberg
*/

if ( class_exists( 'WP_Rest_Customizer_Nonces' ) ) {
return;
}

/**
* Class that returns the customizer "save" nonce that's required for the
* batch save operation using the customizer API endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @since 6.3.0
*/

if ( class_exists( 'WP_REST_Navigation_Fallback_Controller' ) ) {
return;
}

/**
* Import dependencies.
*/
Expand Down
70 changes: 38 additions & 32 deletions lib/experimental/kses.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,43 +66,49 @@ function gutenberg_override_core_kses_init_filters() {
add_action( 'init', 'gutenberg_override_core_kses_init_filters', 20 );
add_action( 'set_current_user', 'gutenberg_override_core_kses_init_filters' );

/**
* See https://github.com/WordPress/wordpress-develop/pull/4108
*
* Mark CSS safe if it contains a "filter: url('#wp-duotone-...')" rule.
*
* This function should not be backported to core.
*
* @param bool $allow_css Whether the CSS is allowed.
* @param string $css_test_string The CSS to test.
*/
function allow_filter_in_styles( $allow_css, $css_test_string ) {
if ( preg_match(
"/^filter:\s*url\('#wp-duotone-[-a-zA-Z0-9]+'\) !important$/",
$css_test_string
) ) {
return true;
if ( ! function_exists( 'allow_filter_in_styles' ) ) {
/**
* See https://github.com/WordPress/wordpress-develop/pull/4108
*
* Mark CSS safe if it contains a "filter: url('#wp-duotone-...')" rule.
*
* This function should not be backported to core.
*
* @param bool $allow_css Whether the CSS is allowed.
* @param string $css_test_string The CSS to test.
*/
function allow_filter_in_styles( $allow_css, $css_test_string ) {
if ( preg_match(
"/^filter:\s*url\('#wp-duotone-[-a-zA-Z0-9]+'\) !important$/",
$css_test_string
) ) {
return true;
}

return $allow_css;
}
return $allow_css;
}

add_filter( 'safecss_filter_attr_allow_css', 'allow_filter_in_styles', 10, 2 );

/**
* Mark CSS safe if it contains grid functions
*
* This function should not be backported to core.
*
* @param bool $allow_css Whether the CSS is allowed.
* @param string $css_test_string The CSS to test.
*/
function allow_grid_functions_in_styles( $allow_css, $css_test_string ) {
if ( preg_match(
'/^grid-template-columns:\s*repeat\([0-9,a-z-\s\(\)]*\)$/',
$css_test_string
) ) {
return true;
if ( ! function_exists( 'allow_grid_functions_in_styles' ) ) {
/**
* Mark CSS safe if it contains grid functions
*
* This function should not be backported to core.
*
* @param bool $allow_css Whether the CSS is allowed.
* @param string $css_test_string The CSS to test.
*/
function allow_grid_functions_in_styles( $allow_css, $css_test_string ) {
if ( preg_match(
'/^grid-template-columns:\s*repeat\([0-9,a-z-\s\(\)]*\)$/',
$css_test_string
) ) {
return true;
}

return $allow_css;
}
return $allow_css;
}
add_filter( 'safecss_filter_attr_allow_css', 'allow_grid_functions_in_styles', 10, 2 );
Loading