PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / compatibility / jet-engine / macros / auto-update-appointment-provider.php

auto-update-appointment-provider.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at compatibility/jet-engine/macros/auto-update-appointment-provider.php

77 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * JetAppointment provider macro for JetFormBuilder auto-update.
4 *
5 * @package JFB_Compatibility\Jet_Engine\Macros
6 */
7
8 namespace JFB_Compatibility\Jet_Engine\Macros;
9
10 if ( ! defined( 'WPINC' ) ) {
11 die;
12 }
13
14 class Auto_Update_Appointment_Provider extends Base_Field_Context_Macro {
15
16 public function macros_tag() {
17 return 'jfb_auto_update_appointment_provider';
18 }
19
20 public function macros_name() {
21 return 'JFB Auto-Update - JetAppointment Provider';
22 }
23
24 public function macros_args() {
25 return array(
26 'field_name' => array(
27 'label' => __( 'Field Name', 'jet-form-builder' ),
28 'type' => 'text',
29 'default' => '',
30 ),
31 );
32 }
33
34 public function macros_callback( $args = array() ) {
35 $field_name = ! empty( $args['field_name'] ) ? $args['field_name'] : null;
36
37 if ( ! $field_name || ! function_exists( 'jet_apb' ) || ! function_exists( 'jet_engine' ) ) {
38 return '';
39 }
40
41 $post_id = $this->get_context_value( $field_name );
42
43 if ( ! $post_id ) {
44 return '';
45 }
46
47 $post = get_post( $post_id );
48
49 if ( ! $post ) {
50 return '';
51 }
52
53 $service_id = $post->ID;
54 $services_cpt = jet_apb()->settings->get( 'services_cpt' );
55 $providers_cpt = jet_apb()->settings->get( 'providers_cpt' );
56
57 if ( ! $service_id || ! $services_cpt || ! $providers_cpt ) {
58 return '';
59 }
60
61 $providers = jet_engine()->relations->get_related_posts(
62 array(
63 'post_type_1' => $services_cpt,
64 'post_type_2' => $providers_cpt,
65 'post_id' => $service_id,
66 'from' => $providers_cpt,
67 )
68 );
69
70 if ( ! is_array( $providers ) ) {
71 $providers = array( $providers );
72 }
73
74 return implode( ',', array_filter( $providers ) );
75 }
76 }
77