2261 | | if ( get_pages() ) { |
2262 | | $this->add_section( 'static_front_page', array( |
2263 | | 'title' => __( 'Static Front Page' ), |
2264 | | // 'theme_supports' => 'static-front-page', |
2265 | | 'priority' => 120, |
2266 | | 'description' => __( 'Your theme supports a static front page.' ), |
2267 | | ) ); |
| 2261 | $this->add_section( 'static_front_page', array( |
| 2262 | 'title' => __( 'Static Front Page' ), |
| 2263 | 'priority' => 120, |
| 2264 | 'description' => __( 'Your theme supports a static front page.' ), |
| 2265 | 'active_callback' => array( $this, 'has_published_pages' ), |
| 2266 | ) ); |
2269 | | $this->add_setting( 'show_on_front', array( |
2270 | | 'default' => get_option( 'show_on_front' ), |
2271 | | 'capability' => 'manage_options', |
2272 | | 'type' => 'option', |
2273 | | // 'theme_supports' => 'static-front-page', |
2274 | | ) ); |
| 2268 | $this->add_setting( 'show_on_front', array( |
| 2269 | 'default' => get_option( 'show_on_front' ), |
| 2270 | 'capability' => 'manage_options', |
| 2271 | 'type' => 'option', |
| 2272 | ) ); |
2276 | | $this->add_control( 'show_on_front', array( |
2277 | | 'label' => __( 'Front page displays' ), |
2278 | | 'section' => 'static_front_page', |
2279 | | 'type' => 'radio', |
2280 | | 'choices' => array( |
2281 | | 'posts' => __( 'Your latest posts' ), |
2282 | | 'page' => __( 'A static page' ), |
2283 | | ), |
2284 | | ) ); |
| 2274 | $this->add_control( 'show_on_front', array( |
| 2275 | 'label' => __( 'Front page displays' ), |
| 2276 | 'section' => 'static_front_page', |
| 2277 | 'type' => 'radio', |
| 2278 | 'choices' => array( |
| 2279 | 'posts' => __( 'Your latest posts' ), |
| 2280 | 'page' => __( 'A static page' ), |
| 2281 | ), |
| 2282 | 'active_callback' => array( $this, 'has_published_pages' ), |
| 2283 | ) ); |
2292 | | $this->add_control( 'page_on_front', array( |
2293 | | 'label' => __( 'Front page' ), |
2294 | | 'section' => 'static_front_page', |
2295 | | 'type' => 'dropdown-pages', |
2296 | | ) ); |
| 2290 | $this->add_control( 'page_on_front', array( |
| 2291 | 'label' => __( 'Front page' ), |
| 2292 | 'section' => 'static_front_page', |
| 2293 | 'type' => 'dropdown-pages', |
| 2294 | 'active_callback' => array( $this, 'has_published_pages' ), |
| 2295 | ) ); |
2304 | | $this->add_control( 'page_for_posts', array( |
2305 | | 'label' => __( 'Posts page' ), |
2306 | | 'section' => 'static_front_page', |
2307 | | 'type' => 'dropdown-pages', |
2308 | | ) ); |
2309 | | } |
| 2302 | $this->add_control( 'page_for_posts', array( |
| 2303 | 'label' => __( 'Posts page' ), |
| 2304 | 'section' => 'static_front_page', |
| 2305 | 'type' => 'dropdown-pages', |
| 2306 | 'active_callback' => array( $this, 'has_published_pages' ), |
| 2307 | ) ); |
| 2308 | } |
| 2309 | |
| 2310 | /** |
| 2311 | * Return whether there are published pages. |
| 2312 | * |
| 2313 | * Used as active callback for static front page section and controls. |
| 2314 | * |
| 2315 | * @access private |
| 2316 | * @since 4.7.0 |
| 2317 | * |
| 2318 | * @returns bool Whether there are published (or to be published) pages. |
| 2319 | */ |
| 2320 | public function has_published_pages() { |
| 2321 | |
| 2322 | // @todo Also look to see if there are any pages among in $this->get_setting( 'nav_menus_created_posts' )->value(). |
| 2323 | return 0 !== count( get_pages( array( |
| 2324 | 'post_type' => 'page', |
| 2325 | 'post_status' => 'publish', |
| 2326 | 'number' => 1, |
| 2327 | ) ) ); |