From c937a110af204b4f814cfa4d22a13619c33788bf Mon Sep 17 00:00:00 2001 From: kodinkat Date: Thu, 18 Dec 2025 17:01:11 +0000 Subject: [PATCH 1/2] Add filter callbacks for home screen apps and training videos - Introduced filter hooks for and in to allow external code to modify the list of apps and links displayed on the home screen. - Added corresponding filter callback methods to return filtered apps based on their type in . - Registered a filter hook for in to enable external modifications to the training videos list. - Implemented a filter callback method to return all training videos in . --- dt-apps/dt-home/includes/class-home-apps.php | 36 +++++++++++++++++++ .../dt-home/includes/class-home-training.php | 15 ++++++++ 2 files changed, 51 insertions(+) diff --git a/dt-apps/dt-home/includes/class-home-apps.php b/dt-apps/dt-home/includes/class-home-apps.php index d51e9041f4..2d6c1bf9f7 100644 --- a/dt-apps/dt-home/includes/class-home-apps.php +++ b/dt-apps/dt-home/includes/class-home-apps.php @@ -55,6 +55,10 @@ public function on_init() { // This is where we can safely apply filters after all classes are loaded $this->load_magic_link_apps(); $this->load_home_apps(); + + // Register filter hooks for external code + add_filter( 'dt_home_screen_apps', [ $this, 'filter_home_screen_apps' ] ); + add_filter( 'dt_home_screen_links', [ $this, 'filter_home_screen_links' ] ); } /** @@ -797,6 +801,38 @@ public function get_apps_for_user( $user_id = 0 ) { return $roles_permissions->filter_apps_by_permissions( $apps, $user_id ); } + /** + * Filter callback for dt_home_screen_apps + * + * Returns only apps of type 'app' when external code calls apply_filters('dt_home_screen_apps', []). + * + * @param array $default_value Default value passed to apply_filters + * @return array Filtered apps of type 'app' + */ + public function filter_home_screen_apps( $default_value ) { + $apps = $this->get_apps_for_frontend(); + $filtered = array_filter( $apps, function( $app ) { + return isset( $app['type'] ) && strtolower( trim( $app['type'] ) ) === 'app'; + }); + return $filtered; + } + + /** + * Filter callback for dt_home_screen_links + * + * Returns only apps of type 'link' when external code calls apply_filters('dt_home_screen_links', []). + * + * @param array $default_value Default value passed to apply_filters + * @return array Filtered apps of type 'link' + */ + public function filter_home_screen_links( $default_value ) { + $apps = $this->get_apps_for_frontend(); + $filtered = array_filter( $apps, function( $app ) { + return isset( $app['type'] ) && strtolower( trim( $app['type'] ) ) === 'link'; + }); + return $filtered; + } + /** * Validate app data */ diff --git a/dt-apps/dt-home/includes/class-home-training.php b/dt-apps/dt-home/includes/class-home-training.php index 218e43cc4e..f4f5549af4 100644 --- a/dt-apps/dt-home/includes/class-home-training.php +++ b/dt-apps/dt-home/includes/class-home-training.php @@ -29,6 +29,9 @@ public static function instance() { public function __construct() { // Initialize with default videos if none exist $this->initialize_default_videos(); + + // Register filter hook for external code + add_filter( 'dt_home_screen_training_videos', [ $this, 'filter_home_screen_training_videos' ] ); } /** @@ -302,6 +305,18 @@ public function get_videos_for_frontend() { return $videos; } + /** + * Filter callback for dt_home_screen_training_videos + * + * Returns all training videos when external code calls apply_filters('dt_home_screen_training_videos', []). + * + * @param array $default_value Default value passed to apply_filters + * @return array All training videos + */ + public function filter_home_screen_training_videos( $default_value ) { + return $this->get_videos_for_frontend(); + } + /** * Get YouTube thumbnail URL */ From cc5922b2c38cc127db3b3d89637ed0b2a65f6fa5 Mon Sep 17 00:00:00 2001 From: kodinkat Date: Tue, 6 Jan 2026 14:00:01 +0000 Subject: [PATCH 2/2] Refactor home apps and training classes to remove filter callbacks - Removed filter callback methods for home screen apps and training videos to streamline functionality. - Updated method to include an optional parameter for filtering by app type. - Adjusted comments for clarity regarding app loading and filtering processes. --- dt-apps/dt-home/includes/class-home-apps.php | 53 ++++++------------- .../dt-home/includes/class-home-training.php | 15 ------ 2 files changed, 15 insertions(+), 53 deletions(-) diff --git a/dt-apps/dt-home/includes/class-home-apps.php b/dt-apps/dt-home/includes/class-home-apps.php index 2d6c1bf9f7..e80370b8a1 100644 --- a/dt-apps/dt-home/includes/class-home-apps.php +++ b/dt-apps/dt-home/includes/class-home-apps.php @@ -52,13 +52,9 @@ private function initialize_default_apps() { * Called on init hook to handle filter timing */ public function on_init() { - // This is where we can safely apply filters after all classes are loaded + // This is where we can safely load apps after all classes are loaded $this->load_magic_link_apps(); $this->load_home_apps(); - - // Register filter hooks for external code - add_filter( 'dt_home_screen_apps', [ $this, 'filter_home_screen_apps' ] ); - add_filter( 'dt_home_screen_links', [ $this, 'filter_home_screen_links' ] ); } /** @@ -705,8 +701,11 @@ private function determine_app_type( $app ) { /** * Get apps for frontend display + * + * @param string|null $type Optional. Filter by app type: 'app', 'link', or null for all apps. + * @return array Array of apps for frontend display */ - public function get_apps_for_frontend() { + public function get_apps_for_frontend( $type = null ) { $apps = $this->get_enabled_apps(); // Enrich coded magic-link app urls. @@ -767,6 +766,16 @@ public function get_apps_for_frontend() { $enriched_apps[] = $app; } + // If type is specified, filter by type + if ( $type !== null ) { + $type_normalized = strtolower( trim( $type ) ); + if ( $type_normalized === 'app' || $type_normalized === 'link' ) { + $enriched_apps = array_filter( $enriched_apps, function( $app ) use ( $type_normalized ) { + return isset( $app['type'] ) && strtolower( trim( $app['type'] ) ) === $type_normalized; + }); + } + } + // Sort by order usort( $enriched_apps, function( $a, $b ) { return $a['order'] <=> $b['order']; @@ -801,38 +810,6 @@ public function get_apps_for_user( $user_id = 0 ) { return $roles_permissions->filter_apps_by_permissions( $apps, $user_id ); } - /** - * Filter callback for dt_home_screen_apps - * - * Returns only apps of type 'app' when external code calls apply_filters('dt_home_screen_apps', []). - * - * @param array $default_value Default value passed to apply_filters - * @return array Filtered apps of type 'app' - */ - public function filter_home_screen_apps( $default_value ) { - $apps = $this->get_apps_for_frontend(); - $filtered = array_filter( $apps, function( $app ) { - return isset( $app['type'] ) && strtolower( trim( $app['type'] ) ) === 'app'; - }); - return $filtered; - } - - /** - * Filter callback for dt_home_screen_links - * - * Returns only apps of type 'link' when external code calls apply_filters('dt_home_screen_links', []). - * - * @param array $default_value Default value passed to apply_filters - * @return array Filtered apps of type 'link' - */ - public function filter_home_screen_links( $default_value ) { - $apps = $this->get_apps_for_frontend(); - $filtered = array_filter( $apps, function( $app ) { - return isset( $app['type'] ) && strtolower( trim( $app['type'] ) ) === 'link'; - }); - return $filtered; - } - /** * Validate app data */ diff --git a/dt-apps/dt-home/includes/class-home-training.php b/dt-apps/dt-home/includes/class-home-training.php index f4f5549af4..218e43cc4e 100644 --- a/dt-apps/dt-home/includes/class-home-training.php +++ b/dt-apps/dt-home/includes/class-home-training.php @@ -29,9 +29,6 @@ public static function instance() { public function __construct() { // Initialize with default videos if none exist $this->initialize_default_videos(); - - // Register filter hook for external code - add_filter( 'dt_home_screen_training_videos', [ $this, 'filter_home_screen_training_videos' ] ); } /** @@ -305,18 +302,6 @@ public function get_videos_for_frontend() { return $videos; } - /** - * Filter callback for dt_home_screen_training_videos - * - * Returns all training videos when external code calls apply_filters('dt_home_screen_training_videos', []). - * - * @param array $default_value Default value passed to apply_filters - * @return array All training videos - */ - public function filter_home_screen_training_videos( $default_value ) { - return $this->get_videos_for_frontend(); - } - /** * Get YouTube thumbnail URL */