wp-create-multiple-posts-pages
Last commit date
assets
2 years ago
includes
2 years ago
readme.txt
2 years ago
wp-create-multiple-posts-pages.php
2 years ago
wp-create-multiple-posts-pages.php
198 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: WP Create Multiple Posts & Pages |
| 4 | * Plugin URI: https://wordpress.org/plugins/wp-create-multiple-posts-pages/ |
| 5 | * Description: Create Multiple Wordpress Posts & Pages At Once With a Single Click. |
| 6 | * Author: Sajjad Hossain Sagor |
| 7 | * Author URI: http://profiles.wordpress.org/sajjad67 |
| 8 | * Version: 1.0.6 |
| 9 | * License: GPL |
| 10 | * Text Domain: wp-create-multiple-posts-pages |
| 11 | */ |
| 12 | |
| 13 | /* Exit if accessed directly */ |
| 14 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 15 | |
| 16 | // --------------------------------------------------------- |
| 17 | // Define Plugin Folders Path |
| 18 | // --------------------------------------------------------- |
| 19 | define( "WPCMP_PLUGIN_PATH", plugin_dir_path( __FILE__ ) ); |
| 20 | |
| 21 | define( "WPCMP_PLUGIN_URL", plugin_dir_url( __FILE__ ) ); |
| 22 | |
| 23 | /** |
| 24 | * Main Class |
| 25 | */ |
| 26 | class WP_CREATE_MULTI_POSTS_PAGES |
| 27 | { |
| 28 | /** |
| 29 | * Load Plugin Files & Add Hooks |
| 30 | */ |
| 31 | public function __construct() |
| 32 | { |
| 33 | add_action( 'init', array( $this, 'init' ) ); |
| 34 | |
| 35 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * |
| 40 | */ |
| 41 | public function init() |
| 42 | { |
| 43 | add_action( 'admin_menu', array( $this, 'add_menu_page' ) ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Add Plugin Settings page to wp menu dashboard |
| 48 | */ |
| 49 | public function add_menu_page() |
| 50 | { |
| 51 | add_menu_page( 'Multiple Posts', 'Multiple Posts', 'manage_options' , 'wp-add-multiple-posts', array( $this, 'wp_add_multiple_posts' ), 'dashicons-menu' ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Multi Post Creating Form |
| 56 | */ |
| 57 | public function wp_add_multiple_posts() |
| 58 | { |
| 59 | $post_types = $this->get_custom_post_types(); |
| 60 | |
| 61 | require_once WPCMP_PLUGIN_PATH . 'includes/settings.php'; ?> |
| 62 | |
| 63 | <div class="wrap"> |
| 64 | <h2>Create Multiple Posts</h2> |
| 65 | <?php if ( isset( $wpcmp_show_message ) ) : ?> |
| 66 | <div class="notice notice-<?php echo $wpcmp_show_message; ?> is-dismissible posts_create_success_failure_message"> |
| 67 | <p><?php echo $wpcmp_message; ?></p> |
| 68 | </div> |
| 69 | <?php $i = 0; ?> |
| 70 | <div class="notice notice-success is-dismissible" style="padding-right: 10px;"> |
| 71 | <h2>Created Posts :</h2> |
| 72 | <div class="container-fluid"> |
| 73 | <?php foreach ( $created_posts as $id ) : $i++; ?> |
| 74 | <div class="row" style="border-bottom: 1px solid lightgrey;"> |
| 75 | <p class="col-md-11" style="line-height: 28px;"><?php echo esc_html( get_the_title( $id ) ); ?></p> |
| 76 | |
| 77 | <p class="col-md-1" style="text-align: right;"><a href="<?php echo get_the_permalink($id); ?>" class='button' style="margin-right: 10px;">View</a><a href="<?php echo get_edit_post_link( $id ); ?>" class='button'>Edit</a></p> |
| 78 | </div> |
| 79 | <?php endforeach; ?> |
| 80 | </div> |
| 81 | </div> |
| 82 | |
| 83 | <?php endif; ?> |
| 84 | |
| 85 | <form action="" method="post"> |
| 86 | <div class="form-group"> |
| 87 | <p class="col-form-label insert_note">Insert Posts Title One Per Line...</p> |
| 88 | <textarea class="form-control new_line_bg new_line_number" name="wpcmp_posts_titles" id="wpcmp_posts_titles" cols="30" rows="8"></textarea> |
| 89 | </div> |
| 90 | <div class="form-group"> |
| 91 | <div class="row"> |
| 92 | <div class="col"> |
| 93 | <p class="col-form-label insert_note">Post Type</p> |
| 94 | <select name="wpcmp_new_post_type" id="wpcmp_new_post_type" class="form-control" disabled> |
| 95 | <?php foreach ( $post_types as $post_type ) : ?> |
| 96 | <option value="<?php echo $post_type; ?>"><?php echo ucfirst( $post_type ) ?></option> |
| 97 | <?php endforeach ?> |
| 98 | </select> |
| 99 | </div> |
| 100 | <div class="col"> |
| 101 | <p class="col-form-label insert_note">Post Status</p> |
| 102 | <select name="wpcmp_new_post_status" id="wpcmp_new_post_status" class="form-control" disabled> |
| 103 | <!-- <option value="" disabled selected style="display:none"></option> --> |
| 104 | <option value="publish">Publish</option> |
| 105 | <option value="draft">Draft</option> |
| 106 | <option value="pending">Pending</option> |
| 107 | <option value="private">Private</option> |
| 108 | </select> |
| 109 | </div> |
| 110 | |
| 111 | <div class="col"> |
| 112 | <p class="col-form-label insert_note">Post Author</p> |
| 113 | <select name="wpcmp_new_post_author" id="wpcmp_new_post_author" class="form-control" disabled> |
| 114 | <!-- <option value="" disabled selected style="display:none"></option> --> |
| 115 | <?php |
| 116 | |
| 117 | $users = get_users( 'who=authors' ); |
| 118 | |
| 119 | foreach ( $users as $user ) { |
| 120 | |
| 121 | echo '<option value="'.$user->ID.'">'.ucwords( str_replace( "_", " ", $user->user_login ) ).'</option>'; |
| 122 | } |
| 123 | ?> |
| 124 | </select> |
| 125 | </div> |
| 126 | |
| 127 | <div class="col"> |
| 128 | <p class="col-form-label insert_note">Post Category (<small>Posts Only)</small></p> |
| 129 | <select name="wpcmp_new_post_category[]" id="wpcmp_new_post_category" class="form-control" multiple disabled> |
| 130 | <?php |
| 131 | foreach ( get_categories() as $category ) { |
| 132 | |
| 133 | echo '<option value="'.$category->term_id.'">'.ucwords( str_replace( "_", " ", $category->cat_name ) ).'</option>'; |
| 134 | } |
| 135 | ?> |
| 136 | </select> |
| 137 | </div> |
| 138 | </div> |
| 139 | </div> |
| 140 | <?php wp_nonce_field( 'wpcmp_create_posts', 'wpcmp_nonce' ); ?> |
| 141 | |
| 142 | <button type="submit" class="button" name="wpcmp_submit_for_create_posts" id="wpcmp_submit_for_create_posts" disabled>Add Posts</button> |
| 143 | </form> |
| 144 | </div> |
| 145 | |
| 146 | <?php } |
| 147 | |
| 148 | /** |
| 149 | * Enqueue JS & CSS Files |
| 150 | */ |
| 151 | public function admin_enqueue_scripts() |
| 152 | { |
| 153 | wp_enqueue_style ( 'wpcmp_bootstrap_css', WPCMP_PLUGIN_URL . '/assets/css/bootstrap.css', false ); |
| 154 | |
| 155 | wp_enqueue_style ( 'wpcmpselect2_css', WPCMP_PLUGIN_URL . 'assets/css/select2.min.css', true ); |
| 156 | |
| 157 | wp_enqueue_style ( 'wpcmp_style_css', WPCMP_PLUGIN_URL . '/assets/css/style.css', false ); |
| 158 | |
| 159 | wp_enqueue_script( 'wpcmpselect2_js', WPCMP_PLUGIN_URL . 'assets/js/select2.min.js', true ); |
| 160 | |
| 161 | wp_enqueue_script( 'wpcmp_popper_js', WPCMP_PLUGIN_URL . '/assets/js/popper.min.js', true ); |
| 162 | |
| 163 | wp_enqueue_script( 'wpcmp_bootstrap_js', WPCMP_PLUGIN_URL . '/assets/js/bootstrap.min.js', array( 'jquery', 'wpcmp_popper_js' ), true ); |
| 164 | |
| 165 | wp_enqueue_script( 'wpcmp_linedtextarea', WPCMP_PLUGIN_URL . '/assets/js/linedtextarea.js', array( 'jquery' ), true ); |
| 166 | |
| 167 | wp_enqueue_script( 'wpcmp_script', WPCMP_PLUGIN_URL . '/assets/js/script.js', array( 'jquery' ), true ); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Get All Custom Post Types Registered By Others |
| 172 | */ |
| 173 | function get_custom_post_types() |
| 174 | { |
| 175 | $all_post_types = array( 'post', 'page' ); |
| 176 | |
| 177 | $args = array( |
| 178 | 'public' => true, |
| 179 | '_builtin' => false, |
| 180 | ); |
| 181 | |
| 182 | $output = 'names'; // names or objects, note names is the default |
| 183 | |
| 184 | $operator = 'and'; // 'and' or 'or' |
| 185 | |
| 186 | $post_types = get_post_types( $args, $output, $operator ); |
| 187 | |
| 188 | if ( ! empty( $post_types ) ) |
| 189 | { |
| 190 | $all_post_types = array_merge( $all_post_types, $post_types ); |
| 191 | } |
| 192 | |
| 193 | return $all_post_types; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | $WP_CREATE_MULTI_POSTS_PAGES = new WP_CREATE_MULTI_POSTS_PAGES(); |
| 198 |