/** * 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; }
function jellythemes_photos_list($atts, $content = null) { extract(shortcode_atts(array('limit' => 8), $atts)); $return = ' <nav class="primary"><ul> <li><a class="selected" href="#" data-filter="*"><span>' . __('All photos', 'jellythemes') . '</span></a></li>'; $types = get_terms('type', array('hide_empty' => 0)); if ($types && !is_wp_error($types)) { foreach ($types as $type) { $return .= '<li><a href="#" data-filter=".' . esc_js($type->slug) . '"><span>' . $type->name . '</span></a></li>'; } } $return .= '</ul></nav> <div class="portfolio">'; $photos = new WP_Query(array('post_type' => 'photo', 'posts_per_page' => esc_attr($limit))); while ($photos->have_posts()) { $photos->the_post(); $term_list = wp_get_post_terms(get_the_ID(), 'type', array("fields" => "names")); $images = rwmb_meta('_jellythemes_project_images', 'type=plupload_image', get_the_ID()); foreach ($images as $image) { $img = wp_get_attachment_image($image['ID'], 'full', false, array('class' => 'img-responsive')); $src = wp_get_attachment_image_src($image['ID'], 'full'); } $return .= '<article class="' . implode(' ', get_post_class('entry')) . '"> <a class="swipebox" href="' . $src[0] . '"> ' . $img . ' <span class="magnifier"></span> </a> </article>'; } $return .= '</div>'; return $return; }
/** * 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; } }
/** * Render the shortcode * @param array $args Shortcode paramters * @param string $content Content between shortcode * @return string HTML output */ function render($args, $content = '') { $defaults = Magee_Core::set_shortcode_defaults(array('url' => '', 'number' => 3, 'class' => '', 'id' => ''), $args); extract($defaults); self::$args = $defaults; $html = ''; //$html = '<h2>'._e( 'Recent news from Some-Other Blog:', 'my-text-domain' ).'<h2>'; if ($url !== '') { include_once ABSPATH . WPINC . '/feed.php'; $rss = fetch_feed(esc_url($url)); $maxitems = 0; if (!is_wp_error($rss)) { $maxitems = $rss->get_item_quantity(esc_attr($number)); $rss_items = $rss->get_items(0, $maxitems); } $html = '<ul class="' . esc_attr($class) . '" id="' . esc_attr($id) . '">'; if ($maxitems == 0) { $html .= '<li>' . _e('No items', 'magee-shortcodes') . '</li>'; } else { foreach ($rss_items as $item) { $html .= '<li>'; $html .= '<a target="_blank" href="' . esc_url($item->get_permalink()) . '" '; $html .= 'title="' . __('Posted ' . $item->get_date('j F Y | g:i a'), 'magee-shortcodes') . '">'; $html .= $item->get_title(); $html .= '</a>'; $html .= '</li>'; } } $html .= '</ul>'; } return $html; }
/** * 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'); }
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)); } }
/** * 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; }
function rcl_confirm_user_registration() { global $wpdb, $rcl_options; $reglogin = $_GET['rglogin']; $regpass = $_GET['rgpass']; $regcode = md5($reglogin); if ($regcode == $_GET['rgcode']) { if ($user = get_user_by('login', $reglogin)) { wp_update_user(array('ID' => $user->ID, 'role' => get_option('default_role'))); $time_action = current_time('mysql'); $action = $wpdb->get_var($wpdb->prepare("SELECT time_action FROM " . RCL_PREF . "user_action WHERE user = '******'", $user->ID)); if (!$action) { $wpdb->insert(RCL_PREF . 'user_action', array('user' => $user->ID, 'time_action' => $time_action)); } $creds = array(); $creds['user_login'] = $reglogin; $creds['user_password'] = $regpass; $creds['remember'] = true; $sign = wp_signon($creds, false); if (!is_wp_error($sign)) { rcl_update_timeaction_user(); do_action('rcl_confirm_registration', $user->ID); wp_redirect(rcl_get_authorize_url($user->ID)); exit; } } } if ($rcl_options['login_form_recall'] == 2) { wp_safe_redirect('wp-login.php?checkemail=confirm'); } else { wp_redirect(get_bloginfo('wpurl') . '?action-rcl=login&error=confirm'); } exit; }
/** * @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))); } }
/** * Add flat taxonomy term from "checklist" meta box on the Media Manager Modal Window * * Adapted from the WordPress post_categories_meta_box() in /wp-admin/includes/meta-boxes.php. * * @since 2.20 * * @param string The taxonomy name, from $_POST['action'] * * @return void Sends JSON response with updated HTML for the checklist */ private static function _mla_ajax_add_flat_term($key) { $taxonomy = get_taxonomy($key); check_ajax_referer($_POST['action'], '_ajax_nonce-add-' . $key, true); if (!current_user_can($taxonomy->cap->edit_terms)) { wp_die(-1); } $new_names = explode(',', $_POST['new' . $key]); $new_terms_markup = ''; foreach ($new_names as $name) { if ('' === sanitize_title($name)) { continue; } if (!($id = term_exists($name, $key))) { $id = wp_insert_term($name, $key); } if (is_wp_error($id)) { continue; } if (is_array($id)) { $id = absint($id['term_id']); } else { continue; } $term = get_term($id, $key); $name = $term->name; $new_terms_markup .= "<li id='{$key}-{$id}'><label class='selectit'><input value='{$name}' type='checkbox' name='tax_input[{$key}][]' id='in-{$key}-{$id}' checked='checked' />{$name}</label></li>\n"; } // foreach new_name $input_new_parent_name = "new{$key}_parent"; $supplemental = "<input type='hidden' name='{$input_new_parent_name}' id='{$input_new_parent_name}' value='-1' />"; $add = array('what' => $key, 'id' => $id, 'data' => $new_terms_markup, 'position' => -1, 'supplemental' => array('newcat_parent' => $supplemental)); $x = new WP_Ajax_Response($add); $x->send(); }
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; }
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; }
/** * 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')); }
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}"; }
/** * 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); }
/** * 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; }
function callback($path = '', $blog_id = 0) { $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; } //upload_files can probably be used for other endpoints but we want contributors to be able to use media too if (!current_user_can('edit_posts')) { return new WP_Error('unauthorized', 'User cannot view media', 403); } $args = $this->query_args(); if ($args['number'] < 1) { $args['number'] = 20; } elseif (100 < $args['number']) { return new WP_Error('invalid_number', 'The NUMBER parameter must be less than or equal to 100.', 400); } $media = get_posts(array('post_type' => 'attachment', 'post_parent' => $args['parent_id'], 'offset' => $args['offset'], 'numberposts' => $args['number'], 'post_mime_type' => $args['mime_type'])); $response = array(); foreach ($media as $item) { $response[] = $this->get_media_item($item->ID); } $_num = (array) wp_count_attachments(); $_total_media = array_sum($_num) - $_num['trash']; $return = array('found' => $_total_media, 'media' => $response); return $return; }
/** * Checks one or more comments against the Akismet API. * * ## OPTIONS * <comment_id>... * : The ID(s) of the comment(s) to check. * * [--noaction] * : Don't change the status of the comment. Just report what Akismet thinks it is. * * ## EXAMPLES * * wp akismet check 12345 * * @alias comment-check */ public function check($args, $assoc_args) { foreach ($args as $comment_id) { if (isset($assoc_args['noaction'])) { // Check the comment, but don't reclassify it. $api_response = Akismet::check_db_comment($comment_id, 'wp-cli'); } else { $api_response = Akismet::recheck_comment($comment_id, 'wp-cli'); } if ('true' === $api_response) { WP_CLI::line(sprintf(__("Comment #%d is spam.", 'akismet'), $comment_id)); } else { if ('false' === $api_response) { WP_CLI::line(sprintf(__("Comment #%d is not spam.", 'akismet'), $comment_id)); } else { if (false === $api_response) { WP_CLI::error(__("Failed to connect to Akismet.", 'akismet')); } else { if (is_wp_error($api_response)) { WP_CLI::warning(sprintf(__("Comment #%d could not be checked.", 'akismet'), $comment_id)); } } } } } }
public function do_affiliates($step = 1) { global $wpdb; $offset = ($step - 1) * 100; $affiliates = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}affiliates_tbl LIMIT {$offset}, 100;"); $to_delete = array(); if ($affiliates) { foreach ($affiliates as $affiliate) { if (empty($affiliate->email)) { continue; } $user = get_user_by('email', $affiliate->email); if (is_wp_error($user) || !$user) { $user_id = wp_insert_user(array('user_email' => $affiliate->email, 'first_name' => $affiliate->firstname, 'last_name' => $affiliate->lastname, 'user_url' => $affiliate->website, 'user_pass' => '', 'user_login' => $affiliate->email)); } else { $user_id = $user->ID; } $payment_email = !empty($affiliate->paypalemail) ? $affiliate->paypalemail : $affiliate->email; $status = 'approved' == $affiliate->account_status ? 'active' : 'pending'; $args = array('date_registered' => date('Y-n-d H:i:s', strtotime($affiliate->date)), 'user_id' => $user_id, 'payment_email' => $payment_email, 'rate' => $affiliate->commissionlevel, 'status' => $status); // Try to get an existing affiliate based on the user_id $existing_affiliate = affiliate_wp()->affiliates->get_by('user_id', $user_id); if ($existing_affiliate) { continue; } // Insert a new affiliate - we need to always insert to make sure the affiliate_ids will match $id = affiliate_wp()->affiliates->insert($args, 'affiliate'); } return true; } else { // No affiliates found, so all done return false; } }
function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) { $this->url = $url; $this->timeout = $timeout; $this->redirects = $redirects; $this->headers = $headers; $this->useragent = $useragent; $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE; if (preg_match('/^http(s)?:\\/\\//i', $url)) { $args = array('timeout' => $this->timeout, 'redirection' => $this->redirects, 'reject_unsafe_urls' => true); if (!empty($this->headers)) { $args['headers'] = $this->headers; } if (SIMPLEPIE_USERAGENT != $this->useragent) { //Use default WP user agent unless custom has been specified $args['user-agent'] = $this->useragent; } $res = wp_remote_request($url, $args); if (is_wp_error($res)) { $this->error = 'WP HTTP Error: ' . $res->get_error_message(); $this->success = false; } else { $this->headers = wp_remote_retrieve_headers($res); $this->body = wp_remote_retrieve_body($res); $this->status_code = wp_remote_retrieve_response_code($res); } } else { $this->error = ''; $this->success = false; } }
public function subscribe_if_not_subscribed() { global $bc_accounts; $accounts = $bc_accounts->get_sanitized_all_accounts(); $completed_accounts = array(); foreach ($accounts as $account => $account_data) { // We may have multiple accounts for an account_id, prevent syncing that account more than once. if (!in_array($account_data['account_id'], $completed_accounts)) { $completed_accounts[] = $account_data['account_id']; $bc_accounts->set_current_account($account); $subscriptions = $this->cms_api->get_subscriptions(); if (is_array($subscriptions)) { foreach ($subscriptions as $subscription) { if ($bc_accounts->get_account_id() === $subscription['service_account'] && isset($subscription['id']) && false !== strpos($subscription['endpoint'], get_admin_url())) { $this->cms_api->remove_subscription($subscription['id']); } } } $subscription_status = $this->cms_api->add_subscription(); if (is_wp_error($subscription_status)) { $bc_accounts->restore_default_account(); return false; } if (isset($subscription_status['id']) && $subscription_status['service_account'] === $bc_accounts->get_account_id()) { $subscription_id = BC_Utility::sanitize_subscription_id($subscription_status['id']); update_option($this->get_option_key_for($bc_accounts->get_account_id()), $subscription_id); } $bc_accounts->restore_default_account(); } } }
public function __construct($sURL, $iTimeout = 10, $iRedirects = 5, $aHeaders = null, $sUserAgent = null, $bForceFsockOpen = false) { $this->timeout = $iTimeout; $this->redirects = $iRedirects; $this->headers = $sUserAgent; $this->useragent = $sUserAgent; $this->url = $sURL; // If the scheme is not http or https. if (!preg_match('/^http(s)?:\\/\\//i', $sURL)) { $this->error = ''; $this->success = false; return; } // Arguments $aArgs = array('timeout' => $this->timeout, 'redirection' => $this->redirects, true, 'sslverify' => false); if (!empty($this->headers)) { $aArgs['headers'] = $this->headers; } if (SIMPLEPIE_USERAGENT != $this->useragent) { $aArgs['user-agent'] = $this->useragent; } // Request $res = function_exists('wp_safe_remote_request') ? wp_safe_remote_request($sURL, $aArgs) : wp_remote_get($sURL, $aArgs); if (is_wp_error($res)) { $this->error = 'WP HTTP Error: ' . $res->get_error_message(); $this->success = false; return; } $this->headers = wp_remote_retrieve_headers($res); $this->body = wp_remote_retrieve_body($res); $this->status_code = wp_remote_retrieve_response_code($res); }
/** * Geocode an address using http * * @param mixed $auto true = automatically update the poi, false = return raw geocoding results * @return true if auto=true and success | WP_Error on failure */ function geocode($auto = true) { if (!class_exists('Mappress_Pro')) { return new WP_Error('geocode', 'MapPress Pro required for geocoding', 'mappress'); } // If point has a lat/lng then no geocoding if (!empty($this->point['lat']) && !empty($this->point['lng'])) { if ($this->address) { $this->correctedAddress = $this->address; } $this->viewport = null; } else { $location = Mappress::$geocoders->geocode($this->address); if (is_wp_error($location)) { return $location; } $this->point = array('lat' => $location->lat, 'lng' => $location->lng); $this->correctedAddress = $location->corrected_address; $this->viewport = $location->viewport; } // Guess a default title / body - use address if available or lat, lng if not if (empty($this->title) && empty($this->body)) { if ($this->correctedAddress) { $parsed = Mappress::$geocoders->parse_address($this->correctedAddress); $this->title = $parsed[0]; $this->body = isset($parsed[1]) ? $parsed[1] : ""; } else { $this->title = $this->point['lat'] . ',' . $this->point['lng']; } } }
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); } }
/** * 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; }
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; }
/** * Test whether force rewrite should be enabled or not. */ function wpseo_title_test() { $options = get_option('wpseo_titles'); $options['forcerewritetitle'] = false; $options['title_test'] = 1; update_option('wpseo_titles', $options); // Setting title_test to > 0 forces the plugin to output the title below through a filter in class-frontend.php. $expected_title = 'This is a Yoast Test Title'; WPSEO_Utils::clear_cache(); $args = array('user-agent' => sprintf('WordPress/%1$s; %2$s - Yoast', $GLOBALS['wp_version'], get_site_url())); $resp = wp_remote_get(get_bloginfo('url'), $args); if ($resp && !is_wp_error($resp) && (200 == $resp['response']['code'] && isset($resp['body']))) { $res = preg_match('`<title>([^<]+)</title>`im', $resp['body'], $matches); if ($res && strcmp($matches[1], $expected_title) !== 0) { $options['forcerewritetitle'] = true; $resp = wp_remote_get(get_bloginfo('url'), $args); $res = false; if ($resp && !is_wp_error($resp) && (200 == $resp['response']['code'] && isset($resp['body']))) { $res = preg_match('`/<title>([^>]+)</title>`im', $resp['body'], $matches); } } if (!$res || $matches[1] != $expected_title) { $options['forcerewritetitle'] = false; } } else { // If that dies, let's make sure the titles are correct and force the output. $options['forcerewritetitle'] = true; } $options['title_test'] = 0; update_option('wpseo_titles', $options); }
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']); } }
protected function get_values() { $terms = array(); // Load all available event categories $source = get_terms(TribeEvents::TAXONOMY, array('orderby' => 'name', 'order' => 'ASC')); if (empty($source) || is_wp_error($source)) { return array(); } // Preprocess the terms foreach ($source as $term) { $terms[(int) $term->term_id] = $term; $term->parent = (int) $term->parent; $term->depth = 0; $term->children = array(); } // Initally copy the source list of terms to our ordered list $ordered_terms = $terms; // Re-order! foreach ($terms as $id => $term) { // Skip root elements if (0 === $term->parent) { continue; } // Reposition child terms within the ordered terms list unset($ordered_terms[$id]); $term->depth = $terms[$term->parent]->depth + 1; $terms[$term->parent]->children[$id] = $term; } // Finally flatten out and return return $this->flattened_term_list($ordered_terms); }
/** * Creates a cropped version of an image for a given attachment ID. * * @param int $attachment_id The attachment for which to generate a cropped image. * @param int $width The width of the cropped image in pixels. * @param int $height The height of the cropped image in pixels. * @param bool $crop Whether to crop the generated image. * @return string The full path to the cropped image. Empty if failed. */ private function _generate_attachment($attachment_id = 0, $width = 0, $height = 0, $crop = true) { $attachment_id = (int) $attachment_id; $width = (int) $width; $height = (int) $height; $crop = (bool) $crop; $original_path = get_attached_file($attachment_id); // fix a WP bug up to 2.9.2 if (!function_exists('wp_load_image')) { require_once ABSPATH . 'wp-admin/includes/image.php'; } $resized_path = @new_image_resize($original_path, $width, $height, $crop); if (!is_wp_error($resized_path) && !is_array($resized_path)) { return $resized_path; // perhaps this image already exists. If so, return it. } else { $orig_info = pathinfo($original_path); $suffix = "{$width}x{$height}"; $dir = $orig_info['dirname']; $ext = $orig_info['extension']; $name = basename($original_path, ".{$ext}"); $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}"; if (file_exists($destfilename)) { return $destfilename; } } return ''; }