Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SaveWysiwygContentAsUnformattedFilter.php #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/Hooks/SaveWysiwygContentAsUnformattedFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
class SaveWysiwygContentAsUnformattedFilter extends AbstractFilter {
public function filter($value, $postId, $field) {
if (empty($GLOBALS['acf_layout_editor_content'])) return $value;

if (
$field['type'] == 'repeater' ||
$field['type'] == 'offbeat_components'
$field['type'] == 'group' ||
$field['type'] == 'offbeat_components'
) {
// bail early if no value
if( empty($value) ) return $value;
Expand All @@ -20,7 +21,13 @@ public function filter($value, $postId, $field) {


// bail early if no sub fields
if( $field['type'] == 'repeater' & empty($field['sub_fields']) ) return $value;
if(
(
$field['type'] == 'repeater' ||
$field['type'] == 'group'
) &&
empty($field['sub_fields'])
) return $value;


// loop over rows
Expand All @@ -41,22 +48,27 @@ public function filter($value, $postId, $field) {
} else {
$sub_fields = $field['sub_fields'];
}



foreach( array_keys($sub_fields) as $j ) {
$sub_field = $sub_fields[ $j ];

if ($sub_field['type'] != 'wysiwyg') continue;

if( is_array($value[ $i ]) && array_key_exists($sub_field['key'], $value[ $i ]) ) {
$value[ $i ][ $sub_field['_name'] . '_raw' ] = $value[ $i ][ $sub_field['key'] ];
if ($field['type'] == 'group') {
if( is_array($value) && array_key_exists($sub_field['key'], $value) ) {
$value[ $sub_field['_name'] . '_raw' ] = $value[ $sub_field['key'] ];
}
} else {
if( is_array($value[ $i ]) && array_key_exists($sub_field['key'], $value[ $i ]) ) {
$value[ $i ][ $sub_field['_name'] . '_raw' ] = $value[ $i ][ $sub_field['key'] ];
}
}

}
}

}

return $value;
}
}
}