| 301 | |
| 302 | /** |
| 303 | * Display notice in admin bar when coming soon mode is on. |
| 304 | * |
| 305 | * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference |
| 306 | */ |
| 307 | function admin_bar_menu_item( $wp_admin_bar ){ |
| 308 | $menu_slug = add_query_arg( |
| 309 | array( |
| 310 | 'autofocus[section]' => 'wccsp_live_preview', |
| 311 | 'url' => rawurlencode( add_query_arg( 'wccsp-preview', '', site_url() ) ), |
| 312 | ), |
| 313 | '/customize.php' |
| 314 | ); |
| 315 | $settings = $GLOBALS['WCCSP_Settings']->get_settings(); |
| 316 | $setting_url = admin_url( $menu_slug ); |
| 317 | |
| 318 | if ( $settings['enabled'] !== 'on' ) { |
| 319 | return; |
| 320 | } |
| 321 | |
| 322 | $wp_admin_bar->add_node( array( |
| 323 | 'id' => 'wordcamp-coming-soon-info', |
| 324 | 'href' => $setting_url, |
| 325 | 'parent' => 'top-secondary', |
| 326 | 'title' => __( 'Coming Soon Mode ON', 'wordcamporg' ), |
| 327 | 'meta' => array( 'class' => 'wc-coming-soon-info' ), |
| 328 | ) ); |
| 329 | } |
| 330 | |
| 331 | public function admin_styling() { |
| 332 | echo '<style type="text/css">#wpadminbar .wc-coming-soon-info { background: #0085ba; }</style>'; |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | * Show a notice if comming soon is enabled. |
| 337 | * |
| 338 | * Explain to users why publishing is disabled when comming soon is enabled. |
| 339 | * |
| 340 | */ |
| 341 | public function block_new_post_admin_notice(){ |
| 342 | $menu_slug = add_query_arg( |
| 343 | array( |
| 344 | 'autofocus[section]' => 'wccsp_live_preview', |
| 345 | 'url' => rawurlencode( add_query_arg( 'wccsp-preview', '', site_url() ) ), |
| 346 | ), |
| 347 | '/customize.php' |
| 348 | ); |
| 349 | $settings = $GLOBALS['WCCSP_Settings']->get_settings(); |
| 350 | $setting_url = admin_url( $menu_slug ); |
| 351 | |
| 352 | if ( $settings['enabled'] !== 'on' ) { |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | $screen = get_current_screen(); |
| 357 | if ( trim( $screen->id ) == 'post' ) { |
| 358 | $class = 'notice notice-info'; |
| 359 | $message = sprintf( __( 'Publishing a post while in <a href="%s">Coming Soon mode</a> will not send an email to the subscribers.', 'wordcamporg' ), $setting_url ); |
| 360 | printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message ); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Disable sending of Jetpack emails when comming soon mode is on. |
| 366 | * |
| 367 | * @param null|array|string $value The value get_metadata() should return - a single metadata value, |
| 368 | * or an array of values. |
| 369 | * @param int $object_id Object ID. |
| 370 | * @param string $meta_key Meta key. |
| 371 | * @param bool $single Whether to return only the first value of the specified $meta_key. |
| 372 | */ |
| 373 | function jetpack_dont_email_post_to_subs( $value, $object_id, $meta_key, $single ) { |
| 374 | $settings = $GLOBALS['WCCSP_Settings']->get_settings(); |
| 375 | if ( $settings['enabled'] !== 'on' && '_jetpack_dont_email_post_to_subs' === $meta_key ) { |
| 376 | return true; |
| 377 | } |
| 378 | return $value; |
| 379 | } |
| 380 | |