isPublic();
} catch ( ReflectionException $e ) {
return false;
}
}
/**
* Whether an object-cache property can be written without triggering a visibility fatal.
*
* @since 8.4.3
*
* @param object $object Object cache instance.
* @param string $property Property name.
* @return bool
*/
function asenha_object_cache_property_is_writable( $object, $property ) {
if ( !is_object( $object ) || !is_string( $property ) || '' === $property ) {
return false;
}
if ( !property_exists( $object, $property ) ) {
return false;
}
if ( method_exists( $object, '__set' ) ) {
return true;
}
try {
$ref = new ReflectionProperty($object, $property);
return $ref->isPublic();
} catch ( ReflectionException $e ) {
return false;
}
}
/**
* Best-effort clear of cache groups from in-process object-cache arrays.
*
* Only touches cache internals when they are safely accessible. Private
* properties without magic accessors are skipped to avoid fatals.
*
* @since 8.4.3
*
* @param array $groups Cache group names to clear.
*/
function asenha_clear_accessible_object_cache_groups( array $groups ) {
global $wp_object_cache;
if ( !is_object( $wp_object_cache ) || empty( $groups ) ) {
return;
}
foreach ( array('local_cache', 'cache') as $property ) {
try {
if ( !asenha_object_cache_property_is_readable( $wp_object_cache, $property ) ) {
continue;
}
$value = $wp_object_cache->{$property};
if ( !is_array( $value ) ) {
continue;
}
foreach ( $groups as $group ) {
if ( !is_string( $group ) || '' === $group ) {
continue;
}
if ( isset( $value[$group] ) ) {
unset($value[$group]);
}
}
if ( !asenha_object_cache_property_is_writable( $wp_object_cache, $property ) ) {
continue;
}
$wp_object_cache->{$property} = $value;
} catch ( Throwable $e ) {
// Best-effort only; wp_cache_flush() already ran.
}
}
}
/**
* Best-effort clear of the options group from in-process object-cache arrays.
*
* @since 8.4.3
*/
function asenha_clear_accessible_object_cache_options_group() {
asenha_clear_accessible_object_cache_groups( array('options') );
}
/**
* Aggressively invalidate WordPress options object-cache layers.
*
* @since 8.4.3
*/
function asenha_invalidate_options_object_cache_layers() {
wp_cache_delete( 'alloptions', 'options' );
wp_cache_delete( 'notoptions', 'options' );
if ( function_exists( 'wp_cache_flush' ) ) {
wp_cache_flush();
}
if ( function_exists( 'wp_cache_flush_group' ) ) {
wp_cache_flush_group( 'options' );
}
asenha_clear_accessible_object_cache_groups( array('options') );
}
if ( false === get_option( ASENHA_SLUG_U ) ) {
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$asenha_exists_in_db = $wpdb->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).
asenha_invalidate_options_object_cache_layers();
}
}
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).
asenha_invalidate_options_object_cache_layers();
}
}
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).
asenha_invalidate_options_object_cache_layers();
}
}
// 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();
}
/**
* Check whether an upgrader-reported plugin basename belongs to ASE.
*
* Supports free, pro, and local development folder names while still requiring
* the canonical ASE main plugin file.
*
* @since 8.8.6
*
* @param string $plugin_basename Plugin basename from upgrader hook data.
* @return bool
*/
function asenha_is_ase_plugin_update( $plugin_basename ) {
if ( !is_string( $plugin_basename ) || '' === $plugin_basename ) {
return false;
}
if ( 'admin-site-enhancements.php' !== wp_basename( $plugin_basename ) ) {
return false;
}
$plugin_dirname = dirname( $plugin_basename );
if ( '.' === $plugin_dirname || '' === $plugin_dirname ) {
return false;
}
return false !== strpos( $plugin_dirname, 'admin-site-enhancements' );
}
/**
* Run SMTP password storage upgrades when ASE is updated via WordPress upgrader.
*
* @since 8.8.6
*
* @param \WP_Upgrader $upgrader WordPress upgrader instance.
* @param array $hook_extra Upgrader hook context.
* @return void
*/
function asenha_maybe_run_smtp_password_storage_upgrades_on_update( $upgrader, $hook_extra ) {
if ( !is_array( $hook_extra ) || empty( $hook_extra['action'] ) || 'update' !== $hook_extra['action'] || empty( $hook_extra['type'] ) || 'plugin' !== $hook_extra['type'] ) {
return;
}
$updated_plugins = array();
if ( !empty( $hook_extra['plugin'] ) && is_string( $hook_extra['plugin'] ) ) {
$updated_plugins[] = $hook_extra['plugin'];
}
if ( !empty( $hook_extra['plugins'] ) && is_array( $hook_extra['plugins'] ) ) {
$updated_plugins = array_merge( $updated_plugins, $hook_extra['plugins'] );
}
if ( empty( $updated_plugins ) ) {
return;
}
foreach ( array_unique( $updated_plugins ) as $updated_plugin ) {
if ( asenha_is_ase_plugin_update( $updated_plugin ) ) {
asenha_run_smtp_password_storage_upgrades();
return;
}
}
}
if ( did_action( 'plugins_loaded' ) ) {
asenha_run_smtp_password_storage_upgrades();
} else {
add_action( 'plugins_loaded', 'asenha_run_smtp_password_storage_upgrades' );
}
add_action(
'upgrader_process_complete',
'asenha_maybe_run_smtp_password_storage_upgrades_on_update',
10,
2
);
/**
* 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'] ) {
?>
script URL.
* @return array Filtered plugins map.
*/
function asenha_settings_page_mce_external_plugins( $plugins ) {
if ( !is_array( $plugins ) || empty( $plugins ) ) {
return array();
}
$asenha_plugins = array();
foreach ( $plugins as $name => $url ) {
if ( is_string( $url ) && 0 === strpos( $url, ASENHA_URL ) ) {
$asenha_plugins[$name] = $url;
}
}
return $asenha_plugins;
}
/**
* Enqueue admin scripts
*
* @since 1.0.0
*/
function asenha_admin_scripts( $hook_suffix ) {
global
$wp_version,
$pagenow,
$typenow,
$taxnow,
$hook_suffix,
$current_user
;
$current_screen = get_current_screen();
// Get all WP Enhancements options, default to empty array in case it's not been created yet
$options = asenha_get_option_array( 'admin_site_enhancements', true );
// For main page of this plugin
if ( is_asenha() ) {
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_script(
'asenha-jsticky',
ASENHA_URL . 'assets/js/jquery.jsticky.mod.min.js',
array('jquery'),
ASENHA_VERSION,
false
);
wp_enqueue_script(
'asenha-js-cookie',
ASENHA_URL . 'assets/js/js.cookie.min.js',
array(),
ASENHA_VERSION,
false
);
// First, we unload the CodeMirror libraries included in WP core
wp_deregister_script( 'wp-codemirror' );
wp_deregister_script( 'code-editor' );
wp_deregister_script( 'htmlhint' );
wp_deregister_script( 'csslint' );
wp_deregister_script( 'esprima' );
wp_deregister_script( 'jshint' );
// Then, we load ASENHA's CodeMirror libraries. In use, e.g. for Utilities >> 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 );
// Prevent third-party TinyMCE external plugins (e.g. ThirstyAffiliates, Advanced Ads) from loading on the
// ASE settings page. Ad blockers often block URLs containing "affiliate" / "ads", which causes TinyMCE to
// show "Failed to load plugin url" alerts for Custom Admin Footer editors that do not need those plugins.
add_filter( 'mce_external_plugins', 'asenha_settings_page_mce_external_plugins', PHP_INT_MAX );
$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
$admin_page_style_dependencies = array(
'asenha-jbox',
'asenha-codemirror',
'asenha-datatables',
'wp-color-picker'
);
wp_enqueue_style(
'asenha-admin-page',
ASENHA_URL . 'assets/css/admin-page.css',
$admin_page_style_dependencies,
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' ),
'contactFormShortcodeCopied' => __( 'Shortcode copied!', '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' ),
'nonce' => wp_create_nonce( 'asenha_media_replace_nonce' ),
'confirmTitle' => __( 'Confirm Media Replacement', 'admin-site-enhancements' ),
'mimeTypeWarning' => __( 'The selected image is of a different type than the image to replace. Please choose an image with the same type.', 'admin-site-enhancements' ),
'analyzingText' => __( 'Analyzing replacement...', 'admin-site-enhancements' ),
'errorAnalyzing' => __( 'Error analyzing replacement.', 'admin-site-enhancements' ),
'errorServer' => __( 'Error communicating with server.', 'admin-site-enhancements' ),
'warningLabel' => __( 'Warning', 'admin-site-enhancements' ),
'currentImageLabel' => __( 'Current:', 'admin-site-enhancements' ),
'replacementImageLabel' => __( 'Replacement:', 'admin-site-enhancements' ),
'specialUsageLabel' => __( 'Special Usage Detected', 'admin-site-enhancements' ),
'filesToReplaceLabel' => __( 'Files to be replaced', 'admin-site-enhancements' ),
'replacementFilesLabel' => __( 'Replacement files', 'admin-site-enhancements' ),
'postsUsingMediaLabel' => __( 'Used in:', 'admin-site-enhancements' ),
'noPostsLabel' => __( 'No posts currently use this media file.', 'admin-site-enhancements' ),
'editLabel' => __( 'Edit', 'admin-site-enhancements' ),
'cancelLabel' => __( 'Cancel', 'admin-site-enhancements' ),
'confirmLabel' => __( 'Confirm Replacement', 'admin-site-enhancements' ),
'preserveFilenameLabel' => __( 'Preserve the current filename(s). Just change the media content.', 'admin-site-enhancements' ),
'updatePostTitleLabel' => __( 'Update post_title and post_name', 'admin-site-enhancements' ),
'afterReplacementLabel' => __( 'After replacement:', 'admin-site-enhancements' ),
'postTitleLabel' => __( 'Title (post_title):', 'admin-site-enhancements' ),
'postNameLabel' => __( 'Permalink slug (post_name):', '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' ),
'resetMenuNonce' => wp_create_nonce( 'reset-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 || 'profile.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() {
?>
registered[$handle] ) ) {
$src = $wp_assets->registered[$handle]->src;
if ( is_string( $src ) && false !== strpos( $src, 'gravityforms' ) ) {
return true;
}
}
return false;
}
/**
* Check whether a script handle belongs to Glossary by Codeat admin.js.
*
* @since 8.8.8
*
* @param string $handle Script handle.
* @param WP_Scripts $wp_scripts WordPress scripts registry.
* @return bool
*/
function asenha_is_glossary_admin_asset_handle( $handle, $wp_scripts ) {
if ( 'glossary-admin-script' === $handle ) {
return true;
}
if ( isset( $wp_scripts->registered[$handle] ) ) {
$src = $wp_scripts->registered[$handle]->src;
if ( is_string( $src ) && false !== strpos( $src, 'glossary-by-codeat' ) && false !== strpos( $src, '/assets/js/admin.js' ) ) {
return true;
}
}
return false;
}
/**
* Check whether a script handle belongs to WPvivid Quick Snapshot.
*
* WPvivid registers the handle as wpvivid_qucick_snapshot_ex_js (typo). Also
* accept the corrected spelling and any handle whose src is the snapshot JS.
*
* @since 9.1.3
*
* @param string $handle Script handle.
* @param WP_Scripts $wp_scripts WordPress scripts registry.
* @return bool
*/
function asenha_is_wpvivid_quick_snapshot_asset_handle( $handle, $wp_scripts ) {
if ( in_array( $handle, array('wpvivid_quick_snapshot_ex_js', 'wpvivid_qucick_snapshot_ex_js'), true ) ) {
return true;
}
if ( isset( $wp_scripts->registered[$handle] ) ) {
$src = $wp_scripts->registered[$handle]->src;
if ( is_string( $src ) && false !== strpos( $src, 'wpvivid-quick-snapshot.js' ) ) {
return true;
}
}
return false;
}
/**
* Stop WPvivid from printing Quick Snapshot markup and inline dialog JS.
*
* The confirmation UI is output on admin_footer by WPvivid_Snapshot::quick_snapshot(),
* not only by the enqueued script. Removing that callback prevents the leftover
* HTML and the jQuery(...).dialog is not a function error on AMO.
*
* @since 9.1.3
*/
function asenha_unhook_wpvivid_quick_snapshot_footer() {
global $wp_filter;
if ( empty( $wp_filter['admin_footer'] ) || !$wp_filter['admin_footer'] instanceof WP_Hook ) {
return;
}
foreach ( $wp_filter['admin_footer']->callbacks as $priority => $callbacks ) {
foreach ( $callbacks as $callback ) {
if ( empty( $callback['function'] ) || !is_array( $callback['function'] ) ) {
continue;
}
$object = $callback['function'][0];
$method = ( isset( $callback['function'][1] ) ? $callback['function'][1] : '' );
if ( 'quick_snapshot' !== $method || !is_object( $object ) ) {
continue;
}
if ( 'WPvivid_Snapshot' === get_class( $object ) ) {
remove_action( 'admin_footer', $callback['function'], $priority );
}
}
}
}
/**
* Dequeue conflicting scripts and styles on ASE custom admin interface pages.
*
* Prevents jQuery UI conflicts from Gravity Forms, and JS errors from plugins
* that enqueue global admin scripts on Admin Menu Organizer and Admin Bar Custom Elements.
* On Admin Menu Organizer, also unloads WPvivid Quick Snapshot (script + footer markup).
*
* @since 8.8.7
*/
function asenha_dequeue_conflicting_assets_on_custom_admin_pages() {
if ( !is_asenha_custom_admin_interface_page() ) {
return;
}
global $wp_scripts, $wp_styles;
foreach ( array($wp_scripts, $wp_styles) as $wp_assets ) {
if ( !is_object( $wp_assets ) || !isset( $wp_assets->queue ) ) {
continue;
}
foreach ( (array) $wp_assets->queue as $handle ) {
if ( asenha_is_gravity_forms_asset_handle( $handle, $wp_assets ) ) {
$wp_assets->dequeue( $handle );
}
}
}
// Voxeler Messages — admin script expects DOM nodes absent on AMO/ABCE
wp_dequeue_script( 'voxeler-messages-admin-scripts' );
$screen = get_current_screen();
if ( $screen && 'settings_page_admin-menu-organizer' === $screen->base ) {
$had_wpvivid_quick_snapshot = false;
foreach ( (array) $wp_scripts->queue as $handle ) {
if ( asenha_is_glossary_admin_asset_handle( $handle, $wp_scripts ) ) {
$wp_scripts->dequeue( $handle );
}
if ( asenha_is_wpvivid_quick_snapshot_asset_handle( $handle, $wp_scripts ) ) {
$wp_scripts->dequeue( $handle );
$had_wpvivid_quick_snapshot = true;
}
}
wp_deregister_script( 'glossary-admin-script' );
wp_deregister_script( 'wpvivid_quick_snapshot_ex_js' );
wp_deregister_script( 'wpvivid_qucick_snapshot_ex_js' );
wp_dequeue_style( 'wpvivid_quick_snapshot_ex' );
if ( $had_wpvivid_quick_snapshot ) {
wp_dequeue_script( 'jquery-ui-dialog' );
}
asenha_unhook_wpvivid_quick_snapshot_footer();
}
}
/**
* Block Glossary admin.js script tag output on Admin Menu Organizer.
*
* Last-resort gate when dequeue hooks run before a late plugin re-enqueue.
*
* @since 8.8.8
*
* @param string $tag Script tag HTML.
* @param string $handle Script handle.
* @param string $src Script source URL.
* @return string
*/
function asenha_block_glossary_admin_script_on_amo( $tag, $handle, $src ) {
if ( !is_asenha_custom_admin_interface_page() ) {
return $tag;
}
$screen = get_current_screen();
if ( !$screen || 'settings_page_admin-menu-organizer' !== $screen->base ) {
return $tag;
}
global $wp_scripts;
if ( asenha_is_glossary_admin_asset_handle( $handle, $wp_scripts ) ) {
return '';
}
if ( is_string( $src ) && false !== strpos( $src, 'glossary-by-codeat' ) && false !== strpos( $src, '/assets/js/admin.js' ) ) {
return '';
}
return $tag;
}
/**
* Enqueue public scripts
*
* @since 3.9.0
*/
function asenha_public_scripts( $hook_suffix ) {
// Get all WP Enhancements options, default to empty array in case it's not been created yet
$options = get_option( 'admin_site_enhancements', array() );
// External Permalinks
$enable_external_permalinks = ( array_key_exists( 'enable_external_permalinks', $options ) ? $options['enable_external_permalinks'] : false );
if ( $enable_external_permalinks ) {
$external_permalinks = new ASENHA\Classes\External_Permalinks();
wp_register_script(
'asenha-external-permalinks',
false,
array(),
ASENHA_VERSION,
false
);
wp_enqueue_script( 'asenha-external-permalinks' );
wp_add_inline_script( 'asenha-external-permalinks', $external_permalinks->get_frontend_inline_script_for_options( $options ) );
}
// 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
base, array('settings_page_admin-menu-organizer', 'settings_page_asenha-admin-bar'), true );
}
/**
* Mark that user have supported ASE
*
* @since 5.2.7
*/
function asenha_have_supported() {
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['have_supported'] = true;
$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,
) );
}
}
}
}
/**
* 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,
) );
}