function ( $value ) { if ( ! is_array( $value ) ) { return []; } return array_map( 'sanitize_text_field', $value ); }, ] ); }); add_action("admin_menu", function () { // Add a submenu for settings add_submenu_page( "wordpress-toolkit-plugin", // Parent menu slug "Models", // Page title "Models", // Menu title "edit_theme_options", "toolkit-manage-models", // Menu slug [self::class, "display_settings_page"], // Callback function to display the settings page ); }); self::enable(); } public static function display_settings_page() { $plugin_models_path = HITHTO_DIR . "/models/custom"; // Path to plugin's models $theme_models_path = HITHTO_THEME_PATH . "/models/custom"; // Path to theme's models // Initialize arrays $plugin_models = []; $theme_models = []; // Check if plugin models directory exists before scanning if (file_exists($plugin_models_path) && is_dir($plugin_models_path)) { $plugin_models = scandir($plugin_models_path); // Filter out non-PHP files and the index.php directory guard $plugin_models = array_filter($plugin_models, function ($file) { return strpos($file, ".php") !== false && $file !== "index.php"; }); } // Check if theme models directory exists before scanning if (file_exists($theme_models_path) && is_dir($theme_models_path)) { $theme_models = scandir($theme_models_path); // Filter out non-PHP files and the index.php directory guard $theme_models = array_filter($theme_models, function ($file) { return strpos($file, ".php") !== false && $file !== "index.php"; }); } // Merge models from both locations $models = array_merge($plugin_models, $theme_models); // Show notice if no models found if (empty($models)) { echo "
No models found. Please create a 'models/custom' directory in your plugin or theme and add your model files there.