*/ namespace Wplmi\Core\Backend; use WP_Query; use Wplmi\Helpers\Hooker; use Wplmi\Helpers\HelperFunctions; defined( 'ABSPATH' ) || exit; /** * Dashboard widget class. */ class DashboardWidget { use HelperFunctions, Hooker; /** * Register functions. */ public function register() { $this->action( 'wp_dashboard_setup', 'dashboard_widget' ); $this->action( 'admin_head-index.php', 'widget_css' ); } /** * Register dashboard widgets. */ public function dashboard_widget() { global $wp_meta_boxes; \wp_add_dashboard_widget( 'dashboard_last_modified_posts', // Widget slug. __( 'Last Updated', 'wp-last-modified-info' ), // Title. [ $this, 'widget_callback' ], // callback. [ $this, 'widget_control_callback' ] // control callback. ); } /** * Dashboard widget callback. */ public function widget_callback() { $timestamp = current_time( 'timestamp', 0 ); $widget_options = get_option( 'lmt_dashboard_widget_options' ); $num = ! empty( $widget_options['number'] ) ? intval( $widget_options['number'] ) : 5; $args = $this->do_filter( 'dashboard_widget_args', [ 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $num, 'orderby' => 'modified', 'order' => 'DESC', 'no_found_rows' => true, 'suppress_filters' => true, ] ); $posts = new WP_Query( $args ); echo '
'; if ( $posts->have_posts() ) { echo '
'; echo '

' . esc_html__( 'Recently Updated', 'wp-last-modified-info' ) . '

'; echo ''; echo '
'; } else { echo '
'; echo ''; echo '

' . __( 'No modified posts yet!' ) . '

'; echo '
'; } wp_reset_postdata(); echo '
'; } /** * Dashboard widget control callback. */ public function widget_control_callback() { // Update widget options if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['wplmi_widget_options'] ) ) { check_admin_referer(); update_option( 'lmt_dashboard_widget_options', array_map( 'intval', $_POST['wplmi_widget_options'] ), false ); } // Get widget options $widget_options = get_option( 'lmt_dashboard_widget_options' ); $value = isset( $widget_options['number'] ) ? $widget_options['number'] : ''; wp_nonce_field(); ?>