PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8.2
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / helpers / FrmFormTemplatesHelper.php

FrmFormTemplatesHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.8.2, at classes/helpers/FrmFormTemplatesHelper.php

200 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Form Templates Helper class.
4 *
5 * @package Formidable
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 die( 'You are not allowed to call this page directly.' );
10 }
11
12 /**
13 * Provides helper functions for managing form templates in the admin area.
14 *
15 * @since 6.7
16 */
17 class FrmFormTemplatesHelper {
18
19 /**
20 * Updates template array with additional details and URL.
21 *
22 * @param array $template Template data.
23 * @param string $pricing Upgrade link URL.
24 * @param string $license_type License type.
25 */
26 public static function prepare_template_details( &$template, $pricing, $license_type ) {
27 $template['is_featured'] = ! empty( $template['is_featured'] );
28 $template['is_favorite'] = ! empty( $template['is_favorite'] );
29 $template['is_custom'] = ! empty( $template['is_custom'] );
30 $template['plan_required'] = FrmFormsHelper::get_plan_required( $template );
31
32 $template['name'] = $template['is_custom']
33 ? $template['name']
34 : preg_replace( '/(\sForm)?(\sTemplate)?$/', '', $template['name'] );
35
36 $template['use_template'] = '#';
37 if ( $template['is_custom'] ) {
38 $template['use_template'] = $template['url'];
39 } elseif ( ! $template['plan_required'] ) {
40 $link = FrmFormsHelper::get_template_install_link( $template, compact( 'pricing', 'license_type' ) );
41
42 $template['use_template'] = esc_url( $link['url'] );
43 }
44 }
45
46 /**
47 * Echo attributes for a given template.
48 *
49 * @since 6.7
50 *
51 * @param array $template The template data.
52 * @param bool $expired Whether the API request is expired or not.
53 * @return void
54 */
55 public static function add_template_attributes( $template, $expired ) {
56 $attributes = array(
57 'tabindex' => '0',
58 'data-id' => $template['id'],
59 'frm-search-text' => strtolower( $template['name'] ),
60 );
61
62 // Set 'data-slug' attribute.
63 if ( ! empty( $template['slug'] ) ) {
64 $attributes['data-slug'] = $template['slug'];
65 }
66
67 // Set 'data-categories' attribute.
68 if ( ! empty( $template['category_slugs'] ) ) {
69 $attributes['data-categories'] = implode( ',', $template['category_slugs'] );
70 }
71
72 $attributes['class'] = self::prepare_single_template_classes( $template );
73 self::prepare_single_template_plan( $template, $expired, $attributes );
74
75 FrmAppHelper::array_to_html_params( $attributes, true );
76 }
77
78 /**
79 * Add classes for a given template.
80 *
81 * @since 6.7
82 *
83 * @param array $template The template data.
84 * @return string
85 */
86 private static function prepare_single_template_classes( $template ) {
87 $class_names = array( 'frm-card-item' );
88 if ( $template['is_featured'] ) {
89 $class_names[] = 'frm-form-templates-featured-item';
90 }
91 if ( $template['is_favorite'] ) {
92 $class_names[] = 'frm-form-templates-favorite-item';
93 }
94 if ( $template['is_custom'] ) {
95 $class_names[] = 'frm-form-templates-custom-item';
96 }
97
98 return implode( ' ', $class_names );
99 }
100
101 /**
102 * Add info about the required plan for this template.
103 *
104 * @since 6.7
105 *
106 * @param array $template The template data.
107 * @param bool $expired Whether the license is expired.
108 * @param array $attributes The template attributes.
109 * @return void
110 */
111 private static function prepare_single_template_plan( $template, $expired, &$attributes ) {
112 if ( ! $template['plan_required'] ) {
113 return;
114 }
115
116 $required_plan_slug = sanitize_title( $template['plan_required'] );
117 $attributes['data-required-plan'] = $expired && 'free' !== $required_plan_slug ? 'renew' : $required_plan_slug;
118 if ( 'free' === $required_plan_slug ) {
119 $attributes['data-key'] = $template['key'];
120 }
121
122 $attributes['class'] .= ' frm-form-templates-locked-item frm-' . esc_attr( $required_plan_slug ) . '-template';
123 }
124
125 /**
126 * Echo attributes for the link to view a template.
127 *
128 * @since 6.7
129 *
130 * @param array $template The template data.
131 * @return void
132 */
133 public static function add_template_link_attributes( $template ) {
134 $attributes = array(
135 'class' => 'button button-secondary frm-button-secondary frm-small',
136 'role' => 'button',
137 'href' => $template['link'],
138 );
139
140 if ( ! $template['is_custom'] ) {
141 $utm = array(
142 'medium' => 'form-templates',
143 'content' => $template['slug'],
144 );
145
146 $attributes['href'] = FrmAppHelper::admin_upgrade_link( $utm, $attributes['href'] );
147 $attributes['target'] = '_blank';
148 }
149
150 FrmAppHelper::array_to_html_params( $attributes, true );
151 }
152
153 /**
154 * Show the CTA to upgrade or renew.
155 *
156 * @since 6.7
157 *
158 * @param array $args {
159 * Arguments for the CTA.
160 *
161 * @type string $upgrade_link Upgrade link URL.
162 * @type string $renew_link Renew link URL.
163 * }
164 * @return void
165 */
166 public static function show_upgrade_renew_cta( $args ) {
167 // Show 'renew' banner for expired users.
168 if ( $args['expired'] ) {
169 FrmTipsHelper::show_admin_cta(
170 array(
171 'title' => esc_html__( 'Get Super Powers with Pre-built Forms', 'formidable' ),
172 'description' => esc_html__( 'Unleash the potential of hundreds of form templates and save precious time. Renew today for unparalleled form-building speed.', 'formidable' ),
173 'link_text' => esc_html__( 'Renew Now', 'formidable' ),
174 'link_url' => $args['renew_link'],
175 'id' => 'frm-renew-subscription-banner',
176 )
177 );
178 return;
179 }
180
181 // Show 'upgrade' banner for non-elite users.
182 if ( ! in_array( FrmAddonsController::license_type(), array( 'elite', 'business' ), true ) ) {
183 FrmTipsHelper::show_admin_cta(
184 array(
185 'title' => sprintf(
186 /* translators: %1$s: Open span tag, %2$s: Close span tag */
187 esc_html__( 'Get Super Powers with %1$s%2$s More Pre-built Forms', 'formidable' ) . ' 🦸',
188 '<span class="frm-form-templates-extra-templates-count">',
189 '</span>'
190 ),
191 'description' => esc_html__( 'Unleash the potential of hundreds of additional form templates and save precious time. Upgrade today for unparalleled form-building capabilities.', 'formidable' ),
192 'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ),
193 'link_url' => $args['upgrade_link'],
194 'id' => 'frm-upgrade-banner',
195 )
196 );
197 }
198 }
199 }
200