PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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
← All changes | inc/class-wpseo-shortlinker.php +6 -114 18.9 → trunk View file →
@@ -10,32 +10,8 @@
10 10 */
11 11 class WPSEO_Shortlinker {
12 12
13 13 /**
14 - * Collects the additional data necessary for the shortlink.
15 - *
16 - * @return array The shortlink data.
17 - */
18 - protected function collect_additional_shortlink_data() {
19 - $data = [
20 - 'php_version' => $this->get_php_version(),
21 - 'platform' => 'wordpress',
22 - 'platform_version' => $this->get_platform_version(),
23 - 'software' => $this->get_software(),
24 - 'software_version' => WPSEO_VERSION,
25 - 'days_active' => $this->get_days_active(),
26 - 'user_language' => $this->get_user_language(),
27 - ];
28 -
29 - $admin_page = filter_input( INPUT_GET, 'page' );
30 - if ( ! empty( $admin_page ) ) {
31 - $data['screen'] = $admin_page;
32 - }
33 -
34 - return $data;
35 - }
36 -
37 - /**
38 14 * Builds a URL to use in the plugin as shortlink.
39 15 *
40 16 * @param string $url The URL to build upon.
41 17 *
@@ -41,9 +17,9 @@
41 17 *
42 18 * @return string The final URL.
43 19 */
44 20 public function build_shortlink( $url ) {
45 - return add_query_arg( $this->collect_additional_shortlink_data(), $url );
21 + return YoastSEO()->helpers->short_link->build( $url );
46 22 }
47 23
48 24 /**
49 25 * Returns a version of the URL with a utm_content with the current version.
@@ -52,11 +28,9 @@
52 28 *
53 29 * @return string The final URL.
54 30 */
55 31 public static function get( $url ) {
56 - $shortlinker = new self();
57 -
58 - return $shortlinker->build_shortlink( $url );
32 + return YoastSEO()->helpers->short_link->get( $url );
59 33 }
60 34
61 35 /**
62 36 * Echoes a version of the URL with a utm_content with the current version.
@@ -61,11 +35,13 @@
61 35 /**
62 36 * Echoes a version of the URL with a utm_content with the current version.
63 37 *
64 38 * @param string $url The URL to build upon.
39 + *
40 + * @return void
65 41 */
66 42 public static function show( $url ) {
67 - echo esc_url( self::get( $url ) );
43 + YoastSEO()->helpers->short_link->show( $url );
68 44 }
69 45
70 46 /**
71 47 * Gets the shortlink's query params.
@@ -72,91 +48,7 @@
72 48 *
73 49 * @return array The shortlink's query params.
74 50 */
75 51 public static function get_query_params() {
76 - $shortlinker = new self();
77 -
78 - return $shortlinker->collect_additional_shortlink_data();
79 - }
80 -
81 - /**
82 - * Gets the current site's PHP version, without the extra info.
83 - *
84 - * @return string The PHP version.
85 - */
86 - private function get_php_version() {
87 - $version = explode( '.', PHP_VERSION );
88 -
89 - return (int) $version[0] . '.' . (int) $version[1];
90 - }
91 -
92 - /**
93 - * Gets the current site's platform version.
94 - *
95 - * @return string The wp_version.
96 - */
97 - protected function get_platform_version() {
98 - return $GLOBALS['wp_version'];
99 - }
100 -
101 - /**
102 - * Get our software and whether it's active or not.
103 - *
104 - * @return string The software name + activation state.
105 - */
106 - private function get_software() {
107 - if ( YoastSEO()->helpers->product->is_premium() ) {
108 - return 'premium';
109 - }
110 -
111 - return 'free';
112 - }
113 -
114 - /**
115 - * Gets the number of days the plugin has been active.
116 - *
117 - * @return int The number of days the plugin is active.
118 - */
119 - private function get_days_active() {
120 - $date_activated = WPSEO_Options::get( 'first_activated_on' );
121 - $datediff = ( time() - $date_activated );
122 - $days = (int) round( $datediff / DAY_IN_SECONDS );
123 - switch ( $days ) {
124 - case 0:
125 - case 1:
126 - $cohort = '0-1';
127 - break;
128 - case ( $days < 5 ):
129 - $cohort = '2-5';
130 - break;
131 - case ( $days < 30 ):
132 - $cohort = '6-30';
133 - break;
134 - case ( $days < 91 ):
135 - $cohort = '31-90';
136 - break;
137 - case ( $days < 181 ):
138 - $cohort = '91-180';
139 - break;
140 - case ( $days < 366 ):
141 - $cohort = '181-365';
142 - break;
143 - default:
144 - $cohort = '365plus';
145 - }
146 -
147 - return $cohort;
148 - }
149 -
150 - /**
151 - * Gets the user's language.
152 - *
153 - * @return string|false The user's language or `false` when it couldn't be retrieved.
154 - */
155 - private function get_user_language() {
156 - if ( function_exists( 'get_user_locale' ) ) {
157 - return get_user_locale();
158 - }
159 -
160 - return false;
52 + return YoastSEO()->helpers->short_link->get_query_params();
161 53 }
162 54 }