/** * Add social link dropdown to the Customizer. * * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ public function customize_register($wp_customize) { $wp_customize->add_section('jetpack_social_links', array('title' => __('Connect', 'jetpack'), 'priority' => 35)); foreach ($this->services as $service) { $wp_customize->add_setting("jetpack_options[social_links][{$service}]", array('type' => 'option', 'default' => '', 'sanitize_callback' => 'esc_url_raw')); $wp_customize->add_control("jetpack-{$service}", array('label' => $this->publicize->get_service_label($service), 'section' => 'jetpack_social_links', 'settings' => "jetpack_options[social_links][{$service}]", 'type' => 'select', 'choices' => $this->get_customize_select($service))); } }
function get_connection($service, $connection) { $publicize = new Publicize(); $connection_id = $publicize->get_connection_id($connection); if (method_exists($connection, 'get_meta')) { $connection_meta = $connection->get_meta(); $connection_data = (array) $connection->get_meta('connection_data'); } else { $connection_meta = $connection; $connection_data = $connection['connection_data']; } return array('ID' => (int) $connection_id, 'token_ID' => (int) $connection_data['token_id'], 'conn_ID' => (int) $connection_id, 'site_ID' => (int) $connection_data['blog_id'], 'user_ID' => (int) $connection_data['user_id'], 'shared' => 0 == (int) $connection_data['user_id'] ? true : false, 'service' => $service, 'label' => $publicize->get_service_label($service), 'issued' => $connection_meta['issued'], 'expires' => $connection_meta['expires'], 'external_ID' => $connection_meta['external_id'], 'external_name' => $connection_meta['external_name'], 'external_display' => $publicize->get_display_name($service, $connection), 'URL' => $publicize->get_profile_link($service, $connection), 'status' => method_exists($connection, 'is_expired') && $connection->is_expired(HOUR_IN_SECONDS) ? 'broken' : 'ok', 'refresh_url' => $publicize->refresh_url($service), 'meta' => maybe_unserialize($connection_data['meta'])); }
function broken_connection( $service_name, $id ) { ?> <div id="thickbox-content"> <div class='error'> <p><?php printf( __( 'There was a problem connecting to %s. Please disconnect and try again.', 'jetpack' ), Publicize::get_service_label( $service_name ) ); ?></p> </div> </div><?php }
function display_connection_error() { $code = false; if (isset($_GET['service'])) { $service_name = $_GET['service']; $error = sprintf(__('There was a problem connecting to %s to create an authorized connection. Please try again in a moment.', 'jetpack'), Publicize::get_service_label($service_name)); } else { if (isset($_GET['publicize_error'])) { $code = strtolower($_GET['publicize_error']); switch ($code) { case '400': $error = __('An invalid request was made. This normally means that something intercepted or corrupted the request from your server to the Jetpack Server. Try again and see if it works this time.', 'jetpack'); break; case 'secret_mismatch': $error = __('We could not verify that your server is making an authorized request. Please try again, and make sure there is nothing interfering with requests from your server to the Jetpack Server.', 'jetpack'); break; case 'empty_blog_id': $error = __('No blog_id was included in your request. Please try disconnecting Jetpack from WordPress.com and then reconnecting it. Once you have done that, try connecting Publicize again.', 'jetpack'); break; case 'empty_state': $error = sprintf(__('No user information was included in your request. Please make sure that your user account has connected to Jetpack. Connect your user account by going to the <a href="%s">Jetpack page</a> within wp-admin.', 'jetpack'), Jetpack::admin_url()); break; default: $error = __('Something which should never happen, happened. Sorry about that. If you try again, maybe it will work.', 'jetpack'); break; } } else { $error = __('There was a problem connecting with Publicize. Please try again in a moment.', 'jetpack'); } } // Using the same formatting/style as Jetpack::admin_notices() error ?> <div id="message" class="jetpack-message jetpack-err"> <div class="squeezer"> <h4><?php echo wp_kses($error, array('a' => array('href' => true), 'code' => true, 'strong' => true, 'br' => true, 'b' => true)); ?> </h4> <?php if ($code) { ?> <p><?php printf(__('Error code: %s', 'jetpack'), esc_html(stripslashes($code))); ?> </p> <?php } ?> </div> </div> <?php }
function refresh_tokens_message() { global $post; $post_id = $post ? $post->ID : 0; $services = $this->get_services('all'); // Same core nonce works for all services $keyring_nonce = wp_create_nonce('keyring-request'); $expired_tokens = false; if (is_array($services) && count($services)) { foreach ($services as $name => $service) { if ($connections = $this->get_connections($name)) { foreach ($connections as $connection) { $cmeta = $this->get_connection_meta($connection); // If the token for this connection is expired, or expires soon, then warn if (!$this->is_expired($cmeta['expires'])) { continue; } if (!$expired_tokens) { ?> <div class="error below-h2 publicize-token-refresh-message"> <p><?php echo esc_html(__('Before you hit Publish, please refresh your connection to make sure we can Publicize your post:', 'jetpack')); ?> </p> <?php $expired_tokens = true; } // No need to request for a specific token id, since the token store detects duplication and updates a single token per service $nonce = wp_create_nonce("keyring-request-" . $name); $url = $this->refresh_url($name); ?> <p style="text-align: center;" id="publicize-token-refresh-<?php echo esc_attr($name); ?> " class="publicize-token-refresh-button"> <a href="<?php echo esc_url($url); ?> " class="button" target="_refresh_<?php echo esc_attr($name); ?> "> <?php printf(__('Refresh connection with %s', 'jetpack'), Publicize::get_service_label($name)); ?> </a> </p><?php } } } } if ($expired_tokens) { echo '</div>'; } }
function display_connection_error() { if (isset($_GET['service'])) { $service_name = $_GET['service']; $m = sprintf(__('There was a problem connecting to %s to create an authorized connection. Please try again in a moment.', 'jetpack'), Publicize::get_service_label($service_name)); } else { $m = __('There was a problem connecting with Publicize. Please try again in a moment.', 'jetpack'); } echo "<div class='error'>\n"; echo '<p>' . esc_html($m) . "</p>\n"; echo "</div>\n\n"; }