Skip to content

Instantly share code, notes, and snippets.

@passatgt
Created October 13, 2024 10:26
Show Gist options
  • Save passatgt/938d249b3cf4d7c1c5daba8c7f16a4dd to your computer and use it in GitHub Desktop.
Save passatgt/938d249b3cf4d7c1c5daba8c7f16a4dd to your computer and use it in GitHub Desktop.
A small snippet to notify users if they accidentally installed Secure Custom Fields instead of Advanced Custom Fields.
<?php
if ( ! function_exists( 'check_scf_upgrade' ) ) :
function check_scf_upgrade() {
add_action( 'admin_notices', function(){
if(!get_user_meta(get_current_user_id(), 'acf_upgrade_notice_dismissed', true) && class_exists( 'ACF_Admin' ) && !method_exists('ACF_Admin', 'setup_help_tab')) {
?>
<div class="notice notice-error acf-upgrade-notice is-dismissible">
<p><strong>Advanced Custom Fields is no longer available through WordPress.org.</strong> Please update to the latest version following these instructions:</p>
<p><a href="https://www.advancedcustomfields.com/blog/installing-and-upgrading-to-the-latest-version-of-acf/" target="_blank">https://www.advancedcustomfields.com/blog/installing-and-upgrading-to-the-latest-version-of-acf/</a></p>
</div>
<?php
}
});
add_action('admin_footer', function(){
$nonce = wp_create_nonce('acf_upgrade_notice_nonce');
?>
<script>
jQuery(document).ready(function($) {
$('.acf-upgrade-notice').on('click', '.notice-dismiss', function(){
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
action: 'dismiss_acf_upgrade_notice',
nonce: '<?php echo esc_attr($nonce); ?>'
}
});
});
});
</script>
<?php
});
add_action('wp_ajax_dismiss_acf_upgrade_notice', function() {
check_ajax_referer('acf_upgrade_notice_nonce', 'nonce');
update_user_meta(get_current_user_id(), 'acf_upgrade_notice_dismissed', true);
wp_send_json_success();
});
};
check_scf_upgrade();
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment