Created
June 20, 2019 13:29
-
-
Save keefyhub/4d9294ffad8de9d63fe7360cb235da03 to your computer and use it in GitHub Desktop.
Validate ACF licence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter('acf/settings/show_admin', '__return_false'); | |
| add_action('admin_action_auto_set_license_keys', 'auto_set_license_keys'); | |
| add_filter('plugin_action_links_advanced-custom-fields-pro/acf.php', 'add_action_to_acf'); | |
| function add_action_to_acf($actions) | |
| { | |
| $actions[] = '<a href="' . wp_nonce_url('admin.php?action=auto_set_license_keys', basename(__FILE__), 'duplicate_nonce') . '">Validate Licence</a>'; | |
| return $actions; | |
| } | |
| function auto_set_license_keys() | |
| { | |
| if (!isset($_REQUEST['action']) && 'auto_set_license_keys' !== $_REQUEST['action']) { | |
| wp_die('Error validating licence'); | |
| } | |
| if (!isset($_GET['duplicate_nonce']) || !wp_verify_nonce($_GET['duplicate_nonce'], basename(__FILE__))) { | |
| wp_die('Error validating licence'); | |
| } | |
| if (defined('ACF_PRO_KEY') && is_plugin_active('advanced-custom-fields-pro/acf.php')) { | |
| include_once(ABSPATH . 'wp-content/plugins/advanced-custom-fields-pro/acf.php'); | |
| $post = [ | |
| 'acf_license' => ACF_PRO_KEY, | |
| 'acf_version' => acf_get_setting('version'), | |
| 'wp_name' => get_bloginfo('name'), | |
| 'wp_url' => home_url(), | |
| 'wp_version' => get_bloginfo('version'), | |
| 'wp_language' => get_bloginfo('language'), | |
| 'wp_timezone' => get_option('timezone_string'), | |
| ]; | |
| $response = acf_updates()->request('v2/plugins/activate?p=pro', $post); | |
| if (is_string($response)) { | |
| $response = new WP_Error('server_error', esc_html($response)); | |
| } | |
| if (is_wp_error($response)) { | |
| acf_pro_update_license($response->get_error_message()); | |
| } | |
| if ($response['status'] == 1) { | |
| acf_pro_update_license($response['license']); | |
| acf_updates()->refresh_plugins_transient(); | |
| acf_add_admin_notice($response['message'], 'success'); | |
| } else { | |
| acf_add_admin_notice($response['message'], 'warning'); | |
| } | |
| } | |
| wp_redirect(admin_url('/plugins.php')); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment