plates as $template_data ) { $template = $template_data['template']; $categories = explode( ',', $template_data['categories'] ); if ( $template['has_access'] ) { ++$available_templates_count; } if ( $template['favorite'] ) { ++$favorites_templates_count; } if ( $template['source'] === 'wpforms-user-template' ) { ++$user_templates_count; } if ( is_array( $categories ) ) { array_push( $all_categories, ...$categories ); continue; } $all_categories[] = $categories; } $categories_count = array_count_values( $all_categories ); $categories_count['all'] = count( $this->prepared_templates ); $categories_count['available'] = $available_templates_count; $categories_count['favorites'] = $favorites_templates_count; $categories_count['user'] = $user_templates_count; $categories_count['subcategories'] = $this->get_count_in_subcategories(); return $categories_count; } /** * Get subcategories templates count. * * @since 1.8.7 * * @return array */ private function get_count_in_subcategories(): array { $all_subcategories = []; foreach ( $this->prepared_templates as $template_data ) { $subcategories = explode( ',', $template_data['subcategories'] ); if ( is_array( $subcategories ) ) { array_push( $all_subcategories, ...$subcategories ); continue; } $all_subcategories[] = $subcategories; } return array_count_values( $all_subcategories ); } }