From b642cc65502c93d872ce1f3e1c253a762d46bbdb Mon Sep 17 00:00:00 2001 From: sevenleaflabs Date: Sun, 27 Apr 2025 21:22:14 +0200 Subject: [PATCH] Fix 'Class QUICKAL\QuickAL not found' error on case-sensitive file systems --- includes/autoload.php | 2 +- includes/class-quickal-fallback.php | 474 ++++++++++++++++++++++++++++ includes/class-quickal.php | 2 +- quick-admin-launcher.php | 24 ++ 4 files changed, 500 insertions(+), 2 deletions(-) create mode 100644 includes/class-quickal-fallback.php diff --git a/includes/autoload.php b/includes/autoload.php index b02e594..e472c45 100644 --- a/includes/autoload.php +++ b/includes/autoload.php @@ -22,7 +22,7 @@ function ( $class ) { // replace the namespace prefix with the base directory, replace namespace // separators with directory separators in the relative class name, append // with .php. - $file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php'; + $file = $base_dir . strtolower(str_replace( '\\', '/', $relative_class )) . '.php'; // if the file exists, require it. if ( file_exists( $file ) ) { diff --git a/includes/class-quickal-fallback.php b/includes/class-quickal-fallback.php new file mode 100644 index 0000000..55b040f --- /dev/null +++ b/includes/class-quickal-fallback.php @@ -0,0 +1,474 @@ + isset( $options['hotkey_key'] ) ? $options['hotkey_key'] : 'k', + 'alt' => isset( $options['hotkey_alt'] ) ? $options['hotkey_alt'] : '', + 'ctrl' => isset( $options['hotkey_ctrl'] ) ? $options['hotkey_ctrl'] : '1', + 'shift' => isset( $options['hotkey_shift'] ) ? $options['hotkey_shift'] : '', + 'meta' => isset( $options['hotkey_meta'] ) ? $options['hotkey_meta'] : '', + ); + + wp_localize_script( + 'quickal-react', + 'quickalData', + array( + 'rest' => esc_url_raw( rest_url( 'quickal/v1' ) ), + 'nonce' => wp_create_nonce( 'wp_rest' ), + 'extra_items' => $extra_items, + 'hotkey' => $hotkey, + ) + ); + } + + public function defer_parsing_of_js( $url ) { + if ( strpos( $url, 'quickal.js' ) ) { + return str_replace( ' src', ' defer src', $url ); + } + return $url; + } + + /** + * Register API Routes for QuickAL. + * + * @since 1.0.0 + */ + public function register_api_routes() { + + // Search posts route. + register_rest_route( + 'quickal/v1', + '/search/(?P\S+)', + array( + 'methods' => 'GET', + 'callback' => array( $this, 'rest_search' ), + 'permission_callback' => function () { + return current_user_can( 'edit_posts' ); + }, + ) + ); + + } + + /** + * Add QuickAL Modal HTML to footer. + * + * @since 1.0.0 + */ + public function modal_html() { + echo '
'; + } + + /** + * Rest API route for searching on posts. + * + * @since 1.0.0 + * + * @param array $data GET data. + * @return array Posts found. + */ + public function rest_search( $data ) { + $term = $data['term']; + $options = get_option( 'quickal_settings' ); + $results = array(); + + // Search on posts. + $post_types = isset( $options['post_types'] ) ? $options['post_types'] : false; + if ( $post_types ) { + $posts = get_posts( + array( + 's' => $term, + 'post_type' => $post_types, + ) + ); + + // Merge all results. + foreach ( $posts as $post ) { + // Get post type icon. + $ptype = $post->post_type; + $ptype_obj = get_post_type_object( $ptype ); + $icon = 'dashicons-admin-post'; + if ( is_string( $ptype_obj->menu_icon ) ) { + if ( 0 === strpos( $ptype_obj->menu_icon, 'data:image/svg+xml;base64,' ) || 0 === strpos( $ptype_obj->menu_icon, 'dashicons-' ) ) { + $icon = $ptype_obj->menu_icon; + } else { + $icon = esc_url( $ptype_obj->menu_icon ); + } + } + + $results[] = array( + 'type' => $post->post_type, + 'icon' => $icon, + 'label' => $post->post_title, + 'term' => strtolower( $post->post_title ), + 'link' => get_edit_post_link( $post->ID, '' ), + ); + } + } + + // Search on users. + $users_search = isset( $options['users_search'] ) ? $options['users_search'] : false; + if ( $users_search ) { + $users = get_users( + array( + 'search' => $term, + ), + ); + + foreach ( $users as $user ) { + $results[] = array( + 'type' => 'user', + 'icon' => 'dashicons-admin-users', + 'label' => $user->display_name, + 'term' => strtolower( $user->display_name ), + 'link' => get_edit_user_link( $user->ID ), + ); + } + } + + /** + * Filters server search results. + * + * @since 1.0.0 + * + * @param array $results { + * Array of results. + * + * @type array $item { + * Searchable item. + * + * @type string $type Search result type. + * @type string $label Search result label. + * @type string $term Searchable term for this result. + * @type string $link Search result link. + * @type string $icon Search result icon (dashicon class name, icon path or base64 icon). + * } + * } + */ + $results = apply_filters( 'quickal_server_search_results', $results, $term ); + + return $results; + } + + /** + * Adds a settings page. + * + * @since 1.0.0 + */ + public function add_settings_page() { + add_options_page( + __( 'Quick Admin Launcher', 'quickal' ), + __( 'Quick Admin Launcher', 'quickal' ), + 'manage_options', + 'quickal-settings', + array( $this, 'render_settings_page' ) + ); + } + + /** + * Renders the settings page. + * + * @since 1.0.0 + */ + public function render_settings_page() { + ?> +

+ +

+
+ + +
+ true, + ), + 'objects' + ); + ?> +
+ + +
+ +
+ + +
+ +
+ + +
+ + + + + + +
+
+ + + 'quickal-admin-bar', + 'title' => '', + 'href' => '#', + 'meta' => array( + 'class' => 'quickal-admin-bar', + 'title' => 'Quick Admin Launcher' + ) + ); + $wp_admin_bar->add_node( $args ); + } + + /** + * Add settings link to plugin page. + * + * @since 1.0. + * + * @param array $links Array of links. + * @return array Array of links. + */ + public function add_settings_link( $links ) { + $settings_link = '' . __( 'Settings' ) . ''; + array_push( $links, $settings_link ); + return $links; + } +} diff --git a/includes/class-quickal.php b/includes/class-quickal.php index 18b8359..333739a 100644 --- a/includes/class-quickal.php +++ b/includes/class-quickal.php @@ -468,4 +468,4 @@ public function add_settings_link( $links ) { array_push( $links, $settings_link ); return $links; } -} +} \ No newline at end of file diff --git a/quick-admin-launcher.php b/quick-admin-launcher.php index 7c5511b..2ad6cd4 100644 --- a/quick-admin-launcher.php +++ b/quick-admin-launcher.php @@ -15,8 +15,12 @@ define( 'QUICKAL_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'QUICKAL_VERSION', '1.0.2' ); +// Include autoloader require_once QUICKAL_PLUGIN_DIR . '/includes/autoload.php'; +// Direct include of the main class file to avoid autoloader issues +require_once QUICKAL_PLUGIN_DIR . '/includes/class-QuickAL.php'; + register_activation_hook( __FILE__, 'quickal_activate' ); register_deactivation_hook( __FILE__, 'quickal_deactivate' ); @@ -52,5 +56,25 @@ function quickal_activate() { */ function quickal_deactivate() {} +// Check if the class exists, if not try to include it directly +if (!class_exists('QUICKAL\\QuickAL')) { + // Try with lowercase filename (for case-insensitive file systems) + if (file_exists(QUICKAL_PLUGIN_DIR . '/includes/class-quickal.php')) { + require_once QUICKAL_PLUGIN_DIR . '/includes/class-quickal.php'; + } + + // Try with uppercase AL (for case-sensitive file systems) + if (file_exists(QUICKAL_PLUGIN_DIR . '/includes/class-QuickAL.php')) { + require_once QUICKAL_PLUGIN_DIR . '/includes/class-QuickAL.php'; + } + + // If class still doesn't exist, define it inline as a last resort + if (!class_exists('QUICKAL\\QuickAL')) { + // Define the class directly in the main file as a fallback + require_once QUICKAL_PLUGIN_DIR . '/includes/class-quickal-fallback.php'; + } +} + +// Initialize the plugin $quickal = new QUICKAL\QuickAL(); $quickal->init();