本文整理汇总了PHP中Sharing_Service::set_blog_services方法的典型用法代码示例。如果您正苦于以下问题:PHP Sharing_Service::set_blog_services方法的具体用法?PHP Sharing_Service::set_blog_services怎么用?PHP Sharing_Service::set_blog_services使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sharing_Service
的用法示例。
在下文中一共展示了Sharing_Service::set_blog_services方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ajax_save_services
public function ajax_save_services()
{
if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'sharing-options') && isset($_POST['hidden']) && isset($_POST['visible'])) {
$sharer = new Sharing_Service();
$sharer->set_blog_services(explode(',', $_POST['visible']), explode(',', $_POST['hidden']));
die;
}
}
示例2: update_data
//.........这里部分代码省略.........
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;
示例3: callback
public function callback($path = '', $blog_id = 0, $button_id = 0)
{
$new = $this->api->ends_with($path, '/new');
$input = $this->input();
// 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);
} else {
if (!empty($input['visibility']) && !in_array($input['visibility'], WPCOM_JSON_API_Get_Sharing_Buttons_Endpoint::$all_visibilities)) {
return new WP_Error('invalid_visibility', sprintf('The visibility field must be one of the following values: %s', implode(', ', WPCOM_JSON_API_Get_Sharing_Buttons_Endpoint::$all_visibilities)), 400);
} else {
if ($new && empty($input['URL'])) {
return new WP_Error('invalid_request', 'The URL field is required', 400);
} else {
if ($new && empty($input['icon'])) {
return new WP_Error('invalid_request', 'The icon field is required', 400);
}
}
}
}
}
// Assign default values
$visibility = $input['visibility'];
if (empty($visibility) || !isset($input['visibility']) && true === $input['enabled']) {
$visibility = 'visible';
}
// Update or create button
$ss = new Sharing_Service();
$blog_services = $ss->get_blog_services();
if ($new) {
// Attempt to create new button
$updated_service = $ss->new_service($input['name'], $input['URL'], $input['icon']);
if (false !== $updated_service && (isset($input['enabled']) && true === $input['enabled'] || isset($input['visibility']))) {
$blog_services[$visibility][(string) $updated_service->get_id()] = $updated_service;
$ss->set_blog_services(array_keys($blog_services['visible']), array_keys($blog_services['hidden']));
}
} else {
// Find existing button
$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);
}
$updated_service = $all_buttons[$button_id];
$service_id = $updated_service->get_id();
if (is_a($all_buttons[$button_id], 'Share_Custom')) {
// Replace options for existing custom button
$options = $updated_service->get_options();
$name = isset($input['name']) ? $input['name'] : $options['name'];
$url = isset($input['URL']) ? $input['URL'] : $options['url'];
$icon = isset($input['icon']) ? $input['icon'] : $options['icon'];
$updated_service = new Share_Custom($service_id, array('name' => $name, 'url' => $url, 'icon' => $icon));
$ss->set_service($button_id, $updated_service);
}
// Update button visibility
$visibility_changed = (isset($input['visibility']) || true === $input['enabled']) && !array_key_exists($service_id, $blog_services[$visibility]);
$is_disabling = false === $input['enabled'];
if ($visibility_changed || $is_disabling) {
// Remove from all other visibilities
foreach ($blog_services as $service_visibility => $services) {
if ($service_visibility !== $visibility || $is_disabling) {
unset($blog_services[$service_visibility][$service_id]);
}
}
if ($visibility_changed) {
$blog_services[$visibility][$service_id] = $updated_service;
}
$ss->set_blog_services(array_keys($blog_services['visible']), array_keys($blog_services['hidden']));
}
}
if (false === $updated_service) {
return new WP_Error('invalid_request', sprintf('The sharing button was not %s', $new ? 'created' : 'updated'), 400);
} else {
return WPCOM_JSON_API_Get_Sharing_Button_Endpoint::format_sharing_button($ss, $updated_service);
}
}
开发者ID:moushegh,项目名称:blog-source-configs,代码行数:83,代码来源:class.wpcom-json-api-sharing-buttons-endpoint.php
示例4: update_module
//.........这里部分代码省略.........
} 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(' ', '', $value)));
if (is_wp_error($updated)) {
$error = $updated->get_error_message();
}
break;
case 'show_headline':
case 'show_thumbnails':
$grouped_options = $grouped_options_current = 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':
$grouped_options = $grouped_options_current = 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':
$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':
$sharer = new Sharing_Service();
$grouped_options = $sharer->get_global_options();
$grouped_options[$option] = $value;
$updated = $sharer->set_global_options($grouped_options);
break;
case 'custom':
$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':
$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':