PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.3
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/class-template-manager.php +148 -150 1.6.91.3.3 View file →
@@ -1,150 +1,148 @@
1 -<?php
2 -
3 -/**
4 - * Template Manager Class
5 - *
6 - * @since 1.1.0
7 - */
8 -class WeForms_Template_Manager {
9 -
10 - /**
11 - * The templates
12 - *
13 - * @var array
14 - */
15 - private $templates = [];
16 -
17 - /**
18 - * Get all the registered fields
19 - *
20 - * @return array
21 - */
22 - public function get_templates() {
23 - if ( !empty( $this->templates ) ) {
24 - return $this->templates;
25 - }
26 -
27 - $this->register_templates();
28 -
29 - return $this->templates;
30 - }
31 -
32 - /**
33 - * Get all the templates
34 - *
35 - * @return array
36 - */
37 - public function register_templates() {
38 - require_once WEFORMS_INCLUDES . '/templates/class-abstract-template.php';
39 -
40 - require_once WEFORMS_INCLUDES . '/templates/class-template-blank.php';
41 - require_once WEFORMS_INCLUDES . '/templates/class-template-contact.php';
42 - require_once WEFORMS_INCLUDES . '/templates/class-template-event-registration.php';
43 - require_once WEFORMS_INCLUDES . '/templates/class-template-delete-data-request.php';
44 - require_once WEFORMS_INCLUDES . '/templates/class-template-export-data-request.php';
45 - require_once WEFORMS_INCLUDES . '/templates/class-template-support.php';
46 - require_once WEFORMS_INCLUDES . '/templates/class-template-tell-a-friend.php';
47 - require_once WEFORMS_INCLUDES . '/templates/class-template-job-application.php';
48 - require_once WEFORMS_INCLUDES . '/templates/class-template-comment-and-rating.php';
49 - require_once WEFORMS_INCLUDES . '/templates/class-template-employee-information.php';
50 - require_once WEFORMS_INCLUDES . '/templates/class-template-to-do-list.php';
51 - require_once WEFORMS_INCLUDES . '/templates/class-template-real-estate-listing.php';
52 - require_once WEFORMS_INCLUDES . '/templates/class-template-my-directory-information.php';
53 - require_once WEFORMS_INCLUDES . '/templates/class-template-request-for-quote.php';
54 - require_once WEFORMS_INCLUDES . '/templates/class-template-leave-request.php';
55 - require_once WEFORMS_INCLUDES . '/templates/class-template-admission-form.php';
56 - require_once WEFORMS_INCLUDES . '/templates/class-template-patient-itake-form.php';
57 - require_once WEFORMS_INCLUDES . '/templates/class-template-loan-application-form.php';
58 - require_once WEFORMS_INCLUDES . '/templates/class-template-website-feedback-form.php';
59 - require_once WEFORMS_INCLUDES . '/templates/class-template-volunteer-application.php';
60 - require_once WEFORMS_INCLUDES . '/templates/class-template-bug-report.php';
61 - require_once WEFORMS_INCLUDES . '/templates/class-template-job-listing.php';
62 - require_once WEFORMS_INCLUDES . '/templates/class-template-donation-form.php';
63 - require_once WEFORMS_INCLUDES . '/templates/class-template-product-order-form.php';
64 - require_once WEFORMS_INCLUDES . '/templates/class-template-online-booking-form.php';
65 - require_once WEFORMS_INCLUDES . '/templates/class-template-restaurant-reservation.php';
66 - require_once WEFORMS_INCLUDES . '/templates/class-template-conference-proposal.php';
67 - require_once WEFORMS_INCLUDES . '/templates/class-template-polling-form.php';
68 - require_once WEFORMS_INCLUDES . '/templates/dokan/class-vendor-contact-form.php';
69 -
70 - $templates = [
71 - 'blank' => new WeForms_Template_Blank(),
72 - 'contact' => new WeForms_Template_Contact(),
73 - 'event_registration' => new WeForms_Template_Event_Registration(),
74 - 'delete_data_request' => new WeForms_Template_Delete_Data_Request(),
75 - 'export_data_request' => new WeForms_Template_Export_Data_Request(),
76 - 'support' => new WeForms_Template_Support(),
77 - 'tell_a_friend' => new WeForms_Template_Tell_A_Friend(),
78 - 'job_application' => new WeForms_Template_Job_Application(),
79 - 'my_directory_information' => new WeForms_Template_My_Directory_Information(),
80 - 'volunteer_application' => new WeForms_Template_Volunteer_Application(),
81 - 'bug_report' => new WeForms_Template_Bug_Report(),
82 - 'job_listing' => new WeForms_Template_Job_Listing(),
83 - 'leave_request' => new WeForms_Template_Leave_Request(),
84 - 'real_estate_listing' => new WeForms_Template_Real_Estate_Listing(),
85 - 'website_feedback' => new WeForms_Template_Website_Feedback(),
86 - 'request_for_quote' => new WeForms_Template_Request_For_Quote(),
87 - 'comment_rating' => new WeForms_Template_Comment_Rating(),
88 - 'employee_information' => new WeForms_Template_Employee_Information(),
89 - 'todo_list' => new WeForms_Template_Todo_List(),
90 - 'admission_form' => new WeForms_Template_Admission_Form(),
91 - 'patient_intake_form' => new WeForms_Template_Patient_Intake_Form(),
92 - 'loan_application_form' => new WeForms_Template_Loan_Application_Form(),
93 - 'donation_form' => new Weforms_Donation_Form(),
94 - 'product_order_form' => new WeForms_Template_Product_Order_Form(),
95 - 'online_booking_form' => new Weforms_Template_Online_Booking_Form(),
96 - 'restaurant_reservation' => new WeForms_Template_Restaurant_Reservation(),
97 - 'conference_proposal' => new Weforms_Template_Conference_Proposal(),
98 - 'polling_form' => new WeForms_Template_Polling_Form(),
99 - 'vendor_contact_form' => new WeForms_Vendor_Contact_Form(),
100 - ];
101 -
102 - $this->templates = apply_filters( 'weforms_get_templates', $templates );
103 - }
104 -
105 - /**
106 - * Check if a template exists
107 - *
108 - * @param string $name
109 - *
110 - * @return bool
111 - */
112 - public function exists( $name ) {
113 - if ( array_key_exists( $name, $this->get_templates() ) ) {
114 - return $this->templates[ $name ];
115 - }
116 -
117 - return false;
118 - }
119 -
120 - /**
121 - * Create a form from a template
122 - *
123 - * @param string $name
124 - *
125 - * @return int
126 - */
127 - public function create( $name ) {
128 - if ( !$template = $this->exists( $name ) ) {
129 - return;
130 - }
131 -
132 - $form_id = weforms()->form->create( $template->get_title(), $template->get_form_fields() );
133 -
134 - if ( is_wp_error( $form_id ) ) {
135 - return $form_id;
136 - }
137 -
138 - $meta_updates = [
139 - 'wpuf_form_settings' => $template->get_form_settings(),
140 - 'notifications' => $template->get_form_notifications(),
141 - 'integrations' => [],
142 - ];
143 -
144 - foreach ( $meta_updates as $meta_key => $meta_value ) {
145 - update_post_meta( $form_id, $meta_key, $meta_value );
146 - }
147 -
148 - return $form_id;
149 - }
150 -}
1 +<?php
2 +
3 +/**
4 + * Template Manager Class
5 + *
6 + * @since 1.1.0
7 + */
8 +class WeForms_Template_Manager {
9 +
10 + /**
11 + * The templates
12 + *
13 + * @var array
14 + */
15 + private $templates = array();
16 +
17 + /**
18 + * Get all the registered fields
19 + *
20 + * @return array
21 + */
22 + public function get_templates() {
23 +
24 + if ( ! empty( $this->templates ) ) {
25 + return $this->templates;
26 + }
27 +
28 + $this->register_templates();
29 +
30 + return $this->templates;
31 + }
32 +
33 + /**
34 + * Get all the templates
35 + *
36 + * @return array
37 + */
38 + public function register_templates() {
39 +
40 + require_once WEFORMS_INCLUDES . '/templates/class-abstract-template.php';
41 +
42 + require_once WEFORMS_INCLUDES . '/templates/class-template-blank.php';
43 + require_once WEFORMS_INCLUDES . '/templates/class-template-contact.php';
44 + require_once WEFORMS_INCLUDES . '/templates/class-template-event-registration.php';
45 + require_once WEFORMS_INCLUDES . '/templates/class-template-support.php';
46 + require_once WEFORMS_INCLUDES . '/templates/class-template-tell-a-friend.php';
47 + require_once WEFORMS_INCLUDES . '/templates/class-template-job-application.php';
48 + require_once WEFORMS_INCLUDES . '/templates/class-template-comment-and-rating.php';
49 + require_once WEFORMS_INCLUDES . '/templates/class-template-employee-information.php';
50 + require_once WEFORMS_INCLUDES . '/templates/class-template-to-do-list.php';
51 + require_once WEFORMS_INCLUDES . '/templates/class-template-real-estate-listing.php';
52 + require_once WEFORMS_INCLUDES . '/templates/class-template-my-directory-information.php';
53 + require_once WEFORMS_INCLUDES . '/templates/class-template-request-for-quote.php';
54 + require_once WEFORMS_INCLUDES . '/templates/class-template-leave-request.php';
55 + require_once WEFORMS_INCLUDES . '/templates/class-template-admission-form.php';
56 + require_once WEFORMS_INCLUDES . '/templates/class-template-patient-itake-form.php';
57 + require_once WEFORMS_INCLUDES . '/templates/class-template-loan-application-form.php';
58 + require_once WEFORMS_INCLUDES . '/templates/class-template-website-feedback-form.php';
59 + require_once WEFORMS_INCLUDES . '/templates/class-template-volunteer-application.php';
60 + require_once WEFORMS_INCLUDES . '/templates/class-template-bug-report.php';
61 + require_once WEFORMS_INCLUDES . '/templates/class-template-job-listing.php';
62 + require_once WEFORMS_INCLUDES . '/templates/class-template-donation-form.php';
63 + require_once WEFORMS_INCLUDES . '/templates/class-template-product-order-form.php';
64 + require_once WEFORMS_INCLUDES . '/templates/class-template-online-booking-form.php';
65 + require_once WEFORMS_INCLUDES . '/templates/class-template-restaurant-reservation.php';
66 + require_once WEFORMS_INCLUDES . '/templates/class-template-conference-proposal.php';
67 + require_once WEFORMS_INCLUDES . '/templates/class-template-polling-form.php';
68 + require_once WEFORMS_INCLUDES . '/templates/dokan/class-vendor-contact-form.php';
69 +
70 + $templates = array(
71 + 'blank' => new WeForms_Template_Blank(),
72 + 'contact' => new WeForms_Template_Contact(),
73 + 'event_registration' => new WeForms_Template_Event_Registration(),
74 + 'support' => new WeForms_Template_Support(),
75 + 'tell_a_friend' => new WeForms_Template_Tell_A_Friend(),
76 + 'job_application' => new WeForms_Template_Job_Application(),
77 + 'my_directory_information' => new WeForms_Template_My_Directory_Information(),
78 + 'volunteer_application' => new WeForms_Template_Volunteer_Application(),
79 + 'bug_report' => new WeForms_Template_Bug_Report(),
80 + 'job_listing' => new WeForms_Template_Job_Listing(),
81 + 'leave_request' => new WeForms_Template_Leave_Request(),
82 + 'real_estate_listing' => new WeForms_Template_Real_Estate_Listing(),
83 + 'website_feedback' => new WeForms_Template_Website_Feedback(),
84 + 'request_for_quote' => new WeForms_Template_Request_For_Quote(),
85 + 'comment_rating' => new WeForms_Template_Comment_Rating(),
86 + 'employee_information' => new WeForms_Template_Employee_Information(),
87 + 'todo_list' => new WeForms_Template_Todo_List(),
88 + 'admission_form' => new WeForms_Template_Admission_Form(),
89 + 'patient_intake_form' => new WeForms_Template_Patient_Intake_Form(),
90 + 'loan_application_form' => new WeForms_Template_Loan_Application_Form(),
91 + 'donation_form' => new Weforms_Donation_Form(),
92 + 'product_order_form' => new WeForms_Template_Product_Order_Form(),
93 + 'online_booking_form' => new Weforms_Template_Online_Booking_Form(),
94 + 'restaurant_reservation' => new WeForms_Template_Restaurant_Reservation(),
95 + 'conference_proposal' => new Weforms_Template_Conference_Proposal(),
96 + 'polling_form' => new WeForms_Template_Polling_Form(),
97 + 'vendor_contact_form' => new WeForms_Vendor_Contact_Form(),
98 + );
99 +
100 + $this->templates = apply_filters( 'weforms_get_templates', $templates );
101 + }
102 +
103 + /**
104 + * Check if a template exists
105 + *
106 + * @param string $name
107 + *
108 + * @return boolean
109 + */
110 + public function exists( $name ) {
111 + if ( array_key_exists( $name, $this->get_templates() ) ) {
112 + return $this->templates[ $name ];
113 + }
114 +
115 + return false;
116 + }
117 +
118 + /**
119 + * Create a form from a template
120 + *
121 + * @param string $name
122 + *
123 + * @return integer
124 + */
125 + public function create( $name ) {
126 + if ( ! $template = $this->exists( $name ) ) {
127 + return;
128 + }
129 +
130 + $form_id = weforms()->form->create( $template->get_title(), $template->get_form_fields() );
131 +
132 + if ( is_wp_error( $form_id ) ) {
133 + return $form_id;
134 + }
135 +
136 + $meta_updates = array(
137 + 'wpuf_form_settings' => $template->get_form_settings(),
138 + 'notifications' => $template->get_form_notifications(),
139 + 'integrations' => array()
140 + );
141 +
142 + foreach ($meta_updates as $meta_key => $meta_value) {
143 + update_post_meta( $form_id, $meta_key, $meta_value );
144 + }
145 +
146 + return $form_id;
147 + }
148 +}