add-cloneable-field-value.php
10 months ago
get-metabox-value.php
10 months ago
get-object-fields.php
10 months ago
set-metavalue.php
10 months ago
update-cloneable-field-value.php
10 months ago
get-object-fields.php
101 lines
| 1 | <?php |
| 2 | /** |
| 3 | * GetObjectFields. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category GetObjectFields |
| 7 | * @package SureTriggers |
| 8 | * @author BSF <username@example.com> |
| 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 10 | * @link https://www.brainstormforce.com/ |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | |
| 14 | use SureTriggers\Integrations\AutomateAction; |
| 15 | use SureTriggers\Traits\SingletonLoader; |
| 16 | |
| 17 | /** |
| 18 | * GetObjectFields |
| 19 | * |
| 20 | * @category GetObjectFields |
| 21 | * @package SureTriggers |
| 22 | * @author BSF <username@example.com> |
| 23 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 24 | * @link https://www.brainstormforce.com/ |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | class GetObjectFields extends AutomateAction { |
| 28 | |
| 29 | /** |
| 30 | * Integration type. |
| 31 | * |
| 32 | * @var string |
| 33 | */ |
| 34 | public $integration = 'MetaBox'; |
| 35 | |
| 36 | /** |
| 37 | * Action name. |
| 38 | * |
| 39 | * @var string |
| 40 | */ |
| 41 | public $action = 'get_object_fields'; |
| 42 | |
| 43 | use SingletonLoader; |
| 44 | |
| 45 | /** |
| 46 | * Register a action. |
| 47 | * |
| 48 | * @param array $actions actions. |
| 49 | * @return array |
| 50 | */ |
| 51 | public function register( $actions ) { |
| 52 | $actions[ $this->integration ][ $this->action ] = [ |
| 53 | 'label' => __( 'Get Object Fields', 'suretriggers' ), |
| 54 | 'action' => $this->action, |
| 55 | 'function' => [ $this, 'action_listener' ], |
| 56 | ]; |
| 57 | return $actions; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Action listener. |
| 62 | * |
| 63 | * @param int $user_id user_id. |
| 64 | * @param int $automation_id automation_id. |
| 65 | * @param array $fields fields. |
| 66 | * @param array $selected_options selectedOptions. |
| 67 | * @psalm-suppress UndefinedMethod |
| 68 | * @throws Exception Exception. |
| 69 | * |
| 70 | * @return array|bool|void |
| 71 | */ |
| 72 | public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) { |
| 73 | $object_id = $selected_options['object_id']; |
| 74 | |
| 75 | if ( function_exists( 'rwmb_get_object_fields' ) ) { |
| 76 | $response = rwmb_get_object_fields( $object_id ); |
| 77 | |
| 78 | if ( empty( $response ) ) { |
| 79 | $response = [ |
| 80 | 'response' => esc_attr__( 'No value found.', 'suretriggers' ), |
| 81 | |
| 82 | ]; |
| 83 | } else { |
| 84 | $response = [ |
| 85 | 'object_fields' => $response, |
| 86 | ]; |
| 87 | } |
| 88 | } else { |
| 89 | $response = |
| 90 | [ |
| 91 | 'status' => esc_attr__( 'Error', 'suretriggers' ), |
| 92 | 'message' => esc_attr__( 'Function rwmb_get_object_fields not exists. Please make sure the Metabox plugin is installed and active.', 'suretriggers' ), |
| 93 | |
| 94 | ]; |
| 95 | } |
| 96 | return $response; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | GetObjectFields::get_instance(); |
| 101 |