diff options
Diffstat (limited to 'plugins/jetpack/modules/publicize')
-rw-r--r-- | plugins/jetpack/modules/publicize/publicize-jetpack.php | 38 | ||||
-rw-r--r-- | plugins/jetpack/modules/publicize/publicize.php | 6 |
2 files changed, 39 insertions, 5 deletions
diff --git a/plugins/jetpack/modules/publicize/publicize-jetpack.php b/plugins/jetpack/modules/publicize/publicize-jetpack.php index f21ca16e..ab371433 100644 --- a/plugins/jetpack/modules/publicize/publicize-jetpack.php +++ b/plugins/jetpack/modules/publicize/publicize-jetpack.php @@ -27,7 +27,7 @@ class Publicize extends Publicize_Base { add_filter( 'publicize_checkbox_default', array( $this, 'publicize_checkbox_default' ), 10, 4 ); - add_action( 'transition_post_status', array( $this, 'save_publicized' ), 10, 3 ); + add_action( 'wp_insert_post', array( $this, 'save_publicized' ), 11, 3 ); add_filter( 'jetpack_twitter_cards_site_tag', array( $this, 'enhaced_twitter_cards_site_tag' ) ); @@ -359,7 +359,25 @@ class Publicize extends Publicize_Base { } function flag_post_for_publicize( $new_status, $old_status, $post ) { - // Stub only. Doesn't need to do anything on Jetpack Client + if ( 'publish' == $new_status && 'publish' != $old_status ) { + /** + * Determines whether a post being published gets publicized. + * + * Side-note: Possibly our most alliterative filter name. + * + * @module publicize + * + * @since 4.1.0 + * + * @param bool $should_publicize Should the post be publicized? Default to true. + * @param WP_POST $post Current Post object. + */ + $should_publicize = apply_filters( 'publicize_should_publicize_published_post', true, $post ); + + if ( $should_publicize ) { + update_post_meta( $post->ID, $this->PENDING, true ); + } + } } function test_connection( $service_name, $connection ) { @@ -405,9 +423,21 @@ class Publicize extends Publicize_Base { * Save a flag locally to indicate that this post has already been Publicized via the selected * connections. */ - function save_publicized( $new_status, $old_status, $post ) { + function save_publicized( $post_ID, $post, $update ) { // Only do this when a post transitions to being published - if ( 'publish' == $new_status && 'publish' != $old_status ) { + if ( get_post_meta( $post->ID, $this->PENDING ) ) { + $connected_services = Jetpack_Options::get_option( 'publicize_connections' ); + if ( ! empty( $connected_services ) ) { + /** + * Fires when a post is saved that has is marked as pending publicizing + * + * @since 4.1.0 + * + * @param int The post ID + */ + do_action( 'jetpack_publicize_post', $post->ID ); + } + delete_post_meta( $post->ID, $this->PENDING ); update_post_meta( $post->ID, $this->POST_DONE . 'all', true ); } } diff --git a/plugins/jetpack/modules/publicize/publicize.php b/plugins/jetpack/modules/publicize/publicize.php index f78bdd9f..6b558f25 100644 --- a/plugins/jetpack/modules/publicize/publicize.php +++ b/plugins/jetpack/modules/publicize/publicize.php @@ -326,7 +326,11 @@ abstract class Publicize_Base { } // Did this request happen via wp-admin? - $from_web = 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$this->ADMIN_PAGE] ); + $from_web = isset( $_SERVER['REQUEST_METHOD'] ) + && + 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) + && + isset( $_POST[$this->ADMIN_PAGE] ); if ( ( $from_web || defined( 'POST_BY_EMAIL' ) ) && isset( $_POST['wpas_title'] ) ) { if ( empty( $_POST['wpas_title'] ) ) { |