diff options
Diffstat (limited to 'plugins/jetpack/modules/publicize/publicize.php')
-rw-r--r-- | plugins/jetpack/modules/publicize/publicize.php | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/plugins/jetpack/modules/publicize/publicize.php b/plugins/jetpack/modules/publicize/publicize.php index 16d4541c..0070e5e0 100644 --- a/plugins/jetpack/modules/publicize/publicize.php +++ b/plugins/jetpack/modules/publicize/publicize.php @@ -39,7 +39,7 @@ abstract class Publicize_Base { * All users with this cap can unglobalize all other global connections, and globalize any of their own * Globalized connections cannot be unselected by users without this capability when publishing */ - const GLOBAL_CAP = 'edit_others_posts'; + var $GLOBAL_CAP = 'edit_others_posts'; /** * Sets up the basics of Publicize @@ -61,6 +61,7 @@ abstract class Publicize_Base { 'url', ) ); + $this->GLOBAL_CAP = apply_filters( 'jetpack_publicize_global_connections_cap', $this->GLOBAL_CAP ); // stage 1 and 2 of 3-stage Publicize. Flag for Publicize on creation, save meta, // then check meta and publicze based on that. stage 3 implemented on wpcom @@ -100,8 +101,6 @@ abstract class Publicize_Base { return 'http://' . $cmeta['connection_data']['meta']['tumblr_base_hostname']; } elseif ( 'twitter' == $service_name ) { return 'http://twitter.com/' . substr( $cmeta['external_display'], 1 ); // Has a leading '@' - } else if ( 'yahoo' == $service_name ) { - return 'http://profile.yahoo.com/' . $cmeta['external_id']; } else if ( 'linkedin' == $service_name ) { if ( !isset( $cmeta['connection_data']['meta']['profile_url'] ) ) { return false; @@ -109,11 +108,15 @@ abstract class Publicize_Base { $profile_url_query = parse_url( $cmeta['connection_data']['meta']['profile_url'], PHP_URL_QUERY ); wp_parse_str( $profile_url_query, $profile_url_query_args ); - if ( !isset( $profile_url_query_args['key'] ) ) { + if ( isset( $profile_url_query_args['key'] ) ) { + $id = $profile_url_query_args['key']; + } elseif ( isset( $profile_url_query_args['id'] ) ) { + $id = $profile_url_query_args['id']; + } else { return false; } - return esc_url_raw( add_query_arg( 'id', urlencode( $profile_url_query_args['key'] ), 'http://www.linkedin.com/profile/view' ) ); + return esc_url_raw( add_query_arg( 'id', urlencode( $id ), 'http://www.linkedin.com/profile/view' ) ); } else { return false; // no fallback. we just won't link it } @@ -139,11 +142,8 @@ abstract class Publicize_Base { } } - function get_service_label( $service_name ) { + public static function get_service_label( $service_name ) { switch ( $service_name ) { - case 'yahoo': - return 'Yahoo!'; - break; case 'linkedin': return 'LinkedIn'; break; @@ -211,8 +211,7 @@ abstract class Publicize_Base { $cron_user = null; $submit_post = true; - // don't do anything if its not actually a post - if ( 'post' !== $post->post_type ) + if ( ! $this->post_type_is_publicizeable( $post->post_type ) ) return; // Don't Publicize during certain contexts: @@ -285,7 +284,13 @@ abstract class Publicize_Base { */ foreach ( (array) $this->get_services( 'connected' ) as $service_name => $connections ) { foreach ( $connections as $connection ) { - if ( false == apply_filters( 'wpas_submit_post?', $submit_post, $post_id, $service_name ) ) { + $connection_data = ''; + if ( method_exists( $connection, 'get_meta' ) ) + $connection_data = $connection->get_meta( 'connection_data' ); + elseif ( ! empty( $connection['connection_data'] ) ) + $connection_data = $connection['connection_data']; + + if ( false == apply_filters( 'wpas_submit_post?', $submit_post, $post_id, $service_name, $connection_data ) ) { delete_post_meta( $post_id, $this->PENDING ); continue; } @@ -325,4 +330,20 @@ abstract class Publicize_Base { // Next up will be ::publicize_post() } + + /** + * Is a given post type Publicize-able? + * + * Not every CPT lends itself to Publicize-ation. Allow CPTs to register by adding their CPT via + * the publicize_post_types array filter. + * + * @param string $post_type The post type to check. + * $return bool True if the post type can be Publicized. + */ + function post_type_is_publicizeable( $post_type ) { + if ( 'post' == $post_type ) + return true; + + return post_type_supports( $post_type, 'publicize' ); + } } |