option( 'jetpack_seo_titles' ) || '' !== (string) get_option( 'jetpack_seo_front_page_description', '' ); } public function post_record( int $post_id ): array { return $this->clean( array( 'title' => $this->vars( $this->meta( $post_id, '_jetpack_seo_html_title' ) ), 'desc' => $this->meta( $post_id, 'advanced_seo_description' ), ) ); } /** * Jetpack stores a title as an ordered list of tokens, not as a string: * [{type: site_name}, {type: separator, value: '|'}, {type: post_title}]. */ private function tokens( array $format ): string { $parts = array(); foreach ( $format as $token ) { $type = is_array( $token ) ? (string) ( $token['type'] ?? '' ) : ''; $parts[] = match ( $type ) { 'site_name' => '%sitename%', 'tagline' => '%tagline%', 'post_title', 'page_title' => '%title%', 'group_title', 'archive_title' => '%term%', 'date' => '%date%', 'string' => trim( (string) ( $token['value'] ?? '' ) ), 'separator' => '%sep%', default => '', }; } return trim( (string) preg_replace( '/\s{2,}/', ' ', implode( ' ', array_filter( $parts ) ) ) ); } public function settings(): array { $titles = $this->option( 'jetpack_seo_titles' ); $front = (string) get_option( 'jetpack_seo_front_page_description', '' ); if ( empty( $titles ) && '' === $front ) { return array(); } $out = array( 'home_desc' => $front ); if ( ! empty( $titles['front_page'] ) ) { $out['home_title'] = $this->tokens( (array) $titles['front_page'] ); } if ( ! empty( $titles['posts'] ) ) { $out['templates'] = array( 'post' => array( 'title' => $this->tokens( (array) $titles['posts'] ), 'desc' => '' ) ); } if ( ! empty( $titles['pages'] ) ) { $out['templates']['page'] = array( 'title' => $this->tokens( (array) $titles['pages'] ), 'desc' => '' ); } if ( ! empty( $titles['groups'] ) ) { $out['taxonomy_templates'] = array( 'category' => array( 'title' => $this->tokens( (array) $titles['groups'] ), 'desc' => '' ) ); } return $out; } }