| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 4 |
namespace Yoast\WP\SEO\User_Meta\Framework\Custom_Meta; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 7 |
use Yoast\WP\SEO\User_Meta\Domain\Custom_Meta_Interface; |
| 8 |
|
| 9 |
/** |
| 10 |
* The Keyword_Analysis_Disable custom meta. |
| 11 |
*/ |
| 12 |
class Keyword_Analysis_Disable implements Custom_Meta_Interface { |
| 13 |
|
| 14 |
/** |
| 15 |
* The options helper. |
| 16 |
* |
| 17 |
* @var Options_Helper |
| 18 |
*/ |
| 19 |
private $options_helper; |
| 20 |
|
| 21 |
/** |
| 22 |
* The constructor. |
| 23 |
* |
| 24 |
* @param Options_Helper $options_helper The options helper. |
| 25 |
*/ |
| 26 |
public function __construct( Options_Helper $options_helper ) { |
| 27 |
$this->options_helper = $options_helper; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Returns the priority which the custom meta's form field should be rendered with. |
| 32 |
* |
| 33 |
* @return int The priority which the custom meta's form field should be rendered with. |
| 34 |
*/ |
| 35 |
public function get_render_priority(): int { |
| 36 |
return 400; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Returns the db key of the Keyword_Analysis_Disable custom meta. |
| 41 |
* |
| 42 |
* @return string The db key of the Keyword_Analysis_Disable custom meta. |
| 43 |
*/ |
| 44 |
public function get_key(): string { |
| 45 |
return 'wpseo_keyword_analysis_disable'; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Returns the id of the custom meta's form field. |
| 50 |
* |
| 51 |
* @return string The id of the custom meta's form field. |
| 52 |
*/ |
| 53 |
public function get_field_id(): string { |
| 54 |
return 'wpseo_keyword_analysis_disable'; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Returns the meta value. |
| 59 |
* |
| 60 |
* @param int $user_id The user ID. |
| 61 |
* |
| 62 |
* @return string The meta value. |
| 63 |
*/ |
| 64 |
public function get_value( $user_id ): string { |
| 65 |
return \get_the_author_meta( $this->get_key(), $user_id ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Returns whether the respective global setting is enabled. |
| 70 |
* |
| 71 |
* @return bool Whether the respective global setting is enabled. |
| 72 |
*/ |
| 73 |
public function is_setting_enabled(): bool { |
| 74 |
return ( $this->options_helper->get( 'keyword_analysis_active', false ) ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Returns whether the custom meta is allowed to be empty. |
| 79 |
* |
| 80 |
* @return bool Whether the custom meta is allowed to be empty. |
| 81 |
*/ |
| 82 |
public function is_empty_allowed(): bool { |
| 83 |
return true; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Renders the custom meta's field in the user form. |
| 88 |
* |
| 89 |
* @param int $user_id The user ID. |
| 90 |
* |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
public function render_field( $user_id ): void { |
| 94 |
echo ' |
| 95 |
|
| 96 |
<input |
| 97 |
class="yoast-settings__checkbox double" |
| 98 |
type="checkbox" |
| 99 |
id="' . \esc_attr( $this->get_field_id() ) . '" |
| 100 |
name="' . \esc_attr( $this->get_field_id() ) . '" |
| 101 |
aria-describedby="' . \esc_attr( $this->get_field_id() ) . '_desc" |
| 102 |
value="on" ' |
| 103 |
. \checked( $this->get_value( $user_id ), 'on', false ) |
| 104 |
. '/>'; |
| 105 |
|
| 106 |
echo ' |
| 107 |
|
| 108 |
<label class="yoast-label-strong" for="' . \esc_attr( $this->get_field_id() ) . '">' |
| 109 |
. \esc_html__( 'Disable SEO analysis', 'wordpress-seo' ) |
| 110 |
. '</label><br>'; |
| 111 |
|
| 112 |
echo ' |
| 113 |
|
| 114 |
<p class="description" id="' . \esc_attr( $this->get_field_id() ) . '_desc">' |
| 115 |
. \esc_html__( 'Removes the focus keyphrase section from the metabox and disables all SEO-related suggestions.', 'wordpress-seo' ) |
| 116 |
. '</p>'; |
| 117 |
} |
| 118 |
} |
| 119 |
|