/** * Checks the /app/addon directory for a list of all addons and loads these * files. * * @since 1.0.0 */ protected static function load_core_addons() { $model = MS_Factory::load('MS_Model_Addon'); $root_path = trailingslashit(dirname(dirname(MS_Plugin::instance()->dir))); $plugin_dir = substr(MS_Plugin::instance()->dir, strlen($root_path)); $addon_dir = $plugin_dir . 'app/addon/'; if (empty($model->addon_files) || self::$_reload_files) { // In Admin dashboard we always refresh the addon-list... self::$_reload_files = false; $mask = $root_path . $addon_dir . '*/class-ms-addon-*.php'; $addons = glob($mask); $model->addon_files = array(); foreach ($addons as $file) { $model->addon_files[] = substr($file, strlen($root_path)); } /** * Allow other plugins/themes to register custom addons * * @since 1.0.0 * * @var array */ $model->addon_files = apply_filters('ms_model_addon_files', $model->addon_files); $model->save(); } // Loop all recignized Add-ons and initialize them. foreach ($model->addon_files as $file) { $addon = $root_path . $file; // Get class-name from file-name $class = basename($file); $class = str_replace('.php', '', $class); $class = implode('_', array_map('ucfirst', explode('-', $class))); $class = substr($class, 6); // remove 'Class_' prefix if (file_exists($addon)) { if (!class_exists($class)) { try { include_once $addon; } catch (Exception $ex) { } } if (class_exists($class)) { MS_Factory::load($class); } } } /** * Allow custom addon-initialization code to run * * @since 1.0.0 */ do_action('ms_model_addon_load'); }