| | 290 | |
| | 291 | /** |
| | 292 | * Display notice in admin bar when coming soon mode is on. |
| | 293 | * |
| | 294 | * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference |
| | 295 | */ |
| | 296 | function admin_bar_menu_item( $wp_admin_bar ){ |
| | 297 | $menu_slug = add_query_arg( |
| | 298 | array( |
| | 299 | 'autofocus[section]' => 'wccsp_live_preview', |
| | 300 | 'url' => rawurlencode( add_query_arg( 'wccsp-preview', '', site_url() ) ), |
| | 301 | ), |
| | 302 | '/customize.php' |
| | 303 | ); |
| | 304 | $settings = $GLOBALS['WCCSP_Settings']->get_settings(); |
| | 305 | $setting_url = admin_url( $menu_slug ); |
| | 306 | |
| | 307 | if ( $settings['enabled'] !== 'on' ) { |
| | 308 | return; |
| | 309 | } |
| | 310 | |
| | 311 | $wp_admin_bar->add_node( array( |
| | 312 | 'id' => 'wordcamp-coming-soon-info', |
| | 313 | 'href' => $setting_url, |
| | 314 | 'parent' => 'top-secondary', |
| | 315 | 'title' => __( 'You are in coming soon mode', 'wordcamporg' ), |
| | 316 | 'meta' => array( 'class' => 'wc-coming-soon-info' ), |
| | 317 | ) ); |
| | 318 | } |
| | 319 | |
| | 320 | /* |
| | 321 | * Show a notice if comming soon is enabled. |
| | 322 | * |
| | 323 | * Explain to users why publishing is disabled when comming soon is enabled. |
| | 324 | * |
| | 325 | */ |
| | 326 | public function block_new_post_admin_notice(){ |
| | 327 | $menu_slug = add_query_arg( |
| | 328 | array( |
| | 329 | 'autofocus[section]' => 'wccsp_live_preview', |
| | 330 | 'url' => rawurlencode( add_query_arg( 'wccsp-preview', '', site_url() ) ), |
| | 331 | ), |
| | 332 | '/customize.php' |
| | 333 | ); |
| | 334 | $settings = $GLOBALS['WCCSP_Settings']->get_settings(); |
| | 335 | $setting_url = admin_url( $menu_slug ); |
| | 336 | |
| | 337 | if ( $settings['enabled'] !== 'on' ) { |
| | 338 | return; |
| | 339 | } |
| | 340 | |
| | 341 | $screen = get_current_screen(); |
| | 342 | if ( trim( $screen->id ) == 'post' ) { |
| | 343 | $class = 'notice notice-error'; |
| | 344 | $message = sprintf( __( 'You cannot pubilsh posts while in Coming Soon mode. Once the site is ready for a public audience, please <a href="%s">disable Coming Soon mode</a> and then publish this post.', 'wordcamporg' ), $setting_url ); |
| | 345 | printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message ); |
| | 346 | } |
| | 347 | } |
| | 348 | |
| | 349 | /* |
| | 350 | * Block users from publishing posts when comming soon mode is enabled. |
| | 351 | * |
| | 352 | * @param array $caps Returns the user's actual capabilities. |
| | 353 | * @param string $cap Capability name. |
| | 354 | * @param int $user_id The user ID. |
| | 355 | * @param array $args Adds the context to the cap. Typically the object ID. |
| | 356 | * |
| | 357 | * @return array Returns the user's actual capabilities. |
| | 358 | */ |
| | 359 | function block_new_post_publish( $user_caps, $cap, $user_id, $args ) { |
| | 360 | $settings = $GLOBALS['WCCSP_Settings']->get_settings(); |
| | 361 | if ( $settings['enabled'] !== 'on' ) { |
| | 362 | return $user_caps; |
| | 363 | } |
| | 364 | |
| | 365 | if ( 'publish_posts' === $cap ){ |
| | 366 | $user_caps[] = 'do_not_allow'; |
| | 367 | } |
| | 368 | return $user_caps; |
| | 369 | } |
| | 370 | |