Skip to content

Commit

Permalink
Merge pull request #2 from jabranr/enable-support-for-acf-pro
Browse files Browse the repository at this point in the history
Enable ACF pro support
  • Loading branch information
jabranr committed Mar 27, 2020
2 parents ed783ed + ed36ba5 commit 95f8c72
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/index.php
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://github.com/jabranr/nullify-empty-fields-for-acf
* Description: Set Advanced Custom Fields (ACF) empty field value as <code>null</code> instead of <code>false</code> to avoid GraphQL error in GatsbyJS.
* Author: Jabran Rafique <hello@jabran.me>
* Version: 1.0.0
* Version: 1.1.0
* Author URI: https://jabran.me?utm_source=nullify-empty-fields-for-acf
* License: MIT License
*
Expand Down Expand Up @@ -106,7 +106,7 @@ function nullify_empty_fields_for_acf_deactivate() {
* Activate hook callback function
*/
function nullify_empty_fields_for_acf_activate() {
if (!is_plugin_active('advanced-custom-fields/acf.php')) {
if (!nullify_empty_fields_for_acf_is_acf_active()) {
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'));
}

Expand Down
5 changes: 4 additions & 1 deletion src/readme.txt
Expand Up @@ -4,7 +4,7 @@ Donate link: https://paypal.me/jabranr
Tags: gatsby, graphql, acf, advanced-custom-fields, wordpress
Requires at least: 5.0
Tested up to: 5.3.2
Stable tag: 1.0.0
Stable tag: 1.1.0
Requires PHP: 7.1
License: MIT License
License URI: https://opensource.org/licenses/MIT
Expand All @@ -27,5 +27,8 @@ Set Advanced Custom Fields (ACF) empty field value as `null` instead of `false`

== Changelog ==

= 1.1.0 =
* Support for Advanced Custom Fields (PRO)

= 1.0.0 =
* First version released
16 changes: 15 additions & 1 deletion src/settings.php
Expand Up @@ -6,10 +6,24 @@
* @author Jabran Rafique
*/

/**
* Util method to check if ACF plugin (free/pro) is enabled
*/
function nullify_empty_fields_for_acf_is_acf_active() {
$activePlugins = (array) get_option('active_plugins', array());
return strpos(join(',', $activePlugins), 'advanced-custom-fields') !== false;
}

/**
* Add UI for WP admin
*/
function nullify_empty_fields_for_acf_add_ui() {
include_once(plugin_dir_path(__FILE__) . '/ui.php');
require_once(plugin_dir_path(__FILE__) . '/ui.php');
}

/**
* Settings for WP admin UI
*/
function nullify_empty_fields_for_acf_add_settings() {
add_plugins_page(
'Settings for Nullify empty fields for ACF',
Expand Down
17 changes: 13 additions & 4 deletions src/ui.php
Expand Up @@ -7,7 +7,6 @@
*/

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

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

if (!$isAcfEnabled) {
if (!nullify_empty_fields_for_acf_is_acf_active()) {
printf('<div class="notice notice-error is-dismissible">');
printf(
'<p>%s</p>',
Expand All @@ -89,9 +88,19 @@
<div class="form-group">
<label for="nullify-types" class="form-label">Field types to nullify</label>
<p class="helper-text">Add types separated by commas e.g. "repeater, image, text". Leave it empty to nullify all types.</p>
<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'); ?>" />
<input
id="nullify-types"
name="nullify-types"
class="form-input regular-text<?php if (!nullify_empty_fields_for_acf_is_acf_active()) echo ' disabled" disabled'; ?>"
<?php if (!nullify_empty_fields_for_acf_is_acf_active()) echo 'disabled'; ?>
type="text"
value="<?php echo get_option('nullify_empty_fields_for_acf_types'); ?>"
/>
<?php wp_nonce_field('update-plugin-options', 'nullify_empty_fields_for_acf_form_wp_nonce', '', true); ?>
<button type="submit" id="nullify-submit" class="form-input button action<?php if (!$isAcfEnabled) echo ' disabled'; ?>">Update</button>
<button
type="submit"
id="nullify-submit"
class="form-input button action<?php if (!nullify_empty_fields_for_acf_is_acf_active()) echo ' disabled'; ?>">Update</button>
</div>
</form>
<hr />
Expand Down

0 comments on commit 95f8c72

Please sign in to comment.