diff --git a/mu-plugins/10up-plugin/includes/classes/Module.php b/mu-plugins/10up-plugin/includes/classes/Module.php deleted file mode 100644 index a1da0bb0..00000000 --- a/mu-plugins/10up-plugin/includes/classes/Module.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ - protected $classes = []; - - /** - * Get all the TenUpPlugin plugin classes. - * - * @return array - */ - protected function get_classes() { - // Get all classes from this directory and its subdirectories. - $class_finder = Discover::in( __DIR__ ); - // Only fetch classes. - $class_finder->classes(); - // Only fetch classes in the current namespace. - $class_finder->custom( - fn( DiscoveredStructure $structure ) => str_starts_with( $structure->namespace, __NAMESPACE__ ) - ); - - // If we are in production or staging, cache the class loader to improve performance. - if ( in_array( wp_get_environment_type(), [ 'production', 'staging' ], true ) ) { - $class_finder->withCache( - __NAMESPACE__, - new FileDiscoverCacheDriver( __DIR__ . '/class-loader-cache' ) - ); - } - - $classes = array_filter( $class_finder->get(), fn( $cl ) => is_string( $cl ) ); - - // Return the classes - return $classes; - } - - /** - * Initialize all the TenUpPlugin plugin classes. - * - * @return void - */ - public function init_classes() { - $load_class_order = []; - foreach ( $this->get_classes() as $class ) { - // Create a slug for the class name. - $slug = $this->slugify_class_name( $class ); - - // If the class has already been initialized, skip it. - if ( isset( $this->classes[ $slug ] ) ) { - continue; - } - - // Create a new reflection of the class. - // @phpstan-ignore argument.type - $reflection_class = new ReflectionClass( $class ); - - // Using reflection, check if the class can be initialized. - // If not, skip. - if ( ! $reflection_class->isInstantiable() ) { - continue; - } - - // Make sure the class is a subclass of Module, so we can initialize it. - if ( ! $reflection_class->isSubclassOf( sprintf( '\%s\Module', __NAMESPACE__ ) ) ) { - continue; - } - - // Initialize the class. - $instantiated_class = new $class(); - - if ( ! $instantiated_class instanceof Module ) { - continue; - } - - // Assign the classes into the order they should be initialized. - $load_class_order[ intval( $instantiated_class->load_order ) ][] = [ - 'slug' => $slug, - 'class' => $instantiated_class, - ]; - } - - // Sort the initialized classes by load order. - ksort( $load_class_order ); - - // Loop through the classes and initialize them. - foreach ( $load_class_order as $class_objects ) { - foreach ( $class_objects as $class_object ) { - $class = $class_object['class']; - $slug = $class_object['slug']; - - // If the class can be registered, register it. - if ( $class->can_register() ) { - // Call its register method. - $class->register(); - // Store the class in the list of initialized classes. - $this->classes[ $slug ] = $class; - } - } - } - } - - /** - * Slugify a class name. - * - * @param string $class_name The class name. - * - * @return string - */ - protected function slugify_class_name( $class_name ) { - return sanitize_title( str_replace( '\\', '-', $class_name ) ); - } - - /** - * Get a class by its full class name, including namespace. - * - * @param string $class_name The class name & namespace. - * - * @return false|\TenUpPlugin\Module - */ - public function get_class( $class_name ) { - $class_name = $this->slugify_class_name( $class_name ); - - if ( isset( $this->classes[ $class_name ] ) ) { - return $this->classes[ $class_name ]; - } - - return false; - } - - /** - * Get all the initialized classes. - * - * @return array<\TenUpPlugin\Module> - */ - public function get_all_classes() { - return $this->classes; - } -} diff --git a/mu-plugins/10up-plugin/includes/classes/PostTypes/AbstractCorePostType.php b/mu-plugins/10up-plugin/includes/classes/PostTypes/AbstractCorePostType.php deleted file mode 100644 index 0cf8e423..00000000 --- a/mu-plugins/10up-plugin/includes/classes/PostTypes/AbstractCorePostType.php +++ /dev/null @@ -1,75 +0,0 @@ -get_name() to get the post's type name. - * @return Bool Whether this theme has supports for this post type. - */ - public function register() { - $this->register_taxonomies(); - $this->after_register(); - - return true; - } -} diff --git a/mu-plugins/10up-plugin/includes/classes/PostTypes/AbstractPostType.php b/mu-plugins/10up-plugin/includes/classes/PostTypes/AbstractPostType.php deleted file mode 100644 index 59a30638..00000000 --- a/mu-plugins/10up-plugin/includes/classes/PostTypes/AbstractPostType.php +++ /dev/null @@ -1,286 +0,0 @@ - - */ - public function get_editor_supports() { - $supports = [ - 'title', - 'editor', - 'author', - 'thumbnail', - 'excerpt', - 'revisions', - ]; - - return $supports; - } - - /** - * Get the options for the post type. - * - * @return array{ - * labels?: array, - * description?: string, - * public?: bool, - * hierarchical?: bool, - * exclude_from_search?: bool, - * publicly_queryable?: bool, - * show_ui?: bool, - * show_in_menu?: bool, - * show_in_nav_menus?: bool, - * show_in_admin_bar?: bool, - * menu_position?: int, - * menu_icon?: string, - * capability_type?: string|array, - * capabilities?: array, - * map_meta_cap?: bool, - * supports?: array|false, - * register_meta_box_cb?: callable, - * taxonomies?: array, - * has_archive?: bool|string, - * rewrite?: bool|array{ - * slug?: string, - * with_front?: bool, - * feeds?: bool, - * pages?: bool, - * ep_mask?: int, - * }, - * query_var?: bool|string, - * can_export?: bool, - * delete_with_user?: bool, - * show_in_rest?: bool, - * rest_base?: string, - * rest_namespace?: string, - * rest_controller_class?: string, - * _builtin?: bool, - * template?: array>, - * template_lock?: string|false, - * } - */ - public function get_options() { - $options = [ - 'labels' => $this->get_labels(), - 'public' => true, - 'has_archive' => true, - 'show_ui' => true, - 'show_in_menu' => true, - 'show_in_nav_menus' => false, - 'show_in_rest' => true, - 'supports' => $this->get_editor_supports(), - 'menu_icon' => $this->get_menu_icon(), - 'hierarchical' => $this->is_hierarchical(), - ]; - - $menu_position = $this->get_menu_position(); - - if ( null !== $menu_position ) { - $options['menu_position'] = $menu_position; - } - - return $options; - } - - /** - * Get the labels for the post type. - * - * @return array - */ - public function get_labels() { - $plural_label = $this->get_plural_label(); - $singular_label = $this->get_singular_label(); - - // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment -- ignoring template strings without translators placeholder since this is dynamic - $labels = [ - 'name' => $plural_label, - // Already translated via get_plural_label(). - 'singular_name' => $singular_label, - // Already translated via get_singular_label(). - 'add_new' => sprintf( __( 'Add New %s', 'tenup-plugin' ), $singular_label ), - 'add_new_item' => sprintf( __( 'Add New %s', 'tenup-plugin' ), $singular_label ), - 'edit_item' => sprintf( __( 'Edit %s', 'tenup-plugin' ), $singular_label ), - 'new_item' => sprintf( __( 'New %s', 'tenup-plugin' ), $singular_label ), - 'view_item' => sprintf( __( 'View %s', 'tenup-plugin' ), $singular_label ), - 'view_items' => sprintf( __( 'View %s', 'tenup-plugin' ), $plural_label ), - 'search_items' => sprintf( __( 'Search %s', 'tenup-plugin' ), $plural_label ), - 'not_found' => sprintf( __( 'No %s found.', 'tenup-plugin' ), strtolower( $plural_label ) ), - 'not_found_in_trash' => sprintf( __( 'No %s found in Trash.', 'tenup-plugin' ), strtolower( $plural_label ) ), - 'parent_item_colon' => sprintf( __( 'Parent %s:', 'tenup-plugin' ), $plural_label ), - 'all_items' => sprintf( __( 'All %s', 'tenup-plugin' ), $plural_label ), - 'archives' => sprintf( __( '%s Archives', 'tenup-plugin' ), $singular_label ), - 'attributes' => sprintf( __( '%s Attributes', 'tenup-plugin' ), $singular_label ), - 'insert_into_item' => sprintf( __( 'Insert into %s', 'tenup-plugin' ), strtolower( $singular_label ) ), - 'uploaded_to_this_item' => sprintf( __( 'Uploaded to this %s', 'tenup-plugin' ), strtolower( $singular_label ) ), - 'filter_items_list' => sprintf( __( 'Filter %s list', 'tenup-plugin' ), strtolower( $plural_label ) ), - 'items_list_navigation' => sprintf( __( '%s list navigation', 'tenup-plugin' ), $plural_label ), - 'items_list' => sprintf( __( '%s list', 'tenup-plugin' ), $plural_label ), - 'item_published' => sprintf( __( '%s published.', 'tenup-plugin' ), $singular_label ), - 'item_published_privately' => sprintf( __( '%s published privately.', 'tenup-plugin' ), $singular_label ), - 'item_reverted_to_draft' => sprintf( __( '%s reverted to draft.', 'tenup-plugin' ), $singular_label ), - 'item_scheduled' => sprintf( __( '%s scheduled.', 'tenup-plugin' ), $singular_label ), - 'item_updated' => sprintf( __( '%s updated.', 'tenup-plugin' ), $singular_label ), - 'menu_name' => $plural_label, - 'name_admin_bar' => $singular_label, - ]; - // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment - - return $labels; - } - - /** - * Registers a post type and associates its taxonomies. - * - * @uses $this->get_name() to get the post's type name. - * @return Bool Whether this theme has supports for this post type. - */ - public function register() { - $this->register_post_type(); - $this->register_taxonomies(); - - $this->after_register(); - - return true; - } - - /** - * Registers the current post type with WordPress. - * - * @return void - */ - public function register_post_type() { - register_post_type( - $this->get_name(), - $this->get_options() - ); - } - - /** - * Registers the taxonomies declared with the current post type. - * - * @return void - */ - public function register_taxonomies() { - $taxonomies = $this->get_supported_taxonomies(); - - $object_type = $this->get_name(); - - if ( ! empty( $taxonomies ) ) { - foreach ( $taxonomies as $taxonomy ) { - register_taxonomy_for_object_type( - $taxonomy, - $object_type - ); - } - } - } - - /** - * Returns the default supported taxonomies. The subclass should declare the - * Taxonomies that it supports here if required. - * - * @return array - */ - public function get_supported_taxonomies() { - return []; - } - - /** - * Run any code after the post type has been registered. - * - * @return void - */ - public function after_register() { - // Do nothing. - } -} diff --git a/mu-plugins/10up-plugin/includes/classes/Taxonomies/AbstractTaxonomy.php b/mu-plugins/10up-plugin/includes/classes/Taxonomies/AbstractTaxonomy.php deleted file mode 100644 index 219a8210..00000000 --- a/mu-plugins/10up-plugin/includes/classes/Taxonomies/AbstractTaxonomy.php +++ /dev/null @@ -1,195 +0,0 @@ -get_name() to get the taxonomy's slug. - * @return bool - */ - public function register() { - \register_taxonomy( - $this->get_name(), - $this->get_post_types(), - $this->get_options() - ); - - $this->after_register(); - - return true; - } - - /** - * Get the options for the taxonomy. - * - * @return array{ - * labels?: array, - * description?: string, - * public?: bool, - * publicly_queryable?: bool, - * hierarchical?: bool, - * show_ui?: bool, - * show_in_menu?: bool, - * show_in_nav_menus?: bool, - * show_tagcloud?: bool, - * show_in_quick_edit?: bool, - * show_admin_column?: bool, - * meta_box_cb?: bool|callable, - * show_in_rest?: bool, - * rest_base?: string, - * rest_namespace?: string, - * rest_controller_class?: string, - * capabilities?: array, - * rewrite?: bool|array{ - * slug?: string, - * with_front?: bool, - * hierarchical?: bool, - * ep_mask?: int, - * }, - * query_var?: string|bool, - * update_count_callback?: callable, - * default_term?: string|array{ - * name: string, - * slug?: string, - * description?: string, - * }, - * sort?: bool, - * _builtin?: bool, - * } - */ - public function get_options() { - return [ - 'labels' => $this->get_labels(), - 'hierarchical' => $this->is_hierarchical(), - 'show_ui' => true, - 'show_admin_column' => true, - 'query_var' => true, - 'show_in_rest' => true, - 'public' => true, - ]; - } - - /** - * Get the labels for the taxonomy. - * - * @return array - */ - public function get_labels() { - $plural_label = $this->get_plural_label(); - $singular_label = $this->get_singular_label(); - - // phpcs:disable - $labels = [ - 'name' => $plural_label, // Already translated via get_plural_label(). - 'singular_name' => $singular_label, // Already translated via get_singular_label(). - 'search_items' => sprintf( __( 'Search %s', 'tenup-plugin' ), $plural_label ), - 'popular_items' => sprintf( __( 'Popular %s', 'tenup-plugin' ), $plural_label ), - 'all_items' => sprintf( __( 'All %s', 'tenup-plugin' ), $plural_label ), - 'edit_item' => sprintf( __( 'Edit %s', 'tenup-plugin' ), $singular_label ), - 'update_item' => sprintf( __( 'Update %s', 'tenup-plugin' ), $singular_label ), - 'add_new_item' => sprintf( __( 'Add %s', 'tenup-plugin' ), $singular_label ), - 'new_item_name' => sprintf( __( 'New %s Name', 'tenup-plugin' ), $singular_label ), - 'separate_items_with_commas' => sprintf( __( 'Separate %s with commas', 'tenup-plugin' ), strtolower( $plural_label ) ), - 'add_or_remove_items' => sprintf( __( 'Add or remove %s', 'tenup-plugin' ), strtolower( $plural_label ) ), - 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'tenup-plugin' ), strtolower( $plural_label ) ), - 'not_found' => sprintf( __( 'No %s found.', 'tenup-plugin' ), strtolower( $plural_label ) ), - 'not_found_in_trash' => sprintf( __( 'No %s found in Trash.', 'tenup-plugin' ), strtolower( $plural_label ) ), - 'view_item' => sprintf( __( 'View %s', 'tenup-plugin' ), $singular_label ), - ]; - // phpcs:enable - - return $labels; - } - - /** - * Setting the post types to null to ensure no post type is registered with - * this taxonomy. Post Type classes declare their supported taxonomies. - * - * @return array - */ - public function get_post_types() { - return []; - } - - /** - * Run any code after the taxonomy has been registered. - * - * @return void - */ - public function after_register() { - // Do nothing. - } -} diff --git a/mu-plugins/10up-plugin/includes/core.php b/mu-plugins/10up-plugin/includes/core.php index 9275ae48..623c0dbf 100755 --- a/mu-plugins/10up-plugin/includes/core.php +++ b/mu-plugins/10up-plugin/includes/core.php @@ -52,21 +52,6 @@ function i18n() { function init() { do_action( 'tenup_plugin_before_init' ); - // If the composer.json isn't found, trigger a warning. - if ( ! file_exists( TENUP_PLUGIN_PATH . 'composer.json' ) ) { - add_action( - 'admin_notices', - function () { - $class = 'notice notice-error'; - /* translators: %s: the path to the plugin */ - $message = sprintf( __( 'The composer.json file was not found within %s. No classes will be loaded.', 'tenup-plugin' ), TENUP_PLUGIN_PATH ); - - printf( '

%2$s

', esc_attr( $class ), esc_html( $message ) ); - } - ); - return; - } - ModuleInitialization::instance()->init_classes(); do_action( 'tenup_plugin_init' ); } diff --git a/mu-plugins/10up-plugin/includes/helpers/helpers.php b/mu-plugins/10up-plugin/includes/helpers/helpers.php deleted file mode 100644 index 8f290756..00000000 --- a/mu-plugins/10up-plugin/includes/helpers/helpers.php +++ /dev/null @@ -1,19 +0,0 @@ -get_class( $class_name ); -} diff --git a/themes/10up-theme/includes/classes/Module.php b/themes/10up-theme/includes/classes/Module.php deleted file mode 100644 index 61004ba9..00000000 --- a/themes/10up-theme/includes/classes/Module.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ - protected $classes = []; - - /** - * Get all the TenUpTheme plugin classes. - * - * @return array - */ - protected function get_classes() { - // Get all classes from this directory and its subdirectories. - $class_finder = Discover::in( __DIR__ ); - // Only fetch classes. - $class_finder->classes(); - // Only fetch classes in the current namespace. - $class_finder->custom( - fn( DiscoveredStructure $structure ) => str_starts_with( $structure->namespace, __NAMESPACE__ ) - ); - - // If we are in production or staging, cache the class loader to improve performance. - if ( in_array( wp_get_environment_type(), [ 'production', 'staging' ], true ) ) { - $class_finder->withCache( - __NAMESPACE__, - new FileDiscoverCacheDriver( __DIR__ . '/class-loader-cache' ) - ); - } - - $classes = array_filter( $class_finder->get(), fn( $cl ) => is_string( $cl ) ); - - // Return the classes - return $classes; - } - - /** - * Initialize all the TenUpTheme plugin classes. - * - * @return void - */ - public function init_classes() { - $load_class_order = []; - - foreach ( $this->get_classes() as $class ) { - // Create a slug for the class name. - $slug = $this->slugify_class_name( $class ); - - // If the class has already been initialized, skip it. - if ( isset( $this->classes[ $slug ] ) ) { - continue; - } - - // Create a new reflection of the class. - // @phpstan-ignore argument.type - $reflection_class = new ReflectionClass( $class ); - - // Using reflection, check if the class can be initialized. - // If not, skip. - if ( ! $reflection_class->isInstantiable() ) { - continue; - } - - // Make sure the class is a subclass of Module, so we can initialize it. - if ( ! $reflection_class->isSubclassOf( sprintf( '\%s\Module', __NAMESPACE__ ) ) ) { - continue; - } - - // Initialize the class. - $instantiated_class = new $class(); - - if ( ! $instantiated_class instanceof Module ) { - continue; - } - - // Assign the classes into the order they should be initialized. - $load_class_order[ intval( $instantiated_class->load_order ) ][] = [ - 'slug' => $slug, - 'class' => $instantiated_class, - ]; - } - - // Sort the initialized classes by load order. - ksort( $load_class_order ); - - // Loop through the classes and initialize them. - foreach ( $load_class_order as $class_objects ) { - foreach ( $class_objects as $class_object ) { - $class = $class_object['class']; - $slug = $class_object['slug']; - - // If the class can be registered, register it. - if ( $class->can_register() ) { - // Call its register method. - $class->register(); - // Store the class in the list of initialized classes. - $this->classes[ $slug ] = $class; - } - } - } - } - - /** - * Slugify a class name. - * - * @param string $class_name The class name. - * - * @return string - */ - protected function slugify_class_name( $class_name ) { - return sanitize_title( str_replace( '\\', '-', $class_name ) ); - } - - /** - * Get a class by its full class name, including namespace. - * - * @param string $class_name The class name & namespace. - * - * @return false|\TenUpTheme\Module - */ - public function get_class( $class_name ) { - $class_name = $this->slugify_class_name( $class_name ); - - if ( isset( $this->classes[ $class_name ] ) ) { - return $this->classes[ $class_name ]; - } - - return false; - } - - /** - * Get all the initialized classes. - * - * @return array<\TenUpTheme\Module> - */ - public function get_all_classes() { - return $this->classes; - } -} diff --git a/themes/10up-theme/includes/core.php b/themes/10up-theme/includes/core.php index 497b7c2d..78854ce7 100755 --- a/themes/10up-theme/includes/core.php +++ b/themes/10up-theme/includes/core.php @@ -38,21 +38,6 @@ function setup() { function init() { do_action( 'tenup_theme_before_init' ); - // If the composer.json isn't found, trigger a warning. - if ( ! file_exists( TENUP_THEME_PATH . 'composer.json' ) ) { - add_action( - 'admin_notices', - function () { - $class = 'notice notice-error'; - /* translators: %s: the path to the plugin */ - $message = sprintf( __( 'The composer.json file was not found within %s. No classes will be loaded.', 'tenup-theme' ), TENUP_THEME_PATH ); - - printf( '

%2$s

', esc_attr( $class ), esc_html( $message ) ); - } - ); - return; - } - ModuleInitialization::instance()->init_classes(); do_action( 'tenup_theme_init' ); }