PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
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.7, at classes/helpers/FrmFormTemplatesHelper.php

197 lines 5.9 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 array $attributes The template attributes.
108 * @return void
109 */
110 private static function prepare_single_template_plan( $template, $expired, &$attributes ) {
111 if ( ! $template['plan_required'] ) {
112 return;
113 }
114
115 $required_plan_slug = sanitize_title( $template['plan_required'] );
116 $attributes['data-required-plan'] = $expired && 'free' !== $required_plan_slug ? 'renew' : $required_plan_slug;
117 if ( 'free' === $required_plan_slug ) {
118 $attributes['data-key'] = $template['key'];
119 }
120
121 $attributes['class'] .= ' frm-form-templates-locked-item frm-' . esc_attr( $required_plan_slug ) . '-template';
122 }
123
124 /**
125 * Echo attributes for the link to view a template.
126 *
127 * @since 6.7
128 *
129 * @param array $template The template data.
130 * @return void
131 */
132 public static function add_template_link_attributes( $template ) {
133 $attributes = array(
134 'class' => 'button button-secondary frm-button-secondary frm-small',
135 'role' => 'button',
136 'href' => $template['link'],
137 );
138
139 if ( ! $template['is_custom'] ) {
140 $utm = array(
141 'medium' => 'form-templates',
142 'content' => $template['slug'],
143 );
144
145 $attributes['href'] = FrmAppHelper::admin_upgrade_link( $utm, $attributes['href'] );
146 $attributes['target'] = '_blank';
147 }
148
149 FrmAppHelper::array_to_html_params( $attributes, true );
150 }
151
152 /**
153 * Show the CTA to upgrade or renew.
154 *
155 * @since 6.7
156 *
157 * @param array $args {
158 * @type string $upgrade_link Upgrade link URL.
159 * @type string $renew_link Renew link URL.
160 * }
161 * @return void
162 */
163 public static function show_upgrade_renew_cta( $args ) {
164 // Show 'renew' banner for expired users.
165 if ( $args['expired'] ) {
166 FrmTipsHelper::show_admin_cta(
167 array(
168 'title' => esc_html__( 'Get Super Powers with Pre-built Forms', 'formidable' ),
169 'description' => esc_html__( 'Unleash the potential of hundreds of form templates and save precious time. Renew today for unparalleled form-building speed.', 'formidable' ),
170 'link_text' => esc_html__( 'Renew Now', 'formidable' ),
171 'link_url' => $args['renew_link'],
172 'id' => 'frm-renew-subscription-banner',
173 )
174 );
175 return;
176 }
177
178 // Show 'upgrade' banner for non-elite users.
179 if ( ! in_array( FrmAddonsController::license_type(), array( 'elite', 'business' ), true ) ) {
180 FrmTipsHelper::show_admin_cta(
181 array(
182 'title' => sprintf(
183 /* translators: %1$s: Open span tag, %2$s: Close span tag */
184 esc_html__( 'Get Super Powers with %1$s%2$s More Pre-built Forms', 'formidable' ) . ' 🦸',
185 '<span class="frm-form-templates-extra-templates-count">',
186 '</span>'
187 ),
188 'description' => esc_html__( 'Unleash the potential of hundreds of additional form templates and save precious time. Upgrade today for unparalleled form-building capabilities.', 'formidable' ),
189 'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ),
190 'link_url' => $args['upgrade_link'],
191 'id' => 'frm-upgrade-banner',
192 )
193 );
194 }
195 }
196 }
197