| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wp-content/plugins/wordpress-seo/src/integrations/watchers/ |
Upload File : |
<?php
namespace Yoast\WP\SEO\Integrations\Watchers;
use Yoast\WP\Lib\Model;
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast\WP\SEO\WordPress\Wrapper;
/**
* Watcher for the titles option.
*
* Represents the option titles watcher.
*/
class Option_Titles_Watcher implements Integration_Interface {
/**
* Initializes the integration.
*
* This is the place to register hooks and filters.
*
* @return void
*/
public function register_hooks() {
\add_action( 'update_option_wpseo_titles', [ $this, 'check_option' ], 10, 2 );
}
/**
* Returns the conditionals based on which this loadable should be active.
*
* @return array<Migrations_Conditional>
*/
public static function get_conditionals() {
return [ Migrations_Conditional::class ];
}
/**
* Checks if one of the relevant options has been changed.
*
* @param array<string|int|bool> $old_value The old value of the option.
* @param array<string|int|bool> $new_value The new value of the option.
*
* @return bool Whether or not the ancestors are removed.
*/
public function check_option( $old_value, $new_value ) {
// If this is the first time saving the option, thus when value is false.
if ( $old_value === false ) {
$old_value = [];
}
if ( ! \is_array( $old_value ) || ! \is_array( $new_value ) ) {
return false;
}
$relevant_keys = $this->get_relevant_keys();
if ( empty( $relevant_keys ) ) {
return false;
}
$post_types = [];
foreach ( $relevant_keys as $post_type => $relevant_option ) {
// If both values aren't set they haven't changed.
if ( ! isset( $old_value[ $relevant_option ] ) && ! isset( $new_value[ $relevant_option ] ) ) {
continue;
}
if ( $old_value[ $relevant_option ] !== $new_value[ $relevant_option ] ) {
$post_types[] = $post_type;
}
}
return $this->delete_ancestors( $post_types );
}
/**
* Retrieves the relevant keys.
*
* @return array<string> Array with the relevant keys.
*/
protected function get_relevant_keys() {
$post_types = \get_post_types( [ 'public' => true ], 'names' );
if ( ! \is_array( $post_types ) || $post_types === [] ) {
return [];
}
$relevant_keys = [];
foreach ( $post_types as $post_type ) {
$relevant_keys[ $post_type ] = 'post_types-' . $post_type . '-maintax';
}
return $relevant_keys;
}
/**
* Removes the ancestors for given post types.
*
* @param array<string> $post_types The post types to remove hierarchy for.
*
* @return bool True when delete query was successful.
*/
protected function delete_ancestors( $post_types ) {
if ( empty( $post_types ) ) {
return false;
}
$wpdb = Wrapper::get_wpdb();
$hierarchy_table = Model::get_table_name( 'Indexable_Hierarchy' );
$indexable_table = Model::get_table_name( 'Indexable' );
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Delete query.
$result = $wpdb->query(
$wpdb->prepare(
"
DELETE FROM %i
WHERE indexable_id IN(
SELECT id
FROM %i
WHERE object_type = 'post'
AND object_sub_type IN( " . \implode( ', ', \array_fill( 0, \count( $post_types ), '%s' ) ) . ' )
)',
$hierarchy_table,
$indexable_table,
...$post_types,
),
);
return $result !== false;
}
}