init_components(); $this->register_hooks(); } /** * Initialize sub-components. */ protected function init_components() { $settings = new OCAP_Settings(); $settings->init(); $review = new OCAP_Review(); $review->init(); $export = new OCAP_Export(); $export->init(); $dashboard = new OCAP_Dashboard(); $dashboard->init(); $email = new OCAP_Email(); $email->init(); } /** * Register main WordPress hooks. */ protected function register_hooks() { add_action( 'admin_menu', array( $this, 'register_admin_menus' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) ); add_filter( 'set-screen-option', array( $this, 'save_screen_options' ), 10, 3 ); add_action( 'admin_notices', array( $this, 'render_admin_notices' ) ); } /** * Register admin menu items. */ public function register_admin_menus() { $stale_count = ocap_get_stale_count(); $menu_title = __( 'Outdated Content', 'contentcortex' ); if ( $stale_count > 0 ) { $badge = sprintf( ' %s', number_format_i18n( $stale_count ) ); $menu_title .= $badge; } // Top-level menu. $this->report_hook = add_menu_page( __( 'Outdated Content Report', 'contentcortex' ), $menu_title, 'edit_others_posts', 'outdated-content', array( $this, 'render_report_page' ), 'dashicons-update', 26 ); // Submenu: Report. add_submenu_page( 'outdated-content', __( 'Outdated Content Report', 'contentcortex' ), __( 'Report', 'contentcortex' ), 'edit_others_posts', 'outdated-content', array( $this, 'render_report_page' ) ); // Submenu: Settings. $this->settings_hook = add_submenu_page( 'outdated-content', __( 'Outdated Content Settings', 'contentcortex' ), __( 'Settings', 'contentcortex' ), 'manage_options', 'outdated-content-settings', array( $this, 'render_settings_page' ) ); // Load screen options for report table. if ( $this->report_hook ) { add_action( "load-{$this->report_hook}", array( $this, 'load_report_page' ) ); } } /** * Load callback for report page to register screen options and instantiate table. */ public function load_report_page() { add_screen_option( 'per_page', array( 'label' => __( 'Items per page', 'contentcortex' ), 'default' => 20, 'option' => 'ocap_posts_per_page', ) ); $this->report_table = new OCAP_Report_Table(); } /** * Save screen option value. * * @param mixed $status Screen option status. * @param string $option Option name. * @param mixed $value Submitted value. * @return mixed */ public function save_screen_options( $status, $option, $value ) { if ( 'ocap_posts_per_page' === $option || 'sct_posts_per_page' === $option ) { return absint( $value ); } return $status; } /** * Enqueue CSS and JavaScript assets on plugin admin screens. * * @param string $hook_suffix Current screen hook. */ public function enqueue_admin_assets( $hook_suffix ) { $plugin_dir_url = plugin_dir_url( __DIR__ ); $is_plugin_screen = ( $hook_suffix === $this->report_hook || $hook_suffix === $this->settings_hook ); $is_dashboard = ( 'index.php' === $hook_suffix ); $is_edit_screen = ( 'edit.php' === $hook_suffix ); // Load admin CSS on plugin screens, dashboard, and edit screens (for list column badge). if ( $is_plugin_screen || $is_dashboard || $is_edit_screen ) { wp_enqueue_style( 'ocap-admin-css', $plugin_dir_url . 'admin/css/admin.css', array(), OCAP_VERSION ); } if ( ! $is_plugin_screen ) { return; } // Enqueue media library and color picker on settings screen. if ( $hook_suffix === $this->settings_hook ) { wp_enqueue_media(); wp_enqueue_style( 'wp-color-picker' ); } wp_enqueue_script( 'ocap-admin-js', $plugin_dir_url . 'admin/js/admin.js', array( 'jquery', 'wp-color-picker' ), OCAP_VERSION, true ); wp_localize_script( 'ocap-admin-js', 'ocapAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'previewNonce' => wp_create_nonce( 'ocap_preview_nonce' ), 'testEmailNonce' => wp_create_nonce( 'ocap_test_email_nonce' ), 'strings' => array( 'selectLogo' => __( 'Select Logo', 'contentcortex' ), 'useThisLogo' => __( 'Use this logo', 'contentcortex' ), 'changeLogo' => __( 'Change Logo', 'contentcortex' ), ), ) ); } /** * Render Outdated Content Report page. */ public function render_report_page() { if ( ! current_user_can( 'edit_others_posts' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'contentcortex' ) ); } if ( null === $this->report_table ) { $this->report_table = new OCAP_Report_Table(); } $this->report_table->prepare_items(); $table = $this->report_table; include plugin_dir_path( __DIR__ ) . 'admin/views/report-page.php'; } /** * Render Outdated Content Settings page. */ public function render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'contentcortex' ) ); } include plugin_dir_path( __DIR__ ) . 'admin/views/settings-page.php'; } /** * Render general admin notices if any. */ public function render_admin_notices() { // Handled directly inside views or via settings API. } }