settings = $settings; $this->sync_service = $sync_service; $this->scheduler = $scheduler; $this->debug_history = $debug_history; add_action( 'admin_menu', array( $this, 'add_menu' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'admin_notices', array( $this, 'render_admin_notice' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); add_action( 'admin_post_' . self::MANUAL_SYNC_ACTION, array( $this, 'handle_manual_sync' ) ); add_action( 'admin_post_' . self::REGENERATE_TOKEN_ACTION, array( $this, 'handle_regenerate_token' ) ); add_action( 'admin_post_' . self::CLEAR_HISTORY_ACTION, array( $this, 'handle_clear_debug_history' ) ); add_action( 'update_option_' . Settings::OPTION_NAME, array( $this, 'after_settings_saved' ), 10, 2 ); } /** * Enqueues plugin CSS and JS on plugin admin pages only. * * @param string $hook_suffix Current admin page hook suffix. */ public function enqueue_assets( $hook_suffix ) { $plugin_pages = array( 'toplevel_page_' . self::PAGE_SLUG, 'ai-blog-poster_page_' . self::SETTINGS_PAGE_SLUG, 'ai-blog-poster_page_' . self::IMPORTED_POSTS_SLUG, 'ai-blog-poster_page_' . self::DEBUG_PAGE_SLUG, 'ai-blog-poster_page_' . self::HELP_PAGE_SLUG, ); if ( ! in_array( $hook_suffix, $plugin_pages, true ) ) { return; } wp_enqueue_style( 'aibp-admin', AIBP_PLUGIN_URL . 'assets/css/admin.css', array(), AIBP_VERSION ); // Only load JS on the Settings page where the cron toggle is needed. if ( 'ai-blog-poster_page_' . self::SETTINGS_PAGE_SLUG === $hook_suffix ) { wp_enqueue_script( 'aibp-admin', AIBP_PLUGIN_URL . 'assets/js/admin.js', array(), AIBP_VERSION, true ); wp_localize_script( 'aibp-admin', 'aibpAdmin', array( 'optionName' => Settings::OPTION_NAME, ) ); } } /** * Registers the plugin admin menu and subpages. */ public function add_menu() { add_menu_page( __( 'AI Blog Poster', 'ai-blog-poster' ), __( 'AI Blog Poster', 'ai-blog-poster' ), 'manage_options', self::PAGE_SLUG, array( $this, 'render_dashboard_page' ), 'dashicons-edit-page', 80 ); add_submenu_page( self::PAGE_SLUG, __( 'Dashboard', 'ai-blog-poster' ), __( 'Dashboard', 'ai-blog-poster' ), 'manage_options', self::PAGE_SLUG, array( $this, 'render_dashboard_page' ) ); add_submenu_page( self::PAGE_SLUG, __( 'Settings', 'ai-blog-poster' ), __( 'Settings', 'ai-blog-poster' ), 'manage_options', self::SETTINGS_PAGE_SLUG, array( $this, 'render_page' ) ); add_submenu_page( self::PAGE_SLUG, __( 'Imported Posts', 'ai-blog-poster' ), __( 'Imported Posts', 'ai-blog-poster' ), 'manage_options', self::IMPORTED_POSTS_SLUG, array( $this, 'render_imported_posts_page' ) ); add_submenu_page( self::PAGE_SLUG, __( 'Debug History', 'ai-blog-poster' ), __( 'Debug History', 'ai-blog-poster' ), 'manage_options', self::DEBUG_PAGE_SLUG, array( $this, 'render_debug_history_page' ) ); add_submenu_page( self::PAGE_SLUG, __( 'Help', 'ai-blog-poster' ), __( 'Help', 'ai-blog-poster' ), 'manage_options', self::HELP_PAGE_SLUG, array( $this, 'render_help_page' ) ); } /** * Registers plugin settings with the WordPress Settings API. */ public function register_settings() { $this->settings->register(); } /** * Renders the plugin dashboard page. */ public function render_dashboard_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $settings = $this->settings->get_all(); $manual_sync_url = wp_nonce_url( admin_url( 'admin-post.php?action=' . self::MANUAL_SYNC_ACTION ), self::MANUAL_SYNC_ACTION ); $last_sync = ! empty( $settings['last_sync'] ) ? $this->format_timestamp( (int) $settings['last_sync'] ) : __( 'Never', 'ai-blog-poster' ); $last_run = ! empty( $settings['last_run'] ) ? $this->format_timestamp( (int) $settings['last_run'] ) : __( 'Never', 'ai-blog-poster' ); $sync_mode = 'manual_cron' === $settings['sync_mode'] ? __( 'Manual Server Cron', 'ai-blog-poster' ) : __( 'WordPress Cron', 'ai-blog-poster' ); $imported_count = $this->get_imported_post_count(); $debug_entries = $this->debug_history->get_entries(); $latest_entry = ! empty( $debug_entries[0] ) ? $debug_entries[0] : array(); $imported_url = admin_url( 'admin.php?page=' . self::IMPORTED_POSTS_SLUG ); $help_url = admin_url( 'admin.php?page=' . self::HELP_PAGE_SLUG ); ?>
settings->get_all(); $manual_sync_url = wp_nonce_url( admin_url( 'admin-post.php?action=' . self::MANUAL_SYNC_ACTION ), self::MANUAL_SYNC_ACTION ); $regenerate_token_url = wp_nonce_url( admin_url( 'admin-post.php?action=' . self::REGENERATE_TOKEN_ACTION ), self::REGENERATE_TOKEN_ACTION ); $last_sync = ! empty( $settings['last_sync'] ) ? $this->format_timestamp( (int) $settings['last_sync'] ) : __( 'Never', 'ai-blog-poster' ); $last_run = ! empty( $settings['last_run'] ) ? $this->format_timestamp( (int) $settings['last_run'] ) : __( 'Never', 'ai-blog-poster' ); $manual_cron_url = $this->scheduler->get_manual_cron_url(); $sync_mode = isset( $settings['sync_mode'] ) ? $settings['sync_mode'] : 'wp_cron'; $example_cron_cmd = 'curl -s "' . $manual_cron_url . '"'; $hourly_cron_cmd = '0 * * * * curl -s "' . $manual_cron_url . '" >/dev/null 2>&1'; $is_manual_cron = 'manual_cron' === $sync_mode; $masked_api_key = $this->settings->mask_api_key( $settings['api_key'] ); $api_key_set = ! empty( $settings['api_key'] ); ?> 'post', 'post_status' => 'any', 'posts_per_page' => $per_page, 'paged' => $paged, 'meta_key' => Sync_Service::REMOTE_ID_META_KEY, 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true, 'update_post_meta_cache' => true, 'update_post_term_cache' => false, ) ); ?>| format_timestamp( (int) $entry['time'] ) : '-' ); ?> |
format_debug_context( ! empty( $entry['context'] ) ? $entry['context'] : array() ) ); ?> |
|||