feat(ui): add bilingual ID/EN support, toggle language, and documentation sidebars
This commit is contained in:
+205
-57
@@ -47,10 +47,11 @@ class DummyLab {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ui_lang = isset($_GET['ui_lang']) && $_GET['ui_lang'] === 'en' ? 'en' : 'id';
|
||||||
$users = get_users(['fields' => ['ID', 'display_name']]);
|
$users = get_users(['fields' => ['ID', 'display_name']]);
|
||||||
|
|
||||||
$query = new WP_Query([
|
$query = new WP_Query([
|
||||||
'post_type' => ['post', 'page'],
|
'post_type' => ['post', 'page', 'attachment'],
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'meta_key' => $this->meta_key,
|
'meta_key' => $this->meta_key,
|
||||||
'meta_value' => '1',
|
'meta_value' => '1',
|
||||||
@@ -58,10 +59,22 @@ class DummyLab {
|
|||||||
'post_status' => 'any',
|
'post_status' => 'any',
|
||||||
]);
|
]);
|
||||||
$dummy_count = $query->found_posts;
|
$dummy_count = $query->found_posts;
|
||||||
|
|
||||||
|
$t = $this->get_translations($ui_lang);
|
||||||
?>
|
?>
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||||
|
<div>
|
||||||
<h1>🧪 DummyLab – Post & Page Generator</h1>
|
<h1>🧪 DummyLab – Post & Page Generator</h1>
|
||||||
<p>Dibuat oleh <a href="https://masbudi.my.id" target="_blank">masbudikusuma</a> | <a href="https://apps.masbudikusuma.my.id/dummylab-wp" target="_blank">Dokumentasi Plugin</a></p>
|
<p><?php echo $t['created_by']; ?> <a href="https://masbudi.my.id" target="_blank">masbudikusuma</a> | <a href="https://apps.masbudikusuma.my.id/dummylab-wp" target="_blank"><?php echo $t['plugin_doc']; ?></a></p>
|
||||||
|
</div>
|
||||||
|
<!-- UI Language Switcher -->
|
||||||
|
<div style="background: #fff; border: 1px solid #ccc; padding: 6px 12px; border-radius: 4px;">
|
||||||
|
<strong>UI Language: </strong>
|
||||||
|
<a href="<?php echo esc_url(add_query_arg('ui_lang', 'id')); ?>" style="font-weight: <?php echo $ui_lang === 'id' ? 'bold' : 'normal'; ?>;">🇮🇩 ID</a> |
|
||||||
|
<a href="<?php echo esc_url(add_query_arg('ui_lang', 'en')); ?>" style="font-weight: <?php echo $ui_lang === 'en' ? 'bold' : 'normal'; ?>;">🇬🇧 EN</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
<?php if (isset($_GET['status'])): ?>
|
<?php if (isset($_GET['status'])): ?>
|
||||||
@@ -69,9 +82,9 @@ class DummyLab {
|
|||||||
<p>
|
<p>
|
||||||
<?php
|
<?php
|
||||||
if ($_GET['status'] === 'generated') {
|
if ($_GET['status'] === 'generated') {
|
||||||
echo esc_html(intval($_GET['count'])) . ' kontent dummy berhasil dibuat!';
|
echo esc_html(intval($_GET['count'])) . ' ' . esc_html($t['msg_generated']);
|
||||||
} elseif ($_GET['status'] === 'purged') {
|
} elseif ($_GET['status'] === 'purged') {
|
||||||
echo esc_html(intval($_GET['count'])) . ' data dummy berhasil dibersihkan!';
|
echo esc_html(intval($_GET['count'])) . ' ' . esc_html($t['msg_purged']);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
@@ -79,28 +92,30 @@ class DummyLab {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<div style="display: flex; gap: 20px; align-items: flex-start; margin-top: 20px;">
|
<div style="display: flex; gap: 20px; align-items: flex-start; margin-top: 20px;">
|
||||||
<div class="card" style="max-width: 650px; width: 100%; padding: 20px;">
|
<!-- Left Main Form -->
|
||||||
<h2>Generate Content Dummy</h2>
|
<div class="card" style="flex: 2; min-width: 500px; padding: 20px;">
|
||||||
|
<h2><?php echo $t['form_title']; ?></h2>
|
||||||
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
|
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
|
||||||
<?php wp_nonce_field('dummylab_generate_action', 'dummylab_nonce'); ?>
|
<?php wp_nonce_field('dummylab_generate_action', 'dummylab_nonce'); ?>
|
||||||
<input type="hidden" name="action" value="dummylab_generate">
|
<input type="hidden" name="action" value="dummylab_generate">
|
||||||
|
<input type="hidden" name="ui_lang" value="<?php echo esc_attr($ui_lang); ?>">
|
||||||
|
|
||||||
<table class="form-table">
|
<table class="form-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><label for="post_count">Jumlah Post/Halaman</label></th>
|
<th scope="row"><label for="post_count"><?php echo $t['lbl_count']; ?></label></th>
|
||||||
<td><input type="number" id="post_count" name="post_count" value="5" min="1" max="50" class="small-text" required></td>
|
<td><input type="number" id="post_count" name="post_count" value="5" min="1" max="50" class="small-text" required></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><label for="post_type">Tipe Konten</label></th>
|
<th scope="row"><label for="post_type"><?php echo $t['lbl_type']; ?></label></th>
|
||||||
<td>
|
<td>
|
||||||
<select name="post_type" id="post_type">
|
<select name="post_type" id="post_type">
|
||||||
<option value="post">Post</option>
|
<option value="post"><?php echo $t['opt_post']; ?></option>
|
||||||
<option value="page">Halaman (Page)</option>
|
<option value="page"><?php echo $t['opt_page']; ?></option>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><label for="content_lang">Bahasa Konten</label></th>
|
<th scope="row"><label for="content_lang"><?php echo $t['lbl_content_lang']; ?></label></th>
|
||||||
<td>
|
<td>
|
||||||
<select name="content_lang" id="content_lang">
|
<select name="content_lang" id="content_lang">
|
||||||
<option value="id">Bahasa Indonesia</option>
|
<option value="id">Bahasa Indonesia</option>
|
||||||
@@ -109,35 +124,35 @@ class DummyLab {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><label for="post_status">Status Post</label></th>
|
<th scope="row"><label for="post_status"><?php echo $t['lbl_status']; ?></label></th>
|
||||||
<td>
|
<td>
|
||||||
<select name="post_status" id="post_status">
|
<select name="post_status" id="post_status">
|
||||||
<option value="publish">Publish (terbit)</option>
|
<option value="publish"><?php echo $t['opt_publish']; ?></option>
|
||||||
<option value="draft">Draft</option>
|
<option value="draft"><?php echo $t['opt_draft']; ?></option>
|
||||||
<option value="pending">Pending Review</option>
|
<option value="pending"><?php echo $t['opt_pending']; ?></option>
|
||||||
<option value="private">Private</option>
|
<option value="private"><?php echo $t['opt_private']; ?></option>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><label for="categories">Kategori</label></th>
|
<th scope="row"><label for="categories"><?php echo $t['lbl_cats']; ?></label></th>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="categories" id="categories" class="regular-text" placeholder="Teknologi, Berita, Hiburan">
|
<input type="text" name="categories" id="categories" class="regular-text" placeholder="Teknologi, Berita, Hiburan">
|
||||||
<p class="description">Kategori dibuat otomatis jika belum ada. Pisahkan dengan koma. Tidak berlaku untuk Halaman.</p>
|
<p class="description"><?php echo $t['desc_cats']; ?></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><label for="tags">Tag Tambahan</label></th>
|
<th scope="row"><label for="tags"><?php echo $t['lbl_tags']; ?></label></th>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="tags" id="tags" class="regular-text" placeholder="wordpress, dummy, test">
|
<input type="text" name="tags" id="tags" class="regular-text" placeholder="wordpress, dummy, test">
|
||||||
<p class="description">Opsional, pisahkan dengan koma.</p>
|
<p class="description"><?php echo $t['desc_tags']; ?></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><label for="post_author">Penulis</label></th>
|
<th scope="row"><label for="post_author"><?php echo $t['lbl_author']; ?></label></th>
|
||||||
<td>
|
<td>
|
||||||
<select name="post_author" id="post_author">
|
<select name="post_author" id="post_author">
|
||||||
<option value="random">Acak dari semua pengguna</option>
|
<option value="random"><?php echo $t['opt_random_author']; ?></option>
|
||||||
<?php foreach ($users as $user): ?>
|
<?php foreach ($users as $user): ?>
|
||||||
<option value="<?php echo esc_attr($user->ID); ?>"><?php echo esc_html($user->display_name); ?></option>
|
<option value="<?php echo esc_attr($user->ID); ?>"><?php echo esc_html($user->display_name); ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@@ -145,65 +160,205 @@ class DummyLab {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><label for="date_option">Tanggal Post</label></th>
|
<th scope="row"><label for="date_option"><?php echo $t['lbl_date']; ?></label></th>
|
||||||
<td>
|
<td>
|
||||||
<select name="date_option" id="date_option">
|
<select name="date_option" id="date_option">
|
||||||
<option value="now">Waktu sekarang</option>
|
<option value="now"><?php echo $t['opt_date_now']; ?></option>
|
||||||
<option value="random_past">Acak dalam beberapa hari terakhir</option>
|
<option value="random_past"><?php echo $t['opt_date_past']; ?></option>
|
||||||
<option value="future">Rentang tanggal tertentu (Future/Scheduled)</option>
|
<option value="future"><?php echo $t['opt_date_future']; ?></option>
|
||||||
</select>
|
</select>
|
||||||
<p class="description">Jika tanggal di masa depan, status otomatis "Scheduled".</p>
|
<p class="description"><?php echo $t['desc_date']; ?></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><label for="content_length">Panjang Artikel</label></th>
|
<th scope="row"><label for="content_length"><?php echo $t['lbl_length']; ?></label></th>
|
||||||
<td>
|
<td>
|
||||||
<select name="content_length" id="content_length">
|
<select name="content_length" id="content_length">
|
||||||
<option value="short">Pendek (2-3 paragraf)</option>
|
<option value="short"><?php echo $t['opt_len_short']; ?></option>
|
||||||
<option value="medium" selected>Sedang (4-6 paragraf + heading)</option>
|
<option value="medium" selected><?php echo $t['opt_len_medium']; ?></option>
|
||||||
<option value="long">Panjang (7-10 paragraf + heading, list, quote)</option>
|
<option value="long"><?php echo $t['opt_len_long']; ?></option>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Gambar Unggulan</th>
|
<th scope="row"><?php echo $t['lbl_image']; ?></th>
|
||||||
<td>
|
<td>
|
||||||
<label><input type="checkbox" name="use_featured_image" value="1"> Sertakan gambar acak dari Picsum Photos</label><br><br>
|
<label><input type="checkbox" name="use_featured_image" value="1"> <?php echo $t['opt_use_img']; ?></label><br><br>
|
||||||
<select name="image_size" id="image_size">
|
<select name="image_size" id="image_size">
|
||||||
<option value="800/600">Kecil (800x600)</option>
|
<option value="800/600"><?php echo $t['opt_img_small']; ?></option>
|
||||||
<option value="1200/800" selected>Sedang (1200x800)</option>
|
<option value="1200/800" selected><?php echo $t['opt_img_med']; ?></option>
|
||||||
<option value="1600/1000">Besar (1600x1000)</option>
|
<option value="1600/1000"><?php echo $t['opt_img_large']; ?></option>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Opsi Tambahan</th>
|
<th scope="row"><?php echo $t['lbl_extra']; ?></th>
|
||||||
<td>
|
<td>
|
||||||
<label><input type="checkbox" name="add_comments" value="1"> Sertakan komentar dummy</label><br>
|
<label><input type="checkbox" name="add_comments" value="1"> <?php echo $t['opt_comments']; ?></label><br>
|
||||||
<label><input type="checkbox" name="make_sticky" value="1"> Jadikan post pertama sebagai sticky post (khusus Post)</label>
|
<label><input type="checkbox" name="make_sticky" value="1"> <?php echo $t['opt_sticky']; ?></label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php submit_button('Generate Data Dummy', 'primary', 'submit'); ?>
|
<?php submit_button($t['btn_generate'], 'primary', 'submit'); ?>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card" style="max-width: 300px; width: 100%; border-left: 4px solid #dc3232; padding: 20px;">
|
<!-- Right Sidebar Column -->
|
||||||
<h2>Cleanup / Rollback</h2>
|
<div style="flex: 1; min-width: 300px; display: flex; flex-direction: column; gap: 20px;">
|
||||||
<p>Total data dummy aktif: <strong><?php echo esc_html($dummy_count); ?></strong></p>
|
<!-- Rollback Card -->
|
||||||
|
<div class="card" style="border-left: 4px solid #dc3232; padding: 20px; margin: 0;">
|
||||||
|
<h2 style="color: #dc3232; margin-top: 0;"><?php echo $t['purge_title']; ?></h2>
|
||||||
|
<p><?php echo $t['purge_active']; ?>: <strong><?php echo esc_html($dummy_count); ?></strong></p>
|
||||||
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
|
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
|
||||||
<?php wp_nonce_field('dummylab_purge_action', 'dummylab_nonce'); ?>
|
<?php wp_nonce_field('dummylab_purge_action', 'dummylab_nonce'); ?>
|
||||||
<input type="hidden" name="action" value="dummylab_purge">
|
<input type="hidden" name="action" value="dummylab_purge">
|
||||||
<p class="description">Tindakan ini akan menghapus permanen seluruh post, page, dan gambar yang dibuat oleh DummyLab.</p>
|
<input type="hidden" name="ui_lang" value="<?php echo esc_attr($ui_lang); ?>">
|
||||||
<?php submit_button('Hapus Semua Data Dummy', 'delete', 'submit', true, ['disabled' => ($dummy_count === 0)]); ?>
|
<p class="description"><?php echo $t['purge_desc']; ?></p>
|
||||||
|
<?php submit_button($t['btn_purge'], 'delete', 'submit', true, ['disabled' => ($dummy_count === 0)]); ?>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- How to Use Documentation Card -->
|
||||||
|
<div class="card" style="padding: 20px; margin: 0;">
|
||||||
|
<h3 style="margin-top: 0;">📖 <?php echo $t['guide_title']; ?></h3>
|
||||||
|
<ol style="padding-left: 18px; line-height: 1.6;">
|
||||||
|
<li><?php echo $t['guide_step1']; ?></li>
|
||||||
|
<li><?php echo $t['guide_step2']; ?></li>
|
||||||
|
<li><?php echo $t['guide_step3']; ?></li>
|
||||||
|
<li><?php echo $t['guide_step4']; ?></li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Safety & Features Info Card -->
|
||||||
|
<div class="card" style="padding: 20px; margin: 0; background-color: #f8f9fa;">
|
||||||
|
<h3 style="margin-top: 0;">🛡️ <?php echo $t['safety_title']; ?></h3>
|
||||||
|
<ul style="padding-left: 18px; line-height: 1.6; list-style-type: disc;">
|
||||||
|
<li><?php echo $t['safety_item1']; ?></li>
|
||||||
|
<li><?php echo $t['safety_item2']; ?></li>
|
||||||
|
<li><?php echo $t['safety_item3']; ?></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_translations($lang) {
|
||||||
|
if ($lang === 'en') {
|
||||||
|
return [
|
||||||
|
'created_by' => 'Created by',
|
||||||
|
'plugin_doc' => 'Plugin Documentation',
|
||||||
|
'msg_generated' => 'dummy posts generated successfully!',
|
||||||
|
'msg_purged' => 'dummy items deleted successfully!',
|
||||||
|
'form_title' => 'Generate Dummy Content',
|
||||||
|
'lbl_count' => 'Post/Page Count',
|
||||||
|
'lbl_type' => 'Content Type',
|
||||||
|
'opt_post' => 'Post',
|
||||||
|
'opt_page' => 'Page',
|
||||||
|
'lbl_content_lang' => 'Content Language',
|
||||||
|
'lbl_status' => 'Post Status',
|
||||||
|
'opt_publish' => 'Publish',
|
||||||
|
'opt_draft' => 'Draft',
|
||||||
|
'opt_pending' => 'Pending Review',
|
||||||
|
'opt_private' => 'Private',
|
||||||
|
'lbl_cats' => 'Categories',
|
||||||
|
'desc_cats' => 'Categories created automatically if not present. Comma-separated. Ignored for Pages.',
|
||||||
|
'lbl_tags' => 'Additional Tags',
|
||||||
|
'desc_tags' => 'Optional, comma-separated.',
|
||||||
|
'lbl_author' => 'Author',
|
||||||
|
'opt_random_author' => 'Random from all users',
|
||||||
|
'lbl_date' => 'Post Date',
|
||||||
|
'opt_date_now' => 'Current time',
|
||||||
|
'opt_date_past' => 'Random in past few days',
|
||||||
|
'opt_date_future' => 'Future date (Scheduled)',
|
||||||
|
'desc_date' => 'If future date, post status will automatically set to "Scheduled".',
|
||||||
|
'lbl_length' => 'Article Length',
|
||||||
|
'opt_len_short' => 'Short (2-3 paragraphs)',
|
||||||
|
'opt_len_medium' => 'Medium (4-6 paragraphs + heading)',
|
||||||
|
'opt_len_long' => 'Long (7-10 paragraphs + heading, quote)',
|
||||||
|
'lbl_image' => 'Featured Image',
|
||||||
|
'opt_use_img' => 'Include random image from Picsum Photos',
|
||||||
|
'opt_img_small' => 'Small (800x600)',
|
||||||
|
'opt_img_med' => 'Medium (1200x800)',
|
||||||
|
'opt_img_large' => 'Large (1600x1000)',
|
||||||
|
'lbl_extra' => 'Additional Options',
|
||||||
|
'opt_comments' => 'Include dummy comments',
|
||||||
|
'opt_sticky' => 'Make first post sticky (Post type only)',
|
||||||
|
'btn_generate' => 'Generate Dummy Data',
|
||||||
|
'purge_title' => 'Cleanup / Rollback',
|
||||||
|
'purge_active' => 'Active dummy items',
|
||||||
|
'purge_desc' => 'Permanently deletes all posts, pages, and media attachments created by DummyLab.',
|
||||||
|
'btn_purge' => 'Delete All Dummy Data',
|
||||||
|
'guide_title' => 'Quick Usage Guide',
|
||||||
|
'guide_step1' => 'Select total count and content type (Post/Page).',
|
||||||
|
'guide_step2' => 'Choose generated text language and length.',
|
||||||
|
'guide_step3' => 'Check image box to auto-fetch thumbnails from Picsum.',
|
||||||
|
'guide_step4' => 'Click Purge anytime to completely clean test data.',
|
||||||
|
'safety_title' => 'Safe Development',
|
||||||
|
'safety_item1' => 'All dummy posts are tracked via unique metadata key.',
|
||||||
|
'safety_item2' => 'Clean purge removes featured images from Media Library.',
|
||||||
|
'safety_item3' => 'Safe for staging and local theme testing.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'created_by' => 'Dibuat oleh',
|
||||||
|
'plugin_doc' => 'Dokumentasi Plugin',
|
||||||
|
'msg_generated' => 'konten dummy berhasil dibuat!',
|
||||||
|
'msg_purged' => 'data dummy berhasil dibersihkan!',
|
||||||
|
'form_title' => 'Generate Content Dummy',
|
||||||
|
'lbl_count' => 'Jumlah Post/Halaman',
|
||||||
|
'lbl_type' => 'Tipe Konten',
|
||||||
|
'opt_post' => 'Post',
|
||||||
|
'opt_page' => 'Halaman (Page)',
|
||||||
|
'lbl_content_lang' => 'Bahasa Konten',
|
||||||
|
'lbl_status' => 'Status Post',
|
||||||
|
'opt_publish' => 'Publish (terbit)',
|
||||||
|
'opt_draft' => 'Draft',
|
||||||
|
'opt_pending' => 'Pending Review',
|
||||||
|
'opt_private' => 'Private',
|
||||||
|
'lbl_cats' => 'Kategori',
|
||||||
|
'desc_cats' => 'Kategori dibuat otomatis jika belum ada. Pisahkan dengan koma. Tidak berlaku untuk Halaman.',
|
||||||
|
'lbl_tags' => 'Tag Tambahan',
|
||||||
|
'desc_tags' => 'Opsional, pisahkan dengan koma.',
|
||||||
|
'lbl_author' => 'Penulis',
|
||||||
|
'opt_random_author' => 'Acak dari semua pengguna',
|
||||||
|
'lbl_date' => 'Tanggal Post',
|
||||||
|
'opt_date_now' => 'Waktu sekarang',
|
||||||
|
'opt_date_past' => 'Acak dalam beberapa hari terakhir',
|
||||||
|
'opt_date_future' => 'Rentang tanggal tertentu (Future/Scheduled)',
|
||||||
|
'desc_date' => 'Jika tanggal di masa depan, status otomatis "Scheduled".',
|
||||||
|
'lbl_length' => 'Panjang Artikel',
|
||||||
|
'opt_len_short' => 'Pendek (2-3 paragraf)',
|
||||||
|
'opt_len_medium' => 'Sedang (4-6 paragraf + heading)',
|
||||||
|
'opt_len_long' => 'Panjang (7-10 paragraf + heading, quote)',
|
||||||
|
'lbl_image' => 'Gambar Unggulan',
|
||||||
|
'opt_use_img' => 'Sertakan gambar acak dari Picsum Photos',
|
||||||
|
'opt_img_small' => 'Kecil (800x600)',
|
||||||
|
'opt_img_med' => 'Sedang (1200x800)',
|
||||||
|
'opt_img_large' => 'Besar (1600x1000)',
|
||||||
|
'lbl_extra' => 'Opsi Tambahan',
|
||||||
|
'opt_comments' => 'Sertakan komentar dummy',
|
||||||
|
'opt_sticky' => 'Jadikan post pertama sebagai sticky post (khusus Post)',
|
||||||
|
'btn_generate' => 'Generate Data Dummy',
|
||||||
|
'purge_title' => 'Cleanup / Rollback',
|
||||||
|
'purge_active' => 'Total data dummy aktif',
|
||||||
|
'purge_desc' => 'Tindakan ini akan menghapus permanen seluruh post, page, dan gambar yang dibuat oleh DummyLab.',
|
||||||
|
'btn_purge' => 'Hapus Semua Data Dummy',
|
||||||
|
'guide_title' => 'Panduan Penggunaan',
|
||||||
|
'guide_step1' => 'Pilih jumlah data dan tipe konten (Post atau Halaman).',
|
||||||
|
'guide_step2' => 'Atur bahasa dan panjang artikel yang akan dihasilkan.',
|
||||||
|
'guide_step3' => 'Centang opsi gambar untuk mengunduh thumbnail dari Picsum.',
|
||||||
|
'guide_step4' => 'Gunakan tombol Purge untuk menghapus semua data pengujian.',
|
||||||
|
'safety_title' => 'Pengembangan Aman',
|
||||||
|
'safety_item1' => 'Setiap postingan dummy dilindungi metadata internal unik.',
|
||||||
|
'safety_item2' => 'Fitur Purge juga membersihkan berkas gambar dari Media Library.',
|
||||||
|
'safety_item3' => 'Aman digunakan pada lingkungan staging maupun lokal.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function handle_generate() {
|
public function handle_generate() {
|
||||||
if (!current_user_can('manage_options') || !check_admin_referer('dummylab_generate_action', 'dummylab_nonce')) {
|
if (!current_user_can('manage_options') || !check_admin_referer('dummylab_generate_action', 'dummylab_nonce')) {
|
||||||
wp_die('Akses ditolak.');
|
wp_die('Akses ditolak.');
|
||||||
@@ -213,6 +368,7 @@ class DummyLab {
|
|||||||
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
||||||
require_once(ABSPATH . 'wp-admin/includes/media.php');
|
require_once(ABSPATH . 'wp-admin/includes/media.php');
|
||||||
|
|
||||||
|
$ui_lang = isset($_POST['ui_lang']) ? sanitize_text_field($_POST['ui_lang']) : 'id';
|
||||||
$count = isset($_POST['post_count']) ? min(50, max(1, intval($_POST['post_count']))) : 5;
|
$count = isset($_POST['post_count']) ? min(50, max(1, intval($_POST['post_count']))) : 5;
|
||||||
$post_type = isset($_POST['post_type']) && in_array($_POST['post_type'], ['post', 'page']) ? $_POST['post_type'] : 'post';
|
$post_type = isset($_POST['post_type']) && in_array($_POST['post_type'], ['post', 'page']) ? $_POST['post_type'] : 'post';
|
||||||
$lang = isset($_POST['content_lang']) ? sanitize_text_field($_POST['content_lang']) : 'id';
|
$lang = isset($_POST['content_lang']) ? sanitize_text_field($_POST['content_lang']) : 'id';
|
||||||
@@ -227,7 +383,6 @@ class DummyLab {
|
|||||||
$add_comments = isset($_POST['add_comments']) ? true : false;
|
$add_comments = isset($_POST['add_comments']) ? true : false;
|
||||||
$make_sticky = isset($_POST['make_sticky']) ? true : false;
|
$make_sticky = isset($_POST['make_sticky']) ? true : false;
|
||||||
|
|
||||||
// Process categories
|
|
||||||
$cat_ids = [];
|
$cat_ids = [];
|
||||||
if ($post_type === 'post' && !empty($categories_raw)) {
|
if ($post_type === 'post' && !empty($categories_raw)) {
|
||||||
$cat_names = array_map('trim', explode(',', $categories_raw));
|
$cat_names = array_map('trim', explode(',', $categories_raw));
|
||||||
@@ -243,17 +398,12 @@ class DummyLab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process tags
|
|
||||||
$tag_names = !empty($tags_raw) ? array_map('trim', explode(',', $tags_raw)) : [];
|
$tag_names = !empty($tags_raw) ? array_map('trim', explode(',', $tags_raw)) : [];
|
||||||
|
|
||||||
// Users pool
|
|
||||||
$user_ids = get_users(['fields' => 'ID']);
|
$user_ids = get_users(['fields' => 'ID']);
|
||||||
|
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
// Determine Author
|
|
||||||
$author_id = ($author_opt === 'random') ? $user_ids[array_rand($user_ids)] : intval($author_opt);
|
$author_id = ($author_opt === 'random') ? $user_ids[array_rand($user_ids)] : intval($author_opt);
|
||||||
|
|
||||||
// Determine Date
|
|
||||||
$post_date = current_time('mysql');
|
$post_date = current_time('mysql');
|
||||||
$final_status = $status;
|
$final_status = $status;
|
||||||
if ($date_opt === 'random_past') {
|
if ($date_opt === 'random_past') {
|
||||||
@@ -265,7 +415,6 @@ class DummyLab {
|
|||||||
$final_status = 'future';
|
$final_status = 'future';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build Content & Title
|
|
||||||
$title = $this->get_sample_title($lang, $i);
|
$title = $this->get_sample_title($lang, $i);
|
||||||
$content = $this->get_sample_content($lang, $content_length);
|
$content = $this->get_sample_content($lang, $content_length);
|
||||||
|
|
||||||
@@ -291,7 +440,6 @@ class DummyLab {
|
|||||||
if ($post_id && !is_wp_error($post_id)) {
|
if ($post_id && !is_wp_error($post_id)) {
|
||||||
update_post_meta($post_id, $this->meta_key, '1');
|
update_post_meta($post_id, $this->meta_key, '1');
|
||||||
|
|
||||||
// Featured Image via Picsum
|
|
||||||
if ($use_image) {
|
if ($use_image) {
|
||||||
$image_url = 'https://picsum.photos/' . $image_size . '?random=' . rand(1, 9999);
|
$image_url = 'https://picsum.photos/' . $image_size . '?random=' . rand(1, 9999);
|
||||||
$tmp = download_url($image_url);
|
$tmp = download_url($image_url);
|
||||||
@@ -309,12 +457,10 @@ class DummyLab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sticky option
|
|
||||||
if ($i === 0 && $make_sticky && $post_type === 'post') {
|
if ($i === 0 && $make_sticky && $post_type === 'post') {
|
||||||
stick_post($post_id);
|
stick_post($post_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add comments
|
|
||||||
if ($add_comments) {
|
if ($add_comments) {
|
||||||
$comment_count = rand(1, 3);
|
$comment_count = rand(1, 3);
|
||||||
for ($c = 0; $c < $comment_count; $c++) {
|
for ($c = 0; $c < $comment_count; $c++) {
|
||||||
@@ -330,7 +476,7 @@ class DummyLab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_redirect(admin_url('tools.php?page=dummylab&status=generated&count=' . $count));
|
wp_redirect(admin_url('tools.php?page=dummylab&ui_lang=' . $ui_lang . '&status=generated&count=' . $count));
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,6 +485,8 @@ class DummyLab {
|
|||||||
wp_die('Akses ditolak.');
|
wp_die('Akses ditolak.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ui_lang = isset($_POST['ui_lang']) ? sanitize_text_field($_POST['ui_lang']) : 'id';
|
||||||
|
|
||||||
$query = new WP_Query([
|
$query = new WP_Query([
|
||||||
'post_type' => ['post', 'page', 'attachment'],
|
'post_type' => ['post', 'page', 'attachment'],
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
@@ -357,7 +505,7 @@ class DummyLab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_redirect(admin_url('tools.php?page=dummylab&status=purged&count=' . $purged_count));
|
wp_redirect(admin_url('tools.php?page=dummylab&ui_lang=' . $ui_lang . '&status=purged&count=' . $purged_count));
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user