Changeset 3009284
- Timestamp:
- 12/13/2023 09:49:44 AM (8 months ago)
- Location:
- add-dummy-post/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
add-dummy-post/trunk/add-dummy-post.php
r3002229 r3009284 4 4 Plugin URI: https://wordpress.org/plugins/add-dummy-post/ 5 5 Description: Add Dummy Post in WordPress 6 Version: 1.0. 16 Version: 1.0. 7 7 Author: shubhamsedani 8 9 10 8 11 Text Domain: adp 12 13 14 15 9 16 */ 10 17 11 18 // Exit if accessed directly 12 if ( !defined( 'ABSPATH' )) exit;19 if () exit; 13 20 14 if ( !defined( 'ADP_DIR' )) {15 define('ADP_DIR', dirname( __FILE__ )); // plugin dir21 if) { 22 define('ADP_DIR', dirname(); // plugin dir 16 23 } 17 if ( !defined( 'ADP_URL' )) {18 define('ADP_URL', plugin_dir_url( __FILE__ )); // plugin url24 if) { 25 define('ADP_URL', plugin_dir_url(); // plugin url 19 26 } 20 //get more knowledge on this 21 if( !defined('ADP_BASENAME') ){ 27 if (!defined('ADP_BASENAME')) { 22 28 define('ADP_BASENAME', 'ADP'); // plugin base name 23 29 } 24 if ( !defined( 'ADP_ADMIN_DIR' )) {25 define('ADP_ADMIN_DIR', ADP_DIR . '/backend' 30 if) { 31 define('ADP_ADMIN_DIR', ADP_DIR . '/backend'); // plugin admin dir 26 32 } 27 if ( !defined( 'ADP_ADMIN_URL' )) {28 define('ADP_ADMIN_URL', ADP_DIR . 'backend' 33 if) { 34 define('ADP_ADMIN_URL', ADP_DIR . 'backend'); // plugin admin url 29 35 } 30 if ( !defined( 'ADP_FRONT_DIR' )) {31 define('ADP_ FRONT_DIR', ADP_DIR . '/frontend' ); // plugin frontend dir36 if) { 37 define('ADP_ 32 38 } 33 if( !defined( 'ADP_FRONT_URL' ) ) { 34 define('ADP_FRONT_URL', ADP_DIR . 'frontend' ); // plugin frontend url 35 } 36 if( !defined( 'ADP_SETTINGS_TABLE' ) ) { 37 define( 'ADP_SETTINGS_TABLE', 'ADP_settings' ); // define the table name - to store seleted options details 38 } 39 39 40 //include custom function file for backend 40 41 include ADP_ADMIN_DIR . '/includes/adp-back-end-custom-functions.php'; 41 42 42 //include custom function file for frontend43 include ADP_FRONT_DIR . '/includes/adp-front-end-custom-functions.php';44 45 43 //get more knowledge on this 46 function adp_load_scripts() { 44 function adp_load_scripts() 45 { 47 46 wp_enqueue_style('adp_custom_css', ADP_URL . 'backend/assets/public-style.css'); 48 47 wp_enqueue_script('adp_custom_js', ADP_URL . 'backend/assets/public-script.js'); 49 48 } 50 add_action( 'admin_init','adp_load_scripts');49 add_action('adp_load_scripts'); 51 50 52 51 /** … … 55 54 * Register plugin activation hook. 56 55 */ 57 register_activation_hook( __FILE__, 'adp_install');56 register_activation_hook(); 58 57 59 58 /** … … 62 61 * Register plugin deactivation hook. 63 62 */ 64 register_deactivation_hook( __FILE__, 'adp_deactivate');63 register_deactivation_hook(); 65 64 66 65 /** … … 69 68 * Register plugin deactivation hook. 70 69 */ 71 register_uninstall_hook ( __FILE__, 'adp_uninstall');70 register_uninstall_hook); 72 71 73 72 /** … … 77 76 * stest default values for the plugin options. 78 77 */ 79 function adp_install() { 78 function adp_install() 79 { 80 80 //create custom table for plugin 81 82 //IMP Call of Function 83 //Need to call when custom post type is being used in plugin 81 //Need to call this without fail when custom post type is being used in plugin 84 82 flush_rewrite_rules(); 85 83 } … … 90 88 * Delete plugin options. 91 89 */ 92 function adp_deactivate() { 90 function adp_deactivate() 91 { 92 // Delete time process 93 } 93 94 94 }95 95 /** 96 96 * Plugin Setup (On Uninstall) … … 98 98 * Delete plugin options. 99 99 */ 100 function adp_uninstall() { 100 function adp_uninstall() 101 { 101 102 //drop custom table for plugin 102 103 } 103 104 ?> -
add-dummy-post/trunk/backend/includes/adp-back-end-custom-functions.php
r2758914 r3009284 1 1 <?php 2 2 // Exit if accessed directly 3 if ( !defined( 'ABSPATH' )) exit;3 if () exit; 4 4 5 5 // import page settings 6 function adp_dummy_settings(){ 6 function adp_dummy_settings() 7 { 7 8 include ADP_ADMIN_DIR . '/methods/adp-import-settings.php'; 8 9 } … … 16 17 * Add Custom admin menu 17 18 */ 18 function adp_add_custom_admin_menu(){ 19 add_management_page( esc_html__( 'Dummy Post Settings', 'adp' ), esc_html__( 'Add Dummy Post', 'adp' ), 'manage_options', 'adp-post', 'adp_dummy_settings'); 19 function adp_add_custom_admin_menu() 20 { 21 add_management_page(esc_html__('Dummy Post Settings', 'adp'), esc_html__('Add Dummy Post', 'adp'), 'manage_options', 'adp-post', 'adp_dummy_settings'); 20 22 } 21 22 //Action to call the admin menu function 23 add_action( 'admin_menu', 'adp_add_custom_admin_menu' ); 23 add_action('admin_menu', 'adp_add_custom_admin_menu'); 24 24 25 25 26 26 //function to check the session 27 function adp_register_my_session(){ 28 if( ! session_id() ) { 27 function adp_register_my_session() 28 { 29 if (!session_id()) { 29 30 session_start(); 30 31 } … … 32 33 33 34 add_action('init', 'adp_register_my_session'); 34 ?> -
add-dummy-post/trunk/backend/methods/adp-import-functions.php
r2758914 r3009284 1 1 <?php 2 2 // Exit if accessed directly 3 if ( !defined( 'ABSPATH' )) exit;3 if () exit; 4 4 5 // Check if user form is submitted and start the import process 6 if( isset($_POST['adp_submit'] ) && !empty( $_POST['blog_number'] ) ){ 5 // check if user is login, if yes then only add new posts 6 function adp_handle_form_submission() 7 { 8 // Check if user form is submitted and start the import process 9 if (isset($_POST['adp_submit']) && !empty($_POST['adp_submit']) && !empty($_POST['blog_number']) && isset($_POST['blog_number'])) { 10 // Verify nonce 11 if (isset($_POST['adp_nonce']) && wp_verify_nonce($_POST['adp_nonce'], 'adp_nonce_action')) { 12 // Check the user permission 13 if (current_user_can('manage_options')) { 14 if (is_user_logged_in() == true) { 15 try { 16 $number_of_post = intval($_POST['blog_number']); 17 str_replace(" ", "", $number_of_post); 7 18 8 // check if user is login, if yes then only add new posts 9 function adp_login_function(){ 10 if ( is_user_logged_in() == true ) { 19 // generate dummy content and title 20 abstract class AdpLorem 21 { 22 public static function title($nparagraphs) 23 { 24 $paragraphs = []; 25 for ($p = 0; $p < $nparagraphs; ++$p) { 26 $nsentences = 1; 27 $sentences = []; 28 for ($s = 0; $s < $nsentences; ++$s) { 29 $frags = []; 30 $commaChance = .33; 31 while (true) { 32 $nwords = 5; 33 $words = self::randomValues(self::$lorem, $nwords); 34 $frags[] = implode(' ', $words); 35 if (self::randomFloat() >= $commaChance) { 36 break; 37 } 38 $commaChance /= 2; 39 } 40 $sentences[] = ucfirst(implode(', ', $frags)) . '.'; 41 } 42 $paragraphs[] = implode(' ', $sentences); 43 } 44 return implode("\n\n", $paragraphs); 45 } 11 46 12 try {13 $number_of_post = intval($_POST['blog_number']);14 str_replace(" ", "", $number_of_post);15 16 // generate dummy content and title17 abstract class adp_lorem {18 public static function title($nparagraphs) {19 $paragraphs = [];20 for($p = 0; $p < $nparagraphs; ++$p) {21 $nsentences = 1;22 $sentences = [];23 for($s = 0; $s < $nsentences; ++$s) {24 $frags = [];25 $commaChance = .33;26 while(true) {27 $nwords = 5;28 $words = self::random_values(self::$lorem, $nwords);29 $frags[] = implode(' ', $words);30 if(self::random_float() >= $commaChance) { 31 break;47 48 49 ; 50 51 52 53 s) { 54 s = []; 55 56 57 ; 58 59 ; 60 61 62 63 ; 64 65 66 ; 32 67 } 33 $ commaChance /= 2;68 $; 34 69 } 35 36 $sentences[] = ucfirst(implode(', ', $frags)) . '.'; 70 return implode("</br></br>", $paragraphs); 37 71 } 38 $paragraphs[] = implode(' ', $sentences); 72 73 private static function randomFloat() 74 { 75 return random_int(0, PHP_INT_MAX - 1) / PHP_INT_MAX; 76 } 77 78 private static function randomValues($arr, $count) 79 { 80 $keys = array_rand($arr, $count); 81 if ($count == 1) { 82 $keys = [$keys]; 83 } 84 return array_intersect_key($arr, array_fill_keys($keys, null)); 85 } 86 87 private static $lorem = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'praesent', 'interdum', 'dictum', 'mi', 'non', 'egestas', 'nulla', 'in', 'lacus', 'sed', 'sapien', 'placerat', 'malesuada', 'at', 'erat', 'etiam', 'id', 'velit', 'finibus', 'viverra', 'maecenas', 'mattis', 'volutpat', 'justo', 'vitae', 'vestibulum', 'metus', 'lobortis', 'mauris', 'luctus', 'leo', 'feugiat', 'nibh', 'tincidunt', 'a', 'integer', 'facilisis', 'lacinia', 'ligula', 'ac', 'suspendisse', 'eleifend', 'nunc', 'nec', 'pulvinar', 'quisque', 'ut', 'semper', 'auctor', 'tortor', 'mollis', 'est', 'tempor', 'scelerisque', 'venenatis', 'quis', 'ultrices', 'tellus', 'nisi', 'phasellus', 'aliquam', 'molestie', 'purus', 'convallis', 'cursus', 'ex', 'massa', 'fusce', 'felis', 'fringilla', 'faucibus', 'varius', 'ante', 'primis', 'orci', 'et', 'posuere', 'cubilia', 'curae', 'proin', 'ultricies', 'hendrerit', 'ornare', 'augue', 'pharetra', 'dapibus', 'nullam', 'sollicitudin', 'euismod', 'eget', 'pretium', 'vulputate', 'urna', 'arcu', 'porttitor', 'quam', 'condimentum', 'consequat', 'tempus', 'hac', 'habitasse', 'platea', 'dictumst', 'sagittis', 'gravida', 'eu', 'commodo', 'dui', 'lectus', 'vivamus', 'libero', 'vel', 'maximus', 'pellentesque', 'efficitur', 'class', 'aptent', 'taciti', 'sociosqu', 'ad', 'litora', 'torquent', 'per', 'conubia', 'nostra', 'inceptos', 'himenaeos', 'fermentum', 'turpis', 'donec', 'magna', 'porta', 'enim', 'curabitur', 'odio', 'rhoncus', 'blandit', 'potenti', 'sodales', 'accumsan', 'congue', 'neque', 'duis', 'bibendum', 'laoreet', 'elementum', 'suscipit', 'diam', 'vehicula', 'eros', 'nam', 'imperdiet', 'sem', 'ullamcorper', 'dignissim', 'risus', 'aliquet', 'habitant', 'morbi', 'tristique', 'senectus', 'netus', 'fames', 'nisl', 'iaculis', 'cras', 'aenean']; 39 88 } 40 return implode("\n\n", $paragraphs); 89 90 // add new dummy post to the wordpress posts 91 if (is_numeric($number_of_post) && $number_of_post < 51) { 92 $blog_data = array(); 93 94 for ($i = 0; $i < $number_of_post; $i++) { 95 $title = AdpLorem::title(1); 96 $para = AdpLorem::para(5); 97 98 if (!empty($title)) { 99 $blog_args['post_title'] = $title; 100 } 101 102 if (!empty($para)) { 103 $blog_args['post_content'] = $para; 104 $blog_args['post_status'] = 'publish'; 105 $blog_args['post_author'] = '1'; 106 } 107 108 try { 109 $post_id = wp_insert_post($blog_args); 110 } catch (\Throwable $th) { 111 echo esc_html__('There is a problem while inserting the posts', 'adp'); 112 } 113 } 114 } 115 } catch (\Throwable $th) { 116 echo esc_html__('There is a problem in the input of data', 'adp'); 41 117 } 42 43 public static function para($nparagraphs) {44 $paragraphs = [];45 for($p = 0; $p < $nparagraphs; ++$p) {46 $nsentences = random_int(3, 8);47 $sentences = [];48 for($s = 0; $s < $nsentences; ++$s) {49 $frags = [];50 $commaChance = .33;51 while(true) {52 $nwords = random_int(3, 15);53 $words = self::random_values(self::$lorem, $nwords);54 $frags[] = implode(' ', $words);55 if(self::random_float() >= $commaChance) {56 break;57 }58 $commaChance /= 2;59 }60 61 $sentences[] = ucfirst(implode(', ', $frags)) . '.';62 }63 $paragraphs[] = implode(' ', $sentences);64 }65 return implode("</br></br>", $paragraphs);66 }67 68 private static function random_float() {69 return random_int(0, PHP_INT_MAX - 1) / PHP_INT_MAX;70 }71 72 private static function random_values($arr, $count) {73 $keys = array_rand($arr, $count);74 if($count == 1) {75 $keys = [$keys];76 }77 return array_intersect_key($arr, array_fill_keys($keys, null));78 }79 80 private static $lorem = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'praesent', 'interdum', 'dictum', 'mi', 'non', 'egestas', 'nulla', 'in', 'lacus', 'sed', 'sapien', 'placerat', 'malesuada', 'at', 'erat', 'etiam', 'id', 'velit', 'finibus', 'viverra', 'maecenas', 'mattis', 'volutpat', 'justo', 'vitae', 'vestibulum', 'metus', 'lobortis', 'mauris', 'luctus', 'leo', 'feugiat', 'nibh', 'tincidunt', 'a', 'integer', 'facilisis', 'lacinia', 'ligula', 'ac', 'suspendisse', 'eleifend', 'nunc', 'nec', 'pulvinar', 'quisque', 'ut', 'semper', 'auctor', 'tortor', 'mollis', 'est', 'tempor', 'scelerisque', 'venenatis', 'quis', 'ultrices', 'tellus', 'nisi', 'phasellus', 'aliquam', 'molestie', 'purus', 'convallis', 'cursus', 'ex', 'massa', 'fusce', 'felis', 'fringilla', 'faucibus', 'varius', 'ante', 'primis', 'orci', 'et', 'posuere', 'cubilia', 'curae', 'proin', 'ultricies', 'hendrerit', 'ornare', 'augue', 'pharetra', 'dapibus', 'nullam', 'sollicitudin', 'euismod', 'eget', 'pretium', 'vulputate', 'urna', 'arcu', 'porttitor', 'quam', 'condimentum', 'consequat', 'tempus', 'hac', 'habitasse', 'platea', 'dictumst', 'sagittis', 'gravida', 'eu', 'commodo', 'dui', 'lectus', 'vivamus', 'libero', 'vel', 'maximus', 'pellentesque', 'efficitur', 'class', 'aptent', 'taciti', 'sociosqu', 'ad', 'litora', 'torquent', 'per', 'conubia', 'nostra', 'inceptos', 'himenaeos', 'fermentum', 'turpis', 'donec', 'magna', 'porta', 'enim', 'curabitur', 'odio', 'rhoncus', 'blandit', 'potenti', 'sodales', 'accumsan', 'congue', 'neque', 'duis', 'bibendum', 'laoreet', 'elementum', 'suscipit', 'diam', 'vehicula', 'eros', 'nam', 'imperdiet', 'sem', 'ullamcorper', 'dignissim', 'risus', 'aliquet', 'habitant', 'morbi', 'tristique', 'senectus', 'netus', 'fames', 'nisl', 'iaculis', 'cras', 'aenean'];81 118 } 82 83 // add new dummy post to the wordpress posts84 if(is_numeric($number_of_post) && $number_of_post < 51){85 $blog_data = array();86 87 for($i=0; $i<$number_of_post; $i++){88 $title = adp_lorem::title(1);89 $para = adp_lorem::para(5);90 91 if( !empty( $title ) ){92 $blog_args['post_title'] = $title;93 }94 95 if( !empty( $para ) ){96 $blog_args['post_content'] = $para;97 $blog_args['post_status'] = 'publish';98 $blog_args['post_author'] = '1';99 }100 101 try {102 $post_id = wp_insert_post( $blog_args );103 } catch (\Throwable $th) {104 _e( 'There is a problem while inserting the posts', 'adp' );105 }106 107 }108 }else{109 // $_SESSION['bigger_number'] = "The number is bigger then 50!";110 }111 112 } catch (\Throwable $th) {113 _e( 'There is a problem in the input of data', 'adp' );114 119 } 115 116 120 } 117 121 } 118 add_action('init', 'adp_login_function'); 119 122 // Redirect after form submission (change URL to your desired location) 123 wp_redirect(admin_url('tools.php?page=adp-post')); 124 exit; 120 125 } 121 126 122 123 124 125 ?> 127 // Hook to handle form submissions 128 add_action('admin_post_adp_handle_form_submission', 'adp_handle_form_submission'); 129 add_action('admin_post_nopriv_adp_handle_form_submission', 'adp_handle_form_submission'); -
add-dummy-post/trunk/backend/methods/adp-import-settings.php
r2758914 r3009284 1 <?php 1 <?php 2 2 // Exit if accessed directly 3 if ( !defined( 'ABSPATH' )) exit;3 if () exit; 4 4 5 5 ?> … … 7 7 <div class="adp-display-page"> 8 8 <div class="adp_customheader"> 9 <h2><?php _e( 'Add Dummy Blog Posts', 'adp') ?></h2>9 <h2><?php ) ?></h2> 10 10 </div> 11 11 12 <?php 13 // if ( array_key_exists( 'bigger_number', $_SESSION ) ) { ?> 14 <!-- <div class="adp_wrapper"> 15 <div class='adp_userInputForm'> 16 <div class="notice notice-error is-dismissible wot_error_spacing"> 17 <p> 18 <?php// echo esc_attr($_SESSION['bigger_number']); ?> 19 </p> 20 </div> 21 </div> 22 </div> --> 23 <?php// unset($_SESSION['bigger_number']); 24 // } 25 ?> 12 <form method='post' action ='<?php echo esc_url(admin_url('admin-post.php')); ?>'> 13 <!-- Adding Nonce Field --> 14 <?php wp_nonce_field('adp_nonce_action', 'adp_nonce'); ?> 26 15 27 <form method='post' action =''>28 16 <div class="adp_wrapper"> 29 17 <div class='adp_userInputForm'> 30 18 <div class="adp_get_number_of_post"> 31 <label for="blog_number" class="blog_number_label"><?php _e( 'Enter number of post you want to add:', 'adp' ); ?></label> 32 <input type="number" class="blog_number" name="blog_number" max="50"> 19 <label for="blog_number" class="blog_number_label"> 20 <?php echo esc_html__('Enter number of post you want to add:', 'adp'); ?> 21 </label> 22 <input type="number" class="blog_number" name="blog_number" min="0" max="50"> 23 <input type="hidden" name="action" value="adp_handle_form_submission"> 33 24 </div> 34 25 <div> -
add-dummy-post/trunk/readme.txt
r3002478 r3009284 4 4 License: GPLv2 or later 5 5 License URI: http://www.gnu.org/licenses/gpl-2.0.html 6 Requires at least: 3.36 Requires at least: 7 7 Tested up to: 6.4.1 8 Stable tag: 1.0. 19 Requires PHP: 7.08 Stable tag: 1.0. 9 Requires PHP: 10 10 11 11 == Description ==
Note: See TracChangeset
for help on using the changeset viewer.