Skip to content

Commit

Permalink
Merge pull request #11 from jabranr/support-wp-v6
Browse files Browse the repository at this point in the history
add WP v6 support
  • Loading branch information
jabranr authored Sep 8, 2023
2 parents 189f92f + 32a4885 commit 2a15bc7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM wordpress:5.8
FROM wordpress:6

COPY ./entrypoint.sh /usr/local/bin/apache2-custom.sh
RUN chmod 755 /usr/local/bin/apache2-custom.sh
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Set Advanced Custom Fields (ACF) empty field value as `null` instead of `false` to avoid GraphQL error in GatsbyJS.

## WordPress plugins
## WordPress plugins

https://wordpress.org/plugins/wp-acf-nullify-gatsby/

Expand All @@ -16,6 +16,6 @@ If you would like to report an issue then report it at [GitHub issues](https://g

MIT License

© Jabran Rafique – 2020
© Jabran Rafique – since 2020

[![Analytics](https://ga-beacon.appspot.com/UA-50688851-1/nullify-empty-fields-for-acf)](https://github.com/igrigorik/ga-beacon)
24 changes: 12 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
version: "3.2"

services:
db:
image: mysql
restart: always
container_name: mysql
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: "1"
volumes:
- db:/var/lib/mysql

wordpress:
build: .
restart: always
Expand All @@ -18,18 +30,6 @@ services:
- plugins:/var/www/html/wp-content/plugins
- ./src:/var/www/html/wp-content/plugins/nullify-empty-fields-for-acf

db:
image: mysql:5.7
restart: always
container_name: mysql
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: "1"
volumes:
- db:/var/lib/mysql

volumes:
wordpress:
plugins:
Expand Down
35 changes: 21 additions & 14 deletions src/index.php
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
*
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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)) {
Expand All @@ -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 {
Expand All @@ -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'));
}
Expand All @@ -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');
7 changes: 5 additions & 2 deletions src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: jabranr
Donate link: https://paypal.me/jabranr
Tags: gatsby, graphql, acf, advanced-custom-fields, wordpress
Requires at least: 5.0
Tested up to: 5.8
Stable tag: 1.2.2
Tested up to: 6
Stable tag: 1.2.3
Requires PHP: 7.1
License: MIT License
License URI: https://opensource.org/licenses/MIT
Expand All @@ -27,6 +27,9 @@ Set Advanced Custom Fields (ACF) empty field value as `null` instead of `false`

== Changelog ==

= 1.2.3 =
* Support for WordPress 6.x

= 1.2.2 =
* Support for WordPress 5.8

Expand Down

0 comments on commit 2a15bc7

Please sign in to comment.