/** * Validate the plugin path. * * Checks that the file exists and is valid file. * * @since 1.0 * @uses validate_file() to check the passed plugin identifier isn't malformed * @uses bb_get_plugin_path() to get the full path of the plugin * @uses bb_get_plugins() to get the plugins that actually exist * * @param string $plugin Plugin Path * @param string $location The location of plugin, one of 'user', 'core' or 'all' * @param string $type The type of plugin, one of 'all', 'autoload' or 'normal' * @return nxt_Error|int 0 on success, nxt_Error on failure. */ function bb_validate_plugin($plugin, $location = 'all', $type = 'all') { if (validate_file(trim($plugin))) { return new nxt_Error('plugin_invalid', __('Invalid plugin path.')); } $path = bb_get_plugin_path(trim($plugin)); if (!file_exists($path)) { return new nxt_Error('plugin_not_found', __('Plugin file does not exist.')); } if (!in_array(trim($plugin), array_keys(bb_get_plugins($location, $type)))) { return new nxt_Error('plugin_not_available', __('That type of plugin is not available in the specified location.')); } return $path; }
$_plugin_type = 'autoload'; $_plugin_status = 'all'; break; default: $plugin_request = 'all'; // For sanitisation $_plugin_type = 'all'; $_plugin_status = 'all'; break; } $plugin_nav_class = array('all' => '', 'active' => '', 'inactive' => '', 'autoload' => ''); $plugin_nav_class[$plugin_request] = ' class="current"'; // Get plugin counts extract(bb_get_plugin_counts()); // Get requested plugins $requested_plugins = bb_get_plugins('all', $_plugin_type, $_plugin_status); // Get currently active $active_plugins = (array) bb_get_option('active_plugins'); // Check for missing plugin files and remove them from the active plugins array $update = false; foreach ($active_plugins as $index => $plugin) { if (!file_exists(bb_get_plugin_path($plugin))) { $update = true; unset($active_plugins[$index]); } } if ($update) { bb_update_option('active_plugins', $active_plugins); } unset($update, $index, $plugin); // Set the action