Skip to content

Commit

Permalink
Merge pull request #1072 from vektor-inc/fix/sns/password
Browse files Browse the repository at this point in the history
【確認待ち】パスワードで保護された記事で OG 説明が表示されないように
  • Loading branch information
kurudrive authored Mar 14, 2024
2 parents 0061c52 + 3990d8c commit e9d2e28
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
18 changes: 10 additions & 8 deletions inc/template-tags/package/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,17 @@ function vk_get_page_description() {
if ( is_search() || is_404() ) {
$page_description = '';
} elseif ( is_front_page() ) {
if ( isset( $post->post_excerpt ) && $post->post_excerpt ) {
$page_description = get_the_excerpt();
if ( isset( $post->post_excerpt ) && $post->post_excerpt && ! post_password_required( $post->ID ) ) {
$page_description = get_the_excerpt( $post->ID );
} else {
$page_description = get_bloginfo( 'description' );
}
} elseif ( is_home() ) {
$page_for_posts = vk_get_page_for_posts();
if ( $page_for_posts['post_top_use'] ) {
$page = get_post( $page_for_posts['post_top_id'] );
if( ! empty( $page->post_excerpt ) ) {
$page_description = $page->post_excerpt;
if( ! empty( $page->post_excerpt ) && ! post_password_required( $post->ID ) ) {
$page_description = get_the_excerpt( $page->ID );
} else {
$page_description = sprintf( _x( 'Article of %s.', 'Archive description', 'vk-all-in-one-expansion-unit' ), esc_html( $page_for_posts['post_top_name'] ) );
$page_description .= ' ' . get_bloginfo( 'name' ) . ' ' . get_bloginfo( 'description' );
Expand All @@ -223,7 +223,7 @@ function vk_get_page_description() {
$page_description = get_bloginfo( 'description' );
}
} elseif ( is_category() || is_tax() ) {
if ( ! $post->description ) {
if ( empty( $post->description ) ) {
$page_description = sprintf( __( 'About %s', 'vk-all-in-one-expansion-unit' ), single_cat_title( '', false ) ) . ' ' . get_bloginfo( 'name' ) . ' ' . get_bloginfo( 'description' );
} else {
$page_description = $post->description;
Expand Down Expand Up @@ -257,10 +257,12 @@ function vk_get_page_description() {
}
}
} elseif ( is_page() || is_single() ) {
if ( $post->post_excerpt ) {
$page_description = $post->post_excerpt;
if ( post_password_required( $post->ID ) ) {
$page_description = __( 'This article is protected by a password.', 'vk-all-in-one-expansion-unit' );
} elseif ( ! empty( $post->post_excerpt ) ) {
$page_description = get_the_excerpt( $post->ID );
} else {
$page_description = $post->post_content;
$page_description = get_the_content( null, false, $post->ID );
}
} else {
$page_description = get_bloginfo( 'description' );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ e.g.

== Changelog ==

[ Bug Fix ][ SNS ] Fix OGP description on password protected page.
[ Add setting ][ Post Type Manager ] Add a custom field setting.
[ Specification Change ][ Post Type Manager ] Change so that "with_front" can be specified as false in permalink settings
[ Bug Fix ][ Contact Section ] Fixed an issue where icons do not display when input in <i> tag format.
Expand Down
71 changes: 71 additions & 0 deletions tests/test-template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ public static function setup_data() {
$data['post_id_02'] = wp_insert_post( $post );
wp_set_object_terms( $data['post_id_02'], array( $data['tag_id_01'], $data['tag_id_02'] ), 'post_tag' );

/**
* Test Post 03 を作成
*/
$post = array(
'post_name' => 'test-post',
'post_title' => 'test-post',
'post_status' => 'publish',
'post_content' => 'test-post-content',
'post_category' => array( $data['cate_id_01'], $data['cate_id_02'] ),
'post_password' => 'test-password',
'post_date' => '2021-11-01 00:00:00',
'post_modified' => '2022-01-01 00:00:00',
);
$data['post_id_03'] = wp_insert_post( $post );
wp_set_object_terms( $data['post_id_03'], array( $data['tag_id_01'], $data['tag_id_02'] ), 'post_tag' );

/**
* Test Page 01 を作成
*/
Expand Down Expand Up @@ -218,6 +234,21 @@ public static function setup_data() {
);
$data['page_id_02'] = wp_insert_post( $post );

/**
* Test Page 03 を作成
*/
$post = array(
'post_name' => 'test-page',
'post_title' => 'test-page',
'post_type' => 'page',
'post_password' => 'test-password',
'post_status' => 'publish',
'post_content' => 'test-page-content',
'post_date' => '2020-07-01 00:00:00',
'post_modified' => '2022-01-01 00:00:00',
);
$data['page_id_03'] = wp_insert_post( $post );

/**
* Test Event 01 を作成.
*/
Expand Down Expand Up @@ -249,6 +280,22 @@ public static function setup_data() {
$data['event_id_02'] = wp_insert_post( $post );
wp_set_object_terms( $data['event_id_02'], array( $data['genre_id_01'], $data['genre_id_02'] ), 'genre' );

/**
* Test Event 02 を作成.
*/
$post = array(
'post_name' => 'test-event',
'post_title' => 'test-event',
'post_type' => 'event',
'post_status' => 'publish',
'post_password' => 'test-password',
'post_content' => 'test-event-content',
'post_date' => '2021-12-01 00:00:00',
'post_modified' => '2021-11-01 12:00:00',
);
$data['event_id_03'] = wp_insert_post( $post );
wp_set_object_terms( $data['event_id_03'], array( $data['genre_id_01'], $data['genre_id_02'] ), 'genre' );

update_option( 'blogname', 'PHP Unit Test' ); // 抜粋
update_option( 'blogdescription', 'This test is checker for PHP.' ); // 抜粋

Expand Down Expand Up @@ -461,6 +508,14 @@ public function test_vk_get_page_description() {
),
'correct' => 'test-page-content',
),
array(
'test_name' => 'Page has Password',
'target_url' => get_permalink( $data['page_id_03'] ),
'options' => array(
'show_on_front' => 'posts',
),
'correct' => 'This article is protected by a password.',
),
array(
'test_name' => 'Post Description',
'target_url' => get_permalink( $data['post_id_01'] ),
Expand All @@ -477,6 +532,14 @@ public function test_vk_get_page_description() {
),
'correct' => 'test-post-content',
),
array(
'test_name' => 'Post has Password',
'target_url' => get_permalink( $data['post_id_03'] ),
'options' => array(
'show_on_front' => 'posts',
),
'correct' => 'This article is protected by a password.',
),
array(
'test_name' => 'Event Description',
'target_url' => get_permalink( $data['event_id_01'] ),
Expand All @@ -493,6 +556,14 @@ public function test_vk_get_page_description() {
),
'correct' => 'test-event-content',
),
array(
'test_name' => 'Event has Password',
'target_url' => get_permalink( $data['event_id_03'] ),
'options' => array(
'show_on_front' => 'posts',
),
'correct' => 'This article is protected by a password.',
),
array(
'test_name' => 'Search Result',
'target_url' => home_url( '/' ) . '?s=test',
Expand Down

0 comments on commit e9d2e28

Please sign in to comment.