إضافة Widget إحصاءات إلى لوحة التحكم
تقدر تضيف ملخص صغير للإدارة باستخدام Dashboard Widgets API
تجهيز المثال
أنشئ مجلد ezl-demo-11 داخل wp-content/plugins في نسخة WordPress للتجربة ثم ضع ملف الإضافة التالي بداخله وفعلها من لوحة التحكم
كود الإضافة
<?php
/*
Plugin Name: Academy Demo 11
*/
if (!defined("ABSPATH")) { exit; }
add_action('wp_dashboard_setup', function () {
if (!current_user_can('manage_options')) {
return;
}
wp_add_dashboard_widget('ezl_post_summary', 'Content Summary', function () {
$counts = wp_count_posts('post');
echo '<p>'.esc_html('Published: '.(int) $counts->publish).'</p>';
echo '<p>'.esc_html('Drafts: '.(int) $counts->draft).'</p>';
});
});طريقة التجربة والنتيجة
افتح الصفحة الرئيسية للوحة التحكم بحساب إداري وهتلاقي ملخص المقالات المنشورة والمسودات