Skip to content

Commit 95f8c72

Browse files
authored
Merge pull request #2 from jabranr/enable-support-for-acf-pro
Enable ACF pro support
2 parents ed783ed + ed36ba5 commit 95f8c72

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

src/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin URI: https://github.com/jabranr/nullify-empty-fields-for-acf
55
* Description: Set Advanced Custom Fields (ACF) empty field value as <code>null</code> instead of <code>false</code> to avoid GraphQL error in GatsbyJS.
66
* Author: Jabran Rafique <hello@jabran.me>
7-
* Version: 1.0.0
7+
* Version: 1.1.0
88
* Author URI: https://jabran.me?utm_source=nullify-empty-fields-for-acf
99
* License: MIT License
1010
*
@@ -106,7 +106,7 @@ function nullify_empty_fields_for_acf_deactivate() {
106106
* Activate hook callback function
107107
*/
108108
function nullify_empty_fields_for_acf_activate() {
109-
if (!is_plugin_active('advanced-custom-fields/acf.php')) {
109+
if (!nullify_empty_fields_for_acf_is_acf_active()) {
110110
wp_die(sprintf('This plugin only works with <a href="%s" target="_blank" rel="noopener">Advanced Custom Fields (ACF)</a>. Please install and activate ACF before using this plugin.', 'https://wordpress.org/plugins/advanced-custom-fields/?utm_source=nullify-empty-fields-for-acf'));
111111
}
112112

src/readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://paypal.me/jabranr
44
Tags: gatsby, graphql, acf, advanced-custom-fields, wordpress
55
Requires at least: 5.0
66
Tested up to: 5.3.2
7-
Stable tag: 1.0.0
7+
Stable tag: 1.1.0
88
Requires PHP: 7.1
99
License: MIT License
1010
License URI: https://opensource.org/licenses/MIT
@@ -27,5 +27,8 @@ Set Advanced Custom Fields (ACF) empty field value as `null` instead of `false`
2727

2828
== Changelog ==
2929

30+
= 1.1.0 =
31+
* Support for Advanced Custom Fields (PRO)
32+
3033
= 1.0.0 =
3134
* First version released

src/settings.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@
66
* @author Jabran Rafique
77
*/
88

9+
/**
10+
* Util method to check if ACF plugin (free/pro) is enabled
11+
*/
12+
function nullify_empty_fields_for_acf_is_acf_active() {
13+
$activePlugins = (array) get_option('active_plugins', array());
14+
return strpos(join(',', $activePlugins), 'advanced-custom-fields') !== false;
15+
}
16+
17+
/**
18+
* Add UI for WP admin
19+
*/
920
function nullify_empty_fields_for_acf_add_ui() {
10-
include_once(plugin_dir_path(__FILE__) . '/ui.php');
21+
require_once(plugin_dir_path(__FILE__) . '/ui.php');
1122
}
1223

24+
/**
25+
* Settings for WP admin UI
26+
*/
1327
function nullify_empty_fields_for_acf_add_settings() {
1428
add_plugins_page(
1529
'Settings for Nullify empty fields for ACF',

src/ui.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
$isSuccess = false;
10-
$isAcfEnabled = is_plugin_active('advanced-custom-fields/acf.php');
1110

1211
if (
1312
isset($_POST['nullify_empty_fields_for_acf_form_wp_nonce']) &&
@@ -66,7 +65,7 @@
6665
printf('<div class="notice notice-success is-dismissible"><p>%s</p></div>', __( 'Successfully updated', 'nullify_empty_fields_for_acf' ));
6766
}
6867

69-
if (!$isAcfEnabled) {
68+
if (!nullify_empty_fields_for_acf_is_acf_active()) {
7069
printf('<div class="notice notice-error is-dismissible">');
7170
printf(
7271
'<p>%s</p>',
@@ -89,9 +88,19 @@
8988
<div class="form-group">
9089
<label for="nullify-types" class="form-label">Field types to nullify</label>
9190
<p class="helper-text">Add types separated by commas e.g. "repeater, image, text". Leave it empty to nullify all types.</p>
92-
<input id="nullify-types" name="nullify-types" class="form-input regular-text<?php if (!$isAcfEnabled) echo ' disabled'; ?>" <?php if (!$isAcfEnabled) echo 'disabled'; ?> type="text" value="<?php echo get_option('nullify_empty_fields_for_acf_types'); ?>" />
91+
<input
92+
id="nullify-types"
93+
name="nullify-types"
94+
class="form-input regular-text<?php if (!nullify_empty_fields_for_acf_is_acf_active()) echo ' disabled" disabled'; ?>"
95+
<?php if (!nullify_empty_fields_for_acf_is_acf_active()) echo 'disabled'; ?>
96+
type="text"
97+
value="<?php echo get_option('nullify_empty_fields_for_acf_types'); ?>"
98+
/>
9399
<?php wp_nonce_field('update-plugin-options', 'nullify_empty_fields_for_acf_form_wp_nonce', '', true); ?>
94-
<button type="submit" id="nullify-submit" class="form-input button action<?php if (!$isAcfEnabled) echo ' disabled'; ?>">Update</button>
100+
<button
101+
type="submit"
102+
id="nullify-submit"
103+
class="form-input button action<?php if (!nullify_empty_fields_for_acf_is_acf_active()) echo ' disabled'; ?>">Update</button>
95104
</div>
96105
</form>
97106
<hr />

0 commit comments

Comments
 (0)