diff --git a/dummylab.php b/dummylab.php index af64214..e135bba 100644 --- a/dummylab.php +++ b/dummylab.php @@ -1,17 +1,18 @@ ['ID', 'display_name']]); + $query = new WP_Query([ - 'post_type' => 'post', + 'post_type' => ['post', 'page'], 'posts_per_page' => -1, 'meta_key' => $this->meta_key, 'meta_value' => '1', 'fields' => 'ids', + 'post_status' => 'any', ]); $dummy_count = $query->found_posts; ?>
Generate dummy posts safely for design testing and layout development.
+Dibuat oleh masbudikusuma | Dokumentasi Plugin
Currently active dummy posts:
+Total data dummy aktif:
' . $paragraphs[array_rand($paragraphs)] . '
' . $paragraphs[array_rand($paragraphs)] . '
'; + // Determine Author + $author_id = ($author_opt === 'random') ? $user_ids[array_rand($user_ids)] : intval($author_opt); - $post_id = wp_insert_post([ - 'post_title' => $random_title, - 'post_content' => $random_content, - 'post_status' => $status, - 'post_type' => 'post', - 'post_author' => get_current_user_id(), - ]); + // Determine Date + $post_date = current_time('mysql'); + $final_status = $status; + if ($date_opt === 'random_past') { + $days_back = rand(1, 30); + $post_date = date('Y-m-d H:i:s', strtotime("-$days_back days")); + } elseif ($date_opt === 'future') { + $days_ahead = rand(1, 15); + $post_date = date('Y-m-d H:i:s', strtotime("+$days_ahead days")); + $final_status = 'future'; + } + + // Build Content & Title + $title = $this->get_sample_title($lang, $i); + $content = $this->get_sample_content($lang, $content_length); + + $post_data = [ + 'post_title' => $title, + 'post_content' => $content, + 'post_status' => $final_status, + 'post_type' => $post_type, + 'post_author' => $author_id, + 'post_date' => $post_date, + ]; + + if ($post_type === 'post' && !empty($cat_ids)) { + $post_data['post_category'] = [$cat_ids[array_rand($cat_ids)]]; + } + + if ($post_type === 'post' && !empty($tag_names)) { + $post_data['tags_input'] = $tag_names; + } + + $post_id = wp_insert_post($post_data); if ($post_id && !is_wp_error($post_id)) { update_post_meta($post_id, $this->meta_key, '1'); + + // Featured Image via Picsum + if ($use_image) { + $image_url = 'https://picsum.photos/' . $image_size . '?random=' . rand(1, 9999); + $tmp = download_url($image_url); + if (!is_wp_error($tmp)) { + $file_array = [ + 'name' => 'dummylab-' . $post_id . '.jpg', + 'tmp_name' => $tmp + ]; + $attach_id = media_handle_sideload($file_array, $post_id); + if (!is_wp_error($attach_id)) { + set_post_thumbnail($post_id, $attach_id); + update_post_meta($attach_id, $this->meta_key, '1'); + } + @unlink($tmp); + } + } + + // Sticky option + if ($i === 0 && $make_sticky && $post_type === 'post') { + stick_post($post_id); + } + + // Add comments + if ($add_comments) { + $comment_count = rand(1, 3); + for ($c = 0; $c < $comment_count; $c++) { + wp_insert_comment([ + 'comment_post_ID' => $post_id, + 'comment_author' => 'Tester Dummy', + 'comment_author_email' => 'tester@example.com', + 'comment_content' => ($lang === 'id') ? 'Artikel yang sangat bermanfaat dan informatif!' : 'Great content, thanks for sharing!', + 'comment_approved' => 1, + ]); + } + } } } @@ -162,15 +336,16 @@ class DummyLab { public function handle_purge() { if (!current_user_can('manage_options') || !check_admin_referer('dummylab_purge_action', 'dummylab_nonce')) { - wp_die('Unauthorized request.'); + wp_die('Akses ditolak.'); } $query = new WP_Query([ - 'post_type' => 'post', + 'post_type' => ['post', 'page', 'attachment'], 'posts_per_page' => -1, 'meta_key' => $this->meta_key, 'meta_value' => '1', 'fields' => 'ids', + 'post_status' => 'any', ]); $purged_count = 0; @@ -185,6 +360,55 @@ class DummyLab { wp_redirect(admin_url('tools.php?page=dummylab&status=purged&count=' . $purged_count)); exit; } + + private function get_sample_title($lang, $index) { + $titles_id = [ + 'Panduan Lengkap Pengembangan Infrastruktur Web Modern', + 'Mengoptimalkan Performa Database untuk Trafik Tinggi', + 'Desain Responsif dan Pengalaman Pengguna Terbaik', + 'Strategi Keamanan Server dan Arsitektur Komputasi Awan', + 'Manajemen Konten Efektif untuk Pertumbuhan Bisnis' + ]; + $titles_en = [ + 'Exploring the Future of Scalable Web Architecture', + '10 Essential Practices for High-Performance Servers', + 'Understanding Modern UI/UX Design Principles', + 'Building Secure Application Infrastructures', + 'Optimizing Database Queries for Enterprise Solutions' + ]; + $arr = ($lang === 'id') ? $titles_id : $titles_en; + return $arr[array_rand($arr)] . ' #' . rand(100, 999); + } + + private function get_sample_content($lang, $length) { + $p_id = [ + 'Pengembangan aplikasi web modern memerlukan perhatian ekstra pada arsitektur sistem dasar. Komponen seperti manajemen memori, optimasi kueri, dan konfigurasi server menjadi kunci utama.', + 'Dengan menerapkan standar keamanan terbaik, kita dapat mencegah potensi bahaya siber dan memastikan layanan tetap stabil di bawah beban lalu lintas data yang tinggi.', + 'Pengalaman pengguna merupakan elemen krusial. Tata letak visual yang konsisten serta navigasi intuitif memudahkan pengunjung dalam menemukan informasi secara cepat.' + ]; + + $p_en = [ + 'Modern web applications require strict adherence to solid system architectures. Key aspects include efficient database queries, memory management, and caching layer implementation.', + 'Ensuring continuous infrastructure security prevents vulnerabilities while guaranteeing optimal uptime during high-volume traffic spikes.', + 'User experience design directly impacts engagement rates. Clean layouts, readable typography, and intuitive interfaces make content consumption seamless.' + ]; + + $paragraphs = ($lang === 'id') ? $p_id : $p_en; + $output = ''; + + $loops = ($length === 'short') ? 2 : (($length === 'long') ? 7 : 4); + for ($k = 0; $k < $loops; $k++) { + $output .= '' . $paragraphs[array_rand($paragraphs)] . '
'; + if ($length !== 'short' && $k === 1) { + $output .= ''; + } + } + + return $output; + } } DummyLab::get_instance();' . (($lang === 'id') ? 'Keamanan dan kecepatan adalah fondasi utama pengembangan web.' : 'Security and performance are the core foundations of web development.') . '