Esempio n. 1
0
/**
 * Execute changes made in WordPress 2.8.
 *
 * @since 2.8.0
 */
function upgrade_280()
{
    global $wp_current_db_version, $wpdb;
    if ($wp_current_db_version < 10360) {
        populate_roles_280();
    }
    if (is_multisite()) {
        $start = 0;
        while ($rows = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} ORDER BY option_id LIMIT {$start}, 20")) {
            foreach ($rows as $row) {
                $value = $row->option_value;
                if (!@unserialize($value)) {
                    $value = stripslashes($value);
                }
                if ($value !== $row->option_value) {
                    update_option($row->option_name, $value);
                }
            }
            $start += 20;
        }
        refresh_blog_details($wpdb->blogid);
    }
}
Esempio n. 2
0
/**
 * Store basic site info in the blogs table.
 *
 * This function creates a row in the wp_blogs table and returns
 * the new blog's ID. It is the first step in creating a new blog.
 *
 * @since MU
 *
 * @param string $domain The domain of the new site.
 * @param string $path The path of the new site.
 * @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1.
 * @return int The ID of the new row
 */
function insert_blog($domain, $path, $site_id)
{
    global $wpdb;
    $path = trailingslashit($path);
    $site_id = (int) $site_id;
    $result = $wpdb->insert($wpdb->blogs, array('site_id' => $site_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')));
    if (!$result) {
        return false;
    }
    refresh_blog_details($wpdb->insert_id);
    return $wpdb->insert_id;
}
Esempio n. 3
0
/**
 * Update a blog details field.
 *
 * @since 3.0.0
 *
 * @param int $blog_id BLog ID
 * @param string $pref A field name
 * @param string $value Value for $pref
 * @param bool $refresh Whether to refresh the blog details cache. Default is true.
 */
function update_blog_status($blog_id, $pref, $value, $refresh = true)
{
    global $wpdb;
    if (!in_array($pref, array('site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'))) {
        return $value;
    }
    $wpdb->update($wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id));
    if ($refresh) {
        refresh_blog_details($blog_id);
    }
    if ($pref == 'spam') {
        if ($value == 1) {
            do_action("make_spam_blog", $blog_id);
        } else {
            do_action("make_ham_blog", $blog_id);
        }
    }
    return $value;
}
Esempio n. 4
0
/**
 * Update a blog details field.
 *
 * @since MU
 *
 * @param int $blog_id BLog ID
 * @param string $pref A field name
 * @param string $value Value for $pref
 * @return string $value
 */
function update_blog_status($blog_id, $pref, $value, $deprecated = null)
{
    global $wpdb;
    if (null !== $deprecated) {
        _deprecated_argument(__FUNCTION__, '3.1');
    }
    if (!in_array($pref, array('site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'))) {
        return $value;
    }
    $result = $wpdb->update($wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id));
    if (false === $result) {
        return false;
    }
    refresh_blog_details($blog_id);
    if ('spam' == $pref) {
        if ($value == 1) {
            /** This filter is documented in wp-includes/ms-blogs.php */
            do_action('make_spam_blog', $blog_id);
        } else {
            /** This filter is documented in wp-includes/ms-blogs.php */
            do_action('make_ham_blog', $blog_id);
        }
    } elseif ('mature' == $pref) {
        if ($value == 1) {
            /** This filter is documented in wp-includes/ms-blogs.php */
            do_action('mature_blog', $blog_id);
        } else {
            /** This filter is documented in wp-includes/ms-blogs.php */
            do_action('unmature_blog', $blog_id);
        }
    } elseif ('archived' == $pref) {
        if ($value == 1) {
            /** This filter is documented in wp-includes/ms-blogs.php */
            do_action('archive_blog', $blog_id);
        } else {
            /** This filter is documented in wp-includes/ms-blogs.php */
            do_action('unarchive_blog', $blog_id);
        }
    } elseif ('deleted' == $pref) {
        if ($value == 1) {
            /** This filter is documented in wp-includes/ms-blogs.php */
            do_action('make_delete_blog', $blog_id);
        } else {
            /** This filter is documented in wp-includes/ms-blogs.php */
            do_action('make_undelete_blog', $blog_id);
        }
    } elseif ('public' == $pref) {
        /**
         * Fires after the current blog's 'public' setting is updated.
         *
         * @since MU
         *
         * @param int    $blog_id Blog ID.
         * @param string $value   The value of blog status.
         */
        do_action('update_blog_public', $blog_id, $value);
        // Moved here from update_blog_public().
    }
    return $value;
}
function xtec_delblogs_page()
{
    if (isset($_POST['inactivity_days'])) {
        $inactivity_days = $_POST['inactivity_days'];
    } else {
        $inactivity_days = get_site_option('xtec_maintenance_inactivity_days', 90);
    }
    if (isset($_POST['posts_pages'])) {
        $posts_pages = $_POST['posts_pages'];
    } else {
        $posts_pages = get_site_option('xtec_maintenance_posts_pages', 2);
    }
    if (get_site_option('xtec_maintenance_never_upload_file', 1) == 1) {
        $never_upload_file = true;
    } else {
        $never_upload_file = false;
    }
    if (isset($_POST['never_upload_file'])) {
        $never_upload_file = true;
    } else {
        if (isset($_POST['submit']) || isset($_POST['set_as_default']) || isset($_POST['touch'])) {
            $never_upload_file = false;
        }
    }
    ?>
	
	<div class="wrap">
	
	<h2>Eliminació de blocs</h2>
	
	<?php 
    global $wpdb;
    if (isset($_POST['delete'])) {
        if (!isset($_POST['idblogs'])) {
            ?>
<div class="error below-h2"><p>No has seleccionat cap bloc.</p></div><?php 
        } else {
            $idblogs = $_POST['idblogs'];
            foreach ($idblogs as $idblog) {
                $blogname = get_blog_option($idblog, 'blogname');
                $path = $wpdb->get_var("SELECT `path` FROM `{$wpdb->blogs}` WHERE `blog_id`='{$idblog}'");
                $del_date = date("Y-m-d H:i:s");
                $sql = "INSERT INTO `wp_delblocs` SET `site_id` = '{$idblog}', `site_path` = '" . $path . "', `blogname` = '" . $blogname . "', `del_date` = '{$del_date}', `status` = '2';";
                $wpdb->get_results($sql);
                $users = get_users_of_blog($idblog);
                foreach ($users as $user) {
                    $sql = "INSERT INTO `wp_delblocs_users` SET `blog_id` = '{$idblog}', `user_id` = '" . $user->user_id . "', `user_login` = '" . $user->user_login . "', `display_name` = '" . $user->display_name . "', `user_email` = '" . $user->user_email . "', `meta_value` = '" . $user->meta_value . "';";
                    $wpdb->get_results($sql);
                }
                // drops data of the blog when deleted
                wpmu_delete_blog($idblog, true);
                echo "El bloc {$blogname} amb ID {$idblog} s'ha eliminat correctament.<br />";
            }
        }
        echo "<p><a href=\"?page=xtec-delblogs\">Torna al formulari d'eliminació de blocs</a></p>";
    } else {
        if (isset($_POST['touch'])) {
            if (!isset($_POST['idblogs'])) {
                ?>
<div class="error below-h2"><p>No has seleccionat cap bloc.</p></div><?php 
            } else {
                $idblogs = $_POST['idblogs'];
                foreach ($idblogs as $idblog) {
                    $blogname = get_blog_option($idblog, 'blogname');
                    $wpdb->update($wpdb->blogs, array('last_updated' => current_time('mysql', true)), array('blog_id' => $idblog));
                    refresh_blog_details($wpdb->blogid);
                    echo "La data de la darrera actualització del bloc <strong>{$blogname}</strong> amb ID <strong>{$idblog}</strong> ha estat actualitzada a la data actual.<br>";
                }
            }
            echo "<p><a href=\"?page=xtec-delblogs\">Torna al formulari d'eliminació de blocs</a></p>";
        } else {
            if (isset($_POST['set_as_default'])) {
                update_site_option('xtec_maintenance_inactivity_days', $_POST['inactivity_days']);
                update_site_option('xtec_maintenance_posts_pages', $_POST['posts_pages']);
                $value = isset($_POST['never_upload_file']) ? 1 : 0;
                update_site_option('xtec_maintenance_never_upload_file', $value);
            }
            ?>
		
		<form action="?page=xtec-delblogs" method="post">
			<table class="form-table">
				<tbody>
					<tr valign="top">
						<th scope="row">
							<label for="inactivity_days">Dies d'inactivitat</label>
						</th>
						<td>
							<input id="inactivity_days" class="small-text" type="text" value="<?php 
            echo $inactivity_days;
            ?>
" name="inactivity_days"/>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row">
							<label for="posts_pages">Articles i pàgines</label>
						</th>
						<td>
							<input id="posts_pages" class="small-text" type="text" value="<?php 
            echo $posts_pages;
            ?>
" name="posts_pages"/>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row">
							<label for="never_upload_file">Mai s'ha pujat cap fitxer</label>
						</th>
						<td>
							<?php 
            if ($never_upload_file) {
                ?>
								<input type="checkbox" checked="checked" value=1 name="never_upload_file"/>
							<?php 
            } else {
                ?>
								<input type="checkbox" value=1 name="never_upload_file"/>
							<?php 
            }
            ?>
						</td>
					</tr>
				</tbody>
			</table>

			<h3>Es llisten tots els blocs que compleixen les següents restriccions:</h3>

			<div  style="background-color: rgb(255, 251, 204); border-color:#E6DB55; border-style: solid;border-width:1px; padding: 0.6em;-moz-border-radius:3px">
				<?php 
            if ($inactivity_days == 1) {
                ?>
 - Fa almenys <strong><?php 
                echo $inactivity_days;
                ?>
</strong> dia que no s'actualitzen.<br>
				<?php 
            } else {
                if ($inactivity_days != 0) {
                    ?>
 - Fa almenys <strong><?php 
                    echo $inactivity_days;
                    ?>
</strong> dies que no s'actualitzen.<br>
				<?php 
                }
            }
            ?>
				<?php 
            if ($posts_pages == 1) {
                ?>
 - Tenen com a molt <strong><?php 
                echo $posts_pages;
                ?>
</strong> article o pàgina.<br>
				<?php 
            } else {
                if ($posts_pages != 0) {
                    ?>
 - Tenen com a molt <strong><?php 
                    echo $posts_pages;
                    ?>
</strong> articles o pàgines.<br>
				<?php 
                } else {
                    if ($posts_pages == 0) {
                        ?>
 - No tenen <strong>cap</strong> article ni <strong>cap</strong> pàgina.<br>
				<?php 
                    }
                }
            }
            ?>
				<?php 
            if ($never_upload_file) {
                ?>
 - <strong>Mai</strong> s'hi ha pujat cap fitxer.<br>
				<?php 
            } else {
                ?>
 - S'hi ha pujat <strong>alguna vegada</strong> algun fitxer.<br>
				<?php 
            }
            ?>
			</div>
			
			<div class="tablenav">
				<div class="alignleft">
						<input class="button-secondary" type="submit" value="Refresca la llista" name="submit"/>
						<input class="button-secondary" type="submit" value="Elimina els blocs seleccionats" name="delete"/>
						<input class="button-secondary" type="submit" value="Actualitza la data dels blocs seleccionats" name="touch"/>
						<input class="button-secondary" type="submit" value="Desa els valors actuals com a predeterminats" name="set_as_default"/>
						<br class="clear" />				
				</div>
			</div>
			<br class="clear" />
			
			<?php 
            $blogname_columns = constant("VHOST") == 'yes' ? __('Domain') : __('Path');
            ?>
						
			<table cellspacing="3" cellpadding="3" width="100%" class="widefat">
				<thead>
					<tr>
						<th class="check-column" scope="col"><input type="checkbox"/></th>
						<th scope="col"><?php 
            echo __('ID');
            ?>
</th>
						<th scope="col"><?php 
            echo $blogname_columns;
            ?>
</th>
						<th scope="col">Dies des de la darrera actualització</th>
						<th scope="col">Articles i pàgines</th>
						<th scope="col">S'han pujat fitxers algun cop?</th>
					</tr>
				</thead>
				<tbody id="the-list">
					<?php 
            // Inactivity check
            $date_limit = date("Y-m-d H:i:s", mktime() - $inactivity_days * 86400);
            $blogs = $wpdb->get_results("SELECT `blog_id`, `path`, `registered`, UNIX_TIMESTAMP(`last_updated`) as last_updated FROM {$wpdb->blogs} WHERE last_updated<'{$date_limit}' AND deleted=0 AND blog_id!=1", ARRAY_A);
            foreach ($blogs as $blog) {
                $blog_id = $blog["blog_id"];
                $path = $blog["path"];
                $registered = $blog["registered"];
                $last_updated = $blog["last_updated"];
                $posts_pages_check = false;
                $upload_check = false;
                $now = mktime();
                $elapsed_days = (int) (($now - $last_updated) / 86400);
                // Posts and Pages check
                $posts_table = $wpdb->get_results("SELECT post_type FROM `wp_" . $blog_id . "_posts`", ARRAY_A);
                $posts = 0;
                $pages = 0;
                foreach ($posts_table as $post_row) {
                    if ($post_row['post_type'] == 'post') {
                        $posts++;
                    } else {
                        if ($post_row['post_type'] == 'page') {
                            $pages++;
                        }
                    }
                }
                if ($posts + $pages <= $posts_pages) {
                    $posts_pages_check = true;
                }
                // Upload check
                if (!file_exists(ABSPATH . "wp-content/blogs.dir/{$blog_id}")) {
                    if ($never_upload_file) {
                        $upload_check = true;
                    }
                } else {
                    if (!$never_upload_file) {
                        $upload_check = true;
                    }
                }
                // Check the rules
                if ($posts_pages_check && $upload_check) {
                    $path = $wpdb->get_var("SELECT `path` FROM `{$wpdb->blogs}` WHERE `blog_id`='{$blog_id}'");
                    ?>
							<tr class="alternate">
								<th class="check-column" scope="row">
									<input type="checkbox" value="<?php 
                    echo $blog_id;
                    ?>
" name="idblogs[]" id="blog_<?php 
                    echo $blog_id;
                    ?>
"/>
								</th>
								
								<th scope="row"><?php 
                    echo $blog_id;
                    ?>
</th>
								<td valign="top">
									<a rel="permalink" href="<?php 
                    echo $path;
                    ?>
"><?php 
                    echo $path;
                    ?>
</a>
								</td>
								<td valign="top">
									<?php 
                    echo '<strong>' . $elapsed_days . '</strong>';
                    ?>
								</td>
								<td valign="top">
									<?php 
                    echo '<strong>' . ($posts + $pages) . '</strong>' . ' (' . $posts . '+' . $pages . ')';
                    ?>
								</td>
								<td valign="top">
									<strong><?php 
                    if ($never_upload_file) {
                        ?>
NO<?php 
                    } else {
                        ?>
SI<?php 
                    }
                    ?>
</strong>
								</td>
							</tr>
							<?php 
                }
            }
            ?>
				</tbody>
			</table>
		</form>		
		<?php 
        }
    }
    ?>
	</div>
	<?php 
}
Esempio n. 6
0
/**
 * Update a blog details field.
 *
 * @since MU
 *
 * @param int $blog_id BLog ID
 * @param string $pref A field name
 * @param string $value Value for $pref
 * @return string $value
 */
function update_blog_status($blog_id, $pref, $value, $deprecated = null)
{
    global $wpdb;
    if (null !== $deprecated) {
        _deprecated_argument(__FUNCTION__, '3.1');
    }
    if (!in_array($pref, array('site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'))) {
        return $value;
    }
    $wpdb->update($wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id));
    refresh_blog_details($blog_id);
    if ('spam' == $pref) {
        $value == 1 ? do_action('make_spam_blog', $blog_id) : do_action('make_ham_blog', $blog_id);
    } elseif ('mature' == $pref) {
        $value == 1 ? do_action('mature_blog', $blog_id) : do_action('unmature_blog', $blog_id);
    } elseif ('archived' == $pref) {
        $value == 1 ? do_action('archive_blog', $blog_id) : do_action('unarchive_blog', $blog_id);
    } elseif ('archived' == $pref) {
        $value == 1 ? do_action('archive_blog', $blog_id) : do_action('unarchive_blog', $blog_id);
    }
    return $value;
}
Esempio n. 7
0
function insert_blog($domain, $path, $site_id)
{
    global $wpdb;
    $path = trailingslashit($path);
    $site_id = (int) $site_id;
    $result = $wpdb->query("INSERT INTO {$wpdb->blogs} ( blog_id, site_id, domain, path, registered ) VALUES ( NULL, '{$site_id}', '{$domain}', '{$path}', NOW( ))");
    if (!$result) {
        return false;
    }
    refresh_blog_details($wpdb->insert_id);
    return $wpdb->insert_id;
}
Esempio n. 8
0
 /**
  * Modify the domain and path of an existing site - and update all of its blogs
  * @param integer id ID of site to modify
  * @param string $domain new domain for site
  * @param string $path new path for site
  * @param array $meta meta keys and values to be updated
  */
 function update_site($id, $domain, $path = '', $meta = null)
 {
     global $wpdb, $url_dependent_blog_options, $wp_version;
     if (!site_exists((int) $id)) {
         return new WP_Error('site_not_exist', __('Network does not exist.', 'njsl-networks'));
     }
     $query = "SELECT * FROM {$wpdb->site} WHERE id=" . (int) $id;
     $site = $wpdb->get_row($query);
     if (!$site) {
         return new WP_Error('site_not_exist', __('Network does not exist.', 'njsl-networks'));
     }
     $domain = untrailingslashit($domain);
     $update = array('domain' => $domain);
     if ($path != '') {
         $path = trim($path, '/');
         $path = trailingslashit('/' . $path);
         $update['path'] = $path;
     }
     $where = array('id' => (int) $id);
     $update_result = $wpdb->update($wpdb->site, $update, $where);
     if (false === $update_result) {
         return new WP_Error('site_not_updatable', __('Network could not be updated.', 'njsl-networks'));
     }
     if (!empty($meta) && is_array($meta)) {
         switch_to_site($id);
         foreach ($meta as $option => $value) {
             if (false === update_site_option($option, $value)) {
                 $wpdb->insert($wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $value));
             }
         }
         restore_current_site();
     }
     // No URL values updated -- quit before needlessly
     //   processing a bunch of URL-specific values and triggering hooks
     if (!$update_result) {
         return;
     }
     $path = $path != '' ? $path : $site->path;
     $fullPath = untrailingslashit($domain . $path);
     $oldPath = untrailingslashit($site->domain . $site->path);
     /** also updated any associated blogs */
     $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id=" . (int) $id;
     $blogs = $wpdb->get_results($query);
     if ($blogs) {
         foreach ($blogs as $blog) {
             $update = array();
             if ($site->domain !== $domain) {
                 $update['domain'] = str_replace($site->domain, $domain, $blog->domain);
             }
             if ($site->path !== $path) {
                 $search = sprintf('|^%s|', preg_quote($site->path, '|'));
                 $update['path'] = preg_replace($search, $path, $blog->path, 1);
             }
             if (empty($update)) {
                 continue;
             }
             $blog_id = (int) $blog->blog_id;
             switch_to_blog($blog_id);
             $wpdb->update($wpdb->blogs, $update, array('blog_id' => $blog_id));
             foreach ($url_dependent_blog_options as $option_name) {
                 // TODO: pop upload_url_path off list if ms_files_rewriting is disabled
                 $option_value = get_option($option_name);
                 if ($option_value) {
                     $newValue = str_replace($oldPath, $fullPath, $option_value->option_value);
                     update_option($option_name, $newValue);
                 }
             }
             restore_current_blog();
             refresh_blog_details($blog_id);
         }
     }
     do_action('wpmu_update_site', $id, array('domain' => $site->domain, 'path' => $site->path));
     do_action('wpms_update_network', $id, array('domain' => $site->domain, 'path' => $site->path));
 }
Esempio n. 9
0
 /**
  * Sets up a blog - called from install() and new_blog()
  *
  * @param int $blog (Optional) If multisite blog_id will be passed, otherwise will be NULL.
  */
 function setup_blog($blog_id = NULL)
 {
     if (!is_null($blog_id)) {
         switch_to_blog($blog_id);
     }
     // Set admin permissions
     $role = get_role('administrator');
     $role->add_cap('edit_wiki_privileges');
     // Set default settings
     $default_settings = array('slug' => 'wiki', 'breadcrumbs_in_title' => 0, 'wiki_name' => __('Wikis', 'wiki'), 'sub_wiki_name' => __('Sub Wikis', 'wiki'), 'sub_wiki_order_by' => 'menu_order', 'sub_wiki_order' => 'ASC');
     // Migrate and delete old settings option name which isn't very intuitive
     if ($settings = get_option('wiki_default')) {
         delete_option('wiki_default');
     } else {
         $settings = get_option('wiki_settings');
     }
     // Merge settings
     if (is_array($settings)) {
         $settings = wp_parse_args($settings, $default_settings);
     } else {
         $settings = $default_settings;
     }
     // Update settings
     $this->settings = $settings;
     update_option('wiki_settings', $settings);
     update_option('wiki_flush_rewrites', 1);
     if (!is_null($blog_id)) {
         restore_current_blog();
         refresh_blog_details($blog_id);
     }
 }
Esempio n. 10
0
/**
 * Update an option for a particular blog.
 *
 * @since MU
 * @deprecated 3.5.0
 *
 * @param int $id The blog id
 * @param string $option The option key
 * @param mixed $value The option value
 * @return bool True on success, false on failrue.
 */
function update_blog_option($id, $option, $value, $deprecated = null)
{
    _deprecated_function(__FUNCTION__, '3.5');
    $id = (int) $id;
    if (null !== $deprecated) {
        _deprecated_argument(__FUNCTION__, '3.1');
    }
    if (get_current_blog_id() == $id) {
        return update_option($option, $value);
    }
    switch_to_blog($id);
    $return = update_option($option, $value);
    restore_current_blog();
    refresh_blog_details($id);
    return $return;
}
Esempio n. 11
0
function stripslashes_from_options($blog_id)
{
    global $wpdb;
    if ($blog_id == 1) {
        // check site_options too
        $start = 0;
        while ($rows = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT {$start}, 20")) {
            foreach ($rows as $row) {
                $value = $row->meta_value;
                if (!@unserialize($value)) {
                    $value = stripslashes($value);
                }
                if ($value !== $row->meta_value) {
                    update_site_option($row->meta_key, $value);
                }
            }
            $start += 20;
        }
    }
    $start = 0;
    $options_table = $wpdb->get_blog_prefix($blog_id) . "options";
    while ($rows = $wpdb->get_results("SELECT option_name, option_value FROM {$options_table} ORDER BY option_id LIMIT {$start}, 20")) {
        foreach ($rows as $row) {
            $value = $row->option_value;
            if (!@unserialize($value)) {
                $value = stripslashes($value);
            }
            if ($value !== $row->option_value) {
                update_blog_option($blog_id, $row->option_name, $value);
            }
        }
        $start += 20;
    }
    refresh_blog_details($blog_id);
}
 /**
  * Set up default terms for Front Matter and Back Matter
  * Insert default part, chapter, front matter, and back matter
  * Insert default pages (Authors, Cover, TOC, About, Buy, and Access Denied)
  * Remove content generated by wp_install_defaults
  * Anything which needs to run on blog activation must go in this function
  */
 private function wpmuActivate()
 {
     /** @var $wpdb \wpdb */
     global $wpdb;
     \Pressbooks\Taxonomy::insertTerms();
     $posts = array(array('post_title' => __('Main Body', 'pressbooks'), 'post_name' => 'main-body', 'post_type' => 'part', 'menu_order' => 1), array('post_title' => __('Introduction', 'pressbooks'), 'post_name' => 'introduction', 'post_content' => __('This is where you can write your introduction.', 'pressbooks'), 'post_type' => 'front-matter', 'menu_order' => 1), array('post_title' => __('Chapter 1', 'pressbooks'), 'post_name' => 'chapter-1', 'post_content' => __('This is the first chapter in the main body of the text. You can change the text, rename the chapter, add new chapters, and add new parts.', 'pressbooks'), 'post_type' => 'chapter', 'menu_order' => 1), array('post_title' => __('Appendix', 'pressbooks'), 'post_name' => 'appendix', 'post_content' => __('This is where you can add appendices or other back matter.', 'pressbooks'), 'post_type' => 'back-matter', 'menu_order' => 1), array('post_title' => __('Authors', 'pressbooks'), 'post_name' => 'authors', 'post_type' => 'page'), array('post_title' => __('Cover', 'pressbooks'), 'post_name' => 'cover', 'post_type' => 'page'), array('post_title' => __('Table of Contents', 'pressbooks'), 'post_name' => 'table-of-contents', 'post_type' => 'page'), array('post_title' => __('About', 'pressbooks'), 'post_name' => 'about', 'post_type' => 'page'), array('post_title' => __('Buy', 'pressbooks'), 'post_name' => 'buy', 'post_type' => 'page'), array('post_title' => __('Access Denied', 'pressbooks'), 'post_name' => 'access-denied', 'post_content' => __('This book is private, and accessible only to registered users. If you have an account you can login <a href="/wp-login.php">here</a>. You can also set up your own Pressbooks book at: <a href="http://pressbooks.com">Pressbooks.com</a>.', 'pressbooks'), 'post_type' => 'page'), array('post_title' => __('Custom CSS for Ebook', 'pressbooks'), 'post_name' => 'epub', 'post_type' => 'custom-css'), array('post_title' => __('Custom CSS for PDF', 'pressbooks'), 'post_name' => 'prince', 'post_type' => 'custom-css'), array('post_title' => __('Custom CSS for Web', 'pressbooks'), 'post_name' => 'web', 'post_type' => 'custom-css'), array('post_title' => __('Book Information', 'pressbooks'), 'post_name' => 'book-information', 'post_type' => 'metadata'));
     $post = array('post_status' => 'publish', 'comment_status' => 'open', 'post_author' => $this->user_id);
     $page = array('post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_content' => '<!-- Here be dragons.-->', 'post_author' => $this->user_id, 'tags_input' => __('Default Data', 'pressbooks'));
     update_option('blogdescription', __('Simple Book Production', 'pressbooks'));
     $parent_part = 0;
     $intro = 0;
     $appendix = 0;
     $chapter1 = 0;
     foreach ($posts as $item) {
         $exists = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = %s AND post_name = %s AND post_status = 'publish' ", array($item['post_title'], $item['post_type'], $item['post_name'])));
         if (empty($exists)) {
             if ('page' == $item['post_type']) {
                 $data = array_merge($item, $page);
             } else {
                 $data = array_merge($item, $post);
             }
             $newpost = wp_insert_post($data, true);
             if (!is_wp_error($newpost)) {
                 switch ($item['post_name']) {
                     case 'cover':
                         $this->opts['page_on_front'] = (int) $newpost;
                         break;
                     case 'table-of-contents':
                         $this->opts['page_for_posts'] = (int) $newpost;
                         break;
                 }
                 if ('part' == $item['post_type']) {
                     $parent_part = $newpost;
                 } elseif ('chapter' == $item['post_type']) {
                     $my_post = array();
                     $my_post['ID'] = $newpost;
                     $my_post['post_parent'] = $parent_part;
                     wp_update_post($my_post);
                     $chapter1 = $newpost;
                 } elseif ('front-matter' == $item['post_type']) {
                     $intro = $newpost;
                 } elseif ('back-matter' == $item['post_type']) {
                     $appendix = $newpost;
                 } elseif ('metadata' == $item['post_type']) {
                     $metadata_id = $newpost;
                     if (0 !== get_current_user_id()) {
                         $user_info = get_userdata(get_current_user_id());
                         $name = $user_info->display_name;
                         update_post_meta($metadata_id, 'pb_author', $name);
                     }
                     $locale = get_site_option('WPLANG');
                     if (!$locale) {
                         $locale = 'en';
                     } else {
                         $locale = array_search($locale, \Pressbooks\L10n\wplang_codes());
                     }
                     update_post_meta($metadata_id, 'pb_title', get_option('blogname'));
                     update_post_meta($metadata_id, 'pb_language', $locale);
                     update_post_meta($metadata_id, 'pb_cover_image', \Pressbooks\Image\default_cover_url());
                 }
             } else {
                 trigger_error($newpost->get_error_message(), E_USER_ERROR);
             }
         }
     }
     // Apply 'introduction' front matter type to 'introduction' post
     wp_set_object_terms($intro, 'introduction', 'front-matter-type');
     // Apply 'appendix' front matter type to 'appendix' post
     wp_set_object_terms($appendix, 'appendix', 'back-matter-type');
     // Apply 'standard' chapter type to 'chapter 1' post
     wp_set_object_terms($chapter1, 'standard', 'chapter-type');
     // Remove content generated by wp_install_defaults
     if (!wp_delete_post(1, true)) {
         return;
     }
     if (!wp_delete_post(2, true)) {
         return;
     }
     if (!wp_delete_comment(1, true)) {
         return;
     }
     $this->opts['pb_activated'] = time();
     refresh_blog_details($this->blog_id);
 }
Esempio n. 13
0
 /**
  * Move a site to a new network
  *
  * @since 1.3
  *
  * @param  integer  $site_id         ID of site to move
  * @param  integer  $new_network_id  ID of destination network
  */
 function move_site($site_id = 0, $new_network_id = 0)
 {
     global $wpdb;
     // Get the site
     $site = get_blog_details($site_id);
     // Bail if site does not exist
     if (empty($site)) {
         return new WP_Error('blog_not_exist', __('Site does not exist.', 'wp-multi-network'));
     }
     // Main sites cannot be moved, to prevent breakage
     if (is_main_site_for_network($site->blog_id)) {
         return true;
     }
     // Cast new network ID
     $new_network_id = (int) $new_network_id;
     // Return early if site does not need to be moved
     if ($new_network_id === (int) $site->site_id) {
         return true;
     }
     // Move the site is the blogs table
     $where = array('blog_id' => $site->blog_id);
     $update = array('site_id' => $new_network_id);
     $result = $wpdb->update($wpdb->blogs, $update, $where);
     // Bail if site could not be moved
     if (empty($result)) {
         return new WP_Error('blog_not_moved', __('Site could not be moved.', 'wp-multi-network'));
     }
     // Update old network count
     if (0 !== $site->site_id) {
         switch_to_network($site->site_id);
         wp_update_network_site_counts();
         restore_current_network();
     }
     // Update new network count
     if (0 !== $new_network_id) {
         switch_to_network($new_network_id);
         wp_update_network_site_counts();
         restore_current_network();
     }
     // Refresh blog details
     refresh_blog_details($site_id);
     // Clean network caches
     clean_network_cache(array_filter(array($site->site_id, $new_network_id)));
     // Site moved
     do_action('move_site', $site_id, $site->site_id, $new_network_id);
     // Return the new network ID as confirmation
     return $new_network_id;
 }