| @@ -209,9 +209,9 @@ | ||
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | public static function get_sortable_classes( $col, $sort_col, $sort_dir ) { |
| 212 | 212 | echo ( $sort_col == $col ) ? 'sorted' : 'sortable'; |
| 213 | - echo ( $sort_col == $col && $sort_dir == 'desc' ) ? ' asc' : ' desc'; | |
| 213 | + echo ( $sort_col == $col && $sort_dir === 'desc' ) ? ' asc' : ' desc'; | |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
| 217 | 217 | * @since 3.0 |
| @@ -418,20 +418,20 @@ | ||
| 418 | 418 | /** |
| 419 | 419 | * @param string $loc |
| 420 | 420 | */ |
| 421 | 421 | public static function get_default_html( $loc ) { |
| 422 | - if ( $loc == 'submit' ) { | |
| 422 | + if ( $loc === 'submit' ) { | |
| 423 | 423 | $draft_link = self::get_draft_link(); |
| 424 | 424 | $start_over = self::get_start_over_shortcode(); |
| 425 | 425 | $default_html = <<<SUBMIT_HTML |
| 426 | -<div class="frm_submit"> | |
| 426 | +<div class="frm_submit frm_flex"> | |
| 427 | +<button class="frm_button_submit" type="submit" [button_action]>[button_label]</button> | |
| 427 | 428 | [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button] |
| 428 | -<button class="frm_button_submit" type="submit" [button_action]>[button_label]</button> | |
| 429 | 429 | $draft_link |
| 430 | 430 | $start_over |
| 431 | 431 | </div> |
| 432 | 432 | SUBMIT_HTML; |
| 433 | - } elseif ( $loc == 'before' ) { | |
| 433 | + } elseif ( $loc === 'before' ) { | |
| 434 | 434 | $default_html = <<<BEFORE_HTML |
| 435 | 435 | <legend class="frm_screen_reader">[form_name]</legend> |
| 436 | 436 | [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name] |
| 437 | 437 | [if form_description]<div class="frm_description">[form_description]</div>[/if form_description] |
| @@ -1183,9 +1183,9 @@ | ||
| 1183 | 1183 | |
| 1184 | 1184 | /** |
| 1185 | 1185 | * @since 3.0 |
| 1186 | 1186 | */ |
| 1187 | - private static function delete_trash_links( $id ) { | |
| 1187 | + public static function delete_trash_links( $id ) { | |
| 1188 | 1188 | $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) ); |
| 1189 | 1189 | $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id; |
| 1190 | 1190 | |
| 1191 | 1191 | return array( |
| @@ -1301,26 +1301,31 @@ | ||
| 1301 | 1301 | return $name; |
| 1302 | 1302 | } |
| 1303 | 1303 | |
| 1304 | 1304 | /** |
| 1305 | - * @param array $categories | |
| 1305 | + * Renders a template icon based on the given categories. | |
| 1306 | + * | |
| 1307 | + * @param array $categories The categories to render the icon for. | |
| 1306 | 1308 | * @param array $atts { |
| 1307 | - * @type string $html 'span' or 'div'. | |
| 1308 | - * @type boolean $bg Whether to add a bg color or not. | |
| 1309 | + * Optional. An array of attributes for rendering. | |
| 1310 | + * @type string $html 'span' or 'div'. Default 'span'. | |
| 1311 | + * @type boolean $bg Whether to add a background color or not. Default false. | |
| 1309 | 1312 | * } |
| 1310 | 1313 | * |
| 1311 | 1314 | * @return void |
| 1312 | 1315 | */ |
| 1313 | 1316 | public static function template_icon( $categories, $atts = array() ) { |
| 1317 | + // Define defaults. | |
| 1314 | 1318 | $defaults = array( |
| 1315 | - 'html' => 'span', | |
| 1316 | - 'bg' => false, | |
| 1319 | + 'bg' => true, | |
| 1317 | 1320 | ); |
| 1318 | 1321 | $atts = array_merge( $defaults, $atts ); |
| 1319 | 1322 | |
| 1323 | + // Filter out ignored categories. | |
| 1320 | 1324 | $ignore = self::ignore_template_categories(); |
| 1321 | 1325 | $categories = array_diff( $categories, $ignore ); |
| 1322 | 1326 | |
| 1327 | + // Define icons mapping. | |
| 1323 | 1328 | $icons = array( |
| 1324 | 1329 | 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ), |
| 1325 | 1330 | 'Post' => array( 'wordpress', 'rgb(0,160,210)' ), |
| 1326 | 1331 | 'User Registration' => array( 'register', 'var(--pink)' ), |
| @@ -1350,45 +1355,38 @@ | ||
| 1350 | 1355 | 'Signature' => array( 'signature' ), |
| 1351 | 1356 | '' => array( 'align_right' ), |
| 1352 | 1357 | ); |
| 1353 | 1358 | |
| 1354 | - $icons[ __( 'My Templates', 'formidable' ) ] = array( 'user', 'var(--orange)' ); | |
| 1355 | - | |
| 1359 | + // Determine the icon to be used. | |
| 1356 | 1360 | $icon = $icons['']; |
| 1357 | - | |
| 1358 | 1361 | if ( count( $categories ) === 1 ) { |
| 1359 | 1362 | $category = reset( $categories ); |
| 1360 | 1363 | $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon; |
| 1361 | 1364 | } elseif ( ! empty( $categories ) ) { |
| 1362 | - foreach ( $icons as $cat => $icon ) { | |
| 1363 | - if ( ! in_array( $cat, $categories ) ) { | |
| 1364 | - unset( $icons[ $cat ] ); | |
| 1365 | - } | |
| 1366 | - } | |
| 1365 | + $icons = array_intersect_key( $icons, array_flip( $categories ) ); | |
| 1367 | 1366 | $icon = reset( $icons ); |
| 1368 | 1367 | } |
| 1369 | 1368 | |
| 1370 | - $bg = isset( $icon[1] ) ? $icon[1] : ''; | |
| 1369 | + // Prepare variables for output. | |
| 1370 | + $icon_name = $icon[0]; | |
| 1371 | + $bg_color = isset( $icon[1] ) ? $icon[1] : ''; | |
| 1371 | 1372 | |
| 1372 | - if ( $atts['html'] === 'div' ) { | |
| 1373 | - echo '<div class="frm-category-icon frm-icon-wrapper" role="button"'; | |
| 1374 | - } else { | |
| 1375 | - echo '<span class="frm-inner-circle"'; | |
| 1373 | + // Render the icon. | |
| 1374 | + echo '<span class="frm-category-icon frm-icon-wrapper"'; | |
| 1375 | + if ( $bg_color && $atts['bg'] ) { | |
| 1376 | + echo ' style="background-color:' . esc_attr( $bg_color ) . '"'; | |
| 1376 | 1377 | } |
| 1377 | - echo empty( $bg ) || empty( $atts['bg'] ) ? '' : ' style="background-color:' . esc_attr( $bg ) . '"'; | |
| 1378 | 1378 | echo '>'; |
| 1379 | - | |
| 1380 | - FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon[0] . '_icon' ); | |
| 1381 | - echo '<span class="frm_hidden">'; | |
| 1382 | - FrmAppHelper::icon_by_class( 'frmfont frm_lock_icon' ); | |
| 1379 | + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' ); | |
| 1383 | 1380 | echo '</span>'; |
| 1384 | - echo '</' . esc_attr( $atts['html'] ) . '>'; | |
| 1385 | 1381 | } |
| 1386 | 1382 | |
| 1387 | 1383 | /** |
| 1384 | + * Retrieves the list of template categories to ignore. | |
| 1385 | + * | |
| 1388 | 1386 | * @since 4.03.01 |
| 1389 | 1387 | * |
| 1390 | - * @return array<string> | |
| 1388 | + * @return string[] Array of categories to ignore. | |
| 1391 | 1389 | */ |
| 1392 | 1390 | public static function ignore_template_categories() { |
| 1393 | 1391 | return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' ); |
| 1394 | 1392 | } |
| @@ -1393,9 +1391,15 @@ | ||
| 1393 | 1391 | return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' ); |
| 1394 | 1392 | } |
| 1395 | 1393 | |
| 1396 | 1394 | /** |
| 1395 | + * Get template install link. | |
| 1396 | + * | |
| 1397 | 1397 | * @since 4.02 |
| 1398 | + * | |
| 1399 | + * @param array $template Template details. | |
| 1400 | + * @param array $args Additional arguments. | |
| 1401 | + * @return array The link attributes. | |
| 1398 | 1402 | */ |
| 1399 | 1403 | public static function get_template_install_link( $template, $args ) { |
| 1400 | 1404 | $defaults = array( |
| 1401 | 1405 | 'class' => 'install-now', |
| @@ -1431,9 +1435,8 @@ | ||
| 1431 | 1435 | * |
| 1432 | 1436 | * @since 4.02.02 |
| 1433 | 1437 | * |
| 1434 | 1438 | * @param array $args |
| 1435 | - * | |
| 1436 | 1439 | * @return bool |
| 1437 | 1440 | */ |
| 1438 | 1441 | public static function plan_is_allowed( $args ) { |
| 1439 | 1442 | if ( empty( $args['license_type'] ) ) { |
| @@ -1439,20 +1442,22 @@ | ||
| 1439 | 1442 | if ( empty( $args['license_type'] ) ) { |
| 1440 | 1443 | return false; |
| 1441 | 1444 | } |
| 1442 | 1445 | |
| 1443 | - $included = $args['license_type'] === strtolower( $args['plan_required'] ); | |
| 1446 | + $plans = array( 'free', 'personal', 'business', 'elite' ); | |
| 1447 | + $license_type = strtolower( $args['license_type'] ); | |
| 1448 | + $plan_required = strtolower( $args['plan_required'] ); | |
| 1449 | + $included = $license_type === $plan_required; | |
| 1444 | 1450 | |
| 1445 | - $plans = array( 'free', 'personal', 'business', 'elite' ); | |
| 1446 | - if ( $included || ! in_array( strtolower( $args['plan_required'] ), $plans, true ) ) { | |
| 1451 | + if ( $included || ! in_array( $plan_required, $plans, true ) ) { | |
| 1447 | 1452 | return $included; |
| 1448 | 1453 | } |
| 1449 | 1454 | |
| 1450 | 1455 | foreach ( $plans as $plan ) { |
| 1451 | - if ( $included || $plan === $args['license_type'] ) { | |
| 1456 | + if ( $included || $plan === $license_type ) { | |
| 1452 | 1457 | break; |
| 1453 | 1458 | } |
| 1454 | - $included = $plan === strtolower( $args['plan_required'] ); | |
| 1459 | + $included = $plan === $plan_required; | |
| 1455 | 1460 | } |
| 1456 | 1461 | |
| 1457 | 1462 | return $included; |
| 1458 | 1463 | } |
| @@ -1457,16 +1462,8 @@ | ||
| 1457 | 1462 | return $included; |
| 1458 | 1463 | } |
| 1459 | 1464 | |
| 1460 | 1465 | /** |
| 1461 | - * @since 4.02 | |
| 1462 | - */ | |
| 1463 | - public static function template_install_html( $link, $class = '' ) { | |
| 1464 | - $link['class'] .= ' ' . $class; | |
| 1465 | - echo '<a ' . esc_attr( $link['href'] ) . '="' . esc_url( $link['url'] ) . '" class="' . esc_attr( $link['class'] ) . ' " aria-label="' . esc_attr( $link['label'] ) . '"' . ( $link['atts'] ? ' target="_blank" rel="noopener"' : '' ) . '>'; | |
| 1466 | - } | |
| 1467 | - | |
| 1468 | - /** | |
| 1469 | 1466 | * If a template or add-on cannot be installed, show a message |
| 1470 | 1467 | * about which plan is required. |
| 1471 | 1468 | * |
| 1472 | 1469 | * @since 4.0 |
| @@ -1671,34 +1668,8 @@ | ||
| 1671 | 1668 | ); |
| 1672 | 1669 | } |
| 1673 | 1670 | |
| 1674 | 1671 | /** |
| 1675 | - * Check an array of templates, determine how many the logged in user can use | |
| 1676 | - * | |
| 1677 | - * @param array $templates | |
| 1678 | - * @param array $args | |
| 1679 | - * @return int | |
| 1680 | - */ | |
| 1681 | - public static function available_count( $templates, $args ) { | |
| 1682 | - return array_reduce( | |
| 1683 | - $templates, | |
| 1684 | - function( $total, $template ) use ( $args ) { | |
| 1685 | - if ( ! empty( $template['url'] ) ) { | |
| 1686 | - return $total + 1; | |
| 1687 | - } | |
| 1688 | - | |
| 1689 | - $args['plan_required'] = self::get_plan_required( $template ); | |
| 1690 | - if ( self::plan_is_allowed( $args ) ) { | |
| 1691 | - return $total + 1; | |
| 1692 | - } | |
| 1693 | - | |
| 1694 | - return $total; | |
| 1695 | - }, | |
| 1696 | - 0 | |
| 1697 | - ); | |
| 1698 | - } | |
| 1699 | - | |
| 1700 | - /** | |
| 1701 | 1672 | * Make sure the field shortcodes in a url always add the sanitize_url=1 option if nothing is defined. |
| 1702 | 1673 | * This is to prevent some field characters like ', @, and | from being stripped from the redirect URL. |
| 1703 | 1674 | * |
| 1704 | 1675 | * @since 5.0.16 |
| @@ -1766,6 +1737,44 @@ | ||
| 1766 | 1737 | * @return bool |
| 1767 | 1738 | */ |
| 1768 | 1739 | public static function should_use_pro_for_ajax_submit() { |
| 1769 | 1740 | return is_callable( 'FrmProForm::is_ajax_on' ) && ! is_callable( 'FrmProFormsHelper::lite_supports_ajax_submit' ); |
| 1741 | + } | |
| 1742 | + | |
| 1743 | + /** | |
| 1744 | + * Outputs the appropriate button text in the publish box. | |
| 1745 | + * | |
| 1746 | + * @return void | |
| 1747 | + */ | |
| 1748 | + public static function publish_box_button_text() { | |
| 1749 | + $is_new_template = FrmAppHelper::simple_get( 'new_template' ); | |
| 1750 | + $action = FrmAppHelper::simple_get( 'frm_action' ); | |
| 1751 | + | |
| 1752 | + if ( ( 'edit' === $action || 'settings' === $action ) && $is_new_template ) { | |
| 1753 | + esc_html_e( 'Save', 'formidable' ); | |
| 1754 | + } else { | |
| 1755 | + esc_html_e( 'Update', 'formidable' ); | |
| 1756 | + } | |
| 1757 | + } | |
| 1758 | + | |
| 1759 | + /** | |
| 1760 | + * @since 4.02 | |
| 1761 | + * @deprecated x.x | |
| 1762 | + */ | |
| 1763 | + public static function template_install_html( $link, $class = '' ) { | |
| 1764 | + _deprecated_function( __METHOD__, 'x.x' ); | |
| 1765 | + } | |
| 1766 | + | |
| 1767 | + /** | |
| 1768 | + * Check an array of templates, determine how many the logged in user can use | |
| 1769 | + * | |
| 1770 | + * @deprecated x.x | |
| 1771 | + * | |
| 1772 | + * @param array $templates | |
| 1773 | + * @param array $args | |
| 1774 | + * @return int | |
| 1775 | + */ | |
| 1776 | + public static function available_count( $templates, $args ) { | |
| 1777 | + _deprecated_function( __METHOD__, 'x.x' ); | |
| 1778 | + return 0; | |
| 1770 | 1779 | } |
| 1771 | 1780 | } |