>filter( $schemas, $jsonld, $data ); return array_merge( $data, $schemas ); } /** * Get Schema Data. * * @param int $term_id Term ID. * * @return array $schemas Schema Data. */ private function get_schema_data( $term_id ) { $schemas = DB::get_schemas( $term_id, 'termmeta' ); if ( ! empty( $schemas ) || metadata_exists( 'term', $term_id, 'rank_math_rich_snippet' ) ) { return $schemas; } return []; } /** * Add active templates to the schemas json * * @return array */ public function get_active_templates() { $templates = $this->get_schema_templates(); if ( empty( $templates ) ) { return []; } $screen = get_current_screen(); $schemas = []; foreach ( $templates as $template ) { if ( empty( $template['schema']['metadata']['displayConditions'] ) ) { continue; } $conditions = $template['schema']['metadata']['displayConditions']; $can_add = false; $data = []; foreach ( $conditions as $condition ) { $category = $condition['category']; if ( 'archive' !== $category ) { continue; } $operator = $condition['condition']; if ( ! empty( $data[ $category ] ) && 'exclude' !== $operator ) { continue; } $type = $condition['type']; $value = $condition['value']; if ( 'general' === $category ) { $data[ $category ] = 'include' === $operator; continue; } if ( $value && absint( Param::get( 'tag_ID' ) ) === $value ) { $data[ $category ] = 'include' === $operator; break; } if ( 'all' === $type ) { $data[ $category ] = 'include' === $operator; } elseif ( $type !== $screen->taxonomy ) { $data[ $category ] = false; } elseif ( ! $value ) { $data[ $category ] = 'include' === $operator; } elseif ( Param::get( 'tag_ID' ) !== $value ) { $data[ $category ] = isset( $data[ $category ] ) ? $data[ $category ] : false; } else { $data[ $category ] = 'include' === $operator; } } if ( isset( $data['archive'] ) ) { $can_add = $data['archive']; } else { $can_add = ! empty( $data['general'] ); } if ( $can_add ) { $template['schema']['isTemplate'] = true; $schemas[ $template['id'] ] = $template['schema']; } } return $schemas; } /** * Can add Schema data on current taxonomy * * @param string $taxonomy Taxonomy name. * * @return bool */ private function can_add( $taxonomy ) { return Helper::get_settings( 'titles.tax_' . $taxonomy . '_add_meta_box' ) && true !== apply_filters( 'rank_math/snippet/remove_taxonomy_data', Helper::get_settings( 'titles.remove_' . $taxonomy . '_snippet_data' ), $taxonomy ); } }