| Server IP : 68.183.124.220 / Your IP : 216.73.217.137 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/wp-content/plugins/wordpress-seo/src/watchers/ |
Upload File : |
<?php
/**
* Author watcher to save the meta data to an Indexable.
*
* @package Yoast\YoastSEO\Watchers
*/
namespace Yoast\WP\Free\Watchers;
use Yoast\WP\Free\Conditionals\Indexables_Feature_Flag_Conditional;
use Yoast\WP\Free\Builders\Indexable_Author_Builder;
use Yoast\WP\Free\Repositories\Indexable_Repository;
use Yoast\WP\Free\WordPress\Integration;
/**
* Watches an Author to save the meta information when updated.
*/
class Indexable_Author_Watcher implements Integration {
/**
* @inheritdoc
*/
public static function get_conditionals() {
return [ Indexables_Feature_Flag_Conditional::class ];
}
/**
* @var \Yoast\WP\Free\Repositories\Indexable_Repository
*/
protected $repository;
/**
* @var \Yoast\WP\Free\Builders\Indexable_Author_Builder
*/
protected $builder;
/**
* Indexable_Author_Watcher constructor.
*
* @param \Yoast\WP\Free\Repositories\Indexable_Repository $repository The repository to use.
* @param \Yoast\WP\Free\Builders\Indexable_Author_Builder $builder The post builder to use.
*/
public function __construct( Indexable_Repository $repository, Indexable_Author_Builder $builder ) {
$this->repository = $repository;
$this->builder = $builder;
}
/**
* @inheritdoc
*/
public function register_hooks() {
\add_action( 'profile_update', [ $this, 'build_indexable' ], \PHP_INT_MAX );
\add_action( 'deleted_user', [ $this, 'delete_indexable' ] );
}
/**
* Deletes user meta.
*
* @param int $user_id User ID to delete the metadata of.
*
* @return void
*/
public function delete_indexable( $user_id ) {
$indexable = $this->repository->find_by_id_and_type( $user_id, 'user', false );
if ( ! $indexable ) {
return;
}
$indexable->delete();
}
/**
* Saves user meta.
*
* @param int $user_id User ID.
*
* @return void
*/
public function build_indexable( $user_id ) {
$indexable = $this->repository->find_by_id_and_type( $user_id, 'user', false );
// If we haven't found an existing indexable, create it. Otherwise update it.
$indexable = ( $indexable === false ) ? $this->repository->create_for_id_and_type( $user_id, 'user' ) : $this->builder->build( $user_id, $indexable );
$indexable->save();
}
}