PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.2
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / views / class-yoast-integration-toggles.php

class-yoast-integration-toggles.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.2, at admin/views/class-yoast-integration-toggles.php

171 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * Class for managing integration toggles.
10 */
11 class Yoast_Integration_Toggles {
12
13 /**
14 * Available integration toggles.
15 *
16 * @var array
17 */
18 protected $toggles;
19
20 /**
21 * Instance holder.
22 *
23 * @var self|null
24 */
25 protected static $instance = null;
26
27 /**
28 * Gets the main integration toggles manager instance used.
29 *
30 * This essentially works like a Singleton, but for its drawbacks does not restrict
31 * instantiation otherwise.
32 *
33 * @return self Main instance.
34 */
35 public static function instance() {
36 if ( self::$instance === null ) {
37 self::$instance = new self();
38 }
39
40 return self::$instance;
41 }
42
43 /**
44 * Gets all available integration toggles.
45 *
46 * @return array List of sorted Yoast_Feature_Toggle instances.
47 */
48 public function get_all() {
49 if ( $this->toggles === null ) {
50 $this->toggles = $this->load_toggles();
51 }
52
53 return $this->toggles;
54 }
55
56 /**
57 * Loads the available integration toggles.
58 *
59 * Also ensures that the toggles are all Yoast_Feature_Toggle instances and sorted by their order value.
60 *
61 * @return array List of sorted Yoast_Feature_Toggle instances.
62 */
63 protected function load_toggles() {
64 $integration_toggles = [
65 (object) [
66 /* translators: %s: 'Semrush' */
67 'name' => sprintf( __( '%s integration', 'wordpress-seo' ), 'Semrush' ),
68 'setting' => 'semrush_integration_active',
69 'label' => sprintf(
70 /* translators: %s: 'Semrush' */
71 __( 'The %s integration offers suggestions and insights for keywords related to the entered focus keyphrase.', 'wordpress-seo' ),
72 'Semrush'
73 ),
74 'order' => 10,
75 ],
76 (object) [
77 /* translators: %s: Ryte */
78 'name' => sprintf( __( '%s integration', 'wordpress-seo' ), 'Ryte' ),
79 'setting' => 'ryte_indexability',
80 'label' => sprintf(
81 /* translators: 1: Ryte, 2: Yoast SEO */
82 __( '%1$s will check weekly if your site is still indexable by search engines and %2$s will notify you when this is not the case.', 'wordpress-seo' ),
83 'Ryte',
84 'Yoast SEO'
85 ),
86 /* translators: %s: Ryte */
87 'read_more_label' => sprintf( __( 'Read more about how %s works.', 'wordpress-seo' ), 'Ryte ' ),
88 'read_more_url' => 'https://yoa.st/2an',
89 'order' => 15,
90 ],
91 (object) [
92 /* translators: %s: Zapier. */
93 'name' => \sprintf( \esc_html__( '%s integration', 'wordpress-seo' ), 'Zapier' ),
94 'premium' => true,
95 'setting' => 'zapier_integration_active',
96 'label' => \sprintf(
97 /* translators: 1: Yoast SEO, 2: Zapier. */
98 \__( 'Set up automated actions when you publish or update your content. By connecting %1$s with %2$s, you can easily send out your published posts to any of its 2000+ destinations, such as Twitter, Facebook and more.', 'wordpress-seo' ),
99 'Yoast SEO',
100 'Zapier'
101 ),
102 /* translators: %s: Zapier. */
103 'read_more_label' => \sprintf( \__( 'Find out more about our %s integration.', 'wordpress-seo' ), 'Zapier' ),
104 'read_more_url' => 'https://yoa.st/4et',
105 'premium_url' => 'https://yoa.st/46o',
106 'order' => 20,
107 ],
108 (object) [
109 /* translators: %s: Algolia. */
110 'name' => \sprintf( \esc_html__( '%s integration', 'wordpress-seo' ), 'Algolia' ),
111 'premium' => true,
112 'setting' => 'algolia_integration_active',
113 'label' => __( 'Improve the quality of your site search! Automatically helps your users find your cornerstone and most important content in your internal search results. It also removes noindexed posts & pages from your site’s search results.', 'wordpress-seo' ),
114 /* translators: %s: Algolia. */
115 'read_more_label' => \sprintf( \__( 'Find out more about our %s integration.', 'wordpress-seo' ), 'Algolia' ),
116 'read_more_url' => 'https://yoa.st/4eu',
117 'premium_url' => 'https://yoa.st/4ex',
118 'order' => 25,
119 ],
120 ];
121
122 /**
123 * Filter to add integration toggles from add-ons.
124 *
125 * @param array $integration_toggles Array with integration toggle objects where each object
126 * should have a `name`, `setting` and `label` property.
127 */
128 $integration_toggles = apply_filters( 'wpseo_integration_toggles', $integration_toggles );
129
130 $integration_toggles = array_map( [ $this, 'ensure_toggle' ], $integration_toggles );
131 usort( $integration_toggles, [ $this, 'sort_toggles_callback' ] );
132
133 return $integration_toggles;
134 }
135
136 /**
137 * Ensures that the passed value is a Yoast_Feature_Toggle.
138 *
139 * @param Yoast_Feature_Toggle|object|array $toggle_data Feature toggle instance, or raw object or array
140 * containing integration toggle data.
141 * @return Yoast_Feature_Toggle Feature toggle instance based on $toggle_data.
142 */
143 protected function ensure_toggle( $toggle_data ) {
144 if ( $toggle_data instanceof Yoast_Feature_Toggle ) {
145 return $toggle_data;
146 }
147
148 if ( is_object( $toggle_data ) ) {
149 $toggle_data = get_object_vars( $toggle_data );
150 }
151
152 return new Yoast_Feature_Toggle( $toggle_data );
153 }
154
155 /**
156 * Callback for sorting integration toggles by their order.
157 *
158 * {@internal Once the minimum PHP version goes up to PHP 7.0, the logic in the function
159 * can be replaced with the spaceship operator `<=>`.}
160 *
161 * @param Yoast_Feature_Toggle $feature_a Feature A.
162 * @param Yoast_Feature_Toggle $feature_b Feature B.
163 *
164 * @return int An integer less than, equal to, or greater than zero indicating respectively
165 * that feature A is considered to be less than, equal to, or greater than feature B.
166 */
167 protected function sort_toggles_callback( Yoast_Feature_Toggle $feature_a, Yoast_Feature_Toggle $feature_b ) {
168 return ( $feature_a->order - $feature_b->order );
169 }
170 }
171