From 77c62c8c8c01fa08317980b019a1970ec871656a Mon Sep 17 00:00:00 2001 From: John Huebner Date: Sun, 29 Aug 2021 08:52:57 -0400 Subject: [PATCH] Added filter to allow disabling all fields so that specific fields can be enabled - #40 --- README.md | 17 +++++++++++++++++ acf-post2post.php | 3 ++- readme.txt | 7 +++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7794b58..87b9842 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,23 @@ You can disable automatic bidirectional relationships for specific field keys us add_filter('acf/post2post/update_relationships/key=field_XXXXXXXX', '__return_false'); ``` +## Disable All Fields +You can disable bidirectional updates using the following code +``` +// field_XXXXXXXX = the field key of the field +// you want to disable bidirectional relationships for +add_filter('acf/post2post/update_relationships/default', '__return_false'); +``` +When doing this the field exceptions filter works in reverse and you must use that filter to enable fields that you want bidirectionality for, like this + +``` +// field_XXXXXXXX = the field key of the field +// you want to disable bidirectional relationships for +add_filter('acf/post2post/update_relationships/key=field_XXXXXXXX', '__return_true'); +``` + + + ## After update hooks There are two actions that can be used after a post is updated and passes a single post ID. Please make sure you see the subtle difference in these two hooks. diff --git a/acf-post2post.php b/acf-post2post.php index c79352d..8313ae1 100644 --- a/acf-post2post.php +++ b/acf-post2post.php @@ -4,7 +4,7 @@ Plugin Name: ACF Post-2-Post Plugin URI: https://github.com/Hube2/acf-post2post Description: Two way relationship fields - Version: 1.6.0 + Version: 1.7.0 Author: John A. Huebner II Author URI: https://github.com/Hube2 License: GPL v2 or later @@ -46,6 +46,7 @@ public function missing_acf5() { public function update_relationship_field($value, $post_id, $field) { $update = true; + $update = apply_filters('acf/post2post/update_relationships/default', $update); $update = apply_filters('acf/post2post/update_relationships/key='.$field['key'], $update); if (!$update) { return $value; diff --git a/readme.txt b/readme.txt index eb4622b..05f5fe5 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: Hube2 Tags: acf, advanced custom fields, add on, bidirectional, 2 way, two way, relationship Requires at least: 4.0 -Tested up to: 5.5 -Stable tag: 1.6.0 +Tested up to: 5.8 +Stable tag: 1.7.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -118,6 +118,9 @@ function my_post_updated_action($posts) { == Changelog == += 1.7.0 = +* Added filter to allow disabling all fields so that specific fields can be enabled + = 1.6.0 = * Added filter to allow specifying append or prepend new relationship when not overwriting