本文整理汇总了PHP中Jetpack::get_option方法的典型用法代码示例。如果您正苦于以下问题:PHP Jetpack::get_option方法的具体用法?PHP Jetpack::get_option怎么用?PHP Jetpack::get_option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jetpack
的用法示例。
在下文中一共展示了Jetpack::get_option方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_access_token
/**
* Gets locally stored token
*
* @return object|false
*/
public static function get_access_token($user_id = false)
{
if ($user_id) {
if (!($tokens = Jetpack::get_option('user_tokens'))) {
return false;
}
if ($user_id === JETPACK_MASTER_USER) {
if (!($user_id = Jetpack::get_option('master_user'))) {
return false;
}
}
if (!isset($tokens[$user_id]) || !($token = $tokens[$user_id])) {
return false;
}
$token_chunks = explode('.', $token);
if (empty($token_chunks[1]) || empty($token_chunks[2])) {
return false;
}
if ($user_id != $token_chunks[2]) {
return false;
}
$token = "{$token_chunks[0]}.{$token_chunks[1]}";
} else {
$token = Jetpack::get_option('blog_token');
if (empty($token)) {
return false;
}
}
return (object) array('secret' => $token, 'external_user_id' => (int) $user_id);
}
示例2: verify_action
/**
* @return WP_Error|string secret_2 on success, WP_Error( error_code => error_code, error_message => error description, error_data => status code ) on failure
*
* Possible error_codes:
*
* verify_secret_1_missing
* verify_secret_1_malformed
* verify_secrets_missing: No longer have verification secrets stored
* verify_secrets_mismatch: stored secret_1 does not match secret_1 sent by Jetpack.WordPress.com
*/
function verify_action($params)
{
$action = $params[0];
$verify_secret = $params[1];
if (empty($verify_secret)) {
return $this->error(new Jetpack_Error('verify_secret_1_missing', sprintf('The required "%s" parameter is missing.', 'secret_1'), 400));
} else {
if (!is_string($verify_secret)) {
return $this->error(new Jetpack_Error('verify_secret_1_malformed', sprintf('The required "%s" parameter is malformed.', 'secret_1'), 400));
}
}
$secrets = Jetpack::get_option($action);
if (!$secrets || is_wp_error($secrets)) {
Jetpack::delete_option($action);
return $this->error(new Jetpack_Error('verify_secrets_missing', 'Verification took too long', 400));
}
@(list($secret_1, $secret_2, $secret_eol) = explode(':', $secrets));
if (empty($secret_1) || empty($secret_2) || empty($secret_eol) || $secret_eol < time()) {
Jetpack::delete_option($action);
return $this->error(new Jetpack_Error('verify_secrets_missing', 'Verification took too long', 400));
}
if ($verify_secret !== $secret_1) {
Jetpack::delete_option($action);
return $this->error(new Jetpack_Error('verify_secrets_mismatch', 'Secret mismatch', 400));
}
Jetpack::delete_option($action);
return $secret_2;
}
示例3: es_api_search_index
/**
* Executes an elasticsearch query via our REST API.
*
* Requires setup on our end and a paid addon to your hosting account.
* You probably shouldn't be using this function. Questions? Ask us.
*
* Valid arguments:
*
* * size: Number of query results to return.
*
* * from: Offset, the starting result to return.
*
* * multi_match: Will do a match search against the default fields (this is almost certainly what you want).
* e.g. array( 'query' => 'this is a test', 'fields' => array( 'content' ) )
* See: http://www.elasticsearch.org/guide/reference/query-dsl/multi-match-query.html
*
* * query_string: Will do a query_string search, interprets the string as Lucene query syntax.
* e.g. array( 'default_field' => 'content', 'query' => 'tag:(world OR nation) howdy' )
* This can fail if the user doesn't close parenthesis, or specifies a field that is not valid.
* See: http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html
*
* * more_like_this: Will do a more_like_this search, which is best for related content.
* e.g. array( 'fields' => array( 'title', 'content' ), 'like_text' => 'this is a test', 'min_term_freq' => 1, 'max_query_terms' => 12 )
* See: http://www.elasticsearch.org/guide/reference/query-dsl/mlt-query.html
*
* * facets: Structured set of facets. DO NOT do a terms facet on the content of posts/comments. It will load ALL terms into memory,
* probably taking minutes to complete and slowing down the entire cluster. With great power... etc.
* See: http://www.elasticsearch.org/guide/reference/api/search/facets/index.html
*
* * filter: Structured set of filters (often FASTER, since cached from one query to the next).
* See: http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html
*
* * highlight: Structure defining how to highlight the results.
* See: http://www.elasticsearch.org/guide/reference/api/search/highlighting.html
*
* * fields: Structure defining what fields to return with the results.
* See: http://www.elasticsearch.org/guide/reference/api/search/fields.html
*
* * sort: Structure defining how to sort the results.
* See: http://www.elasticsearch.org/guide/reference/api/search/sort.html
*
* @param array $args
* @return bool|string False if WP_Error, otherwise JSON string
*/
function es_api_search_index($args)
{
if (class_exists('Jetpack')) {
$jetpack_blog_id = Jetpack::get_option('id');
if (!$jetpack_blog_id) {
return array('error' => 'Failed to get Jetpack blog_id');
}
$args['blog_id'] = $jetpack_blog_id;
}
$defaults = array('blog_id' => get_current_blog_id());
$args = wp_parse_args($args, $defaults);
$args['blog_id'] = absint($args['blog_id']);
$service_url = 'http://public-api.wordpress.com/rest/v1/sites/' . $args['blog_id'] . '/search';
unset($args['blog_id']);
$request = wp_remote_post($service_url, array('headers' => array('Content-Type' => 'application/json'), 'body' => json_encode($args)));
if (is_wp_error($request)) {
return false;
}
$response = json_decode(wp_remote_retrieve_body($request), true);
// Rewrite blog id from remote to local id
if (isset($response['results']) && isset($response['results']['hits'])) {
$local_blog_id = get_current_blog_id();
foreach ($response['results']['hits'] as $key => $hit) {
if (isset($hit['fields']['blog_id']) && $hit['fields']['blog_id'] == $jetpack_blog_id) {
$response['results']['hits'][$key]['fields']['blog_id'] = $local_blog_id;
}
}
}
return $response;
}
示例4: jetpack_enhanced_distribution_before_activate_default_modules
function jetpack_enhanced_distribution_before_activate_default_modules()
{
$old_version = Jetpack::get_option('old_version');
list($old_version) = explode(':', $old_version);
if (version_compare($old_version, '1.9-something', '>=')) {
return;
}
Jetpack::check_privacy(__FILE__);
}
示例5: wpme_get_shortlink
function wpme_get_shortlink($id = 0, $context = 'post', $allow_slugs = true)
{
global $wp_query;
$blog_id = Jetpack::get_option('id');
if ('query' == $context) {
if (is_singular()) {
$id = $wp_query->get_queried_object_id();
$context = 'post';
} elseif (is_front_page()) {
$context = 'blog';
} else {
return '';
}
}
if ('blog' == $context) {
if (empty($id)) {
$id = $blog_id;
}
return 'http://wp.me/' . wpme_dec2sixtwo($id);
}
$post = get_post($id);
if (empty($post)) {
return '';
}
$post_id = $post->ID;
$type = '';
if ($allow_slugs && 'publish' == $post->post_status && 'post' == $post->post_type && strlen($post->post_name) <= 8 && false === strpos($post->post_name, '%') && false === strpos($post->post_name, '-')) {
$id = $post->post_name;
$type = 's';
} else {
$id = wpme_dec2sixtwo($post_id);
if ('page' == $post->post_type) {
$type = 'P';
} elseif ('post' == $post->post_type) {
$type = 'p';
} elseif ('attachment' == $post->post_type) {
$type = 'a';
}
}
if (empty($type)) {
return '';
}
return 'http://wp.me/' . $type . wpme_dec2sixtwo($blog_id) . '-' . $id;
}
示例6: get_token
/**
* @return object|WP_Error
*/
function get_token($data)
{
$jetpack = Jetpack::init();
$role = $jetpack->translate_current_user_to_role();
if (!$role) {
return new Jetpack_Error('role', __('An administrator for this blog must set up the Jetpack connection.', 'jetpack'));
}
$client_secret = Jetpack_Data::get_access_token(0);
if (!$client_secret) {
return new Jetpack_Error('client_secret', __('You need to register your Jetpack before connecting it.', 'jetpack'));
}
$body = array('client_id' => Jetpack::get_option('id'), 'client_secret' => $client_secret->secret, 'grant_type' => 'authorization_code', 'code' => $data['code'], 'redirect_uri' => add_query_arg(array('action' => 'authorize', '_wpnonce' => wp_create_nonce("jetpack-authorize_{$role}")), menu_page_url('jetpack', false)));
$args = array('method' => 'POST', 'body' => $body, 'headers' => array('Accept' => 'application/json'));
$response = Jetpack_Client::_wp_remote_request(Jetpack::fix_url_for_bad_hosts(Jetpack::api_url('token'), $args), $args);
if (is_wp_error($response)) {
return new Jetpack_Error('token_http_request_failed', $response->get_error_message());
}
$code = wp_remote_retrieve_response_code($response);
$entity = wp_remote_retrieve_body($response);
if ($entity) {
$json = json_decode($entity);
} else {
$json = false;
}
if (200 != $code || !empty($json->error)) {
if (empty($json->error)) {
return new Jetpack_Error('unknown', '', $code);
}
$error_description = isset($json->error_description) ? sprintf(__('Error Details: %s', 'jetpack'), (string) $json->error_description) : '';
return new Jetpack_Error((string) $json->error, $error_description, $code);
}
if (empty($json->access_token) || !is_scalar($json->access_token)) {
return new Jetpack_Error('access_token', '', $code);
}
if (empty($json->token_type) || 'X_JETPACK' != strtoupper($json->token_type)) {
return new Jetpack_Error('token_type', '', $code);
}
if (empty($json->scope)) {
return new Jetpack_Error('scope', 'No Scope', $code);
}
@(list($role, $hmac) = explode(':', $json->scope));
if (empty($role) || empty($hmac)) {
return new Jetpack_Error('scope', 'Malformed Scope', $code);
}
if ($jetpack->sign_role($role) !== $json->scope) {
return new Jetpack_Error('scope', 'Invalid Scope', $code);
}
if (!($cap = $jetpack->translate_role_to_cap($role))) {
return new Jetpack_Error('scope', 'No Cap', $code);
}
if (!current_user_can($cap)) {
return new Jetpack_Error('scope', 'current_user_cannot', $code);
}
return (string) $json->access_token;
}
示例7: set_time_diff
public static function set_time_diff(&$response, $force_set = false)
{
$code = wp_remote_retrieve_response_code($response);
// Only trust the Date header on some responses
if (200 != $code && 304 != $code && 400 != $code && 401 != $code) {
return;
}
if (!($date = wp_remote_retrieve_header($response, 'date'))) {
return;
}
if (0 >= ($time = (int) strtotime($date))) {
return;
}
$time_diff = $time - time();
if ($force_set) {
// during register
Jetpack::update_option('time_diff', $time_diff);
} else {
// otherwise
$old_diff = Jetpack::get_option('time_diff');
if (false === $old_diff || abs($time_diff - (int) $old_diff) > 10) {
Jetpack::update_option('time_diff', $time_diff);
}
}
}
示例8: options_page_tumblr
function options_page_tumblr()
{
// Nonce check
check_admin_referer('options_page_tumblr_' . $_REQUEST['connection']);
$connected_services = Jetpack::get_option('publicize_connections');
$connection = $connected_services['tumblr'][$_POST['connection']];
$options_to_show = $connection['connection_data']['meta']['options_responses'];
$request = $options_to_show[0];
$blogs = $request['response']['user']['blogs'];
$blog_selected = false;
if (!empty($connection['connection_data']['meta']['tumblr_base_hostname'])) {
foreach ($blogs as $blog) {
if ($connection['connection_data']['meta']['tumblr_base_hostname'] == $this->get_basehostname($blog['url'])) {
$blog_selected = $connection['connection_data']['meta']['tumblr_base_hostname'];
break;
}
}
}
// Use their Primary blog if they haven't selected one yet
if (!$blog_selected) {
foreach ($blogs as $blog) {
if ($blog['primary']) {
$blog_selected = $this->get_basehostname($blog['url']);
}
}
}
?>
<div id="thickbox-content">
<?php
ob_start();
Publicize_UI::connected_notice('Tumblr');
$update_notice = ob_get_clean();
if (!empty($update_notice)) {
echo $update_notice;
}
?>
<p><?php
printf(esc_html__('Publicize to my %s:', 'jetpack'), '<strong>' . esc_html__('Tumblr blog', 'jetpack') . '</strong>');
?>
</p>
<ul id="option-tumblr-blog">
<?php
foreach ($blogs as $blog) {
$url = $this->get_basehostname($blog['url']);
?>
<li>
<input type="radio" name="option" data-type="blog" id="<?php
echo esc_attr($url);
?>
" value="<?php
echo esc_attr($url);
?>
" <?php
checked($blog_selected == $url, true);
?>
/>
<label for="<?php
echo esc_attr($url);
?>
"><span class="name"><?php
echo esc_html($blog['title']);
?>
</span></label>
</li>
<?php
}
?>
</ul>
<?php
Publicize_UI::global_checkbox('tumblr', $_REQUEST['connection']);
?>
<p style="text-align: center;">
<input type="submit" value="<?php
esc_attr_e('OK', 'jetpack');
?>
" class="button tumblr-options save-options" name="save" data-connection="<?php
echo esc_attr($_REQUEST['connection']);
?>
" rel="<?php
echo wp_create_nonce('save_tumblr_blog_' . $_REQUEST['connection']);
?>
" />
</p> <br />
</div>
<?php
}
示例9: filter_infinite_scroll_js_settings
/**
* Modify Infinite Scroll configuration information
*
* @uses Jetpack::get_active_modules, is_user_logged_in, stats_get_options, Jetpack::get_option, get_option, JETPACK__API_VERSION, JETPACK__VERSION
* @filter infinite_scroll_js_settings
* @return array
*/
public function filter_infinite_scroll_js_settings($settings)
{
// Provide WP Stats info for tracking Infinite Scroll loads
// Abort if Stats module isn't active
if (in_array('stats', Jetpack::get_active_modules())) {
// Abort if user is logged in but logged-in users shouldn't be tracked.
if (is_user_logged_in()) {
$stats_options = stats_get_options();
$track_loggedin_users = isset($stats_options['reg_users']) ? (bool) $stats_options['reg_users'] : false;
if (!$track_loggedin_users) {
return $settings;
}
}
// We made it this far, so gather the data needed to track IS views
$settings['stats'] = 'blog=' . Jetpack::get_option('id') . '&host=' . parse_url(get_option('home'), PHP_URL_HOST) . '&v=ext&j=' . JETPACK__API_VERSION . ':' . JETPACK__VERSION;
}
// Check if Google Analytics tracking is requested
$settings['google_analytics'] = (bool) get_option($this->option_name_google_analytics);
return $settings;
}
示例10: jetpack_debug_menu_display_handler
function jetpack_debug_menu_display_handler()
{
if (!current_user_can('manage_options')) {
wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'jetpack'));
}
global $current_user;
get_currentuserinfo();
$is_jetpack_support_open = is_jetpack_support_open();
$self_xml_rpc_url = site_url('xmlrpc.php');
$tests = array();
$tests['HTTP'] = wp_remote_get('http://jetpack.wordpress.com/jetpack.test/1/');
$tests['HTTPS'] = wp_remote_get('https://jetpack.wordpress.com/jetpack.test/1/');
if (preg_match('/^https:/', $self_xml_rpc_url)) {
$tests['SELF'] = wp_remote_get(preg_replace('/^https:/', 'http:', $self_xml_rpc_url));
$tests['SELF-SEC'] = wp_remote_get($self_xml_rpc_url, array('sslverify' => true));
} else {
$tests['SELF'] = wp_remote_get($self_xml_rpc_url);
}
$user_id = get_current_user_id();
$user_tokens = Jetpack::get_option('user_tokens');
if (is_array($user_tokens) && array_key_exists($user_id, $user_tokens)) {
$user_token = $user_tokens[$user_id];
} else {
$user_token = '[this user has no token]';
}
unset($user_tokens);
$debug_info = "\r\n";
foreach (array('CLIENT_ID' => 'id', 'BLOG_TOKEN' => 'blog_token', 'MASTER_USER' => 'master_user', 'CERT' => 'fallback_no_verify_ssl_certs', 'TIME_DIFF' => 'time_diff', 'VERSION' => 'version', 'OLD_VERSION' => 'old_version', 'PUBLIC' => 'public') as $label => $option_name) {
$debug_info .= "\r\n" . esc_html($label . ": " . Jetpack::get_option($option_name));
}
$debug_info .= "\r\n" . esc_html("USER_ID: " . $user_id);
$debug_info .= "\r\n" . esc_html("USER_TOKEN: " . $user_token);
$debug_info .= "\r\n" . esc_html("PHP_VERSION: " . PHP_VERSION);
$debug_info .= "\r\n" . esc_html("WORDPRESS_VERSION: " . $GLOBALS['wp_version']);
$debug_info .= "\r\n" . esc_html("JETPACK__VERSION: " . JETPACK__VERSION);
$debug_info .= "\r\n" . esc_html("JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR);
$debug_info .= "\r\n" . esc_html("SITE_URL: " . site_url());
$debug_info .= "\r\n" . esc_html("HOME_URL: " . home_url());
$debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
$debug_raw_info = '';
?>
<div class="wrap">
<h2><?php
esc_html_e('Jetpack Debugging Center', 'jetpack');
?>
</h2>
<h3><?php
_e("Tests your site's compatibily with Jetpack.", 'jetpack');
?>
</h3>
<h3><?php
_e('Tests:', 'jetpack');
?>
</h3>
<div class="jetpack-debug-test-container">
<?php
foreach ($tests as $test_name => $test_result) {
$result = '';
if (is_wp_error($test_result)) {
$test_class = 'jetpack-test-error';
$offer_ticket_submission = true;
$status = __('System Failure!', 'jetpack');
$result = esc_html($test_result->get_error_message());
} else {
$response_code = wp_remote_retrieve_response_code($test_result);
if (empty($response_code)) {
$test_class = 'jetpack-test-error';
$offer_ticket_submission = true;
$status = __('Failed!', 'jetpack');
} elseif ('200' == $response_code) {
$test_class = 'jetpack-test-success';
$status = __('Passed!', 'jetpack');
} else {
$test_class = 'jetpack-test-error';
$offer_ticket_submission = true;
$status = __('Failed!', 'jetpack');
}
}
$debug_info .= $test_name . ': ' . $status . "\r\n";
$debug_raw_info .= "\r\n\r\n" . $test_name . "\r\n" . esc_html(print_r($test_result, 1));
?>
<div class="jetpack-test-results <?php
esc_html_e($test_class, 'jetpack');
?>
">
<p>
<a class="jetpack-test-heading" href="#"><?php
esc_html_e($test_name, 'jetpack');
?>
: <?php
esc_html_e($status, 'jetpack');
?>
<span class="noticon noticon-collapse"></span>
</a>
</p>
<pre class="jetpack-test-details"><?php
esc_html_e($result, 'jetpack');
?>
</pre>
//.........这里部分代码省略.........
示例11: get_link
/**
* Just a shortcut to the serialized Jetpack options.
*
* @param string $service The name of the service that we're looking for.
* @param string $default The data to return if we've not got anything on file.
* @returns string $link The social link that we've got, or the default if not.
*/
private function get_link($service, $default = '')
{
$links = Jetpack::get_option('social_links', array());
if (!empty($links[$service])) {
return $links[$service];
}
return $default;
}
示例12: jumpstart_has_updated_module_option
public static function jumpstart_has_updated_module_option($option_name = '')
{
// Bail if Jump Start has already been dismissed
if ('new_connection' !== Jetpack::get_option('jumpstart')) {
return false;
}
$jetpack = Jetpack::init();
// Manual build of module options
$option_names = self::get_jetapck_options_for_reset();
if (in_array($option_name, $option_names['wp_options'])) {
Jetpack_Options::update_option('jumpstart', 'jetpack_action_taken');
//Jump start is being dismissed send data to MC Stats
$jetpack->stat('jumpstart', 'manual,' . $option_name);
$jetpack->do_stats('server_side');
}
}
示例13: stats_get_csv
function stats_get_csv($table, $args = null)
{
$defaults = array('end' => false, 'days' => false, 'limit' => 3, 'post_id' => false, 'summarize' => '');
$args = wp_parse_args($args, $defaults);
$args['table'] = $table;
$args['blog_id'] = Jetpack::get_option('id');
$stats_csv_url = add_query_arg($args, 'http://stats.wordpress.com/csv.php');
$key = md5($stats_csv_url);
// Get cache
$stats_cache = get_option('stats_cache');
if (!$stats_cache || !is_array($stats_cache)) {
$stats_cache = array();
}
// Return or expire this key
if (isset($stats_cache[$key])) {
$time = key($stats_cache[$key]);
if (time() - $time < 300) {
return $stats_cache[$key][$time];
}
unset($stats_cache[$key]);
}
$stats_rows = array();
do {
if (!($stats = stats_get_remote_csv($stats_csv_url))) {
break;
}
$labels = array_shift($stats);
if (0 === stripos($labels[0], 'error')) {
break;
}
$stats_rows = array();
for ($s = 0; isset($stats[$s]); $s++) {
$row = array();
foreach ($labels as $col => $label) {
$row[$label] = $stats[$s][$col];
}
$stats_rows[] = $row;
}
} while (0);
// Expire old keys
foreach ($stats_cache as $k => $cache) {
if (!is_array($cache) || 300 < time() - key($cache)) {
unset($stats_cache[$k]);
}
}
// Set cache
$stats_cache[$key] = array(time() => $stats_rows);
update_option('stats_cache', $stats_cache);
return $stats_rows;
}
示例14: pre_comment_on_post
/**
* Verify the hash included in remote comments.
*
* @since JetpackComments (1.4)
* @param type $comment Not used
*/
public function pre_comment_on_post($comment)
{
$post_array = stripslashes_deep($_POST);
// Bail if missing the Jetpack token
if (!isset($post_array['sig'])) {
unset($_POST['hc_post_as']);
return;
}
if (FALSE !== strpos($post_array['hc_avatar'], '.gravatar.com')) {
$post_array['hc_avatar'] = htmlentities($post_array['hc_avatar']);
}
$check = Jetpack_Comments::sign_remote_comment_parameters($post_array, Jetpack::get_option('blog_token'));
if (is_wp_error($check)) {
wp_die($check);
}
// Bail if token is expired or not valid
if ($check !== $post_array['sig']) {
wp_die(__('Invalid security token.', 'jetpack'));
}
}
示例15: initialize
function initialize()
{
$this->token_details['blog_id'] = Jetpack::get_option('id');
}