/** * This function taken and only slightly adapted from WP No Category Base plugin by Saurabh Gupta */ function category_rewrite_rules($rewrite) { global $wp_rewrite; $category_rewrite = array(); $categories = get_categories(array('hide_empty' => false)); $blog_prefix = ''; if (function_exists('is_multisite') && is_multisite() && !is_subdomain_install() && is_main_site()) { $blog_prefix = 'blog/'; } foreach ($categories as $category) { $category_nicename = $category->slug; if ($category->parent == $category->cat_ID) { // recursive recursion $category->parent = 0; } elseif ($category->parent != 0) { $category_nicename = get_category_parents($category->parent, false, '/', true) . $category_nicename; } $category_rewrite[$blog_prefix . '(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]'; $category_rewrite[$blog_prefix . '(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]'; $category_rewrite[$blog_prefix . '(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]'; } // Redirect support from Old Category Base $old_base = $wp_rewrite->get_category_permastruct(); $old_base = str_replace('%category%', '(.+)', $old_base); $old_base = trim($old_base, '/'); $category_rewrite[$old_base . '$'] = 'index.php?wpseo_category_redirect=$matches[1]'; return $category_rewrite; }
function render() { $this->open_section_box($this->id, __("Create New Site", "ns-cloner"), false, __("Create Site", "ns-cloner")); ?> <label for="target_title"><?php _e("Give the Target site a Title", "ns-cloner"); ?> </label> <input type="text" name="target_title" placeholder="New Site H1"/> <label for="target_name"><?php _e("Give the Target site a URL (or \"Name\" in WP terminology)", "ns-cloner"); ?> </label> <?php if (is_subdomain_install()) { ?> <input type="text" name="target_name" />.<?php echo preg_replace('|^www\\.|', '', get_current_site()->domain); ?> <?php } else { ?> <?php echo get_current_site()->domain . get_current_site()->path; ?> <input type="text" name="target_name" /> <?php } ?> <?php $this->close_section_box(); }
/** * Helper function for generating the registration fields array. */ function wdfb_get_registration_fields_array() { global $current_site; $data = Wdfb_OptionsRegistry::get_instance(); $wp_grant_blog = false; if (is_multisite()) { $reg = get_site_option('registration'); if ('all' == $reg) { $wp_grant_blog = true; } else { if ('user' != $reg) { return array(); } } } else { if (!(int) get_option('users_can_register')) { return array(); } } $fields = array(array("name" => "name"), array("name" => "email"), array("name" => "first_name"), array("name" => "last_name"), array("name" => "gender"), array("name" => "location"), array("name" => "birthday")); if ($wp_grant_blog) { $fields[] = array('name' => 'blog_title', 'description' => __('Your blog title', 'wdfb'), 'type' => 'text'); $newdomain = is_subdomain_install() ? 'youraddress.' . preg_replace('|^www\\.|', '', $current_site->domain) : $current_site->domain . $current_site->path . 'youraddress'; $fields[] = array('name' => 'blog_domain', 'description' => sprintf(__('Your blog address (%s)', 'wdfb'), $newdomain), 'type' => 'text'); } if (!$data->get_option('wdfb_connect', 'no_captcha')) { $fields[] = array("name" => "captcha"); } return apply_filters('wdfb-registration_fields_array', $fields); }
public static function add_rewrite_rules($rules) { //Get taxonomies $taxonomies = get_taxonomies(); $blog_prefix = ''; $endpoint = Slash_Edit::get_instance()->get_endpoint(); if (is_multisite() && !is_subdomain_install() && is_main_site()) { /* stolen from /wp-admin/options-permalink.php */ $blog_prefix = 'blog/'; } $exclude = array('category', 'post_tag', 'nav_menu', 'link_category', 'post_format'); foreach ($taxonomies as $key => $taxonomy) { if (in_array($key, $exclude)) { continue; } $rules["{$blog_prefix}{$key}/([^/]+)/{$endpoint}(/(.*))?/?\$"] = 'index.php?' . $key . '=$matches[1]&' . $endpoint . '=$matches[3]'; } //Add home_url/edit to rewrites $add_frontpage_edit_rules = false; if (!get_page_by_path($endpoint)) { $add_frontpage_edit_rules = true; } else { $page = get_page_by_path($endpoint); if (is_a($page, 'WP_Post') && $page->post_status != 'publish') { $add_frontpage_edit_rules = true; } } if ($add_frontpage_edit_rules) { $edit_array_rule = array("{$endpoint}/?\$" => 'index.php?' . $endpoint . '=frontpage'); $rules = $edit_array_rule + $rules; } return $rules; }
/** * Determine whether to apply a subdomain replace over each value in the database. * * @return bool */ function is_subdomain_replaces_on() { if (!isset($this->subdomain_replaces_on)) { $this->subdomain_replaces_on = is_multisite() && is_subdomain_install() && !$this->has_same_base_domain() && apply_filters('wpmdb_subdomain_replace', true); } return $this->subdomain_replaces_on; }
function get_blog_prefix() { $blog_prefix = ''; if (is_multisite() && !is_subdomain_install() && is_main_site()) { $blog_prefix = '/blog'; } return $blog_prefix; }
/** * Update the permalink structure. * * ## DESCRIPTION * * Updates the post permalink structure. * * To regenerate a .htaccess file with WP-CLI, you'll need to add the mod_rewrite module * to your wp-cli.yml or config.yml. For example: * * apache_modules: * - mod_rewrite * * ## OPTIONS * * <permastruct> * : The new permalink structure to apply. * * [--category-base=<base>] * : Set the base for category permalinks, i.e. '/category/'. * * [--tag-base=<base>] * : Set the base for tag permalinks, i.e. '/tag/'. * * [--hard] * : Perform a hard flush - update `.htaccess` rules as well as rewrite rules in database. * * ## EXAMPLES * * wp rewrite structure '/%year%/%monthnum%/%postname%' */ public function structure($args, $assoc_args) { global $wp_rewrite; // copypasta from /wp-admin/options-permalink.php $home_path = get_home_path(); $iis7_permalinks = iis7_supports_permalinks(); $prefix = $blog_prefix = ''; if (!got_mod_rewrite() && !$iis7_permalinks) { $prefix = '/index.php'; } if (is_multisite() && !is_subdomain_install() && is_main_site()) { $blog_prefix = '/blog'; } $permalink_structure = $args[0] == 'default' ? '' : $args[0]; if (!empty($permalink_structure)) { $permalink_structure = preg_replace('#/+#', '/', '/' . str_replace('#', '', $permalink_structure)); if ($prefix && $blog_prefix) { $permalink_structure = $prefix . preg_replace('#^/?index\\.php#', '', $permalink_structure); } else { $permalink_structure = $blog_prefix . $permalink_structure; } } $wp_rewrite->set_permalink_structure($permalink_structure); // Update category or tag bases if (isset($assoc_args['category-base'])) { $category_base = $assoc_args['category-base']; if (!empty($category_base)) { $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $category_base)); } $wp_rewrite->set_category_base($category_base); } if (isset($assoc_args['tag-base'])) { $tag_base = $assoc_args['tag-base']; if (!empty($tag_base)) { $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $tag_base)); } $wp_rewrite->set_tag_base($tag_base); } // make sure we detect mod_rewrite if configured in apache_modules in config self::apache_modules(); // Launch a new process to flush rewrites because core expects flush // to happen after rewrites are set $new_assoc_args = array(); if (\WP_CLI\Utils\get_flag_value($assoc_args, 'hard')) { $new_assoc_args['hard'] = true; if (!in_array('mod_rewrite', (array) WP_CLI::get_config('apache_modules'))) { WP_CLI::warning("Regenerating a .htaccess file requires special configuration. See usage docs."); } } $process_run = WP_CLI::launch_self('rewrite flush', array(), $new_assoc_args, true, true, array('apache_modules', WP_CLI::get_config('apache_modules'))); if (!empty($process_run->stderr)) { // Strip "Warning: " WP_CLI::warning(substr($process_run->stderr, 9)); } WP_CLI::success("Rewrite structure set."); }
function show_blog_form($blogname = '', $blog_title = '', $errors = '') { global $current_site; // Blog name if ( !is_subdomain_install() ) echo '<label for="blogname">' . __('Site Name:') . '</label>'; else echo '<label for="blogname">' . __('Site Domain:') . '</label>'; if ( $errmsg = $errors->get_error_message('blogname') ) { ?> <p class="error"><?php echo $errmsg ?></p> <?php } if ( !is_subdomain_install() ) echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blogname" type="text" id="blogname" value="'. esc_attr($blogname) .'" maxlength="60" /><br />'; else echo '<input name="blogname" type="text" id="blogname" value="'.esc_attr($blogname).'" maxlength="60" /><span class="suffix_address">.' . ( $site_domain = preg_replace( '|^www\.|', '', $current_site->domain ) ) . '</span><br />'; if ( !is_user_logged_in() ) { print '(<strong>' . __( 'Your address will be ' ); if ( !is_subdomain_install() ) print $current_site->domain . $current_site->path . __( 'sitename' ); else print __( 'domain.' ) . $site_domain . $current_site->path; echo '.</strong>) ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed, so choose carefully!' ) . '</p>'; } // Blog Title ?> <label for="blog_title"><?php _e('Site Title:') ?></label> <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?> <p class="error"><?php echo $errmsg ?></p> <?php } echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_attr($blog_title).'" />'; ?> <div id="privacy"> <p class="privacy-intro"> <label for="blog_public_on"><?php _e('Privacy:') ?></label> <?php _e('Allow my site to appear in search engines like Google, Technorati, and in public listings around this network.'); ?> <br style="clear:both" /> <label class="checkbox" for="blog_public_on"> <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if ( !isset( $_POST['blog_public'] ) || $_POST['blog_public'] == '1' ) { ?>checked="checked"<?php } ?> /> <strong><?php _e( 'Yes' ); ?></strong> </label> <label class="checkbox" for="blog_public_off"> <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if ( isset( $_POST['blog_public'] ) && $_POST['blog_public'] == '0' ) { ?>checked="checked"<?php } ?> /> <strong><?php _e( 'No' ); ?></strong> </label> </p> </div> <?php do_action('signup_blogform', $errors); }
/** * Return the avatar link of a user * * @param array $args This function supports these arguments: * - int $size If we're showing an avatar, set it to this size * - string $type What type of link to return; either "avatar", "name", or "both", or "url". * - int $user_id The ID for the user. * @return string * @since Achievements (3.0) */ function dpa_get_user_avatar_link($args = array()) { $defaults = array('size' => 50, 'type' => 'both', 'user_id' => 0); $r = dpa_parse_args($args, $defaults, 'get_user_avatar_link'); extract($r); // Default to current user if (empty($user_id) && is_user_logged_in()) { $user_id = get_current_user_id(); } // Assemble some link bits $user_link = array(); // BuddyPress if (dpa_integrate_into_buddypress()) { $user_url = user_trailingslashit(bp_core_get_user_domain($user_id) . dpa_get_authors_endpoint()); // WordPress } else { $user_url = user_trailingslashit(trailingslashit(get_author_posts_url($user_id)) . dpa_get_authors_endpoint()); /** * Multisite, running network-wide. * * When this function is used by the "unlocked achievement" popup, if multisite + running network-wide + and not subdomains, * we'll have already done switch_to_blog( DPA_ROOT_BLOG ) by the time that this function is called. This makes inspecting * the current site ID, and is_main_site(), both useless as the globals will have already been changed. * * We need to find out if the user is likely to be on the "main site" in this situation. so we can modify our link. * The main site's author URLs are prefixed with "/blog". We do this by inspecting the _wp_switched_stack global. * * I think this solution might result in a wrong link in multi-network configuration, or if the main site has been set * to something non-default, but these are edge-cases for now. */ if (is_multisite() && !is_subdomain_install() && dpa_is_running_networkwide() && DPA_DATA_STORE === 1 && !empty($GLOBALS['_wp_switched_stack'])) { $last_element = count($GLOBALS['_wp_switched_stack']) - 1; if (isset($GLOBALS['_wp_switched_stack'][$last_element]) && $GLOBALS['_wp_switched_stack'][$last_element] != 1) { $user_url = str_replace(home_url(), home_url() . '/blog', $user_url); } } } // Get avatar if ('avatar' === $type || 'both' === $type) { $user_link[] = sprintf('<a href="%1$s">%2$s</a>', esc_url($user_url), get_avatar($user_id, $size)); } // Get display name if ('avatar' !== $type) { $user_link[] = sprintf('<a href="%1$s">%2$s</a>', esc_url($user_url), get_the_author_meta('display_name', $user_id)); } // Maybe return user URL only if ('url' === $type) { $user_link = $user_url; // Otherwise piece together the link parts and return } else { $user_link = join(' ', $user_link); } return apply_filters('dpa_get_user_avatar_link', $user_link, $args); }
/** * Returns the correct baseurl path of the current site's uploads folder. * * @since 3.0.0 * * @return string The correct baseurl path of the current site's uploads folder. */ public function baseurl() { $uploads = $this->get_uploads_dir(); $base_url = (string) $uploads['baseurl']; if (!is_subdomain_install()) { return $base_url; } $site_url = get_option('siteurl'); if (0 === strpos($base_url, $site_url)) { return $base_url; } return str_replace(parse_url($base_url, PHP_URL_HOST), parse_url($site_url, PHP_URL_HOST), $base_url); }
/** * @ticket 34450 */ public function test_get_id_from_blogname_www() { global $current_site; $original_network = $current_site; $current_site = get_network(self::$network_ids['www.wordpress.net/']); if (is_subdomain_install()) { $expected = self::$site_ids['foo.wordpress.net/']; } else { $expected = self::$site_ids['www.wordpress.net/foo/']; } $result = get_id_from_blogname('foo'); $current_site = $original_network; $this->assertEquals($expected, $result); }
/** * Update the permalink structure. * * ## OPTIONS * * <permastruct> * : The new permalink structure to apply. * * [--category-base=<base>] * : Set the base for category permalinks, i.e. '/category/'. * * [--tag-base=<base>] * : Set the base for tag permalinks, i.e. '/tag/'. * * [--hard] * : Perform a hard flush - update `.htaccess` rules as well as rewrite rules in database. * * ## EXAMPLES * * wp rewrite structure '/%year%/%monthnum%/%postname%' */ public function structure($args, $assoc_args) { global $wp_rewrite; // copypasta from /wp-admin/options-permalink.php $home_path = get_home_path(); $iis7_permalinks = iis7_supports_permalinks(); $prefix = $blog_prefix = ''; if (!got_mod_rewrite() && !$iis7_permalinks) { $prefix = '/index.php'; } if (is_multisite() && !is_subdomain_install() && is_main_site()) { $blog_prefix = '/blog'; } $permalink_structure = $args[0] == 'default' ? '' : $args[0]; if (!empty($permalink_structure)) { $permalink_structure = preg_replace('#/+#', '/', '/' . str_replace('#', '', $permalink_structure)); if ($prefix && $blog_prefix) { $permalink_structure = $prefix . preg_replace('#^/?index\\.php#', '', $permalink_structure); } else { $permalink_structure = $blog_prefix . $permalink_structure; } } $wp_rewrite->set_permalink_structure($permalink_structure); // Update category or tag bases if (isset($assoc_args['category-base'])) { $category_base = $assoc_args['category-base']; if (!empty($category_base)) { $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $category_base)); } $wp_rewrite->set_category_base($category_base); } if (isset($assoc_args['tag-base'])) { $tag_base = $assoc_args['tag-base']; if (!empty($tag_base)) { $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $tag_base)); } $wp_rewrite->set_tag_base($tag_base); } // make sure we detect mod_rewrite if configured in apache_modules in config self::apache_modules(); // Launch a new process to flush rewrites because core expects flush // to happen after rewrites are set $new_assoc_args = array(); if (isset($assoc_args['hard'])) { $new_assoc_args['hard'] = true; } \WP_CLI::launch_self('rewrite flush', array(), $new_assoc_args); WP_CLI::success("Rewrite structure set."); }
/** * Set permalink structure * * @param array $args * @param array $assoc_args */ public function structure($args, $assoc_args) { if (!count($args) && !count($assoc_args)) { WP_CLI::line("usage: wp rewrite structure <new-permalink-structure>"); exit; } global $wp_rewrite; // copypasta from /wp-admin/options-permalink.php $home_path = get_home_path(); $iis7_permalinks = iis7_supports_permalinks(); $prefix = $blog_prefix = ''; if (!got_mod_rewrite() && !$iis7_permalinks) { $prefix = '/index.php'; } if (is_multisite() && !is_subdomain_install() && is_main_site()) { $blog_prefix = '/blog'; } // Update base permastruct if argument is provided if (isset($args[0])) { $permalink_structure = $args[0] == 'default' ? '' : $args[0]; if (!empty($permalink_structure)) { $permalink_structure = preg_replace('#/+#', '/', '/' . str_replace('#', '', $permalink_structure)); if ($prefix && $blog_prefix) { $permalink_structure = $prefix . preg_replace('#^/?index\\.php#', '', $permalink_structure); } else { $permalink_structure = $blog_prefix . $permalink_structure; } } $wp_rewrite->set_permalink_structure($permalink_structure); } // Update category or tag bases if (isset($assoc_args['category-base'])) { $category_base = $assoc_args['category-base']; if (!empty($category_base)) { $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $category_base)); } $wp_rewrite->set_category_base($category_base); } if (isset($assoc_args['tag-base'])) { $tag_base = $assoc_args['tag-base']; if (!empty($tag_base)) { $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $tag_base)); } $wp_rewrite->set_tag_base($tag_base); } flush_rewrite_rules($hard); }
function bogo_post_rewrite_rules($post_rewrite) { global $wp_rewrite; $permastruct = $wp_rewrite->permalink_structure; // from wp-admin/includes/misc.php $got_rewrite = apply_filters('got_rewrite', apache_mod_loaded('mod_rewrite', true)); $got_url_rewrite = apply_filters('got_url_rewrite', $got_rewrite || $GLOBALS['is_nginx'] || iis7_supports_permalinks()); if (!$got_url_rewrite) { $permastruct = preg_replace('#^/index\\.php#', '/index.php/%lang%', $permastruct); } elseif (is_multisite() && !is_subdomain_install() && is_main_site()) { $permastruct = preg_replace('#^/blog#', '/%lang%/blog', $permastruct); } else { $permastruct = preg_replace('#^/#', '/%lang%/', $permastruct); } $extra = bogo_generate_rewrite_rules($permastruct, array('ep_mask' => EP_PERMALINK, 'paged' => false)); return array_merge($extra, $post_rewrite); }
/** * @return bool */ public function replace_url() { ob_start(); $_SERVER['_REQUEST_URI'] = untrailingslashit($_SERVER['REQUEST_URI']); if (false === strpos($_SERVER['_REQUEST_URI'], UPLOADS_STRUCTURE_NAME)) { return false; } // Fix conflict with WProcket define('DONOTCACHEPAGE', true); // Get extension $extension = pathinfo($_SERVER['_REQUEST_URI'], PATHINFO_EXTENSION); // Send content type header header('Content-Type: ' . $this->get_mime_type_from_file_extension($extension)); // Test if is local file for MS subfolder installation. $request_uri_parts = explode('/', ltrim($_SERVER['_REQUEST_URI'], '/')); array_shift($request_uri_parts); if (function_exists('is_subdomain_install') && !is_subdomain_install() && is_file(ABSPATH . implode('/', $request_uri_parts))) { status_header(200); readfile(ABSPATH . implode('/', $request_uri_parts)); exit; } // Get remote HTML file $response = wp_remote_get(untrailingslashit(PROD_UPLOADS_URL) . $_SERVER['_REQUEST_URI']); // Get response code $response_code = wp_remote_retrieve_response_code($response); ob_end_clean(); // Check for error and the response code if (!is_wp_error($response) && 200 == $response_code) { // Parse remote HTML file $data = wp_remote_retrieve_body($response); // Check for error if (!is_wp_error($data)) { status_header(200); echo $data; exit; } } //TODO Improve cache header('Pragma: public'); header('Cache-Control: max-age=86400'); header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 86400)); //header( 'Content-Length: 0' ); exit; }
function render() { $this->open_section_box($this->id, __("Select Source", "ns-cloner")); ?> <label class="ns-cloner-site-search-label">Search by url</label> <input type="text" class="ns-cloner-site-search" /> <label class="ns-cloner-site-select-label">Or select</label> <select name="source_id" class="ns-cloner-site-select"> <?php $sites = function_exists('wp_get_sites') ? wp_get_sites(array('limit' => 9999)) : get_blog_list(0, 'all'); ?> <?php foreach ($sites as $site) { ?> <option value="<?php echo $site['blog_id']; ?> "> <?php $title = get_blog_details($site['blog_id'])->blogname; ?> <?php $url = is_subdomain_install() ? "{$site['domain']}" : "{$site['domain']}{$site['path']}"; ?> <?php echo "{$site['blog_id']} - " . substr($title, 0, 30) . " ({$url})"; ?> <?php } ?> </select> <p class="description ns-cloner-clear"><?php _e('Pick an existing source site to clone. If you haven\'t already, now is a great time to set up a "template" site exactly the way you want the new clone site to start out (theme, plugins, settings, etc.).', 'ns-cloner'); ?> </p> <?php $this->close_section_box(); }
/** * Defines Multisite cookie constants. * * @since 3.0.0 */ function ms_cookie_constants() { global $current_site; /** * @since 1.2.0 */ if (!defined('COOKIEPATH')) { define('COOKIEPATH', $current_site->path); } /** * @since 1.5.0 */ if (!defined('SITECOOKIEPATH')) { define('SITECOOKIEPATH', $current_site->path); } /** * @since 2.6.0 */ if (!defined('ADMIN_COOKIE_PATH')) { if (!is_subdomain_install()) { define('ADMIN_COOKIE_PATH', SITECOOKIEPATH); } else { define('ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin'); } } /** * @since 2.0.0 */ if (!defined('COOKIE_DOMAIN') && is_subdomain_install()) { if (!empty($current_site->cookie_domain)) { define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain); } else { define('COOKIE_DOMAIN', '.' . $current_site->domain); } } }
/** * Defines Multisite cookie constants. * * @since 3.0.0 */ function ms_cookie_constants() { $current_site = get_current_site(); /** * @since 1.2.0 */ if (!defined('COOKIEPATH')) { define('COOKIEPATH', $current_site->path); } /** * @since 1.5.0 */ if (!defined('SITECOOKIEPATH')) { define('SITECOOKIEPATH', $current_site->path); } /** * @since 2.6.0 */ if (!defined('ADMIN_COOKIE_PATH')) { if (!is_subdomain_install() || trim(parse_url(get_option('siteurl'), PHP_URL_PATH), '/')) { define('ADMIN_COOKIE_PATH', SITECOOKIEPATH); } else { define('ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin'); } } /** * @since 2.0.0 */ if (!defined('COOKIE_DOMAIN') && is_subdomain_install()) { if (!empty($current_site->cookie_domain)) { define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain); } else { define('COOKIE_DOMAIN', '.' . $current_site->domain); } } }
" value="<?php echo esc_attr($blogname); ?> " maxlength="60" /> <span class="suffix_address"><?php echo $site_domain = preg_replace('|^www\\.|', '', $current_site->domain); ?> </span><br /> <?php } ?> <?php if (!is_user_logged_in()) { if (!is_subdomain_install()) { $site = $current_site->domain . $current_site->path . __('sitename'); } else { $site = __('domain') . '.' . $site_domain . $current_site->path; } echo '<p>(<strong>' . sprintf(__('Your address will be %s.'), $site) . '</strong>) ' . __('Must be at least 4 characters, letters and numbers only. It cannot be changed, so choose carefully!') . '</p>'; } ?> <label for="blog_title<?php $template->the_instance(); ?> "><?php _e('Site Title:'); ?>
/** * * @global string $s * @global string $mode * @global wpdb $wpdb */ public function prepare_items() { global $s, $mode, $wpdb; $current_site = get_current_site(); $mode = empty($_REQUEST['mode']) ? 'list' : $_REQUEST['mode']; $per_page = $this->get_items_per_page('sites_network_per_page'); $pagenum = $this->get_pagenum(); $s = isset($_REQUEST['s']) ? wp_unslash(trim($_REQUEST['s'])) : ''; $wild = ''; if (false !== strpos($s, '*')) { $wild = '%'; $s = trim($s, '*'); } /* * If the network is large and a search is not being performed, show only * the latest blogs with no paging in order to avoid expensive count queries. */ if (!$s && wp_is_large_network()) { if (!isset($_REQUEST['orderby'])) { $_GET['orderby'] = $_REQUEST['orderby'] = ''; } if (!isset($_REQUEST['order'])) { $_GET['order'] = $_REQUEST['order'] = 'DESC'; } } $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' "; if (empty($s)) { // Nothing to do. } elseif (preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $s) || preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.?$/', $s) || preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.?$/', $s) || preg_match('/^[0-9]{1,3}\\.$/', $s)) { // IPv4 address $sql = $wpdb->prepare("SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like($s) . $wild); $reg_blog_ids = $wpdb->get_col($sql); if (!$reg_blog_ids) { $reg_blog_ids = array(0); } $query = "SELECT *\n\t\t\t\tFROM {$wpdb->blogs}\n\t\t\t\tWHERE site_id = '{$wpdb->siteid}'\n\t\t\t\tAND {$wpdb->blogs}.blog_id IN (" . implode(', ', $reg_blog_ids) . ")"; } else { if (is_numeric($s) && empty($wild)) { $query .= $wpdb->prepare(" AND ( {$wpdb->blogs}.blog_id = %s )", $s); } elseif (is_subdomain_install()) { $blog_s = str_replace('.' . $current_site->domain, '', $s); $blog_s = $wpdb->esc_like($blog_s) . $wild . $wpdb->esc_like('.' . $current_site->domain); $query .= $wpdb->prepare(" AND ( {$wpdb->blogs}.domain LIKE %s ) ", $blog_s); } else { if ($s != trim('/', $current_site->path)) { $blog_s = $wpdb->esc_like($current_site->path . $s) . $wild . $wpdb->esc_like('/'); } else { $blog_s = $wpdb->esc_like($s); } $query .= $wpdb->prepare(" AND ( {$wpdb->blogs}.path LIKE %s )", $blog_s); } } $order_by = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : ''; if ($order_by === 'registered') { $query .= ' ORDER BY registered '; } elseif ($order_by === 'lastupdated') { $query .= ' ORDER BY last_updated '; } elseif ($order_by === 'blogname') { if (is_subdomain_install()) { $query .= ' ORDER BY domain '; } else { $query .= ' ORDER BY path '; } } elseif ($order_by === 'blog_id') { $query .= ' ORDER BY blog_id '; } else { $order_by = null; } if (isset($order_by)) { $order = isset($_REQUEST['order']) && 'DESC' === strtoupper($_REQUEST['order']) ? "DESC" : "ASC"; $query .= $order; } // Don't do an unbounded count on large networks if (!wp_is_large_network()) { $total = $wpdb->get_var(str_replace('SELECT *', 'SELECT COUNT( blog_id )', $query)); } $query .= " LIMIT " . intval(($pagenum - 1) * $per_page) . ", " . intval($per_page); $this->items = $wpdb->get_results($query, ARRAY_A); if (wp_is_large_network()) { $total = count($this->items); } $this->set_pagination_args(array('total_items' => $total, 'per_page' => $per_page)); }
/** * Prints step 2 for Network installation process. * * @since 3.0.0 */ function network_step2($errors = false) { global $wpdb; $hostname = get_clean_basedomain(); $slashed_home = trailingslashit(get_option('home')); $base = parse_url($slashed_home, PHP_URL_PATH); $document_root_fix = str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT'])); $abspath_fix = str_replace('\\', '/', ABSPATH); $home_path = 0 === strpos($abspath_fix, $document_root_fix) ? $document_root_fix . $base : get_home_path(); $wp_siteurl_subdir = preg_replace('#^' . preg_quote($home_path, '#') . '#', '', $abspath_fix); $rewrite_base = !empty($wp_siteurl_subdir) ? ltrim(trailingslashit($wp_siteurl_subdir), '/') : ''; $location_of_wp_config = ABSPATH; if (!file_exists(ABSPATH . 'wp-config.php') && file_exists(dirname(ABSPATH) . '/wp-config.php')) { $location_of_wp_config = trailingslashit(dirname(ABSPATH)); } // Wildcard DNS message. if (is_wp_error($errors)) { echo '<div class="error">' . $errors->get_error_message() . '</div>'; } if ($_POST) { if (allow_subdomain_install()) { $subdomain_install = allow_subdirectory_install() ? !empty($_POST['subdomain_install']) : true; } else { $subdomain_install = false; } } else { if (is_multisite()) { $subdomain_install = is_subdomain_install(); ?> <p><?php _e('The original configuration steps are shown here for reference.'); ?> </p> <?php } else { $subdomain_install = (bool) $wpdb->get_var("SELECT meta_value FROM {$wpdb->sitemeta} WHERE site_id = 1 AND meta_key = 'subdomain_install'"); ?> <div class="error"><p><strong><?php _e('Warning:'); ?> </strong> <?php _e('An existing WordPress network was detected.'); ?> </p></div> <p><?php _e('Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.'); ?> </p> <?php } } $subdir_match = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?'; $subdir_replacement_01 = $subdomain_install ? '' : '$1'; $subdir_replacement_12 = $subdomain_install ? '$1' : '$2'; if ($_POST || !is_multisite()) { ?> <h3><?php esc_html_e('Enabling the Network'); ?> </h3> <p><?php _e('Complete the following steps to enable the features for creating a network of sites.'); ?> </p> <div class="updated inline"><p><?php if (file_exists($home_path . '.htaccess')) { printf(__('<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.'), '.htaccess'); } elseif (file_exists($home_path . 'web.config')) { printf(__('<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.'), 'web.config'); } else { _e('<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> file.'); } ?> </p></div> <?php } ?> <ol> <li><p><?php printf(__('Add the following to your <code>wp-config.php</code> file in <code>%s</code> <strong>above</strong> the line reading <code>/* That’s all, stop editing! Happy blogging. */</code>:'), $location_of_wp_config); ?> </p> <textarea class="code" readonly="readonly" cols="100" rows="6"> define('MULTISITE', true); define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> ); define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?> '); define('PATH_CURRENT_SITE', '<?php echo $base; ?> '); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1);</textarea> <?php $keys_salts = array('AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => ''); foreach ($keys_salts as $c => $v) { if (defined($c)) { unset($keys_salts[$c]); } } if (!empty($keys_salts)) { $keys_salts_str = ''; $from_api = wp_remote_get('https://api.wordpress.org/secret-key/1.1/salt/'); if (is_wp_error($from_api)) { foreach ($keys_salts as $c => $v) { $keys_salts_str .= "\ndefine( '{$c}', '" . wp_generate_password(64, true, true) . "' );"; } } else { $from_api = explode("\n", wp_remote_retrieve_body($from_api)); foreach ($keys_salts as $c => $v) { $keys_salts_str .= "\ndefine( '{$c}', '" . substr(array_shift($from_api), 28, 64) . "' );"; } } $num_keys_salts = count($keys_salts); ?> <p><?php echo _n('This unique authentication key is also missing from your <code>wp-config.php</code> file.', 'These unique authentication keys are also missing from your <code>wp-config.php</code> file.', $num_keys_salts); ?> <?php _e('To make your installation more secure, you should also add:'); ?> </p> <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?> "><?php echo esc_textarea($keys_salts_str); ?> </textarea> <?php } ?> </li> <?php if (iis7_supports_permalinks()) { // IIS doesn't support RewriteBase, all your RewriteBase are belong to us $iis_subdir_match = ltrim($base, '/') . $subdir_match; $iis_rewrite_base = ltrim($base, '/') . $rewrite_base; $iis_subdir_replacement = $subdomain_install ? '' : '{R:1}'; $web_config_file = '<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="WordPress Rule 1" stopProcessing="true"> <match url="^index\\.php$" ignoreCase="false" /> <action type="None" /> </rule>'; if (is_multisite() && get_site_option('ms_files_rewriting')) { $web_config_file .= ' <rule name="WordPress Rule for Files" stopProcessing="true"> <match url="^' . $iis_subdir_match . 'files/(.+)" ignoreCase="false" /> <action type="Rewrite" url="' . $iis_rewrite_base . 'wp-includes/ms-files.php?file={R:1}" appendQueryString="false" /> </rule>'; } $web_config_file .= ' <rule name="WordPress Rule 2" stopProcessing="true"> <match url="^' . $iis_subdir_match . 'wp-admin$" ignoreCase="false" /> <action type="Redirect" url="' . $iis_subdir_replacement . 'wp-admin/" redirectType="Permanent" /> </rule> <rule name="WordPress Rule 3" stopProcessing="true"> <match url="^" ignoreCase="false" /> <conditions logicalGrouping="MatchAny"> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" /> </conditions> <action type="None" /> </rule> <rule name="WordPress Rule 4" stopProcessing="true"> <match url="^' . $iis_subdir_match . '(wp-(content|admin|includes).*)" ignoreCase="false" /> <action type="Rewrite" url="' . $iis_rewrite_base . '{R:1}" /> </rule> <rule name="WordPress Rule 5" stopProcessing="true"> <match url="^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.*\\.php)$" ignoreCase="false" /> <action type="Rewrite" url="' . $iis_rewrite_base . '{R:2}" /> </rule> <rule name="WordPress Rule 6" stopProcessing="true"> <match url="." ignoreCase="false" /> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration>'; ?> <li><p><?php printf(__('Add the following to your <code>web.config</code> file in <code>%s</code>, replacing other WordPress rules:'), $home_path); ?> </p> <?php if (!$subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content') { echo '<p><strong>' . __('Warning:') . ' ' . __('Subdirectory networks may not be fully compatible with custom wp-content directories.') . '</strong></p>'; } ?> <textarea class="code" readonly="readonly" cols="100" rows="20"><?php echo esc_textarea($web_config_file); ?> </textarea></li> </ol> <?php } else { // end iis7_supports_permalinks(). construct an htaccess file instead: $ms_files_rewriting = ''; if (is_multisite() && get_site_option('ms_files_rewriting')) { $ms_files_rewriting = "\n# uploaded files\nRewriteRule ^"; $ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}wp-includes/ms-files.php?file={$subdir_replacement_12} [L]" . "\n"; } $htaccess_file = <<<EOF RewriteEngine On RewriteBase {$base} RewriteRule ^index\\.php\$ - [L] {$ms_files_rewriting} # add a trailing slash to /wp-admin RewriteRule ^{$subdir_match}wp-admin\$ {$subdir_replacement_01}wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^{$subdir_match}(wp-(content|admin|includes).*) {$rewrite_base}{$subdir_replacement_12} [L] RewriteRule ^{$subdir_match}(.*\\.php)\$ {$rewrite_base}{$subdir_replacement_12} [L] RewriteRule . index.php [L] EOF; ?> <li><p><?php printf(__('Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:'), $home_path); ?> </p> <?php if (!$subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content') { echo '<p><strong>' . __('Warning:') . ' ' . __('Subdirectory networks may not be fully compatible with custom wp-content directories.') . '</strong></p>'; } ?> <textarea class="code" readonly="readonly" cols="100" rows="<?php echo substr_count($htaccess_file, "\n") + 1; ?> "> <?php echo esc_textarea($htaccess_file); ?> </textarea></li> </ol> <?php } // end IIS/Apache code branches. if (!is_multisite()) { ?> <p><?php printf(__('Once you complete these steps, your network is enabled and configured. You will have to log in again.')); ?> <a href="<?php echo esc_url(site_url('wp-login.php')); ?> "><?php _e('Log In'); ?> </a></p> <?php } }
/** * Create a site. * * This function runs when a user self-registers a new site as well * as when a Super Admin creates a new site. Hook to 'wpmu_new_blog' * for events that should affect all new sites. * * On subdirectory installs, $domain is the same as the main site's * domain, and the path is the subdirectory name (eg 'example.com' * and '/blog1/'). On subdomain installs, $domain is the new subdomain + * root domain (eg 'blog1.example.com'), and $path is '/'. * * @since MU * @uses domain_exists() * @uses insert_blog() * @uses wp_install_defaults() * @uses add_user_to_blog() * * @param string $domain The new site's domain. * @param string $path The new site's path. * @param string $title The new site's title. * @param int $user_id The user ID of the new site's admin. * @param array $meta Optional. Used to set initial site options. * @param int $site_id Optional. Only relevant on multi-network installs. * @return mixed Returns WP_Error object on failure, int $blog_id on success */ function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) { $domain = preg_replace('/\\s+/', '', sanitize_user($domain, true)); if (is_subdomain_install()) { $domain = str_replace('@', '', $domain); } $title = strip_tags($title); $user_id = (int) $user_id; if (empty($path)) { $path = '/'; } // Check if the domain has been used already. We should return an error message. if (domain_exists($domain, $path, $site_id)) { return new WP_Error('blog_taken', __('Site already exists.')); } if (!defined('WP_INSTALLING')) { define('WP_INSTALLING', true); } if (!($blog_id = insert_blog($domain, $path, $site_id))) { return new WP_Error('insert_blog', __('Could not create site.')); } switch_to_blog($blog_id); install_blog($blog_id, $title); wp_install_defaults($user_id); add_user_to_blog($blog_id, $user_id, 'administrator'); if (is_array($meta)) { foreach ($meta as $key => $value) { if ($key == 'public' || $key == 'archived' || $key == 'mature' || $key == 'spam' || $key == 'deleted' || $key == 'lang_id') { update_blog_status($blog_id, $key, $value); } else { update_option($key, $value); } } } add_option('WPLANG', get_site_option('WPLANG')); update_option('blog_public', (int) $meta['public']); if (!is_super_admin() && !get_user_meta($user_id, 'primary_blog', true)) { update_user_meta($user_id, 'primary_blog', $blog_id); } restore_current_blog(); do_action('wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta); return $blog_id; }
/** * Get a full blog URL, given a domain and a path. * * @since MU * @deprecated 3.7.0 * * @param string $domain * @param string $path * @return string */ function get_blogaddress_by_domain($domain, $path) { _deprecated_function(__FUNCTION__, '3.7.0'); if (is_subdomain_install()) { $url = "http://" . $domain . $path; } else { if ($domain != $_SERVER['HTTP_HOST']) { $blogname = substr($domain, 0, strpos($domain, '.')); $url = 'http://' . substr($domain, strpos($domain, '.') + 1) . $path; // we're not installing the main blog if ($blogname != 'www.') { $url .= $blogname . '/'; } } else { // main blog $url = 'http://' . $domain . $path; } } return esc_url_raw($url); }
function avoid_blog_page_permalink_collision( $data, $postarr ) { if ( is_subdomain_install() ) return $data; if ( $data['post_type'] != 'page' ) return $data; if ( !isset( $data['post_name'] ) || $data['post_name'] == '' ) return $data; if ( !is_main_site() ) return $data; $post_name = $data['post_name']; $c = 0; while( $c < 10 && get_id_from_blogname( $post_name ) ) { $post_name .= mt_rand( 1, 10 ); $c ++; } if ( $post_name != $data['post_name'] ) { $data['post_name'] = $post_name; } return $data; }
/** * Removes unneeded query variables from the URL. * @return boolean */ public function clean_permalink() { if (is_robots() || get_query_var('sitemap')) { return false; } global $wp_query; // Recreate current URL $cururl = 'http'; if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { $cururl .= 's'; } $cururl .= '://'; if ($_SERVER['SERVER_PORT'] != '80' && $_SERVER['SERVER_PORT'] != '443') { $cururl .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']; } else { $cururl .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; } $properurl = ''; if (is_singular()) { global $post; if (empty($post)) { $post = $wp_query->get_queried_object(); } $properurl = get_permalink($post->ID); $page = get_query_var('page'); if ($page && $page != 1) { $post = get_post($post->ID); $page_count = substr_count($post->post_content, '<!--nextpage-->'); if ($page > $page_count + 1) { $properurl = user_trailingslashit(trailingslashit($properurl) . ($page_count + 1)); } else { $properurl = user_trailingslashit(trailingslashit($properurl) . $page); } } // Fix reply to comment links, whoever decided this should be a GET variable? $result = preg_match('`(\\?replytocom=[^&]+)`', $_SERVER['REQUEST_URI'], $matches); if ($result) { $properurl .= str_replace('?replytocom=', '#comment-', $matches[0]); } // Prevent cleaning out posts & page previews for people capable of viewing them if (isset($_GET['preview']) && isset($_GET['preview_nonce']) && current_user_can('edit_post')) { $properurl = ''; } } elseif (is_front_page()) { if ($this->is_home_posts_page()) { $properurl = get_bloginfo('url') . '/'; } elseif ($this->is_home_static_page()) { global $post; $properurl = get_permalink($post->ID); } } elseif (is_category() || is_tag() || is_tax()) { $term = $wp_query->get_queried_object(); if (is_feed()) { $properurl = get_term_feed_link($term->term_id, $term->taxonomy); } else { $properurl = get_term_link($term, $term->taxonomy); } } elseif (is_search()) { $s = preg_replace('`(%20|\\+)`', ' ', get_search_query()); $properurl = get_bloginfo('url') . '/?s=' . rawurlencode($s); } elseif (is_404()) { if (function_exists('is_multisite') && is_multisite() && !is_subdomain_install() && is_main_site()) { if ($cururl == get_bloginfo('url') . '/blog/' || $cururl == get_bloginfo('url') . '/blog') { if ($this->is_home_static_page()) { $properurl = get_permalink(get_option('page_for_posts')); } else { $properurl = get_bloginfo('url') . '/'; } } } } if (!empty($properurl) && $wp_query->query_vars['paged'] != 0 && $wp_query->post_count != 0) { if (is_search()) { $properurl = get_bloginfo('url') . '/page/' . $wp_query->query_vars['paged'] . '/?s=' . rawurlencode(get_search_query()); } else { $properurl = user_trailingslashit(trailingslashit($properurl) . 'page/' . $wp_query->query_vars['paged']); } } // Prevent cleaning out the WP Subscription managers interface for everyone if (isset($_GET['wp-subscription-manager'])) { $properurl = ''; } /** * Filter: 'wpseo_whitelist_permalink_vars' - Allow plugins to register their own variables not to clean * * @api array $unsigned Array of permalink variables _not_ to clean. Empty by default. */ $whitelisted_extravars = apply_filters('wpseo_whitelist_permalink_vars', array()); if ($this->options['cleanpermalink-googlesitesearch'] === true) { // Prevent cleaning out Google Site searches $whitelisted_extravars = array_merge($whitelisted_extravars, array('q', 'cx', 'debug', 'cof', 'ie', 'sa')); } if ($this->options['cleanpermalink-googlecampaign'] === true) { // Prevent cleaning out Google Analytics campaign variables $whitelisted_extravars = array_merge($whitelisted_extravars, array('utm_campaign', 'utm_medium', 'utm_source', 'utm_content', 'utm_term', 'utm_id', 'gclid')); } if ($this->options['cleanpermalink-extravars'] !== '') { $extravars = explode(',', $this->options['cleanpermalink-extravars']); $extravars = array_map('trim', $extravars); $whitelisted_extravars = array_merge($whitelisted_extravars, $extravars); unset($extravars); } foreach ($whitelisted_extravars as $get) { if (isset($_GET[trim($get)])) { $properurl = ''; } } if (!empty($properurl) && $cururl != $properurl) { wp_safe_redirect($properurl, 301); exit; } }
/** * Initiate a player object based on shortcode values and possible blog-level option overrides * * @since 1.3 * @var string $guid VideoPress unique identifier * @var int $maxwidth maximum desired width of the video player if specified * @var array $options player customizations */ public function __construct($guid, $maxwidth = 0, $options = array()) { if (empty(self::$shown[$guid])) { self::$shown[$guid] = 0; } self::$shown[$guid]++; $this->video_container_id = 'v-' . $guid . '-' . self::$shown[$guid]; $this->video_id = $this->video_container_id . '-video'; if (is_array($options)) { $this->options = $options; } else { $this->options = array(); } // set up the video $cache_key = null; // disable cache in debug mode if (defined('WP_DEBUG') && WP_DEBUG === true) { $cached_video = null; } else { $cache_key_pieces = array('video'); if (is_multisite() && is_subdomain_install()) { $cache_key_pieces[] = get_current_blog_id(); } $cache_key_pieces[] = $guid; if ($maxwidth > 0) { $cache_key_pieces[] = $maxwidth; } if (is_ssl()) { $cache_key_pieces[] = 'ssl'; } $cache_key = implode('-', $cache_key_pieces); unset($cache_key_pieces); $cached_video = wp_cache_get($cache_key, 'video'); } if (empty($cached_video)) { $video = new VideoPress_Video($guid, $maxwidth); if (empty($video)) { return; } elseif (isset($video->error)) { $this->video = $video->error; return; } elseif (is_wp_error($video)) { $this->video = $video; return; } $this->video = $video; unset($video); if (!defined('WP_DEBUG') || WP_DEBUG !== true) { $expire = 3600; if (isset($video->expires) && is_int($video->expires)) { $expires_diff = time() - $video->expires; if ($expires_diff > 0 && $expires_diff < 86400) { // allowed range: 1 second to 1 day $expire = $expires_diff; } unset($expires_diff); } wp_cache_set($cache_key, serialize($this->video), 'video', $expire); unset($expire); } } else { $this->video = unserialize($cached_video); } unset($cache_key); unset($cached_video); }
echo esc_html($title); ?> </h1> <form name="form" action="options-permalink.php" method="post"> <?php wp_nonce_field('update-permalink'); ?> <p><?php _e('By default WordPress uses web <abbr title="Universal Resource Locator">URL</abbr>s which have question marks and lots of numbers in them; however, WordPress offers you the ability to create a custom URL structure for your permalinks and archives. This can improve the aesthetics, usability, and forward-compatibility of your links. A <a href="https://codex.wordpress.org/Using_Permalinks">number of tags are available</a>, and here are some examples to get you started.'); ?> </p> <?php if (is_multisite() && !is_subdomain_install() && is_main_site()) { $permalink_structure = preg_replace('|^/?blog|', '', $permalink_structure); $category_base = preg_replace('|^/?blog|', '', $category_base); $tag_base = preg_replace('|^/?blog|', '', $tag_base); } $structures = array(0 => '', 1 => $prefix . '/%year%/%monthnum%/%day%/%postname%/', 2 => $prefix . '/%year%/%monthnum%/%postname%/', 3 => $prefix . '/' . _x('archives', 'sample permalink base') . '/%post_id%', 4 => $prefix . '/%postname%/'); ?> <h2 class="title"><?php _e('Common Settings'); ?> </h2> <table class="form-table permalink-structure"> <tr> <th><label><input name="selection" type="radio" value="" <?php checked('', $permalink_structure); ?>
/** * Retrieve the details for a blog from the blogs table and blog options. * * @since MU * * @param int|string|array $fields A blog ID, a blog slug, or an array of fields to query against. Optional. If not specified the current blog ID is used. * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true. * @return object Blog details. */ function get_blog_details($fields = null, $get_all = true) { global $wpdb; if (is_array($fields)) { if (isset($fields['blog_id'])) { $blog_id = $fields['blog_id']; } elseif (isset($fields['domain']) && isset($fields['path'])) { $key = md5($fields['domain'] . $fields['path']); $blog = wp_cache_get($key, 'blog-lookup'); if (false !== $blog) { return $blog; } if (substr($fields['domain'], 0, 4) == 'www.') { $nowww = substr($fields['domain'], 4); $blog = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->blogs} WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'])); } else { $blog = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'])); } if ($blog) { wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); $blog_id = $blog->blog_id; } else { return false; } } elseif (isset($fields['domain']) && is_subdomain_install()) { $key = md5($fields['domain']); $blog = wp_cache_get($key, 'blog-lookup'); if (false !== $blog) { return $blog; } if (substr($fields['domain'], 0, 4) == 'www.') { $nowww = substr($fields['domain'], 4); $blog = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->blogs} WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'])); } else { $blog = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->blogs} WHERE domain = %s", $fields['domain'])); } if ($blog) { wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); $blog_id = $blog->blog_id; } else { return false; } } else { return false; } } else { if (!$fields) { $blog_id = get_current_blog_id(); } elseif (!is_numeric($fields)) { $blog_id = get_id_from_blogname($fields); } else { $blog_id = $fields; } } $blog_id = (int) $blog_id; $all = $get_all == true ? '' : 'short'; $details = wp_cache_get($blog_id . $all, 'blog-details'); if ($details) { if (!is_object($details)) { if ($details == -1) { return false; } else { // Clear old pre-serialized objects. Cache clients do better with that. wp_cache_delete($blog_id . $all, 'blog-details'); unset($details); } } else { return $details; } } // Try the other cache. if ($get_all) { $details = wp_cache_get($blog_id . 'short', 'blog-details'); } else { $details = wp_cache_get($blog_id, 'blog-details'); // If short was requested and full cache is set, we can return. if ($details) { if (!is_object($details)) { if ($details == -1) { return false; } else { // Clear old pre-serialized objects. Cache clients do better with that. wp_cache_delete($blog_id, 'blog-details'); unset($details); } } else { return $details; } } } if (empty($details)) { $details = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d /* get_blog_details */", $blog_id)); if (!$details) { // Set the full cache. wp_cache_set($blog_id, -1, 'blog-details'); return false; } } if (!$get_all) { wp_cache_set($blog_id . $all, $details, 'blog-details'); return $details; } switch_to_blog($blog_id); $details->blogname = get_option('blogname'); $details->siteurl = get_option('siteurl'); $details->post_count = get_option('post_count'); restore_current_blog(); /** * Filter a blog's details. * * @since MU * * @param object $details The blog details. */ $details = apply_filters('blog_details', $details); wp_cache_set($blog_id . $all, $details, 'blog-details'); $key = md5($details->domain . $details->path); wp_cache_set($key, $details, 'blog-lookup'); return $details; }
public function display_rows() { global $mode; $status_list = array('archived' => array('site-archived', __('Archived')), 'spam' => array('site-spammed', _x('Spam', 'site')), 'deleted' => array('site-deleted', __('Deleted')), 'mature' => array('site-mature', __('Mature'))); if ('list' == $mode) { $date = 'Y/m/d'; } else { $date = 'Y/m/d \\<\\b\\r \\/\\> g:i:s a'; } $class = ''; foreach ($this->items as $blog) { $class = 'alternate' == $class ? '' : 'alternate'; reset($status_list); $blog_states = array(); foreach ($status_list as $status => $col) { if (get_blog_status($blog['blog_id'], $status) == 1) { $class = $col[0]; $blog_states[] = $col[1]; } } $blog_state = ''; if (!empty($blog_states)) { $state_count = count($blog_states); $i = 0; $blog_state .= ' - '; foreach ($blog_states as $state) { ++$i; $i == $state_count ? $sep = '' : ($sep = ', '); $blog_state .= "<span class='post-state'>{$state}{$sep}</span>"; } } echo "<tr class='{$class}'>"; $blogname = is_subdomain_install() ? str_replace('.' . get_current_site()->domain, '', $blog['domain']) : $blog['path']; list($columns, $hidden) = $this->get_column_info(); foreach ($columns as $column_name => $column_display_name) { $style = ''; if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; } switch ($column_name) { case 'cb': ?> <th scope="row" class="check-column"> <?php if (!is_main_site($blog['blog_id'])) { ?> <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?> "><?php printf(__('Select %s'), $blogname); ?> </label> <input type="checkbox" id="blog_<?php echo $blog['blog_id']; ?> " name="allblogs[]" value="<?php echo esc_attr($blog['blog_id']); ?> " /> <?php } ?> </th> <?php break; case 'id': ?> <th scope="row"> <?php echo $blog['blog_id']; ?> </th> <?php break; case 'blogname': echo "<td class='column-{$column_name} {$column_name}'{$style}>"; ?> <a href="<?php echo esc_url(network_admin_url('site-info.php?id=' . $blog['blog_id'])); ?> " class="edit"><?php echo $blogname . $blog_state; ?> </a> <?php if ('list' != $mode) { switch_to_blog($blog['blog_id']); echo '<p>' . sprintf(_x('%1$s – <em>%2$s</em>', '%1$s: site name. %2$s: site tagline.'), get_option('blogname'), get_option('blogdescription ')) . '</p>'; restore_current_blog(); } // Preordered. $actions = array('edit' => '', 'backend' => '', 'activate' => '', 'deactivate' => '', 'archive' => '', 'unarchive' => '', 'spam' => '', 'unspam' => '', 'delete' => '', 'visit' => ''); $actions['edit'] = '<span class="edit"><a href="' . esc_url(network_admin_url('site-info.php?id=' . $blog['blog_id'])) . '">' . __('Edit') . '</a></span>'; $actions['backend'] = "<span class='backend'><a href='" . esc_url(get_admin_url($blog['blog_id'])) . "' class='edit'>" . __('Dashboard') . '</a></span>'; if (get_current_site()->blog_id != $blog['blog_id']) { if (get_blog_status($blog['blog_id'], 'deleted') == '1') { $actions['activate'] = '<span class="activate"><a href="' . esc_url(wp_nonce_url(network_admin_url('sites.php?action=confirm&action2=activateblog&id=' . $blog['blog_id'] . '&msg=' . urlencode(sprintf(__('You are about to activate the site %s'), $blogname))), 'confirm')) . '">' . __('Activate') . '</a></span>'; } else { $actions['deactivate'] = '<span class="activate"><a href="' . esc_url(wp_nonce_url(network_admin_url('sites.php?action=confirm&action2=deactivateblog&id=' . $blog['blog_id'] . '&msg=' . urlencode(sprintf(__('You are about to deactivate the site %s'), $blogname))), 'confirm')) . '">' . __('Deactivate') . '</a></span>'; } if (get_blog_status($blog['blog_id'], 'archived') == '1') { $actions['unarchive'] = '<span class="archive"><a href="' . esc_url(wp_nonce_url(network_admin_url('sites.php?action=confirm&action2=unarchiveblog&id=' . $blog['blog_id'] . '&msg=' . urlencode(sprintf(__('You are about to unarchive the site %s.'), $blogname))), 'confirm')) . '">' . __('Unarchive') . '</a></span>'; } else { $actions['archive'] = '<span class="archive"><a href="' . esc_url(wp_nonce_url(network_admin_url('sites.php?action=confirm&action2=archiveblog&id=' . $blog['blog_id'] . '&msg=' . urlencode(sprintf(__('You are about to archive the site %s.'), $blogname))), 'confirm')) . '">' . _x('Archive', 'verb; site') . '</a></span>'; } if (get_blog_status($blog['blog_id'], 'spam') == '1') { $actions['unspam'] = '<span class="spam"><a href="' . esc_url(wp_nonce_url(network_admin_url('sites.php?action=confirm&action2=unspamblog&id=' . $blog['blog_id'] . '&msg=' . urlencode(sprintf(__('You are about to unspam the site %s.'), $blogname))), 'confirm')) . '">' . _x('Not Spam', 'site') . '</a></span>'; } else { $actions['spam'] = '<span class="spam"><a href="' . esc_url(wp_nonce_url(network_admin_url('sites.php?action=confirm&action2=spamblog&id=' . $blog['blog_id'] . '&msg=' . urlencode(sprintf(__('You are about to mark the site %s as spam.'), $blogname))), 'confirm')) . '">' . _x('Spam', 'site') . '</a></span>'; } if (current_user_can('delete_site', $blog['blog_id'])) { $actions['delete'] = '<span class="delete"><a href="' . esc_url(wp_nonce_url(network_admin_url('sites.php?action=confirm&action2=deleteblog&id=' . $blog['blog_id'] . '&msg=' . urlencode(sprintf(__('You are about to delete the site %s.'), $blogname))), 'confirm')) . '">' . __('Delete') . '</a></span>'; } } $actions['visit'] = "<span class='view'><a href='" . esc_url(get_home_url($blog['blog_id'], '/')) . "' rel='permalink'>" . __('Visit') . '</a></span>'; /** * Filter the action links displayed for each site in the Sites list table. * * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by * default for each site. The site's status determines whether to show the * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and * 'Not Spam' or 'Spam' link for each site. * * @since 3.1.0 * * @param array $actions An array of action links to be displayed. * @param int $blog_id The site ID. * @param string $blogname Site path, formatted depending on whether it is a sub-domain * or subdirectory multisite install. */ $actions = apply_filters('manage_sites_action_links', array_filter($actions), $blog['blog_id'], $blogname); echo $this->row_actions($actions); ?> </td> <?php break; case 'lastupdated': echo "<td class='{$column_name} column-{$column_name}'{$style}>"; echo $blog['last_updated'] == '0000-00-00 00:00:00' ? __('Never') : mysql2date($date, $blog['last_updated']); ?> </td> <?php break; case 'registered': echo "<td class='{$column_name} column-{$column_name}'{$style}>"; if ($blog['registered'] == '0000-00-00 00:00:00') { echo '—'; } else { echo mysql2date($date, $blog['registered']); } ?> </td> <?php break; case 'users': echo "<td class='{$column_name} column-{$column_name}'{$style}>"; $blogusers = get_users(array('blog_id' => $blog['blog_id'], 'number' => 6)); if (is_array($blogusers)) { $blogusers_warning = ''; if (count($blogusers) > 5) { $blogusers = array_slice($blogusers, 0, 5); $blogusers_warning = __('Only showing first 5 users.') . ' <a href="' . esc_url(network_admin_url('site-users.php?id=' . $blog['blog_id'])) . '">' . __('More') . '</a>'; } foreach ($blogusers as $user_object) { echo '<a href="' . esc_url(network_admin_url('user-edit.php?user_id=' . $user_object->ID)) . '">' . esc_html($user_object->user_login) . '</a> '; if ('list' != $mode) { echo '( ' . $user_object->user_email . ' )'; } echo '<br />'; } if ($blogusers_warning != '') { echo '<strong>' . $blogusers_warning . '</strong><br />'; } } ?> </td> <?php break; case 'plugins': ?> <?php if (has_filter('wpmublogsaction')) { echo "<td class='{$column_name} column-{$column_name}'{$style}>"; /** * Fires inside the auxiliary 'Actions' column of the Sites list table. * * By default this column is hidden unless something is hooked to the action. * * @since MU * * @param int $blog_id The site ID. */ do_action('wpmublogsaction', $blog['blog_id']); ?> </td> <?php } break; default: echo "<td class='{$column_name} column-{$column_name}'{$style}>"; /** * Fires for each registered custom column in the Sites list table. * * @since 3.1.0 * * @param string $column_name The name of the column to display. * @param int $blog_id The site ID. */ do_action('manage_sites_custom_column', $column_name, $blog['blog_id']); echo "</td>"; break; } } ?> </tr> <?php } }
function create_microweb() { global $_POST, $current_site, $current_user; if (!is_array($_POST['blog'])) { wp_die(__('Can’t create an empty site.')); } $blog = $_POST['blog']; $email = sanitize_email($blog['email']); $title = $blog['title']; $domain = $blog['domain']; if (empty($domain)) { print_r(__('Missing or invalid site address.')); } if (empty($email)) { print_r(__('Missing email address.')); } if (!is_email($email)) { print_r(__('Invalid email address.')); } if (is_subdomain_install()) { $newdomain = $domain . '.' . preg_replace('|^www\\.|', '', $current_site->domain); $path = $current_site->path; } else { $newdomain = $current_site->domain; $path = $current_site->path . $domain . '/'; } $password = '******'; $user_id = email_exists($email); if ($user_id) { $password = wp_generate_password(12, false); $user_id = wp_update_user(array("ID" => $user_id, "user_pass" => $password)); if (false == $user_id) { print_r(__('There was an error updating the user.')); } else { wp_new_user_notification($user_id, $password); } } $id = wpmu_create_blog($newdomain, $path, $title, $user_id, array('public' => 1), $current_site->id); if (!is_wp_error($id)) { update_user_meta($user_id, "agent-web", $path); if (!is_super_admin($user_id) && !get_user_option('primary_blog', $user_id)) { update_user_option($user_id, 'primary_blog', $id, true); } $content_mail = sprintf(__('New site created by %1$s Address: %2$s Name: %3$s'), $current_user->user_login, get_site_url($id), stripslashes($title)); wp_mail(get_site_option('admin_email'), sprintf(__('[%s] New Site Created'), $current_site->site_name), $content_mail, 'From: "Site Admin" <' . get_site_option('admin_email') . '>'); wpmu_welcome_notification($id, $user_id, $password, $title, array('public' => 1)); // wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) ); // exit; } else { wp_die($id->get_error_message()); } }