acf.php
448 lines
| 1 | <?php |
| 2 | |
| 3 | // Don't load directly. |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | die( '-1' ); |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * Compatibility functions for integration with other plugins. |
| 10 | * |
| 11 | * @package Pods |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * Enable backwards compatibility with ACF functions. |
| 16 | * |
| 17 | * @param bool $acf_backwards_compatibility Whether to enable backwards compatibility for ACF functions. |
| 18 | * |
| 19 | * @since 2.7.17 |
| 20 | */ |
| 21 | $acf_backwards_compatibility = apply_filters( 'pods_acf_backwards_compatibility', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound |
| 22 | |
| 23 | if ( $acf_backwards_compatibility && ! class_exists( 'ACF' ) ) { |
| 24 | if ( ! function_exists( 'the_field' ) ) { |
| 25 | /** |
| 26 | * Backwards compatibility function for the_field() from ACF. |
| 27 | * |
| 28 | * @param string|array $field The field name, or an associative array of parameters. |
| 29 | * @param mixed|false $id The ID or slug to load a single item, array of $params to run find. |
| 30 | * |
| 31 | * @since 2.7.17 |
| 32 | */ |
| 33 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 34 | function the_field( $field, $id = false ) { |
| 35 | // @codingStandardsIgnoreLine |
| 36 | echo pods_field_display( null, $id, $field, true ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if ( ! function_exists( 'get_field' ) ) { |
| 41 | /** |
| 42 | * Backwards compatibility function for get_field() from ACF. |
| 43 | * |
| 44 | * @param string|array $field The field name, or an associative array of parameters. |
| 45 | * @param mixed|false $id The ID or slug to load a single item, array of $params to run find. |
| 46 | * |
| 47 | * @return mixed Field value. |
| 48 | * |
| 49 | * @since 2.7.17 |
| 50 | */ |
| 51 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 52 | function get_field( $field, $id = false ) { |
| 53 | return pods_field( null, $id, $field, true ); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if ( ! function_exists( 'update_field' ) ) { |
| 58 | /** |
| 59 | * Backwards compatibility function for update_field() from ACF. |
| 60 | * |
| 61 | * @param string|array $field The field name, or an associative array of parameters. |
| 62 | * @param mixed $value The value to save. |
| 63 | * @param mixed|false $id The ID or slug to load a single item, array of $params to run find. |
| 64 | * |
| 65 | * @return int|false The item ID or false if not saved. |
| 66 | * |
| 67 | * @since 2.7.17 |
| 68 | */ |
| 69 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 70 | function update_field( $field, $value, $id = false ) { |
| 71 | return pods_field_update( null, $id, $field, $value ); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | if ( ! function_exists( 'delete_field' ) ) { |
| 76 | /** |
| 77 | * Backwards compatibility function for delete_field() from ACF. |
| 78 | * |
| 79 | * @param string|array $field The field name, or an associative array of parameters. |
| 80 | * @param mixed|false $id The ID or slug to load a single item, array of $params to run find. |
| 81 | * |
| 82 | * @return int|false The item ID or false if not saved. |
| 83 | * |
| 84 | * @since 2.7.17 |
| 85 | */ |
| 86 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 87 | function delete_field( $field, $id = false ) { |
| 88 | return pods_field_update( null, $id, $field, null ); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if ( ! shortcode_exists( 'acf' ) ) { |
| 93 | /** |
| 94 | * Backwards compatibility function for [acf] shortcode from ACF. |
| 95 | * |
| 96 | * @param array $tags An associative array of shortcode properties. |
| 97 | * @param string $content A string that represents a template override. |
| 98 | * |
| 99 | * @return string |
| 100 | * |
| 101 | * @since 2.7.17 |
| 102 | */ |
| 103 | function pods_acf_shortcode( $tags, $content ) { |
| 104 | |
| 105 | $post_id = null; |
| 106 | |
| 107 | if ( ! empty( $tags['post_id'] ) ) { |
| 108 | $post_id = $tags['post_id']; |
| 109 | } |
| 110 | |
| 111 | $tags = array( |
| 112 | 'field' => $tags['field'], |
| 113 | 'id' => $post_id, |
| 114 | ); |
| 115 | |
| 116 | return pods_shortcode( $tags, $content ); |
| 117 | } |
| 118 | |
| 119 | add_shortcode( 'acf', 'pods_acf_shortcode' ); |
| 120 | }//end if |
| 121 | |
| 122 | /** |
| 123 | * These functions below will do nothing for now. We might add some sort of further compatibility later. |
| 124 | */ |
| 125 | |
| 126 | if ( ! function_exists( 'get_field_object' ) ) { |
| 127 | /** |
| 128 | * Backwards compatibility function for get_field_object() from ACF. |
| 129 | * |
| 130 | * @return array |
| 131 | * |
| 132 | * @since 2.7.17 |
| 133 | */ |
| 134 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 135 | function get_field_object() { |
| 136 | return array(); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | if ( ! function_exists( 'get_fields' ) ) { |
| 141 | /** |
| 142 | * Backwards compatibility function for get_fields() from ACF. |
| 143 | * |
| 144 | * @return array |
| 145 | * |
| 146 | * @since 2.7.17 |
| 147 | */ |
| 148 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 149 | function get_fields() { |
| 150 | return array(); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | if ( ! function_exists( 'get_field_objects' ) ) { |
| 155 | /** |
| 156 | * Backwards compatibility function for get_field_objects() from ACF. |
| 157 | * |
| 158 | * @return array |
| 159 | * |
| 160 | * @since 2.7.17 |
| 161 | */ |
| 162 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 163 | function get_field_objects() { |
| 164 | return array(); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | if ( ! function_exists( 'have_rows' ) ) { |
| 169 | /** |
| 170 | * Backwards compatibility function for have_rows() from ACF. |
| 171 | * |
| 172 | * @return false |
| 173 | * |
| 174 | * @since 2.7.17 |
| 175 | */ |
| 176 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 177 | function have_rows() { |
| 178 | return false; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | if ( ! function_exists( 'get_sub_field' ) ) { |
| 183 | /** |
| 184 | * Backwards compatibility function for get_sub_field() from ACF. |
| 185 | * |
| 186 | * @return false |
| 187 | * |
| 188 | * @since 2.7.17 |
| 189 | */ |
| 190 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 191 | function get_sub_field() { |
| 192 | return false; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if ( ! function_exists( 'the_sub_field' ) ) { |
| 197 | /** |
| 198 | * Backwards compatibility function for the_sub_field() from ACF. |
| 199 | * |
| 200 | * @return null |
| 201 | * |
| 202 | * @since 2.7.17 |
| 203 | */ |
| 204 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 205 | function the_sub_field() { |
| 206 | return null; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if ( ! function_exists( 'get_sub_field_object' ) ) { |
| 211 | /** |
| 212 | * Backwards compatibility function for get_sub_field_object() from ACF. |
| 213 | * |
| 214 | * @return array |
| 215 | * |
| 216 | * @since 2.7.17 |
| 217 | */ |
| 218 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 219 | function get_sub_field_object() { |
| 220 | return array(); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if ( ! function_exists( 'get_row' ) ) { |
| 225 | /** |
| 226 | * Backwards compatibility function for get_row() from ACF. |
| 227 | * |
| 228 | * @return array |
| 229 | * |
| 230 | * @since 2.7.17 |
| 231 | */ |
| 232 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 233 | function get_row() { |
| 234 | return array(); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | if ( ! function_exists( 'get_row_index' ) ) { |
| 239 | /** |
| 240 | * Backwards compatibility function for get_row_index() from ACF. |
| 241 | * |
| 242 | * @return int |
| 243 | * |
| 244 | * @since 2.7.17 |
| 245 | */ |
| 246 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 247 | function get_row_index() { |
| 248 | return 0; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | if ( ! function_exists( 'get_row_layout' ) ) { |
| 253 | /** |
| 254 | * Backwards compatibility function for get_row_layout() from ACF. |
| 255 | * |
| 256 | * @return null |
| 257 | * |
| 258 | * @since 2.7.17 |
| 259 | */ |
| 260 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 261 | function get_row_layout() { |
| 262 | return null; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if ( ! function_exists( 'delete_sub_field' ) ) { |
| 267 | /** |
| 268 | * Backwards compatibility function for delete_sub_field() from ACF. |
| 269 | * |
| 270 | * @return null |
| 271 | * |
| 272 | * @since 2.7.17 |
| 273 | */ |
| 274 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 275 | function delete_sub_field() { |
| 276 | return null; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | if ( ! function_exists( 'update_sub_field' ) ) { |
| 281 | /** |
| 282 | * Backwards compatibility function for update_sub_field() from ACF. |
| 283 | * |
| 284 | * @return null |
| 285 | * |
| 286 | * @since 2.7.17 |
| 287 | */ |
| 288 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 289 | function update_sub_field() { |
| 290 | return null; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | if ( ! function_exists( 'add_row' ) ) { |
| 295 | /** |
| 296 | * Backwards compatibility function for add_row() from ACF. |
| 297 | * |
| 298 | * @return null |
| 299 | * |
| 300 | * @since 2.7.17 |
| 301 | */ |
| 302 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 303 | function add_row() { |
| 304 | return null; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | if ( ! function_exists( 'update_row' ) ) { |
| 309 | /** |
| 310 | * Backwards compatibility function for update_row() from ACF. |
| 311 | * |
| 312 | * @return null |
| 313 | * |
| 314 | * @since 2.7.17 |
| 315 | */ |
| 316 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 317 | function update_row() { |
| 318 | return null; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | if ( ! function_exists( 'delete_row' ) ) { |
| 323 | /** |
| 324 | * Backwards compatibility function for delete_row() from ACF. |
| 325 | * |
| 326 | * @return null |
| 327 | * |
| 328 | * @since 2.7.17 |
| 329 | */ |
| 330 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 331 | function delete_row() { |
| 332 | return null; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | if ( ! function_exists( 'add_sub_row' ) ) { |
| 337 | /** |
| 338 | * Backwards compatibility function for add_sub_row() from ACF. |
| 339 | * |
| 340 | * @return null |
| 341 | * |
| 342 | * @since 2.7.17 |
| 343 | */ |
| 344 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 345 | function add_sub_row() { |
| 346 | return null; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | if ( ! function_exists( 'update_sub_row' ) ) { |
| 351 | /** |
| 352 | * Backwards compatibility function for update_sub_row() from ACF. |
| 353 | * |
| 354 | * @return null |
| 355 | * |
| 356 | * @since 2.7.17 |
| 357 | */ |
| 358 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 359 | function update_sub_row() { |
| 360 | return null; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | if ( ! function_exists( 'delete_sub_row' ) ) { |
| 365 | /** |
| 366 | * Backwards compatibility function for delete_sub_row() from ACF. |
| 367 | * |
| 368 | * @return null |
| 369 | * |
| 370 | * @since 2.7.17 |
| 371 | */ |
| 372 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 373 | function delete_sub_row() { |
| 374 | return null; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if ( ! function_exists( 'acf_add_options_page' ) ) { |
| 379 | /** |
| 380 | * Backwards compatibility function for acf_add_options_page() from ACF. |
| 381 | * |
| 382 | * @return null |
| 383 | * |
| 384 | * @since 2.7.17 |
| 385 | */ |
| 386 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 387 | function acf_add_options_page() { |
| 388 | return null; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | if ( ! function_exists( 'acf_add_options_sub_page' ) ) { |
| 393 | /** |
| 394 | * Backwards compatibility function for acf_add_options_sub_page() from ACF. |
| 395 | * |
| 396 | * @return null |
| 397 | * |
| 398 | * @since 2.7.17 |
| 399 | */ |
| 400 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 401 | function acf_add_options_sub_page() { |
| 402 | return null; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | if ( ! function_exists( 'acf_form_head' ) ) { |
| 407 | /** |
| 408 | * Backwards compatibility function for acf_form_head() from ACF. |
| 409 | * |
| 410 | * @return null |
| 411 | * |
| 412 | * @since 2.7.17 |
| 413 | */ |
| 414 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 415 | function acf_form_head() { |
| 416 | return null; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | if ( ! function_exists( 'acf_form' ) ) { |
| 421 | /** |
| 422 | * Backwards compatibility function for acf_form() from ACF. |
| 423 | * |
| 424 | * @return null |
| 425 | * |
| 426 | * @since 2.7.17 |
| 427 | */ |
| 428 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 429 | function acf_form() { |
| 430 | return null; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | if ( ! function_exists( 'acf_register_form' ) ) { |
| 435 | /** |
| 436 | * Backwards compatibility function for acf_register_form() from ACF. |
| 437 | * |
| 438 | * @return null |
| 439 | * |
| 440 | * @since 2.7.17 |
| 441 | */ |
| 442 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 443 | function acf_register_form() { |
| 444 | return null; |
| 445 | } |
| 446 | } |
| 447 | }//end if |
| 448 |