AcfAjax.php
1 year ago
ExactOnlineAjax.php
1 year ago
ZohoCRMAjax.php
1 year ago
ZohoInventoryAjax.php
1 year ago
index.php
1 year ago
AcfAjax.php
61 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 | * @since 1.0.0 |
| 17 | * @return void |
| 18 | */ |
| 19 | final class AcfAjax { |
| 20 | |
| 21 | use Singleton; |
| 22 | use AjaxRequest; |
| 23 | use OptionStatus; |
| 24 | use LogWriter; |
| 25 | |
| 26 | |
| 27 | |
| 28 | private const ACTIONS = array( |
| 29 | |
| 30 | 'get_acf_fields' => 'get_acf_fields', |
| 31 | ); |
| 32 | |
| 33 | public function __construct() { |
| 34 | $this->load_actions(); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | public function get_acf_fields(): void { |
| 39 | $post_type_value = isset( $_GET['post_type'] ) ? sanitize_text_field( wp_unslash( $_GET['post_type'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 40 | if ( 'users' === $post_type_value ) { |
| 41 | $post_type_value = 'all'; |
| 42 | $group_type = 'user_role'; |
| 43 | } else { |
| 44 | $group_type = 'post_type'; |
| 45 | } |
| 46 | // Get all field groups associated with WooCommerce products |
| 47 | $groups = acf_get_field_groups( array( $group_type => $post_type_value ) ); |
| 48 | |
| 49 | // Check if there are any field groups |
| 50 | if ( $groups ) { |
| 51 | // Loop through each group |
| 52 | foreach ( $groups as $group ) { |
| 53 | // Get the fields for the current group |
| 54 | $fields = acf_get_fields( $group['key'] ); |
| 55 | } |
| 56 | $this->response['fields'] = $fields; |
| 57 | $this->serve(); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 |