should_offer() || get_option( 'pingpush_import_notice_dismissed' ) ) {
return false;
}
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
return $screen && in_array( $screen->id, array( 'dashboard', 'plugins' ), true );
}
/**
* Make the notice's X button remember the dismissal (same as the "Dismiss" link).
*/
public function notice_script() {
if ( ! $this->show_notice() ) {
return;
}
wp_add_inline_script(
'common',
"document.addEventListener('click',function(e){var b=e.target.closest('.pingpush-import-notice .notice-dismiss');if(!b){return;}var n=b.closest('.pingpush-import-notice');if(n&&n.dataset.dismissUrl){fetch(n.dataset.dismissUrl,{credentials:'same-origin'});}});"
);
}
/**
* One-time admin notice on Dashboard and Plugins screens.
*/
public function notice() {
if ( ! $this->show_notice() ) {
return;
}
$dismiss = wp_nonce_url( admin_url( 'admin-post.php?action=pingpush_import_dismiss' ), 'pingpush_import_dismiss' );
?>
should_offer() ) {
return;
}
?>
$on( 'new_user' ),
'core_post_published' => $on( 'new_post' ),
'core_new_comment' => $on( 'new_comment' ),
'core_password_reset' => $on( 'password_reset' ),
'core_updates' => $on( 'core_update' ) || $on( 'plugin_updates' ),
);
$events = is_array( $current['events'] ?? null ) ? $current['events'] : array();
foreach ( $map as $id => $enabled ) {
if ( ! PingPush_Events::get( $id ) ) {
continue;
}
$row = array_merge( PingPush_Events::settings_for( $id ), $events[ $id ] ?? array() );
$row['enabled'] = $enabled ? 1 : 0;
if ( 'core_updates' === $id && $enabled ) {
$types = array();
if ( $on( 'core_update' ) ) {
$types[] = 'core';
}
if ( $on( 'plugin_updates' ) ) {
$types[] = 'plugins';
$types[] = 'themes';
}
$row['types'] = $types;
}
$events[ $id ] = $row;
}
$current['events'] = $events;
return $current;
}
/**
* Import handler.
*/
public function handle_import() {
check_admin_referer( 'pingpush_import' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to do this.', 'pingpush' ), 403 );
}
$old = self::old_settings();
if ( $old ) {
$current = PingPush_Settings::get();
// Fill every registered event so the sanitizer keeps their current state.
foreach ( PingPush_Events::all() as $id => $def ) {
if ( 'custom' !== $def['source'] && ! isset( $current['events'][ $id ] ) ) {
$current['events'][ $id ] = PingPush_Events::settings_for( $id );
}
}
update_option( PINGPUSH_OPTION, self::map( $old, $current ), false );
update_option( 'pingpush_import_done', time(), false );
}
PingPush_Settings::flash( __( 'Settings imported. Check the keys with "Validate keys", then deactivate the old plugin so you do not get duplicate alerts.', 'pingpush' ) );
wp_safe_redirect( PingPush_Settings::url() );
exit;
}
/**
* Dismiss the notice.
*/
public function handle_dismiss() {
check_admin_referer( 'pingpush_import_dismiss' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to do this.', 'pingpush' ), 403 );
}
update_option( 'pingpush_import_notice_dismissed', 1, false );
wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url() );
exit;
}
}