WP_Error PHP Class Code Examples

This page contains top rated real world PHP examples of class WP_Error extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: class-vimeo-thumbnails.php Project: congtrieu112/anime
0
 public function get_thumbnail_url($id)
 {
     // Get our settings
     $client_id = isset($this) && isset($this->options['client_id']) && $this->options['client_id'] != '' ? $this->options['client_id'] : false;
     $client_secret = isset($this) && isset($this->options['client_secret']) && $this->options['client_secret'] != '' ? $this->options['client_secret'] : false;
     $access_token = isset($this) && isset($this->options['access_token']) && $this->options['access_token'] != '' ? $this->options['access_token'] : false;
     $access_token_secret = isset($this) && isset($this->options['access_token_secret']) && $this->options['access_token_secret'] != '' ? $this->options['access_token_secret'] : false;
     // If API credentials are entered, use the API
     if ($client_id && $client_secret && $access_token && $access_token_secret) {
         $vimeo = new phpVimeo($this->options['client_id'], $this->options['client_secret']);
         $vimeo->setToken($this->options['access_token'], $this->options['access_token_secret']);
         $response = $vimeo->call('vimeo.videos.getThumbnailUrls', array('video_id' => $id));
         $result = $response->thumbnails->thumbnail[count($response->thumbnails->thumbnail) - 1]->_content;
     } else {
         $request = "http://vimeo.com/api/oembed.json?url=http%3A//vimeo.com/{$id}";
         $response = wp_remote_get($request);
         if (is_wp_error($response)) {
             $result = $this->construct_info_retrieval_error($request, $response);
         } elseif ($response['response']['code'] == 404) {
             $result = new WP_Error('vimeo_info_retrieval', __('The Vimeo endpoint located at <a href="' . $request . '">' . $request . '</a> returned a 404 error.<br />Details: ' . $response['response']['message'], 'video-thumbnails'));
         } elseif ($response['response']['code'] == 403) {
             $result = new WP_Error('vimeo_info_retrieval', __('The Vimeo endpoint located at <a href="' . $request . '">' . $request . '</a> returned a 403 error.<br />This can occur when a video has embedding disabled or restricted to certain domains. Try entering API credentials in the provider settings.', 'video-thumbnails'));
         } else {
             $result = json_decode($response['body']);
             $result = $result->thumbnail_url;
         }
     }
     return $result;
 }
Example #2
Show file File: class.wp-taxonomy.php Project: danielcoats/schoolpress
0
 /**
  * Get all Term data from database by Term ID.
  *
  * The usage of the get_term function is to apply filters to a term object. It
  * is possible to get a term object from the database before applying the
  * filters.
  *
  * $term ID must be part of $taxonomy, to get from the database. Failure, might
  * be able to be captured by the hooks. Failure would be the same value as $this->db
  * returns for the get_row method.
  *
  * There are two hooks, one is specifically for each term, named 'get_term', and
  * the second is for the taxonomy name, 'term_$taxonomy'. Both hooks gets the
  * term object, and the taxonomy name as parameters. Both hooks are expected to
  * return a Term object.
  *
  * 'get_term' hook - Takes two parameters the term Object and the taxonomy name.
  * Must return term object. Used in get_term() as a catch-all filter for every
  * $term.
  *
  * 'get_$taxonomy' hook - Takes two parameters the term Object and the taxonomy
  * name. Must return term object. $taxonomy will be the taxonomy name, so for
  * example, if 'category', it would be 'get_category' as the filter name. Useful
  * for custom taxonomies or plugging into default taxonomies.
  *
  * @package WordPress
  * @subpackage Taxonomy
  * @since 2.3.0
  *
  * @uses $this->sanitize_term() Cleanses the term based on $filter context before returning.
  * @see $this->sanitize_term_field() The $context param lists the available values for get_term_by() $filter param.
  *
  * @param int|object $term If integer, will get from database. If object will apply filters and return $term.
  * @param string $taxonomy Taxonomy name that $term is part of.
  * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N
  * @param string $filter Optional, default is raw or no WordPress defined filter will applied.
  * @return mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not
  * exist then WP_Error will be returned.
  */
 function &get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw')
 {
     if (empty($term)) {
         $error = new WP_Error('invalid_term', __('Empty Term'));
         return $error;
     }
     if (!$this->is_taxonomy($taxonomy)) {
         $error = new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
         return $error;
     }
     if (is_object($term)) {
         wp_cache_add($term->term_id, $term, $taxonomy);
         wp_cache_add($term->term_taxonomy_id, $term->term_id, "{$taxonomy}:tt_id");
         $_term = $term;
     } else {
         $term = (int) $term;
         if (!($_term = wp_cache_get($term, $taxonomy))) {
             $_term = $this->db->get_row($this->db->prepare("SELECT t.*, tt.* FROM {$this->db->terms} AS t INNER JOIN {$this->db->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %s LIMIT 1", $taxonomy, $term));
             wp_cache_add($term, $_term, $taxonomy);
             wp_cache_add($_term->term_taxonomy_id, $_term->term_id, "{$taxonomy}:tt_id");
         }
     }
     $_term = apply_filters('get_term', $_term, $taxonomy);
     $_term = apply_filters("get_{$taxonomy}", $_term, $taxonomy);
     $_term = $this->sanitize_term($_term, $taxonomy, $filter);
     backpress_convert_object($_term, $output);
     return $_term;
 }
Example #3
Show file File: plugin-install.php Project: gigikiri/bcnAutoWallpaperSite
0
/**
 * 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
 * overridding 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 mixed
 */
function plugins_api($action, $args = null)
{
    if (is_array($args)) {
        $args = (object) $args;
    }
    if (!isset($args->per_page)) {
        $args->per_page = 24;
    }
    $args = apply_filters('plugins_api_args', $args, $action);
    //NOTE: Ensure that an object is returned via this filter.
    $res = apply_filters('plugins_api', false, $action, $args);
    //NOTE: Allows a plugin to completely override the builtin WordPress.org API.
    if (!$res) {
        $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array('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.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message());
        } else {
            $res = unserialize($request['body']);
            if (!$res) {
                $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']);
            }
        }
    } elseif (!is_wp_error($res)) {
        $res->external = true;
    }
    return apply_filters('plugins_api_result', $res, $action, $args);
}
Example #4
Show file File: class-wak-login-endpoint.php Project: YanikPei/wp-jwt-authentication
0
 /**
  * Generates token.
  *
  * Uses 'create_token' to create a token.
  *
  * @since 4.3.0
  *
  * @param string $request The rest-api request that contains all parameters.
  * @return array The token and expiration-timestamp
  */
 function action(WP_REST_Request $request)
 {
     $return = new WP_Error('400', __('Authentication failed.', 'wp_jwt_auth'));
     if (isset($request['method'])) {
         // if user wants to login by social-media-account
         $return = apply_filters('wak_login_method_' . $request['method'], $return, $request);
     } else {
         // if user wants to login by username/password
         $username = $request['username'];
         $password = $request['password'];
         $jwt_functions = new WAK_Functions();
         $user = get_user_by('login', $username);
         if ($user && wp_check_password($password, $user->data->user_pass, $user->ID)) {
             $return = $jwt_functions->create_token($user->ID);
         } else {
             $return = new WP_Error('credentials_invalid', __('Username/Password combination is invalid', 'wp_jwt_auth'));
         }
     }
     if (isset($request['set_wp_cookie']) && $request['set_wp_cookie'] == 'true' && !is_wp_error($return)) {
         wp_set_auth_cookie($return['userid'], true);
     }
     if (isset($request['redirect_to']) && !is_wp_error($return)) {
         $location = $request['redirect_to'];
         if (is_wp_error($return)) {
             $location .= '?error=true&msg=' . urlencode($return->get_error_message());
         }
         wp_redirect($location);
         exit;
         return;
     }
     return $return;
 }
Example #5
Show file File: theme.php Project: vivekkodira1/wordpress
0
/**
 * Retrieve theme installer pages from WordPress Themes API.
 *
 * It is possible for a theme to override the Themes API result with three
 * filters. Assume this is for themes, which can extend on the Theme Info to
 * offer more choices. This is very powerful and must be used with care, when
 * overridding the filters.
 *
 * The first filter, 'themes_api_args', is for the args and gives the action as
 * the second parameter. The hook for 'themes_api_args' must ensure that an
 * object is returned.
 *
 * The second filter, 'themes_api', is the result that would be returned.
 *
 * @since 2.8.0
 *
 * @param string $action
 * @param array|object $args Optional. Arguments to serialize for the Theme Info API.
 * @return mixed
 */
function themes_api($action, $args = null)
{
    if (is_array($args)) {
        $args = (object) $args;
    }
    if (!isset($args->per_page)) {
        $args->per_page = 24;
    }
    $args = apply_filters('themes_api_args', $args, $action);
    //NOTE: Ensure that an object is returned via this filter.
    $res = apply_filters('themes_api', false, $action, $args);
    //NOTE: Allows a theme to completely override the builtin WordPress.org API.
    if (!$res) {
        $request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array('body' => array('action' => $action, 'request' => serialize($args))));
        if (is_wp_error($request)) {
            $res = new WP_Error('themes_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message());
        } else {
            $res = unserialize(wp_remote_retrieve_body($request));
            if (!$res) {
                $res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body($request));
            }
        }
    }
    //var_dump(array($args, $res));
    return apply_filters('themes_api_result', $res, $action, $args);
}
Example #6
Show file File: class-wc-rest-authentication.php Project: jesusmarket/jesusmarket
0
 /**
  * Check that the API keys provided have the proper key-specific permissions to either read or write API resources.
  *
  * @param string $permissions
  * @return bool
  */
 private function check_permissions($permissions)
 {
     global $wc_rest_authentication_error;
     $valid = true;
     if (!isset($_SERVER['REQUEST_METHOD'])) {
         return false;
     }
     switch ($_SERVER['REQUEST_METHOD']) {
         case 'HEAD':
         case 'GET':
             if ('read' !== $permissions && 'read_write' !== $permissions) {
                 $wc_rest_authentication_error = new WP_Error('woocommerce_rest_authentication_error', __('The API key provided does not have read permissions.', 'woocommerce'), array('status' => 401));
                 $valid = false;
             }
             break;
         case 'POST':
         case 'PUT':
         case 'PATCH':
         case 'DELETE':
             if ('write' !== $permissions && 'read_write' !== $permissions) {
                 $wc_rest_authentication_error = new WP_Error('woocommerce_rest_authentication_error', __('The API key provided does not have write permissions.', 'woocommerce'), array('status' => 401));
                 $valid = false;
             }
             break;
     }
     return $valid;
 }
Example #7
Show file File: class-wc-subscriptions-manager.php Project: akshayxhtmljunkies/brownglock
0
 /**
  * Change a subscription's next payment date.
  *
  * @param mixed $new_payment_date Either a MySQL formatted Date/time string or a Unix timestamp.
  * @param string $subscription_key A subscription key of the form created by @see self::get_subscription_key()
  * @param int $user_id The id of the user who purchased the subscription
  * @param string $timezone Either 'server' or 'user' to describe the timezone of the $new_payment_date.
  * @since 1.2
  */
 public static function update_next_payment_date($new_payment_date, $subscription_key, $user_id = '', $timezone = 'server')
 {
     if (empty($user_id)) {
         $user_id = self::get_user_id_from_subscription_key($subscription_key);
     }
     $next_payment_timestamp = self::get_next_payment_date($subscription_key, $user_id, 'timestamp');
     $new_payment_timestamp = is_numeric($new_payment_date) ? $new_payment_date : strtotime($new_payment_date);
     // Use server time not user time
     if ('server' != $timezone) {
         $new_payment_timestamp = $new_payment_timestamp - get_option('gmt_offset') * 3600;
     }
     $expiration_timestamp = self::get_subscription_expiration_date($subscription_key, $user_id, 'timestamp');
     $trial_expiration_timestamp = self::get_trial_expiration_date($subscription_key, $user_id, 'timestamp');
     if (0 == $next_payment_timestamp) {
         $response = new WP_Error('invalid-date', __('This subscription does not have any future payments.', 'woocommerce-subscriptions'));
     } elseif ($new_payment_timestamp <= gmdate('U')) {
         $response = new WP_Error('invalid-date', __('Please enter a date in the future.', 'woocommerce-subscriptions'));
     } elseif (0 != $trial_expiration_timestamp && $new_payment_timestamp <= $trial_expiration_timestamp) {
         $response = new WP_Error('invalid-date', sprintf(__('Please enter a date after the trial period ends (%s).', 'woocommerce-subscriptions'), date_i18n(woocommerce_date_format(), $trial_expiration_timestamp + get_option('gmt_offset') * 3600)));
     } elseif (0 != $expiration_timestamp && $new_payment_timestamp >= $expiration_timestamp) {
         $response = new WP_Error('invalid-date', __('Please enter a date before the expiration date.', 'woocommerce-subscriptions'));
     } elseif (self::set_next_payment_date($subscription_key, $user_id, $new_payment_timestamp)) {
         self::update_wp_cron_lock($subscription_key, $new_payment_timestamp - gmdate('U'), $user_id);
         $response = $new_payment_timestamp;
     } else {
         $response = new WP_Error('misc-error', __('The payment date could not be changed.', 'woocommerce-subscriptions'));
     }
     return $response;
 }
Example #8
Show file File: plugin-install.php Project: pankajsinghjarial/SYLC-AMERICAN
0
/**
 * 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 error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.'), $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 unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.'), wp_remote_retrieve_body($request));
            }
        }
    } elseif (!is_wp_error($res)) {
        $res->external = true;
    }
    return apply_filters('plugins_api_result', $res, $action, $args);
}
Example #9
Show file File: class-miniorange-2-factor-pass2fa-login.php Project: sekane81/ratoninquietoweb
0
 function mo2f_pass2login_mobile_verification($user)
 {
     $useragent = $_SERVER['HTTP_USER_AGENT'];
     if (strpos($useragent, 'Mobi') !== false) {
         unset($_SESSION['mo2f-login-qrCode']);
         unset($_SESSION['mo2f-login-transactionId']);
         $_SESSION['mo2f-login-message'] = 'Please enter the one time passcode shown in the miniOrange Authenticator app.';
         $_SESSION['mo_2factor_login_status'] = 'MO_2_FACTOR_CHALLENGE_SOFT_TOKEN';
     } else {
         $challengeMobile = new Customer_Setup();
         $content = $challengeMobile->send_otp_token(get_user_meta($user->ID, 'mo_2factor_map_id_with_email', true), 'MOBILE AUTHENTICATION', get_option('mo2f_customerKey'), get_option('mo2f_api_key'));
         $response = json_decode($content, true);
         if (json_last_error() == JSON_ERROR_NONE) {
             /* Generate Qr code */
             if ($response['status'] == 'SUCCESS') {
                 $_SESSION['mo2f-login-qrCode'] = $response['qrCode'];
                 $_SESSION['mo2f-login-transactionId'] = $response['txId'];
                 $_SESSION['mo_2factor_login_status'] = 'MO_2_FACTOR_CHALLENGE_MOBILE_AUTHENTICATION';
             } else {
                 if ($response['status'] == 'ERROR') {
                     $this->remove_current_activity();
                     $error = new WP_Error();
                     $error->add('empty_username', __('<strong>ERROR</strong>: An error occured while processing your request. Please Try again.'));
                     return $error;
                 }
             }
         } else {
             $this->remove_current_activity();
             $error = new WP_Error();
             $error->add('empty_username', __('<strong>ERROR</strong>: An error occured while processing your request. Please Try again.'));
             return $error;
         }
     }
 }
Example #10
Show file File: layerslider.php Project: sebfabiani/vcv
0
function layerslider_plugin_api_call($def, $action, $args)
{
    // Get WP version
    global $wp_version;
    // Get purchase code
    $code = get_option('layerslider-purchase-code', '');
    if (!isset($args->slug) || $args->slug != $GLOBALS['lsPluginSlug']) {
        return false;
    }
    // Get the current version
    $plugin_info = get_site_transient('update_plugins');
    $current_version = $plugin_info->checked[$GLOBALS['lsPluginSlug'] . '/' . strtolower($GLOBALS['lsPluginSlug']) . '.php'];
    $args->version = $current_version;
    $request_string = array('body' => array('action' => $action, 'code' => $code, 'request' => serialize($args), 'api-key' => md5(get_bloginfo('url'))), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'));
    $request = wp_remote_post($GLOBALS['lsRepoAPI'], $request_string);
    if (is_wp_error($request)) {
        $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>', 'LayerSlider'), $request->get_error_message());
    } else {
        $res = unserialize($request['body']);
        if ($res === false) {
            $res = new WP_Error('plugins_api_failed', __('An unknown error occurred', 'LayerSlider'), $request['body']);
        }
    }
    return $res;
}
Example #11
Show file File: theme-install.php Project: gigikiri/bcnAutoWallpaperSite
0
/**
 * Retrieve theme installer pages from WordPress Themes API.
 *
 * It is possible for a theme to override the Themes API result with three
 * filters. Assume this is for themes, which can extend on the Theme Info to
 * offer more choices. This is very powerful and must be used with care, when
 * overridding the filters.
 *
 * The first filter, 'themes_api_args', is for the args and gives the action as
 * the second parameter. The hook for 'themes_api_args' must ensure that an
 * object is returned.
 *
 * The second filter, 'themes_api', is the result that would be returned.
 *
 * @since 2.8.0
 *
 * @param string $action
 * @param array|object $args Optional. Arguments to serialize for the Theme Info API.
 * @return mixed
 */
function themes_api($action, $args = null)
{
    if (is_array($args)) {
        $args = (object) $args;
    }
    if (!isset($args->per_page)) {
        $args->per_page = 24;
    }
    $args = apply_filters('themes_api_args', $args, $action);
    //NOTE: Ensure that an object is returned via this filter.
    $res = apply_filters('themes_api', false, $action, $args);
    //NOTE: Allows a theme to completely override the builtin WordPress.org API.
    if (!$res) {
        $request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array('body' => array('action' => $action, 'request' => serialize($args))));
        if (is_wp_error($request)) {
            $res = new WP_Error('themes_api_failed', __('An Unexpected HTTP Error occured during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message());
        } else {
            $res = unserialize($request['body']);
            if (!$res) {
                $res = new WP_Error('themes_api_failed', __('An unknown error occured'), $request['body']);
            }
        }
    }
    //var_dump(array($args, $res));
    return apply_filters('themes_api_result', $res, $action, $args);
}
Example #12
Show file File: theme.php Project: pankajsinghjarial/SYLC-AMERICAN
0
/**
 * Retrieve theme installer pages from WordPress Themes API.
 *
 * It is possible for a theme to override the Themes API result with three
 * filters. Assume this is for themes, which can extend on the Theme Info to
 * offer more choices. This is very powerful and must be used with care, when
 * overridding the filters.
 *
 * The first filter, 'themes_api_args', is for the args and gives the action as
 * the second parameter. The hook for 'themes_api_args' must ensure that an
 * object is returned.
 *
 * The second filter, 'themes_api', is the result that would be returned.
 *
 * @since 2.8.0
 *
 * @param string $action
 * @param array|object $args Optional. Arguments to serialize for the Theme Info API.
 * @return mixed
 */
function themes_api($action, $args = null)
{
    if (is_array($args)) {
        $args = (object) $args;
    }
    if (!isset($args->per_page)) {
        $args->per_page = 24;
    }
    $args = apply_filters('themes_api_args', $args, $action);
    //NOTE: Ensure that an object is returned via this filter.
    $res = apply_filters('themes_api', false, $action, $args);
    //NOTE: Allows a theme to completely override the builtin WordPress.org API.
    if (!$res) {
        $request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array('body' => array('action' => $action, 'request' => serialize($args))));
        if (is_wp_error($request)) {
            $res = new WP_Error('themes_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.'), $request->get_error_message());
        } else {
            $res = maybe_unserialize(wp_remote_retrieve_body($request));
            if (!is_object($res) && !is_array($res)) {
                $res = new WP_Error('themes_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.'), wp_remote_retrieve_body($request));
            }
        }
    }
    return apply_filters('themes_api_result', $res, $action, $args);
}
Example #13
Show file File: plugin-install.php Project: Esleelkartea/asociacion-tecnicos-artes-escenicas-ATAE-
0
/**
 * 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 = unserialize(wp_remote_retrieve_body($request));
            if (false === $res) {
                $res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body($request));
            }
        }
    } elseif (!is_wp_error($res)) {
        $res->external = true;
    }
    return apply_filters('plugins_api_result', $res, $action, $args);
}
Example #14
Show file File: widget-tweetscroll.php Project: vanbungkring/24custom
0
 function pi_tweetscroll_ajax()
 {
     session_start();
     require_once TS_PLUGIN_DIR . "/twitter/twitteroauth.php";
     //Path to twitteroauth library
     $current_instance_id = $_GET['instance_id'];
     $current_post_id = $_GET['post_id'];
     $instances_options = get_option('widget_pi_tweet_scroll');
     $widget_options = isset($instances_options[$current_instance_id]) ? $instances_options[$current_instance_id] : '';
     // filter widget options
     $widget_options = apply_filters('tweetscroll_widget_options', $widget_options, $current_instance_id, $current_post_id);
     $caching = $widget_options['caching'];
     // Generate key
     $key = 'tsw_' . $current_instance_id;
     // expires every hour
     $expiration = 60 * $caching;
     $transient = get_transient($key);
     if (base64_encode(base64_decode($transient, true)) === $transient) {
         $transient = base64_decode($transient);
         $transient = unserialize($transient);
     } else {
         delete_transient($key);
         $transient = false;
     }
     if (false === $transient) {
         $data = ts_get_user_data($widget_options);
         //if returned data is null, init error object
         if (empty($data) || isset($data->errors)) {
             $data = new WP_Error('api-error');
         }
         if (!is_wp_error($data)) {
             // Update transient
             ts_set_twitter_transient($key, $data, $expiration);
             $data = ts_convert_date_time_format($data);
             header('content-type: application/json');
             echo json_encode($data);
         } else {
             _e('Failed to retrieve tweets.');
         }
     } else {
         // Soft expiration. $transient = array( expiration time, data)
         if ($transient[0] !== 0 && (int) $transient[0] <= time()) {
             // Expiration time passed, attempt to get new data
             $new_data = ts_get_user_data($widget_options);
             // if returned data is null, init error object
             if (empty($new_data) || isset($new_data->errors)) {
                 $new_data = new WP_Error('api-error', __('Failed to retrieve tweets.'));
             }
             if (!is_wp_error($new_data)) {
                 // If successful return update transient and new data
                 ts_set_twitter_transient($key, $new_data, $expiration);
                 $transient[1] = $new_data;
             }
         }
         $transient[1] = ts_convert_date_time_format($transient[1]);
         header('content-type: application/json');
         echo json_encode($transient[1]);
     }
     exit;
 }
Example #15
Show file File: class-wc-subscriptions-manager.php Project: bulats/chef
0
 /**
  * Change a subscription's next payment date.
  *
  * @param $new_payment_date mixed Either a MySQL formatted Date/time string or a Unix timestamp.
  * @param $subscription_key string A subscription key of the form created by @see self::get_subscription_key()
  * @param $user_id int The id of the user who purchased the subscription
  * @param $timezone string Either 'server' or 'user' to describe the timezone of the $new_payment_date.
  * @since 1.2
  */
 public static function update_next_payment_date($new_payment_date, $subscription_key, $user_id = '', $timezone = 'server')
 {
     $next_payment_timestamp = self::get_next_payment_date($subscription_key, $user_id, 'timestamp');
     $new_payment_timestamp = is_numeric($new_payment_date) ? $new_payment_date : strtotime($new_payment_date);
     // Use server time not user time
     if ('server' != $timezone) {
         $new_payment_timestamp = $new_payment_timestamp - get_option('gmt_offset') * 3600;
     }
     $expiration_timestamp = self::get_subscription_expiration_date($subscription_key, $user_id, 'timestamp');
     $trial_expiration_timestamp = self::get_trial_expiration_date($subscription_key, $user_id, 'timestamp');
     if (0 == $next_payment_timestamp) {
         $response = new WP_Error('invalid-date', __('This subscription does not have any future payments.', WC_Subscriptions::$text_domain));
     } elseif ($new_payment_timestamp <= gmdate('U')) {
         $response = new WP_Error('invalid-date', __('Please enter a date in the future.', WC_Subscriptions::$text_domain));
     } elseif (0 != $trial_expiration_timestamp && $new_payment_timestamp <= $trial_expiration_timestamp) {
         $response = new WP_Error('invalid-date', sprintf(__('Please enter a date after the trial period ends (%s).', WC_Subscriptions::$text_domain), date_i18n(get_option('date_format'), $trial_expiration_timestamp + get_option('gmt_offset') * 3600)));
     } elseif (0 != $expiration_timestamp && $new_payment_timestamp >= $expiration_timestamp) {
         $response = new WP_Error('invalid-date', __('Please enter a date before the expiration date.', WC_Subscriptions::$text_domain));
     } elseif (self::set_next_payment_date($subscription_key, $user_id, $new_payment_timestamp)) {
         self::update_wp_cron_lock($subscription_key, $new_payment_timestamp - gmdate('U'), $user_id);
         $response = $new_payment_timestamp;
     } else {
         $response = new WP_Error('misc-error', __('The payment date could not be changed.', WC_Subscriptions::$text_domain));
     }
     return $response;
 }