Created
February 3, 2017 08:45
-
-
Save apsolut/53a5a940c9e81ca1a0913fd87e67fa15 to your computer and use it in GitHub Desktop.
Create pages from plugin - easy one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Plugin Name: Easy Create Page from plugin | |
| * Description: Delete and Add - pages, posts | |
| * Version: 0.0.1 | |
| * | |
| * https://developer.wordpress.org/reference/functions/wp_delete_post/ | |
| */ | |
| defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); | |
| add_action('admin_init', 'dc_create_start_pages', 10, 2); | |
| function dc_create_start_pages($user_id, $page_id){ | |
| global $my_admin_page; | |
| // Find and delete the WP default 'Sample Page' | |
| $defaultPage = get_page_by_title( 'Sample Page' ); | |
| wp_delete_post( $defaultPage->ID ); | |
| $blog_posts = post_exists('A new Post'); | |
| $screen = get_current_screen(); | |
| // Add multiple pages | |
| $args = array( | |
| array( | |
| 'post_title' => 'A new Post', | |
| 'post_content' => 'A This is new post', | |
| 'post_status' => 'publish' | |
| ), | |
| array( | |
| 'post_title' => 'B new Post', | |
| 'post_content' => 'B is new post', | |
| 'post_status' => 'publish' | |
| ), | |
| array( | |
| 'post_title' => 'C new Post', | |
| 'post_content' => 'C is new post', | |
| 'post_status' => 'publish' | |
| ), | |
| array( | |
| 'post_title' => 'Startseite', | |
| 'post_content' => 'This is start seite', | |
| 'post_status' => 'publish', | |
| 'post_type' => 'page' | |
| ), | |
| ); | |
| if (!$blog_posts) { | |
| foreach ( $args as $arg ) { | |
| wp_insert_post( $arg ); // Set to False if you want to send them to Trash. | |
| } | |
| } | |
| else { | |
| echo "<script>alert('We created pages already - be careful next time boy, oh boy.');</script>"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment