/**
  * Check that legacy data exists before doing anything
  *
  * @return void
  */
 public static function load()
 {
     // Exit early if there is no option holding the DB version
     if (false === get_site_option('wp_stream_db')) {
         return;
     }
     global $wpdb;
     // If there are no legacy tables found, then attempt to clear all legacy data and exit early
     if (null === $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->base_prefix}stream'")) {
         self::drop_legacy_data(false);
         return;
     }
     self::$site_id = is_multisite() ? get_current_site()->id : 1;
     self::$blog_id = get_current_blog_id();
     $since = WP_Stream::$api->get_plan_retention_max_date();
     self::$record_count = $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT COUNT(*)\n\t\t\t\tFROM {$wpdb->base_prefix}stream AS s, {$wpdb->base_prefix}stream_context AS sc\n\t\t\t\tWHERE s.site_id = %d\n\t\t\t\t\tAND s.blog_id = %d\n\t\t\t\t\tAND s.type = 'stream'\n\t\t\t\t\tAND s.created > %s\n\t\t\t\t\tAND sc.record_id = s.ID\n\t\t\t\t", self::$site_id, self::$blog_id, $since));
     // If there are no legacy records for this site/blog, then attempt to clear all legacy data and exit early
     if (0 === self::$record_count) {
         self::drop_legacy_data();
         return;
     }
     self::$limit = apply_filters('wp_stream_migrate_chunk_size', 100);
     add_action('admin_notices', array(__CLASS__, 'migrate_notice'), 9);
     add_action('wp_ajax_wp_stream_migrate_action', array(__CLASS__, 'process_migrate_action'));
 }
예제 #2
0
파일: site.php 프로젝트: amekusa/WPELib
 /**
  * In a multisite, returns the id of the primary site in the network.
  * Otherwise, returns the same value as get_current_blog_id()
  * @return integer
  */
 static function primary()
 {
     if (is_multisite()) {
         return get_current_site()->blog_id;
     }
     return get_current_blog_id();
 }
    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();
    }
예제 #4
0
 public function log($connector, $message, $args, $object_id, $contexts, $user_id = null)
 {
     global $wpdb;
     if (is_null($user_id)) {
         $user_id = get_current_user_id();
     }
     require_once MAINWP_WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
     $user = new WP_User($user_id);
     $roles = get_option($wpdb->get_blog_prefix() . 'user_roles');
     if (!isset($args['author_meta'])) {
         $args['author_meta'] = array('user_email' => $user->user_email, 'display_name' => defined('WP_CLI') && empty($user->display_name) ? 'WP-CLI' : $user->display_name, 'user_login' => $user->user_login, 'user_role_label' => !empty($user->roles) ? $roles[$user->roles[0]]['name'] : null, 'agent' => MainWP_WP_Stream_Author::get_current_agent());
         if (defined('WP_CLI') && function_exists('posix_getuid')) {
             $uid = posix_getuid();
             $user_info = posix_getpwuid($uid);
             $args['author_meta']['system_user_id'] = $uid;
             $args['author_meta']['system_user_name'] = $user_info['name'];
         }
     }
     // Remove meta with null values from being logged
     $meta = array_filter($args, function ($var) {
         return !is_null($var);
     });
     $recordarr = array('object_id' => $object_id, 'site_id' => is_multisite() ? get_current_site()->id : 1, 'blog_id' => apply_filters('blog_id_logged', is_network_admin() ? 0 : get_current_blog_id()), 'author' => $user_id, 'author_role' => !empty($user->roles) ? $user->roles[0] : null, 'created' => current_time('mysql', 1), 'summary' => vsprintf($message, $args), 'parent' => self::$instance->prev_record, 'connector' => $connector, 'contexts' => $contexts, 'meta' => $meta, 'ip' => mainwp_wp_stream_filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP));
     $record_id = MainWP_WP_Stream_DB::get_instance()->insert($recordarr);
     return $record_id;
 }
예제 #5
0
 protected function setup_constants()
 {
     $domain = strtoupper($this->args['domain']);
     // JUST IN CASE
     defined($domain . '_TEXTDOMAIN') or define($domain . '_TEXTDOMAIN', $this->args['domain']);
     defined($domain . '_ENABLE_MULTIROOTBLOG') or define($domain . '_ENABLE_MULTIROOTBLOG', FALSE);
     if (!defined($domain . '_ROOT_BLOG')) {
         // root blog is the main site on this network
         if (is_multisite() && !constant($domain . '_ENABLE_MULTIROOTBLOG')) {
             $current_site = get_current_site();
             // root blogs for multi-network
             if (defined($domain . '_SITE_ROOT_BLOG_' . $current_site->id)) {
                 $root_blog_id = constant($domain . '_SITE_ROOT_BLOG_' . $current_site->id);
             } else {
                 $root_blog_id = $current_site->blog_id;
             }
             // root blog is every site on this network
         } else {
             if (is_multisite() && constant($domain . '_ENABLE_MULTIROOTBLOG')) {
                 $root_blog_id = $this->current_blog;
                 // root blog is the only blog on this network
             } else {
                 if (!is_multisite()) {
                     $root_blog_id = 1;
                 }
             }
         }
         define($domain . '_ROOT_BLOG', $root_blog_id);
     }
 }
/**
 * Get the "dashboard blog", the blog where users without a blog edit their profile data.
 * Dashboard blog functionality was removed in WordPress 3.1, replaced by the user admin.
 *
 * @since MU
 * @deprecated 3.1.0 Use get_blog_details()
 * @see get_blog_details()
 *
 * @return int Current site ID.
 */
function get_dashboard_blog()
{
    _deprecated_function(__FUNCTION__, '3.1.0');
    if ($blog = get_site_option('dashboard_blog')) {
        return get_blog_details($blog);
    }
    return get_blog_details(get_current_site()->blog_id);
}
예제 #7
0
 function override_base_var()
 {
     global $base;
     if (!is_multisite()) {
         return;
     }
     $base = get_current_site()->path;
 }
 /**
  * ## OPTIONS
  *
  * [<network>]
  * : Network ID (defaults to current network, use `--url=...`)
  *
  * [--format=<format>]
  * : Format to display as (table, json, csv, count)
  *
  * @subcommand list
  */
 public function list_($args, $assoc_args)
 {
     $id = empty($args[0]) ? get_current_site()->id : absint($args[0]);
     $mappings = Network_Mapping::get_by_network($id);
     if (empty($mappings)) {
         return;
     }
     $this->display($mappings, $assoc_args);
 }
예제 #9
0
function comicpress_profile_members_only()
{
    global $profileuser, $errormsg;
    $comicpress_is_member = get_user_meta($profileuser->ID, 'comicpress-is-member', true);
    if (empty($comicpress_is_member)) {
        $comicpress_is_member = 0;
    }
    $site_name = get_option('blogname');
    if (is_multisite()) {
        $current_site = get_current_site();
        if (!isset($current_site->site_name)) {
            $site_name = ucfirst($current_site->domain);
        } else {
            $site_name = $current_site->site_name;
        }
    }
    ?>
	<div style="border: solid 1px #aaa; background: #eee; padding: 0 10px 10px;">
	<h3><?php 
    _e('Member of', 'comicpress');
    ?>
 <?php 
    echo $site_name;
    ?>
</h3>
	<table class="form-table">
	<tr>
		<th><label for="Memberflag"><?php 
    _e('Member?', 'comicpress');
    ?>
</label></th>
		<td> 
	<?php 
    if (current_user_can('edit_users') || is_super_admin()) {
        ?>
			<input id="comicpress-is-member" name="comicpress-is-member" type="checkbox" value="1" <?php 
        checked(true, $comicpress_is_member);
        ?>
 />		
	<?php 
    } else {
        if ($comicpress_is_member) {
            echo 'Is Member';
        } else {
            echo 'Not a Member';
        }
    }
    ?>
		</td>
	</tr>
	</table>
	</div>
	<br />
	<br />
<?php 
}
 /**
  * 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;
 }
예제 #11
0
 function subdomain_body_class($classes)
 {
     global $subdomain;
     $site = get_current_site()->domain;
     $url = get_bloginfo('url');
     $sub = preg_replace('@http://@i', '', $url);
     $sub = preg_replace('@' . $site . '@i', '', $sub);
     $sub = preg_replace('@\\.@i', '', $sub);
     $classes[] = 'site-' . $sub;
     $subdomain = $sub;
     return $classes;
 }
function ra_bp_multinetwork_meta_key_filter($key)
{
    global $wpdb;
    static $user_meta_keys = array('last_activity' => false, 'bp_new_mention_count' => false, 'bp_favorite_activities' => false, 'bp_latest_update' => false, 'total_friend_count' => false, 'total_group_count' => false, 'notification_groups_group_updated' => false, 'notification_groups_membership_request' => false, 'notification_membership_request_completed' => false, 'notification_groups_admin_promotion' => false, 'notification_groups_invite' => false, 'notification_messages_new_message' => false, 'notification_messages_new_notice' => false, 'closed_notices' => false, 'profile_last_updated' => false, 'notification_activity_new_mention' => false, 'notification_activity_new_reply' => false);
    if ($wpdb->siteid < 2 || !isset($user_meta_keys[$key])) {
        return $key;
    }
    if (!$user_meta_keys[$key]) {
        $current_site = get_current_site();
        $user_meta_keys[$key] = $wpdb->get_blog_prefix($current_site->blog_id) . $key;
    }
    return $user_meta_keys[$key];
}
예제 #13
0
 function comicpress_hosted_on()
 {
     if (is_multisite()) {
         $current_site = get_current_site();
         if (!isset($current_site->site_name)) {
             $site_name = ucfirst($current_site->domain);
         } else {
             $site_name = $current_site->site_name;
         }
         $output = "<span class=\"footer-pipe\">|</span> ";
         $output .= __('Hosted on', 'comicpress') . ' <a href="http://' . $current_site->domain . $current_site->path . '">' . $site_name . '</a> ';
         return apply_filters('comicpress_hosted_on', $output);
     }
 }
예제 #14
0
 /**
  * Resets `crons_setup` and clears WP-Cron schedules.
  *
  * @since 151220 Fixing bug with Auto-Cache Engine cron disappearing in some scenarios
  *
  * @note This MUST happen upon uninstall and deactivation due to buggy WP_Cron behavior. Events with a custom schedule will disappear when plugin is not active (see http://bit.ly/1lGdr78).
  */
 public function resetCronSetup()
 {
     if (is_multisite()) {
         // Main site CRON jobs.
         switch_to_blog(get_current_site()->blog_id);
         wp_clear_scheduled_hook('_cron_' . GLOBAL_NS . '_cleanup');
         restore_current_blog();
         // Restore current blog.
     } else {
         // Standard WP installation.
         wp_clear_scheduled_hook('_cron_' . GLOBAL_NS . '_cleanup');
     }
     $this->updateOptions(['crons_setup' => $this->default_options['crons_setup'], 'crons_setup_on_namespace' => $this->default_options['crons_setup_on_namespace'], 'crons_setup_with_cache_cleanup_schedule' => $this->default_options['crons_setup_with_cache_cleanup_schedule'], 'crons_setup_on_wp_with_schedules' => $this->default_options['crons_setup_on_wp_with_schedules']]);
 }
예제 #15
0
/**
 * Add a bu-navigation site if this plugin is being tested by lettuce.
 * This sets up for the "User is warned when leaving changes" scenario
 */
function bu_navigation_sandbox_init($response, $coverage, $users)
{
    if (in_array('plugin-bu-navigation', $coverage)) {
        $network = get_current_site();
        $domain = $network->domain;
        $admin_id = get_current_user_id();
        $options = array('users' => array('site_admin' => array($users['site_admin']), 'contributor' => array($users['contributor'])), 'network_id' => $network->id);
        // Public site, no ACL
        $path = '/bu-navigation/';
        $title = 'BU Navigation';
        $site_id = bu_create_site($domain, $path, $title, $admin_id, $options);
        bu_navigation_sandbox_setup_site($response, $site_id, 'bu-navigation');
    }
}
예제 #16
0
 /**
  * Run the deactivation script on every blog for a multisite install
  *
  * @return void
  */
 protected function multisite_deactivate()
 {
     /** @var wpdb $wpdb */
     global $wpdb;
     $site = get_current_site();
     $blog_ids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE site_id=%d", $site->id));
     $large = wp_is_large_network();
     foreach ($blog_ids as $blog) {
         set_time_limit(30);
         switch_to_blog($blog);
         $large ? $this->short_blog_deactivate() : $this->blog_deactivate();
         restore_current_blog();
     }
 }
 /**
  * Get the ID prefix for AWS documents
  *
  * @return string
  */
 public static function get_document_id_prefix()
 {
     // generate prefix if we haven't already
     if (empty(self::$document_id_prefix)) {
         if (is_multisite()) {
             $site = get_current_site();
             self::$document_id_prefix = $site->id;
         } else {
             self::$document_id_prefix = 1;
         }
         self::$document_id_prefix .= '_' . get_current_blog_id() . '_';
         self::$document_id_prefix = apply_filters('lift_document_id_prefix', self::$document_id_prefix);
     }
     return self::$document_id_prefix;
 }
예제 #18
0
 /**
  * Test to see if executing an AJAX call specific to the WP Migrate DB family of plugins.
  *
  * @return bool
  */
 public static function is_ajax()
 {
     // must be doing AJAX the WordPress way
     if (!defined('DOING_AJAX') || !DOING_AJAX) {
         return false;
     }
     // must be one of our actions -- e.g. core plugin (wpmdb_*), media files (wpmdbmf_*)
     if (!isset($_POST['action']) || 0 !== strpos($_POST['action'], 'wpmdb')) {
         return false;
     }
     // must be on blog #1 (first site) if multisite
     if (is_multisite() && 1 != get_current_site()->id) {
         return false;
     }
     return true;
 }
예제 #19
0
 function vibe_header_essentials()
 {
     $favicon = vibe_get_option('favicon');
     if (!isset($favicon)) {
         $favicon = VIBE_URL . '/images/favicon.png';
     }
     echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">
             <meta name="author" content="' . get_current_site() . '">
             <link rel="shortcut icon" href="' . $favicon . '" />
             <link rel="icon" type="image/png" href="' . $favicon . '">
             <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
             <!--[if lt IE 9]>
               <script src="' . VIBE_URL . '/js/html5shiv.js"></script>
               <script src="' . VIBE_URL . '/js/respond.min.js"></script>
             <![endif]-->';
 }
예제 #20
0
 /**
  * Log handler
  *
  * @param Connector $connector Connector responsible for logging the event
  * @param string $message      sprintf-ready error message string
  * @param array  $args         sprintf (and extra) arguments to use
  * @param int $object_id       Target object id
  * @param string $context      Context of the event
  * @param string $action       Action of the event
  * @param int $user_id         User responsible for the event
  *
  * @return mixed True if updated, otherwise false|WP_Error
  */
 public function log($connector, $message, $args, $object_id, $context, $action, $user_id = null)
 {
     if (is_null($user_id)) {
         $user_id = get_current_user_id();
     }
     if (is_null($object_id)) {
         $object_id = 0;
     }
     $wp_cron_tracking = isset($this->plugin->settings->options['advanced_wp_cron_tracking']) ? $this->plugin->settings->options['advanced_wp_cron_tracking'] : false;
     $author = new Author($user_id);
     $agent = $author->get_current_agent();
     // WP Cron tracking requires opt-in and WP Cron to be enabled
     if (!$wp_cron_tracking && 'wp_cron' === $agent) {
         return false;
     }
     $user = new \WP_User($user_id);
     if ($this->is_record_excluded($connector, $context, $action, $user)) {
         return false;
     }
     $user_meta = array('user_email' => (string) (!empty($user->user_email)) ? $user->user_email : '', 'display_name' => (string) $author->get_display_name(), 'user_login' => (string) (!empty($user->user_login)) ? $user->user_login : '', 'user_role_label' => (string) $author->get_role(), 'agent' => (string) $agent);
     if ('wp_cli' === $agent && function_exists('posix_getuid')) {
         $uid = posix_getuid();
         $user_info = posix_getpwuid($uid);
         $user_meta['system_user_id'] = (int) $uid;
         $user_meta['system_user_name'] = (string) $user_info['name'];
     }
     // Prevent any meta with null values from being logged
     $stream_meta = array_filter($args, function ($var) {
         return !is_null($var);
     });
     // Add user meta to Stream meta
     $stream_meta['user_meta'] = $user_meta;
     // All meta must be strings, so we will serialize any array meta values
     array_walk($stream_meta, function (&$v) {
         $v = (string) maybe_serialize($v);
     });
     // Get the current time in milliseconds
     $iso_8601_extended_date = wp_stream_get_iso_8601_extended_date();
     $recordarr = array('object_id' => (int) $object_id, 'site_id' => (int) is_multisite() ? get_current_site()->id : 1, 'blog_id' => (int) apply_filters('wp_stream_blog_id_logged', get_current_blog_id()), 'user_id' => (int) $user_id, 'user_role' => (string) (!empty($user->roles)) ? $user->roles[0] : '', 'created' => (string) $iso_8601_extended_date, 'summary' => (string) vsprintf($message, $args), 'connector' => (string) $connector, 'context' => (string) $context, 'action' => (string) $action, 'ip' => (string) wp_stream_filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP), 'meta' => (array) $stream_meta);
     if (0 === $recordarr['object_id']) {
         unset($recordarr['object_id']);
     }
     $result = $this->plugin->db->insert($recordarr);
     $this->debug_backtrace($recordarr);
     return $result;
 }
예제 #21
0
/**
 * Retrieves a sites ID given its (subdomain or directory) slug.
 *
 * @since MU
 * @since 4.7.0 Converted to use get_sites().
 *
 * @param string $slug A site's slug.
 * @return int|null The site ID, or null if no site is found for the given slug.
 */
function get_id_from_blogname($slug)
{
    $current_site = get_current_site();
    $slug = trim($slug, '/');
    if (is_subdomain_install()) {
        $domain = $slug . '.' . preg_replace('|^www\\.|', '', $current_site->domain);
        $path = $current_site->path;
    } else {
        $domain = $current_site->domain;
        $path = $current_site->path . $slug . '/';
    }
    $site_ids = get_sites(array('number' => 1, 'fields' => 'ids', 'domain' => $domain, 'path' => $path));
    if (empty($site_ids)) {
        return null;
    }
    return array_shift($site_ids);
}
예제 #22
0
 public function init()
 {
     global $blog_id;
     $this->logo_locations = array();
     if (is_multisite() && function_exists('get_current_site')) {
         // First, see if there is one for this specific site (blog)
         $this->logo_locations['site'] = array('path' => WP_CONTENT_DIR . '/login-logo-site-' . $blog_id . '.png', 'url' => $this->maybe_ssl(content_url('login-logo-site-' . $blog_id . '.png')));
         // Next, we see if there is one for this specific network
         $site = get_current_site();
         // Site = Network? Ugh.
         if ($site && isset($site->id)) {
             $this->logo_locations['network'] = array('path' => WP_CONTENT_DIR . '/login-logo-network-' . $site->id . '.png', 'url' => $this->maybe_ssl(content_url('login-logo-network-' . $site->id . '.png')));
         }
     }
     // Finally, we do a global lookup
     $this->logo_locations['global'] = array('path' => WP_CONTENT_DIR . '/login-logo.png', 'url' => $this->maybe_ssl(content_url('login-logo.png')));
 }
function searchwp_maybe_nuke()
{
    global $wpdb;
    // maybe nuke all data and settings
    $swp_live_settings = get_option(SEARCHWP_PREFIX . 'settings');
    $swp_nuke_on_delete = isset($swp_live_settings['nuke_on_delete']) ? $swp_live_settings['nuke_on_delete'] : false;
    $swp_multisite = is_multisite() && function_exists('get_current_site') ? get_current_site() : null;
    if (!empty($swp_nuke_on_delete) || get_option(SEARCHWP_PREFIX . 'nuke_on_delete') || apply_filters('searchwp_nuke_on_delete', false, $swp_multisite)) {
        // purge the index including all post meta
        $searchwp = new SearchWP();
        $searchwp->purge_index();
        // deactivate the license
        if (class_exists('SearchWP_Settings_Implementation_License')) {
            $license_manager = new SearchWP_Settings_Implementation_License();
            $license_manager->deactivate_license();
        }
        // drop all custom database tables
        $tables = array('cf', 'index', 'log', 'media', 'tax', 'terms');
        foreach ($tables as $table) {
            $tableName = $wpdb->prefix . SEARCHWP_DBPREFIX . $table;
            // make sure the table exists
            if ($tableName == $wpdb->get_var("SHOW TABLES LIKE '{$tableName}'")) {
                // drop it
                $sql = "DROP TABLE {$tableName}";
                $wpdb->query($sql);
            }
        }
        // delete all plugin settings
        delete_option(SEARCHWP_PREFIX . 'settings');
        delete_option(SEARCHWP_PREFIX . 'settings_backup');
        delete_option(SEARCHWP_PREFIX . 'indexer');
        delete_option(SEARCHWP_PREFIX . 'purge_queue');
        delete_option(SEARCHWP_PREFIX . 'version');
        delete_option(SEARCHWP_PREFIX . 'progress');
        delete_option(SEARCHWP_PREFIX . 'license_key');
        delete_option(SEARCHWP_PREFIX . 'paused');
        delete_option(SEARCHWP_PREFIX . 'last_activity');
        delete_option(SEARCHWP_PREFIX . 'busy');
        delete_option(SEARCHWP_PREFIX . 'doing_delta');
        // remove transients
        delete_option('searchwp_transient');
        delete_option('swppurge_transient');
    }
}
예제 #24
0
function __my_sharepress_ok_page_names($pages)
{
    // This function needs to return an array that contains the titles of
    // the Facebook pages that you want to be visible and selectable as
    // targets for scheduled posting.
    // The $pages argument is an array of Facebook page titles that the
    // active user can see by default, based on the Facebook session that
    // has been configured for use with SharePress.
    // So you have two options:
    // 1. Create a new array that has only the titles of pages that you
    // want to appear.
    // 2. Filter the $pages argument and return that, again containing
    // only the pages you want to appear.
    // So for example, if your client's Facebook page is titled
    // "My Super Awesome Facebook Page", then you would use the following
    // snippet of code to filter his targets list to only that page:
    //
    // return array('My Super Awesome Facebook Page');
    // The personal wall of the user who setup SharePress will not appear
    // by default. To include this as a target option, include the pseudo
    // page name "wall" in the array returned from this function:
    //
    // return array('wall', 'My Super Awesome Facebook Page');
    // More advanced and multisite/multinetwork configuration options below:
    // $current_site is an object that represents the site that is currently
    // running this code - one of the blogs in your multisite installation.
    // You can use this variable in a multisite or multinetwork environment
    // to configure available pages on a site-by-site basis--see example code below.
    $current_site = get_current_site();
    // if ($current_site->blog_id == 1) {
    //   $pages = array('OK Page Title for Blog #1');
    // } else if ($current_site->blog_id == 2) {
    //   $pages = array('OK Page Title for Blog #2');
    // } else {
    //   // Consider having an "empty" default such that new sites don't get
    //   // to see all of the targets available simply because they haven't been
    //   // configured yet.
    //   $pages = array();
    // }
    // Simply returning an unaltered copy of the $pages argument is the same
    // as performing no filtering whatsoever.
    return $pages;
}
예제 #25
0
 /**
  * Get blog details.
  *
  * @since 150821 Improving multisite compat.
  *
  * @param int $blog_id For which blog ID?
  *
  * @return \stdClass|null Blog details if possible.
  *
  * @note The return value of this function is NOT cached in support of `switch_to_blog()`.
  */
 public function blogDetails($blog_id = 0)
 {
     if (!is_multisite() || $this->isAdvancedCache()) {
         return null;
         // Not possible.
     }
     if (($blog_id = (int) $blog_id) < 0) {
         $blog_id = (int) get_current_site()->blog_id;
     }
     if (!$blog_id) {
         $blog_id = (int) get_current_blog_id();
     }
     if (!$blog_id || $blog_id < 0) {
         return null;
         // Not possible.
     }
     $details = get_blog_details($blog_id);
     return is_object($details) ? $details : null;
 }
예제 #26
0
/**
 * Given a blog's (subdomain or directory) slug, retrieve its id.
 *
 * @since MU
 *
 * @param string $slug
 * @return int A blog id
 */
function get_id_from_blogname($slug)
{
    global $wpdb;
    $current_site = get_current_site();
    $slug = trim($slug, '/');
    $blog_id = wp_cache_get('get_id_from_blogname_' . $slug, 'blog-details');
    if ($blog_id) {
        return $blog_id;
    }
    if (is_subdomain_install()) {
        $domain = $slug . '.' . $current_site->domain;
        $path = $current_site->path;
    } else {
        $domain = $current_site->domain;
        $path = $current_site->path . $slug . '/';
    }
    $blog_id = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path));
    wp_cache_set('get_id_from_blogname_' . $slug, $blog_id, 'blog-details');
    return $blog_id;
}
예제 #27
0
 function test_switch_upload_dir()
 {
     $this->assertTrue(is_main_site());
     $site = get_current_site();
     $user_id = $this->factory->user->create(array('role' => 'administrator'));
     $blog_id2 = $this->factory->blog->create(array('user_id' => $user_id));
     $info = wp_upload_dir();
     $this->assertEquals('http://' . $site->domain . '/wp-content/uploads/' . gmstrftime('%Y/%m'), $info['url']);
     $this->assertEquals(ABSPATH . 'wp-content/uploads/' . gmstrftime('%Y/%m'), $info['path']);
     $this->assertEquals(gmstrftime('/%Y/%m'), $info['subdir']);
     $this->assertEquals('', $info['error']);
     switch_to_blog($blog_id2);
     $info2 = wp_upload_dir();
     $this->assertNotEquals($info, $info2);
     $this->assertEquals(get_option('siteurl') . '/wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . gmstrftime('%Y/%m'), $info2['url']);
     $this->assertEquals(ABSPATH . 'wp-content/blogs.dir/' . get_current_blog_id() . '/files/' . gmstrftime('%Y/%m'), $info2['path']);
     $this->assertEquals(gmstrftime('/%Y/%m'), $info2['subdir']);
     $this->assertEquals('', $info2['error']);
     restore_current_blog();
 }
예제 #28
0
 /**
  * Creates new MLP site for the provided language
  *
  * @param string $language
  *
  * @return int
  */
 public function create_site($language)
 {
     if ($this->site_exists($language)) {
         return -1;
     }
     $active = (int) $language['active'];
     $lng_code = $language['language_code'];
     $is_multisite_on_subdomain = $this->check_is_subdomain_multisite_running();
     $current_site = get_current_site();
     $domain = $is_multisite_on_subdomain ? $lng_code . $current_site->domain : $current_site->domain;
     $path = $is_multisite_on_subdomain ? "/" : "/" . $lng_code;
     $user_id = get_current_user_id();
     $this->set_or_update_post_obj($language, $current_site);
     $blog_id = wpmu_create_blog($domain, $path, "My " . $language['translated_name'] . " site", $user_id, array('public' => $active, 'lang_id' => $language['id']), $current_site->id);
     if (0 < $blog_id) {
         $this->set_after_blog_created_vars($language, $current_site, $blog_id);
         //$this->network_new_site_controler->update( $blog_id );
         Wpml2mlp_Helper::update_flag($blog_id, $language['country_flag_url']);
     }
     return $blog_id;
 }
예제 #29
0
/**
 * Create site
 */
function ns_wp_create_site($site_name, $site_title, $logfile)
{
    $user = apply_filters('ns_wp_create_site_admin', wp_get_current_user());
    $site_meta = apply_filters('ns_wp_create_site_meta', array("public" => 1));
    // use wp's built in wpmu_validate_blog_signup validation for all new site vars
    // also, use a test on  a known valid name/title to filter out any validation errors added by other plugins via the wpmu_validate_blog_signup filter
    $baseline_validation = wpmu_validate_blog_signup('1000000', 'NS Cloner Test');
    $site_data = wpmu_validate_blog_signup($site_name, $site_title, $user);
    $site_errors = array_diff($baseline_validation['errors']->get_error_messages(), $site_data['errors']->get_error_messages());
    if (!empty($site_errors) && false) {
        ns_log_write(array("Error creating site with name '{$site_name}' and title '{$site_title}'. One or more problems errors detected by WP:", $site_errors), $logfile);
        return false;
    }
    $site_id = wpmu_create_blog($site_data["domain"], $site_data["path"], $site_title, $site_data["user"]->ID, $site_meta, get_current_site()->id);
    if (!is_wp_error($site_id)) {
        ns_log_write("New site with name '{$site_name}' and title '{$site_title}' (" . get_site_url($site_id) . ") successfully created!", $logfile);
        return $site_id;
    } else {
        ns_log_write("Error creating site with domain '{$site_name}' and path '{$site_title}' - " . $site_id->get_error_message(), $logfile);
        return false;
    }
}
예제 #30
0
 /**
  * Creates an EM_Tags instance, currently accepts an EM_Event object (gets all Tags for that event) or array of any EM_Tag objects, which can be manipulated in bulk with helper functions.
  * @param mixed $data
  * @return null
  */
 function EM_Tags($data = false)
 {
     global $wpdb;
     //an EM_Event object
     if (is_object($data) && get_class($data) == "EM_Event" && !empty($data->post_id)) {
         //Creates a blank tags object if needed
         $this->event_id = $data->event_id;
         $this->post_id = $data->post_id;
         if (EM_MS_GLOBAL && (get_current_blog_id() !== $data->blog_id || !$data->blog_id && !is_main_blog())) {
             if (!$this->blog_id) {
                 $this->blog_id = get_current_site()->blog_id;
             }
             switch_to_blog($this->blog_id);
             $results = get_the_terms($data->post_id, EM_TAXONOMY_TAG);
             restore_current_blog();
         } else {
             $results = get_the_terms($data->post_id, EM_TAXONOMY_TAG);
         }
         if (is_array($results)) {
             foreach ($results as $result) {
                 $this->tags[$result->term_id] = new EM_Tag($result);
             }
         }
         //array of EM_Tag ids
     } elseif (is_array($data) && self::array_is_numeric($data)) {
         foreach ($data as $tag_id) {
             $this->tags[$tag_id] = new EM_Tag($tag_id);
         }
         //array of EM_Tag objects
     } elseif (is_array($data)) {
         foreach ($data as $EM_Tag) {
             if (get_class($EM_Tag) == 'EM_Tag') {
                 $this->tags[] = $EM_Tag;
             }
         }
     }
     do_action('em_tags', $this);
 }