Пример #1
0
 public static function insert_wp_page($page_name, $page_template = '')
 {
     remove_action('wp_insert_post', array('advanced_page_manager', 'wp_insert_post'));
     $post_type = 'page';
     //TODO dynamise post_type
     //Use of "default_title" hook so that the default title may still be customized using "default_title" hook with a higher priority than 10.
     $callback = create_function('$title,$post', 'return $post->post_type == "' . $post_type . '" ? "' . $page_name . '" : $title;');
     add_filter('default_title', $callback, 10, 2);
     $post = get_default_post_to_edit($post_type);
     remove_filter('default_title', $callback);
     //Fix very strange bug related to $post->post_category not being an array.
     // > warning in wp-includes/post.php line 2755 :
     if (isset($post->post_category) && !empty($post->post_category) && !is_array($post->post_category)) {
         $post->post_category = array($post->post_category);
     }
     $new_page_id = wp_insert_post((array) $post);
     add_action('wp_insert_post', array('advanced_page_manager', 'wp_insert_post'), 10, 2);
     if (!empty($page_template)) {
         ApmNodeDataDisplay::set_page_template($new_page_id, $page_template);
     }
     return $new_page_id;
 }