我正在使用以下代码删除一些默认页面,并为创建的所有新站点创建一些默认页面。它现在可以正常工作,但那只是因为我故意在那里犯了一个错误,每当我纠正时,函数就会停止工作。
这是代码中有故意错误的部分(我也尝试使用一些代码来选择默认页面模板,但这不起作用)
function create_my_pages3($blog_id, $user_id){
switch_to_blog($blog_id);
// not really need, new blogs shouldn\'t have any content
if(get_page_by_title(\'contact\')) return;
// create each page
$page_id = wp_insert_post(array(
\'post_title\' => \'Attorneys\',
\'post_name\' => \'attorneys\',
\'post_content\' => \'This is your Attorney page.\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id, // or "1" (super-admin?)
\'post_type\' => \'page\',
\'menu_order\' => 3,
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
// + see: http://codex.wordpress.org/Function_Reference/wp_insert_post
));
update_post_meta( $id, \'_wp_page_template\', \'new_template.php\' );
restore_current_blog();
}
这是完整的代码
// Create Pages
add_action(\'wpmu_new_blog\', \'create_my_pages\', 10, 2);
function create_my_pages($blog_id, $user_id){
switch_to_blog($blog_id);
// not really need, new blogs shouldn\'t have any content
if(get_page_by_title(\'About\')) return;
// create each page
$page_id = wp_insert_post(array(
\'post_title\' => \'About\',
\'post_name\' => \'about\',
\'post_content\' => \'This is your about page\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id, // or "1" (super-admin?)
\'post_type\' => \'page\',
\'menu_order\' => 1,
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
// + see: http://codex.wordpress.org/Function_Reference/wp_insert_post
));
restore_current_blog();
}
add_action(\'wpmu_new_blog\', \'create_my_pages2\', 10, 2);
function create_my_pages2($blog_id, $user_id){
switch_to_blog($blog_id);
// not really need, new blogs shouldn\'t have any content
if(get_page_by_title(\'Contact\')) return;
// create each page
$page_id = wp_insert_post(array(
\'post_title\' => \'Contact\',
\'post_name\' => \'contact\',
\'post_content\' => \'This is your contact page.\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id, // or "1" (super-admin?)
\'post_type\' => \'page\',
\'menu_order\' => 2,
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
// + see: http://codex.wordpress.org/Function_Reference/wp_insert_post
));
restore_current_blog();
}
add_action(\'wpmu_new_blog\', \'create_my_pages5\', 10, 2);
function create_my_pages5($blog_id, $user_id){
switch_to_blog($blog_id);
// not really need, new blogs shouldn\'t have any content
if(get_page_by_title(\'Attorneys\')) return;
// create each page
$page_id = wp_insert_post(array(
\'post_title\' => \'Attorneys\',
\'post_name\' => \'attorneys\',
\'post_content\' => \'This is your Attorney page.\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id, // or "1" (super-admin?)
\'post_type\' => \'page\',
\'menu_order\' => 5,
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
// + see: http://codex.wordpress.org/Function_Reference/wp_insert_post
));
restore_current_blog();
}
add_action(\'wpmu_new_blog\', \'create_my_pages3\', 10, 2);
function create_my_pages3($blog_id, $user_id){
switch_to_blog($blog_id);
// not really need, new blogs shouldn\'t have any content
if(get_page_by_title(\'contact\')) return;
// create each page
$page_id = wp_insert_post(array(
\'post_title\' => \'Attorneys\',
\'post_name\' => \'attorneys\',
\'post_content\' => \'This is your Attorney page.\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id, // or "1" (super-admin?)
\'post_type\' => \'page\',
\'menu_order\' => 3,
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
// + see: http://codex.wordpress.org/Function_Reference/wp_insert_post
));
update_post_meta( $id, \'_wp_page_template\', \'new_template.php\' );
restore_current_blog();
}
add_action(\'wpmu_new_blog\', \'create_my_pages4\', 10, 2);
function create_my_pages4($blog_id, $user_id){
switch_to_blog($blog_id);
// not really need, new blogs shouldn\'t have any content
if(get_page_by_title(\'Practice Areas\')) return;
// create each page
$page_id = wp_insert_post(array(
\'post_title\' => \'Practice Areas\',
\'post_name\' => \'practice-areas\',
\'post_content\' => \'This is your practice areas page.\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id, // or "1" (super-admin?)
\'post_type\' => \'page\',
\'menu_order\' => 4,
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
// + see: http://codex.wordpress.org/Function_Reference/wp_insert_post
));
restore_current_blog();
}
// Delete Pages
add_action(\'wpmu_new_blog\', \'delete_my_pages\', 10, 2);
function delete_my_pages(){
$post = get_page_by_path(\'hello-world\',OBJECT,\'post\');
if ($post)
wp_delete_post($post->ID,true);
}
add_action(\'wpmu_new_blog\', \'delete_my_pages2\', 10, 2);
function delete_my_pages2(){
$page = get_page_by_path(\'login\',OBJECT,\'page\');
if ($page)
wp_delete_post($page->ID,true);
}
add_action(\'wpmu_new_blog\', \'delete_my_pages3\', 10, 2);
function delete_my_pages3(){
$page = get_page_by_path(\'logout\',OBJECT,\'page\');
if ($page)
wp_delete_post($page->ID,true);
}
add_action(\'wpmu_new_blog\', \'delete_my_pages4\', 10, 2);
function delete_my_pages4(){
$page = get_page_by_path(\'lostpassword\',OBJECT,\'page\');
if ($page)
wp_delete_post($page->ID,true);
}
add_action(\'wpmu_new_blog\', \'delete_my_pages5\', 10, 2);
function delete_my_pages5(){
$page = get_page_by_path(\'register\',OBJECT,\'page\');
if ($page)
wp_delete_post($page->ID,true);
}
add_action(\'wpmu_new_blog\', \'delete_my_pages6\', 10, 2);
function delete_my_pages6(){
$page = get_page_by_path(\'resetpass\',OBJECT,\'page\');
if ($page)
wp_delete_post($page->ID,true);
}
add_action(\'wpmu_new_blog\', \'delete_my_pages7\', 10, 2);
function delete_my_pages7(){
$page = get_page_by_path(\'sample-page\',OBJECT,\'page\');
if ($page)
wp_delete_post($page->ID,true);
}
add_action(\'wpmu_new_blog\', \'delete_my_pages8\', 10, 2);
function delete_my_pages8(){
$page = get_page_by_path(\'store\',OBJECT,\'page\');
if ($page)
wp_delete_post($page->ID,true);
}
我怎样才能清除这些错误并使其在没有故意错误的情况下正常工作?
EDIT
此处显示错误-
// not really need, new blogs shouldn\'t have any content
if(get_page_by_title(\'contact\')) return;
如果上面写着“联系”,那么应该与此匹配(律师)
// create each page
$page_id = wp_insert_post(array(
\'post_title\' => \'Attorneys\',
\'post_name\' => \'attorneys\',
如果我将联系人改为律师,那么所有被删除的页面都会再次显示出来。