Skip to content

Commit

Permalink
Update import AIO SEO variables
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatrangnet authored and rilwis committed Nov 5, 2024
1 parent 1288b26 commit 5f6a400
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Migration/Sources/AIOSEO.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ protected function get_post_title( $post_id ) {
$title = new Common\Meta\Title;
$meta_data = aioseo()->meta->metaData->getMetaData( $this->post );

return empty( $meta_data->title ) ? '' : $title->helpers->prepare( $meta_data->title, $post_id );
return empty( $meta_data->title ) ? '' : $title->helpers->prepare( $this->replace_with_slim_seo_variables( $meta_data->title ), $post_id );
}

protected function get_post_description( $post_id ) {
$description = new Common\Meta\Description;
$meta_data = aioseo()->meta->metaData->getMetaData( $this->post );

return empty( $meta_data->description ) ? '' : $description->helpers->prepare( $meta_data->description, $post_id, false, false );
return empty( $meta_data->description ) ? '' : $description->helpers->prepare( $this->replace_with_slim_seo_variables( $meta_data->description ), $post_id, false, false );
}

protected function get_post_facebook_image( $post_id ) {
Expand Down Expand Up @@ -111,6 +111,23 @@ private function getAioImage( $type, $post ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM {$wpdb->prefix}aioseo_posts WHERE post_id = %d", $post->ID ) );
}

private function replace_with_slim_seo_variables( string $text ): string {
$variables = [
'#post_title' => '{{ post.title }}',
'#post_excerpt' => '{{ post.auto_description }}',
'#post_excerpt_only' => '{{ post.excerpt }}',
'#post_date' => '{{ post.date }}',
'#post_content' => '{{ post.content }}',
'#categories' => '{{ post.categories }}',
'#site_title' => '{{ site.title }}',
'#current_year' => '{{ current.year }}',
'#author_name' => '{{ author.display_name }}',
'#separator_sa' => '{{ sep }}',
];

return strtr( $text, $variables );
}
}

if ( class_exists( 'AIOSEO\Plugin\Common\Social\Image' ) ) {
Expand Down

0 comments on commit 5f6a400

Please sign in to comment.