compatibility.php
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | if(!class_exists('acfe_compatibility')): |
| 7 | |
| 8 | class acfe_compatibility{ |
| 9 | |
| 10 | function __construct(){ |
| 11 | |
| 12 | add_action('acf/init', array($this, 'init'), 98); |
| 13 | |
| 14 | } |
| 15 | |
| 16 | function init(){ |
| 17 | |
| 18 | $this->update_settings(); |
| 19 | |
| 20 | add_filter('acf/validate_field_group', array($this, 'field_group_location_list'), 20); |
| 21 | add_filter('acf/validate_field', array($this, 'field_acfe_update'), 20); |
| 22 | |
| 23 | add_filter('acf/validate_field/type=group', array($this, 'field_seamless_style'), 20); |
| 24 | add_filter('acf/validate_field/type=clone', array($this, 'field_seamless_style'), 20); |
| 25 | add_filter('acfe/load_fields/type=flexible_content', array($this, 'field_flexible_settings_title'), 20, 2); |
| 26 | |
| 27 | add_filter('acf/prepare_field/name=acfe_flexible_category', array($this, 'field_flexible_layout_categories'), 10, 2); |
| 28 | |
| 29 | add_filter('pto/posts_orderby/ignore', array($this, 'pto_acf_field_group'), 10, 3); |
| 30 | add_filter('pto/get_options', array($this, 'pto_options_acf_field_group')); |
| 31 | |
| 32 | add_action('admin_menu', array($this, 'cotto_submenu'), 999); |
| 33 | add_filter('rank_math/metabox/priority', array($this, 'rankmath_metaboxes_priority')); |
| 34 | add_filter('wpseo_metabox_prio', array($this, 'yoast_metaboxes_priority')); |
| 35 | add_filter('pll_get_post_types', array($this, 'polylang'), 10, 2 ); |
| 36 | |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * ACF Extended: Settings |
| 41 | */ |
| 42 | function update_settings(){ |
| 43 | |
| 44 | // ACF Extended: 0.8.6.3 - Renamed 'acfe/modules/taxonomies' to 'acfe/modules/ui' |
| 45 | if(acf_get_setting('acfe/modules/taxonomies') !== null){ |
| 46 | acf_update_setting('acfe/modules/ui', acf_get_setting('acfe/modules/taxonomies')); |
| 47 | } |
| 48 | |
| 49 | // ACF Extended: 0.8 - Renamed 'acfe_php*' to 'acfe/php*' |
| 50 | if(acf_get_setting('acfe_php') !== null){ |
| 51 | acf_update_setting('acfe/php', acf_get_setting('acfe_php')); |
| 52 | } |
| 53 | |
| 54 | if(acf_get_setting('php_save') !== null){ |
| 55 | acf_update_setting('acfe/php_save', acf_get_setting('php_save')); |
| 56 | } |
| 57 | |
| 58 | if(acf_get_setting('php_load') !== null){ |
| 59 | acf_update_setting('acfe/php_load', acf_get_setting('php_load')); |
| 60 | } |
| 61 | |
| 62 | if(acf_get_setting('php_found') !== null){ |
| 63 | acf_update_setting('acfe/php_found', acf_get_setting('php_found')); |
| 64 | } |
| 65 | |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * ACF Extended: 0.8 |
| 70 | * Field Group Location: Archive renamed to List |
| 71 | */ |
| 72 | function field_group_location_list($field_group){ |
| 73 | |
| 74 | if(!acf_maybe_get($field_group, 'location')) |
| 75 | return $field_group; |
| 76 | |
| 77 | foreach($field_group['location'] as &$or){ |
| 78 | |
| 79 | foreach($or as &$and){ |
| 80 | |
| 81 | if(!isset($and['value'])) |
| 82 | continue; |
| 83 | |
| 84 | // Post Type List |
| 85 | if($and['param'] === 'post_type' && acfe_ends_with($and['value'], '_archive')){ |
| 86 | |
| 87 | $and['param'] = 'post_type_list'; |
| 88 | $and['value'] = substr_replace($and['value'], '', -8); |
| 89 | |
| 90 | } |
| 91 | |
| 92 | // Taxonomy List |
| 93 | elseif($and['param'] === 'taxonomy' && acfe_ends_with($and['value'], '_archive')){ |
| 94 | |
| 95 | $and['param'] = 'taxonomy_list'; |
| 96 | $and['value'] = substr_replace($and['value'], '', -8); |
| 97 | |
| 98 | } |
| 99 | |
| 100 | } |
| 101 | |
| 102 | } |
| 103 | |
| 104 | return $field_group; |
| 105 | |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * ACF Extended: 0.8 |
| 110 | * Field Filter Value: Removed from this version |
| 111 | */ |
| 112 | function field_acfe_update($field){ |
| 113 | |
| 114 | if(!acf_maybe_get($field, 'acfe_update')) |
| 115 | return $field; |
| 116 | |
| 117 | unset($field['acfe_update']); |
| 118 | |
| 119 | return $field; |
| 120 | |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * ACF Extended: 0.8.5 |
| 125 | * Field Group/Clone: Fixed typo "Seamless" |
| 126 | */ |
| 127 | function field_seamless_style($field){ |
| 128 | |
| 129 | if($seamless = acf_maybe_get($field, 'acfe_seemless_style', false)){ |
| 130 | |
| 131 | $field['acfe_seamless_style'] = $seamless; |
| 132 | |
| 133 | } |
| 134 | |
| 135 | return $field; |
| 136 | |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * ACF Extended: 0.8.4.5 |
| 141 | * Field Flexible Content: Fix duplicated "layout_settings" & "layout_title" |
| 142 | */ |
| 143 | function field_flexible_settings_title($fields, $parent){ |
| 144 | |
| 145 | // Check if is tool screen |
| 146 | if(!acf_is_screen(acfe_get_acf_screen_id('acf-tools'))) |
| 147 | return $fields; |
| 148 | |
| 149 | foreach($fields as $_k => $_field){ |
| 150 | |
| 151 | // field name |
| 152 | $_field_name = acf_maybe_get($_field, 'name'); |
| 153 | |
| 154 | // check 'acfe_flexible_layout_title' & 'layout_settings' |
| 155 | if($_field_name !== 'acfe_flexible_layout_title' && $_field_name !== 'layout_settings') |
| 156 | continue; |
| 157 | |
| 158 | // unset |
| 159 | unset($fields[$_k]); |
| 160 | |
| 161 | } |
| 162 | |
| 163 | return $fields; |
| 164 | |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * ACF Extended: 0.8.6.7 |
| 169 | * Field Flexible Content: Compatibility for Layout Categories |
| 170 | */ |
| 171 | function field_flexible_layout_categories($field){ |
| 172 | |
| 173 | $value = acf_maybe_get($field, 'value'); |
| 174 | |
| 175 | if(empty($value)) |
| 176 | return $field; |
| 177 | |
| 178 | if(is_string($value)){ |
| 179 | |
| 180 | $explode = explode('|', $value); |
| 181 | |
| 182 | $choices = array(); |
| 183 | |
| 184 | foreach($explode as $v){ |
| 185 | |
| 186 | $v = trim($v); |
| 187 | $choices[$v] = $v; |
| 188 | |
| 189 | } |
| 190 | |
| 191 | $field['choices'] = $choices; |
| 192 | $field['value'] = $choices; |
| 193 | |
| 194 | } |
| 195 | |
| 196 | return $field; |
| 197 | |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Plugin: Post Types Order |
| 202 | * https://wordpress.org/plugins/post-types-order/ |
| 203 | * The plugin apply custom order to ACF Field Group Post Type. We have to fix this |
| 204 | */ |
| 205 | function pto_acf_field_group($ignore, $orderby, $query){ |
| 206 | |
| 207 | if(is_admin() && $query->is_main_query() && $query->get('post_type') === 'acf-field-group') |
| 208 | $ignore = true; |
| 209 | |
| 210 | return $ignore; |
| 211 | |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Plugin: Post Types Order |
| 216 | * https://wordpress.org/plugins/post-types-order/ |
| 217 | * The plugin apply a drag & drop UI on ACF Field Group UI. We have to fix this |
| 218 | */ |
| 219 | function pto_options_acf_field_group($options){ |
| 220 | |
| 221 | $options['show_reorder_interfaces']['acf-field-group'] = 'hide'; |
| 222 | |
| 223 | return $options; |
| 224 | |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Plugin: Category Order and Taxonomy Terms Order |
| 229 | * https://wordpress.org/plugins/taxonomy-terms-order/ |
| 230 | * The plugin add a submenu to 'Custom Fields' to order Field Group Categories. It's unecessary |
| 231 | */ |
| 232 | function cotto_submenu(){ |
| 233 | |
| 234 | remove_submenu_page('edit.php?post_type=acf-field-group', 'to-interface-acf-field-group'); |
| 235 | |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Plugin: Rank Math SEO |
| 240 | * https://wordpress.org/plugins/seo-by-rank-math/ |
| 241 | * Fix the plugin post metabox which is always above ACF metaboxes |
| 242 | */ |
| 243 | function rankmath_metaboxes_priority(){ |
| 244 | |
| 245 | return 'default'; |
| 246 | |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Plugin: YOAST SEO |
| 251 | * https://wordpress.org/plugins/wordpress-seo/ |
| 252 | * Fix the plugin post metabox which is always above ACF metaboxes |
| 253 | */ |
| 254 | function yoast_metaboxes_priority(){ |
| 255 | |
| 256 | return 'default'; |
| 257 | |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * ACF Extended: 0.8.3 |
| 262 | * Modules: Enable PolyLang Translation for ACFE Form Module |
| 263 | * https://polylang.pro/doc/filter-reference/ |
| 264 | */ |
| 265 | function polylang($post_types, $is_settings){ |
| 266 | |
| 267 | if($is_settings){ |
| 268 | |
| 269 | unset($post_types['acfe-form']); |
| 270 | |
| 271 | }else{ |
| 272 | |
| 273 | $post_types['acfe-form'] = 'acfe-form'; |
| 274 | |
| 275 | } |
| 276 | |
| 277 | return $post_types; |
| 278 | |
| 279 | } |
| 280 | |
| 281 | } |
| 282 | |
| 283 | new acfe_compatibility(); |
| 284 | |
| 285 | endif; |