Skip to content

Commit

Permalink
Merge pull request #2 from daomapsieucap/3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
daomapsieucap authored Jul 15, 2024
2 parents dd7e80a + 50615aa commit ca5a9dd
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 79 deletions.
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
== Changelog ==

= 3.1.0 =
*Release Date - 15 July 2024*

* New: Rename plugin to Dummie.
* Fixed: Fix wrong default admin post author.
* Changed: Tested up to 6.5.5.

= 3.0 =
*Release Date - 24 March 2022*

Expand Down
26 changes: 13 additions & 13 deletions includes/cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
]
);
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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';
Expand All @@ -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;
}
Expand Down
32 changes: 16 additions & 16 deletions includes/generate-items.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
]
);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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 ++;
Expand All @@ -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';
Expand Down
22 changes: 11 additions & 11 deletions includes/setting/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,60 +16,60 @@ public function lipnamo_general_page_init(){
register_setting(
'lipnamo_group',
'lipsum-dynamo-general',
array($this, 'sanitize_text_field')
[$this, 'sanitize_text_field']
);

add_settings_section(
'lipnamo_section',
'',
array($this, 'lipnamo_admin_section_info'),
[$this, 'lipnamo_admin_section_info'],
'lipsum-dynamo-general'
);

add_settings_field(
'lipnamo_post_total', // id
'Number of items', // title
array($this, 'lipnamo_post_total'), // callback
[$this, 'lipnamo_post_total'], // callback
'lipsum-dynamo-general', // page
'lipnamo_section' // section
);

add_settings_field(
'post_type', // id
'Select post type', // title
array($this, 'lipnamo_post_type'), // callback
[$this, 'lipnamo_post_type'], // callback
'lipsum-dynamo-general', // page
'lipnamo_section' // section
);

add_settings_field(
'post_author', // id
'Post author', // title
array($this, 'lipnamo_post_author'), // callback
[$this, 'lipnamo_post_author'], // callback
'lipsum-dynamo-general', // page
'lipnamo_section' // section
);

add_settings_field(
'post_status', // id
'New Item status', // title
array($this, 'lipnamo_post_status'), // callback
[$this, 'lipnamo_post_status'], // callback
'lipsum-dynamo-general', // page
'lipnamo_section' // section
);

add_settings_field(
'post_thumbnail', // id
'New Item Thumbnails', // title
array($this, 'lipnamo_post_thumbnail'), // callback
[$this, 'lipnamo_post_thumbnail'], // callback
'lipsum-dynamo-general', // page
'lipnamo_section' // section
);

add_settings_field(
'length_control', // id
'Length Control', // title
array($this, 'lipnamo_length_control'), // callback
[$this, 'lipnamo_length_control'], // callback
'lipsum-dynamo-general', // page
'lipnamo_section' // section
);
Expand All @@ -89,7 +89,7 @@ public function lipnamo_post_total(){
}

public function lipnamo_post_type(){
$post_types = get_post_types(array('public' => true), 'objects');
$post_types = get_post_types(['public' => true], 'objects');
?>
<fieldset>
<label for="post_type">
Expand All @@ -115,8 +115,8 @@ public function lipnamo_post_type(){
}

public function lipnamo_post_author(){
$users = get_users(array('role__in' => array('administrator'), 'fields' => array('ID')));
$admin_email = get_option('new_admin_email');
$users = get_users(['role__in' => ['administrator'], 'fields' => ['ID']]);
$admin_email = get_option('admin_email');
?>
<fieldset>
<label for="post_author">
Expand Down
53 changes: 26 additions & 27 deletions includes/setting/setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand All @@ -42,11 +42,11 @@ public function lipnamo_setting_init(){
public function lipnamo_setting(){
add_submenu_page(
'tools.php',
'Lipsum Dynamo',
'Lipsum Dynamo',
'Dummie',
'Dummie',
'manage_options',
'lipsum-dynamo',
array($this, 'lipnamo_setting_html'),
[$this, 'lipnamo_setting_html'],
);
}

Expand All @@ -56,34 +56,30 @@ public function lipnamo_setting_html(){
return;
}

$form_action = admin_url("tools.php?page=lipsum-dynamo");
if(isset ($_GET['tab'])){
$form_action = admin_url("tools.php?page=lipsum-dynamo&tab=" . $_GET['tab']);
}
$tab = esc_attr(lipnamo_array_key_exists('tab', $_GET));
$form_action = $tab ? admin_url("tools.php?page=lipsum-dynamo&tab=" . $tab) : admin_url("tools.php?page=lipsum-dynamo");

echo '<div class="wrap">';

echo '<h1>Dummie</h1>';

// nav
echo '<nav class="nav-tab-wrapper">';
if(isset ($_GET['tab'])){
$this->lipnamo_setting_tab_navs($_GET['tab']);
if($tab){
$this->lipnamo_setting_tab_navs($tab);
}else{
$this->lipnamo_setting_tab_navs();
}
echo '</nav>';

// content
echo '<div class="tab-content">';
echo '<div class="wrap">';

echo '<form class="lipsum-dynamo" method="POST" action="' . $form_action . '">';

wp_nonce_field("lipsum-dynamo");

$current_tab = 'general';
if(isset ($_GET['tab'])){
$current_tab = $_GET['tab'];
}

echo '<h1>' . $this->lipnamo_setting_tabs()[$current_tab] . '</h1>';

$current_tab = lipnamo_array_key_exists('tab', $_GET) ? : 'general';
if($current_tab == 'uninstall'){
echo '<p class="description">' . __("When you uninstall this plugin, what do you want to do with your settings and the generated dummy items? Be careful to use this option. It can't be reverted.", "lipsum-dynamo") . '</p>';
}
Expand All @@ -92,15 +88,18 @@ public function lipnamo_setting_html(){

echo '</form>';
echo '</div>';
echo '</div>';

echo '</div>'; // wrap
}

public function lipnamo_setting_tabs(): array{
return array(
$tabs = [
'general' => 'General',
'cleanup' => 'Cleanup',
'uninstall' => 'Uninstall',
);
];

return $tabs;
}

public function lipnamo_setting_tab_navs($current = 'general'){
Expand Down Expand Up @@ -159,15 +158,15 @@ class="lipnamo-<?php echo $btn; ?> button button-primary"><?php echo ucfirst($bt

public function lipnamo_save_options(){
global $pagenow;
if($pagenow == 'tools.php' && $_GET['page'] == 'lipsum-dynamo'){
if($pagenow == 'tools.php' && esc_attr(lipnamo_array_key_exists('page', $_GET)) == 'lipsum-dynamo'){
$option_key = 'lipsum-dynamo';
if(isset($_POST[$option_key])){
$options = $new_options = $_POST[$option_key];
foreach($options as $key => $value){
$new_options[$key] = sanitize_text_field($value);
}
}else{
$new_options = array();
$new_options = [];
}

update_option($option_key, $new_options);
Expand Down
Loading

0 comments on commit ca5a9dd

Please sign in to comment.