本文整理匯總了PHP中maybe_unserialize函數的典型用法代碼示例。如果您正苦於以下問題:PHP maybe_unserialize函數的具體用法?PHP maybe_unserialize怎麽用?PHP maybe_unserialize使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了maybe_unserialize函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: genesis_update_check
/**
* Pings http://api.genesistheme.com/ asking if a new version of this theme is
* available.
*
* If not, it returns false.
*
* If so, the external server passes serialized data back to this function,
* which gets unserialized and returned for use.
*
* @since 1.1.0
*
* @uses genesis_get_option()
* @uses PARENT_THEME_VERSION Genesis version string
*
* @global string $wp_version WordPress version string
* @return mixed Unserialized data, or false on failure
*/
function genesis_update_check()
{
global $wp_version;
/** If updates are disabled */
if (!genesis_get_option('update') || !current_theme_supports('genesis-auto-updates')) {
return false;
}
/** Get time of last update check */
$genesis_update = get_transient('genesis-update');
/** If it has expired, do an update check */
if (!$genesis_update) {
$url = 'http://api.genesistheme.com/update-themes/';
$options = apply_filters('genesis_update_remote_post_options', array('body' => array('genesis_version' => PARENT_THEME_VERSION, 'wp_version' => $wp_version, 'php_version' => phpversion(), 'uri' => home_url(), 'user-agent' => "WordPress/{$wp_version};")));
$response = wp_remote_post($url, $options);
$genesis_update = wp_remote_retrieve_body($response);
/** If an error occurred, return FALSE, store for 1 hour */
if ('error' == $genesis_update || is_wp_error($genesis_update) || !is_serialized($genesis_update)) {
set_transient('genesis-update', array('new_version' => PARENT_THEME_VERSION), 60 * 60);
return false;
}
/** Else, unserialize */
$genesis_update = maybe_unserialize($genesis_update);
/** And store in transient for 24 hours */
set_transient('genesis-update', $genesis_update, 60 * 60 * 24);
}
/** If we're already using the latest version, return false */
if (version_compare(PARENT_THEME_VERSION, $genesis_update['new_version'], '>=')) {
return false;
}
return $genesis_update;
}
示例2: set_dfi_meta_key
/**
* Mostly the same as `get_metadata()` makes sure any postthumbnail function gets checked at
* the deepest level possible.
*
* @see /wp-includes/meta.php get_metadata()
*
* @param null $null
* @param int $object_id ID of the object metadata is for
* @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
* the specified object.
* @param bool $single Optional, default is false. If true, return only the first value of the
* specified meta_key. This parameter has no effect if meta_key is not specified.
* @return string|array Single metadata value, or array of values
*/
function set_dfi_meta_key($null = null, $object_id, $meta_key, $single)
{
// only affect thumbnails on the frontend, do allow ajax calls
if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX) || '_thumbnail_id' != $meta_key) {
return $null;
}
$meta_type = 'post';
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
if (!$meta_cache) {
$meta_cache = update_meta_cache($meta_type, array($object_id));
$meta_cache = $meta_cache[$object_id];
}
if (!$meta_key) {
return $meta_cache;
}
if (isset($meta_cache[$meta_key])) {
if ($single) {
return maybe_unserialize($meta_cache[$meta_key][0]);
} else {
return array_map('maybe_unserialize', $meta_cache[$meta_key]);
}
}
if ($single) {
// allow to set an other ID see the readme.txt for details
return apply_filters('dfi_thumbnail_id', get_option('dfi_image_id'), $object_id);
} else {
return array();
}
}
示例3: calibrefx_update_check
/**
* This function calibrefx_update_check is to ...
*/
function calibrefx_update_check()
{
global $wp_version;
/** Get time of last update check */
$calibrefx_update = get_transient('calibrefx-update');
/** If it has expired, do an update check */
if (!$calibrefx_update) {
$url = 'http://api.calibrefx.com/themes-update/';
$options = apply_filters('calibrefx_update_remote_post_options', array('body' => array('theme_name' => 'calibrefx', 'theme_version' => FRAMEWORK_VERSION, 'url' => home_url(), 'wp_version' => $wp_version, 'php_version' => phpversion(), 'user-agent' => "WordPress/{$wp_version};")));
$response = wp_remote_post($url, $options);
$calibrefx_update = wp_remote_retrieve_body($response);
/** If an error occurred, return FALSE, store for 48 hour */
if ('error' == $calibrefx_update || is_wp_error($calibrefx_update) || !is_serialized($calibrefx_update)) {
set_transient('calibrefx-update', array('new_version' => FRAMEWORK_VERSION), 60 * 60 * 48);
return false;
}
/** Else, unserialize */
$calibrefx_update = maybe_unserialize($calibrefx_update);
/** And store in transient for 48 hours */
set_transient('calibrefx-update', $calibrefx_update, 60 * 60 * 48);
}
/** If we're already using the latest version, return false */
if (version_compare(FRAMEWORK_VERSION, $calibrefx_update['new_version'], '>=')) {
return false;
}
return $calibrefx_update;
}
示例4: get_data
public function get_data($key)
{
global $post;
$settings = array();
if (isset($this->manager->post_meta['_cornerstone_settings'])) {
$settings = maybe_unserialize($this->manager->post_meta['_cornerstone_settings'][0]);
}
if ('custom_css' == $key && isset($settings['custom_css'])) {
return $settings['custom_css'];
}
if ('custom_js' == $key && isset($settings['custom_js'])) {
return $settings['custom_js'];
}
if ('post_title' == $key && isset($post->post_title)) {
return $post->post_title;
}
if ('post_status' == $key && isset($post->post_status)) {
return $post->post_status;
}
if ('allow_comments' == $key && isset($post->comment_status)) {
return $post->comment_status == 'open';
}
if ('post_parent' == $key && isset($post->post_parent)) {
return "{$post->post_parent}";
}
if ('page_template' == $key && isset($this->manager->post_meta['_wp_page_template'])) {
return $this->manager->post_meta['_wp_page_template'][0];
}
return null;
}
示例5: pre_http_request
function pre_http_request($content, $r, $url)
{
$key = $this->getKey($url, $r);
$this->r(sprintf('request transient key: %s<br />request url: %s,<br />request args: %s', $key, $url, print_r($r, true)), false, 'Request Details');
// If caching isn't set, return.
if (!$this->getCacheTime($r)) {
$this->r('Not cached because the `cache` parameter is not set or cacheTime() method says no cache');
return false;
}
$response = maybe_unserialize(get_transient($key));
$this->flushCache($url, $r);
if (strtoupper($r['method'] !== 'GET') || current_user_can('manage_options') && isset($_REQUEST['cache']) || !$response || is_wp_error($response) || $response && $response['response']['code'] !== 200) {
if (strtoupper($r['method'] !== 'GET')) {
// If something's been PUT or POSTed to the same endpoint, let's reset the cache for that.
$this->r('not cached due to method not GET');
} elseif (current_user_can('manage_options') && isset($_REQUEST['cache'])) {
$this->r('not cached due to overrides');
} elseif (!$response || is_wp_error($response)) {
$this->r('not cached due to no response (or error response)');
$this->r($response, false, '$response:');
} else {
$this->r(sprintf('not cached due to response code being %s', $response['response']['code']));
}
return false;
}
if ($this->debug) {
$this->r($response, false, 'Response (Cached)');
}
return $response;
}
示例6: _get_items_from_thimpress
private function _get_items_from_thimpress($add_ons)
{
$cache = WP_CONTENT_DIR . '/upgrade/' . md5(serialize($add_ons)) . '.cache';
$timeover = HOUR_IN_SECONDS * 24;
if (file_exists($cache) && time() - filemtime($cache) < $timeover) {
$items = maybe_unserialize(file_get_contents($cache));
} else {
$repo_url = 'http://thimpress.com/lprepo/';
foreach ($add_ons as $slug) {
if (false !== strpos($slug, '.php')) {
$filename = basename($slug);
$slug = dirname($slug);
} else {
$filename = "{$slug}.php";
}
$item = array('name' => '', 'slug' => '', 'version' => '0.0', 'author' => '<a href="http://profiles.wordpress.org/thimpress">thimpress</a>', 'author_profile' => 'http://profiles.wordpress.org/thimpress', 'contributors' => array(), 'requires' => '4.0', 'tested' => '4.2.2', 'rating' => 0, 'num_ratings' => 0, 'ratings' => array('5' => 0, '4' => 0, '3' => 0, '2' => 0, '1' => 0), 'active_installs' => 0, 'last_updated' => gmdate('Y-m-d h:iA', strtotime('last Friday', time())) . ' GMT', 'homepage' => 'http://thimpress.com/learnpress', 'short_description' => '', 'icons' => array('2x' => LPR_PLUGIN_URL . '/assets/images/icon-128x128.png', '1x' => LPR_PLUGIN_URL . '/assets/images/icon-128x128.png'));
$readme = $this->upgrader->get_plugin_info($repo_url . "/{$slug}.zip", $filename);
$item['name'] = $readme['name'];
$item['slug'] = $slug;
if (preg_match('!<h4>(.*)<\\/h4>!', $readme['sections']['changelog'], $matches)) {
$item['version'] = $matches[1];
}
$item['requires'] = $readme['requires_at_least'];
$item['tested'] = $readme['tested_up_to'];
$items["{$slug}/{$filename}"] = (object) $item;
}
file_put_contents($cache, serialize($items));
}
$this->items = $items;
}
示例7: sf_acf_postmeta_values_of_checkboxes
function sf_acf_postmeta_values_of_checkboxes($value)
{
global $wpdb;
$meta_key = $value[0]->meta_key;
$sql = "select meta_value from " . $wpdb->prefix . "postmeta where meta_key = %s group by meta_value";
$sql = $wpdb->prepare($sql, '_' . $meta_key);
$res = $wpdb->get_results($sql);
if (count($res) == 0) {
return $value;
}
$sql = "select meta_value from " . $wpdb->prefix . "postmeta where meta_key = %s group by meta_value";
$sql = $wpdb->prepare($sql, $res[0]->meta_value);
$res = $wpdb->get_results($sql);
if (count($res) == 0) {
return $value;
}
$maybe_checkbox = maybe_unserialize($res[0]->meta_value);
if (!isset($maybe_checkbox['choices']) || !isset($maybe_checkbox['type']) || $maybe_checkbox['type'] != 'checkbox') {
return $value;
}
$choices = array();
foreach ($maybe_checkbox['choices'] as $key => $val) {
$choice['meta_key'] = $key;
$choice['meta_value'] = $key;
$choices[] = $choice;
}
$choices = json_encode($choices);
$choices = json_decode($choices);
return $choices;
}
示例8: acf_get_value
function acf_get_value($post_id, $field)
{
// try cache
$found = false;
$cache = wp_cache_get("load_value/post_id={$post_id}/name={$field['name']}", 'acf', false, $found);
if ($found) {
return $cache;
}
// load value
$value = acf_get_metadata($post_id, $field['name']);
// if value was duplicated, it may now be a serialized string!
$value = maybe_unserialize($value);
// no value? try default_value
if ($value === null && isset($field['default_value'])) {
$value = $field['default_value'];
}
// filter for 3rd party customization
$value = apply_filters("acf/load_value", $value, $post_id, $field);
$value = apply_filters("acf/load_value/type={$field['type']}", $value, $post_id, $field);
$value = apply_filters("acf/load_value/name={$field['name']}", $value, $post_id, $field);
$value = apply_filters("acf/load_value/key={$field['key']}", $value, $post_id, $field);
//update cache
wp_cache_set("load_value/post_id={$post_id}/name={$field['name']}", $value, 'acf');
// return
return $value;
}
示例9: wpsc_update_meta
/**
* Adds and updates meta data in the database
*
* @internal
*/
function wpsc_update_meta($object_id = 0, $meta_key, $meta_value, $type, $global = false)
{
global $wpdb;
if (!is_numeric($object_id) || empty($object_id) && !$global) {
return false;
}
$cache_object_id = $object_id = (int) $object_id;
$object_type = $type;
$meta_key = wpsc_sanitize_meta_key($meta_key);
$meta_tuple = compact('object_type', 'object_id', 'meta_key', 'meta_value', 'type');
$meta_tuple = apply_filters('wpsc_update_meta', $meta_tuple);
extract($meta_tuple, EXTR_OVERWRITE);
$meta_value = $_meta_value = maybe_serialize($meta_value);
$meta_value = maybe_unserialize($meta_value);
$cur = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_META . "` WHERE `object_type` = %s AND `object_id` = %d AND `meta_key` = %s", $object_type, $object_id, $meta_key));
if (!$cur) {
$wpdb->insert(WPSC_TABLE_META, array('object_type' => $object_type, 'object_id' => $object_id, 'meta_key' => $meta_key, 'meta_value' => $_meta_value));
} elseif ($cur->meta_value != $meta_value) {
$wpdb->update(WPSC_TABLE_META, array('meta_value' => $_meta_value), array('object_type' => $object_type, 'object_id' => $object_id, 'meta_key' => $meta_key));
}
wp_cache_delete($cache_object_id, $object_type);
if (!$cur) {
return true;
}
}
示例10: call_remote_api
/**
* Calls the API and, if successfull, returns the object delivered by the API.
*
* @uses get_bloginfo()
* @uses wp_remote_post()
* @uses is_wp_error()
*
* @return false||object
*/
protected function call_remote_api()
{
// only check if a transient is not set (or if it's expired)
if (get_transient($this->product->get_slug() . '-update-check-error') !== false) {
return;
}
// setup api parameters
$api_params = array('edd_action' => 'get_version', 'license' => $this->license_key, 'name' => $this->product->get_item_name(), 'slug' => $this->product->get_slug(), 'author' => $this->product->get_author());
// setup request parameters
$request_params = array('timeout' => 15, 'sslverify' => false, 'body' => $api_params);
// call remote api
$response = wp_remote_post($this->product->get_api_url(), $request_params);
// wp / http error?
if (is_wp_error($response)) {
$this->wp_error = $response;
// show error to user
add_action('admin_notices', array($this, 'show_update_error'));
// set a transient to prevent checking for updates on every page load
set_transient($this->product->get_slug() . '-update-check-error', true, 60 * 30);
// 30 mins
return false;
}
// decode response
$response = json_decode(wp_remote_retrieve_body($response));
$response->sections = maybe_unserialize($response->sections);
return $response;
}
示例11: plugins_api
/**
* Retrieve plugin installer pages from WordPress Plugins API.
*
* It is possible for a plugin to override the Plugin API result with three
* filters. Assume this is for plugins, which can extend on the Plugin Info to
* offer more choices. This is very powerful and must be used with care, when
* overriding the filters.
*
* The first filter, 'plugins_api_args', is for the args and gives the action as
* the second parameter. The hook for 'plugins_api_args' must ensure that an
* object is returned.
*
* The second filter, 'plugins_api', is the result that would be returned.
*
* @since 2.7.0
*
* @param string $action
* @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
* @return object plugins_api response object on success, WP_Error on failure.
*/
function plugins_api($action, $args = null)
{
if (is_array($args)) {
$args = (object) $args;
}
if (!isset($args->per_page)) {
$args->per_page = 24;
}
// Allows a plugin to override the WordPress.org API entirely.
// Use the filter 'plugins_api_result' to merely add results.
// Please ensure that a object is returned from the following filters.
$args = apply_filters('plugins_api_args', $args, $action);
$res = apply_filters('plugins_api', false, $action, $args);
if (false === $res) {
$request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))));
if (is_wp_error($request)) {
$res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message());
} else {
$res = maybe_unserialize(wp_remote_retrieve_body($request));
if (!is_object($res) && !is_array($res)) {
$res = new WP_Error('plugins_api_failed', __('An unknown error occurred during the API request.'), wp_remote_retrieve_body($request));
}
}
} elseif (!is_wp_error($res)) {
$res->external = true;
}
return apply_filters('plugins_api_result', $res, $action, $args);
}
示例12: xprofile_sanitize_data_value_before_save
/**
* xprofile_sanitize_data_value_before_save ( $field_value, $field_id )
*
* Safely runs profile field data through kses and force_balance_tags.
*
* @param string $field_value
* @param int $field_id
* @param bool $reserialize Whether to reserialize arrays before returning. Defaults to true
* @return string
*/
function xprofile_sanitize_data_value_before_save($field_value, $field_id, $reserialize = true)
{
// Return if empty
if (empty($field_value)) {
return;
}
// Value might be serialized
$field_value = maybe_unserialize($field_value);
// Filter single value
if (!is_array($field_value)) {
$kses_field_value = xprofile_filter_kses($field_value);
$filtered_field_value = nxt_rel_nofollow(force_balance_tags($kses_field_value));
$filtered_field_value = apply_filters('xprofile_filtered_data_value_before_save', $filtered_field_value, $field_value);
// Filter each array item independently
} else {
$filtered_values = array();
foreach ((array) $field_value as $value) {
$kses_field_value = xprofile_filter_kses($value);
$filtered_value = nxt_rel_nofollow(force_balance_tags($kses_field_value));
$filtered_values[] = apply_filters('xprofile_filtered_data_value_before_save', $filtered_value, $value);
}
if ($reserialize) {
$filtered_field_value = serialize($filtered_values);
} else {
$filtered_field_value = $filtered_values;
}
}
return $filtered_field_value;
}
示例13: get_paypal_order
/**
* Get the order from the PayPal 'Custom' variable
*
* @param string $raw_custom JSON Data passed back by PayPal
* @return bool|WC_Order object
*/
protected function get_paypal_order($raw_custom)
{
// We have the data in the correct format, so get the order
if (($custom = json_decode($raw_custom)) && is_object($custom)) {
$order_id = $custom->order_id;
$order_key = $custom->order_key;
// Fallback to serialized data if safe. This is @deprecated in 2.3.11
} elseif (preg_match('/^a:2:{/', $raw_custom) && !preg_match('/[CO]:\\+?[0-9]+:"/', $raw_custom) && ($custom = maybe_unserialize($raw_custom))) {
$order_id = $custom[0];
$order_key = $custom[1];
// Nothing was found
} else {
WC_Gateway_Paypal::log('Error: Order ID and key were not found in "custom".');
return false;
}
if (!($order = wc_get_order($order_id))) {
// We have an invalid $order_id, probably because invoice_prefix has changed
$order_id = wc_get_order_id_by_order_key($order_key);
$order = wc_get_order($order_id);
}
if (!$order || $order->order_key !== $order_key) {
WC_Gateway_Paypal::log('Error: Order Keys do not match.');
return false;
}
return $order;
}
示例14: sv_wc_mpc_shipstation_get_product_from_item_weight
/**
* Filter the product retruned by `WC_Order::woocommerce_get_product_from_item()`
* to re-calculate a Measurement Price Calculator product's weight based on the
* selected measurements. This function ensures that the "Weight" calculator
* type is handled appropriately as well.
*
* @param \WC_Product $product The product.
* @param array $item The order item.
* @param \WC_Order $order The order.
* @return \WC_Product The filtered product
*/
function sv_wc_mpc_shipstation_get_product_from_item_weight($product, $item, $order)
{
if (WC_Price_Calculator_Product::pricing_calculated_weight_enabled($product)) {
$settings = new WC_Price_Calculator_Settings($product);
if ('weight' == $settings->get_calculator_type()) {
// Now, the weight calculator products have to be handled specially
// since the customer is actually supplying the weight, but it will
// be in pricing units which may not be the same as the globally
// configured WooCommerce Weight Unit expected by other plugins and code
if (isset($item['item_meta']['_measurement_data'][0])) {
$measurement_data = maybe_unserialize($item['item_meta']['_measurement_data'][0]);
if (isset($measurement_data['_measurement_needed_unit']) && isset($measurement_data['_measurement_needed'])) {
$supplied_weight = new WC_Price_Calculator_Measurement($measurement_data['_measurement_needed_unit'], $measurement_data['_measurement_needed']);
// set the product weight as supplied by the customer, in WC Weight Units
$product->weight = $supplied_weight->get_value(get_option('woocommerce_weight_unit'));
}
}
} elseif ($product->get_weight()) {
if (isset($item['item_meta']['_measurement_data'][0])) {
$measurement_data = maybe_unserialize($item['item_meta']['_measurement_data'][0]);
// record the configured weight per unit for future reference
if (!isset($measurement_data['_weight'])) {
$measurement_data['_weight'] = $product->get_weight();
}
// calculate the product weight = unit weight * total measurement (both will be in the same pricing units so we have say lbs/sq. ft. * sq. ft. = lbs)
$product->weight = $measurement_data['_weight'] * $measurement_data['_measurement_needed'];
}
}
}
return $product;
}
示例15: get_post_pinterest_meta
/**
* Gets post Pinterest meta and sets default values, if none are entered.
*
* @param WP_Post $post The post / page.
*
* @return array Pinterest meta.
*/
public function get_post_pinterest_meta($post)
{
$pinterest = maybe_unserialize(get_post_meta($post->ID, 'pinterest', true));
if (is_admin()) {
if (empty($pinterest)) {
$pinterest['hover'] = 'true';
$pinterest['description'] = '';
$pinterest['image'] = '';
$pinterest['url'] = '';
}
return $pinterest;
}
if (!isset($pinterest['hover'])) {
$pinterest['hover'] = 'true';
}
if (empty($pinterest['description'])) {
$pinterest['description'] = $post->post_title;
}
if (empty($pinterest['image'])) {
$default_image = '';
$default_image = apply_filters('wp_pinterest_default_image', $default_image);
$pinterest['image'] = WP_Image_Util::get_instance()->get_first_image($post->post_content, $default_image);
}
if (empty($pinterest['url'])) {
$pinterest['url'] = get_permalink();
}
return $pinterest;
}