本文整理汇总了PHP中is_wp_error函数的典型用法代码示例。如果您正苦于以下问题:PHP is_wp_error函数的具体用法?PHP is_wp_error怎么用?PHP is_wp_error使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_wp_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: memberlite_getUpdateInfo
/**
* Get theme update information from the PMPro server.
*
* @since 2.0
*/
function memberlite_getUpdateInfo()
{
//check if forcing a pull from the server
$update_info = get_option("memberlite_update_info", false);
$update_info_timestamp = get_option("memberlite_update_info_timestamp", 0);
//if no update_infos locally, we need to hit the server
if (empty($update_info) || !empty($_REQUEST['force-check']) || current_time('timestamp') > $update_info_timestamp + 86400) {
/**
* Filter to change the timeout for this wp_remote_get() request.
*
* @since 2.0.1
*
* @param int $timeout The number of seconds before the request times out
*/
$timeout = apply_filters("memberlite_get_update_info_timeout", 5);
//get em
$remote_info = wp_remote_get(PMPRO_LICENSE_SERVER . "/themes/memberlite", $timeout);
//test response
if (is_wp_error($remote_info) || empty($remote_info['response']) || $remote_info['response']['code'] != '200') {
//error
pmpro_setMessage("Could not connect to the PMPro License Server to get update information. Try again later.", "error");
} else {
//update update_infos in cache
$update_info = json_decode(wp_remote_retrieve_body($remote_info), true);
delete_option('memberlite_update_info');
add_option("memberlite_update_info", $update_info, NULL, 'no');
}
//save timestamp of last update
delete_option('memberlite_update_info_timestamp');
add_option("memberlite_update_info_timestamp", current_time('timestamp'), NULL, 'no');
}
return $update_info;
}
示例2: plugin_information
/**
* Sends and receives data to and from the server API
*
* @access public
* @since 1.0.0
* @return object $response
*/
public function plugin_information($args)
{
$target_url = $this->create_upgrade_api_url($args);
$apisslverify = get_option('mainwp_api_sslVerifyCertificate') === false || get_option('mainwp_api_sslVerifyCertificate') == 1 ? 1 : 0;
$request = wp_remote_get($target_url, array('timeout' => 50, 'sslverify' => $apisslverify));
// $request = wp_remote_post( MainWP_Api_Manager::instance()->getUpgradeUrl() . 'wc-api/upgrade-api/', array('body' => $args) );
if (is_wp_error($request) || wp_remote_retrieve_response_code($request) != 200) {
return false;
}
$response = unserialize(wp_remote_retrieve_body($request));
/**
* For debugging errors from the API
* For errors like: unserialize(): Error at offset 0 of 170 bytes
* Comment out $response above first
*/
// $response = wp_remote_retrieve_body( $request );
// print_r($response); exit;
if (is_object($response)) {
if (isset($response->package)) {
$response->package = apply_filters('mainwp_api_manager_upgrade_url', $response->package);
}
return $response;
} else {
return false;
}
}
示例3: _wprp_upgrade_plugin
/**
* Update a plugin
*
* @access private
* @param mixed $plugin
* @return array
*/
function _wprp_upgrade_plugin($plugin)
{
include_once ABSPATH . 'wp-admin/includes/admin.php';
if (!_wprp_supports_plugin_upgrade()) {
return array('status' => 'error', 'error' => 'WordPress version too old for plugin upgrades');
}
$skin = new WPRP_Plugin_Upgrader_Skin();
$upgrader = new Plugin_Upgrader($skin);
$is_active = is_plugin_active($plugin);
// Do the upgrade
ob_start();
$result = $upgrader->upgrade($plugin);
$data = ob_get_contents();
ob_clean();
if (!$result && !is_null($result) || $data) {
return array('status' => 'error', 'error' => 'file_permissions_error');
} elseif (is_wp_error($result)) {
return array('status' => 'error', 'error' => $result->get_error_code());
}
if ($skin->error) {
return array('status' => 'error', 'error' => $skin->error);
}
// If the plugin was activited, we have to re-activate it
// @todo Shouldn't this use activate_plugin?
if ($is_active) {
$current = get_option('active_plugins', array());
$current[] = plugin_basename(trim($plugin));
sort($current);
update_option('active_plugins', $current);
}
return array('status' => 'success');
}
示例4: after
function after()
{
if (empty($this->upgrader->result['destination_name'])) {
return;
}
$theme_info = $this->upgrader->theme_info();
if (empty($theme_info)) {
return;
}
$name = $theme_info['Name'];
$stylesheet = $this->upgrader->result['destination_name'];
$template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
$preview_link = htmlspecialchars(add_query_arg(array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => 1, 'TB_iframe' => 'true'), trailingslashit(esc_url(get_option('home')))));
$activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
$install_actions = array('preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>', 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr(sprintf(__('Activate “%s”'), $name)) . '">' . __('Activate') . '</a>');
if (is_network_admin() && current_user_can('manage_network_themes')) {
$install_actions['network_enable'] = '<a href="' . esc_url(wp_nonce_url('themes.php?action=enable&theme=' . $template, 'enable-theme_' . $template)) . '" title="' . esc_attr__('Enable this theme for all sites in this network') . '" target="_parent">' . __('Network Enable') . '</a>';
}
$install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('View Installed Themes', 'wp-app-store') . '</a>';
if (!$this->result || is_wp_error($this->result) || is_network_admin()) {
unset($install_actions['activate'], $install_actions['preview']);
}
$install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info);
if (!empty($install_actions)) {
$this->feedback(implode(' | ', (array) $install_actions));
}
}
示例5: run
/**
* Performs the actual image manipulation,
* including saving the target file.
*
* @param string $load_filename filepath (not URL) to source file
* (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
* @param string $save_filename filepath (not URL) where result file should be saved
* (ex: /src/var/www/wp-content/uploads/my-pic@2x.jpg)
* @return bool true if everything went fine, false otherwise
*/
function run($load_filename, $save_filename)
{
$image = wp_get_image_editor($load_filename);
if (!is_wp_error($image)) {
$current_size = $image->get_size();
$src_w = $current_size['width'];
$src_h = $current_size['height'];
// Get ratios
$w = $src_w * $this->factor;
$h = $src_h * $this->factor;
$image->crop(0, 0, $src_w, $src_h, $w, $h);
$result = $image->save($save_filename);
if (is_wp_error($result)) {
error_log('Error resizing image');
error_log(print_r($result, true));
return false;
} else {
return true;
}
} else {
if (isset($image->error_data['error_loading_image'])) {
TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']);
} else {
TimberHelper::error_log($image);
}
}
return false;
}
示例6: woo_vl_news_widget
function woo_vl_news_widget()
{
include_once ABSPATH . WPINC . '/feed.php';
// Get the RSS feed for WooCommerce Plugins
$rss = fetch_feed('http://www.visser.com.au/blog/category/woocommerce/feed/');
$output = '<div class="rss-widget">';
if (!is_wp_error($rss)) {
$maxitems = $rss->get_item_quantity(5);
$rss_items = $rss->get_items(0, $maxitems);
$output .= '<ul>';
foreach ($rss_items as $item) {
$output .= '<li>';
$output .= '<a href="' . $item->get_permalink() . '" title="' . 'Posted ' . $item->get_date('j F Y | g:i a') . '" class="rsswidget">' . $item->get_title() . '</a>';
$output .= '<span class="rss-date">' . $item->get_date('j F, Y') . '</span>';
$output .= '<div class="rssSummary">' . $item->get_description() . '</div>';
$output .= '</li>';
}
$output .= '</ul>';
} else {
$message = __('Connection failed. Please check your network settings.', 'woocommerce-exporter');
$output .= '<p>' . $message . '</p>';
}
$output .= '</div>';
echo $output;
}
示例7: run_backfill
function run_backfill($site_id)
{
$backend_upgrade = $this->ext->get_option('livefyre_backend_upgrade', 'not_started');
if ($backend_upgrade == 'not_started') {
# Need to upgrade the backend for this plugin. It's never been done for this site.
# Since this only happens once, notify the user and then run it.
$url = LFAPPS_Comments_Core::$quill_url . '/import/wordpress/' . $site_id . '/upgrade';
$http = new LFAPPS_Http_Extension();
$resp = $http->request($url, array('timeout' => 10));
if (is_wp_error($resp)) {
update_option('livefyre_backend_upgrade', 'error');
update_option('livefyre_backend_msg', $resp->get_error_message());
return;
}
$resp_code = $resp['response']['code'];
$resp_message = $resp['response']['message'];
if ($resp_code != '200') {
update_option('livefyre_backend_upgrade', 'error');
$this->lf_core->Raven->captureMessage("Backfill error for site " . $site_id . ": " . $resp->get_error_message());
return;
}
$json_data = json_decode($resp['body']);
$backfill_status = $json_data->status;
$backfill_msg = $json_data->msg;
if ($backfill_status == 'success') {
$backfill_msg = 'Request for Comments 2 upgrade has been sent';
}
update_option('livefyre_backend_upgrade', $backfill_status);
update_option('livefyre_backend_msg', $backfill_msg);
}
}
示例8: __construct
/**
* @param WP_Post|WP_User|object $object
*/
public function __construct($object)
{
if (!function_exists('get_editable_roles')) {
require_once ABSPATH . '/wp-admin/includes/user.php';
}
$this->object = $object;
if (is_a($object, 'WP_Post')) {
$this->id = $object->ID;
$this->type = $object->post_type;
$this->meta_type = 'post';
} elseif (is_a($object, 'WP_User')) {
$this->id = $object->ID;
$this->type = $object->roles[0];
$this->meta_type = 'user';
} elseif (isset($object->term_id)) {
$this->id = $object->term_id;
$this->type = $object->taxonomy;
$this->meta_type = 'term';
} elseif (empty($object) || is_wp_error($object)) {
$this->id = null;
$this->type = null;
$this->meta_type = null;
} else {
throw new Exception(sprintf('Invalid $object type error. $object is "%s".', get_class($object)));
}
}
示例9: activate
protected function activate()
{
foreach ($this->plugins as $plugin) {
if (!$this->network_wide && Jetpack::is_plugin_active($plugin) || is_plugin_active_for_network($plugin)) {
$this->log[$plugin]['error'] = __('The Plugin is already active.', 'jetpack');
$has_errors = true;
continue;
}
if (!$this->network_wide && is_network_only_plugin($plugin) && is_multisite()) {
$this->log[$plugin]['error'] = __('Plugin can only be Network Activated', 'jetpack');
$has_errors = true;
continue;
}
$result = activate_plugin($plugin, '', $this->network_wide);
if (is_wp_error($result)) {
$this->log[$plugin]['error'] = $result->get_error_messages();
$has_errors = true;
continue;
}
$success = Jetpack::is_plugin_active($plugin);
if ($success && $this->network_wide) {
$success &= is_plugin_active_for_network($plugin);
}
if (!$success) {
$this->log[$plugin]['error'] = $result->get_error_messages;
$has_errors = true;
continue;
}
$this->log[$plugin][] = __('Plugin activated.', 'jetpack');
}
if (!$this->bulk && isset($has_errors)) {
$plugin = $this->plugins[0];
return new WP_Error('activation_error', $this->log[$plugin]['error']);
}
}
示例10: create_data
function create_data()
{
$svg_file = find_file($this->paths['tempdir'], '.svg');
$return = array();
if (empty($svg_file)) {
zn_delete_folder($this->paths['tempdir']);
$return['message'] = 'The zip did not contained any svg files.';
}
$file_data = file_get_contents(trailingslashit($this->paths['tempdir']) . $svg_file);
if (!is_wp_error($file_data) && !empty($file_data)) {
$xml = simplexml_load_string($file_data);
$font_attr = $xml->defs->font->attributes();
$this->font_name = (string) $font_attr['id'];
$icon_list = array();
$glyphs = $xml->defs->font->children();
$class = '';
foreach ($glyphs as $item => $glyph) {
if ($item == 'glyph') {
$attributes = $glyph->attributes();
$unicode = (string) $attributes['unicode'];
$d = (string) $attributes['d'];
if ($class != 'hidden' && !empty($d)) {
$unicode_key = trim(json_encode($unicode), '\\\\"');
if ($item == 'glyph' && !empty($unicode_key) && trim($unicode_key) != '') {
$icon_list[$this->font_name][$unicode_key] = $unicode_key;
}
}
}
}
if (!empty($icon_list) && !empty($this->font_name)) {
$icon_list_file = fopen($this->paths['tempdir'] . '/icon_list.php', 'w');
if ($icon_list_file) {
fwrite($icon_list_file, '<?php $icons = array();');
foreach ($icon_list[$this->font_name] as $unicode) {
if (!empty($unicode)) {
$delimiter = "'";
if (strpos($unicode, "'") !== false) {
$delimiter = '"';
}
fwrite($icon_list_file, "\r\n" . '$icons[\'' . $this->font_name . '\'][' . $delimiter . $unicode . $delimiter . '] = ' . $delimiter . $unicode . $delimiter . ';');
}
}
fclose($icon_list_file);
} else {
zn_delete_folder($this->paths['tempdir']);
$return['message'] = 'There was a problem creating the icon list file';
return;
}
// RENAME ALL FILES SO WE CAN LOAD THEM BY FONT NAME
$this->rename_files();
// RENAME THE FOLDER WITH THE FONT NAME
$this->rename_folder();
// ADD FONT DATA TO FONT OPTION
$this->add_font_data();
}
} else {
$return['message'] = 'The svg file could not be opened.';
}
return $return;
}
示例11: rp_getstring_related_posts
function rp_getstring_related_posts($post, $args)
{
// args
$defaults = array('limit' => 3, 'title' => '', 'beforeposts' => '', 'afterposts' => '', 'eachpost' => '<li><a href="%permalink%">%title%</a></li>', 'noposts' => '');
$args = wp_parse_args($args, $defaults);
// no posts string
$noposts = '';
if (strlen($args['noposts']) > 0) {
$noposts = rp_replace_placeholders($post, $args['title']) . rp_replace_placeholders($post, $args['noposts']);
}
// get related posts
$relatedposts = rp_get_related_posts($post, $args['limit']);
if (is_wp_error($relatedposts) || !is_array($relatedposts)) {
return $noposts;
}
// print only if there are related posts
if (count($relatedposts) <= 0) {
return $noposts;
}
// the string
$string = '';
// print title and before
$string .= rp_replace_placeholders($post, $args['title']);
$string .= rp_replace_placeholders($post, $args['beforeposts']);
// print related posts
foreach ($relatedposts as $relatedpost) {
$string .= rp_replace_placeholders($relatedpost, $args['eachpost']);
}
// print after
$string .= rp_replace_placeholders($post, $args['afterposts']);
// return string
return $string;
}
示例12: wpcf_admin_image_settings_form_submit
/**
* Saves settings.
*
* @param type $form
*/
function wpcf_admin_image_settings_form_submit($form)
{
if (isset($_POST['clear-cache-images']) || isset($_POST['clear-cache-images-outdated'])) {
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/image.php';
$cache_dir = wpcf_fields_image_get_cache_directory(true);
if (is_wp_error($cache_dir)) {
wpcf_admin_message_store($cache_dir->get_error_message());
} else {
if (isset($_POST['clear-cache-images'])) {
wpcf_fields_image_clear_cache($cache_dir, 'all');
} else {
wpcf_fields_image_clear_cache($cache_dir);
}
wpcf_admin_message_store(__('Images cache cleared', 'wpcf'));
}
return true;
}
$settings = wpcf_get_settings();
$data = $_POST['wpcf_settings'];
foreach (array('add_resized_images_to_library', 'images_remote', 'images_remote_cache_time') as $setting) {
if (!isset($data[$setting])) {
$settings[$setting] = 0;
} else {
$settings[$setting] = $data[$setting];
}
}
update_option('wpcf_settings', $settings);
wpcf_admin_message_store(__('Settings saved', 'wpcf'));
}
示例13: createFile
function createFile($imgURL)
{
$remImgURL = urldecode($imgURL);
$urlParced = pathinfo($remImgURL);
$remImgURLFilename = $urlParced['basename'];
$imgData = wp_remote_get($remImgURL);
if (is_wp_error($imgData)) {
$badOut['Error'] = print_r($imgData, true) . " - ERROR";
return $badOut;
}
$imgData = $imgData['body'];
$tmp = array_search('uri', @array_flip(stream_get_meta_data($GLOBALS[mt_rand()] = tmpfile())));
if (!is_writable($tmp)) {
return "Your temporary folder or file (file - " . $tmp . ") is not witable. Can't upload images to Flickr";
}
rename($tmp, $tmp .= '.png');
register_shutdown_function(create_function('', "unlink('{$tmp}');"));
file_put_contents($tmp, $imgData);
if (!$tmp) {
return 'You must specify a path to a file';
}
if (!file_exists($tmp)) {
return 'File path specified does not exist';
}
if (!is_readable($tmp)) {
return 'File path specified is not readable';
}
// $data['name'] = basename($tmp);
return "@{$tmp}";
}
示例14: log
/**
* Writes a log message.
*
* Can extract a message from WP_Error object.
*
* @param string|WP_Error $msg Message to log.
*/
protected function log($msg)
{
if (is_wp_error($msg)) {
$msg = $msg->get_error_message();
}
WordPress_GitHub_Sync::write_log($msg);
}
示例15: get_suggestions
/**
* Returns an array of search suggestions from the unofficial completion API located
* at the endpoint specified in this class. &q=query
*
* Parses the output into an array of associative arrays with keys of term, volume and
* current. "current" is a boolean that determines whether the result in question is the searched
* for term.
*
* @return array|WP_Error WP_Error if something goes wrong. Otherwise, an array as described above.
*/
public static function get_suggestions($search_term)
{
$search_term = trim($search_term);
if (empty($search_term)) {
return new WP_Error('empty_term', __('Please provide a search term.', 'scribeseo'));
}
$response = wp_remote_get(add_query_arg(array('q' => urlencode($search_term)), self::ENDPOINT));
if (is_wp_error($response)) {
return $response;
}
$result = array();
// turn on user error handing
$user_errors = libxml_use_internal_errors(true);
$complete_suggestions = simplexml_load_string(wp_remote_retrieve_body($response));
// get any errors
$xml_errors = libxml_get_errors();
// restore error handling setting
libxml_use_internal_errors($user_errors);
if (!empty($xml_errors)) {
return new WP_Error('xml_error', __('The XML from the Google Completion API could not be loaded appropriately.', 'scribeseo'));
}
$complete_suggestions_po = json_decode(json_encode($complete_suggestions));
if (!is_object($complete_suggestions_po) || !isset($complete_suggestions_po->CompleteSuggestion)) {
return new WP_Error('xml_error', __('The XML from the Google Completion API could not be loaded appropriately.', 'scribeseo'));
}
foreach ($complete_suggestions_po->CompleteSuggestion as $suggestion) {
$term = $suggestion->suggestion->{'@attributes'}->data;
$volume = intval($suggestion->num_queries->{'@attributes'}->int);
$volume_nice = number_format_i18n($volume);
$current = $term == $search_term;
$result[] = compact('term', 'volume', 'volume_nice', 'current');
}
return $result;
}