From cc28a6347482fb115c1330135c896572b5a94cb7 Mon Sep 17 00:00:00 2001 From: daomapsieucap Date: Mon, 15 Jul 2024 10:32:50 +0700 Subject: [PATCH 01/13] feat(global): rename plugin to Dummie --- lipsum-dynamo.php | 8 ++++---- readme.txt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lipsum-dynamo.php b/lipsum-dynamo.php index 562c954..ef5913a 100644 --- a/lipsum-dynamo.php +++ b/lipsum-dynamo.php @@ -1,6 +1,6 @@ Date: Mon, 15 Jul 2024 10:33:06 +0700 Subject: [PATCH 02/13] refactor(global): re-format code --- includes/cleanup.php | 26 +++++++++++++------------- includes/generate-items.php | 32 ++++++++++++++++---------------- includes/setting/setting.php | 18 +++++++++--------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/includes/cleanup.php b/includes/cleanup.php index a50415a..504a502 100644 --- a/includes/cleanup.php +++ b/includes/cleanup.php @@ -9,23 +9,23 @@ */ class Lipsum_Dynamo_Cleanup{ public function __construct(){ - add_action('admin_enqueue_scripts', array($this, 'lipnamo_cleanup_scripts')); + add_action('admin_enqueue_scripts', [$this, 'lipnamo_cleanup_scripts']); - add_action("wp_ajax_lipnamo_cleanup_items", array($this, 'lipnamo_cleanup_items')); - add_action("wp_ajax_nopriv_lipnamo_cleanup_items", array($this, 'lipnamo_cleanup_items')); + add_action("wp_ajax_lipnamo_cleanup_items", [$this, 'lipnamo_cleanup_items']); + add_action("wp_ajax_nopriv_lipnamo_cleanup_items", [$this, 'lipnamo_cleanup_items']); - add_action("wp_ajax_lipnamo_total_items", array($this, 'lipnamo_update_total_items')); - add_action("wp_ajax_nopriv_lipnamo_total_items", array($this, 'lipnamo_update_total_items')); + add_action("wp_ajax_lipnamo_total_items", [$this, 'lipnamo_update_total_items']); + add_action("wp_ajax_nopriv_lipnamo_total_items", [$this, 'lipnamo_update_total_items']); } public function lipnamo_cleanup_scripts($hook_suffix){ if(strpos($hook_suffix, 'lipsum-dynamo') !== false){ - wp_enqueue_script('lipnamo-cleanup-items', LIPNAMO_ASSETS_URL . 'js/lipnamo-cleanup-items.js', array('jquery'), LIPNAMO_VERSION, true); + wp_enqueue_script('lipnamo-cleanup-items', LIPNAMO_ASSETS_URL . 'js/lipnamo-cleanup-items.js', ['jquery'], DUMMIE_VERSION, true); wp_localize_script('lipnamo-cleanup-items', 'lipnamo_items', - array( + [ 'ajax_url' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce('lipnamo_ajax_nonce'), - ) + ] ); } } @@ -48,7 +48,7 @@ public function lipnamo_cleanup_items(){ // Exit if invalid post type if($post_type !== 'any'){ - $valid_post_types = get_post_types(array('public' => true), 'objects'); + $valid_post_types = get_post_types(['public' => true], 'objects'); if(!in_array($post_type, array_keys($valid_post_types))){ return; } @@ -84,9 +84,9 @@ public function lipnamo_cleanup_items(){ } // Store results in an array. - $result = array( - 'step' => $post_step - ); + $result = [ + 'step' => $post_step, + ]; if($post_step >= $post_total){ $result['message'] = 'Deleted total ' . $post_total . ' items'; @@ -113,7 +113,7 @@ public function lipnamo_update_total_items(){ // Exit if invalid post type if($post_type !== 'any'){ - $valid_post_types = get_post_types(array('public' => true), 'objects'); + $valid_post_types = get_post_types(['public' => true], 'objects'); if(!in_array($post_type, array_keys($valid_post_types))){ return; } diff --git a/includes/generate-items.php b/includes/generate-items.php index 6ea0bd1..e9cdc24 100644 --- a/includes/generate-items.php +++ b/includes/generate-items.php @@ -11,20 +11,20 @@ */ class Lipsum_Dynamo_Generate{ public function __construct(){ - add_action('admin_enqueue_scripts', array($this, 'lipnamo_generate_scripts')); + add_action('admin_enqueue_scripts', [$this, 'lipnamo_generate_scripts']); - add_action("wp_ajax_lipnamo_generate_items", array($this, 'lipnamo_generate_items')); - add_action("wp_ajax_nopriv_lipnamo_generate_items", array($this, 'lipnamo_generate_items')); + add_action("wp_ajax_lipnamo_generate_items", [$this, 'lipnamo_generate_items']); + add_action("wp_ajax_nopriv_lipnamo_generate_items", [$this, 'lipnamo_generate_items']); } public function lipnamo_generate_scripts($hook_suffix){ if(strpos($hook_suffix, 'lipsum-dynamo') !== false){ - wp_enqueue_script('lipnamo-generate-items', LIPNAMO_ASSETS_URL . 'js/lipnamo-generate-items.js', array('jquery'), LIPNAMO_VERSION, true); + wp_enqueue_script('lipnamo-generate-items', LIPNAMO_ASSETS_URL . 'js/lipnamo-generate-items.js', ['jquery'], DUMMIE_VERSION, true); wp_localize_script('lipnamo-generate-items', 'lipnamo_items', - array( + [ 'ajax_url' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce('lipnamo_ajax_nonce'), - ) + ] ); } } @@ -52,7 +52,7 @@ public function lipnamo_generate_items(){ $post_step = intval(lipnamo_array_key_exists('post_step', $_POST)); // Exit if invalid post type - $valid_post_types = get_post_types(array('public' => true), 'objects'); + $valid_post_types = get_post_types(['public' => true], 'objects'); if(!in_array($post_type, array_keys($valid_post_types))){ return; } @@ -99,14 +99,14 @@ public function lipnamo_generate_items(){ $post_content = $generator->paragraphs($content_paragraphs); // Create post - $new_post = array( + $new_post = [ 'post_type' => $post_type, 'post_title' => wp_strip_all_tags($post_title), 'post_excerpt' => $post_excerpt, 'post_content' => $post_content, 'post_status' => $post_status, - 'post_author' => $post_author - ); + 'post_author' => $post_author, + ]; $post_id = wp_insert_post($new_post); if(!is_wp_error($post_id) && $thumbnail_id){ set_post_thumbnail($post_id, $thumbnail_id); @@ -115,10 +115,10 @@ public function lipnamo_generate_items(){ if(!is_wp_error($post_id)){ global $wpdb; $table_name = $wpdb->prefix . 'lipnamo'; - $wpdb->insert($table_name, array( + $wpdb->insert($table_name, [ 'post_id' => $post_id, - 'post_type' => $post_type - )); + 'post_type' => $post_type, + ]); } $post_step ++; @@ -129,9 +129,9 @@ public function lipnamo_generate_items(){ } // Store results in an array. - $result = array( - 'step' => $post_step - ); + $result = [ + 'step' => $post_step, + ]; if($post_step >= $post_total){ $result['message'] = 'Created total ' . $post_total . ' items'; diff --git a/includes/setting/setting.php b/includes/setting/setting.php index dfa96d5..effddc2 100644 --- a/includes/setting/setting.php +++ b/includes/setting/setting.php @@ -10,20 +10,20 @@ class Lipsum_Dynamo_Setting{ public function __construct(){ - add_action('admin_menu', array($this, 'lipnamo_setting')); - add_action('admin_init', array($this, 'lipnamo_setting_init')); + add_action('admin_menu', [$this, 'lipnamo_setting']); + add_action('admin_init', [$this, 'lipnamo_setting_init']); - add_action("admin_enqueue_scripts", array($this, 'lipnamo_assets')); + add_action("admin_enqueue_scripts", [$this, 'lipnamo_assets']); } public function lipnamo_assets(){ - wp_enqueue_style('lipnamo-admin', LIPNAMO_ASSETS_URL . 'css/lipnamo-admin.css', false, LIPNAMO_VERSION); + wp_enqueue_style('lipnamo-admin', LIPNAMO_ASSETS_URL . 'css/lipnamo-admin.css', false, DUMMIE_VERSION); // Upload field wp_enqueue_media(); // Plugin scripts - wp_enqueue_script('lipnamo-admin', LIPNAMO_ASSETS_URL . 'js/lipnamo-admin.js', array('jquery'), LIPNAMO_VERSION); + wp_enqueue_script('lipnamo-admin', LIPNAMO_ASSETS_URL . 'js/lipnamo-admin.js', ['jquery'], DUMMIE_VERSION); } public function lipnamo_setting_init(){ @@ -46,7 +46,7 @@ public function lipnamo_setting(){ 'Lipsum Dynamo', 'manage_options', 'lipsum-dynamo', - array($this, 'lipnamo_setting_html'), + [$this, 'lipnamo_setting_html'], ); } @@ -96,11 +96,11 @@ public function lipnamo_setting_html(){ } public function lipnamo_setting_tabs(): array{ - return array( + return [ 'general' => 'General', 'cleanup' => 'Cleanup', 'uninstall' => 'Uninstall', - ); + ]; } public function lipnamo_setting_tab_navs($current = 'general'){ @@ -167,7 +167,7 @@ public function lipnamo_save_options(){ $new_options[$key] = sanitize_text_field($value); } }else{ - $new_options = array(); + $new_options = []; } update_option($option_key, $new_options); From 44321ea3f4e109368c1077df1bc0d552578c5277 Mon Sep 17 00:00:00 2001 From: daomapsieucap Date: Mon, 15 Jul 2024 10:37:23 +0700 Subject: [PATCH 03/13] feat(settings): rename settings title --- includes/setting/setting.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/setting/setting.php b/includes/setting/setting.php index effddc2..c5dc699 100644 --- a/includes/setting/setting.php +++ b/includes/setting/setting.php @@ -42,8 +42,8 @@ public function lipnamo_setting_init(){ public function lipnamo_setting(){ add_submenu_page( 'tools.php', - 'Lipsum Dynamo', - 'Lipsum Dynamo', + 'Dummie', + 'Dummie', 'manage_options', 'lipsum-dynamo', [$this, 'lipnamo_setting_html'], @@ -61,6 +61,8 @@ public function lipnamo_setting_html(){ $form_action = admin_url("tools.php?page=lipsum-dynamo&tab=" . $_GET['tab']); } + echo '

Dummie

'; + // nav echo '