| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | |
| 8 | 8 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 9 | 9 | |
| 10 | 10 | use Automattic\Jetpack\Assets; |
| 11 | +use Automattic\Jetpack\Sharing_Likes\Post_Sharing_Switch; | |
| 11 | 12 | use Automattic\Jetpack\Sharing_Likes\Settings\Post_Handler; |
| 12 | 13 | use Automattic\Jetpack\Sharing_Likes\Settings\Services_Config; |
| 13 | 14 | use Automattic\Jetpack\Sharing_Likes\Settings\Settings_Page; |
| 14 | 15 | use Automattic\Jetpack\Status\Host; |
| @@ -276,11 +277,9 @@ | ||
| 276 | 277 | |
| 277 | 278 | /** |
| 278 | 279 | * Callback to get the value for the jetpack_sharing_enabled field. |
| 279 | 280 | * |
| 280 | - * When the sharing_disabled post_meta is unset, we follow the global setting in Sharing. | |
| 281 | - * When it is set to 1, we disable sharing on the post, regardless of the global setting. | |
| 282 | - * It is not possible to enable sharing on a post if it is disabled globally. | |
| 281 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Post_Sharing_Switch::get_value() instead. | |
| 283 | 282 | * |
| 284 | 283 | * @param array $post The post object. |
| 285 | 284 | * |
| 286 | 285 | * @return bool |
| @@ -285,14 +284,10 @@ | ||
| 285 | 284 | * |
| 286 | 285 | * @return bool |
| 287 | 286 | */ |
| 288 | 287 | function jetpack_post_sharing_get_value( array $post ) { |
| 289 | - if ( ! isset( $post['id'] ) ) { | |
| 290 | - return false; | |
| 291 | - } | |
| 292 | - | |
| 293 | - // if sharing IS disabled on this post, enabled=false, so negate the meta | |
| 294 | - return ! get_post_meta( $post['id'], 'sharing_disabled', true ); | |
| 288 | + _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Post_Sharing_Switch::get_value' ); | |
| 289 | + return Post_Sharing_Switch::get_value( $post ); | |
| 295 | 290 | } |
| 296 | 291 | |
| 297 | 292 | /** |
| 298 | 293 | * Callback to set sharing_disabled post_meta when the |
| @@ -297,11 +292,9 @@ | ||
| 297 | 292 | /** |
| 298 | 293 | * Callback to set sharing_disabled post_meta when the |
| 299 | 294 | * jetpack_sharing_enabled field is updated. |
| 300 | 295 | * |
| 301 | - * When the sharing_disabled post_meta is unset, we follow the global setting in Sharing. | |
| 302 | - * When it is set to 1, we disable sharing on the post, regardless of the global setting. | |
| 303 | - * It is not possible to enable sharing on a post if it is disabled globally. | |
| 296 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Post_Sharing_Switch::update_value() instead. | |
| 304 | 297 | * |
| 305 | 298 | * @param bool $enable_sharing Should sharing be enabled on this post. |
| 306 | 299 | * @param WP_Post $post_object The post object. |
| 307 | 300 | * |
| @@ -307,53 +300,23 @@ | ||
| 307 | 300 | * |
| 308 | 301 | * @return int|bool |
| 309 | 302 | */ |
| 310 | 303 | function jetpack_post_sharing_update_value( $enable_sharing, $post_object ) { |
| 311 | - if ( $enable_sharing ) { | |
| 312 | - // delete the override if we want to enable sharing | |
| 313 | - return delete_post_meta( $post_object->ID, 'sharing_disabled' ); | |
| 314 | - } else { | |
| 315 | - return update_post_meta( $post_object->ID, 'sharing_disabled', true ); | |
| 316 | - } | |
| 304 | + _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Post_Sharing_Switch::update_value' ); | |
| 305 | + return Post_Sharing_Switch::update_value( $enable_sharing, $post_object ); | |
| 317 | 306 | } |
| 318 | 307 | |
| 319 | 308 | /** |
| 320 | 309 | * Add Sharing post_meta to the REST API Post response. |
| 321 | 310 | * |
| 322 | - * @action rest_api_init | |
| 323 | - * @uses register_rest_field | |
| 324 | - * @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/ | |
| 311 | + * @deprecated 16.3 Use Automattic\Jetpack\Sharing_Likes\Post_Sharing_Switch::register_rest_field() instead. | |
| 325 | 312 | */ |
| 326 | 313 | function jetpack_post_sharing_register_rest_field() { |
| 327 | - $post_types = get_post_types( array( 'public' => true ) ); | |
| 328 | - foreach ( $post_types as $post_type ) { | |
| 329 | - register_rest_field( | |
| 330 | - $post_type, | |
| 331 | - 'jetpack_sharing_enabled', | |
| 332 | - array( | |
| 333 | - 'get_callback' => 'jetpack_post_sharing_get_value', | |
| 334 | - 'update_callback' => 'jetpack_post_sharing_update_value', | |
| 335 | - 'schema' => array( | |
| 336 | - 'description' => __( 'Are sharing buttons enabled?', 'jetpack' ), | |
| 337 | - 'type' => 'boolean', | |
| 338 | - ), | |
| 339 | - ) | |
| 340 | - ); | |
| 341 | - | |
| 342 | - /** | |
| 343 | - * Ensures all public internal post-types support `sharing` | |
| 344 | - * This feature support flag is used by the REST API and Gutenberg. | |
| 345 | - */ | |
| 346 | - add_post_type_support( $post_type, 'jetpack-sharing-buttons' ); | |
| 347 | - } | |
| 314 | + _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Sharing_Likes\Post_Sharing_Switch::register_rest_field' ); | |
| 315 | + Post_Sharing_Switch::register_rest_field(); | |
| 348 | 316 | } |
| 349 | 317 | |
| 350 | -// Add Sharing post_meta to the REST API Post response. | |
| 351 | -add_action( 'rest_api_init', 'jetpack_post_sharing_register_rest_field' ); | |
| 352 | - | |
| 353 | -// Some CPTs (e.g. Jetpack portfolios and testimonials) get registered with | |
| 354 | -// restapi_theme_init because they depend on theme support, so let's also hook to that | |
| 355 | -add_action( 'restapi_theme_init', 'jetpack_post_likes_register_rest_field', 20 ); | |
| 318 | +Post_Sharing_Switch::init(); | |
| 356 | 319 | |
| 357 | 320 | /** |
| 358 | 321 | * Initialize sharing settings in WP Admin. |
| 359 | 322 | * |