diff --git a/.ai-workflows/folder-structure.md b/.ai-workflows/folder-structure.md index 21ba270..e63e665 100644 --- a/.ai-workflows/folder-structure.md +++ b/.ai-workflows/folder-structure.md @@ -21,14 +21,14 @@ This document outlines the folder structure of the plugin and explains the purpo - **admin/settings/** - Admin settings functionality - **admin/tools/** - Admin tools functionality - **admin/lib/** - Admin-specific library files and helper functions + - **admin/lib/admin.php** - Admin class for handling admin-specific functionality + - **admin/lib/modal.php** - Modal class for handling the update source selector modal ## Includes Directory The `includes/` directory contains the core plugin functionality: -- **includes/admin.php** - Admin class for handling admin-specific functionality - **includes/core.php** - Core class for handling the main plugin functionality -- **includes/modal.php** - Modal class for handling the update source selector modal - **includes/plugin.php** - Main plugin class that initializes all components - **includes/updater.php** - Updater class for handling plugin updates @@ -52,8 +52,8 @@ When referring to files or directories in AI conversations, use the following fo - **@includes/plugin.php** - Main plugin class - **@includes/core.php** - Core functionality -- **@includes/admin.php** - Admin functionality -- **@includes/modal.php** - Modal functionality +- **@admin/lib/admin.php** - Admin functionality +- **@admin/lib/modal.php** - Modal functionality - **@includes/updater.php** - Updater functionality - **@admin/js/update-source-selector.js** - Update source selector JavaScript - **@admin/css/update-source-selector.css** - Update source selector CSS diff --git a/admin/lib/admin.php b/admin/lib/admin.php new file mode 100644 index 0000000..b7f8174 --- /dev/null +++ b/admin/lib/admin.php @@ -0,0 +1,95 @@ +core = $core; + + // Enqueue admin scripts and styles + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_assets')); + } + + /** + * Enqueue scripts and styles needed for the admin area. + * + * @param string $hook_suffix The current admin page hook. + * @return void + */ + public function enqueue_admin_assets($hook_suffix) { + // Only load on the plugins page + if ('plugins.php' !== $hook_suffix) { + return; + } + + // Version fix script is no longer needed after refactoring + // Commented out for testing + /* + wp_enqueue_script( + 'fpden-version-fix', + FPDEN_PLUGIN_URL . 'admin/js/version-fix.js', + array('jquery', 'thickbox'), + FPDEN_VERSION, + true // Load in footer + ); + */ + + // Get invalid plugins to decide if other assets are needed + $invalid_plugins = $this->core->get_invalid_plugins(); + if (empty($invalid_plugins)) { + return; // No missing plugins, no need for the special notice JS/CSS + } + + wp_enqueue_style( + 'fpden-admin-styles', + FPDEN_PLUGIN_URL . 'admin/css/admin-styles.css', + array(), + FPDEN_VERSION + ); + + wp_enqueue_script( + 'fpden-admin-scripts', + FPDEN_PLUGIN_URL . 'admin/js/admin-scripts.js', + array('jquery'), // Add dependencies if needed, e.g., jQuery + FPDEN_VERSION, + true // Load in footer + ); + + // Add translation strings for JavaScript + wp_localize_script( + 'fpden-admin-scripts', + 'fpdenData', + array( + 'i18n' => array( + 'clickToScroll' => esc_html__('Click here to scroll to missing plugins', 'wp-fix-plugin-does-not-exist-notices'), + 'pluginMissing' => esc_html__('File Missing', 'wp-fix-plugin-does-not-exist-notices'), + 'removeNotice' => esc_html__('Remove Notice', 'wp-fix-plugin-does-not-exist-notices'), + ), + 'version' => FPDEN_VERSION, // Add version for the plugin details fix script + ) + ); + } +} diff --git a/admin/lib/modal.php b/admin/lib/modal.php new file mode 100644 index 0000000..70ac935 --- /dev/null +++ b/admin/lib/modal.php @@ -0,0 +1,167 @@ +Update Source ' . $badge_text . ''; + $links[] = $update_source_link; + + return $links; + } + + /** + * Add the update source modal to the admin footer + */ + public function add_update_source_modal() { + if (!is_admin() || !current_user_can('manage_options')) { + return; + } + + // Only show on plugins page + $screen = get_current_screen(); + if (!$screen || $screen->id !== 'plugins') { + return; + } + + // Get current source + $current_source = get_option('fpden_update_source', 'auto'); + + // Enqueue the CSS and JS + wp_enqueue_style( + 'fpden-update-source-selector', + FPDEN_PLUGIN_URL . 'admin/css/update-source-selector.css', + array(), + FPDEN_VERSION + ); + + wp_enqueue_script( + 'fpden-update-source-selector', + FPDEN_PLUGIN_URL . 'admin/js/update-source-selector.js', + array('jquery'), + FPDEN_VERSION, + true + ); + + // Add nonce to the existing fpdenData object or create it if it doesn't exist + $nonce = wp_create_nonce('fpden_update_source'); + wp_localize_script( + 'fpden-update-source-selector', + 'fpdenData', + array( + 'updateSourceNonce' => $nonce, + ) + ); + + // Modal HTML + ?> +
+ × +

Choose Update Source

+

Select where you want to receive plugin updates from:

+ +
+ + + + + + +
+ +
+
+
+