plugin updates

This commit is contained in:
Tony Volpe
2024-06-17 15:33:26 -04:00
parent 3751a5a1a6
commit e4e274a9a7
2674 changed files with 0 additions and 507851 deletions

View File

@@ -1,77 +0,0 @@
<?php
namespace Yoast\WP\SEO\User_Meta\Application;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The collector to get additional contactmethods.
*
* @makePublic
*/
class Additional_Contactmethods_Collector {
/**
* All additional contactmethods.
*
* @var array<Additional_Contactmethod_Interface> $additional_contactmethods
*/
private $additional_contactmethods;
/**
* The constructor.
*
* @param Additional_Contactmethod_Interface ...$additional_contactmethods All additional contactmethods.
*/
public function __construct( Additional_Contactmethod_Interface ...$additional_contactmethods ) {
$this->additional_contactmethods = $additional_contactmethods;
}
/**
* Returns all the additional contactmethods.
*
* @return array<Additional_Contactmethod_Interface> All the additional contactmethods.
*/
public function get_additional_contactmethods(): array {
$additional_contactmethods = $this->additional_contactmethods;
/**
* Filter: Adds the possibility to add more additional contactmethods in the user profile.
*
* @param array<Additional_Contactmethod_Interface> $additional_contactmethods Array with additional contact method classes.
*/
return \apply_filters( 'wpseo_additional_contactmethods', $additional_contactmethods );
}
/**
* Returns the additional contactmethods key/value pairs.
*
* @return array<string, string> The additional contactmethods key/value pairs.
*/
public function get_additional_contactmethods_objects(): array {
$additional_contactmethods_objects = [];
$additional_contactmethods = $this->get_additional_contactmethods();
foreach ( $additional_contactmethods as $additional_contactmethod ) {
$additional_contactmethods_objects[ $additional_contactmethod->get_key() ] = $additional_contactmethod->get_label();
}
return $additional_contactmethods_objects;
}
/**
* Returns the additional contactmethods keys.
*
* @return array<string> The additional contactmethods keys.
*/
public function get_additional_contactmethods_keys(): array {
$additional_contactmethods_keys = [];
$additional_contactmethods = $this->get_additional_contactmethods();
foreach ( $additional_contactmethods as $additional_contactmethod ) {
$additional_contactmethods_keys[] = $additional_contactmethod->get_key();
}
return $additional_contactmethods_keys;
}
}

View File

@@ -1,74 +0,0 @@
<?php
namespace Yoast\WP\SEO\User_Meta\Application;
use Yoast\WP\SEO\User_Meta\Infrastructure\Cleanup_Repository;
/**
* Service with all usermeta cleanup queries.
*/
class Cleanup_Service {
/**
* The additional contactmethods collector.
*
* @var Additional_Contactmethods_Collector $additional_contactmethods_collector The additional contactmethods collector.
*/
private $additional_contactmethods_collector;
/**
* The custom meta collector.
*
* @var Custom_Meta_Collector $custom_meta_collector The custom meta collector.
*/
private $custom_meta_collector;
/**
* The cleanup repository.
*
* @var Cleanup_Repository $custom_meta_collector The custom meta repository.
*/
private $cleanup_repository;
/**
* The constructor.
*
* @param Additional_Contactmethods_Collector $additional_contactmethods_collector The additional contactmethods collector.
* @param Custom_Meta_Collector $custom_meta_collector The custom meta collector.
* @param Cleanup_Repository $cleanup_repository The cleanup repository.
*/
public function __construct(
Additional_Contactmethods_Collector $additional_contactmethods_collector,
Custom_Meta_Collector $custom_meta_collector,
Cleanup_Repository $cleanup_repository
) {
$this->additional_contactmethods_collector = $additional_contactmethods_collector;
$this->custom_meta_collector = $custom_meta_collector;
$this->cleanup_repository = $cleanup_repository;
}
/**
* Deletes selected empty usermeta.
*
* @param int $limit The limit we'll apply to the cleanups.
*
* @return int|bool The number of rows that was deleted or false if the query failed.
*/
public function cleanup_selected_empty_usermeta( int $limit ) {
$meta_to_check = $this->get_meta_to_check();
return $this->cleanup_repository->delete_empty_usermeta_query( $meta_to_check, $limit );
}
/**
* Gets which meta are going to be checked for emptiness.
*
* @return array<string> The meta to be checked for emptiness.
*/
private function get_meta_to_check() {
$additional_contactmethods = $this->additional_contactmethods_collector->get_additional_contactmethods_keys();
$custom_meta = $this->custom_meta_collector->get_non_empty_custom_meta();
return \array_merge( $additional_contactmethods, $custom_meta );
}
}

View File

@@ -1,54 +0,0 @@
<?php
namespace Yoast\WP\SEO\User_Meta\Application;
use Yoast\WP\SEO\User_Meta\Domain\Custom_Meta_Interface;
/**
* The collector to get custom user meta.
*
* @makePublic
*/
class Custom_Meta_Collector {
/**
* All custom meta.
*
* @var array<Custom_Meta_Interface> $custom_meta
*/
private $custom_meta;
/**
* The constructor.
*
* @param Custom_Meta_Interface ...$custom_meta All custom meta.
*/
public function __construct( Custom_Meta_Interface ...$custom_meta ) {
$this->custom_meta = $custom_meta;
}
/**
* Returns all the custom meta.
*
* @return array<Custom_Meta_Interface> All the custom meta.
*/
public function get_custom_meta(): array {
return $this->custom_meta;
}
/**
* Returns the custom meta that can't be empty.
*
* @return array<string> The custom meta that can't be empty.
*/
public function get_non_empty_custom_meta(): array {
$non_empty_custom_meta = [];
foreach ( $this->custom_meta as $custom_meta ) {
if ( ! $custom_meta->is_empty_allowed() ) {
$non_empty_custom_meta[] = $custom_meta->get_key();
}
}
return $non_empty_custom_meta;
}
}

View File

@@ -1,23 +0,0 @@
<?php
namespace Yoast\WP\SEO\User_Meta\Domain;
/**
* This interface describes an additional contactmethod.
*/
interface Additional_Contactmethod_Interface {
/**
* Returns the key of the contactmethod.
*
* @return string
*/
public function get_key(): string;
/**
* Returns the label of the contactmethod field.
*
* @return string
*/
public function get_label(): string;
}

View File

@@ -1,30 +0,0 @@
<?php
namespace Yoast\WP\SEO\User_Meta\Domain;
/**
* This interface describes a custom meta.
*/
interface Custom_Meta_Interface {
/**
* Returns the db key of the custom meta.
*
* @return string
*/
public function get_key(): string;
/**
* Returns the id of the custom meta's form field.
*
* @return string
*/
public function get_field_id(): string;
/**
* Returns whether the custom meta is allowed to be empty.
*
* @return bool
*/
public function is_empty_allowed(): bool;
}

View File

@@ -1,30 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Additional_Contactmethods;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The Facebook contactmethod.
*/
class Facebook implements Additional_Contactmethod_Interface {
/**
* Returns the key of the Facebook contactmethod.
*
* @return string The key of the Facebook contactmethod.
*/
public function get_key(): string {
return 'facebook';
}
/**
* Returns the label of the Facebook field.
*
* @return string The label of the Facebook field.
*/
public function get_label(): string {
return \__( 'Facebook profile URL', 'wordpress-seo' );
}
}

View File

@@ -1,30 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Additional_Contactmethods;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The Instagram contactmethod.
*/
class Instagram implements Additional_Contactmethod_Interface {
/**
* Returns the key of the Instagram contactmethod.
*
* @return string The key of the Instagram contactmethod.
*/
public function get_key(): string {
return 'instagram';
}
/**
* Returns the label of the Instagram field.
*
* @return string The label of the Instagram field.
*/
public function get_label(): string {
return \__( 'Instagram profile URL', 'wordpress-seo' );
}
}

View File

@@ -1,30 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Additional_Contactmethods;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The Linkedin contactmethod.
*/
class Linkedin implements Additional_Contactmethod_Interface {
/**
* Returns the key of the Linkedin contactmethod.
*
* @return string The key of the Linkedin contactmethod.
*/
public function get_key(): string {
return 'linkedin';
}
/**
* Returns the label of the Linkedin field.
*
* @return string The label of the Linkedin field.
*/
public function get_label(): string {
return \__( 'LinkedIn profile URL', 'wordpress-seo' );
}
}

View File

@@ -1,30 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Additional_Contactmethods;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The Myspace contactmethod.
*/
class Myspace implements Additional_Contactmethod_Interface {
/**
* Returns the key of the MySpace contactmethod.
*
* @return string The key of the MySpace contactmethod.
*/
public function get_key(): string {
return 'myspace';
}
/**
* Returns the label of the MySpace field.
*
* @return string The label of the MySpace field.
*/
public function get_label(): string {
return \__( 'MySpace profile URL', 'wordpress-seo' );
}
}

View File

@@ -1,30 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Additional_Contactmethods;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The Pinterest contactmethod.
*/
class Pinterest implements Additional_Contactmethod_Interface {
/**
* Returns the key of the Pinterest contactmethod.
*
* @return string The key of the Pinterest contactmethod.
*/
public function get_key(): string {
return 'pinterest';
}
/**
* Returns the label of the Pinterest field.
*
* @return string The label of the Pinterest field.
*/
public function get_label(): string {
return \__( 'Pinterest profile URL', 'wordpress-seo' );
}
}

View File

@@ -1,30 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Additional_Contactmethods;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The Soundcloud contactmethod.
*/
class Soundcloud implements Additional_Contactmethod_Interface {
/**
* Returns the key of the SoundCloud contactmethod.
*
* @return string The key of the SoundCloud contactmethod.
*/
public function get_key(): string {
return 'soundcloud';
}
/**
* Returns the label of the SoundCloud field.
*
* @return string The label of the SoundCloud field.
*/
public function get_label(): string {
return \__( 'SoundCloud profile URL', 'wordpress-seo' );
}
}

View File

@@ -1,30 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Additional_Contactmethods;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The Tumblr contactmethod.
*/
class Tumblr implements Additional_Contactmethod_Interface {
/**
* Returns the key of the Tumblr contactmethod.
*
* @return string The key of the Tumblr contactmethod.
*/
public function get_key(): string {
return 'tumblr';
}
/**
* Returns the label of the Tumblr field.
*
* @return string The label of the Tumblr field.
*/
public function get_label(): string {
return \__( 'Tumblr profile URL', 'wordpress-seo' );
}
}

View File

@@ -1,30 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Additional_Contactmethods;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The Wikipedia contactmethod.
*/
class Wikipedia implements Additional_Contactmethod_Interface {
/**
* Returns the key of the Wikipedia contactmethod.
*
* @return string The key of the Wikipedia contactmethod.
*/
public function get_key(): string {
return 'wikipedia';
}
/**
* Returns the label of the Wikipedia field.
*
* @return string The label of the Wikipedia field.
*/
public function get_label(): string {
return \__( 'Wikipedia page about you', 'wordpress-seo' ) . '<br/><small>' . \__( '(if one exists)', 'wordpress-seo' ) . '</small>';
}
}

View File

@@ -1,30 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Additional_Contactmethods;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The X contactmethod.
*/
class X implements Additional_Contactmethod_Interface {
/**
* Returns the key of the X contactmethod.
*
* @return string The key of the X contactmethod.
*/
public function get_key(): string {
return 'twitter';
}
/**
* Returns the label of the X field.
*
* @return string The label of the X field.
*/
public function get_label(): string {
return \__( 'X username (without @)', 'wordpress-seo' );
}
}

View File

@@ -1,30 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Additional_Contactmethods;
use Yoast\WP\SEO\User_Meta\Domain\Additional_Contactmethod_Interface;
/**
* The Youtube contactmethod.
*/
class Youtube implements Additional_Contactmethod_Interface {
/**
* Returns the key of the YouTube contactmethod.
*
* @return string The key of the YouTube contactmethod.
*/
public function get_key(): string {
return 'youtube';
}
/**
* Returns the label of the YouTube field.
*
* @return string The label of the YouTube field.
*/
public function get_label(): string {
return \__( 'YouTube profile URL', 'wordpress-seo' );
}
}

View File

@@ -1,39 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Custom_Meta;
use Yoast\WP\SEO\User_Meta\Domain\Custom_Meta_Interface;
/**
* The Author_Metadesc custom meta.
*/
class Author_Metadesc implements Custom_Meta_Interface {
/**
* Returns the db key of the Author_Metadesc custom meta.
*
* @return string The db key of the Author_Metadesc custom meta.
*/
public function get_key(): string {
return 'wpseo_metadesc';
}
/**
* Returns the id of the custom meta's form field.
*
* @return string The id of the custom meta's form field.
*/
public function get_field_id(): string {
return 'wpseo_author_metadesc';
}
/**
* Returns whether the custom meta is allowed to be empty.
*
* @return bool Whether the custom meta is allowed to be empty.
*/
public function is_empty_allowed(): bool {
return true;
}
}

View File

@@ -1,39 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Custom_Meta;
use Yoast\WP\SEO\User_Meta\Domain\Custom_Meta_Interface;
/**
* The Author_Title custom meta.
*/
class Author_Title implements Custom_Meta_Interface {
/**
* Returns the db key of the Author_Title custom meta.
*
* @return string The db key of the Author_Title custom meta.
*/
public function get_key(): string {
return 'wpseo_title';
}
/**
* Returns the id of the custom meta's form field.
*
* @return string The id of the custom meta's form field.
*/
public function get_field_id(): string {
return 'wpseo_author_title';
}
/**
* Returns whether the custom meta is allowed to be empty.
*
* @return bool Whether the custom meta is allowed to be empty.
*/
public function is_empty_allowed(): bool {
return true;
}
}

View File

@@ -1,39 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Custom_Meta;
use Yoast\WP\SEO\User_Meta\Domain\Custom_Meta_Interface;
/**
* The Content_Analysis_Disable custom meta.
*/
class Content_Analysis_Disable implements Custom_Meta_Interface {
/**
* Returns the db key of the Content_Analysis_Disable custom meta.
*
* @return string The db key of the Content_Analysis_Disable custom meta.
*/
public function get_key(): string {
return 'wpseo_content_analysis_disable';
}
/**
* Returns the id of the custom meta's form field.
*
* @return string The id of the custom meta's form field.
*/
public function get_field_id(): string {
return 'wpseo_content_analysis_disable';
}
/**
* Returns whether the custom meta is allowed to be empty.
*
* @return bool Whether the custom meta is allowed to be empty.
*/
public function is_empty_allowed(): bool {
return true;
}
}

View File

@@ -1,39 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Custom_Meta;
use Yoast\WP\SEO\User_Meta\Domain\Custom_Meta_Interface;
/**
* The Inclusive_Language_Analysis_Disable custom meta.
*/
class Inclusive_Language_Analysis_Disable implements Custom_Meta_Interface {
/**
* Returns the db key of the Inclusive_Language_Analysis_Disable custom meta.
*
* @return string The db key of the Inclusive_Language_Analysis_Disable custom meta.
*/
public function get_key(): string {
return 'wpseo_inclusive_language_analysis_disable';
}
/**
* Returns the id of the custom meta's form field.
*
* @return string The id of the custom meta's form field.
*/
public function get_field_id(): string {
return 'wpseo_inclusive_language_analysis_disable';
}
/**
* Returns whether the custom meta is allowed to be empty.
*
* @return bool Whether the custom meta is allowed to be empty.
*/
public function is_empty_allowed(): bool {
return true;
}
}

View File

@@ -1,39 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Custom_Meta;
use Yoast\WP\SEO\User_Meta\Domain\Custom_Meta_Interface;
/**
* The Keyword_Analysis_Disable custom meta.
*/
class Keyword_Analysis_Disable implements Custom_Meta_Interface {
/**
* Returns the db key of the Keyword_Analysis_Disable custom meta.
*
* @return string The db key of the Keyword_Analysis_Disable custom meta.
*/
public function get_key(): string {
return 'wpseo_keyword_analysis_disable';
}
/**
* Returns the id of the custom meta's form field.
*
* @return string The id of the custom meta's form field.
*/
public function get_field_id(): string {
return 'wpseo_keyword_analysis_disable';
}
/**
* Returns whether the custom meta is allowed to be empty.
*
* @return bool Whether the custom meta is allowed to be empty.
*/
public function is_empty_allowed(): bool {
return true;
}
}

View File

@@ -1,39 +0,0 @@
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\User_Meta\Framework\Custom_Meta;
use Yoast\WP\SEO\User_Meta\Domain\Custom_Meta_Interface;
/**
* The Noindex_Author custom meta.
*/
class Noindex_Author implements Custom_Meta_Interface {
/**
* Returns the db key of the Noindex_Author custom meta.
*
* @return string The db key of the Noindex_Author custom meta.
*/
public function get_key(): string {
return 'wpseo_noindex_author';
}
/**
* Returns the id of the custom meta's form field.
*
* @return string The id of the custom meta's form field.
*/
public function get_field_id(): string {
return 'wpseo_noindex_author';
}
/**
* Returns whether the custom meta is allowed to be empty.
*
* @return bool Whether the custom meta is allowed to be empty.
*/
public function is_empty_allowed(): bool {
return false;
}
}

View File

@@ -1,38 +0,0 @@
<?php
namespace Yoast\WP\SEO\User_Meta\Infrastructure;
/**
* Repository going into the database to clean up.
*/
class Cleanup_Repository {
/**
* Deletes empty usermeta based on their meta_keys and returns the number of the deleted meta.
*
* @param array<string> $meta_keys The meta to be potentially deleted.
* @param int $limit The number of maximum deletions.
*
* @return int|false The number of rows that was deleted or false if the query failed.
*/
public function delete_empty_usermeta_query( $meta_keys, $limit ) {
global $wpdb;
// phpcs:disable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- Reason: we're passing an array instead.
$delete_query = $wpdb->prepare(
'DELETE FROM %i
WHERE meta_key IN ( ' . \implode( ', ', \array_fill( 0, \count( $meta_keys ), '%s' ) ) . ' )
AND meta_value = ""
ORDER BY user_id
LIMIT %d',
\array_merge( [ $wpdb->usermeta ], $meta_keys, [ $limit ] )
);
// phpcs:enable
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
return $wpdb->query( $delete_query );
// phpcs:enable
}
}

View File

@@ -1,77 +0,0 @@
<?php
namespace Yoast\WP\SEO\User_Meta\User_Interface;
use Yoast\WP\SEO\Conditionals\No_Conditionals;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast\WP\SEO\User_Meta\Application\Additional_Contactmethods_Collector;
/**
* Handles registering and saving additional contactmethods for users.
*/
class Additional_Contactmethods_Integration implements Integration_Interface {
use No_Conditionals;
/**
* The additional contactmethods collector.
*
* @var Additional_Contactmethods_Collector $additional_contactmethods_collector The additional contactmethods collector.
*/
private $additional_contactmethods_collector;
/**
* The constructor.
*
* @param Additional_Contactmethods_Collector $additional_contactmethods_collector The additional contactmethods collector.
*/
public function __construct( Additional_Contactmethods_Collector $additional_contactmethods_collector ) {
$this->additional_contactmethods_collector = $additional_contactmethods_collector;
}
/**
* Registers action hook.
*
* @return void
*/
public function register_hooks(): void {
\add_filter( 'user_contactmethods', [ $this, 'update_contactmethods' ] );
\add_filter( 'update_user_metadata', [ $this, 'stop_storing_empty_metadata' ], 10, 4 );
}
/**
* Updates the contactmethods with an additional set of social profiles.
*
* These are used with the Facebook author, rel="author", Twitter cards implementation, but also in the `sameAs` schema attributes.
*
* @param array<string, string> $contactmethods Currently set contactmethods.
*
* @return array<string, string> Contactmethods with added contactmethods.
*/
public function update_contactmethods( $contactmethods ) {
$additional_contactmethods = $this->additional_contactmethods_collector->get_additional_contactmethods_objects();
return \array_merge( $contactmethods, $additional_contactmethods );
}
/**
* Returns a check value, which will stop empty contactmethods from going into the database.
*
* @param bool|null $check Whether to allow updating metadata for the given type.
* @param int $object_id ID of the object metadata is for.
* @param string $meta_key Metadata key.
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
*
* @return false|null False for when we are to filter out empty metadata, null for no filtering.
*/
public function stop_storing_empty_metadata( $check, $object_id, $meta_key, $meta_value ) {
$additional_contactmethods = $this->additional_contactmethods_collector->get_additional_contactmethods_keys();
if ( \in_array( $meta_key, $additional_contactmethods, true ) && $meta_value === '' ) {
\delete_user_meta( $object_id, $meta_key );
return false;
}
return $check;
}
}

View File

@@ -1,58 +0,0 @@
<?php
namespace Yoast\WP\SEO\User_Meta\User_Interface;
use Yoast\WP\SEO\Conditionals\No_Conditionals;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast\WP\SEO\User_Meta\Application\Cleanup_Service;
/**
* Handles the cleanup for user meta.
*/
class Cleanup_Integration implements Integration_Interface {
use No_Conditionals;
/**
* The cleanup service.
*
* @var Cleanup_Service $cleanup_service The cleanup service.
*/
private $cleanup_service;
/**
* The constructor.
*
* @param Cleanup_Service $cleanup_service The cleanup service.
*/
public function __construct( Cleanup_Service $cleanup_service ) {
$this->cleanup_service = $cleanup_service;
}
/**
* Registers action hook.
*
* @return void
*/
public function register_hooks(): void {
\add_filter( 'wpseo_misc_cleanup_tasks', [ $this, 'add_user_meta_cleanup_tasks' ] );
}
/**
* Adds cleanup tasks for the cleanup integration.
*
* @param Closure[] $tasks Array of tasks to be added.
*
* @return Closure[] An associative array of tasks to be added to the cleanup integration.
*/
public function add_user_meta_cleanup_tasks( $tasks ) {
return \array_merge(
$tasks,
[
'clean_selected_empty_usermeta' => function ( $limit ) {
return $this->cleanup_service->cleanup_selected_empty_usermeta( $limit );
},
]
);
}
}

View File

@@ -1,81 +0,0 @@
<?php
namespace Yoast\WP\SEO\User_Meta\User_Interface;
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
use Yoast\WP\SEO\Conditionals\User_Can_Edit_Users_Conditional;
use Yoast\WP\SEO\Conditionals\User_Edit_Conditional;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast\WP\SEO\User_Meta\Application\Custom_Meta_Collector;
/**
* Handles custom meta for users.
*/
class Custom_Meta_Integration implements Integration_Interface {
/**
* The custom meta collector.
*
* @var Custom_Meta_Collector $custom_meta_collector The custom meta collector.
*/
private $custom_meta_collector;
/**
* The constructor.
*
* @param Custom_Meta_Collector $custom_meta_collector The custom meta collector.
*/
public function __construct( Custom_Meta_Collector $custom_meta_collector ) {
$this->custom_meta_collector = $custom_meta_collector;
}
/**
* Retrieves the conditionals for the integration.
*
* @return array<Yoast\WP\SEO\Conditionals> The conditionals.
*/
public static function get_conditionals() {
return [
Admin_Conditional::class,
User_Can_Edit_Users_Conditional::class,
User_Edit_Conditional::class,
];
}
/**
* Registers action hook.
*
* @return void
*/
public function register_hooks(): void {
\add_action( 'personal_options_update', [ $this, 'process_user_option_update' ] );
\add_action( 'edit_user_profile_update', [ $this, 'process_user_option_update' ] );
}
/**
* Updates the user metas that (might) have been set on the user profile page.
*
* @param int $user_id User ID of the updated user.
*
* @return void
*/
public function process_user_option_update( $user_id ) {
\update_user_meta( $user_id, '_yoast_wpseo_profile_updated', \time() );
if ( ! \check_admin_referer( 'wpseo_user_profile_update', 'wpseo_nonce' ) ) {
return;
}
foreach ( $this->custom_meta_collector->get_custom_meta() as $meta ) {
$meta_field_id = $meta->get_field_id();
$user_input_to_store = isset( $_POST[ $meta_field_id ] ) ? \sanitize_text_field( \wp_unslash( $_POST[ $meta_field_id ] ) ) : '';
if ( $meta->is_empty_allowed() || $user_input_to_store !== '' ) {
\update_user_meta( $user_id, $meta->get_key(), $user_input_to_store );
continue;
}
\delete_user_meta( $user_id, $meta->get_key() );
}
}
}