diff --git a/dt-apps/dt-home/includes/class-home-apps.php b/dt-apps/dt-home/includes/class-home-apps.php index d51e9041f4..e80370b8a1 100644 --- a/dt-apps/dt-home/includes/class-home-apps.php +++ b/dt-apps/dt-home/includes/class-home-apps.php @@ -52,7 +52,7 @@ 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(); } @@ -701,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. @@ -763,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'];