@@ -116,10 +116,20 @@ private static function get_prompt_from_info( $site_info ) {
116
116
* Get the patterns for a particular category.
117
117
*
118
118
* @param string $category The category to get patterns for.
119
+ * @param array $site_classification site classification as determined by AI.
119
120
*/
120
- private static function get_patterns_for_category ( $ category ) {
121
+ private static function get_patterns_for_category ( $ category , $ site_classification = array () ) {
122
+ $ primary_sitetype = isset ( $ site_classification ['primaryType ' ] ) ? $ site_classification ['primaryType ' ] : null ;
123
+ $ secondary_sitetype = isset ( $ site_classification ['slug ' ] ) ? $ site_classification ['slug ' ] : null ;
124
+ $ args = array (
125
+ 'category ' => $ category ,
126
+ 'primary_type ' => $ primary_sitetype ,
127
+ 'secondary_type ' => $ secondary_sitetype ,
128
+ );
129
+ $ api = NFD_PATTERNS_BASE . 'patterns? ' . http_build_query ( $ args );
130
+
121
131
$ response = wp_remote_get (
122
- NFD_PATTERNS_BASE . ' patterns?category= ' . $ category ,
132
+ $ api ,
123
133
array (
124
134
'headers ' => array (
125
135
'Content-Type ' => 'application/json ' ,
@@ -527,6 +537,34 @@ public static function get_content_for_page(
527
537
$ keywords ,
528
538
$ page
529
539
) {
540
+ $ site_classification_mapping = self ::get_sitegen_from_cache ( 'siteclassificationmapping ' );
541
+ if ( ! $ site_classification_mapping ) {
542
+ $ site_classification_mapping = self ::generate_site_meta (
543
+ array (
544
+ 'site_description ' => $ site_description ,
545
+ ),
546
+ 'siteclassificationmapping '
547
+ );
548
+ }
549
+
550
+ $ site_classification = self ::get_sitegen_from_cache ( 'siteclassification ' );
551
+ if ( Patterns::check_custom_menu_needed ( $ site_classification , $ site_classification_mapping , $ page ) ) {
552
+ $ menu_patterns = self ::get_patterns_for_category ( $ page , $ site_classification );
553
+ if ( ! $ menu_patterns ['error ' ] ) {
554
+ $ menu_patterns_slugs = Patterns::get_custom_menu_slugs ();
555
+ $ menu_patterns_filtered = array_filter (
556
+ $ menu_patterns ,
557
+ function ( $ key ) use ( $ menu_patterns_slugs ) {
558
+ return in_array ( $ key , $ menu_patterns_slugs , true );
559
+ },
560
+ ARRAY_FILTER_USE_KEY
561
+ );
562
+ $ random_menu_pattern_slug = array_rand ( $ menu_patterns_filtered );
563
+
564
+ return $ menu_patterns_filtered [ $ random_menu_pattern_slug ]['content ' ];
565
+ }
566
+ }
567
+
530
568
$ response = wp_remote_post (
531
569
NFD_AI_BASE . 'generatePageContent ' ,
532
570
array (
0 commit comments