AcfAjax.php
7 months ago
ExactOnlineAjax.php
5 months ago
SettingsAjax.php
7 months ago
ZohoCRMAjax.php
7 months ago
ZohoInventoryAjax.php
5 months ago
index.php
1 year ago
AcfAjax.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | namespace CommerceBird\Admin\Actions\Ajax; |
| 4 | |
| 5 | use CommerceBird\Admin\Traits\AjaxRequest; |
| 6 | use CommerceBird\Admin\Traits\OptionStatus; |
| 7 | use CommerceBird\Admin\Traits\Singleton; |
| 8 | use CommerceBird\Admin\Traits\LogWriter; |
| 9 | |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | /** |
| 15 | * Initializes the ACF functions class. |
| 16 | * |
| 17 | * @since 1.0.0 |
| 18 | * @return void |
| 19 | */ |
| 20 | final class AcfAjax { |
| 21 | |
| 22 | use Singleton; |
| 23 | use AjaxRequest; |
| 24 | use OptionStatus; |
| 25 | use LogWriter; |
| 26 | |
| 27 | |
| 28 | |
| 29 | private const ACTIONS = array( |
| 30 | |
| 31 | 'get_acf_fields' => 'get_acf_fields', |
| 32 | ); |
| 33 | |
| 34 | public function __construct() { |
| 35 | $this->load_actions(); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | public function get_acf_fields(): void { |
| 40 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Admin-only AJAX call, nonce verified in parent. |
| 41 | $post_type_value = isset( $_GET['post_type'] ) ? sanitize_text_field( wp_unslash( $_GET['post_type'] ) ) : ''; |
| 42 | if ( 'users' === $post_type_value ) { |
| 43 | $post_type_value = 'all'; |
| 44 | $group_type = 'user_role'; |
| 45 | } else { |
| 46 | $group_type = 'post_type'; |
| 47 | } |
| 48 | // Get all field groups associated with WooCommerce products. |
| 49 | $groups = acf_get_field_groups( array( $group_type => $post_type_value ) ); |
| 50 | |
| 51 | // Check if there are any field groups. |
| 52 | if ( $groups ) { |
| 53 | // Loop through each group. |
| 54 | foreach ( $groups as $group ) { |
| 55 | // Get the fields for the current group. |
| 56 | $fields = acf_get_fields( $group['key'] ); |
| 57 | } |
| 58 | $this->response['fields'] = $fields; |
| 59 | $this->serve(); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 |