| 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\SEO\Builders\Indexable_Builder;
use Yoast\WP\SEO\Builders\Indexable_Link_Builder;
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
use Yoast\WP\SEO\Helpers\Indexable_Helper;
use Yoast\WP\SEO\Helpers\Site_Helper;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast\WP\SEO\Repositories\Indexable_Repository;
/**
* Watches Terms/Taxonomies to fill the related Indexable.
*/
class Indexable_Term_Watcher implements Integration_Interface {
/**
* The indexable repository.
*
* @var Indexable_Repository
*/
protected $repository;
/**
* The indexable builder.
*
* @var Indexable_Builder
*/
protected $builder;
/**
* The link builder.
*
* @var Indexable_Link_Builder
*/
protected $link_builder;
/**
* The indexable helper.
*
* @var Indexable_Helper
*/
private $indexable_helper;
/**
* Represents the site helper.
*
* @var Site_Helper
*/
protected $site;
/**
* Returns the conditionals based on which this loadable should be active.
*
* @return array
*/
public static function get_conditionals() {
return [ Migrations_Conditional::class ];
}
/**
* Indexable_Term_Watcher constructor.
*
* @param Indexable_Repository $repository The repository to use.
* @param Indexable_Builder $builder The post builder to use.
* @param Indexable_Link_Builder $link_builder The lint builder to use.
* @param Indexable_Helper $indexable_helper The indexable helper.
* @param Site_Helper $site The site helper.
*/
public function __construct(
Indexable_Repository $repository,
Indexable_Builder $builder,
Indexable_Link_Builder $link_builder,
Indexable_Helper $indexable_helper,
Site_Helper $site
) {
$this->repository = $repository;
$this->builder = $builder;
$this->link_builder = $link_builder;
$this->indexable_helper = $indexable_helper;
$this->site = $site;
}
/**
* Registers the hooks.
*
* @return void
*/
public function register_hooks() {
\add_action( 'created_term', [ $this, 'build_indexable' ], \PHP_INT_MAX );
\add_action( 'edited_term', [ $this, 'build_indexable' ], \PHP_INT_MAX );
\add_action( 'delete_term', [ $this, 'delete_indexable' ], \PHP_INT_MAX );
}
/**
* Deletes a term from the index.
*
* @param int $term_id The Term ID to delete.
*
* @return void
*/
public function delete_indexable( $term_id ) {
$indexable = $this->repository->find_by_id_and_type( $term_id, 'term', false );
if ( ! $indexable ) {
return;
}
$indexable->delete();
\do_action( 'wpseo_indexable_deleted', $indexable );
}
/**
* Update the taxonomy meta data on save.
*
* @param int $term_id ID of the term to save data for.
*
* @return void
*/
public function build_indexable( $term_id ) {
// Bail if this is a multisite installation and the site has been switched.
if ( $this->site->is_multisite_and_switched() ) {
return;
}
$term = \get_term( $term_id );
if ( $term === null || \is_wp_error( $term ) ) {
return;
}
if ( ! \is_taxonomy_viewable( $term->taxonomy ) ) {
return;
}
$indexable = $this->repository->find_by_id_and_type( $term_id, 'term', false );
// If we haven't found an existing indexable, create it. Otherwise update it.
$indexable = $this->builder->build_for_id_and_type( $term_id, 'term', $indexable );
if ( ! $indexable ) {
return;
}
// Update links.
$this->link_builder->build( $indexable, $term->description );
$indexable->object_last_modified = \max( $indexable->object_last_modified, \current_time( 'mysql' ) );
$this->indexable_helper->save_indexable( $indexable );
}
}