Skip to content

Commit

Permalink
Added filter to allow disabling all fields so that specific fields ca…
Browse files Browse the repository at this point in the history
…n be enabled - #40
  • Loading branch information
Hube2 committed Aug 29, 2021
1 parent ab63c7e commit 77c62c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion acf-post2post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 77c62c8

Please sign in to comment.