public function output() { global $post; if (!function_exists('sharing_display')) { return; } $buttons = sharing_display(''); if ('' == $buttons) { return; } $sharer = new Sharing_Service(); $global = $sharer->get_global_options(); $sharing = ''; $sharing .= sprintf('<a href="#share-%d" class="popup-trigger"><i class="ion-share"></i> %s</a>', $post->ID, __('Share', 'listify')); $sharing .= sprintf('<div class="popup share-popup" id="share-%1$d"> <h3 class="popup-title">%2$s</h3> %3$s </div>', $post->ID, $global['sharing_label'], $buttons); echo $sharing; }
public function __construct($id, $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(); }
function get_default_sharing_status() { $default_sharing_status = false; if (class_exists('Sharing_Service')) { $ss = new Sharing_Service(); $blog_services = $ss->get_blog_services(); $default_sharing_status = !empty($blog_services['visible']); } return (bool) $default_sharing_status; }
/** * Updates site settings for authorized users * * @return (array) */ public function update_settings() { // $this->input() retrieves posted arguments whitelisted and casted to the $request_format // specs that get passed in when this class is instantiated /** * Filters the settings to be updated on the site. * * @since 3.6.0 * * @param array $input Associative array of site settings to be updated. */ $input = apply_filters('rest_api_update_site_settings', $this->input()); $jetpack_relatedposts_options = array(); $sharing_options = array(); $updated = array(); foreach ($input as $key => $value) { if (!is_array($value)) { $value = trim($value); } $value = wp_unslash($value); switch ($key) { case 'default_ping_status': case 'default_comment_status': // settings are stored as closed|open $coerce_value = $value ? 'open' : 'closed'; if (update_option($key, $coerce_value)) { $updated[$key] = $value; } break; case 'jetpack_protect_whitelist': if (function_exists('jetpack_protect_save_whitelist')) { $result = jetpack_protect_save_whitelist($value); if (is_wp_error($result)) { return $result; } $updated[$key] = jetpack_protect_format_whitelist(); } break; case 'jetpack_sync_non_public_post_stati': Jetpack_Options::update_option('sync_non_public_post_stati', $value); break; case 'jetpack_relatedposts_enabled': case 'jetpack_relatedposts_show_thumbnails': case 'jetpack_relatedposts_show_headline': if (!$this->jetpack_relatedposts_supported()) { break; } if ('jetpack_relatedposts_enabled' === $key && method_exists('Jetpack', 'is_module_active') && $this->jetpack_relatedposts_supported()) { $before_action = Jetpack::is_module_active('related-posts'); if ($value) { Jetpack::activate_module('related-posts', false, false); } else { Jetpack::deactivate_module('related-posts'); } $after_action = Jetpack::is_module_active('related-posts'); if ($after_action == $before_action) { break; } } $just_the_key = substr($key, 21); $jetpack_relatedposts_options[$just_the_key] = $value; break; case 'social_notifications_like': case 'social_notifications_reblog': case 'social_notifications_subscribe': // settings are stored as on|off $coerce_value = $value ? 'on' : 'off'; if (update_option($key, $coerce_value)) { $updated[$key] = $value; } break; case 'wga': if (!isset($value['code']) || !preg_match('/^$|^UA-[\\d-]+$/i', $value['code'])) { return new WP_Error('invalid_code', 'Invalid UA ID'); } $wga = get_option('wga', array()); $wga['code'] = $value['code']; // maintain compatibility with wp-google-analytics if (update_option('wga', $wga)) { $updated[$key] = $value; } $enabled_or_disabled = $wga['code'] ? 'enabled' : 'disabled'; do_action('jetpack_bump_stats_extras', 'google-analytics', $enabled_or_disabled); $business_plugins = WPCOM_Business_Plugins::instance(); $business_plugins->activate_plugin('wp-google-analytics'); break; case 'jetpack_comment_likes_enabled': // settings are stored as 1|0 $coerce_value = (int) $value; if (update_option($key, $coerce_value)) { $updated[$key] = $value; } break; // Sharing options // Sharing options case 'sharing_button_style': case 'sharing_show': case 'sharing_open_links': $sharing_options[preg_replace('/^sharing_/', '', $key)] = $value; break; case 'sharing_label': $sharing_options[$key] = $value; break; // Keyring token option // Keyring token option case 'eventbrite_api_token': // These options can only be updated for sites hosted on WordPress.com if (defined('IS_WPCOM') && IS_WPCOM) { if (empty($value) || WPCOM_JSON_API::is_falsy($value)) { if (delete_option($key)) { $updated[$key] = null; } } else { if (update_option($key, $value)) { $updated[$key] = (int) $value; } } } break; // no worries, we've already whitelisted and casted arguments above // no worries, we've already whitelisted and casted arguments above default: if (update_option($key, $value)) { $updated[$key] = $value; } } } if (count($jetpack_relatedposts_options)) { // track new jetpack_relatedposts options against old $old_relatedposts_options = Jetpack_Options::get_option('relatedposts'); if (Jetpack_Options::update_option('relatedposts', $jetpack_relatedposts_options)) { foreach ($jetpack_relatedposts_options as $key => $value) { if ($value !== $old_relatedposts_options[$key]) { $updated['jetpack_relatedposts_' . $key] = $value; } } } } if (!empty($sharing_options) && class_exists('Sharing_Service')) { $ss = new Sharing_Service(); // Merge current values with updated, since Sharing_Service expects // all values to be included when updating $current_sharing_options = $ss->get_global_options(); foreach ($current_sharing_options as $key => $val) { if (!isset($sharing_options[$key])) { $sharing_options[$key] = $val; } } $updated_social_options = $ss->set_global_options($sharing_options); if (isset($input['sharing_button_style'])) { $updated['sharing_button_style'] = (string) $updated_social_options['button_style']; } if (isset($input['sharing_label'])) { // Sharing_Service won't report label as updated if set to default $updated['sharing_label'] = (string) $sharing_options['sharing_label']; } if (isset($input['sharing_show'])) { $updated['sharing_show'] = (array) $updated_social_options['show']; } if (isset($input['sharing_open_links'])) { $updated['sharing_open_links'] = (string) $updated_social_options['open_links']; } } return array('updated' => $updated); }
public function management_page() { $sharer = new Sharing_Service(); $enabled = $sharer->get_blog_services(); $global = $sharer->get_global_options(); $shows = array_values(get_post_types(array('public' => true))); array_unshift($shows, 'index'); if (false == function_exists('mb_stripos')) { echo '<div id="message" class="updated fade"><h3>' . __('Warning! Multibyte support missing!', 'jetpack') . '</h3>'; echo "<p>" . sprintf(__('This plugin will work without it, but multibyte support is used <a href="%s">if available</a>. You may see minor problems with Tweets and other sharing services.', 'jetpack'), "http://www.php.net/manual/en/mbstring.installation.php") . '</p></div>'; } if (isset($_GET['update']) && $_GET['update'] == 'saved') { echo '<div class="updated"><p>' . __('Settings have been saved', 'jetpack') . '</p></div>'; } ?> <div class="wrap"> <div class="icon32" id="icon-options-general"><br /></div> <h2><?php _e('Sharing Settings', 'jetpack'); ?> </h2> <div id="services-config"> <table id="available-services"> <tr> <td class="description"> <h3><?php _e('Available Services', 'jetpack'); ?> </h3> <p><?php _e("Drag and drop the services you'd like to enable into the box below.", 'jetpack'); ?> </p> <p><a href="#TB_inline?height=395&width=600&inlineId=new-service" title="<?php echo esc_attr(__('Add a new service', 'jetpack')); ?> " class="thickbox"><?php _e('Add a new service', 'jetpack'); ?> </a></p> </td> <td class="services"> <ul class="services-available" style="height: 100px;"> <?php foreach ($sharer->get_all_services_blog() as $id => $service) { ?> <?php if (!isset($enabled['all'][$id])) { $this->output_service($id, $service); } ?> <?php } ?> </ul> <br class="clearing" /> </td> </tr> </table> <table id="enabled-services"> <tr> <td class="description"> <h3> <?php _e('Enabled Services', 'jetpack'); ?> <img src="<?php echo admin_url('images/loading.gif'); ?> " width="16" height="16" alt="loading" style="vertical-align: middle; display: none" /> </h3> <p><?php _e('Services dragged here will appear individually.', 'jetpack'); ?> </p> </td> <td class="services" id="share-drop-target"> <h2 id="drag-instructions" <?php if (count($enabled['visible']) > 0) { echo ' style="display: none"'; } ?> ><?php _e('Drag and drop available services here', 'jetpack'); ?> </h2> <ul class="services-enabled"> <?php foreach ($enabled['visible'] as $id => $service) { ?> <?php $this->output_service($id, $service, true); ?> <?php } ?> <li class="end-fix"></li> </ul> </td> <td id="hidden-drop-target" class="services"> <p><?php _e('Services dragged here will be hidden behind a share button.', 'jetpack'); ?> </p> <ul class="services-hidden"> <?php foreach ($enabled['hidden'] as $id => $service) { ?> <?php $this->output_service($id, $service, true); ?> <?php } ?> <li class="end-fix"></li> </ul> </td> </tr> </table> <table id="live-preview"> <tr> <td class="description"> <h3><?php _e('Live Preview', 'jetpack'); ?> </h3> </td> <td class="services"> <h2<?php if (count($enabled['all']) > 0) { echo ' style="display: none"'; } ?> ><?php _e('Sharing is off. Please add services above to enable', 'jetpack'); ?> </h2> <ul class="preview"> <?php if (count($enabled['all']) > 0) { ?> <li class="sharing-label"><?php echo esc_html($global['sharing_label']); ?> </li> <?php } ?> <?php foreach ($enabled['visible'] as $id => $service) { ?> <?php $this->output_preview($service); ?> <?php } ?> <?php if (count($enabled['hidden']) > 0) { ?> <li class="share-custom"> <a href="#" class="sharing-anchor"><?php _ex('Share', 'dropdown button', 'jetpack'); ?> </a> <div class="sharing-hidden"> <div class="inner" style="display: none;"> <ul> <?php $count = 1; foreach ($enabled['hidden'] as $id => $service) { $this->output_preview($service); if ($count % 2 == 0) { echo '<li class="share-end"></li>'; } $count++; } ?> <li class="share-end"></li> </ul> </div> </div> </li> <?php } ?> </ul> <ul class="archive" style="display: none"> <li class="sharing-label"><?php echo esc_html($global['sharing_label']); ?> </li> <?php foreach ($sharer->get_all_services_blog() as $id => $service) { ?> <?php if (isset($enabled['visible'][$id])) { $service = $enabled['visible'][$id]; } elseif (isset($enabled['hidden'][$id])) { $service = $enabled['hidden'][$id]; } $service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later $this->output_preview($service); ?> <?php } ?> <li class="share-custom"> <a href="#" class="sharing-anchor"><?php _ex('Share', 'dropdown button', 'jetpack'); ?> </a> <div class="sharing-hidden"> <div class="inner" style="display: none;"> <ul> <li/> </ul> </div> </div> </li> </ul> <br class="clearing" /> </td> </tr> </table> <form method="post" action="<?php echo admin_url('admin-ajax.php'); ?> " id="save-enabled-shares"> <input type="hidden" name="action" value="sharing_save_services" /> <input type="hidden" name="visible" value="<?php echo implode(',', array_keys($enabled['visible'])); ?> " /> <input type="hidden" name="hidden" value="<?php echo implode(',', array_keys($enabled['hidden'])); ?> " /> <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('sharing-options'); ?> " /> </form> </div> <form method="post" action=""> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row"><label><?php _e('Default button style', 'jetpack'); ?> </label></th> <td> <select name="button_style"> <option<?php if ($global['button_style'] == 'icon-text') { echo ' selected="selected"'; } ?> value="icon-text"><?php _e('Icon + text', 'jetpack'); ?> </option> <option<?php if ($global['button_style'] == 'icon') { echo ' selected="selected"'; } ?> value="icon"><?php _e('Icon only', 'jetpack'); ?> </option> <option<?php if ($global['button_style'] == 'text') { echo ' selected="selected"'; } ?> value="text"><?php _e('Text only', 'jetpack'); ?> </option> </select> </td> </tr> <tr valign="top"> <th scope="row"><label><?php _e('Sharing label', 'jetpack'); ?> </label></th> <td> <input type="text" name="sharing_label" value="<?php echo esc_attr($global['sharing_label']); ?> " /> </td> </tr> <tr valign="top"> <th scope="row"><label><?php _e('Open links in', 'jetpack'); ?> </label></th> <td> <select name="open_links"> <option<?php if ($global['open_links'] == 'new') { echo ' selected="selected"'; } ?> value="new"><?php _e('New window', 'jetpack'); ?> </option> <option<?php if ($global['open_links'] == 'same') { echo ' selected="selected"'; } ?> value="same"><?php _e('Same window', 'jetpack'); ?> </option> </select> </td> </tr> <tr valign="top"> <th scope="row"><label><?php _e('Show sharing buttons on', 'jetpack'); ?> </label></th> <td> <?php $br = false; foreach ($shows as $show) { if ('index' == $show) { $label = __('Front Page, Archive Pages, and Search Results', 'jetpack'); } else { $post_type_object = get_post_type_object($show); $label = $post_type_object->labels->name; } ?> <?php if ($br) { echo '<br />'; } ?> <label><input type="checkbox"<?php checked(in_array($show, $global['show'])); ?> name="show[]" value="<?php echo esc_attr($show); ?> " /> <?php echo esc_html($label); ?> </label> <?php $br = true; } ?> </td> </tr> <?php do_action('sharing_global_options'); ?> </tbody> </table> <p class="submit"> <input type="submit" name="submit" class="button-primary" value="<?php _e('Save Changes', 'jetpack'); ?> " /> </p> <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('sharing-options'); ?> " /> </form> <div id="new-service" style="display: none"> <form method="post" action="<?php echo admin_url('admin-ajax.php'); ?> " id="new-service-form"> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row" width="100"><label><?php _e('Service name', 'jetpack'); ?> </label></th> <td> <input type="text" name="sharing_name" size="40" /> </td> </tr> <tr valign="top"> <th scope="row" width="100"><label><?php _e('Sharing URL', 'jetpack'); ?> </label></th> <td> <input type="text" name="sharing_url" size="40" /> <p><?php _e('You can add the following variables to your service sharing URL:', 'jetpack'); ?> <br/> <code>%post_title%</code>, <code>%post_url%</code>, <code>%post_full_url%</code>, <code>%post_excerpt%</code>, <code>%post_full_url%</code>, <code>%post_tags%</code></p> </td> </tr> <tr valign="top"> <th scope="row" width="100"><label><?php _e('Icon URL', 'jetpack'); ?> </label></th> <td> <input type="text" name="sharing_icon" size="40" /> <p><?php _e('Enter the URL of a 16x16px icon you want to use for this service.', 'jetpack'); ?> </p> </td> </tr> <tr valign="top" width="100"> <th scope="row"></th> <td> <input type="submit" class="button-secondary" value="<?php _e('Create Share', 'jetpack'); ?> " /> <img src="<?php echo admin_url('images/loading.gif'); ?> " width="16" height="16" alt="loading" style="vertical-align: middle; display: none" /> </td> </tr> <?php do_action('sharing_new_service_form'); ?> </tbody> </table> <div class="inerror" style="display: none; margin-top: 15px"> <p><?php _e('An error occurred creating your new sharing service - please check you gave valid details.', 'jetpack'); ?> </p> </div> <input type="hidden" name="action" value="sharing_new_service" /> <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('sharing-new_service'); ?> " /> </form> </div> </div> <script type="text/javascript"> var sharing_loading_icon = '<?php echo esc_js(admin_url("/images/loading.gif")); ?> '; </script> <?php }
public function management_page() { $sharer = new Sharing_Service(); $enabled = $sharer->get_blog_services(); $global = $sharer->get_global_options(); $shows = array_values(get_post_types(array('public' => true))); array_unshift($shows, 'index'); if (false == function_exists('mb_stripos')) { echo '<div id="message" class="updated fade"><h3>' . __('Warning! Multibyte support missing!', 'jetpack') . '</h3>'; echo "<p>" . sprintf(__('This plugin will work without it, but multibyte support is used <a href="%s">if available</a>. You may see minor problems with Tweets and other sharing services.', 'jetpack'), "http://www.php.net/manual/en/mbstring.installation.php") . '</p></div>'; } if (isset($_GET['update']) && $_GET['update'] == 'saved') { echo '<div class="updated"><p>' . __('Settings have been saved', 'jetpack') . '</p></div>'; } if (!isset($global['sharing_label'])) { $global['sharing_label'] = __('Share this:', 'jetpack'); } ?> <div class="wrap"> <div class="icon32" id="icon-options-general"><br /></div> <h2><?php _e('Sharing Settings', 'jetpack'); ?> </h2> <?php /** * Fires at the top of the admin sharing settings screen. * * @since 1.6.0 */ do_action('pre_admin_screen_sharing'); ?> <?php if (current_user_can('manage_options')) { ?> <div class="share_manage_options"> <h3><?php _e('Sharing Buttons', 'jetpack'); ?> </h3> <p><?php _e('Add sharing buttons to your blog and allow your visitors to share posts with their friends.', 'jetpack'); ?> </p> <div id="services-config"> <table id="available-services"> <tr> <td class="description"> <h3><?php _e('Available Services', 'jetpack'); ?> </h3> <p><?php _e("Drag and drop the services you'd like to enable into the box below.", 'jetpack'); ?> </p> <p><a href="#TB_inline?height=395&width=600&inlineId=new-service" class="thickbox" id="add-a-new-service"><?php _e('Add a new service', 'jetpack'); ?> </a></p> </td> <td class="services"> <ul class="services-available" style="height: 100px;"> <?php foreach ($sharer->get_all_services_blog() as $id => $service) { ?> <?php if (!isset($enabled['all'][$id])) { $this->output_service($id, $service); } ?> <?php } ?> </ul> <?php if (-1 == get_option('blog_public')) { echo '<p><strong>' . __('Please note that your services have been restricted because your site is private.', 'jetpack') . '</strong></p>'; } ?> <br class="clearing" /> </td> </tr> </table> <table id="enabled-services"> <tr> <td class="description"> <h3> <?php _e('Enabled Services', 'jetpack'); ?> <img src="<?php echo admin_url('images/loading.gif'); ?> " width="16" height="16" alt="loading" style="vertical-align: middle; display: none" /> </h3> <p><?php _e('Services dragged here will appear individually.', 'jetpack'); ?> </p> </td> <td class="services" id="share-drop-target"> <h2 id="drag-instructions" <?php if (count($enabled['visible']) > 0) { echo ' style="display: none"'; } ?> ><?php _e('Drag and drop available services here.', 'jetpack'); ?> </h2> <ul class="services-enabled"> <?php foreach ($enabled['visible'] as $id => $service) { ?> <?php $this->output_service($id, $service, true); ?> <?php } ?> <li class="end-fix"></li> </ul> </td> <td id="hidden-drop-target" class="services"> <p><?php _e('Services dragged here will be hidden behind a share button.', 'jetpack'); ?> </p> <ul class="services-hidden"> <?php foreach ($enabled['hidden'] as $id => $service) { ?> <?php $this->output_service($id, $service, true); ?> <?php } ?> <li class="end-fix"></li> </ul> </td> </tr> </table> <table id="live-preview"> <tr> <td class="description"> <h3><?php _e('Live Preview', 'jetpack'); ?> </h3> </td> <td class="services"> <h2<?php if (count($enabled['all']) > 0) { echo ' style="display: none"'; } ?> ><?php _e('Sharing is off. Add services above to enable.', 'jetpack'); ?> </h2> <div class="sharedaddy sd-sharing-enabled"> <?php if (count($enabled['all']) > 0) { ?> <h3 class="sd-title"><?php echo esc_html($global['sharing_label']); ?> </h3> <?php } ?> <div class="sd-content"> <ul class="preview"> <?php foreach ($enabled['visible'] as $id => $service) { ?> <?php $this->output_preview($service); ?> <?php } ?> <?php if (count($enabled['hidden']) > 0) { ?> <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php _e('More', 'jetpack'); ?> </span></a></li> <?php } ?> </ul> <?php if (count($enabled['hidden']) > 0) { ?> <div class="sharing-hidden"> <div class="inner" style="display: none; <?php echo count($enabled['hidden']) == 1 ? 'width:150px;' : ''; ?> "> <?php if (count($enabled['hidden']) == 1) { ?> <ul style="background-image:none;"> <?php } else { ?> <ul> <?php } ?> <?php foreach ($enabled['hidden'] as $id => $service) { $this->output_preview($service); } ?> </ul> </div> </div> <?php } ?> <ul class="archive" style="display:none;"> <?php foreach ($sharer->get_all_services_blog() as $id => $service) { if (isset($enabled['visible'][$id])) { $service = $enabled['visible'][$id]; } elseif (isset($enabled['hidden'][$id])) { $service = $enabled['hidden'][$id]; } $service->button_style = 'icon-text'; // The archive needs the full text, which is removed in JS later $service->smart = false; $this->output_preview($service); } ?> <li class="advanced"><a href="#" class="sharing-anchor sd-button share-more"><span><?php _e('More', 'jetpack'); ?> </span></a></li> </ul> </div> </div> <br class="clearing" /> </td> </tr> </table> <form method="post" action="<?php echo admin_url('admin-ajax.php'); ?> " id="save-enabled-shares"> <input type="hidden" name="action" value="sharing_save_services" /> <input type="hidden" name="visible" value="<?php echo implode(',', array_keys($enabled['visible'])); ?> " /> <input type="hidden" name="hidden" value="<?php echo implode(',', array_keys($enabled['hidden'])); ?> " /> <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('sharing-options'); ?> " /> </form> </div> <form method="post" action=""> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row"><label><?php _e('Button style', 'jetpack'); ?> </label></th> <td> <select name="button_style" id="button_style"> <option<?php if ($global['button_style'] == 'icon-text') { echo ' selected="selected"'; } ?> value="icon-text"><?php _e('Icon + text', 'jetpack'); ?> </option> <option<?php if ($global['button_style'] == 'icon') { echo ' selected="selected"'; } ?> value="icon"><?php _e('Icon only', 'jetpack'); ?> </option> <option<?php if ($global['button_style'] == 'text') { echo ' selected="selected"'; } ?> value="text"><?php _e('Text only', 'jetpack'); ?> </option> <option<?php if ($global['button_style'] == 'official') { echo ' selected="selected"'; } ?> value="official"><?php _e('Official buttons', 'jetpack'); ?> </option> </select> </td> </tr> <tr valign="top"> <th scope="row"><label><?php _e('Sharing label', 'jetpack'); ?> </label></th> <td> <input type="text" name="sharing_label" value="<?php echo esc_attr($global['sharing_label']); ?> " /> </td> </tr> <?php /** * Filters the HTML at the beginning of the "Show button on" row. * * @since 2.1.0 * * @param string $var Opening HTML tag at the beginning of the "Show button on" row. */ echo apply_filters('sharing_show_buttons_on_row_start', '<tr valign="top">'); ?> <th scope="row"><label><?php _e('Show buttons on', 'jetpack'); ?> </label></th> <td> <?php $br = false; foreach ($shows as $show) { if ('index' == $show) { $label = __('Front Page, Archive Pages, and Search Results', 'jetpack'); } else { $post_type_object = get_post_type_object($show); $label = $post_type_object->labels->name; } ?> <?php if ($br) { echo '<br />'; } ?> <label><input type="checkbox"<?php checked(in_array($show, $global['show'])); ?> name="show[]" value="<?php echo esc_attr($show); ?> " /> <?php echo esc_html($label); ?> </label> <?php $br = true; } ?> </td> <?php /** * Filters the HTML at the end of the "Show button on" row. * * @since 2.1.0 * * @param string $var Closing HTML tag at the end of the "Show button on" row. */ echo apply_filters('sharing_show_buttons_on_row_end', '</tr>'); ?> <?php /** * Fires at the end of the sharing global options settings table. * * @since 1.1.0 */ do_action('sharing_global_options'); ?> </tbody> </table> <p class="submit"> <input type="submit" name="submit" class="button-primary" value="<?php _e('Save Changes', 'jetpack'); ?> " /> </p> <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('sharing-options'); ?> " /> </form> <div id="new-service" style="display: none"> <form method="post" action="<?php echo admin_url('admin-ajax.php'); ?> " id="new-service-form"> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row" width="100"><label><?php _e('Service name', 'jetpack'); ?> </label></th> <td> <input type="text" name="sharing_name" id="new_sharing_name" size="40" /> </td> </tr> <tr valign="top"> <th scope="row" width="100"><label><?php _e('Sharing URL', 'jetpack'); ?> </label></th> <td> <input type="text" name="sharing_url" id="new_sharing_url" size="40" /> <p><?php _e('You can add the following variables to your service sharing URL:', 'jetpack'); ?> <br/> <code>%post_title%</code>, <code>%post_url%</code>, <code>%post_full_url%</code>, <code>%post_excerpt%</code>, <code>%post_tags%</code></p> </td> </tr> <tr valign="top"> <th scope="row" width="100"><label><?php _e('Icon URL', 'jetpack'); ?> </label></th> <td> <input type="text" name="sharing_icon" id="new_sharing_icon" size="40" /> <p><?php _e('Enter the URL of a 16x16px icon you want to use for this service.', 'jetpack'); ?> </p> </td> </tr> <tr valign="top" width="100"> <th scope="row"></th> <td> <input type="submit" class="button-primary" value="<?php _e('Create Share Button', 'jetpack'); ?> " /> <img src="<?php echo admin_url('images/loading.gif'); ?> " width="16" height="16" alt="loading" style="vertical-align: middle; display: none" /> </td> </tr> <?php /** * Fires after the custom sharing service form * * @since 1.1.0 */ do_action('sharing_new_service_form'); ?> </tbody> </table> <?php /** * Fires at the bottom of the admin sharing settings screen. * * @since 1.6.0 */ do_action('post_admin_screen_sharing'); ?> <div class="inerror" style="display: none; margin-top: 15px"> <p><?php _e('An error occurred creating your new sharing service - please check you gave valid details.', 'jetpack'); ?> </p> </div> <input type="hidden" name="action" value="sharing_new_service" /> <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('sharing-new_service'); ?> " /> </form> </div> </div> <?php } ?> </div> <script type="text/javascript"> var sharing_loading_icon = '<?php echo esc_js(admin_url("/images/loading.gif")); ?> '; <?php if (isset($_GET['create_new_service']) && 'true' == $_GET['create_new_service']) { ?> jQuery(document).ready(function() { // Prefill new service box and then open it jQuery( '#new_sharing_name' ).val( '<?php echo esc_js($_GET['name']); ?> ' ); jQuery( '#new_sharing_url' ).val( '<?php echo esc_js($_GET['url']); ?> ' ); jQuery( '#new_sharing_icon' ).val( '<?php echo esc_js($_GET['icon']); ?> ' ); jQuery( '#add-a-new-service' ).click(); }); <?php } ?> </script> <?php }
/** * Remove 'validate_callback' item from options available for module. * Fetch current option value and add to array of module options. * Prepare values of module options that need special handling, like those saved in wpcom. * * @since 4.3.0 * * @param string $module Module slug. * @return array */ public static function prepare_options_for_response($module = '') { $options = self::get_module_available_options($module); if (!is_array($options) || empty($options)) { return $options; } foreach ($options as $key => $value) { if (isset($options[$key]['validate_callback'])) { unset($options[$key]['validate_callback']); } $default_value = isset($options[$key]['default']) ? $options[$key]['default'] : ''; $current_value = get_option($key, $default_value); $options[$key]['current_value'] = self::cast_value($current_value, $options[$key]); } // Some modules need special treatment. switch ($module) { case 'monitor': // Status of user notifications $options['monitor_receive_notifications']['current_value'] = self::cast_value(self::get_remote_value('monitor', 'monitor_receive_notifications'), $options['monitor_receive_notifications']); break; case 'post-by-email': // Email address $options['post_by_email_address']['current_value'] = self::cast_value(self::get_remote_value('post-by-email', 'post_by_email_address'), $options['post_by_email_address']); break; case 'protect': // Protect $options['jetpack_protect_key']['current_value'] = get_site_option('jetpack_protect_key', false); if (!function_exists('jetpack_protect_format_whitelist')) { @(include JETPACK__PLUGIN_DIR . 'modules/protect/shared-functions.php'); } $options['jetpack_protect_global_whitelist']['current_value'] = jetpack_protect_format_whitelist(); break; case 'related-posts': // It's local, but it must be broken apart since it's saved as an array. $options = self::split_options($options, Jetpack_Options::get_option('relatedposts')); break; case 'verification-tools': // It's local, but it must be broken apart since it's saved as an array. $options = self::split_options($options, get_option('verification_services_codes')); break; case 'sharedaddy': // It's local, but it must be broken apart since it's saved as an array. if (!class_exists('Sharing_Service') && !@(include JETPACK__PLUGIN_DIR . 'modules/sharedaddy/sharing-service.php')) { break; } $sharer = new Sharing_Service(); $options = self::split_options($options, $sharer->get_global_options()); $options['sharing_services']['current_value'] = $sharer->get_blog_services(); break; case 'site-icon': // Return site icon ID and URL to make it more complete. $options['site_icon_id']['current_value'] = Jetpack_Options::get_option('site_icon_id'); if (!function_exists('jetpack_site_icon_url')) { @(include JETPACK__PLUGIN_DIR . 'modules/site-icon/site-icon-functions.php'); } $options['site_icon_url']['current_value'] = jetpack_site_icon_url(); break; case 'after-the-deadline': if (!function_exists('AtD_get_options')) { @(include JETPACK__PLUGIN_DIR . 'modules/after-the-deadline.php'); } $atd_options = array_merge(AtD_get_options(get_current_user_id(), 'AtD_options'), AtD_get_options(get_current_user_id(), 'AtD_check_when')); unset($atd_options['name']); foreach ($atd_options as $key => $value) { $options[$key]['current_value'] = self::cast_value($value, $options[$key]); } $atd_options = AtD_get_options(get_current_user_id(), 'AtD_guess_lang'); $options['guess_lang']['current_value'] = self::cast_value(isset($atd_options['true']), $options['guess_lang']); $options['ignored_phrases']['current_value'] = AtD_get_setting(get_current_user_id(), 'AtD_ignored_phrases'); unset($options['unignore_phrase']); break; case 'minileven': $options['wp_mobile_excerpt']['current_value'] = 1 === intval($options['wp_mobile_excerpt']['current_value']) ? 'enabled' : 'disabled'; $options['wp_mobile_featured_images']['current_value'] = 1 === intval($options['wp_mobile_featured_images']['current_value']) ? 'enabled' : 'disabled'; break; case 'stats': // It's local, but it must be broken apart since it's saved as an array. if (!function_exists('stats_get_options')) { @(include JETPACK__PLUGIN_DIR . 'modules/stats.php'); } $options = self::split_options($options, stats_get_options()); break; } return $options; }
/** * Collects the necessary information to return for a site's response. * * @return (array) */ public function build_current_site_response() { global $wpdb, $wp_version; $response_format = self::$site_format; $is_user_logged_in = is_user_logged_in(); $visible = array(); if ($is_user_logged_in) { $current_user = wp_get_current_user(); $visible = get_user_meta($current_user->ID, 'blog_visibility', true); if (!is_array($visible)) { $visible = array(); } } $blog_id = (int) $this->api->get_blog_id_for_output(); /** This filter is documented in class.json-api-endpoints.php */ $is_jetpack = true === apply_filters('is_jetpack_site', false, $blog_id); $site_url = get_option('siteurl'); if ($is_jetpack) { remove_filter('option_stylesheet', 'fix_theme_location'); if ('https' !== parse_url($site_url, PHP_URL_SCHEME)) { add_filter('set_url_scheme', array($this, 'force_http'), 10, 3); } } foreach (array_keys($response_format) as $key) { switch ($key) { case 'ID': $response[$key] = $blog_id; break; case 'name': $response[$key] = (string) htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); break; case 'description': $response[$key] = (string) htmlspecialchars_decode(get_bloginfo('description'), ENT_QUOTES); break; case 'URL': $response[$key] = (string) home_url(); break; case 'jetpack': $response[$key] = $is_jetpack; // jetpack magic affects this value break; case 'is_private': if (defined('IS_WPCOM') && IS_WPCOM) { $public_setting = get_option('blog_public'); if (-1 == $public_setting) { $response[$key] = true; } else { $response[$key] = false; } } else { $response[$key] = false; // magic } break; case 'visible': if ($is_user_logged_in) { $is_visible = true; if (isset($visible[$blog_id])) { $is_visible = (bool) $visible[$blog_id]; } // null and true are visible $response[$key] = $is_visible; } break; case 'post_count': if ($is_user_logged_in) { $response[$key] = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = 'publish'"); } break; case 'lang': if ($is_user_logged_in) { $response[$key] = (string) get_bloginfo('language'); } break; case 'icon': if (function_exists('blavatar_domain') && function_exists('blavatar_exists') && function_exists('blavatar_url')) { $domain = blavatar_domain(home_url()); if (blavatar_exists($domain)) { $response[$key] = array('img' => (string) remove_query_arg('s', blavatar_url($domain, 'img')), 'ico' => (string) remove_query_arg('s', blavatar_url($domain, 'ico'))); } else { // This is done so that we can access the updated blavatar on .com via the /me/sites endpoint if (is_jetpack_site()) { $site_icon_url = get_option('jetpack_site_icon_url'); if ($site_icon_url) { $response[$key] = array('img' => (string) jetpack_photon_url($site_icon_url, array(), 'https'), 'ico' => (string) jetpack_photon_url($site_icon_url, array('w' => 16), 'https')); } } } } elseif (function_exists('jetpack_site_icon_url') && function_exists('jetpack_photon_url')) { $response[$key] = array('img' => (string) jetpack_photon_url(jetpack_site_icon_url(get_current_blog_id(), 80), array('w' => 80), 'https'), 'ico' => (string) jetpack_photon_url(jetpack_site_icon_url(get_current_blog_id(), 16), array('w' => 16), 'https')); } break; case 'logo': // Set an empty response array. $response[$key] = array('id' => (int) 0, 'sizes' => array(), 'url' => ''); // Get current site logo values. $logo = get_option('site_logo'); // Update the response array if there's a site logo currenty active. if ($logo && 0 != $logo['id']) { $response[$key]['id'] = $logo['id']; $response[$key]['url'] = $logo['url']; foreach ($logo['sizes'] as $size => $properties) { $response[$key]['sizes'][$size] = $properties; } } break; case 'subscribers_count': if (function_exists('wpcom_subs_total_wpcom_subscribers')) { $total_wpcom_subs = wpcom_subs_total_wpcom_subscribers(array('blog_id' => $blog_id)); $response[$key] = $total_wpcom_subs; } else { $response[$key] = 0; // magic } break; case 'is_following': $response[$key] = (bool) $this->api->is_following($blog_id); break; case 'options': // Figure out if the blog supports VideoPress, have to do some extra checking for JP blogs $has_videopress = false; if (get_option('video_upgrade') == '1') { $has_videopress = true; } else { if (class_exists('Jetpack_Options')) { $videopress = Jetpack_Options::get_option('videopress', array()); if (isset($videopress['blog_id']) && $videopress['blog_id'] > 0) { $has_videopress = true; } } } // deprecated - see separate endpoint. get a list of supported post formats $all_formats = get_post_format_strings(); $supported = get_theme_support('post-formats'); $supported_formats = array(); if (isset($supported[0])) { foreach ($supported[0] as $format) { $supported_formats[$format] = $all_formats[$format]; } } // determine if sharing buttons should be visible by default $default_sharing_status = false; if (class_exists('Sharing_Service')) { $ss = new Sharing_Service(); $blog_services = $ss->get_blog_services(); $default_sharing_status = !empty($blog_services['visible']); } $is_mapped_domain = false; if (function_exists('get_primary_redirect')) { $primary_redirect = strtolower(get_primary_redirect()); if (false === strpos($primary_redirect, '.wordpress.com')) { $is_mapped_domain = true; } } $is_redirect = false; if (function_exists('get_primary_domain_mapping_record')) { if (get_primary_domain_mapping_record()->type == 1) { $is_redirect = true; } } if (function_exists('get_mime_types')) { $allowed_file_types = get_mime_types(); } else { // http://codex.wordpress.org/Uploading_Files $mime_types = get_allowed_mime_types(); foreach ($mime_types as $type => $mime_type) { $extras = explode('|', $type); foreach ($extras as $extra) { $allowed_file_types[] = $extra; } } } if (function_exists('get_blog_details')) { $blog_details = get_blog_details(); if (!empty($blog_details->registered)) { $registered_date = $blog_details->registered; } } $upgraded_filetypes_enabled = false; if ($is_jetpack || get_option('use_upgraded_upload_filetypes')) { $upgraded_filetypes_enabled = true; } $wordads = false; if (function_exists('has_any_blog_stickers')) { $wordads = has_any_blog_stickers(array('wordads-approved', 'wordads-approved-misfits'), $blog_id); } $response[$key] = array('timezone' => (string) get_option('timezone_string'), 'gmt_offset' => (double) get_option('gmt_offset'), 'videopress_enabled' => $has_videopress, 'upgraded_filetypes_enabled' => $upgraded_filetypes_enabled, 'login_url' => wp_login_url(), 'admin_url' => get_admin_url(), 'is_mapped_domain' => $is_mapped_domain, 'is_redirect' => $is_redirect, 'unmapped_url' => get_site_url($blog_id), 'featured_images_enabled' => current_theme_supports('post-thumbnails'), 'theme_slug' => get_option('stylesheet'), 'header_image' => get_theme_mod('header_image_data'), 'background_color' => get_theme_mod('background_color'), 'image_default_link_type' => get_option('image_default_link_type'), 'image_thumbnail_width' => (int) get_option('thumbnail_size_w'), 'image_thumbnail_height' => (int) get_option('thumbnail_size_h'), 'image_thumbnail_crop' => get_option('thumbnail_crop'), 'image_medium_width' => (int) get_option('medium_size_w'), 'image_medium_height' => (int) get_option('medium_size_h'), 'image_large_width' => (int) get_option('large_size_w'), 'image_large_height' => (int) get_option('large_size_h'), 'permalink_structure' => get_option('permalink_structure'), 'post_formats' => $supported_formats, 'default_post_format' => get_option('default_post_format'), 'default_category' => (int) get_option('default_category'), 'allowed_file_types' => $allowed_file_types, 'show_on_front' => get_option('show_on_front'), 'default_likes_enabled' => (bool) apply_filters('wpl_is_enabled_sitewide', !get_option('disabled_likes')), 'default_sharing_status' => (bool) $default_sharing_status, 'default_comment_status' => 'closed' == get_option('default_comment_status') ? false : true, 'default_ping_status' => 'closed' == get_option('default_ping_status') ? false : true, 'software_version' => $wp_version, 'created_at' => !empty($registered_date) ? $this->format_date($registered_date) : '0000-00-00T00:00:00+00:00', 'wordads' => $wordads); if ('page' === get_option('show_on_front')) { $response['options']['page_on_front'] = (int) get_option('page_on_front'); $response['options']['page_for_posts'] = (int) get_option('page_for_posts'); } if ($is_jetpack) { $response['options']['jetpack_version'] = get_option('jetpack_version'); if (get_option('jetpack_main_network_site')) { $response['options']['main_network_site'] = (string) rtrim(get_option('jetpack_main_network_site'), '/'); } if (is_array(Jetpack_Options::get_option('active_modules'))) { $response['options']['active_modules'] = (array) array_values(Jetpack_Options::get_option('active_modules')); } if ($jetpack_wp_version = get_option('jetpack_wp_version')) { $response['options']['software_version'] = (string) $jetpack_wp_version; } else { if ($jetpack_update = get_option('jetpack_updates')) { if (is_array($jetpack_update) && isset($jetpack_update['wp_version'])) { $response['options']['software_version'] = (string) $jetpack_update['wp_version']; } else { $response['options']['software_version'] = null; } } else { $response['options']['software_version'] = null; } } $response['options']['max_upload_size'] = get_option('jetpack_max_upload_size', false); // Sites have to prove that they are not main_network site. // If the sync happends right then we should be able to see that we are not dealing with a network site $response['options']['is_multi_network'] = (bool) get_option('jetpack_is_main_network', true); $response['options']['is_multi_site'] = (bool) get_option('jetpack_is_multi_site', true); } if (!current_user_can('edit_posts')) { unset($response[$key]); } break; case 'meta': /** * Filters the URL scheme used when querying your site's REST API endpoint. * * @module json-api * * @since 3.2.0 * * @param string parse_url( get_option( 'home' ), PHP_URL_SCHEME ) URL scheme parsed from home URL. */ $xmlrpc_scheme = apply_filters('wpcom_json_api_xmlrpc_scheme', parse_url(get_option('home'), PHP_URL_SCHEME)); $xmlrpc_url = site_url('xmlrpc.php', $xmlrpc_scheme); $response[$key] = (object) array('links' => (object) array('self' => (string) $this->get_site_link($blog_id), 'help' => (string) $this->get_site_link($blog_id, 'help'), 'posts' => (string) $this->get_site_link($blog_id, 'posts/'), 'comments' => (string) $this->get_site_link($blog_id, 'comments/'), 'xmlrpc' => (string) $xmlrpc_url)); break; } } if ($is_jetpack) { // Add the updates only make them visible if the user has manage options permission. $jetpack_update = (array) get_option('jetpack_updates'); if (!empty($jetpack_update) && current_user_can('manage_options')) { if (isset($jetpack_update['wp_version'])) { // In previous version of Jetpack 3.4, 3.5, 3.6 we synced the wp_version into to jetpack_updates unset($jetpack_update['wp_version']); } if (isset($jetpack_update['site_is_version_controlled'])) { // In previous version of Jetpack 3.4, 3.5, 3.6 we synced the site_is_version_controlled into to jetpack_updates unset($jetpack_update['site_is_version_controlled']); } $response['updates'] = (array) $jetpack_update; } add_filter('option_stylesheet', 'fix_theme_location'); if ('https' !== parse_url($site_url, PHP_URL_SCHEME)) { remove_filter('set_url_scheme', array($this, 'force_http'), 10, 3); } } return $response; }
/** * Collects the necessary information to return for a site's response. * * @return (array) */ public function build_current_site_response() { global $wpdb, $wp_version; $response_format = self::$site_format; $is_user_logged_in = is_user_logged_in(); $visible = array(); if ($is_user_logged_in) { $current_user = wp_get_current_user(); $visible = get_user_meta($current_user->ID, 'blog_visibility', true); if (!is_array($visible)) { $visible = array(); } } $blog_id = (int) $this->api->get_blog_id_for_output(); $is_jetpack = true === apply_filters('is_jetpack_site', false, $blog_id); $site_url = get_option('siteurl'); if ($is_jetpack) { remove_filter('option_stylesheet', 'fix_theme_location'); if ('https' !== parse_url($site_url, PHP_URL_SCHEME)) { add_filter('set_url_scheme', array($this, 'force_http'), 10, 3); } } foreach (array_keys($response_format) as $key) { switch ($key) { case 'ID': $response[$key] = $blog_id; break; case 'name': $response[$key] = (string) htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); break; case 'description': $response[$key] = (string) htmlspecialchars_decode(get_bloginfo('description'), ENT_QUOTES); break; case 'URL': $response[$key] = (string) home_url(); break; case 'jetpack': $response[$key] = $is_jetpack; // jetpack magic affects this value break; case 'is_private': if (defined('IS_WPCOM') && IS_WPCOM) { $public_setting = get_option('blog_public'); if (-1 == $public_setting) { $response[$key] = true; } else { $response[$key] = false; } } else { $response[$key] = false; // magic } break; case 'visible': if ($is_user_logged_in) { $is_visible = true; if (isset($visible[$blog_id])) { $is_visible = $visible[$blog_id]; } // null and true are visible $response[$key] = $is_visible; } break; case 'post_count': if ($is_user_logged_in) { $response[$key] = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = 'publish'"); } break; case 'lang': if ($is_user_logged_in) { $response[$key] = (string) get_bloginfo('language'); } break; case 'icon': if (function_exists('blavatar_domain') && function_exists('blavatar_exists') && function_exists('blavatar_url')) { $domain = blavatar_domain(home_url()); if (blavatar_exists($domain)) { $response[$key] = array('img' => (string) remove_query_arg('s', blavatar_url($domain, 'img')), 'ico' => (string) remove_query_arg('s', blavatar_url($domain, 'ico'))); } } elseif (function_exists('jetpack_site_icon_url') && function_exists('jetpack_photon_url')) { $response[$key] = array('img' => (string) jetpack_photon_url(jetpack_site_icon_url(get_current_blog_id(), 80), array('w' => 80), 'https'), 'ico' => (string) jetpack_photon_url(jetpack_site_icon_url(get_current_blog_id(), 16), array('w' => 16), 'https')); } break; case 'logo': // Set an empty response array. $response[$key] = array('id' => (int) 0, 'sizes' => array(), 'url' => ''); // Get current site logo values. $logo = get_option('site_logo'); // Update the response array if there's a site logo currenty active. if ($logo && 0 != $logo['id']) { $response[$key]['id'] = $logo['id']; $response[$key]['url'] = $logo['url']; foreach ($logo['sizes'] as $size => $properties) { $response[$key]['sizes'][$size] = $properties; } } break; case 'subscribers_count': if (function_exists('wpcom_subs_total_wpcom_subscribers')) { $total_wpcom_subs = wpcom_subs_total_wpcom_subscribers(array('blog_id' => $blog_id)); $response[$key] = $total_wpcom_subs; } else { $response[$key] = 0; // magic } break; case 'is_following': $response[$key] = (bool) $this->api->is_following($blog_id); break; case 'options': // Figure out if the blog supports VideoPress, have to do some extra checking for JP blogs $has_videopress = false; if (get_option('video_upgrade') == '1') { $has_videopress = true; } else { if (class_exists('Jetpack_Options')) { $videopress = Jetpack_Options::get_option('videopress', array()); if ($videopress['blog_id'] > 0) { $has_videopress = true; } } } // deprecated - see separate endpoint. get a list of supported post formats $all_formats = get_post_format_strings(); $supported = get_theme_support('post-formats'); $supported_formats = array(); if (isset($supported[0])) { foreach ($supported[0] as $format) { $supported_formats[$format] = $all_formats[$format]; } } // determine if sharing buttons should be visible by default $default_sharing_status = false; if (class_exists('Sharing_Service')) { $ss = new Sharing_Service(); $blog_services = $ss->get_blog_services(); $default_sharing_status = !empty($blog_services['visible']); } $is_mapped_domain = false; if (function_exists('get_primary_redirect')) { $primary_redirect = strtolower(get_primary_redirect()); if (false === strpos($primary_redirect, '.wordpress.com')) { $is_mapped_domain = true; } } if (function_exists('get_mime_types')) { $allowed_file_types = get_mime_types(); } else { // http://codex.wordpress.org/Uploading_Files $mime_types = get_allowed_mime_types(); foreach ($mime_types as $type => $mime_type) { $extras = explode('|', $type); foreach ($extras as $extra) { $allowed_file_types[] = $extra; } } } $response[$key] = array('timezone' => (string) get_option('timezone_string'), 'gmt_offset' => (double) get_option('gmt_offset'), 'videopress_enabled' => $has_videopress, 'login_url' => wp_login_url(), 'admin_url' => get_admin_url(), 'is_mapped_domain' => $is_mapped_domain, 'unmapped_url' => get_site_url($blog_id), 'featured_images_enabled' => current_theme_supports('post-thumbnails'), 'header_image' => get_theme_mod('header_image_data'), 'background_color' => get_theme_mod('background_color'), 'image_default_link_type' => get_option('image_default_link_type'), 'image_thumbnail_width' => (int) get_option('thumbnail_size_w'), 'image_thumbnail_height' => (int) get_option('thumbnail_size_h'), 'image_thumbnail_crop' => get_option('thumbnail_crop'), 'image_medium_width' => (int) get_option('medium_size_w'), 'image_medium_height' => (int) get_option('medium_size_h'), 'image_large_width' => (int) get_option('large_size_w'), 'image_large_height' => (int) get_option('large_size_h'), 'post_formats' => $supported_formats, 'allowed_file_types' => $allowed_file_types, 'default_likes_enabled' => (bool) apply_filters('wpl_is_enabled_sitewide', !get_option('disabled_likes')), 'default_sharing_status' => (bool) $default_sharing_status, 'default_comment_status' => 'closed' == get_option('default_comment_status') ? false : true, 'default_ping_status' => 'closed' == get_option('default_ping_status') ? false : true, 'software_version' => $wp_version); if (!current_user_can('edit_posts')) { unset($response[$key]); } break; case 'meta': $xmlrpc_scheme = apply_filters('wpcom_json_api_xmlrpc_scheme', parse_url(get_option('home'), PHP_URL_SCHEME)); $xmlrpc_url = site_url('xmlrpc.php', $xmlrpc_scheme); $response[$key] = (object) array('links' => (object) array('self' => (string) $this->get_site_link($blog_id), 'help' => (string) $this->get_site_link($blog_id, 'help'), 'posts' => (string) $this->get_site_link($blog_id, 'posts/'), 'comments' => (string) $this->get_site_link($blog_id, 'comments/'), 'xmlrpc' => (string) $xmlrpc_url)); break; } } if ($is_jetpack) { add_filter('option_stylesheet', 'fix_theme_location'); if ('https' !== parse_url($site_url, PHP_URL_SCHEME)) { remove_filter('set_url_scheme', array($this, 'force_http'), 10, 3); } } return $response; }
/** * Collects the necessary information to return for a site's response. * * @return (array) */ public function build_current_site_response() { global $wpdb, $wp_version; $response_format = self::$site_format; $is_user_logged_in = is_user_logged_in(); $visible = array(); if ($is_user_logged_in) { $current_user = wp_get_current_user(); $visible = get_user_meta($current_user->ID, 'blog_visibility', true); if (!is_array($visible)) { $visible = array(); } } $blog_id = (int) $this->api->get_blog_id_for_output(); foreach (array_keys($response_format) as $key) { switch ($key) { case 'ID': $response[$key] = $blog_id; break; case 'name': $response[$key] = (string) htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); break; case 'description': $response[$key] = (string) htmlspecialchars_decode(get_bloginfo('description'), ENT_QUOTES); break; case 'URL': $response[$key] = (string) home_url(); break; case 'jetpack': $response[$key] = false; // magic break; case 'is_private': if (defined('IS_WPCOM') && IS_WPCOM) { $public_setting = get_option('blog_public'); if (-1 == $public_setting) { $response[$key] = true; } else { $response[$key] = false; } } else { $response[$key] = false; // magic } break; case 'visible': if ($is_user_logged_in) { $is_visible = true; if (isset($visible[$blog_id])) { $is_visible = $visible[$blog_id]; } // null and true are visible $response[$key] = $is_visible; } break; case 'post_count': if ($is_user_logged_in) { $response[$key] = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = 'publish'"); } break; case 'lang': if ($is_user_logged_in) { $response[$key] = (string) get_bloginfo('language'); } break; case 'icon': if (function_exists('blavatar_domain') && function_exists('blavatar_exists') && function_exists('blavatar_url')) { $domain = blavatar_domain(home_url()); if (blavatar_exists($domain)) { $response[$key] = array('img' => (string) remove_query_arg('s', blavatar_url($domain, 'img')), 'ico' => (string) remove_query_arg('s', blavatar_url($domain, 'ico'))); } } break; case 'subscribers_count': if (function_exists('wpcom_subs_total_wpcom_subscribers')) { $total_wpcom_subs = wpcom_subs_total_wpcom_subscribers(array('blog_id' => $blog_id)); $response[$key] = $total_wpcom_subs; } else { $response[$key] = 0; // magic } break; case 'is_following': $response[$key] = (bool) $this->api->is_following($blog_id); break; case 'options': // Figure out if the blog supports VideoPress, have to do some extra checking for JP blogs $has_videopress = false; if (get_option('video_upgrade') == '1') { $has_videopress = true; } else { if (class_exists('Jetpack_Options')) { $videopress = Jetpack_Options::get_option('videopress', array()); if ($videopress['blog_id'] > 0) { $has_videopress = true; } } } // Get a list of supported post formats $all_formats = get_post_format_strings(); $supported = get_theme_support('post-formats'); $supported_formats = array(); if (isset($supported[0])) { foreach ($supported[0] as $format) { $supported_formats[$format] = $all_formats[$format]; } } // determine if sharing buttons should be visible by default $default_sharing_status = false; if (class_exists('Sharing_Service')) { $ss = new Sharing_Service(); $blog_services = $ss->get_blog_services(); $default_sharing_status = !empty($blog_services['visible']); } $response[$key] = array('timezone' => (string) get_option('timezone_string'), 'gmt_offset' => (double) get_option('gmt_offset'), 'videopress_enabled' => $has_videopress, 'login_url' => wp_login_url(), 'admin_url' => get_admin_url(), 'featured_images_enabled' => current_theme_supports('post-thumbnails'), 'header_image' => get_theme_mod('header_image_data'), 'image_default_link_type' => get_option('image_default_link_type'), 'image_thumbnail_width' => (int) get_option('thumbnail_size_w'), 'image_thumbnail_height' => (int) get_option('thumbnail_size_h'), 'image_thumbnail_crop' => get_option('thumbnail_crop'), 'image_medium_width' => (int) get_option('medium_size_w'), 'image_medium_height' => (int) get_option('medium_size_h'), 'image_large_width' => (int) get_option('large_size_w'), 'image_large_height' => (int) get_option('large_size_h'), 'post_formats' => $supported_formats, 'default_likes_enabled' => (bool) apply_filters('wpl_is_enabled_sitewide', !get_option('disabled_likes')), 'default_sharing_status' => (bool) $default_sharing_status, 'default_comment_status' => 'closed' == get_option('default_comment_status') ? false : true, 'default_ping_status' => 'closed' == get_option('default_ping_status') ? false : true, 'software_version' => $wp_version); if (!current_user_can('publish_posts')) { unset($response[$key]); } break; case 'meta': $xmlrpc_url = site_url('xmlrpc.php'); $response[$key] = (object) array('links' => (object) array('self' => (string) $this->get_site_link($blog_id), 'help' => (string) $this->get_site_link($blog_id, 'help'), 'posts' => (string) $this->get_site_link($blog_id, 'posts/'), 'comments' => (string) $this->get_site_link($blog_id, 'comments/'), 'xmlrpc' => (string) $xmlrpc_url)); break; } } return $response; }
public function callback($path = '', $blog_id = 0, $button_id = 0) { // Validate request $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id)); if (is_wp_error($blog_id)) { return $blog_id; } if (!current_user_can('manage_options')) { return new WP_Error('forbidden', 'You do not have the capability to manage sharing buttons for this site', 403); } else { if (!class_exists('Sharing_Service') || !class_exists('Sharing_Source') || method_exists('Jetpack', 'is_module_active') && !Jetpack::is_module_active('sharedaddy')) { return new WP_Error('missing_jetpack_module', 'The Sharing module must be activated in order to use this endpoint', 400); } } // Find existing button $ss = new Sharing_Service(); $all_buttons = $ss->get_all_services_blog(); if (!array_key_exists($button_id, $all_buttons)) { // Button doesn't exist return new WP_Error('not_found', 'The specified sharing button was not found', 404); } // Verify button is custom if (!is_a($all_buttons[$button_id], 'Share_Custom')) { return new WP_error('invalid_request', 'Only custom sharing buttons can be deleted', 400); } $success = $ss->delete_service($button_id); return array('ID' => $button_id, 'success' => $success); }
/** * If it's a valid Jetpack module and configuration parameters have been sent, update it. * * @since 4.3.0 * * @param WP_REST_Request $data { * Array of parameters received by request. * * @type string $slug Module slug. * } * * @return bool|WP_Error True if module was updated. Otherwise, a WP_Error instance with the corresponding error. */ public function update_data($data) { // If it's null, we're trying to update many module options from different modules. if (is_null($data['slug'])) { // Value admitted by Jetpack_Core_Json_Api_Endpoints::get_updateable_data_list that will make it return all module options. // It will not be passed. It's just checked in this method to pass that method a string or array. $data['slug'] = 'any'; } else { if (!Jetpack::is_module($data['slug'])) { return new WP_Error('not_found', esc_html__('The requested Jetpack module was not found.', 'jetpack'), array('status' => 404)); } if (!Jetpack::is_module_active($data['slug'])) { return new WP_Error('inactive', esc_html__('The requested Jetpack module is inactive.', 'jetpack'), array('status' => 409)); } } // Get parameters to update the module. $params = $data->get_json_params(); // Exit if no parameters were passed. if (!is_array($params)) { return new WP_Error('missing_options', esc_html__('Missing options.', 'jetpack'), array('status' => 404)); } // Get available module options. $options = Jetpack_Core_Json_Api_Endpoints::get_updateable_data_list('any' === $data['slug'] ? $params : $data['slug']); // Prepare to toggle module if needed $toggle_module = new Jetpack_Core_API_Module_Toggle_Endpoint(new Jetpack_IXR_Client()); // Options that are invalid or failed to update. $invalid = array_keys(array_diff_key($params, $options)); $not_updated = array(); // Remove invalid options $params = array_intersect_key($params, $options); // Used if response is successful. The message can be overwritten and additional data can be added here. $response = array('code' => 'success', 'message' => esc_html__('The requested Jetpack data updates were successful.', 'jetpack')); // If there are modules to activate, activate them first so they're ready when their options are set. foreach ($params as $option => $value) { if ('modules' === $options[$option]['jp_group']) { // Used if there was an error. Can be overwritten with specific error messages. $error = ''; // Set to true if the module toggling was successful. $updated = false; // Check if user can toggle the module. if ($toggle_module->can_request()) { // Activate or deactivate the module according to the value passed. $toggle_result = $value ? $toggle_module->activate_module($option) : $toggle_module->deactivate_module($option); if (is_wp_error($toggle_result)) { $error = $toggle_result->get_error_message(); } else { $updated = true; } } else { $error = Jetpack_Core_Json_Api_Endpoints::$user_permissions_error_msg; } // The module was not toggled. if (!$updated) { $not_updated[$option] = $error; } // Remove module from list so we don't go through it again. unset($params[$option]); } } foreach ($params as $option => $value) { // Used if there was an error. Can be overwritten with specific error messages. $error = ''; // Set to true if the option update was successful. $updated = false; // Get option attributes, including the group it belongs to. $option_attrs = $options[$option]; // If this is a module option and the related module isn't active for any reason, continue with the next one. if ('settings' !== $option_attrs['jp_group']) { if (!Jetpack::is_module($option_attrs['jp_group'])) { $not_updated[$option] = esc_html__('The requested Jetpack module was not found.', 'jetpack'); continue; } if (!Jetpack::is_module_active($option_attrs['jp_group'])) { $not_updated[$option] = esc_html__('The requested Jetpack module is inactive.', 'jetpack'); continue; } } // Properly cast value based on its type defined in endpoint accepted args. $value = Jetpack_Core_Json_Api_Endpoints::cast_value($value, $option_attrs); switch ($option) { case 'monitor_receive_notifications': $monitor = new Jetpack_Monitor(); // If we got true as response, consider it done. $updated = true === $monitor->update_option_receive_jetpack_monitor_notification($value); break; case 'post_by_email_address': if ('create' == $value) { $result = $this->_process_post_by_email('jetpack.createPostByEmailAddress', esc_html__('Unable to create the Post by Email address. Please try again later.', 'jetpack')); } elseif ('regenerate' == $value) { $result = $this->_process_post_by_email('jetpack.regeneratePostByEmailAddress', esc_html__('Unable to regenerate the Post by Email address. Please try again later.', 'jetpack')); } elseif ('delete' == $value) { $result = $this->_process_post_by_email('jetpack.deletePostByEmailAddress', esc_html__('Unable to delete the Post by Email address. Please try again later.', 'jetpack')); } else { $result = false; } // If we got an email address (create or regenerate) or 1 (delete), consider it done. if (preg_match('/[a-z0-9]+@post.wordpress.com/', $result)) { $response[$option] = $result; $updated = true; } elseif (1 == $result) { $updated = true; } elseif (is_array($result) && isset($result['message'])) { $error = $result['message']; } break; case 'jetpack_protect_key': $protect = Jetpack_Protect_Module::instance(); if ('create' == $value) { $result = $protect->get_protect_key(); } else { $result = false; } // If we got one of Protect keys, consider it done. if (preg_match('/[a-z0-9]{40,}/i', $result)) { $response[$option] = $result; $updated = true; } break; case 'jetpack_protect_global_whitelist': $updated = jetpack_protect_save_whitelist(explode(PHP_EOL, str_replace(array(' ', ','), array('', "\n"), $value))); if (is_wp_error($updated)) { $error = $updated->get_error_message(); } break; case 'show_headline': case 'show_thumbnails': $grouped_options = $grouped_options_current = (array) Jetpack_Options::get_option('relatedposts'); $grouped_options[$option] = $value; // If option value was the same, consider it done. $updated = $grouped_options_current != $grouped_options ? Jetpack_Options::update_option('relatedposts', $grouped_options) : true; break; case 'google': case 'bing': case 'pinterest': case 'yandex': $grouped_options = $grouped_options_current = (array) get_option('verification_services_codes'); $grouped_options[$option] = $value; // If option value was the same, consider it done. $updated = $grouped_options_current != $grouped_options ? update_option('verification_services_codes', $grouped_options) : true; break; case 'sharing_services': if (!class_exists('Sharing_Service') && !@(include JETPACK__PLUGIN_DIR . 'modules/sharedaddy/sharing-service.php')) { break; } $sharer = new Sharing_Service(); // If option value was the same, consider it done. $updated = $value != $sharer->get_blog_services() ? $sharer->set_blog_services($value['visible'], $value['hidden']) : true; break; case 'button_style': case 'sharing_label': case 'show': if (!class_exists('Sharing_Service') && !@(include JETPACK__PLUGIN_DIR . 'modules/sharedaddy/sharing-service.php')) { break; } $sharer = new Sharing_Service(); $grouped_options = $sharer->get_global_options(); $grouped_options[$option] = $value; $updated = $sharer->set_global_options($grouped_options); break; case 'custom': if (!class_exists('Sharing_Service') && !@(include JETPACK__PLUGIN_DIR . 'modules/sharedaddy/sharing-service.php')) { break; } $sharer = new Sharing_Service(); $updated = $sharer->new_service(stripslashes($value['sharing_name']), stripslashes($value['sharing_url']), stripslashes($value['sharing_icon'])); // Return new custom service $response[$option] = $updated; break; case 'sharing_delete_service': if (!class_exists('Sharing_Service') && !@(include JETPACK__PLUGIN_DIR . 'modules/sharedaddy/sharing-service.php')) { break; } $sharer = new Sharing_Service(); $updated = $sharer->delete_service($value); break; case 'jetpack-twitter-cards-site-tag': $value = trim(ltrim(strip_tags($value), '@')); $updated = get_option($option) !== $value ? update_option($option, $value) : true; break; case 'onpublish': case 'onupdate': case 'Bias Language': case 'Cliches': case 'Complex Expression': case 'Diacritical Marks': case 'Double Negative': case 'Hidden Verbs': case 'Jargon Language': case 'Passive voice': case 'Phrases to Avoid': case 'Redundant Expression': case 'guess_lang': if (in_array($option, array('onpublish', 'onupdate'))) { $atd_option = 'AtD_check_when'; } elseif ('guess_lang' == $option) { $atd_option = 'AtD_guess_lang'; $option = 'true'; } else { $atd_option = 'AtD_options'; } $user_id = get_current_user_id(); $grouped_options_current = AtD_get_options($user_id, $atd_option); unset($grouped_options_current['name']); $grouped_options = $grouped_options_current; if ($value && !isset($grouped_options[$option])) { $grouped_options[$option] = $value; } elseif (!$value && isset($grouped_options[$option])) { unset($grouped_options[$option]); } // If option value was the same, consider it done, otherwise try to update it. $options_to_save = implode(',', array_keys($grouped_options)); $updated = $grouped_options != $grouped_options_current ? AtD_update_setting($user_id, $atd_option, $options_to_save) : true; break; case 'ignored_phrases': case 'unignore_phrase': $user_id = get_current_user_id(); $atd_option = 'AtD_ignored_phrases'; $grouped_options = $grouped_options_current = explode(',', AtD_get_setting($user_id, $atd_option)); if ('ignored_phrases' == $option) { $grouped_options = explode(',', $value); } else { $index = array_search($value, $grouped_options); if (false !== $index) { unset($grouped_options[$index]); $grouped_options = array_values($grouped_options); } } $ignored_phrases = implode(',', array_filter(array_map('strip_tags', $grouped_options))); $updated = $grouped_options != $grouped_options_current ? AtD_update_setting($user_id, $atd_option, $ignored_phrases) : true; break; case 'admin_bar': case 'roles': case 'count_roles': case 'blog_id': case 'do_not_track': case 'hide_smile': case 'version': $grouped_options = $grouped_options_current = (array) get_option('stats_options'); $grouped_options[$option] = $value; // If option value was the same, consider it done. $updated = $grouped_options_current != $grouped_options ? update_option('stats_options', $grouped_options) : true; break; case Jetpack_Core_Json_Api_Endpoints::holiday_snow_option_name(): $updated = get_option($option) != $value ? update_option($option, (bool) $value ? 'letitsnow' : '') : true; break; case 'wp_mobile_featured_images': case 'wp_mobile_excerpt': $value = 'enabled' === $value ? '1' : '0'; // break intentionally omitted // break intentionally omitted default: // If option value was the same, consider it done. $updated = get_option($option) != $value ? update_option($option, $value) : true; break; } // The option was not updated. if (!$updated) { $not_updated[$option] = $error; } } if (empty($invalid) && empty($not_updated)) { // The option was updated. return rest_ensure_response($response); } else { $invalid_count = count($invalid); $not_updated_count = count($not_updated); $error = ''; if ($invalid_count > 0) { $error = sprintf(_n('Invalid option: %s.', 'Invalid options: %s.', $invalid_count, 'jetpack'), join(', ', $invalid)); } if ($not_updated_count > 0) { $not_updated_messages = array(); foreach ($not_updated as $not_updated_option => $not_updated_message) { if (!empty($not_updated_message)) { $not_updated_messages[] = sprintf(__('Extra info for %1$s: %2$s', 'jetpack'), $not_updated_option, $not_updated_message); } } if (!empty($error)) { $error .= ' '; } $error .= sprintf(_n('Option not updated: %s.', 'Options not updated: %s.', $not_updated_count, 'jetpack'), join(', ', array_keys($not_updated))); if (!empty($not_updated_messages)) { $error .= ' ' . join('. ', $not_updated_messages); } } // There was an error because some options were updated but others were invalid or failed to update. return new WP_Error('some_updated', esc_html($error), array('status' => 400)); } }
protected function render_option_keys(&$options_response_keys) { if (!current_user_can('edit_posts')) { return; } global $wp_version; $options = array(); $custom_front_page = 'page' === get_option('show_on_front'); foreach ($options_response_keys as $key) { switch ($key) { case 'timezone': $options[$key] = (string) get_option('timezone_string'); break; case 'gmt_offset': $options[$key] = (double) get_option('gmt_offset'); break; case 'videopress_enabled': $options[$key] = $this->site->has_videopress(); break; case 'upgraded_filetypes_enabled': $options[$key] = $this->site->upgraded_filetypes_enabled(); break; case 'login_url': $options[$key] = wp_login_url(); break; case 'admin_url': $options[$key] = get_admin_url(); break; case 'is_mapped_domain': $options[$key] = $this->site->is_mapped_domain(); break; case 'is_redirect': $options[$key] = $this->site->is_redirect(); break; case 'unmapped_url': $options[$key] = get_site_url($this->site->blog_id); break; case 'featured_images_enabled': $options[$key] = $this->site->featured_images_enabled(); break; case 'theme_slug': $options[$key] = get_option('stylesheet'); break; case 'header_image': $options[$key] = get_theme_mod('header_image_data'); break; case 'background_color': $options[$key] = get_theme_mod('background_color'); break; case 'image_default_link_type': $options[$key] = get_option('image_default_link_type'); break; case 'image_thumbnail_width': $options[$key] = (int) get_option('thumbnail_size_w'); break; case 'image_thumbnail_height': $options[$key] = (int) get_option('thumbnail_size_h'); break; case 'image_thumbnail_crop': $options[$key] = get_option('thumbnail_crop'); break; case 'image_medium_width': $options[$key] = (int) get_option('medium_size_w'); break; case 'image_medium_height': $options[$key] = (int) get_option('medium_size_h'); break; case 'image_large_width': $options[$key] = (int) get_option('large_size_w'); break; case 'image_large_height': $options[$key] = (int) get_option('large_size_h'); break; case 'permalink_structure': $options[$key] = get_option('permalink_structure'); break; case 'post_formats': $options[$key] = $this->site->get_post_formats(); break; case 'default_post_format': $options[$key] = get_option('default_post_format'); break; case 'default_category': $options[$key] = (int) get_option('default_category'); break; case 'allowed_file_types': $options[$key] = $this->site->allowed_file_types(); break; case 'show_on_front': $options[$key] = get_option('show_on_front'); break; /** This filter is documented in modules/likes.php */ /** This filter is documented in modules/likes.php */ case 'default_likes_enabled': $options[$key] = (bool) apply_filters('wpl_is_enabled_sitewide', !get_option('disabled_likes')); break; case 'default_sharing_status': $default_sharing_status = false; if (class_exists('Sharing_Service')) { $ss = new Sharing_Service(); $blog_services = $ss->get_blog_services(); $default_sharing_status = !empty($blog_services['visible']); } $options[$key] = (bool) $default_sharing_status; break; case 'default_comment_status': $options[$key] = 'closed' !== get_option('default_comment_status'); break; case 'default_ping_status': $options[$key] = 'closed' !== get_option('default_ping_status'); break; case 'software_version': $options[$key] = $wp_version; break; case 'created_at': $options[$key] = $this->site->get_registered_date(); break; case 'wordads': $options[$key] = $this->site->has_wordads(); break; case 'publicize_permanently_disabled': $publicize_permanently_disabled = false; if (function_exists('is_publicize_permanently_disabled')) { $publicize_permanently_disabled = is_publicize_permanently_disabled($this->site->blog_id); } $options[$key] = $publicize_permanently_disabled; break; case 'frame_nonce': $options[$key] = $this->site->get_frame_nonce(); break; case 'page_on_front': if ($custom_front_page) { $options[$key] = (int) get_option('page_on_front'); } break; case 'page_for_posts': if ($custom_front_page) { $options[$key] = (int) get_option('page_for_posts'); } break; case 'ak_vp_bundle_enabled': $options[$key] = $this->site->get_ak_vp_bundle_enabled(); } } return $options; }
/** * Updates site settings for authorized users * * @return (array) */ public function update_settings() { // $this->input() retrieves posted arguments whitelisted and casted to the $request_format // specs that get passed in when this class is instantiated $input = $this->input(); $jetpack_relatedposts_options = array(); $sharing_options = array(); $updated = array(); foreach ($input as $key => $value) { if (!is_array($value)) { $value = trim($value); } $value = wp_unslash($value); switch ($key) { case 'default_ping_status': case 'default_comment_status': // settings are stored as closed|open $coerce_value = $value ? 'open' : 'closed'; if (update_option($key, $coerce_value)) { $updated[$key] = $value; } break; case 'jetpack_sync_non_public_post_stati': Jetpack_Options::update_option('sync_non_public_post_stati', $value); break; case 'jetpack_relatedposts_enabled': case 'jetpack_relatedposts_show_thumbnails': case 'jetpack_relatedposts_show_headline': if (!$this->jetpack_relatedposts_supported()) { break; } if ('jetpack_relatedposts_enabled' === $key && method_exists('Jetpack', 'is_module_active') && $this->jetpack_relatedposts_supported()) { $before_action = Jetpack::is_module_active('related-posts'); if ($value) { Jetpack::activate_module('related-posts', false, false); } else { Jetpack::deactivate_module('related-posts'); } $after_action = Jetpack::is_module_active('related-posts'); if ($after_action == $before_action) { break; } } $just_the_key = substr($key, 21); $jetpack_relatedposts_options[$just_the_key] = $value; break; case 'social_notifications_like': case 'social_notifications_reblog': case 'social_notifications_subscribe': // settings are stored as on|off $coerce_value = $value ? 'on' : 'off'; if (update_option($key, $coerce_value)) { $updated[$key] = $value; } break; case 'wga': if (!isset($value['code']) || !preg_match('/^UA-[\\d-]+$/', $value['code'])) { return new WP_Error('invalid_code', 'Invalid UA ID'); } $wga = get_option('wga', array()); $wga['code'] = $value['code']; // maintain compatibility with wp-google-analytics if (update_option('wga', $wga)) { $updated[$key] = $value; } break; case 'jetpack_comment_likes_enabled': // settings are stored as 1|0 $coerce_value = (int) $value; if (update_option($key, $coerce_value)) { $updated[$key] = $value; } break; // Sharing options // Sharing options case 'sharing_button_style': case 'sharing_show': case 'sharing_open_links': $sharing_options[preg_replace('/^sharing_/', '', $key)] = $value; break; case 'sharing_label': $sharing_options[$key] = $value; break; // no worries, we've already whitelisted and casted arguments above // no worries, we've already whitelisted and casted arguments above default: if (update_option($key, $value)) { $updated[$key] = $value; } } } if (count($jetpack_relatedposts_options)) { // track new jetpack_relatedposts options against old $old_relatedposts_options = Jetpack_Options::get_option('relatedposts'); if (Jetpack_Options::update_option('relatedposts', $jetpack_relatedposts_options)) { foreach ($jetpack_relatedposts_options as $key => $value) { if ($value !== $old_relatedposts_options[$key]) { $updated['jetpack_relatedposts_' . $key] = $value; } } } } if (!empty($sharing_options) && class_exists('Sharing_Service')) { $ss = new Sharing_Service(); // Merge current values with updated, since Sharing_Service expects // all values to be included when updating $current_sharing_options = $ss->get_global_options(); foreach ($current_sharing_options as $key => $val) { if (!isset($sharing_options[$key])) { $sharing_options[$key] = $val; } } $updated_social_options = $ss->set_global_options($sharing_options); if (isset($input['sharing_button_style'])) { $updated['sharing_button_style'] = (string) $updated_social_options['button_style']; } if (isset($input['sharing_label'])) { // Sharing_Service won't report label as updated if set to default $updated['sharing_label'] = (string) $sharing_options['sharing_label']; } if (isset($input['sharing_show'])) { $updated['sharing_show'] = (array) $updated_social_options['show']; } if (isset($input['sharing_open_links'])) { $updated['sharing_open_links'] = (string) $updated_social_options['open_links']; } } return array('updated' => $updated); }
function sharing_display_extra($text = '') { global $post, $wp_current_filter; if (is_preview()) { return $text; } if (in_array('get_the_excerpt', (array) $wp_current_filter)) { 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(). // We only want to output the sharing buttons once. Let's stick with the_content(). return $text; } $sharer = new Sharing_Service(); $global = $sharer->get_global_options(); $show = false; if (!is_feed()) { if (is_singular() && in_array(get_post_type(), $global['show'])) { $show = true; } elseif (in_array('index', $global['show']) && (is_home() || is_archive() || is_search())) { $show = true; } } // Pass through a filter for final say so $show = apply_filters('sharing_show', $show, $post); // Disabled for this post? $switched_status = get_post_meta($post->ID, 'sharing_disabled', false); if (!empty($switched_status)) { $show = 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']) { $show = true; } $sharing_content = ''; if ($show) { $enabled = $sharer->get_blog_services(); if (count($enabled['all']) > 0) { global $post; $dir = get_option('text_direction'); // Wrapper $sharing_content .= '<div class="sharedaddy sd-sharing-enabled"><div class="robots-nocontent sd-block sd-social sd-social-' . $global['button_style'] . ' sd-sharing">'; if ($global['sharing_label'] != '') { $sharing_content .= '<h3 class="sd-title">' . $global['sharing_label'] . '</h3>'; } $sharing_content .= '<div class="sd-content"><ul>'; // Visible items $visible = ''; foreach ($enabled['visible'] as $id => $service) { // Individual HTML for sharing service $visible .= '<li class="share-' . $service->get_class() . '">' . $service->get_display($post) . '</li>'; } $parts = array(); $parts[] = $visible; if (count($enabled['hidden']) > 0) { if (count($enabled['visible']) > 0) { $expand = __('More', 'jetpack'); } else { $expand = __('Share', 'jetpack'); } $parts[] = '<li><a href="#" class="sharing-anchor sd-button share-more"><span>' . $expand . '</span></a></li>'; } if ($dir == 'rtl') { $parts = array_reverse($parts); } $sharing_content .= implode('', $parts); $sharing_content .= '<li class="share-end"></li></ul>'; if (count($enabled['hidden']) > 0) { $sharing_content .= '<div class="sharing-hidden"><div class="inner" style="display: none;'; if (count($enabled['hidden']) == 1) { $sharing_content .= 'width:150px;'; } $sharing_content .= '">'; if (count($enabled['hidden']) == 1) { $sharing_content .= '<ul style="background-image:none;">'; } 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 .= $service->get_display($post); $sharing_content .= '</li>'; if ($count % 2 == 0) { $sharing_content .= '<li class="share-end"></li>'; } $count++; } // End of wrapper $sharing_content .= '<li class="share-end"></li></ul></div></div>'; } $sharing_content .= '<div class="sharing-clear"></div></div></div></div>'; // Register our JS wp_register_script('sharing-js', WP_SHARING_PLUGIN_URL . 'sharing.js', array('jquery'), '20120131'); add_action('wp_footer', 'sharing_add_footer'); } } $options = get_option('jetpack_extras-options', array()); $option = ''; if (is_singular() || is_single()) { $option = isset($options['placement'][get_post_type()]) ? $options['placement'][get_post_type()] : 'below'; } else { $option = $options['placement']['index']; } switch ($option) { case 'above': return $sharing_content . $text; case 'both': return $sharing_content . $text . $sharing_content; case 'below': default: return $text . $sharing_content; } }
/** * Updates site settings for authorized users * * @return (array) */ public function update_settings() { // $this->input() retrieves posted arguments whitelisted and casted to the $request_format // specs that get passed in when this class is instantiated /** * Filters the settings to be updated on the site. * * @module json-api * * @since 3.6.0 * * @param array $input Associative array of site settings to be updated. */ $input = apply_filters('rest_api_update_site_settings', $this->input()); $jetpack_relatedposts_options = array(); $sharing_options = array(); $updated = array(); foreach ($input as $key => $value) { if (!is_array($value)) { $value = trim($value); } $value = wp_unslash($value); switch ($key) { case 'default_ping_status': case 'default_comment_status': // settings are stored as closed|open $coerce_value = $value ? 'open' : 'closed'; if (update_option($key, $coerce_value)) { $updated[$key] = $value; } break; case 'jetpack_protect_whitelist': if (function_exists('jetpack_protect_save_whitelist')) { $result = jetpack_protect_save_whitelist($value); if (is_wp_error($result)) { return $result; } $updated[$key] = jetpack_protect_format_whitelist(); } break; case 'jetpack_sync_non_public_post_stati': Jetpack_Options::update_option('sync_non_public_post_stati', $value); break; case 'jetpack_relatedposts_enabled': case 'jetpack_relatedposts_show_thumbnails': case 'jetpack_relatedposts_show_headline': if (!$this->jetpack_relatedposts_supported()) { break; } if ('jetpack_relatedposts_enabled' === $key && method_exists('Jetpack', 'is_module_active') && $this->jetpack_relatedposts_supported()) { $before_action = Jetpack::is_module_active('related-posts'); if ($value) { Jetpack::activate_module('related-posts', false, false); } else { Jetpack::deactivate_module('related-posts'); } $after_action = Jetpack::is_module_active('related-posts'); if ($after_action == $before_action) { break; } } $just_the_key = substr($key, 21); $jetpack_relatedposts_options[$just_the_key] = $value; break; case 'social_notifications_like': case 'social_notifications_reblog': case 'social_notifications_subscribe': // settings are stored as on|off $coerce_value = $value ? 'on' : 'off'; if (update_option($key, $coerce_value)) { $updated[$key] = $value; } break; case 'wga': if (!isset($value['code']) || !preg_match('/^$|^UA-[\\d-]+$/i', $value['code'])) { return new WP_Error('invalid_code', 'Invalid UA ID'); } $wga = get_option('wga', array()); $wga['code'] = $value['code']; // maintain compatibility with wp-google-analytics if (update_option('wga', $wga)) { $updated[$key] = $value; } $enabled_or_disabled = $wga['code'] ? 'enabled' : 'disabled'; /** This action is documented in modules/widgets/social-media-icons.php */ do_action('jetpack_bump_stats_extras', 'google-analytics', $enabled_or_disabled); $business_plugins = WPCOM_Business_Plugins::instance(); $business_plugins->activate_plugin('wp-google-analytics'); break; case 'jetpack_testimonial': case 'jetpack_portfolio': case 'jetpack_comment_likes_enabled': // settings are stored as 1|0 $coerce_value = (int) $value; if (update_option($key, $coerce_value)) { $updated[$key] = (bool) $value; } break; case 'jetpack_testimonial_posts_per_page': case 'jetpack_portfolio_posts_per_page': // settings are stored as numeric $coerce_value = (int) $value; if (update_option($key, $coerce_value)) { $updated[$key] = $coerce_value; } break; // Sharing options // Sharing options case 'sharing_button_style': case 'sharing_show': case 'sharing_open_links': $sharing_options[preg_replace('/^sharing_/', '', $key)] = $value; break; case 'sharing_label': $sharing_options[$key] = $value; break; // Keyring token option // Keyring token option case 'eventbrite_api_token': // These options can only be updated for sites hosted on WordPress.com if (defined('IS_WPCOM') && IS_WPCOM) { if (empty($value) || WPCOM_JSON_API::is_falsy($value)) { if (delete_option($key)) { $updated[$key] = null; } } else { if (update_option($key, $value)) { $updated[$key] = (int) $value; } } } break; case 'holidaysnow': if (empty($value) || WPCOM_JSON_API::is_falsy($value)) { if (function_exists('jetpack_holiday_snow_option_name') && delete_option(jetpack_holiday_snow_option_name())) { $updated[$key] = false; } } else { if (function_exists('jetpack_holiday_snow_option_name') && update_option(jetpack_holiday_snow_option_name(), 'letitsnow')) { $updated[$key] = true; } } break; case 'timezone_string': // Map UTC+- timezones to gmt_offsets and set timezone_string to empty // https://github.com/WordPress/WordPress/blob/4.4.2/wp-admin/options.php#L175 if (!empty($value) && preg_match('/^UTC[+-]/', $value)) { $gmt_offset = preg_replace('/UTC\\+?/', '', $value); if (update_option('gmt_offset', $gmt_offset)) { $updated['gmt_offset'] = $gmt_offset; } $value = ''; } // Always set timezone_string either with the given value or with an // empty string if (update_option($key, $value)) { $updated[$key] = $value; } break; default: //allow future versions of this endpoint to support additional settings keys if (has_filter('site_settings_endpoint_update_' . $key)) { /** * Filter current site setting value to be updated. * * @module json-api * * @since 3.9.3 * * @param mixed $response_item A single site setting value. */ $value = apply_filters('site_settings_endpoint_update_' . $key, $value); $updated[$key] = $value; continue; } // no worries, we've already whitelisted and casted arguments above if (update_option($key, $value)) { $updated[$key] = $value; } } } if (count($jetpack_relatedposts_options)) { // track new jetpack_relatedposts options against old $old_relatedposts_options = Jetpack_Options::get_option('relatedposts'); if (Jetpack_Options::update_option('relatedposts', $jetpack_relatedposts_options)) { foreach ($jetpack_relatedposts_options as $key => $value) { if ($value !== $old_relatedposts_options[$key]) { $updated['jetpack_relatedposts_' . $key] = $value; } } } } if (!empty($sharing_options) && class_exists('Sharing_Service')) { $ss = new Sharing_Service(); // Merge current values with updated, since Sharing_Service expects // all values to be included when updating $current_sharing_options = $ss->get_global_options(); foreach ($current_sharing_options as $key => $val) { if (!isset($sharing_options[$key])) { $sharing_options[$key] = $val; } } $updated_social_options = $ss->set_global_options($sharing_options); if (isset($input['sharing_button_style'])) { $updated['sharing_button_style'] = (string) $updated_social_options['button_style']; } if (isset($input['sharing_label'])) { // Sharing_Service won't report label as updated if set to default $updated['sharing_label'] = (string) $sharing_options['sharing_label']; } if (isset($input['sharing_show'])) { $updated['sharing_show'] = (array) $updated_social_options['show']; } if (isset($input['sharing_open_links'])) { $updated['sharing_open_links'] = (string) $updated_social_options['open_links']; } } return array('updated' => $updated); }