PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | modules/theme-tools/social-links.php +40 -171 13.7.2 → 16.3-a.5 View file →
@@ -12,8 +12,14 @@
12 12 *
13 13 * @package automattic/jetpack
14 14 */
15 15
16 +use Automattic\Jetpack\Status\Host;
17 +
18 +if ( ! defined( 'ABSPATH' ) ) {
19 + exit( 0 );
20 +}
21 +
16 22 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
17 23
18 24 if ( ! function_exists( 'jetpack_theme_supports_social_links' ) ) {
19 25 /**
@@ -19,13 +25,13 @@
19 25 /**
20 26 * Init Social_Links if the theme declares support.
21 27 */
22 28 function jetpack_theme_supports_social_links() {
23 - if ( ! wp_is_block_theme() && current_theme_supports( 'social-links' ) && function_exists( 'publicize_init' ) ) {
24 - new Social_Links();
25 - }
29 + new \Automattic\Jetpack\Classic_Theme_Helper\Social_Links();
26 30 }
27 - add_action( 'init', 'jetpack_theme_supports_social_links', 30 );
31 + if ( ! ( new Host() )->is_wpcom_platform() ) {
32 + add_action( 'init', 'jetpack_theme_supports_social_links', 30 );
33 + }
28 34 }
29 35
30 36 if ( ! class_exists( 'Social_Links' ) ) {
31 37
@@ -30,88 +36,32 @@
30 36 if ( ! class_exists( 'Social_Links' ) ) {
31 37
32 38 /**
33 39 * Social_Links main class.
40 + *
41 + * @deprecated 13.8 Moved to Classic Theme Helper package.
34 42 */
35 43 class Social_Links {
36 44
37 45 /**
38 - * The links the user set for each service.
46 + * Constructor.
39 47 *
40 - * @var array
48 + * @deprecated 13.8 Moved to Classic Theme Helper package.
41 49 */
42 - private $links;
43 -
44 - /**
45 - * A Publicize object.
46 - *
47 - * @var Publicize
48 - */
49 - private $publicize;
50 -
51 - /**
52 - * An array with all services that are supported by both Publicize and the
53 - * currently active theme.
54 - *
55 - * @var array
56 - */
57 - private $services = array();
58 -
59 - /**
60 - * An array of the services the theme supports
61 - *
62 - * @var array
63 - */
64 - private $theme_supported_services = array();
65 -
66 - /**
67 - * Constructor.
68 - */
69 50 public function __construct() {
70 - $theme_support = get_theme_support( 'social-links' );
71 -
72 - /*
73 - An array of named arguments must be passed as the second parameter
74 - * of add_theme_support().
75 - */
76 - if ( empty( $theme_support[0] ) ) {
77 - return;
78 - }
79 -
80 - $this->theme_supported_services = $theme_support[0];
81 - $this->links = Jetpack_Options::get_option( 'social_links', array() );
82 -
83 - $this->admin_setup();
84 -
85 - add_filter( 'jetpack_has_social_links', array( $this, 'has_social_links' ) );
86 - add_filter( 'jetpack_get_social_links', array( $this, 'get_social_links' ) );
87 -
88 - foreach ( $theme_support[0] as $service ) {
89 - add_filter( "pre_option_jetpack-$service", array( $this, 'get_social_link_filter' ) ); // - `get_option( 'jetpack-service' );`
90 - add_filter( "theme_mod_jetpack-$service", array( $this, 'get_social_link_filter' ) ); // - `get_theme_mod( 'jetpack-service' );`
91 - }
51 + _deprecated_function( __METHOD__, '13.8', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Social_Links->__construct' );
52 + new \Automattic\Jetpack\Classic_Theme_Helper\Social_Links();
92 53 }
93 54
94 55 /**
95 56 * Init the admin setup.
57 + *
58 + * @deprecated 13.8 Moved to Classic Theme Helper package.
96 59 */
97 60 public function admin_setup() {
98 - if ( ! current_user_can( 'manage_options' ) ) {
99 - return;
100 - }
101 -
102 - if ( ! is_admin() && ! $this->is_customize_preview() ) {
103 - return;
104 - }
105 -
106 - $this->publicize = publicize_init();
107 - $publicize_services = $this->publicize->get_services( 'connected' );
108 - $this->services = array_intersect( array_keys( $publicize_services ), $this->theme_supported_services );
109 -
110 - add_action( 'publicize_connected', array( $this, 'check_links' ), 20 );
111 - add_action( 'publicize_disconnected', array( $this, 'check_links' ), 20 );
112 - add_action( 'customize_register', array( $this, 'customize_register' ) );
113 - add_filter( 'sanitize_option_jetpack_options', array( $this, 'sanitize_link' ) );
61 + _deprecated_function( __METHOD__, '13.8', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Social_Links->admin_setup' );
62 + $social_links_instance = new \Automattic\Jetpack\Classic_Theme_Helper\Social_Links();
63 + $social_links_instance->admin_setup();
114 64 }
115 65
116 66 /**
117 67 * Compares the currently saved links with the connected services and removes
@@ -116,87 +66,50 @@
116 66 /**
117 67 * Compares the currently saved links with the connected services and removes
118 68 * links from services that are no longer connected.
119 69 *
70 + * @deprecated 13.8 Moved to Classic Theme Helper package.
120 71 * @return void
121 72 */
122 73 public function check_links() {
123 - $active_links = array_intersect_key( $this->links, array_flip( $this->services ) );
124 -
125 - if ( $active_links !== $this->links ) {
126 - $this->links = $active_links;
127 - Jetpack_Options::update_option( 'social_links', $active_links );
128 - }
74 + _deprecated_function( __METHOD__, '13.8', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Social_Links->check_links' );
75 + $social_links_instance = new \Automattic\Jetpack\Classic_Theme_Helper\Social_Links();
76 + $social_links_instance->check_links();
129 77 }
130 78
131 79 /**
132 80 * Add social link dropdown to the Customizer.
133 81 *
82 + * @deprecated 13.8 Moved to Classic Theme Helper package.
134 83 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
135 84 */
136 85 public function customize_register( $wp_customize ) {
137 - $wp_customize->add_section(
138 - 'jetpack_social_links',
139 - array(
140 - 'title' => esc_html__( 'Connect', 'jetpack' ),
141 - 'priority' => 35,
142 - )
143 - );
144 -
145 - foreach ( array_keys( $this->publicize->get_services( 'all' ) ) as $service ) {
146 - $choices = $this->get_customize_select( $service );
147 -
148 - if ( empty( $choices ) ) {
149 - continue;
150 - }
151 -
152 - $wp_customize->add_setting(
153 - "jetpack_options[social_links][$service]",
154 - array(
155 - 'type' => 'option',
156 - 'default' => '',
157 - )
158 - );
159 -
160 - $wp_customize->add_control(
161 - "jetpack-$service",
162 - array(
163 - 'label' => $this->publicize->get_service_label( $service ),
164 - 'section' => 'jetpack_social_links',
165 - 'settings' => "jetpack_options[social_links][$service]",
166 - 'type' => 'select',
167 - 'choices' => $choices,
168 - )
169 - );
170 - }
86 + _deprecated_function( __METHOD__, '13.8', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Social_Links->customize_register' );
87 + $social_links_instance = new \Automattic\Jetpack\Classic_Theme_Helper\Social_Links();
88 + $social_links_instance->customize_register( $wp_customize );
171 89 }
172 90
173 91 /**
174 92 * Sanitizes social links.
175 93 *
94 + * @deprecated 13.8 Moved to Classic Theme Helper package.
176 95 * @param array $option The incoming values to be sanitized.
177 96 * @return array
178 97 */
179 98 public function sanitize_link( $option ) {
180 - foreach ( $this->services as $service ) {
181 - if ( ! empty( $option['social_links'][ $service ] ) ) {
182 - $option['social_links'][ $service ] = esc_url_raw( $option['social_links'][ $service ] );
183 - } else {
184 - unset( $option['social_links'][ $service ] );
185 - }
186 - }
187 -
188 - return $option;
99 + _deprecated_function( __METHOD__, '13.8', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Social_Links->sanitize_link' );
100 + return ( new \Automattic\Jetpack\Classic_Theme_Helper\Social_Links() )->sanitize_link( $option );
189 101 }
190 102
191 103 /**
192 104 * Returns whether there are any social links set.
193 105 *
106 + * @deprecated 13.8 Moved to Classic Theme Helper package.
194 107 * @return bool
195 108 */
196 109 public function has_social_links() {
197 - return ! empty( $this->links );
198 - }
110 + _deprecated_function( __METHOD__, '13.8', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Social_Links->has_social_links' );
111 + return ( new \Automattic\Jetpack\Classic_Theme_Helper\Social_Links() )->has_social_links(); }
199 112
200 113 /**
201 114 * Return available social links.
202 115 *
@@ -202,66 +115,22 @@
202 115 *
203 116 * @return array
204 117 */
205 118 public function get_social_links() {
206 - return $this->links;
119 + _deprecated_function( __METHOD__, '13.8', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Social_Links->get_social_links' );
120 + return ( new \Automattic\Jetpack\Classic_Theme_Helper\Social_Links() )->get_social_links();
207 121 }
208 122
209 123 /**
210 124 * Short-circuits get_option and get_theme_mod calls.
211 125 *
126 + * @deprecated 13.8 Moved to Classic Theme Helper package.
212 127 * @param string $link The incoming value to be replaced.
213 128 * @return string $link The social link that we've got.
214 129 */
215 130 public function get_social_link_filter( $link ) {
216 - if ( preg_match( '/_jetpack-(.+)$/i', current_filter(), $matches ) && ! empty( $this->links[ $matches[1] ] ) ) {
217 - return $this->links[ $matches[1] ];
218 - }
219 -
220 - return $link;
221 - }
222 -
223 - /**
224 - * Puts together an array of choices for a specific service.
225 - *
226 - * @param string $service The social service.
227 - * @return array An associative array with profile links and display names.
228 - */
229 - private function get_customize_select( $service ) {
230 - $choices = array(
231 - '' => __( '— Select —', 'jetpack' ),
232 - );
233 -
234 - if ( isset( $this->links[ $service ] ) ) {
235 - $choices[ $this->links[ $service ] ] = $this->links[ $service ];
236 - }
237 -
238 - $connected_services = $this->publicize->get_services( 'connected' );
239 - if ( isset( $connected_services[ $service ] ) ) {
240 - foreach ( $connected_services[ $service ] as $c ) {
241 - $profile_link = $this->publicize->get_profile_link( $service, $c );
242 -
243 - if ( false === $profile_link ) {
244 - continue;
245 - }
246 -
247 - $choices[ $profile_link ] = $this->publicize->get_display_name( $service, $c );
248 - }
249 - }
250 -
251 - if ( 1 === count( $choices ) ) {
252 - return array();
253 - }
254 -
255 - return $choices;
256 - }
257 -
258 - /**
259 - * Back-compat function for versions prior to 4.0.
260 - */
261 - private function is_customize_preview() {
262 - global $wp_customize;
263 - return is_a( $wp_customize, 'WP_Customize_Manager' ) && $wp_customize->is_preview();
131 + _deprecated_function( __METHOD__, '13.8', 'Automattic\\Jetpack\\Classic_Theme_Helper\\Social_Links->get_social_link_filter' );
132 + return ( new \Automattic\Jetpack\Classic_Theme_Helper\Social_Links() )->get_social_link_filter( $link );
264 133 }
265 134 }
266 135
267 136 } // - end if ( ! class_exists( 'Social_Links' )