Skip to content

Commit

Permalink
Fix issue with papi_get_page_type_id and only page type filter
Browse files Browse the repository at this point in the history
  • Loading branch information
frozzare committed Nov 30, 2015
1 parent 814db90 commit e0f7dcf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ function papi_get_page_type_id( $post_id = 0 ) {
$page_type = empty( $meta_value ) ? '' : $meta_value;
}

// When using `only_page_type` filter we need to fetch the value since it
// maybe not always saved in the database.
if ( empty ( $page_type ) ) {
$post_type = get_post_type( $post_id );

if ( is_string( $post_type ) && $page_type = papi_filter_settings_only_page_type( $post_type ) ) {
return $page_type;
}
}

// Load page type id from the container if it exists or
// load it from `papi_get_all_page_types`.
if ( empty( $page_type ) ) {
Expand Down
15 changes: 15 additions & 0 deletions tests/cases/lib/page-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,21 @@ public function test_papi_get_page_type_id() {
unset( $_GET['post_type'] );
}

public function test_papi_get_page_type_id_only_page_type_filter() {
$this->assertEmpty( papi_get_page_type_id() );

$_GET['post'] = $this->factory->post->create( ['post_type' => 'module'] );
$_GET['post_type'] = 'module';

add_filter( 'papi/settings/only_page_type_module', function () {
return 'modules/feature-module-type';
} );

$this->assertSame( 'modules/feature-module-type', papi_get_page_type_id() );
unset( $_GET['post'] );
unset( $_GET['post_type'] );
}

public function test_papi_get_post_types() {
$actual = papi_get_post_types();

Expand Down

0 comments on commit e0f7dcf

Please sign in to comment.