-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from jabranr/support-wp-v6
add WP v6 support
- Loading branch information
Showing
5 changed files
with
41 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
<?php | ||
|
||
/** | ||
* Plugin Name: Nullify empty fields for ACF | ||
* 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 <[email protected]> | ||
* Version: 1.2.2 | ||
* Version: 1.2.3 | ||
* Author URI: https://jabran.me?utm_source=nullify-empty-fields-for-acf | ||
* License: MIT License | ||
* | ||
|
@@ -22,9 +23,10 @@ | |
/** | ||
* Add settings link | ||
*/ | ||
function nullify_empty_fields_for_acf_settings_link( $links ) { | ||
function nullify_empty_fields_for_acf_settings_link($links) | ||
{ | ||
$links[] = sprintf('<a href="%s">%s</a>', admin_url('plugins.php?page=nullify-empty-fields-for-acf'), __('Settings')); | ||
return $links; | ||
return $links; | ||
} | ||
|
||
/** | ||
|
@@ -37,7 +39,8 @@ function nullify_empty_fields_for_acf_settings_link( $links ) { | |
* @link https://www.gatsbyjs.org/packages/gatsby-source-wordpress/#graphql-error---unknown-field-on-acf | ||
* @return mixed | ||
*/ | ||
function nullify_empty_fields_for_acf_empty($value, $post_id, $field) { | ||
function nullify_empty_fields_for_acf_empty($value, $post_id, $field) | ||
{ | ||
if (empty($value)) { | ||
return null; | ||
} | ||
|
@@ -48,15 +51,16 @@ function nullify_empty_fields_for_acf_empty($value, $post_id, $field) { | |
/** | ||
* Uninstall hook callback function | ||
*/ | ||
function nullify_empty_fields_for_acf_uninstall() { | ||
function nullify_empty_fields_for_acf_uninstall() | ||
{ | ||
$nullifyTypes = get_option('nullify_empty_fields_for_acf_types'); | ||
|
||
if (empty($nullifyTypes)) { | ||
remove_filter('acf/format_value', 'nullify_empty_fields_for_acf_empty', 100, 3); | ||
} else { | ||
$nullifyTypes = explode(',', $nullifyTypes); | ||
|
||
foreach($nullifyTypes as $nullifyType) { | ||
foreach ($nullifyTypes as $nullifyType) { | ||
if ($remove) { | ||
remove_filter('acf/format_value/type=' . $nullifyType, 'nullify_empty_fields_for_acf_empty', 100, 3); | ||
} | ||
|
@@ -71,7 +75,8 @@ function nullify_empty_fields_for_acf_uninstall() { | |
* | ||
* @param $remove boolean | ||
*/ | ||
function nullify_empty_fields_for_acf_toggle($remove = false) { | ||
function nullify_empty_fields_for_acf_toggle($remove = false) | ||
{ | ||
$nullifyTypes = get_option('nullify_empty_fields_for_acf_types'); | ||
|
||
if (empty($nullifyTypes)) { | ||
|
@@ -83,7 +88,7 @@ function nullify_empty_fields_for_acf_toggle($remove = false) { | |
} else { | ||
$nullifyTypes = explode(',', $nullifyTypes); | ||
|
||
foreach($nullifyTypes as $nullifyType) { | ||
foreach ($nullifyTypes as $nullifyType) { | ||
if ($remove) { | ||
remove_filter('acf/format_value/type=' . trim($nullifyType), 'nullify_empty_fields_for_acf_empty', 100, 3); | ||
} else { | ||
|
@@ -92,20 +97,22 @@ function nullify_empty_fields_for_acf_toggle($remove = false) { | |
} | ||
} | ||
|
||
add_filter('plugin_action_links_'. plugin_basename(__FILE__), 'nullify_empty_fields_for_acf_settings_link', 100, 3); | ||
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'nullify_empty_fields_for_acf_settings_link', 100, 3); | ||
} | ||
|
||
/** | ||
* Deactivate hook callback function | ||
*/ | ||
function nullify_empty_fields_for_acf_deactivate() { | ||
function nullify_empty_fields_for_acf_deactivate() | ||
{ | ||
nullify_empty_fields_for_acf_toggle(true); | ||
} | ||
|
||
/** | ||
* Activate hook callback function | ||
*/ | ||
function nullify_empty_fields_for_acf_activate() { | ||
function nullify_empty_fields_for_acf_activate() | ||
{ | ||
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')); | ||
} | ||
|
@@ -117,6 +124,6 @@ function nullify_empty_fields_for_acf_activate() { | |
nullify_empty_fields_for_acf_toggle(); | ||
|
||
// hooks | ||
register_activation_hook( __FILE__, 'nullify_empty_fields_for_acf_activate' ); | ||
register_deactivation_hook( __FILE__, 'nullify_empty_fields_for_acf_deactivate' ); | ||
register_uninstall_hook( __FILE__, 'nullify_empty_fields_for_acf_uninstall' ); | ||
register_activation_hook(__FILE__, 'nullify_empty_fields_for_acf_activate'); | ||
register_deactivation_hook(__FILE__, 'nullify_empty_fields_for_acf_deactivate'); | ||
register_uninstall_hook(__FILE__, 'nullify_empty_fields_for_acf_uninstall'); |
This file contains 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