Skip to content

Commit

Permalink
change: use function to regiter deaactivatin modal
Browse files Browse the repository at this point in the history
  • Loading branch information
10upbot on GitHub committed Jan 15, 2024
1 parent d10a2f7 commit 38c8d15
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions includes/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,35 +223,33 @@ function() {
*
* @since x.x.x
*/
add_action(
'load-plugins.php',
static function() {
// Exit if deactivating plugin from sub site.
$screen = get_current_screen();
if ( ! ( ! is_multisite() || $screen->in_admin( 'network' ) ) ) {
return;
}
function register_deactivation_modal() {
// Exit if deactivating plugin from sub site.
$screen = get_current_screen();
if ( ! ( ! is_multisite() || $screen->in_admin( 'network' ) ) ) {
return;
}

wp_enqueue_script( 'jquery-ui-dialog' );
wp_enqueue_style( 'wp-jquery-ui-dialog' );
wp_enqueue_script( 'jquery-ui-dialog' );
wp_enqueue_style( 'wp-jquery-ui-dialog' );

add_action(
'admin_footer',
static function () {
printf(
'<div id="my-modal" style="display:none;"><p>%1$s</p><p>%2$s</p><p><code>%3$s</code></p><p>%4$s</p></div>',
esc_html__( 'Would you like to delete all Distributor data?', 'distributor' ),
esc_html__( 'By default the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well check, add below code to wp-config.php .', 'distributor' ),
'define(\'DT_REMOVE_ALL_DATA\', true)',
esc_html__( 'After adding this code, the Distributor plugin data will be removed from the main website database when deleting the plugin. You can review uninstall.php (in the plugin root directory) to learn more about deleted data. After deleting the Distributor plugin, you can remove the code.', 'distributor' )
);
}
);
add_action(
'admin_footer',
static function () {
printf(
'<div id="my-modal" style="display:none;"><p>%1$s</p><p>%2$s</p><p><code>%3$s</code></p><p>%4$s</p></div>',
esc_html__( 'Would you like to delete all Distributor data?', 'distributor' ),
esc_html__( 'By default the database entries are not deleted when you deactivate Distributor. If you are deleting Distributor completely from your website and want those items removed as well check, add below code to wp-config.php .', 'distributor' ),
'define(\'DT_REMOVE_ALL_DATA\', true)',
esc_html__( 'After adding this code, the Distributor plugin data will be removed from the main website database when deleting the plugin. You can review uninstall.php (in the plugin root directory) to learn more about deleted data. After deleting the Distributor plugin, you can remove the code.', 'distributor' )
);
}
);

$modal_title = esc_js( esc_html__( 'Distributor Deactivation', 'distributor' ) );
$modal_button_title_deactivate = esc_js( esc_html__( 'Deactivate', 'distributor' ) );
$modal_button_title_cancel = esc_js( esc_html__( 'Cancel', 'distributor' ) );
$script = <<<EOD
$modal_title = esc_js( esc_html__( 'Distributor Deactivation', 'distributor' ) );
$modal_button_title_deactivate = esc_js( esc_html__( 'Deactivate', 'distributor' ) );
$modal_button_title_cancel = esc_js( esc_html__( 'Cancel', 'distributor' ) );
$script = <<<EOD
jQuery(document).ready(function($) {
const deactivateButton = jQuery('#deactivate-distributor');
deactivateButton.on( 'click', function() {
Expand Down Expand Up @@ -284,9 +282,9 @@ class: 'button-primary',
});
EOD;

wp_add_inline_script( 'jquery-ui-dialog', $script );
}
);
wp_add_inline_script( 'jquery-ui-dialog', $script );
}
add_action( 'load-plugins.php', __NAMESPACE__ . '\register_deactivation_modal' );

/**
* We use setup functions to avoid unit testing WP_Mock strict mode errors.
Expand Down

0 comments on commit 38c8d15

Please sign in to comment.