plugin updates

This commit is contained in:
Tony Volpe
2024-10-24 12:57:16 -04:00
parent 8217f0dbed
commit 5e040c9234
399 changed files with 3377 additions and 46318 deletions

View File

@@ -0,0 +1,122 @@
<?php
/**
* WPSEO Premium plugin file.
*
* @package WPSEO\Premium\Classes
*/
if ( ! class_exists( 'WP_Text_Diff_Renderer_inline' ) ) {
require_once ABSPATH . '/wp-includes/wp-diff.php';
}
/**
* Class HTML_Diff_Renderer.
* This class is a modified version of Text_Diff_Renderer_inline from WordPress core.
* The following methods have been modified:
* - _lines: removed the encoding.
* - _changed: removed the new line at the end of the diff.
*/
class WPSEO_HTML_Diff_Renderer extends WP_Text_Diff_Renderer_inline {
// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore -- we are overriding a class.
// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore -- we are overriding a class.
/**
* Prefix for inserted text.
*
* @var string
*/
public $_ins_prefix = '<ins class="yst-diff">';
/**
* Prefix for deleted text.
*
* @var string
*/
public $_del_prefix = '<del class="yst-diff">';
/**
* Handles the rendering of lines.
* This method has been modified to remove the encoding.
*
* @param string[] $lines The lines to render.
* @param string $prefix The prefix (unused).
* @param bool $encode Whether to encode the lines (unused).
* @return string The rendered lines.
*/
public function _lines( $lines, $prefix = '', $encode = false ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- we are overriding a method.
return implode( '', $lines );
}
/**
* Handles the rendering of changed lines.
*
* @param string[] $orig The original text.
* @param string[] $new_ The new text.
* @return string The rendered diff.
*/
public function _changed( $orig, $new_ ) {
/* If we've already split on characters, just display. */
if ( $this->_split_level === 'characters' ) {
return $this->_deleted( $orig ) . $this->_added( $new_ );
}
/* If we've already split on words, just display. */
if ( $this->_split_level === 'words' ) {
$prefix = '';
while ( $orig[0] !== false
&& $new_[0] !== false
&& substr( $orig[0], 0, 1 ) === ' '
&& substr( $new_[0], 0, 1 ) === ' ' ) {
$prefix .= substr( $orig[0], 0, 1 );
$orig[0] = substr( $orig[0], 1 );
$new_[0] = substr( $new_[0], 1 );
}
return $prefix . $this->_deleted( $orig ) . $this->_added( $new_ );
}
$text1 = implode( "\n", $orig );
$text2 = implode( "\n", $new_ );
/* Non-printing newline marker. */
$nl = "\0";
if ( $this->_split_characters ) {
$diff = new Text_Diff(
'native',
[
preg_split( '//', $text1 ),
preg_split( '//', $text2 ),
]
);
}
else {
/*
* We want to split on word boundaries, but we need to preserve
* whitespace as well. Therefore we split on words, but include
* all blocks of whitespace in the wordlist.
*/
$diff = new Text_Diff(
'native',
[
$this->_splitOnWords( $text1, $nl ),
$this->_splitOnWords( $text2, $nl ),
]
);
}
/* Get the diff in inline format. */
$renderer = new WPSEO_HTML_Diff_Renderer(
array_merge(
$this->getParams(),
[ 'split_level' => ( $this->_split_characters ) ? 'characters' : 'words' ]
)
);
/* Run the diff and get the output. */
return str_replace( $nl, "\n", $renderer->render( $diff ) );
}
// phpcs:enable PSR2.Classes.PropertyDeclaration.Underscore
// phpcs:enable PSR2.Methods.MethodDeclaration.Underscore
}

View File

@@ -30,7 +30,7 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
add_action( 'admin_enqueue_scripts', [ $this, 'page_scripts' ] );
// Only set the hooks for the page where they are needed.
if ( ! $this->is_rest_request() && ! $this->post_redirect_can_be_made( $pagenow ) ) {
if ( ! wp_is_serving_rest_request() && ! $this->post_redirect_can_be_made( $pagenow ) ) {
return;
}
@@ -470,15 +470,6 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
return false;
}
/**
* Determines whether we're dealing with a REST request or not.
*
* @return bool Whether or not the current request is a REST request.
*/
private function is_rest_request() {
return defined( 'REST_REQUEST' ) && REST_REQUEST === true;
}
/**
* Returns the undo message for the post.
*
@@ -589,7 +580,7 @@ class WPSEO_Post_Watcher extends WPSEO_Watcher implements WPSEO_WordPress_Integr
*/
protected function set_undo_slug_notification( WPSEO_Redirect $redirect, $object_id, $object_type ) {
if ( ! $this->is_rest_request() && ! wp_doing_ajax() ) {
if ( ! wp_is_serving_rest_request() && ! wp_doing_ajax() ) {
parent::set_undo_slug_notification( $redirect, $object_id, $object_type );
return;

View File

@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore Yoast.Files.FileName.InvalidClassFileName -- Reason: this is an old premium file.
/**
* WPSEO Premium plugin file.
*
@@ -68,7 +68,7 @@ class WPSEO_Premium_Assets implements WPSEO_WordPress_Integration {
*
* @param string $version Current version number.
*
* @return array The scripts.
* @return array<array<string|array>> The scripts.
*/
protected function get_frontend_scripts( $version ) {
return [
@@ -101,7 +101,7 @@ class WPSEO_Premium_Assets implements WPSEO_WordPress_Integration {
*
* @param string $version Current version number.
*
* @return array The scripts.
* @return array<array<string|array>> The scripts.
*/
protected function get_scripts( $version ) {
return [
@@ -324,6 +324,26 @@ class WPSEO_Premium_Assets implements WPSEO_WordPress_Integration {
WPSEO_Admin_Asset_Manager::PREFIX . 'react-helmet-package',
],
],
[
'name' => 'wp-seo-premium-ai-fix-assessments',
'path' => 'assets/js/dist/',
'filename' => 'ai-fix-assessments-' . $version . WPSEO_CSSJS_SUFFIX . '.js',
'dependencies' => [
'lodash',
'regenerator-runtime',
'wp-api-fetch',
'wp-components',
'wp-data',
'wp-dom-ready',
'wp-element',
'wp-hooks',
'wp-i18n',
WPSEO_Admin_Asset_Manager::PREFIX . 'analysis',
WPSEO_Admin_Asset_Manager::PREFIX . 'editor-modules',
WPSEO_Admin_Asset_Manager::PREFIX . 'ui-library-package',
WPSEO_Admin_Asset_Manager::PREFIX . 'react-helmet-package',
],
],
[
'name' => 'wp-seo-premium-manage-ai-consent-button',
'path' => 'assets/js/dist/',
@@ -371,7 +391,7 @@ class WPSEO_Premium_Assets implements WPSEO_WordPress_Integration {
*
* @param string $version Current version number.
*
* @return array The styles.
* @return array<array<string|array>> The styles.
*/
protected function get_styles( $version ) {
$rtl_suffix = ( is_rtl() ) ? '-rtl' : '';
@@ -429,6 +449,14 @@ class WPSEO_Premium_Assets implements WPSEO_WordPress_Integration {
WPSEO_Admin_Asset_Manager::PREFIX . 'monorepo',
],
],
[
'name' => WPSEO_Admin_Asset_Manager::PREFIX . 'premium-ai-fix-assessments',
'source' => 'assets/css/dist/premium-ai-fix-assessments-' . $version . $rtl_suffix . '.css',
'dependencies' => [
WPSEO_Admin_Asset_Manager::PREFIX . 'premium-tailwind',
WPSEO_Admin_Asset_Manager::PREFIX . 'monorepo',
],
],
];
}
@@ -437,7 +465,7 @@ class WPSEO_Premium_Assets implements WPSEO_WordPress_Integration {
*
* @codeCoverageIgnore Method calls a WordPress function.
*
* @param array $script The script to register.
* @param array<string|array> $script The script to register.
*
* @return void
*/
@@ -464,7 +492,7 @@ class WPSEO_Premium_Assets implements WPSEO_WordPress_Integration {
*
* @codeCoverageIgnore Method calls a WordPress function.
*
* @param array $style The style to register.
* @param array<string|array> $style The style to register.
*
* @return void
*/

View File

@@ -118,13 +118,13 @@ class WPSEO_Premium_Keyword_Export_Manager implements WPSEO_WordPress_Integratio
*/
protected function get_csv_contents() {
$columns = [ 'keywords' ];
$post_wpseo = filter_input( INPUT_POST, 'wpseo', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
if ( is_array( $post_wpseo ) ) {
$columns = array_merge( $columns, $this->get_export_columns( $post_wpseo ) );
// phpcs:disable WordPress.Security.NonceVerification -- Reason: Nonce is checked in export.
if ( isset( $_POST['wpseo'] ) && is_array( $_POST['wpseo'] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: It will be sanitized after via an array map so that each individual value gets sanitized.
$post_wpseo = wp_unslash( $_POST['wpseo'] );
$post_wpseo = array_map( [ 'WPSEO_Utils', 'sanitize_text_field' ], $post_wpseo );
$columns = array_merge( $columns, $this->get_export_columns( $post_wpseo ) );
}
$builder = new WPSEO_Export_Keywords_CSV( $columns );
$builder->print_headers();
$this->prepare_export( $builder, $columns );

View File

@@ -186,7 +186,6 @@ class WPSEO_Premium_Metabox implements WPSEO_WordPress_Integration {
'wpseoTOCData',
[
'data' => [
'TOCTitle' => __( 'Table of contents', 'wordpress-seo-premium' ),
'disableTableOfContents' => $disable_table_of_content,
],
]

View File

@@ -125,9 +125,12 @@ class WPSEO_Redirect_Ajax {
if ( $validator->validate( $redirect, $current_redirect ) === true ) {
return;
}
$ignore_warning = filter_input( INPUT_POST, 'ignore_warning' );
$ignore_warning = 'false';
// phpcs:disable WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information and only comparing the variable in a condition.
if ( isset( $_POST['ignore_warning'] ) ) {
$ignore_warning = wp_unslash( $_POST['ignore_warning'] );
}
// phpcs:enable
$error = $validator->get_error();
if ( $error->get_type() === 'error' || ( $error->get_type() === 'warning' && $ignore_warning === 'false' ) ) {