0
WordPlus 플러그인을 활성화 할 때 다음 코드가 실행됩니다.WP_insert_post도 메뉴 항목을 추가합니다.
페이지를 만들지 만 가지고 싶지 않은 탐색 메뉴 항목도 추가합니다.
내가 잘못한 곳을 볼 수 없기 때문에 누군가 나를 도울 수 있습니까?
wp_posts 테이블의 데이터베이스를보고 있기 때문에 탐색 메뉴 항목도 추가된다는 것을 알고 있습니다. post_date는 post_type 페이지 및 nav_menu_item과 완전히 같습니다.
public static function activate() {
global $myplugin;
require_once plugin_dir_path(__FILE__) . 'install-sql.php';
//Add a front end page
$author_id = 9;
$slug = 'myplugin';
$title = "My Plugin";
$content = '[myplugin_render]';
$page = array(
'post_author' => 1,
'post_content' => $content,
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'page',
'comment_status' => 'closed',
'ping_status' => 'closed',
'guid' => '',
'import_id' => 0,
'context' => ''
);
if(null == get_page_by_title($title)) {
wp_insert_post($page);
} else {
$page = get_page_by_title($title);
if (is_page($page->ID)) {
$post = array(
'ID' => $page->ID,
'post_content' => $content
);
wp_update_post($post);
}
}
}
내 친구, 천재세요! 정말 고마워요, 제 정신이 아니에요! – Caveman