summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/sharedaddy')
-rw-r--r--plugins/jetpack/modules/sharedaddy/sharedaddy.php1
-rw-r--r--plugins/jetpack/modules/sharedaddy/sharing-service.php355
-rw-r--r--plugins/jetpack/modules/sharedaddy/sharing-sources.php14
-rw-r--r--plugins/jetpack/modules/sharedaddy/sharing.js4
-rw-r--r--plugins/jetpack/modules/sharedaddy/sharing.php13
5 files changed, 229 insertions, 158 deletions
diff --git a/plugins/jetpack/modules/sharedaddy/sharedaddy.php b/plugins/jetpack/modules/sharedaddy/sharedaddy.php
index f8d0e92f..3f34cf32 100644
--- a/plugins/jetpack/modules/sharedaddy/sharedaddy.php
+++ b/plugins/jetpack/modules/sharedaddy/sharedaddy.php
@@ -275,6 +275,7 @@ function sharing_email_check( $true, $post, $data ) {
add_action( 'init', 'sharing_init' );
add_action( 'add_meta_boxes', 'sharing_add_meta_box' );
add_action( 'save_post', 'sharing_meta_box_save' );
+add_action( 'edit_attachment', 'sharing_meta_box_save' );
add_action( 'sharing_email_send_post', 'sharing_email_send_post' );
add_filter( 'sharing_email_can_send', 'sharing_email_check_for_spam_via_akismet' );
add_action( 'sharing_global_options', 'sharing_global_resources', 30 );
diff --git a/plugins/jetpack/modules/sharedaddy/sharing-service.php b/plugins/jetpack/modules/sharedaddy/sharing-service.php
index 86e3cc20..ec7bb0b6 100644
--- a/plugins/jetpack/modules/sharedaddy/sharing-service.php
+++ b/plugins/jetpack/modules/sharedaddy/sharing-service.php
@@ -1,11 +1,11 @@
<?php
-include_once dirname( __FILE__ ).'/sharing-sources.php';
+include_once dirname( __FILE__ ) . '/sharing-sources.php';
define( 'WP_SHARING_PLUGIN_VERSION', JETPACK__VERSION );
class Sharing_Service {
- private $global = false;
+ private $global = false;
public $default_sharing_label = '';
public function __construct() {
@@ -16,20 +16,21 @@ class Sharing_Service {
* Gets a generic list of all services, without any config
*/
public function get_all_services_blog() {
- $options = get_option( 'sharing-options' );
+ $options = get_option( 'sharing-options' );
- $all = $this->get_all_services();
+ $all = $this->get_all_services();
$services = array();
- foreach ( $all AS $id => $name ) {
- if ( isset( $all[$id] ) ) {
+ foreach ( $all as $id => $name ) {
+ if ( isset( $all[ $id ] ) ) {
$config = array();
// Pre-load custom modules otherwise they won't know who they are
- if ( substr( $id, 0, 7 ) == 'custom-' && is_array( $options[$id] ) )
- $config = $options[$id];
+ if ( substr( $id, 0, 7 ) == 'custom-' && is_array( $options[ $id ] ) ) {
+ $config = $options[ $id ];
+ }
- $services[$id] = new $all[$id]( $id, $config );
+ $services[ $id ] = new $all[ $id ]( $id, $config );
}
}
@@ -45,18 +46,18 @@ class Sharing_Service {
// if you update this list, please update the REST API tests
// in bin/tests/api/suites/SharingTest.php
$services = array(
- 'print' => 'Share_Print',
- 'facebook' => 'Share_Facebook',
- 'linkedin' => 'Share_LinkedIn',
- 'reddit' => 'Share_Reddit',
- 'twitter' => 'Share_Twitter',
- 'google-plus-1' => 'Share_GooglePlus1',
- 'tumblr' => 'Share_Tumblr',
- 'pinterest' => 'Share_Pinterest',
- 'pocket' => 'Share_Pocket',
- 'telegram' => 'Share_Telegram',
- 'jetpack-whatsapp' => 'Jetpack_Share_WhatsApp',
- 'skype' => 'Share_Skype',
+ 'print' => 'Share_Print',
+ 'facebook' => 'Share_Facebook',
+ 'linkedin' => 'Share_LinkedIn',
+ 'reddit' => 'Share_Reddit',
+ 'twitter' => 'Share_Twitter',
+ 'google-plus-1' => 'Share_GooglePlus1',
+ 'tumblr' => 'Share_Tumblr',
+ 'pinterest' => 'Share_Pinterest',
+ 'pocket' => 'Share_Pocket',
+ 'telegram' => 'Share_Telegram',
+ 'jetpack-whatsapp' => 'Jetpack_Share_WhatsApp',
+ 'skype' => 'Share_Skype',
);
/**
@@ -80,8 +81,8 @@ class Sharing_Service {
if ( $include_custom ) {
// Add any custom services in
$options = $this->get_global_options();
- foreach ( (array) $options['custom'] AS $custom_id ) {
- $services[$custom_id] = 'Share_Custom';
+ foreach ( (array) $options['custom'] as $custom_id ) {
+ $services[ $custom_id ] = 'Share_Custom';
}
}
@@ -105,10 +106,11 @@ class Sharing_Service {
if ( $label && $url && $icon ) {
$options = get_option( 'sharing-options' );
- if ( !is_array( $options ) )
+ if ( ! is_array( $options ) ) {
$options = array();
+ }
- $service_id = 'custom-'.time();
+ $service_id = 'custom-' . time();
// Add a new custom service
$options['global']['custom'][] = $service_id;
@@ -119,7 +121,13 @@ class Sharing_Service {
update_option( 'sharing-options', $options );
// Create a custom service and set the options for it
- $service = new Share_Custom( $service_id, array( 'name' => $label, 'url' => $url, 'icon' => $icon ) );
+ $service = new Share_Custom(
+ $service_id, array(
+ 'name' => $label,
+ 'url' => $url,
+ 'icon' => $icon,
+ )
+ );
$this->set_service( $service_id, $service );
// Return the service
@@ -131,19 +139,21 @@ class Sharing_Service {
public function delete_service( $service_id ) {
$options = get_option( 'sharing-options' );
- if ( isset( $options[$service_id] ) )
- unset( $options[$service_id] );
+ if ( isset( $options[ $service_id ] ) ) {
+ unset( $options[ $service_id ] );
+ }
$key = array_search( $service_id, $options['global']['custom'] );
- if ( $key !== false )
- unset( $options['global']['custom'][$key] );
+ if ( $key !== false ) {
+ unset( $options['global']['custom'][ $key ] );
+ }
update_option( 'sharing-options', $options );
return true;
}
public function set_blog_services( array $visible, array $hidden ) {
- $services = $this->get_all_services();
+ $services = $this->get_all_services();
// Validate the services
$available = array_keys( $services );
@@ -162,24 +172,31 @@ class Sharing_Service {
* @since 1.1.0
*
* @param array $args {
- * Array of options describing the state of the sharing services.
+ * Array of options describing the state of the sharing services.
*
- * @type array $services List of all available service names and classes.
- * @type array $available Validated list of all available service names and classes.
- * @type array $hidden List of services hidden behind a "More" button.
- * @type array $visible List of visible services.
- * @type array $this->get_blog_services() Array of Sharing Services currently enabled.
+ * @type array $services List of all available service names and classes.
+ * @type array $available Validated list of all available service names and classes.
+ * @type array $hidden List of services hidden behind a "More" button.
+ * @type array $visible List of visible services.
+ * @type array $this->get_blog_services() Array of Sharing Services currently enabled.
* }
*/
- do_action( 'sharing_get_services_state', array(
- 'services' => $services,
- 'available' => $available,
- 'hidden' => $hidden,
- 'visible' => $visible,
- 'currently_enabled' => $this->get_blog_services()
- ) );
+ do_action(
+ 'sharing_get_services_state', array(
+ 'services' => $services,
+ 'available' => $available,
+ 'hidden' => $hidden,
+ 'visible' => $visible,
+ 'currently_enabled' => $this->get_blog_services(),
+ )
+ );
- return update_option( 'sharing-services', array( 'visible' => $visible, 'hidden' => $hidden ) );
+ return update_option(
+ 'sharing-services', array(
+ 'visible' => $visible,
+ 'hidden' => $hidden,
+ )
+ );
}
public function get_blog_services() {
@@ -194,7 +211,7 @@ class Sharing_Service {
*/
if ( ! is_array( $options ) || ! isset( $options['button_style'], $options['global'] ) ) {
$global_options = array( 'global' => $this->get_global_options() );
- $options = is_array( $options )
+ $options = is_array( $options )
? array_merge( $options, $global_options )
: $global_options;
}
@@ -205,7 +222,7 @@ class Sharing_Service {
if ( ! is_array( $enabled ) ) {
$enabled = array(
'visible' => array(),
- 'hidden' => array()
+ 'hidden' => array(),
);
/**
@@ -228,17 +245,20 @@ class Sharing_Service {
}
if ( is_array( $enabled['hidden'] ) ) {
- $enabled['hidden'] = array_unique( $enabled['hidden'] );
+ $enabled['hidden'] = array_unique( $enabled['hidden'] );
} else {
$enabled['hidden'] = array();
}
// Form the enabled services
- $blog = array( 'visible' => array(), 'hidden' => array() );
+ $blog = array(
+ 'visible' => array(),
+ 'hidden' => array(),
+ );
- foreach ( $blog AS $area => $stuff ) {
- foreach ( (array)$enabled[$area] AS $service ) {
- if ( isset( $services[$service] ) ) {
+ foreach ( $blog as $area => $stuff ) {
+ foreach ( (array) $enabled[ $area ] as $service ) {
+ if ( isset( $services[ $service ] ) ) {
if ( ! isset( $options[ $service ] ) || ! is_array( $options[ $service ] ) ) {
$options[ $service ] = array();
}
@@ -259,8 +279,9 @@ class Sharing_Service {
$blog = apply_filters( 'sharing_services_enabled', $blog );
// Add CSS for NASCAR
- if ( count( $blog['visible'] ) || count( $blog['hidden'] ) )
+ if ( count( $blog['visible'] ) || count( $blog['hidden'] ) ) {
add_filter( 'post_flair_block_css', 'post_flair_service_enabled_sharing' );
+ }
// Convenience for checking if a service is present
$blog['all'] = array_flip( array_merge( array_keys( $blog['visible'] ), array_keys( $blog['hidden'] ) ) );
@@ -270,11 +291,13 @@ class Sharing_Service {
public function get_service( $service_name ) {
$services = $this->get_blog_services();
- if ( isset( $services['visible'][$service_name] ) )
- return $services['visible'][$service_name];
+ if ( isset( $services['visible'][ $service_name ] ) ) {
+ return $services['visible'][ $service_name ];
+ }
- if ( isset( $services['hidden'][$service_name] ) )
- return $services['hidden'][$service_name];
+ if ( isset( $services['hidden'][ $service_name ] ) ) {
+ return $services['hidden'][ $service_name ];
+ }
return false;
}
@@ -283,8 +306,9 @@ class Sharing_Service {
$options = get_option( 'sharing-options' );
// No options yet
- if ( !is_array( $options ) )
+ if ( ! is_array( $options ) ) {
$options = array();
+ }
// Defaults
$options['global'] = array(
@@ -292,7 +316,7 @@ class Sharing_Service {
'sharing_label' => $this->default_sharing_label,
'open_links' => 'same',
'show' => array(),
- 'custom' => isset( $options['global']['custom'] ) ? $options['global']['custom'] : array()
+ 'custom' => isset( $options['global']['custom'] ) ? $options['global']['custom'] : array(),
);
/**
@@ -307,8 +331,9 @@ class Sharing_Service {
$options['global'] = apply_filters( 'sharing_default_global', $options['global'] );
// Validate options and set from our data
- if ( isset( $data['button_style'] ) && in_array( $data['button_style'], array( 'icon-text', 'icon', 'text', 'official' ) ) )
+ if ( isset( $data['button_style'] ) && in_array( $data['button_style'], array( 'icon-text', 'icon', 'text', 'official' ) ) ) {
$options['global']['button_style'] = $data['button_style'];
+ }
if ( isset( $data['sharing_label'] ) ) {
if ( $this->default_sharing_label === $data['sharing_label'] ) {
@@ -318,23 +343,24 @@ class Sharing_Service {
}
}
- if ( isset( $data['open_links'] ) && in_array( $data['open_links'], array( 'new', 'same' ) ) )
+ if ( isset( $data['open_links'] ) && in_array( $data['open_links'], array( 'new', 'same' ) ) ) {
$options['global']['open_links'] = $data['open_links'];
+ }
- $shows = array_values( get_post_types( array( 'public' => true ) ) );
+ $shows = array_values( get_post_types( array( 'public' => true ) ) );
$shows[] = 'index';
if ( isset( $data['show'] ) ) {
if ( is_scalar( $data['show'] ) ) {
switch ( $data['show'] ) {
- case 'posts' :
- $data['show'] = array( 'post', 'page' );
- break;
- case 'index' :
- $data['show'] = array( 'index' );
- break;
- case 'posts-index' :
- $data['show'] = array( 'post', 'page', 'index' );
- break;
+ case 'posts':
+ $data['show'] = array( 'post', 'page' );
+ break;
+ case 'index':
+ $data['show'] = array( 'index' );
+ break;
+ case 'posts-index':
+ $data['show'] = array( 'post', 'page', 'index' );
+ break;
}
}
@@ -362,15 +388,15 @@ class Sharing_Service {
$this->global['show'] = array( 'post', 'page' );
} elseif ( is_scalar( $this->global['show'] ) ) {
switch ( $this->global['show'] ) {
- case 'posts' :
- $this->global['show'] = array( 'post', 'page' );
- break;
- case 'index' :
- $this->global['show'] = array( 'index' );
- break;
- case 'posts-index' :
- $this->global['show'] = array( 'post', 'page', 'index' );
- break;
+ case 'posts':
+ $this->global['show'] = array( 'post', 'page' );
+ break;
+ case 'index':
+ $this->global['show'] = array( 'index' );
+ break;
+ case 'posts-index':
+ $this->global['show'] = array( 'post', 'page', 'index' );
+ break;
}
}
@@ -398,16 +424,22 @@ class Sharing_Service {
* @since 1.1.0
*
* @param array $args {
- * State of a sharing button.
+ * State of a sharing button.
*
- * @type string $id Service ID.
- * @type array $options Array of all sharing options.
- * @type array $service Details about a service.
+ * @type string $id Service ID.
+ * @type array $options Array of all sharing options.
+ * @type array $service Details about a service.
* }
*/
- do_action( 'sharing_get_button_state', array( 'id' => $id, 'options' => $options, 'service' => $service ) );
+ do_action(
+ 'sharing_get_button_state', array(
+ 'id' => $id,
+ 'options' => $options,
+ 'service' => $service,
+ )
+ );
- $options[$id] = $service->get_options();
+ $options[ $id ] = $service->get_options();
update_option( 'sharing-options', array_filter( $options ) );
}
@@ -415,33 +447,35 @@ class Sharing_Service {
// Soon to come to a .org plugin near you!
public function get_total( $service_name = false, $post_id = false, $_blog_id = false ) {
global $wpdb, $blog_id;
- if ( !$_blog_id ) {
+ if ( ! $_blog_id ) {
$_blog_id = $blog_id;
}
if ( $service_name == false ) {
if ( $post_id > 0 ) {
// total number of shares for this post
- return (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND post_id = %d", $_blog_id, $post_id ) );
+ return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND post_id = %d', $_blog_id, $post_id ) );
} else {
// total number of shares for this blog
- return (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d", $_blog_id ) );
+ return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d', $_blog_id ) );
}
}
- if ( $post_id > 0 )
- return (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s", $_blog_id, $post_id, $service_name ) );
- else
- return (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s", $_blog_id, $service_name ) );
+ if ( $post_id > 0 ) {
+ return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s', $_blog_id, $post_id, $service_name ) );
+ } else {
+ return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s', $_blog_id, $service_name ) );
+ }
}
public function get_services_total( $post_id = false ) {
- $totals = array();
+ $totals = array();
$services = $this->get_blog_services();
- if ( !empty( $services ) && isset( $services[ 'all' ] ) )
- foreach( $services[ 'all' ] as $key => $value ) {
- $totals[$key] = new Sharing_Service_Total( $key, $this->get_total( $key, $post_id ) );
+ if ( ! empty( $services ) && isset( $services['all'] ) ) {
+ foreach ( $services['all'] as $key => $value ) {
+ $totals[ $key ] = new Sharing_Service_Total( $key, $this->get_total( $key, $post_id ) );
}
+ }
usort( $totals, array( 'Sharing_Service_Total', 'cmp' ) );
return $totals;
@@ -451,11 +485,13 @@ class Sharing_Service {
$totals = array();
global $wpdb, $blog_id;
- $my_data = $wpdb->get_results( $wpdb->prepare( "SELECT post_id as id, SUM( count ) as total FROM sharing_stats WHERE blog_id = %d GROUP BY post_id ORDER BY count DESC ", $blog_id ) );
+ $my_data = $wpdb->get_results( $wpdb->prepare( 'SELECT post_id as id, SUM( count ) as total FROM sharing_stats WHERE blog_id = %d GROUP BY post_id ORDER BY count DESC ', $blog_id ) );
- if ( !empty( $my_data ) )
- foreach( $my_data as $row )
+ if ( ! empty( $my_data ) ) {
+ foreach ( $my_data as $row ) {
$totals[] = new Sharing_Post_Total( $row->id, $row->total );
+ }
+ }
usort( $totals, array( 'Sharing_Post_Total', 'cmp' ) );
@@ -464,23 +500,24 @@ class Sharing_Service {
}
class Sharing_Service_Total {
- public $id = '';
- public $name = '';
- public $service = '';
- public $total = 0;
+ public $id = '';
+ public $name = '';
+ public $service = '';
+ public $total = 0;
public function __construct( $id, $total ) {
- $services = new Sharing_Service();
- $this->id = esc_html( $id );
- $this->service = $services->get_service( $id );
- $this->total = (int) $total;
+ $services = new Sharing_Service();
+ $this->id = esc_html( $id );
+ $this->service = $services->get_service( $id );
+ $this->total = (int) $total;
- $this->name = $this->service->get_name();
+ $this->name = $this->service->get_name();
}
static function cmp( $a, $b ) {
- if ( $a->total == $b->total )
+ if ( $a->total == $b->total ) {
return $a->name < $b->name;
+ }
return $a->total < $b->total;
}
}
@@ -492,15 +529,16 @@ class Sharing_Post_Total {
public $url = '';
public function __construct( $id, $total ) {
- $this->id = (int) $id;
- $this->total = (int) $total;
- $this->title = get_the_title( $this->id );
- $this->url = get_permalink( $this->id );
+ $this->id = (int) $id;
+ $this->total = (int) $total;
+ $this->title = get_the_title( $this->id );
+ $this->url = get_permalink( $this->id );
}
static function cmp( $a, $b ) {
- if ( $a->total == $b->total )
+ if ( $a->total == $b->total ) {
return $a->id < $b->id;
+ }
return $a->total < $b->total;
}
}
@@ -508,17 +546,18 @@ class Sharing_Post_Total {
function sharing_register_post_for_share_counts( $post_id ) {
global $jetpack_sharing_counts;
- if ( ! isset( $jetpack_sharing_counts ) || ! is_array( $jetpack_sharing_counts ) )
+ if ( ! isset( $jetpack_sharing_counts ) || ! is_array( $jetpack_sharing_counts ) ) {
$jetpack_sharing_counts = array();
+ }
$jetpack_sharing_counts[ (int) $post_id ] = get_permalink( $post_id );
}
function sharing_maybe_enqueue_scripts() {
- $sharer = new Sharing_Service();
- $global_options = $sharer->get_global_options();
+ $sharer = new Sharing_Service();
+ $global_options = $sharer->get_global_options();
- $enqueue = false;
+ $enqueue = false;
if ( is_singular() && in_array( get_post_type(), $global_options['show'] ) ) {
$enqueue = true;
} elseif ( in_array( 'index', $global_options['show'] ) && ( is_home() || is_front_page() || is_archive() || is_search() || in_array( get_post_type(), $global_options['show'] ) ) ) {
@@ -563,40 +602,41 @@ function sharing_add_footer() {
if ( apply_filters( 'jetpack_sharing_counts', true ) && is_array( $jetpack_sharing_counts ) && count( $jetpack_sharing_counts ) ) :
$sharing_post_urls = array_filter( $jetpack_sharing_counts );
if ( $sharing_post_urls ) :
-?>
+ ?>
<script type="text/javascript">
window.WPCOM_sharing_counts = <?php echo json_encode( array_flip( $sharing_post_urls ) ); ?>;
</script>
-<?php
+ <?php
endif;
endif;
wp_enqueue_script( 'sharing-js' );
$sharing_js_options = array(
- 'lang' => get_base_recaptcha_lang_code(),
+ 'lang' => get_base_recaptcha_lang_code(),
/** This filter is documented in modules/sharedaddy/sharing-service.php */
- 'counts' => apply_filters( 'jetpack_sharing_counts', true )
+ 'counts' => apply_filters( 'jetpack_sharing_counts', true ),
+ 'is_stats_active' => Jetpack::is_module_active( 'stats' ),
);
- wp_localize_script( 'sharing-js', 'sharing_js_options', $sharing_js_options);
+ wp_localize_script( 'sharing-js', 'sharing_js_options', $sharing_js_options );
}
- $sharer = new Sharing_Service();
+ $sharer = new Sharing_Service();
$enabled = $sharer->get_blog_services();
- foreach ( array_merge( $enabled['visible'], $enabled['hidden'] ) AS $service ) {
+ foreach ( array_merge( $enabled['visible'], $enabled['hidden'] ) as $service ) {
$service->display_footer();
}
}
function sharing_add_header() {
- $sharer = new Sharing_Service();
+ $sharer = new Sharing_Service();
$enabled = $sharer->get_blog_services();
- foreach ( array_merge( $enabled['visible'], $enabled['hidden'] ) AS $service ) {
+ foreach ( array_merge( $enabled['visible'], $enabled['hidden'] ) as $service ) {
$service->display_header();
}
if ( count( $enabled['all'] ) > 0 && sharing_maybe_enqueue_scripts() ) {
- wp_enqueue_style( 'sharedaddy', plugin_dir_url( __FILE__ ) .'sharing.css', array(), JETPACK__VERSION );
+ wp_enqueue_style( 'sharedaddy', plugin_dir_url( __FILE__ ) . 'sharing.css', array(), JETPACK__VERSION );
wp_enqueue_style( 'social-logos' );
}
@@ -626,8 +666,9 @@ function sharing_display( $text = '', $echo = false ) {
return $text;
}
- if ( empty( $post ) )
+ if ( empty( $post ) ) {
return $text;
+ }
if ( ( is_preview() || is_admin() ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
return $text;
@@ -642,19 +683,21 @@ function sharing_display( $text = '', $echo = false ) {
$done = false;
foreach ( $wp_current_filter as $filter ) {
if ( 'the_content' == $filter ) {
- if ( $done )
+ if ( $done ) {
return $text;
- else
+ } else {
$done = true;
+ }
}
}
// check whether we are viewing the front page and whether the front page option is checked
- $options = get_option( 'sharing-options' );
+ $options = get_option( 'sharing-options' );
$display_options = $options['global']['show'];
- if ( is_front_page() && ( is_array( $display_options ) && ! in_array( 'index', $display_options ) ) )
+ if ( is_front_page() && ( is_array( $display_options ) && ! in_array( 'index', $display_options ) ) ) {
return $text;
+ }
if ( is_attachment() && in_array( 'the_excerpt', (array) $wp_current_filter ) ) {
// Many themes run the_excerpt() conditionally on an attachment page, then run the_content().
@@ -666,7 +709,7 @@ function sharing_display( $text = '', $echo = false ) {
$global = $sharer->get_global_options();
$show = false;
- if ( !is_feed() ) {
+ if ( ! is_feed() ) {
if ( is_singular() && in_array( get_post_type(), $global['show'] ) ) {
$show = true;
} elseif ( in_array( 'index', $global['show'] ) && ( is_home() || is_front_page() || is_archive() || is_search() || in_array( get_post_type(), $global['show'] ) ) ) {
@@ -689,7 +732,7 @@ function sharing_display( $text = '', $echo = false ) {
// Disabled for this post?
$switched_status = get_post_meta( $post->ID, 'sharing_disabled', false );
- if ( !empty( $switched_status ) ) {
+ if ( ! empty( $switched_status ) ) {
$show = false;
}
@@ -701,11 +744,12 @@ function sharing_display( $text = '', $echo = false ) {
}
// Allow to be used on P2 ajax requests for latest posts.
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && 'get_latest_posts' == $_REQUEST['action'] )
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && 'get_latest_posts' == $_REQUEST['action'] ) {
$show = true;
+ }
$sharing_content = '';
- $enabled = false;
+ $enabled = false;
if ( $show ) {
/**
@@ -752,18 +796,20 @@ function sharing_display( $text = '', $echo = false ) {
$visible .= '<li class="share-' . $service->get_class() . '">' . $service->get_display( $post ) . '</li>';
}
- $parts = array();
+ $parts = array();
$parts[] = $visible;
if ( count( $enabled['hidden'] ) > 0 ) {
- if ( count( $enabled['visible'] ) > 0 )
+ if ( count( $enabled['visible'] ) > 0 ) {
$expand = __( 'More', 'jetpack' );
- else
+ } else {
$expand = __( 'Share', 'jetpack' );
- $parts[] = '<li><a href="#" class="sharing-anchor sd-button share-more"><span>'.$expand.'</span></a></li>';
+ }
+ $parts[] = '<li><a href="#" class="sharing-anchor sd-button share-more"><span>' . $expand . '</span></a></li>';
}
- if ( $dir == 'rtl' )
+ if ( $dir == 'rtl' ) {
$parts = array_reverse( $parts );
+ }
$sharing_content .= implode( '', $parts );
$sharing_content .= '<li class="share-end"></li></ul>';
@@ -771,25 +817,28 @@ function sharing_display( $text = '', $echo = false ) {
if ( count( $enabled['hidden'] ) > 0 ) {
$sharing_content .= '<div class="sharing-hidden"><div class="inner" style="display: none;';
- if ( count( $enabled['hidden'] ) == 1 )
+ if ( count( $enabled['hidden'] ) == 1 ) {
$sharing_content .= 'width:150px;';
+ }
$sharing_content .= '">';
- if ( count( $enabled['hidden'] ) == 1 )
+ if ( count( $enabled['hidden'] ) == 1 ) {
$sharing_content .= '<ul style="background-image:none;">';
- else
+ } else {
$sharing_content .= '<ul>';
+ }
$count = 1;
foreach ( $enabled['hidden'] as $id => $service ) {
// Individual HTML for sharing service
- $sharing_content .= '<li class="share-'.$service->get_class().'">';
+ $sharing_content .= '<li class="share-' . $service->get_class() . '">';
$sharing_content .= $service->get_display( $post );
$sharing_content .= '</li>';
- if ( ( $count % 2 ) == 0 )
+ if ( ( $count % 2 ) == 0 ) {
$sharing_content .= '<li class="share-end"></li>';
+ }
$count ++;
}
@@ -834,10 +883,11 @@ function sharing_display( $text = '', $echo = false ) {
*/
$sharing_markup = apply_filters( 'jetpack_sharing_display_markup', $sharing_content, $enabled );
- if ( $echo )
+ if ( $echo ) {
echo $text . $sharing_markup;
- else
+ } else {
return $text . $sharing_markup;
+ }
}
add_filter( 'the_content', 'sharing_display', 19 );
@@ -856,12 +906,13 @@ function get_base_recaptcha_lang_code() {
'pt-br' => 'pt',
'ru' => 'ru',
'es' => 'es',
- 'tr' => 'tr'
+ 'tr' => 'tr',
);
$blog_lang_code = function_exists( 'get_blog_lang_code' ) ? get_blog_lang_code() : get_bloginfo( 'language' );
- if( isset( $base_recaptcha_lang_code_mapping[ $blog_lang_code ] ) )
+ if ( isset( $base_recaptcha_lang_code_mapping[ $blog_lang_code ] ) ) {
return $base_recaptcha_lang_code_mapping[ $blog_lang_code ];
+ }
// if no base mapping is found return default 'en'
return 'en';
diff --git a/plugins/jetpack/modules/sharedaddy/sharing-sources.php b/plugins/jetpack/modules/sharedaddy/sharing-sources.php
index a086e0f0..a77a6cbf 100644
--- a/plugins/jetpack/modules/sharedaddy/sharing-sources.php
+++ b/plugins/jetpack/modules/sharedaddy/sharing-sources.php
@@ -201,11 +201,12 @@ abstract class Sharing_Source {
$text = apply_filters( 'jetpack_sharing_display_text', $text, $this, $id, $args );
return sprintf(
- '<a rel="nofollow" data-shared="%s" class="%s" href="%s"%s title="%s"><span%s>%s</span></a>',
+ '<a rel="nofollow%s" data-shared="%s" class="%s" href="%s"%s title="%s"><span%s>%s</span></a>',
+ ( true == $this->open_link_in_new ) ? ' noopener noreferrer' : '',
( $id ? esc_attr( $id ) : '' ),
implode( ' ', $klasses ),
$url,
- ( true == $this->open_link_in_new ) ? ' rel="noopener noreferrer" target="_blank"' : '',
+ ( true == $this->open_link_in_new ) ? ' target="_blank"' : '',
$title,
( 'icon' == $this->button_style ) ? '></span><span class="sharing-screen-reader-text"' : '',
$text
@@ -532,7 +533,7 @@ class Share_Email extends Sharing_Source {
/** This filter is documented in modules/stats.php */
echo apply_filters( 'jetpack_static_url', plugin_dir_url( __FILE__ ) . 'images/loading.gif' ); ?>" alt="loading" width="16" height="16" />
<input type="submit" value="<?php esc_attr_e( 'Send Email', 'jetpack' ); ?>" class="sharing_send" />
- <a rel="nofollow" href="#cancel" class="sharing_cancel"><?php _e( 'Cancel', 'jetpack' ); ?></a>
+ <a rel="nofollow" href="#cancel" class="sharing_cancel" role="button"><?php _e( 'Cancel', 'jetpack' ); ?></a>
<div class="errors errors-1" style="display: none;">
<?php _e( 'Post was not sent - check your email addresses!', 'jetpack' ); ?>
@@ -589,7 +590,12 @@ class Share_Twitter extends Sharing_Source {
* @param string $string Twitter Username.
* @param array $args Array of Open Graph Meta Tags and Twitter Cards tags.
*/
- $twitter_site_tag_value = apply_filters( 'jetpack_twitter_cards_site_tag', '', array() );
+ $twitter_site_tag_value = apply_filters(
+ 'jetpack_twitter_cards_site_tag',
+ '',
+ /** This action is documented in modules/sharedaddy/sharing-sources.php */
+ array( 'twitter:creator' => apply_filters( 'jetpack_sharing_twitter_via', '', $post->ID ) )
+ );
/*
* Hack to remove the unwanted behavior of adding 'via @jetpack' which
diff --git a/plugins/jetpack/modules/sharedaddy/sharing.js b/plugins/jetpack/modules/sharedaddy/sharing.js
index 9d8d5c5d..52430634 100644
--- a/plugins/jetpack/modules/sharedaddy/sharing.js
+++ b/plugins/jetpack/modules/sharedaddy/sharing.js
@@ -42,7 +42,9 @@ if ( sharing_js_options && sharing_js_options.counts ) {
jQuery.getScript( service_request );
}
- WPCOMSharing.bump_sharing_count_stat( service );
+ if ( sharing_js_options.is_stats_active ) {
+ WPCOMSharing.bump_sharing_count_stat( service );
+ }
}
WPCOMSharing.done_urls[ id ] = true;
diff --git a/plugins/jetpack/modules/sharedaddy/sharing.php b/plugins/jetpack/modules/sharedaddy/sharing.php
index 19b0e3be..0e3d7ee5 100644
--- a/plugins/jetpack/modules/sharedaddy/sharing.php
+++ b/plugins/jetpack/modules/sharedaddy/sharing.php
@@ -85,7 +85,14 @@ class Sharing_Admin {
}
}
- add_submenu_page( 'options-general.php', __( 'Sharing Settings', 'jetpack' ), __( 'Sharing', 'jetpack' ), 'publish_posts', 'sharing', array( &$this, 'management_page' ) );
+ add_submenu_page(
+ 'options-general.php',
+ __( 'Sharing Settings', 'jetpack' ),
+ __( 'Sharing', 'jetpack' ),
+ 'publish_posts',
+ 'sharing',
+ array( &$this, 'wrapper_admin_page' )
+ );
}
public function ajax_save_services() {
@@ -173,6 +180,10 @@ class Sharing_Admin {
<?php
}
+ public function wrapper_admin_page() {
+ Jetpack_Admin_Page::wrap_ui( array( &$this, 'management_page' ), array( 'is-wide' =>true ) );
+ }
+
public function management_page() {
$sharer = new Sharing_Service();
$enabled = $sharer->get_blog_services();