get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name = %s", ASENHA_SLUG_U ) );
if ( !$asenha_exists_in_db ) {
add_option(
ASENHA_SLUG_U,
array(),
'',
true
);
} else {
// Option exists in DB but cache returned false (stale persistent cache).
// Aggressively invalidate all cache layers including local in-process caches
// that some Redis/Memcached backends maintain separately from the external store.
wp_cache_delete( 'alloptions', 'options' );
wp_cache_delete( 'notoptions', 'options' );
if ( function_exists( 'wp_cache_flush' ) ) {
wp_cache_flush();
}
global $wp_object_cache;
if ( is_object( $wp_object_cache ) ) {
if ( property_exists( $wp_object_cache, 'local_cache' ) && is_array( $wp_object_cache->local_cache ) ) {
unset($wp_object_cache->local_cache['options']);
}
if ( property_exists( $wp_object_cache, 'cache' ) && is_array( $wp_object_cache->cache ) ) {
unset($wp_object_cache->cache['options']);
}
}
}
}
if ( false === get_option( ASENHA_SLUG_U . '_stats' ) ) {
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$asenha_stats_exists_in_db = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name = %s", ASENHA_SLUG_U . '_stats' ) );
if ( !$asenha_stats_exists_in_db ) {
add_option(
ASENHA_SLUG_U . '_stats',
array(),
'',
false
);
} else {
// Option exists in DB but cache returned false (stale persistent cache).
// Aggressively invalidate all cache layers including local in-process caches.
wp_cache_delete( 'alloptions', 'options' );
wp_cache_delete( 'notoptions', 'options' );
if ( function_exists( 'wp_cache_flush' ) ) {
wp_cache_flush();
}
global $wp_object_cache;
if ( is_object( $wp_object_cache ) ) {
if ( property_exists( $wp_object_cache, 'local_cache' ) && is_array( $wp_object_cache->local_cache ) ) {
unset($wp_object_cache->local_cache['options']);
}
if ( property_exists( $wp_object_cache, 'cache' ) && is_array( $wp_object_cache->cache ) ) {
unset($wp_object_cache->cache['options']);
}
}
}
}
if ( false === get_option( ASENHA_SLUG_U . '_extra' ) ) {
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$asenha_extra_exists_in_db = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name = %s", ASENHA_SLUG_U . '_extra' ) );
if ( !$asenha_extra_exists_in_db ) {
add_option(
ASENHA_SLUG_U . '_extra',
array(),
'',
true
);
} else {
// Option exists in DB but cache returned false (stale persistent cache).
// Aggressively invalidate all cache layers including local in-process caches.
wp_cache_delete( 'alloptions', 'options' );
wp_cache_delete( 'notoptions', 'options' );
if ( function_exists( 'wp_cache_flush' ) ) {
wp_cache_flush();
}
global $wp_object_cache;
if ( is_object( $wp_object_cache ) ) {
if ( property_exists( $wp_object_cache, 'local_cache' ) && is_array( $wp_object_cache->local_cache ) ) {
unset($wp_object_cache->local_cache['options']);
}
if ( property_exists( $wp_object_cache, 'cache' ) && is_array( $wp_object_cache->cache ) ) {
unset($wp_object_cache->cache['options']);
}
}
}
}
// Bugfix in v7.1.2 for Custom Content Type module
$options_extra = asenha_get_option_array( ASENHA_SLUG_U . '_extra', true );
if ( !isset( $options_extra['cfgroup_next_field_id'] ) ) {
$options_extra['cfgroup_next_field_id'] = 1;
update_option( ASENHA_SLUG_U . '_extra', $options_extra, true );
}
// Move Admin Menu Organizer options storage to extra table since v7.8.5
if ( !isset( $options_extra['admin_menu'] ) ) {
$options = asenha_get_option_array( ASENHA_SLUG_U, true );
$options_extra['admin_menu']['custom_menu_order'] = ( isset( $options['custom_menu_order'] ) ? $options['custom_menu_order'] : '' );
unset($options['custom_menu_order']);
$options_extra['admin_menu']['custom_menu_titles'] = ( isset( $options['custom_menu_titles'] ) ? $options['custom_menu_titles'] : '' );
unset($options['custom_menu_titles']);
$options_extra['admin_menu']['custom_menu_hidden'] = ( isset( $options['custom_menu_hidden'] ) ? trim( $options['custom_menu_hidden'], ',' ) : '' );
unset($options['custom_menu_hidden']);
update_option( ASENHA_SLUG_U . '_extra', $options_extra, true );
update_option( ASENHA_SLUG_U, $options, true );
}
/**
* Get the SMTP password storage status with backward-compatible fallbacks.
*
* This avoids fatal errors during mixed-version deployments where newer
* settings code may temporarily run against an older Email_Delivery class
* definition that does not yet provide the newer helper method/constants.
*
* @since 8.5.1
*
* @param string|null $stored_password Stored option value.
* @return string
*/
function asenha_get_smtp_password_status_compat( $stored_password = null ) {
if ( null === $stored_password ) {
$options = asenha_get_option_array( ASENHA_SLUG_U, true );
$stored_password = ( isset( $options['smtp_password'] ) ? $options['smtp_password'] : '' );
}
$email_delivery = new \ASENHA\Classes\Email_Delivery();
if ( method_exists( $email_delivery, 'get_smtp_password_status' ) ) {
return $email_delivery->get_smtp_password_status( $stored_password );
}
if ( empty( $stored_password ) ) {
return 'empty';
}
if ( is_string( $stored_password ) && (0 === strpos( $stored_password, 'asenha_encrypted::smtp_password::v1::' ) || 0 === strpos( $stored_password, 'asenha_encrypted::smtp_password::v2::' )) ) {
return 'encrypted_invalid';
}
if ( is_string( $stored_password ) && 0 === strpos( $stored_password, 'asenha_encrypted::smtp_password::' ) ) {
return 'encrypted_invalid';
}
return 'legacy_plaintext';
}
/**
* Encrypt the SMTP password when the runtime supports the newer helper.
*
* @since 8.5.1
*
* @param \ASENHA\Classes\Email_Delivery $email_delivery Email delivery instance.
* @param string $password Plaintext SMTP password.
* @return string Encrypted payload or empty string when unsupported.
*/
function asenha_encrypt_smtp_password_compat( $email_delivery, $password ) {
if ( !method_exists( $email_delivery, 'encrypt_smtp_password' ) ) {
return '';
}
return $email_delivery->encrypt_smtp_password( $password );
}
/**
* Migrate SMTP password storage to the current encrypted format.
*
* Upgrades legacy plaintext and decryptable v1 ciphertext to v2 automatically.
*
* @since 8.5.1
*/
function asenha_migrate_smtp_password_storage() {
$options = asenha_get_option_array( ASENHA_SLUG_U, true );
if ( empty( $options['smtp_password'] ) ) {
return;
}
$email_delivery = new \ASENHA\Classes\Email_Delivery();
$stored_password = $options['smtp_password'];
if ( method_exists( $email_delivery, 'is_smtp_password_storage_version_v2' ) && $email_delivery->is_smtp_password_storage_version_v2() && method_exists( $email_delivery, 'is_smtp_password_v2_encrypted' ) && $email_delivery->is_smtp_password_v2_encrypted( $stored_password ) ) {
return;
}
$updated = false;
if ( method_exists( $email_delivery, 'is_smtp_password_v2_encrypted' ) && $email_delivery->is_smtp_password_v2_encrypted( $stored_password ) ) {
$plaintext_password = ( method_exists( $email_delivery, 'unwrap_smtp_password_to_plaintext' ) ? $email_delivery->unwrap_smtp_password_to_plaintext( $stored_password ) : false );
if ( false !== $plaintext_password && method_exists( $email_delivery, 'is_probable_smtp_ciphertext' ) && !$email_delivery->is_probable_smtp_ciphertext( $plaintext_password ) ) {
$email_delivery->mark_smtp_password_storage_version_v2();
return;
}
if ( false === $plaintext_password || method_exists( $email_delivery, 'is_probable_smtp_ciphertext' ) && $email_delivery->is_probable_smtp_ciphertext( $plaintext_password ) ) {
$email_delivery->set_smtp_password_unavailable_flag();
return;
}
} elseif ( method_exists( $email_delivery, 'is_smtp_password_v1_encrypted' ) && $email_delivery->is_smtp_password_v1_encrypted( $stored_password ) ) {
$plaintext_password = $email_delivery->decrypt_smtp_password( $stored_password );
if ( false !== $plaintext_password && method_exists( $email_delivery, 'is_probable_smtp_ciphertext' ) && !$email_delivery->is_probable_smtp_ciphertext( $plaintext_password ) ) {
$encrypted_smtp_password = asenha_encrypt_smtp_password_compat( $email_delivery, $plaintext_password );
if ( !empty( $encrypted_smtp_password ) ) {
$options['smtp_password'] = $encrypted_smtp_password;
$updated = true;
}
} elseif ( false !== $plaintext_password && method_exists( $email_delivery, 'is_probable_smtp_ciphertext' ) && $email_delivery->is_probable_smtp_ciphertext( $plaintext_password ) ) {
$email_delivery->set_smtp_password_unavailable_flag();
return;
}
} elseif ( method_exists( $email_delivery, 'is_probable_smtp_ciphertext' ) && $email_delivery->is_probable_smtp_ciphertext( $stored_password ) ) {
$email_delivery->set_smtp_password_unavailable_flag();
return;
} else {
$encrypted_smtp_password = asenha_encrypt_smtp_password_compat( $email_delivery, $stored_password );
if ( !empty( $encrypted_smtp_password ) ) {
$options['smtp_password'] = $encrypted_smtp_password;
$updated = true;
}
}
if ( $updated ) {
update_option( ASENHA_SLUG_U, $options, true );
if ( method_exists( $email_delivery, 'mark_smtp_password_storage_version_v2' ) ) {
$email_delivery->mark_smtp_password_storage_version_v2();
}
}
}
/**
* Repair nested SMTP password storage after migration.
*
* @since 8.8.6
*/
function asenha_repair_nested_smtp_password_storage() {
$email_delivery = new \ASENHA\Classes\Email_Delivery();
if ( method_exists( $email_delivery, 'repair_nested_smtp_password_storage' ) ) {
$email_delivery->repair_nested_smtp_password_storage();
}
}
/**
* Run SMTP password storage migration and nested repair.
*
* @since 8.8.6
*/
function asenha_run_smtp_password_storage_upgrades() {
asenha_migrate_smtp_password_storage();
asenha_repair_nested_smtp_password_storage();
}
if ( did_action( 'plugins_loaded' ) ) {
asenha_run_smtp_password_storage_upgrades();
} else {
add_action( 'plugins_loaded', 'asenha_run_smtp_password_storage_upgrades' );
}
/**
* Register admin menu
*
* @since 1.0.0
*/
function asenha_register_admin_menu() {
add_submenu_page(
'tools.php',
// Parent page/menu
'Admin and Site Enhancements',
// Browser tab/window title
__( 'Enhancements', 'admin-site-enhancements' ),
// Sube menu title
'manage_options',
// Minimal user capabililty
ASENHA_SLUG,
// Page slug. Shows up in URL.
'asenha_add_settings_page'
);
}
/**
* Create the settings page of the plugin
*
* @since 1.0.0
*/
function asenha_add_settings_page() {
$options = asenha_get_option_array( ASENHA_SLUG_U, true );
?>
providing feedback.', 'admin-site-enhancements' );
?>
translate to your language.', 'admin-site-enhancements' );
?>
ASE Pro. Lifetime deal (LTD)
available.', 'admin-site-enhancements' );
?> 20% discount.', 'admin-site-enhancements' );
}
?>
= 10 ) {
$is_yearend_promo_period = true;
// Clear out last year's promo nudge dismissal data
$current_year = date( 'Y', time() );
$asenha_stats = asenha_get_option_array( ASENHA_SLUG_U . '_stats', false );
if ( isset( $asenha_stats['promo_nudge_dismissed'] ) && $asenha_stats['promo_nudge_dismissed'] ) {
$last_dismissed_year = date( 'Y', strtotime( $asenha_stats['promo_nudge_dismissed_date'] ) );
if ( $current_year > $last_dismissed_year ) {
$asenha_stats['promo_nudge_dismissed'] = false;
$asenha_stats['promo_nudge_dismissed_date'] = '';
update_option( ASENHA_SLUG_U . '_stats', $asenha_stats, false );
}
}
} else {
$is_yearend_promo_period = false;
}
// For year end promo between November 15 to December 31
// $tz = wp_timezone(); // WordPress timezone; or: new DateTimeZone('UTC')
// $current_date = new DateTimeImmutable('now', $tz);
// // $current_date = new DateTimeImmutable('2025-11-15', $tz); // For testing
// // $current_date = new DateTimeImmutable('2026-01-01', $tz); // For testing
// // $current_date = new DateTimeImmutable('2027-11-15', $tz); // For testing
// $year = (int) $current_date->format('Y');
// $start = new DateTimeImmutable("$year-11-15 00:00:00", $tz);
// $end = new DateTimeImmutable("$year-12-31 23:59:59", $tz);
// $is_between = ($current_date >= $start && $current_date <= $end);
// if ( $is_between ) {
// $is_yearend_promo_period = true;
// } else {
// $is_yearend_promo_period = false;
// }
// // Clear out last year's promo nudge dismissal data
// if ( $is_yearend_promo_period ) {
// $current_year = $year;
// $asenha_stats = get_option( ASENHA_SLUG_U . '_stats', array() );
// if ( isset( $asenha_stats['promo_nudge_dismissed'] ) && $asenha_stats['promo_nudge_dismissed'] ) {
// $last_dismissed_year = date( 'Y', strtotime( $asenha_stats['promo_nudge_dismissed_date'] ) );
// if ( $current_year > $last_dismissed_year ) {
// $asenha_stats['promo_nudge_dismissed'] = false;
// $asenha_stats['promo_nudge_dismissed_date'] = '';
// update_option( ASENHA_SLUG_U . '_stats', $asenha_stats, false );
// }
// }
// }
return $is_yearend_promo_period;
}
/**
* Suppress all notices, then add notice for successful settings update
*
* @since 1.1.0
*/
function asenha_suppress_add_notices() {
global $plugin_page;
// Suppress all notices
if ( ASENHA_SLUG === $plugin_page ) {
remove_all_actions( 'admin_notices' );
}
// Add notice for successful settings update
if ( isset( $_GET['page'] ) && ASENHA_SLUG == $_GET['page'] && isset( $_GET['settings-updated'] ) && true == $_GET['settings-updated'] ) {
?>
> Enable Custom Admin / Frontend CSS / ads.txt / app-ads.txt
wp_enqueue_style(
'asenha-codemirror',
ASENHA_URL . 'assets/css/codemirror/codemirror.min.css',
array(),
ASENHA_VERSION
);
wp_enqueue_script(
'asenha-codemirror',
ASENHA_URL . 'assets/js/codemirror/codemirror.min.js',
array('jquery'),
ASENHA_VERSION,
true
);
wp_enqueue_script(
'asenha-codemirror-htmlmixed-mode',
ASENHA_URL . 'assets/js/codemirror/htmlmixed.js',
array('asenha-codemirror'),
ASENHA_VERSION,
true
);
wp_enqueue_script(
'asenha-codemirror-xml-mode',
ASENHA_URL . 'assets/js/codemirror/xml.js',
array('asenha-codemirror'),
ASENHA_VERSION,
true
);
wp_enqueue_script(
'asenha-codemirror-javascript-mode',
ASENHA_URL . 'assets/js/codemirror/javascript.js',
array('asenha-codemirror'),
ASENHA_VERSION,
true
);
wp_enqueue_script(
'asenha-codemirror-css-mode',
ASENHA_URL . 'assets/js/codemirror/css.js',
array('asenha-codemirror'),
ASENHA_VERSION,
true
);
wp_enqueue_script(
'asenha-codemirror-markdown-mode',
ASENHA_URL . 'assets/js/codemirror/markdown.js',
array('asenha-codemirror'),
ASENHA_VERSION,
true
);
// DataTables. In use, e.g. for Security >> Limit Login Attempts
wp_enqueue_style(
'asenha-datatables',
ASENHA_URL . 'assets/css/datatables/datatables.min.css',
array(),
ASENHA_VERSION
);
wp_enqueue_script(
'asenha-datatables',
ASENHA_URL . 'assets/js/datatables/datatables.min.js',
array('jquery'),
ASENHA_VERSION,
false
);
// Add WP media library assets
wp_enqueue_media();
// Add WP color picker assets
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
// We force loading the uncompressed version of TinyMCE. This ensures we load 'wp-tinymce-root' and then 'wp-tinymce',
// which prevents issue where the Visual tab is unusable in some scenarios
$wp_scripts = wp_scripts();
$wp_scripts->remove( 'wp-tinymce' );
wp_register_tinymce_scripts( $wp_scripts, true );
$admin_page_script_dependencies = array(
'asenha-jsticky',
'asenha-jbox',
'asenha-js-cookie',
'asenha-codemirror-htmlmixed-mode',
'asenha-codemirror-xml-mode',
'asenha-codemirror-javascript-mode',
'asenha-codemirror-css-mode',
'asenha-codemirror-markdown-mode',
'asenha-datatables',
'wp-color-picker',
'wp-mediaelement',
'wp-tinymce-root',
'wp-tinymce'
);
// Main style and script for the admin page
wp_enqueue_style(
'asenha-admin-page',
ASENHA_URL . 'assets/css/admin-page.css',
array(
'asenha-jbox',
'asenha-codemirror',
'asenha-datatables',
'wp-color-picker'
),
ASENHA_VERSION
);
wp_enqueue_script(
'asenha-admin-page',
ASENHA_URL . 'assets/js/admin-page.js',
$admin_page_script_dependencies,
ASENHA_VERSION,
false
);
$jsvars = array(
'nonce' => wp_create_nonce( 'asenha-' . get_current_user_id() ),
'siteUrl' => get_site_url(),
'wpcontentUrl' => content_url(),
'mediaFrameTitle' => __( 'Select an Image', 'admin-site-enhancements' ),
'mediaFrameButtonText' => __( 'Use Selected Image', 'admin-site-enhancements' ),
'resetMenuNonce' => wp_create_nonce( 'reset-menu-nonce' ),
'sendTestEmailNonce' => wp_create_nonce( 'send-test-email-nonce_' . get_current_user_id() ),
'formBuilderSendTestEmailNonce' => wp_create_nonce( 'formbuilder_ajax' ),
'expandText' => __( 'Expand', 'admin-site-enhancements' ),
'collapseText' => __( 'Collapse', 'admin-site-enhancements' ),
'dataTable' => array(
'emptyTable' => __( 'No data available in table', 'admin-site-enhancements' ),
'info' => __( 'Showing _START_ to _END_ of _TOTAL_ entries', 'admin-site-enhancements' ),
'infoEmpty' => __( 'Showing 0 to 0 of 0 entries', 'admin-site-enhancements' ),
'infoFiltered' => __( '(filtered from _MAX_ total entries)', 'admin-site-enhancements' ),
'lengthMenu' => __( 'Show _MENU_ entries', 'admin-site-enhancements' ),
'search' => __( 'Search:', 'admin-site-enhancements' ),
'zeroRecords' => __( 'No matching records found', 'admin-site-enhancements' ),
'paginate' => array(
'first' => __( 'First', 'admin-site-enhancements' ),
'last' => __( 'Last', 'admin-site-enhancements' ),
'next' => __( 'Next', 'admin-site-enhancements' ),
'previous' => __( 'Previous', 'admin-site-enhancements' ),
),
),
'limitLoginAttempts' => array(
'releaseLockSuccess' => __( 'Lock released for %s.', 'admin-site-enhancements' ),
'releaseLockError' => __( 'Could not release lock. Please try again.', 'admin-site-enhancements' ),
),
);
wp_localize_script( 'asenha-admin-page', 'adminPageVars', $jsvars );
}
// Enqueue on all wp-admin
wp_enqueue_style(
'asenha-wp-admin',
ASENHA_URL . 'assets/css/wp-admin.css',
array(),
ASENHA_VERSION
);
// Content Management >> Show IDs, for list tables in wp-admin, e.g. All Posts page
if ( false !== strpos( $current_screen->base, 'edit' ) || false !== strpos( $current_screen->base, 'users' ) || false !== strpos( $current_screen->base, 'upload' ) ) {
wp_enqueue_style(
'asenha-list-table',
ASENHA_URL . 'assets/css/list-table.css',
array(),
ASENHA_VERSION
);
}
// Content Management >> Enable Media Replacement
if ( $current_screen->base == 'upload' || $current_screen->id == 'attachment' ) {
// wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION );
// wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false );
wp_enqueue_media();
wp_enqueue_style(
'asenha-media-replace',
ASENHA_URL . 'assets/css/media-replace.css',
array(),
ASENHA_VERSION
);
wp_enqueue_script(
'asenha-media-replace',
ASENHA_URL . 'assets/js/media-replace.js',
array('media-editor'),
ASENHA_VERSION,
false
);
$media_replace = array(
'selectMediaText' => __( 'Select New Media File', 'admin-site-enhancements' ),
'performReplacementText' => __( 'Perform Replacement', 'admin-site-enhancements' ),
);
wp_localize_script( 'asenha-media-replace', 'mediaReplace', $media_replace );
}
// Admin Interface >> Admin Menu Organizer
if ( 'settings_page_admin-menu-organizer' == $current_screen->base ) {
// Re-register and re-enqueue jQuery UI Core and plugins required for sortable, draggable and droppable when ordering menu items
wp_deregister_script( 'jquery-ui-core' );
wp_register_script(
'jquery-ui-core',
get_site_url() . '/wp-includes/js/jquery/ui/core.min.js',
array('jquery'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-core' );
if ( version_compare( $wp_version, '5.6.0', '>=' ) ) {
wp_deregister_script( 'jquery-ui-mouse' );
wp_register_script(
'jquery-ui-mouse',
get_site_url() . '/wp-includes/js/jquery/ui/mouse.min.js',
array('jquery-ui-core'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-mouse' );
} else {
wp_deregister_script( 'jquery-ui-widget' );
wp_register_script(
'jquery-ui-widget',
get_site_url() . '/wp-includes/js/jquery/ui/widget.min.js',
array('jquery'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-widget' );
wp_deregister_script( 'jquery-ui-mouse' );
wp_register_script(
'jquery-ui-mouse',
get_site_url() . '/wp-includes/js/jquery/ui/mouse.min.js',
array('jquery-ui-core', 'jquery-ui-widget'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-mouse' );
}
wp_deregister_script( 'jquery-ui-sortable' );
wp_register_script(
'jquery-ui-sortable',
get_site_url() . '/wp-includes/js/jquery/ui/sortable.min.js',
array('jquery-ui-mouse'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-sortable' );
wp_deregister_script( 'jquery-ui-draggable' );
wp_register_script(
'jquery-ui-draggable',
get_site_url() . '/wp-includes/js/jquery/ui/draggable.min.js',
array('jquery-ui-mouse'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-draggable' );
wp_deregister_script( 'jquery-ui-droppable' );
wp_register_script(
'jquery-ui-droppable',
get_site_url() . '/wp-includes/js/jquery/ui/droppable.min.js',
array('jquery-ui-draggable'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-droppable' );
// Script to set behaviour and actions of the sortable menu
wp_enqueue_script(
'asenha-custom-admin-menu',
ASENHA_URL . 'assets/js/custom-admin-menu.js',
array('jquery-ui-draggable'),
ASENHA_VERSION,
false
);
wp_enqueue_style(
'asenha-admin-menu-organizer',
ASENHA_URL . 'assets/css/admin-menu-organizer.css',
array(),
ASENHA_VERSION
);
wp_enqueue_script(
'asenha-admin-menu-organizer',
ASENHA_URL . 'assets/js/admin-menu-organizer.js',
array('asenha-custom-admin-menu'),
ASENHA_VERSION,
false
);
$amo_page_vars = array(
'saveMenuNonce' => wp_create_nonce( 'save-menu-nonce' ),
'strings' => array(
'saveChangesError' => __( 'Unable to save changes. Please reload the page and try again.', 'admin-site-enhancements' ),
),
);
wp_localize_script( 'asenha-custom-admin-menu', 'amoPageVars', $amo_page_vars );
}
// Admin Interface >> Admin Bar Custom Elements (Pro)
if ( $current_screen && 'settings_page_asenha-admin-bar' === $current_screen->base ) {
wp_deregister_script( 'jquery-ui-core' );
wp_register_script(
'jquery-ui-core',
get_site_url() . '/wp-includes/js/jquery/ui/core.min.js',
array('jquery'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-core' );
if ( version_compare( $wp_version, '5.6.0', '>=' ) ) {
wp_deregister_script( 'jquery-ui-mouse' );
wp_register_script(
'jquery-ui-mouse',
get_site_url() . '/wp-includes/js/jquery/ui/mouse.min.js',
array('jquery-ui-core'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-mouse' );
} else {
wp_deregister_script( 'jquery-ui-widget' );
wp_register_script(
'jquery-ui-widget',
get_site_url() . '/wp-includes/js/jquery/ui/widget.min.js',
array('jquery'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-widget' );
wp_deregister_script( 'jquery-ui-mouse' );
wp_register_script(
'jquery-ui-mouse',
get_site_url() . '/wp-includes/js/jquery/ui/mouse.min.js',
array('jquery-ui-core', 'jquery-ui-widget'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-mouse' );
}
wp_deregister_script( 'jquery-ui-sortable' );
wp_register_script(
'jquery-ui-sortable',
get_site_url() . '/wp-includes/js/jquery/ui/sortable.min.js',
array('jquery-ui-mouse'),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_style(
'asenha-admin-bar-custom-elements',
ASENHA_URL . 'assets/premium/css/admin-bar-custom-elements.css',
array(),
ASENHA_VERSION
);
wp_enqueue_script(
'asenha-admin-bar-custom-elements',
ASENHA_URL . 'assets/premium/js/admin-bar-custom-elements.js',
array('jquery-ui-sortable'),
ASENHA_VERSION,
false
);
}
// Utilities >> Email Delivery Log
if ( 'tools_page_email-delivery-log' == $hook_suffix ) {
wp_enqueue_style( 'jquery-ui-css', ASENHA_URL . 'assets/premium/css/jquery-ui/jquery-ui.min.css' );
wp_enqueue_style( 'asenha-email-delivery-log', ASENHA_URL . 'assets/premium/css/email-delivery-log.css' );
wp_enqueue_script( 'jquery-ui' );
// wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'jquery-ui-tabs' );
wp_enqueue_script( 'asenha-email-delivery-log', ASENHA_URL . 'assets/premium/js/email-delivery-log.js' );
$nonce = wp_create_nonce( 'email-delivery-log' . get_current_user_id() );
wp_localize_script( 'asenha-email-delivery-log', 'emailLog', array(
'nonce' => $nonce,
) );
}
// Utilities >> Image Sizes Panel∂
if ( 'post' == $current_screen->base && 'attachment' == $current_screen->id ) {
global $post;
// Only enqueue if the attachment is an image
if ( property_exists( $post, 'post_mime_type' ) && false !== strpos( $post->post_mime_type, 'image' ) ) {
wp_enqueue_style( 'asenha-image-sizes-panel', ASENHA_URL . 'assets/css/image-sizes-panel.css' );
}
}
// Code Snippets Manager
if ( 'post' == $current_screen->base && 'asenha_code_snippet' == $current_screen->id || 'edit' == $current_screen->base && 'edit-asenha_code_snippet' == $current_screen->id ) {
}
// Content Management >> Hide Admin Notices
if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) {
$hide_for_nonadmins = ( isset( $options['hide_admin_notices_for_nonadmins'] ) ? $options['hide_admin_notices_for_nonadmins'] : false );
$minimum_capability = 'manage_options';
if ( current_user_can( $minimum_capability ) ) {
wp_enqueue_style(
'asenha-jbox',
ASENHA_URL . 'assets/css/jBox.all.min.css',
array(),
ASENHA_VERSION
);
wp_enqueue_script(
'asenha-jbox',
ASENHA_URL . 'assets/js/jBox.all.min.js',
array(),
ASENHA_VERSION,
false
);
wp_enqueue_style(
'asenha-hide-admin-notices',
ASENHA_URL . 'assets/css/hide-admin-notices.css',
array(),
ASENHA_VERSION
);
wp_enqueue_script(
'asenha-hide-admin-notices',
ASENHA_URL . 'assets/js/hide-admin-notices.js',
array('asenha-jbox'),
ASENHA_VERSION,
false
);
}
}
if ( array_key_exists( 'disable_user_account', $options ) && $options['disable_user_account'] && 'users.php' === $pagenow ) {
wp_enqueue_script(
'asenha-disable-user-account',
ASENHA_URL . 'assets/js/disable-user-account.js',
array('jquery'),
ASENHA_VERSION,
true
);
wp_localize_script( 'asenha-disable-user-account', 'asenhaDisableUserAccount', array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'asenha_user_account_toggle' ),
) );
}
// Utilities >> Multiple User Roles
if ( array_key_exists( 'multiple_user_roles', $options ) && $options['multiple_user_roles'] ) {
if ( 'user-edit.php' == $hook_suffix || 'user-new.php' == $hook_suffix ) {
// Only replace roles dropdown with checkboxes for users that can assign roles to other users, e.g. administrators
if ( current_user_can( 'promote_users', get_current_user_id() ) ) {
wp_enqueue_script(
'asenha-multiple-user-roles',
ASENHA_URL . 'assets/js/multiple-user-roles.js',
array('jquery'),
ASENHA_VERSION,
false
);
}
}
}
$asenha_stats = asenha_get_option_array( ASENHA_SLUG_U . '_stats', false );
$hide_promo_nudge = false;
$is_yearend_promo_period = is_yearend_promo_period();
// Pass on ASENHA stats to admin-page.js to determine whether to show support nudge
$current_date = date( 'Y-m-d', time() );
$show_support_nudge = false;
$asenha_stats_localized = array(
'firstSaveDate' => '',
'lastSaveDate' => '',
'saveCount' => 0,
'hideUpgradeNudge' => false,
'hidePromoNudge' => false,
'showSupportNudge' => false,
);
if ( !empty( $asenha_stats ) ) {
$hide_upgrade_nudge = ( isset( $asenha_stats['upgrade_nudge_dismissed'] ) ? $asenha_stats['upgrade_nudge_dismissed'] : false );
$hide_promo_nudge = ( isset( $asenha_stats['promo_nudge_dismissed'] ) ? $asenha_stats['promo_nudge_dismissed'] : false );
$have_supported = ( isset( $asenha_stats['have_supported'] ) ? $asenha_stats['have_supported'] : false );
$changes_saved = ( isset( $_GET['settings-updated'] ) && 'true' == sanitize_text_field( $_GET['settings-updated'] ) ? true : false );
$save_count = ( isset( $asenha_stats['save_count'] ) ? $asenha_stats['save_count'] : 0 );
// Compensate for redirect from settings-updated=true URL
if ( $changes_saved ) {
$save_count = $save_count + 1;
} else {
$save_count = $save_count;
}
$saves_to_nudge_support = 10;
if ( $save_count < $saves_to_nudge_support ) {
$save_count_modulo = -1;
} else {
$save_count_modulo = $save_count % $saves_to_nudge_support;
}
// User have not supported ASE
if ( false === $have_supported ) {
// Support nudge have not been dismissed
if ( isset( $asenha_stats['support_nudge_dismissed'] ) && false === $asenha_stats['support_nudge_dismissed'] ) {
// Show support nudge after every x saves
if ( $save_count_modulo >= 0 ) {
$show_support_nudge = true;
} else {
$show_support_nudge = false;
}
if ( $show_support_nudge && $save_count_modulo >= 0 ) {
$asenha_stats['support_nudge_last_shown_date'] = $current_date;
$asenha_stats['support_nudge_last_shown_save_count'] = $save_count;
update_option( ASENHA_SLUG_U . '_stats', $asenha_stats, false );
}
} else {
if ( $save_count_modulo == 0 ) {
$support_nudge_last_shown_save_count = ( isset( $asenha_stats['support_nudge_last_shown_save_count'] ) ? $asenha_stats['support_nudge_last_shown_save_count'] : 0 );
if ( $save_count > $support_nudge_last_shown_save_count ) {
$asenha_stats['support_nudge_dismissed'] = false;
update_option( ASENHA_SLUG_U . '_stats', $asenha_stats, false );
$show_support_nudge = true;
} else {
$show_support_nudge = false;
}
} else {
$show_support_nudge = false;
}
}
}
$first_save_date = ( isset( $asenha_stats['first_save_date'] ) ? $asenha_stats['first_save_date'] : '' );
$last_save_date = ( isset( $asenha_stats['last_save_date'] ) ? $asenha_stats['last_save_date'] : '' );
$asenha_stats_localized = array(
'firstSaveDate' => $first_save_date,
'lastSaveDate' => $last_save_date,
'saveCount' => $save_count,
'isYearEndPromoPeriod' => $is_yearend_promo_period,
'hideUpgradeNudge' => $hide_upgrade_nudge,
'hidePromoNudge' => $hide_promo_nudge,
'showSupportNudge' => $show_support_nudge,
);
}
wp_localize_script( 'asenha-admin-page', 'asenhaStats', $asenha_stats_localized );
}
/**
* Enqueue block editor scripts and styles.
*
* Loaded via the `enqueue_block_editor_assets` hook so assets are scoped
* strictly to block-editor post-edit screens (post.php / post-new.php).
*
* @since 7.11.0
*/
function asenha_block_editor_scripts() {
$current_screen = get_current_screen();
// Only load on post edit / new post block editor screens.
if ( !$current_screen instanceof \WP_Screen || 'post' !== $current_screen->base || !method_exists( $current_screen, 'is_block_editor' ) || !$current_screen->is_block_editor() ) {
return;
}
wp_enqueue_style(
'asenha-wp-block-editor',
ASENHA_URL . 'assets/css/wp-block-editor.css',
array(),
ASENHA_VERSION
);
}
/**
* Inline CSS for Admin Menu Organizer in all wp-admin pages. Previously loaded externally as part of wp-admin.css file
*
* @since 7.6.11
*/
function asenha_admin_menu_organizer_css() {
?>
$enable_external_permalinks,
) );
}
// Media Categories
$enable_media_categories = ( array_key_exists( 'enable_media_categories', $options ) ? $options['enable_media_categories'] : false );
if ( $enable_media_categories && !is_admin() && is_user_logged_in() ) {
wp_enqueue_style(
'asenha-media-categories-frontend',
ASENHA_URL . 'assets/css/media-categories-frontend.css',
array(),
ASENHA_VERSION
);
}
}
/**
* Add admin bar styles for wp-admin and frontend
*
* @since 6.2.1
*/
function asenha_admin_bar_item_js_css() {
if ( is_user_logged_in() ) {
?>
' . __( 'Configure', 'admin-site-enhancements' ) . '';
array_unshift( $links, $settings_link );
return $links;
}
/**
* Modify footer text
*
* @since 1.0.0
*/
function asenha_footer_text() {
// Show nothing
?>
ASE v
true,
) );
} else {
echo json_encode( array(
'success' => false,
) );
}
}
}
}
/**
* Dismiss support nudge
*
* @since 5.8.2
*/
function asenha_dismiss_upgrade_nudge() {
if ( isset( $_REQUEST ) && current_user_can( 'manage_options' ) ) {
if ( wp_verify_nonce( sanitize_text_field( $_REQUEST['nonce'] ), 'asenha-' . get_current_user_id() ) ) {
$current_date = date( 'Y-m-d', time() );
$asenha_stats = asenha_get_option_array( ASENHA_SLUG_U . '_stats', false );
$asenha_stats['upgrade_nudge_dismissed'] = true;
$asenha_stats['upgrade_nudge_dismissed_date'] = $current_date;
$success = update_option( ASENHA_SLUG_U . '_stats', $asenha_stats, false );
if ( $success ) {
echo json_encode( array(
'success' => true,
) );
} else {
echo json_encode( array(
'success' => false,
) );
}
}
}
}
/**
* Dismiss promo nudge
*
* @since 7.5.1
*/
function asenha_dismiss_promo_nudge() {
if ( isset( $_REQUEST ) && current_user_can( 'manage_options' ) ) {
if ( wp_verify_nonce( sanitize_text_field( $_REQUEST['nonce'] ), 'asenha-' . get_current_user_id() ) ) {
$current_date = date( 'Y-m-d', time() );
$asenha_stats = asenha_get_option_array( ASENHA_SLUG_U . '_stats', false );
$asenha_stats['promo_nudge_dismissed'] = true;
$asenha_stats['promo_nudge_dismissed_date'] = $current_date;
$success = update_option( ASENHA_SLUG_U . '_stats', $asenha_stats, false );
if ( $success ) {
echo json_encode( array(
'success' => true,
) );
} else {
echo json_encode( array(
'success' => false,
) );
}
}
}
}
/**
* Dismiss support nudge
*
* @since 5.2.7
*/
function asenha_dismiss_support_nudge() {
if ( isset( $_REQUEST ) && current_user_can( 'manage_options' ) ) {
if ( wp_verify_nonce( sanitize_text_field( $_REQUEST['nonce'] ), 'asenha-' . get_current_user_id() ) ) {
$asenha_stats = asenha_get_option_array( ASENHA_SLUG_U . '_stats', false );
$asenha_stats['support_nudge_dismissed'] = true;
$success = update_option( ASENHA_SLUG_U . '_stats', $asenha_stats, false );
if ( $success ) {
echo json_encode( array(
'success' => true,
) );
} else {
echo json_encode( array(
'success' => false,
) );
}
}
}
}
/**
* Release lock for an IP address in Limit Login Attempts.
*
* Deletes the IP entry from the failed login attempts table, which immediately
* releases the lockout for that IP address.
*
* @since 8.3.1
*/
function asenha_release_login_lock() {
if ( !current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'message' => __( 'Insufficient permissions.', 'admin-site-enhancements' ),
) );
}
if ( !isset( $_REQUEST['nonce'] ) || !isset( $_REQUEST['ip_address'] ) ) {
wp_send_json_error( array(
'message' => __( 'Missing required data.', 'admin-site-enhancements' ),
) );
}
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) );
if ( !wp_verify_nonce( $nonce, 'asenha-' . get_current_user_id() ) ) {
wp_send_json_error( array(
'message' => __( 'Invalid security token.', 'admin-site-enhancements' ),
) );
}
$ip_address = sanitize_text_field( wp_unslash( $_REQUEST['ip_address'] ) );
$common_methods = new \ASENHA\Classes\Common_Methods();
if ( !$common_methods->is_ip_valid( $ip_address ) ) {
wp_send_json_error( array(
'message' => __( 'Invalid IP address.', 'admin-site-enhancements' ),
) );
}
global $wpdb;
$table_name = $wpdb->prefix . 'asenha_failed_logins';
$deleted = $wpdb->delete( $table_name, array(
'ip_address' => $ip_address,
), array('%s') );
if ( false === $deleted ) {
wp_send_json_error( array(
'message' => __( 'Could not release lock.', 'admin-site-enhancements' ),
) );
}
wp_send_json_success( array(
'deleted' => (int) $deleted,
) );
}