public static function remote_request($args)
 {
     $name = x_addons_get_api_key_option_name();
     $api_key = esc_attr(get_option($name));
     if ($api_key == '') {
         $api_key = 'unverified';
     }
     $args = wp_parse_args($args, array('action' => 'autoupdates', 'api-key' => $api_key, 'siteurl' => preg_replace('#(https?:)?//#', '', esc_attr(untrailingslashit(network_home_url()))), 'xversion' => X_VERSION));
     $request_url = self::$base_url . trailingslashit($args['action']) . trailingslashit($args['api-key']);
     unset($args['action']);
     unset($args['api-key']);
     $uri = add_query_arg($args, $request_url);
     $request = wp_remote_get($uri, array('timeout' => 15));
     $connection_error = array('code' => 4, 'message' => __('Could not establish connection. For assistance, please start by reviewing our article on troubleshooting <a href="https://community.theme.co/kb/connection-issues/">connection issues.</a>', '__x__'));
     if (is_wp_error($request) || $request['response']['code'] != 200) {
         self::store_error($request);
         return $connection_error;
     }
     $data = json_decode($request['body'], true);
     if (!isset($data['code'])) {
         return $connection_error;
     }
     //
     // Key was good but is now invalid (revoked).
     //
     if ($api_key != '' && $data['code'] == 3) {
         delete_option($name);
         delete_site_option('x_addon_list_cache');
     }
     return $data;
 }
 public static function setRulesFilters()
 {
     $home_url = parse_url(is_multisite() ? network_home_url('/') : home_url('/'));
     extract($home_url);
     self::$rules_filters = ['www\\.example\\.com' => preg_quote($host), 'www.example.com/' => $host . $path, 'www.example.com' => $host, '/wordpress' => parse_url(site_url(), PHP_URL_PATH)];
     self::$rules_filters = apply_filters('roots/h5bp-htaccess-filters', self::$rules_filters);
 }
Example #3
0
 function is_multisite_root()
 {
     if (is_multisite()) {
         return trailingslashit(get_home_url()) === trailingslashit(network_home_url()) ? true : false;
     }
     return true;
 }
 function global_home_url($path = '', $scheme = null)
 {
     if (!is_multinetwork()) {
         return network_home_url($path, $scheme);
     }
     $main_site_id = get_main_network_id();
     $main_site = get_network($main_site_id);
     $orig_scheme = $scheme;
     if (!in_array($scheme, array('http', 'https', 'relative'))) {
         $scheme = is_ssl() && !is_admin() ? 'https' : 'http';
     }
     if ('relative' == $scheme) {
         $url = $main_site->path;
     } else {
         $url = set_url_scheme('http://' . $main_site->domain . $main_site->path, $scheme);
     }
     if ($path && is_string($path)) {
         $url .= ltrim($path, '/');
     }
     /**
      * Filters the global home URL.
      *
      * @since 1.0.0
      *
      * @param string      $url         The complete global home URL including scheme and path.
      * @param string      $path        Path relative to the global home URL. Blank string
      *                                 if no path is specified.
      * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https',
      *                                 'relative' or null.
      */
     return apply_filters('global_home_url', $url, $path, $orig_scheme);
 }
 function filter_body_class($classes = array())
 {
     $return = $classes;
     $site_id = 0;
     $site_url = network_site_url();
     $home_url = network_home_url();
     if (is_multisite()) {
         $site_id = get_current_blog_id();
     }
     if (!empty($site_id)) {
         $arrReturn = 'site-id-' . $site_id;
     }
     if ($site_url != $home_url) {
         $arrReturn[] = 'site-url-' . $this->sanitize_url_class($site_url);
         $arrReturn[] = 'home-url-' . $this->sanitize_url_class($home_url);
     } else {
         $arrReturn[] = $this->sanitize_url_class($site_url);
     }
     if (!empty($arrReturn)) {
         if (!empty($classes)) {
             $return = array_unique($arrReturn + $classes);
         } else {
             $return = $arrReturn;
         }
     }
     return $return;
 }
Example #6
0
 function set_site_host()
 {
     $host = network_home_url();
     $host = parse_url($host);
     $host = $host['host'];
     $host = apply_filters('vp_seo_hide_site_host', $host);
     $this->site_host = $host;
 }
Example #7
0
/**
 * Return the URL of the site
 *
 * @since 2.5.0
 *
 * @return string Site URL.
 */
function wxr_site_url()
{
    // ms: the base url
    if (is_multisite()) {
        return network_home_url();
    } else {
        return get_site_url();
    }
}
/**
 * Return the URL of the site
 *
 * @since 2.5.0
 *
 * @return string Site URL.
 */
function wcli_wxr_site_url()
{
    // ms: the base url
    if (is_multisite()) {
        return network_home_url();
    } else {
        return get_bloginfo_rss('url');
    }
}
/**
 * Return the URL of the site
 *
 * @since 2.5.0
 *
 * @return string Site URL.
 */
function wxr_site_url()
{
    // Multisite: the base URL.
    if (is_multisite()) {
        return network_home_url();
    } else {
        return get_bloginfo_rss('url');
    }
}
 /**
  * The Constructor function adds the function that pushes published posts to the list, as well as registers the widget.
  */
 function __construct()
 {
     load_plugin_textdomain('hrpn', false, dirname(plugin_basename(__FILE__)) . '/languages');
     add_action('publish_post', array($this, 'Add_Post_To_H1_Recent_Posts_From_Network'));
     add_action('widgets_init', array($this, 'Register_H1_Recent_Posts_From_Network_Widget'));
     $first_post = get_site_option('first_post');
     $first_post = str_replace("SITE_URL", esc_url(network_home_url()), $first_post);
     $first_post = str_replace("SITE_NAME", get_current_site()->site_name, $first_post);
     $this->first_post = $first_post;
 }
 /**
  * @param Delicious_Brains_API_Plugin $plugin
  */
 function __construct(Delicious_Brains_API_Plugin $plugin)
 {
     $this->plugin = $plugin;
     $home_url = home_url('', 'http');
     if ($this->plugin->is_network_activated) {
         // Make sure always use the network URL in API communication
         $home_url = network_home_url('', 'http');
     }
     $this->home_url = untrailingslashit($home_url);
     parent::__construct();
 }
function get_absolute_file_url($url)
{
    if (is_multisite()) {
        global $blog_id;
        $upload_dir = wp_upload_dir();
        if (strpos($upload_dir['basedir'], 'blogs.dir') !== false) {
            $parts = explode('/files/', $url);
            $url = network_home_url() . '/wp-content/blogs.dir/' . $blog_id . '/files/' . $parts[1];
        }
    }
    return $url;
}
Example #13
0
function edd_w3edge_w3tc_reset_rooturi($license, $version)
{
    // data to send in our API request
    $api_params = array('edd_action' => 'reset_rooturi', 'license_key' => $license, 'home_url' => network_home_url(), 'item_name' => urlencode(EDD_W3EDGE_W3TC_NAME), 'r' => rand(), 'version' => $version);
    // Call the custom API.
    $response = wp_remote_get(add_query_arg($api_params, EDD_W3EDGE_STORE_URL), array('timeout' => 15, 'sslverify' => false));
    if (is_wp_error($response)) {
        return false;
    }
    // decode the license data
    $status = json_decode(wp_remote_retrieve_body($response));
    return $status;
}
Example #14
0
function get_blogaddress_by_name( $blogname ) {
	global $current_site;

	if ( is_subdomain_install() ) {
		if ( $blogname == 'main' )
			$blogname = 'www';
		$url = rtrim( network_home_url(), '/' );
		if ( !empty( $blogname ) )
			$url = preg_replace( '|^([^\.]+://)|', '$1' . $blogname . '.', $url );
	} else {
		$url = network_home_url( $blogname );
	}
	return esc_url( $url . '/' );
}
Example #15
0
/**
 * Get a full blog URL, given a blog name.
 *
 * @since MU
 *
 * @param string $blogname The (subdomain or directory) name
 * @return string
 */
function get_blogaddress_by_name($blogname)
{
    if (is_subdomain_install()) {
        if ($blogname == 'main') {
            $blogname = 'www';
        }
        $url = rtrim(network_home_url(), '/');
        if (!empty($blogname)) {
            $url = preg_replace('|^([^\\.]+://)|', "\${1}" . $blogname . '.', $url);
        }
    } else {
        $url = network_home_url($blogname);
    }
    return esc_url($url . '/');
}
Example #16
0
 public function go_to($url)
 {
     $GLOBALS['_SERVER']['REQUEST_URI'] = $url = str_replace(network_home_url(), '', $url);
     $_GET = $_POST = array();
     foreach (array('query_string', 'id', 'postdata', 'authordata', 'day', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages', 'pagenow') as $v) {
         if (isset($GLOBALS[$v])) {
             unset($GLOBALS[$v]);
         }
     }
     $parts = parse_url($url);
     if (isset($parts['scheme'])) {
         $req = $parts['path'];
         if (isset($parts['query'])) {
             $req .= '?' . $parts['query'];
             parse_str($parts['query'], $_GET);
         }
     } else {
         $req = $url;
     }
     if (!isset($parts['query'])) {
         $parts['query'] = '';
     }
     // Scheme
     if (0 === strpos($req, '/wp-admin') && force_ssl_admin()) {
         $_SERVER['HTTPS'] = 'on';
     } else {
         unset($_SERVER['HTTPS']);
     }
     $_SERVER['REQUEST_URI'] = $req;
     unset($_SERVER['PATH_INFO']);
     $this->flush_cache();
     unset($GLOBALS['wp_query'], $GLOBALS['wp_the_query']);
     $GLOBALS['wp_the_query'] = new WP_Query();
     $GLOBALS['wp_query'] =& $GLOBALS['wp_the_query'];
     $GLOBALS['wp'] = new WP();
     foreach ($GLOBALS['wp']->public_query_vars as $v) {
         unset($GLOBALS[$v]);
     }
     foreach ($GLOBALS['wp']->private_query_vars as $v) {
         unset($GLOBALS[$v]);
     }
     $GLOBALS['wp']->main($parts['query']);
 }
Example #17
0
/**
 *
 * This file is a core Ultimatum file and should not be edited.
 *
 * @package  Ultimatum
 * @author   Wonder Foundry http://www.wonderfoundry.com
 * @license  http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
 * @link     http://ultimatumtheme.com
 * @version 2.50
 */
 
function ultimatum_toolset_setup(){
	if(isset($_REQUEST['api_key'])){
		$apireturn = ultimatum_api_returned_check($_REQUEST['api_key']);	
	} elseif (isset($_REQUEST['e'])){ ?>
		<div class="error fade"><p><?php echo $_REQUEST['e'] ?></p></div>
	<?php 
	}
	
	?>
	<div class="wrap about-wrap">
	<h1 style="width:100%;text-align:center"><?php _e('Login to your Ultimatum Account','ultimatum');?></h1>
	<div class="login" style="width:50%;margin:0 auto;">
	<form name="loginform" id="loginform" action="<?php echo ULTIMATUM_API;?>" method="post" style="background:transparent;box-shadow:none">
	<p>
		<label for="user_login"><?php _e('Username','ultimatum');?><br />
		<input type="text" name="user" id="user_login" class="input" value="" size="20" /></label>
	</p>
	<p>
		<label for="user_pass"><?php _e('Password','ultimatum');?><br />
		<input type="password" name="pass" id="user_pass" class="input" value="" size="20" /></label>
	</p>
	<p style="text-align:center">
		<input type="hidden" name="site" value="<?php echo  network_home_url();?>" />
		<input type="hidden" name="admin" value="<?php echo network_admin_url();?>" />
		<input type="hidden" name="task" value="getapi" />
		<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-hero" value="<?php _e('Log In','ultimatum');?>" />
	</p>
	</form>
	</div>
	<h3><?php _e('What is Tool Set and Why you need to register?','ultimatum');?></h3>
	<ol>
	<li><?php _e('Registering your site with ToolSet will grant you automatic Updates on Ultimatum and plugins included with it.','ultimatum');?></li>
	<li><?php _e('ToolSet is the control center and extension center of Ultimatum. You can access to the plugins we have included with Ultimatum via ToolSet.','ultimatum');?></li>
	</ol>
	<table>
	<?php access_check();?>
	</table>
	</div>
	<?php 
}
Example #18
0
 static function passwordReset(\WP_User $user, $reset_key)
 {
     if (is_multisite()) {
         $blogname = $GLOBALS['current_site']->site_name;
     } else {
         $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     }
     $user_email = $user->user_email;
     $user_login = $user->user_login;
     $message = __('Hi ' . $user->display_name . ',', 'thisdata-plugin') . "\r\n\r\n";
     $message .= sprintf(__('We\'ve automatically reset your password on %s', 'thisdata-plugin'), network_home_url('/')) . "\r\n\r\n";
     $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
     $message .= __('We did this to secure your account, in response to suspicious activity.', 'thisdata-plugin') . "\r\n\r\n";
     $message .= __('Please visit the following address now to complete the password reset process: ', 'thisdata-plugin') . "\r\n\r\n";
     $message .= '<' . network_site_url("wp-login.php?action=rp&key={$reset_key}&login="******">\r\n\r\n\r\n\r\n";
     $message .= __('Also remember to triple-check any future emails for suspicious looking content. We will never ask you for your password, and you should make sure the address (URL) of any website you do enter your password hasn\'t changed.', 'thisdata-plugin') . "\r\n\r\n";
     $title = sprintf(__('[%s] Password Reset', 'thisdata-plugin'), $blogname);
     $title = apply_filters('thisdata/reset_password_title', $title, $user_login);
     $message = apply_filters('thisdata/reset_password_message', $message, $reset_key, $user_login);
     //\Analog::log('Sending message '.$message, \Analog::DEBUG);
     return wp_mail($user_email, wp_specialchars_decode($title), $message);
 }
 public function remote_request()
 {
     $args = apply_filters('themeco_update_api', array());
     $args = wp_parse_args($args, array('api-key' => 'unverified', 'siteurl' => preg_replace('#(https?:)?//#', '', esc_attr(untrailingslashit(network_home_url())))));
     if (!$args['api-key']) {
         $args['api-key'] = 'unverified';
     }
     $request_url = self::$base_url . trailingslashit($args['api-key']);
     unset($args['api-key']);
     $uri = add_query_arg($args, $request_url);
     $request = wp_remote_get($uri, array('timeout' => 15));
     $connection_error = array('code' => 4, 'message' => __('Could not establish connection. For assistance, please start by reviewing our article on troubleshooting <a href="https://community.theme.co/kb/connection-issues/">connection issues.</a>', '__x__'));
     if (is_wp_error($request) || $request['response']['code'] != 200) {
         self::store_error($request);
         return $connection_error;
     }
     $data = json_decode($request['body'], true);
     if (defined('THEMECO_PRERELEASES') && THEMECO_PRERELEASES) {
         $data = $this->edge_filter($data);
     }
     return $data;
 }
Example #20
0
/**
 * Enques Admin and Front End JS/CSS
 */
function enqueue_admin_js()
{
    wp_register_script('ignitiondeck-admin', plugins_url('/js/ignitiondeck-admin.js', __FILE__));
    wp_enqueue_script('jQuery');
    wp_enqueue_script('ignitiondeck-admin');
    if (is_multisite() && is_id_network_activated()) {
        $id_ajaxurl = network_home_url('/') . 'wp-admin/admin-ajax.php';
    } else {
        $id_ajaxurl = site_url('/') . 'wp-admin/admin-ajax.php';
    }
    wp_localize_script('ignitiondeck-admin', 'id_homeurl', home_url());
    wp_localize_script('ignitiondeck-admin', 'id_ajaxurl', $id_ajaxurl);
    global $post;
    if (isset($post->post_type) && $post->post_type == 'ignition_product') {
        wp_register_script('ignitiondeck', plugins_url('/js/ignitiondeck.js', __FILE__));
        wp_enqueue_script('ignitiondeck');
        wp_localize_script('ignitiondeck', 'id_ajaxurl', $id_ajaxurl);
        wp_dequeue_script('autosave');
        //wp_enqueue_style('wp-pointer');
        //wp_enqueue_script('wp-pointer');
    }
}
Example #21
0
function ceo_import_add_comic_and_post($comic_to_add, $date_to_add, $title_to_add, $import_create_post, $import_chapter, $import_time, $import_directory)
{
    global $wpdb;
    // (TODO) check to see if the post already exists THEN do wp_insert_post below // $import_create_post
    // get the $timestamp set correctly
    $post_date = date('Y-m-d H:i:s', strtotime($date_to_add .= " " . $import_time));
    $post_args = array('post_name' => sanitize_title($title_to_add), 'post_title' => $title_to_add, 'post_date' => $post_date, 'post_type' => 'comic', 'post_status' => 'publish', 'tax_input' => array('chapters' => array($import_chapter)));
    $post_id = wp_insert_post($post_args);
    if (!is_wp_error($post_id)) {
        // Attach the Comic Now
        $file_url = is_multisite ? esc_url(network_home_url() . '/' . $import_directory . '/' . $comic_to_add) : esc_url(home_url() . '/' . $import_directory . '/' . $comic_to_add);
        $comic = new WP_Http();
        $comic = $comic->request($file_url);
        if (!is_wp_error($comic)) {
            $comic_date = isset($comic['headers']['last-modified']) ? $comic['headers']['last-modified'] : $comic['headers']['date'];
            $attachment = wp_upload_bits($comic_to_add, null, $comic['body'], date("Y-m", strtotime($comic_date)));
            if (!is_wp_error($attachment)) {
                $filetype = wp_check_filetype(basename($attachment['file']), null);
                $postinfo_args = array('guid' => $attachment['file'], 'post_mime_type' => $filetype['type'], 'post_title' => 'comic-' . $comic_to_add, 'post_content' => '', 'post_status' => 'inherit');
                $attached_filename = $attachment['file'];
                $attach_id = wp_insert_attachment($postinfo_args, $attached_filename, $post_id);
                $attach_data = wp_generate_attachment_metadata($attach_id, $attached_filename);
                wp_update_attachment_metadata($attach_id, $attach_data);
                // set it as the post featured image
                add_post_meta($post_id, '_thumbnail_id', $attach_id, true);
                set_post_thumbnail($post_id, $attach_id);
                return __('Comic Post made and Comic Attached', 'comiceasel');
            } else {
                return $attachment->get_error_message();
            }
        } else {
            return $comic->get_error_message();
        }
    } else {
        return $post_id->get_error_message();
    }
    return false;
}
Example #22
0
File: utils.php Project: roots/soil
/**
 * Make a URL relative
 */
function root_relative_url($input)
{
    if (is_feed()) {
        return $input;
    }
    $url = parse_url($input);
    if (!isset($url['host']) || !isset($url['path'])) {
        return $input;
    }
    $site_url = parse_url(network_home_url());
    // falls back to home_url
    if (!isset($url['scheme'])) {
        $url['scheme'] = $site_url['scheme'];
    }
    $hosts_match = $site_url['host'] === $url['host'];
    $schemes_match = $site_url['scheme'] === $url['scheme'];
    $ports_exist = isset($site_url['port']) && isset($url['port']);
    $ports_match = $ports_exist ? $site_url['port'] === $url['port'] : true;
    if ($hosts_match && $schemes_match && $ports_match) {
        return wp_make_link_relative($input);
    }
    return $input;
}
Example #23
0
/**
 * Handles sending password retrieval email to user.
 *
 * @global wpdb         $wpdb      WordPress database abstraction object.
 * @global PasswordHash $wp_hasher Portable PHP password hashing framework.
 *
 * @return bool|WP_Error True: when finish. WP_Error on error
 */
function retrieve_password()
{
    global $wpdb, $wp_hasher;
    $errors = new WP_Error();
    if (empty($_POST['user_login'])) {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or email address.'));
    } elseif (strpos($_POST['user_login'], '@')) {
        $user_data = get_user_by('email', trim($_POST['user_login']));
        if (empty($user_data)) {
            $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
        }
    } else {
        $login = trim($_POST['user_login']);
        $user_data = get_user_by('login', $login);
    }
    /**
     * Fires before errors are returned from a password reset request.
     *
     * @since 2.1.0
     * @since 4.4.0 Added the `$errors` parameter.
     *
     * @param WP_Error $errors A WP_Error object containing any errors generated
     *                         by using invalid credentials.
     */
    do_action('lostpassword_post', $errors);
    if ($errors->get_error_code()) {
        return $errors;
    }
    if (!$user_data) {
        $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or email.'));
        return $errors;
    }
    // Redefining user_login ensures we return the right case in the email.
    $user_login = $user_data->user_login;
    $user_email = $user_data->user_email;
    $key = get_password_reset_key($user_data);
    if (is_wp_error($key)) {
        return $key;
    }
    $message = __('Someone has requested a password reset for the following account:') . "\r\n\r\n";
    $message .= network_home_url('/') . "\r\n\r\n";
    $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
    $message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
    $message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
    $message .= '<' . network_site_url("wp-login.php?action=rp&key={$key}&login="******">\r\n";
    if (is_multisite()) {
        $blogname = $GLOBALS['current_site']->site_name;
    } else {
        /*
         * The blogname option is escaped with esc_html on the way into the database
         * in sanitize_option we want to reverse this for the plain text arena of emails.
         */
        $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    }
    $title = sprintf(__('[%s] Password Reset'), $blogname);
    /**
     * Filter the subject of the password reset email.
     *
     * @since 2.8.0
     * @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
     *
     * @param string  $title      Default email title.
     * @param string  $user_login The username for the user.
     * @param WP_User $user_data  WP_User object.
     */
    $title = apply_filters('retrieve_password_title', $title, $user_login, $user_data);
    /**
     * Filter the message body of the password reset mail.
     *
     * @since 2.8.0
     * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
     *
     * @param string  $message    Default mail message.
     * @param string  $key        The activation key.
     * @param string  $user_login The username for the user.
     * @param WP_User $user_data  WP_User object.
     */
    $message = apply_filters('retrieve_password_message', $message, $key, $user_login, $user_data);
    if ($message && !wp_mail($user_email, wp_specialchars_decode($title), $message)) {
        wp_die(__('The email could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.'));
    }
    return true;
}
Example #24
0
 private static function get_site_url()
 {
     if (is_callable('network_home_url')) {
         $site_url = network_home_url();
     } else {
         $site_url = get_bloginfo('url');
     }
     $site_url = preg_replace('/^https/', 'http', $site_url);
     $site_url = preg_replace('|/$|', '', $site_url);
     return $site_url;
 }
Example #25
0
 public function retrieve_password()
 {
     global $wpdb, $json_api, $wp_hasher;
     if (!$json_api->query->user_login) {
         $json_api->error("You must include 'user_login' var in your request. ");
     }
     $user_login = $json_api->query->user_login;
     if (strpos($user_login, '@')) {
         $user_data = get_user_by('email', trim($user_login));
         if (empty($user_data)) {
             $json_api->error("Your email address not found! ");
         }
     } else {
         $login = trim($user_login);
         $user_data = get_user_by('login', $login);
     }
     // redefining user_login ensures we return the right case in the email
     $user_login = $user_data->user_login;
     $user_email = $user_data->user_email;
     do_action('retrieve_password', $user_login);
     $allow = apply_filters('allow_password_reset', true, $user_data->ID);
     if (!$allow) {
         $json_api->error("password reset not allowed! ");
     } elseif (is_wp_error($allow)) {
         $json_api->error("An error occured! ");
     }
     $key = wp_generate_password(20, false);
     do_action('retrieve_password_key', $user_login, $key);
     if (empty($wp_hasher)) {
         require_once ABSPATH . 'wp-includes/class-phpass.php';
         $wp_hasher = new PasswordHash(8, true);
     }
     $hashed = $wp_hasher->HashPassword($key);
     $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $user_login));
     $message = __('Someone requested that the password be reset for the following account:') . "\r\n\r\n";
     $message .= network_home_url('/') . "\r\n\r\n";
     $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
     $message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
     $message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
     $message .= '<' . network_site_url("wp-login.php?action=rp&key={$key}&login="******">\r\n";
     if (is_multisite()) {
         $blogname = $GLOBALS['current_site']->site_name;
     } else {
         $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     }
     $title = sprintf(__('[%s] Password Reset'), $blogname);
     $title = apply_filters('retrieve_password_title', $title);
     $message = apply_filters('retrieve_password_message', $message, $key);
     if ($message && !wp_mail($user_email, $title, $message)) {
         $json_api->error("The e-mail could not be sent. Possible reason: your host may have disabled the mail() function...");
     } else {
         return array("msg" => 'Link for password reset has been emailed to you. Please check your email.');
     }
 }
Example #26
0
/**
 * Correct 404 redirects when NOBLOGREDIRECT is defined.
 *
 * @since MU
 */
function maybe_redirect_404()
{
    global $current_site;
    if (is_main_site() && is_404() && defined('NOBLOGREDIRECT') && ($destination = apply_filters('blog_redirect_404', NOBLOGREDIRECT))) {
        if ($destination == '%siteurl%') {
            $destination = network_home_url();
        }
        wp_redirect($destination);
        exit;
    }
}
 /**
  * Handles sending password retrieval email to user.
  *
  * @since 6.0
  * @access public
  * @uses $wpdb WordPress Database object
  *
  * @return bool|WP_Error True: when finish. WP_Error on error
  */
 public static function retrieve_password()
 {
     global $wpdb, $wp_hasher;
     $errors = new WP_Error();
     if (empty($_POST['user_login'])) {
         $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.', 'theme-my-login'));
     } else {
         if (strpos($_POST['user_login'], '@')) {
             $user_data = get_user_by('email', trim($_POST['user_login']));
             if (empty($user_data)) {
                 $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.', 'theme-my-login'));
             }
         } else {
             $login = trim($_POST['user_login']);
             $user_data = get_user_by('login', $login);
         }
     }
     do_action('lostpassword_post', $errors);
     if ($errors->get_error_code()) {
         return $errors;
     }
     if (!$user_data) {
         $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.', 'theme-my-login'));
         return $errors;
     }
     // redefining user_login ensures we return the right case in the email
     $user_login = $user_data->user_login;
     $user_email = $user_data->user_email;
     $key = get_password_reset_key($user_data);
     if (is_wp_error($key)) {
         return $key;
     }
     $message = __('Someone requested that the password be reset for the following account:', 'theme-my-login') . "\r\n\r\n";
     $message .= network_home_url('/') . "\r\n\r\n";
     $message .= sprintf(__('Username: %s', 'theme-my-login'), $user_login) . "\r\n\r\n";
     $message .= __('If this was a mistake, just ignore this email and nothing will happen.', 'theme-my-login') . "\r\n\r\n";
     $message .= __('To reset your password, visit the following address:', 'theme-my-login') . "\r\n\r\n";
     $message .= '<' . network_site_url("wp-login.php?action=rp&key={$key}&login="******">\r\n";
     if (is_multisite()) {
         $blogname = $GLOBALS['current_site']->site_name;
     } else {
         // The blogname option is escaped with esc_html on the way into the database in sanitize_option
         // we want to reverse this for the plain text arena of emails.
         $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     }
     $title = sprintf(__('[%s] Password Reset', 'theme-my-login'), $blogname);
     $title = apply_filters('retrieve_password_title', $title, $user_login, $user_data);
     $message = apply_filters('retrieve_password_message', $message, $key, $user_login, $user_data);
     if ($message && !wp_mail($user_email, $title, $message)) {
         wp_die(__('The e-mail could not be sent.', 'theme-my-login') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...', 'theme-my-login'));
     }
     return true;
 }
Example #28
0
 /**
  * Adds the network (all sites) home page link to the items array.
  *
  * @since  0.6.0
  * @access public
  * @return void
  */
 public function do_network_home_link()
 {
     if (is_multisite() && !is_main_site() && true === $this->args['network']) {
         $this->items[] = '<a href="' . esc_url(network_home_url()) . '" rel="home">' . $this->args['labels']['home'] . '</a>';
     }
 }
Example #29
0
function choose_primary_blog() {
	?>
	<table class="form-table">
	<tr>
	<?php /* translators: My sites label */ ?>
		<th scope="row"><?php _e( 'Primary Site' ); ?></th>
		<td>
		<?php
		$all_blogs = get_blogs_of_user( get_current_user_id() );
		$primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
		if ( count( $all_blogs ) > 1 ) {
			$found = false;
			?>
			<select name="primary_blog">
				<?php foreach( (array) $all_blogs as $blog ) {
					if ( $primary_blog == $blog->userblog_id )
						$found = true;
					?><option value="<?php echo $blog->userblog_id ?>"<?php selected( $primary_blog,  $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ) ?></option><?php
				} ?>
			</select>
			<?php
			if ( !$found ) {
				$blog = array_shift( $all_blogs );
				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
			}
		} elseif ( count( $all_blogs ) == 1 ) {
			$blog = array_shift( $all_blogs );
			echo $blog->domain;
			if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
		} else {
			echo "N/A";
		}
		?>
		</td>
	</tr>
	<?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?>
		<tr>
			<th scope="row" colspan="2" class="th-full">
				<a href="<?php echo apply_filters( 'wp_signup_location', network_home_url( 'wp-signup.php' ) ); ?>"><?php _e( 'Create a New Site' ); ?></a>
			</th>
		</tr>
	<?php endif; ?>
	</table>
	<?php
}
    /**
     * {@internal Missing Short Description}}
     *
     * {@internal Missing Long Description}}
     *
     * @since 2.1.0
     *
     * @param int $user_id User ID.
     */
    function wp_install_defaults($user_id)
    {
        global $wpdb, $wp_rewrite, $table_prefix;
        // Default category
        $cat_name = __('Uncategorized');
        /* translators: Default category slug */
        $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
        if (global_terms_enabled()) {
            $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug));
            if ($cat_id == null) {
                $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)));
                $cat_id = $wpdb->insert_id;
            }
            update_option('default_category', $cat_id);
        } else {
            $cat_id = 1;
        }
        $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0));
        $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
        $cat_tt_id = $wpdb->insert_id;
        // First post
        $now = date('Y-m-d H:i:s');
        $now_gmt = gmdate('Y-m-d H:i:s');
        $first_post_guid = get_option('home') . '/?p=1';
        if (is_multisite()) {
            $first_post = get_site_option('first_post');
            if (empty($first_post)) {
                $first_post = __('Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!');
            }
            $first_post = str_replace("SITE_URL", esc_url(network_home_url()), $first_post);
            $first_post = str_replace("SITE_NAME", get_current_site()->site_name, $first_post);
        } else {
            $first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
        }
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_post, 'post_excerpt' => '', 'post_title' => __('Hello world!'), 'post_name' => sanitize_title(_x('hello-world', 'Default post slug')), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'comment_count' => 1, 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
        $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1));
        // Default comment
        $first_comment_author = __('Mr WordPress');
        $first_comment_url = 'https://wordpress.org/';
        $first_comment = __('Hi, this is a comment.
To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
        if (is_multisite()) {
            $first_comment_author = get_site_option('first_comment_author', $first_comment_author);
            $first_comment_url = get_site_option('first_comment_url', network_home_url());
            $first_comment = get_site_option('first_comment', $first_comment);
        }
        $wpdb->insert($wpdb->comments, array('comment_post_ID' => 1, 'comment_author' => $first_comment_author, 'comment_author_email' => '', 'comment_author_url' => $first_comment_url, 'comment_date' => $now, 'comment_date_gmt' => $now_gmt, 'comment_content' => $first_comment));
        // First Page
        $first_page = sprintf(__("This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:\n\n<blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>\n\n...or something like this:\n\n<blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>\n\nAs a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!"), admin_url());
        if (is_multisite()) {
            $first_page = get_site_option('first_page', $first_page);
        }
        $first_post_guid = get_option('home') . '/?page_id=2';
        $wpdb->insert($wpdb->posts, array('post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __('Sample Page'), 'post_name' => __('sample-page'), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => ''));
        $wpdb->insert($wpdb->postmeta, array('post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default'));
        // Set up default widgets for default theme.
        update_option('widget_search', array(2 => array('title' => ''), '_multiwidget' => 1));
        update_option('widget_recent-posts', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
        update_option('widget_recent-comments', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1));
        update_option('widget_archives', array(2 => array('title' => '', 'count' => 0, 'dropdown' => 0), '_multiwidget' => 1));
        update_option('widget_categories', array(2 => array('title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1));
        update_option('widget_meta', array(2 => array('title' => ''), '_multiwidget' => 1));
        update_option('sidebars_widgets', array('wp_inactive_widgets' => array(), 'sidebar-1' => array(0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2'), 'sidebar-2' => array(), 'sidebar-3' => array(), 'array_version' => 3));
        if (!is_multisite()) {
            update_user_meta($user_id, 'show_welcome_panel', 1);
        } elseif (!is_super_admin($user_id) && !metadata_exists('user', $user_id, 'show_welcome_panel')) {
            update_user_meta($user_id, 'show_welcome_panel', 2);
        }
        if (is_multisite()) {
            // Flush rules to pick up the new page.
            $wp_rewrite->init();
            $wp_rewrite->flush_rules();
            $user = new WP_User($user_id);
            $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email'));
            // Remove all perms except for the login user.
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'user_level'));
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->usermeta} WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities'));
            // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
            if (!is_super_admin($user_id) && $user_id != 1) {
                $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix . '1_capabilities'));
            }
        }
    }