2258 | | // #WP19627 |
2259 | | |
2260 | | // Replicate behavior from options-reading.php and hide front page options if there are no pages |
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 | | ) ); |
| 2258 | // See also https://core.trac.wordpress.org/ticket/19627 which introduces the the static-front-page theme_support. |
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 | | ) ); |
| 2260 | // Replicate behavior from options-reading.php. |
| 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 | ) ); |
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 | | ) ); |
| 2267 | $this->add_setting( 'show_on_front', array( |
| 2268 | 'default' => get_option( 'show_on_front' ), |
| 2269 | 'capability' => 'manage_options', |
| 2270 | 'type' => 'option', |
| 2271 | ) ); |
2286 | | $this->add_setting( 'page_on_front', array( |
2287 | | 'type' => 'option', |
2288 | | 'capability' => 'manage_options', |
2289 | | // 'theme_supports' => 'static-front-page', |
2290 | | ) ); |
| 2273 | $this->add_control( 'show_on_front', array( |
| 2274 | 'label' => __( 'Front page displays' ), |
| 2275 | 'section' => 'static_front_page', |
| 2276 | 'type'=> 'radio', |
| 2277 | 'choices' => array( |
| 2278 | 'posts' => __( 'Your latest posts' ), |
| 2279 | 'page' => __( 'A static page' ), |
| 2280 | ), |
| 2281 | 'active_callback' => array( $this, 'has_published_pages' ), |
| 2282 | ) ); |
2292 | | $this->add_control( 'page_on_front', array( |
2293 | | 'label' => __( 'Front page' ), |
2294 | | 'section' => 'static_front_page', |
2295 | | 'type' => 'dropdown-pages', |
2296 | | ) ); |
| 2284 | $this->add_setting( 'page_on_front', array( |
| 2285 | 'type' => 'option', |
| 2286 | 'capability' => 'manage_options', |
| 2287 | ) ); |
2298 | | $this->add_setting( 'page_for_posts', array( |
2299 | | 'type' => 'option', |
2300 | | 'capability' => 'manage_options', |
2301 | | // 'theme_supports' => 'static-front-page', |
2302 | | ) ); |
| 2289 | $this->add_control( 'page_on_front', array( |
| 2290 | 'label' => __( 'Front page' ), |
| 2291 | 'section' => 'static_front_page', |
| 2292 | 'type' => 'dropdown-pages', |
| 2293 | 'active_callback' => array( $this, 'has_published_pages' ), |
| 2294 | ) ); |
2304 | | $this->add_control( 'page_for_posts', array( |
2305 | | 'label' => __( 'Posts page' ), |
2306 | | 'section' => 'static_front_page', |
2307 | | 'type' => 'dropdown-pages', |
2308 | | ) ); |
| 2296 | $this->add_setting( 'page_for_posts', array( |
| 2297 | 'type' => 'option', |
| 2298 | 'capability' => 'manage_options', |
| 2299 | // 'theme_supports' => 'static-front-page', |
| 2300 | ) ); |
| 2301 | |
| 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 | $setting = $this->get_setting( 'nav_menus_created_posts' ); |
| 2323 | if ( $setting ) { |
| 2324 | foreach ( $setting->value() as $post_id ) { |
| 2325 | if ( get_post_type( $post_id ) ) { |
| 2326 | return true; |
| 2327 | } |
| 2328 | } |