WP_Customize_Manager::has_published_pages PHP Method

has_published_pages() public method

Used as active callback for static front page section and controls.
Since: 4.7.0
public has_published_pages ( )
    public function has_published_pages()
    {
        $setting = $this->get_setting('nav_menus_created_posts');
        if ($setting) {
            foreach ($setting->value() as $post_id) {
                if ('page' === get_post_type($post_id)) {
                    return true;
                }
            }
        }
        return 0 !== count(get_pages());
    }

Usage Example

 /**
  * Ensure that page stubs created via nav menus will cause has_published_pages to return true.
  *
  * @ticket 38013
  * @covers WP_Customize_Manager::has_published_pages()
  */
 function test_has_published_pages_when_nav_menus_created_posts()
 {
     foreach (get_pages() as $page) {
         wp_delete_post($page->ID, true);
     }
     $this->assertFalse($this->manager->has_published_pages());
     wp_set_current_user(self::$admin_user_id);
     $this->manager->nav_menus->customize_register();
     $setting_id = 'nav_menus_created_posts';
     $setting = $this->manager->get_setting($setting_id);
     $this->assertInstanceOf('WP_Customize_Filter_Setting', $setting);
     $auto_draft_page = $this->factory()->post->create(array('post_type' => 'page', 'post_status' => 'auto-draft'));
     $this->manager->set_post_value($setting_id, array($auto_draft_page));
     $setting->preview();
     $this->assertTrue($this->manager->has_published_pages());
 }
WP_Customize_Manager