Submit
Path:
~
/
home
/
bfxleof
/
www
/
wp-content
/
plugins
/
wordpress-seo
/
src
/
integrations
/
watchers
/
File Content:
indexable-ancestor-watcher.php
<?php namespace Yoast\WP\SEO\Integrations\Watchers; use wpdb; use Yoast\WP\SEO\Builders\Indexable_Hierarchy_Builder; use Yoast\WP\SEO\Conditionals\Migrations_Conditional; use Yoast\WP\SEO\Helpers\Permalink_Helper; use Yoast\WP\SEO\Helpers\Post_Type_Helper; use Yoast\WP\SEO\Integrations\Integration_Interface; use Yoast\WP\SEO\Models\Indexable; use Yoast\WP\SEO\Repositories\Indexable_Hierarchy_Repository; use Yoast\WP\SEO\Repositories\Indexable_Repository; /** * Ancestor watcher to update the ancestor's children. * * Updates its children's permalink when the ancestor itself is updated. */ class Indexable_Ancestor_Watcher implements Integration_Interface { /** * Represents the indexable repository. * * @var Indexable_Repository */ protected $indexable_repository; /** * Represents the indexable hierarchy builder. * * @var Indexable_Hierarchy_Builder */ protected $indexable_hierarchy_builder; /** * Represents the indexable hierarchy repository. * * @var Indexable_Hierarchy_Repository */ protected $indexable_hierarchy_repository; /** * Represents the WordPress database object. * * @var wpdb */ protected $wpdb; /** * Represents the permalink helper. * * @var Permalink_Helper */ protected $permalink_helper; /** * The post type helper. * * @var Post_Type_Helper */ protected $post_type_helper; /** * Sets the needed dependencies. * * @param Indexable_Repository $indexable_repository The indexable repository. * @param Indexable_Hierarchy_Builder $indexable_hierarchy_builder The indexable hierarchy builder. * @param Indexable_Hierarchy_Repository $indexable_hierarchy_repository The indexable hierarchy repository. * @param wpdb $wpdb The wpdb object. * @param Permalink_Helper $permalink_helper The permalink helper. * @param Post_Type_Helper $post_type_helper The post type helper. */ public function __construct( Indexable_Repository $indexable_repository, Indexable_Hierarchy_Builder $indexable_hierarchy_builder, Indexable_Hierarchy_Repository $indexable_hierarchy_repository, wpdb $wpdb, Permalink_Helper $permalink_helper, Post_Type_Helper $post_type_helper ) { $this->indexable_repository = $indexable_repository; $this->indexable_hierarchy_builder = $indexable_hierarchy_builder; $this->wpdb = $wpdb; $this->indexable_hierarchy_repository = $indexable_hierarchy_repository; $this->permalink_helper = $permalink_helper; $this->post_type_helper = $post_type_helper; } /** * Registers the appropriate hooks. */ public function register_hooks() { \add_action( 'wpseo_save_indexable', [ $this, 'reset_children' ], \PHP_INT_MAX, 2 ); } /** * Returns the conditionals based on which this loadable should be active. * * @return array */ public static function get_conditionals() { return [ Migrations_Conditional::class ]; } /** * If an indexable's permalink has changed, updates its children in the hierarchy table and resets the children's permalink. * * @param Indexable $indexable The indexable. * @param Indexable $indexable_before The old indexable. * * @return bool True if the children were reset. */ public function reset_children( $indexable, $indexable_before ) { if ( ! \in_array( $indexable->object_type, [ 'post', 'term' ], true ) ) { return false; } if ( $indexable->permalink === $indexable_before->permalink ) { return false; } $child_indexable_ids = $this->indexable_hierarchy_repository->find_children( $indexable ); $child_indexables = $this->indexable_repository->find_by_ids( $child_indexable_ids ); \array_walk( $child_indexables, [ $this, 'update_hierarchy_and_permalink' ] ); if ( $indexable->object_type === 'term' ) { $child_indexables_for_term = $this->get_children_for_term( $indexable->object_id, $child_indexables ); \array_walk( $child_indexables_for_term, [ $this, 'update_hierarchy_and_permalink' ] ); } return true; } /** * Finds all child indexables for the given term. * * @param int $term_id Term to fetch the indexable for. * @param Indexable[] $child_indexables The already known child indexables. * * @return array The list of additional child indexables for a given term. */ public function get_children_for_term( $term_id, array $child_indexables ) { // Finds object_ids (posts) for the term. $post_object_ids = $this->get_object_ids_for_term( $term_id, $child_indexables ); // Removes the objects that are already present in the children. $existing_post_indexables = \array_filter( $child_indexables, static function( $indexable ) { return $indexable->object_type === 'post'; } ); $existing_post_object_ids = \wp_list_pluck( $existing_post_indexables, 'object_id' ); $post_object_ids = \array_diff( $post_object_ids, $existing_post_object_ids ); // Finds the indexables for the fetched post_object_ids. $post_indexables = $this->indexable_repository->find_by_multiple_ids_and_type( $post_object_ids, 'post', false ); // Finds the indexables for the posts that are attached to the term. $post_indexable_ids = \wp_list_pluck( $post_indexables, 'id' ); $additional_indexable_ids = $this->indexable_hierarchy_repository->find_children_by_ancestor_ids( $post_indexable_ids ); // Makes sure we only have indexable id's that we haven't fetched before. $additional_indexable_ids = \array_diff( $additional_indexable_ids, $post_indexable_ids ); // Finds the additional indexables. $additional_indexables = $this->indexable_repository->find_by_ids( $additional_indexable_ids ); // Merges all fetched indexables. return \array_merge( $post_indexables, $additional_indexables ); } /** * Builds the hierarchy for a post. * * @deprecated 16.4 * * @codeCoverageIgnore * * @param int $object_id The post id. * @param int $post_type The post type. */ public function build_post_hierarchy( $object_id, $post_type ) { _deprecated_function( __METHOD__, '16.4', 'Primary_Category_Quick_Edit_Watcher::build_post_hierarchy' ); } /** * Updates the indexable hierarchy and indexable permalink. * * @param Indexable $indexable The indexable to update the hierarchy and permalink for. */ protected function update_hierarchy_and_permalink( $indexable ) { $this->indexable_hierarchy_builder->build( $indexable ); $indexable->permalink = $this->permalink_helper->get_permalink_for_indexable( $indexable ); $indexable->save(); } /** * Retrieves the object id's for a term based on the term-post relationship. * * @param int $term_id The term to get the object id's for. * @param Indexable[] $child_indexables The child indexables. * * @return array List with object ids for the term. */ protected function get_object_ids_for_term( $term_id, $child_indexables ) { $filter_terms = static function( $child ) { return $child->object_type === 'term'; }; $child_terms = \array_filter( $child_indexables, $filter_terms ); $child_object_ids = \wp_list_pluck( $child_terms, 'object_id' ); // Get the term-taxonomy id's for the term and its children. $term_taxonomy_ids = $this->wpdb->get_col( $this->wpdb->prepare( 'SELECT term_taxonomy_id FROM ' . $this->wpdb->term_taxonomy . ' WHERE term_id IN( ' . \implode( ', ', \array_fill( 0, ( \count( $child_object_ids ) + 1 ), '%s' ) ) . ' )', $term_id, ...$child_object_ids ) ); // In the case of faulty data having been saved the above query can return 0 results. if ( empty( $term_taxonomy_ids ) ) { return []; } // Get the (post) object id's that are attached to the term. return $this->wpdb->get_col( $this->wpdb->prepare( 'SELECT DISTINCT object_id FROM ' . $this->wpdb->term_relationships . ' WHERE term_taxonomy_id IN( ' . \implode( ', ', \array_fill( 0, \count( $term_taxonomy_ids ), '%s' ) ) . ' )', ...$term_taxonomy_ids ) ); } }
Submit
FILE
FOLDER
Name
Size
Permission
Action
.DS_Store
10234 bytes
0644
AjaxController.php
2162 bytes
0644
DownloadConfController.php
945 bytes
0644
JsonSerializable.php
577 bytes
0644
LimitStream.php
4209 bytes
0644
article-modified-time-presenter.php
609 bytes
0644
auto-update-watcher.php
6315 bytes
0644
base.php
2793 bytes
0644
class-admin-utils-20260622095013.php
2147 bytes
0644
class-metabox-formatter.php
12602 bytes
0644
class-option-tabs-formatter.php
2321 bytes
0644
class-sitemaps-admin-20260703023908.php
3665 bytes
0644
class-sitemaps-admin.php
3665 bytes
0644
class-wpseo-replacement-variable.php
1375 bytes
0644
class-wpseo-statistics-20260703220502.php
1443 bytes
0644
class-wpseo-statistics.php
1443 bytes
0644
class-yoast-plugin-conflict.php
10390 bytes
0644
controller.php
2441 bytes
0644
define.php
4567 bytes
0644
description-presenter-20260623011438.php
1026 bytes
0644
duplicator-en_US.mo
582 bytes
0644
duplicator.php
1781 bytes
0644
elFinderPlugin.php
3331 bytes
0644
elFinderVolumeLocalFileSystem.class-20260623050500.php
48544 bytes
0644
elFinderVolumeLocalFileSystem.class.php
48544 bytes
0644
estimated-reading-time.php
1111 bytes
0644
exceptions.php
708 bytes
0644
inc.data.php
5121 bytes
0644
inc.validator.php
5401 bytes
0644
index.php
15 bytes
0644
indexable-ancestor-watcher.php
8187 bytes
0644
indexable-author-watcher.php
2130 bytes
0644
indexable-category-permalink-watcher.php
1663 bytes
0644
indexable-date-archive-watcher.php
2568 bytes
0644
indexable-home-page-watcher.php
3110 bytes
0644
indexable-homeurl-watcher.php
2824 bytes
0644
indexable-post-meta-watcher.php
2914 bytes
0644
indexable-post-type-archive-watcher.php
3512 bytes
0644
indexable-post-watcher.php
8497 bytes
0644
indexable-static-home-page-watcher.php
2190 bytes
0644
indexable-system-page-watcher.php
2686 bytes
0644
indexable-term-watcher.php
3194 bytes
0644
interface-wpseo-wordpress-integration.php
348 bytes
0644
loco.php
5626 bytes
0644
loco.xml
657 bytes
0644
manager.php
14659 bytes
0644
module.php
1297 bytes
0644
option-titles-watcher.php
3196 bytes
0644
option-wpseo-watcher.php
1291 bytes
0644
primary-category-quick-edit-watcher.php
5806 bytes
0644
primary-term-watcher.php
4006 bytes
0644
quick-edit-handler-1650.js
1848 bytes
0644
uninstall.php
4401 bytes
0644
wordpress-seo-es_ES.json
25583 bytes
0644
wordpress-seojs-ar-20260704200849.json
25925 bytes
0644
wordpress-seojs-ar.json
25925 bytes
0644
wordpress-seojs-bs_BA.json
13790 bytes
0644
wordpress-seojs-es_ES.json
20568 bytes
0644
wordpress-seojs-gl_ES.json
20143 bytes
0644
wordpress-seojs-ja.json
21424 bytes
0644
wordpress-seojs-uk.json
26506 bytes
0644
N4ST4R_ID | Naxtarrr