diff --git a/projects/packages/publicize/changelog/add-share-save-hook b/projects/packages/publicize/changelog/add-share-save-hook new file mode 100644 index 0000000000000..aa57fdaf0e102 --- /dev/null +++ b/projects/packages/publicize/changelog/add-share-save-hook @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Social: adds hook for plugin developers to be able to pull social share URLs on save. diff --git a/projects/packages/publicize/src/class-rest-controller.php b/projects/packages/publicize/src/class-rest-controller.php index 316ed1d6f6d45..a0e04a851ef18 100644 --- a/projects/packages/publicize/src/class-rest-controller.php +++ b/projects/packages/publicize/src/class-rest-controller.php @@ -655,6 +655,25 @@ public function update_post_shares( $request ) { if ( $post && 'publish' === $post->post_status && isset( $post_meta[ self::SOCIAL_SHARES_POST_META_KEY ] ) ) { update_post_meta( $post_id, self::SOCIAL_SHARES_POST_META_KEY, $post_meta[ self::SOCIAL_SHARES_POST_META_KEY ] ); + $urls = array(); + foreach ( $post_meta[ self::SOCIAL_SHARES_POST_META_KEY ] as $share ) { + if ( isset( $share['status'] ) && 'success' === $share['status'] ) { + $urls[] = array( + 'url' => $share['message'], + 'service' => $share['service'], + ); + } + } + /** + * Fires after Publicize Shares post meta has been saved. + * + * @param array $urls { + * An array of social media shares. + * @type array $url URL to the social media post. + * @type string $service Social media service shared to. + * } + */ + do_action( 'jetpack_publicize_share_urls_saved', $urls ); return rest_ensure_response( new WP_REST_Response() ); } diff --git a/projects/plugins/social/changelog/add-share-save-hook b/projects/plugins/social/changelog/add-share-save-hook new file mode 100644 index 0000000000000..aa57fdaf0e102 --- /dev/null +++ b/projects/plugins/social/changelog/add-share-save-hook @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Social: adds hook for plugin developers to be able to pull social share URLs on save. diff --git a/projects/plugins/social/src/class-rest-social-note-controller.php b/projects/plugins/social/src/class-rest-social-note-controller.php index 05cf8001f25e0..b19aeb690063e 100644 --- a/projects/plugins/social/src/class-rest-social-note-controller.php +++ b/projects/plugins/social/src/class-rest-social-note-controller.php @@ -66,6 +66,17 @@ public function update_post_shares( $request ) { if ( $post && $post->post_type === Note::JETPACK_SOCIAL_NOTE_CPT && $post->post_status === 'publish' && isset( $post_meta[ self::SOCIAL_SHARES_POST_META_KEY ] ) ) { update_post_meta( $post_id, self::SOCIAL_SHARES_POST_META_KEY, $post_meta[ self::SOCIAL_SHARES_POST_META_KEY ] ); + $urls = array(); + foreach ( $post_meta[ self::SOCIAL_SHARES_POST_META_KEY ] as $share ) { + if ( isset( $share['status'] ) && 'success' === $share['status'] ) { + $urls[] = array( + 'url' => $share['message'], + 'service' => $share['service'], + ); + } + } + /** This action is documented in src/class-rest-controller.php */ + do_action( 'jetpack_publicize_share_urls_saved', $urls ); return rest_ensure_response( new WP_REST_Response() ); }