PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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
← All changes | classes/controllers/FrmFormsController.php +185 -9 6.32 → trunk View file →
@@ -283,8 +283,12 @@
283 283 if ( $antispam_is_on !== $antispam_was_on ) {
284 284 FrmAntiSpam::clear_caches();
285 285 }
286 286
287 + // Handle captcha field inclusion
288 + $include_captcha = isset( $_POST['frm_include_captcha'] ) && '1' === $_POST['frm_include_captcha']; // phpcs:ignore WordPress.Security.NonceVerification.Missing
289 + self::handle_captcha_field( $id, $include_captcha );
290 +
287 291 $message = __( 'Settings Successfully Updated', 'formidable' );
288 292
289 293 self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
290 294 }
@@ -299,8 +303,46 @@
299 303 return ! empty( $form->options['antispam'] );
300 304 }
301 305
302 306 /**
307 + * Handle captcha field inclusion in form
308 + *
309 + * @since 6.33
310 + *
311 + * @param int $form_id Form ID.
312 + * @param bool $include_captcha Whether to include captcha field.
313 + *
314 + * @return void
315 + */
316 + private static function handle_captcha_field( $form_id, $include_captcha ) {
317 + $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude' );
318 + $captcha_field_id = 0;
319 + $submit_field_order = 0;
320 +
321 + foreach ( $form_fields as $field ) {
322 + if ( 'captcha' === $field->type ) {
323 + $captcha_field_id = $field->id;
324 + break;
325 + }
326 +
327 + if ( 'submit' === $field->type ) {
328 + $submit_field_order = $field->field_order;
329 + }
330 + }
331 +
332 + if ( $include_captcha && ! $captcha_field_id ) {
333 + // Create captcha field just before submit button
334 + $field_values = FrmFieldsHelper::setup_new_vars( 'captcha', $form_id );
335 + $field_values['name'] = __( 'Captcha', 'formidable' );
336 + $field_values['field_order'] = $submit_field_order > 0 ? $submit_field_order - 1 : 0;
337 + FrmField::create( $field_values );
338 + } elseif ( ! $include_captcha && $captcha_field_id ) {
339 + // Delete captcha field
340 + FrmField::destroy( $captcha_field_id );
341 + }
342 + }
343 +
344 + /**
303 345 * @param array $values
304 346 *
305 347 * @return void
306 348 */
@@ -1545,8 +1587,13 @@
1545 1587 'function' => array( 'FrmFormActionsController', 'email_settings' ),
1546 1588 'id' => 'frm_notification_settings',
1547 1589 'icon' => 'frmfont frm_notification_check_icon',
1548 1590 ),
1591 + 'spam' => array(
1592 + 'name' => __( 'Spam', 'formidable' ),
1593 + 'function' => array( self::class, 'spam_settings' ),
1594 + 'icon' => 'frmfont frm_shield_check2_icon',
1595 + ),
1549 1596 'permissions' => array(
1550 1597 'name' => __( 'Form Permissions', 'formidable' ),
1551 1598 'icon' => 'frmfont frm_lock_closed2_icon',
1552 1599 'html_class' => 'frm_show_upgrade_tab frm_noallow',
@@ -1664,18 +1711,16 @@
1664 1711 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-advanced.php';
1665 1712 }
1666 1713
1667 1714 /**
1715 + * @since 6.33
1716 + *
1668 1717 * @param array $values
1669 1718 *
1670 1719 * @return void
1671 1720 */
1672 - public static function render_spam_settings( $values ) {
1673 - if ( function_exists( 'akismet_http_post' ) ) {
1674 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1675 - }
1676 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/stopforumspam.php';
1677 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/antispam.php';
1721 + public static function spam_settings( $values ) {
1722 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings.php';
1678 1723 }
1679 1724
1680 1725 /**
1681 1726 * @since 4.0
@@ -1753,9 +1798,9 @@
1753 1798 $linked_forms = array();
1754 1799 $col = 'one';
1755 1800 $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1756 1801 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1757 - $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1802 + $entry_shortcodes = self::get_shortcode_helpers( $settings_tab, $form_id );
1758 1803 $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1759 1804
1760 1805 if ( 'default' === $template_path || ! file_exists( $template_path ) ) {
1761 1806 include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
@@ -1806,8 +1851,126 @@
1806 1851 return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
1807 1852 }
1808 1853
1809 1854 /**
1855 + * Adds a shortcode for each part of a multi-part field to the field shortcode list,
1856 + * so a single part can be used on its own, like [25 show=first] for a Name field.
1857 + *
1858 + * @since 6.35
1859 + *
1860 + * @param array $atts Includes 'field'.
1861 + *
1862 + * @return void
1863 + */
1864 + public static function field_part_shortcodes( $atts ) {
1865 + $field = $atts['field'];
1866 +
1867 + foreach ( self::get_field_parts( $field ) as $part => $label ) {
1868 + FrmFormsHelper::insert_opt_html(
1869 + array(
1870 + 'id' => $field->id . ' show=' . $part,
1871 + 'key' => $field->field_key . ' show=' . $part,
1872 + // Keep the part label and the option out of the truncated text so they stay readable.
1873 + 'key_label' => $field->field_key,
1874 + 'key_suffix' => ' show=' . $part,
1875 + 'name' => $field->name,
1876 + 'name_suffix' => ' (' . $label . ')',
1877 + 'type' => $field->type,
1878 + 'class' => 'frm-customize-list dropdown-item',
1879 + )
1880 + );
1881 + unset( $part, $label );
1882 + }
1883 + }
1884 +
1885 + /**
1886 + * Gets the parts of a multi-part field that can be shown on their own with a show= shortcode option.
1887 + *
1888 + * @since 6.35
1889 + *
1890 + * @param stdClass $field
1891 + *
1892 + * @return array Part labels keyed by the show= option value.
1893 + */
1894 + private static function get_field_parts( $field ) {
1895 + $parts = array();
1896 +
1897 + if ( 'name' === $field->type ) {
1898 + $parts = self::get_name_field_parts( $field );
1899 + } elseif ( 'address' === $field->type ) {
1900 + $parts = self::get_address_field_parts( $field );
1901 + }
1902 +
1903 + /**
1904 + * Allows add-ons to add the parts of their own multi-part fields.
1905 + *
1906 + * @since 6.35
1907 + *
1908 + * @param array $parts Part labels keyed by the show= option value.
1909 + * @param stdClass $field The field the parts belong to.
1910 + */
1911 + return apply_filters( 'frm_field_parts_for_shortcodes', $parts, $field );
1912 + }
1913 +
1914 + /**
1915 + * Gets the parts of a Name field that are in use. Only the parts included in the
1916 + * selected name layout hold a value, so the rest would always show as blank.
1917 + *
1918 + * @since 6.35
1919 + *
1920 + * @param stdClass $field
1921 + *
1922 + * @return array Part labels keyed by the show= option value, in layout order.
1923 + */
1924 + private static function get_name_field_parts( $field ) {
1925 + $labels = array(
1926 + 'first' => __( 'First', 'formidable' ),
1927 + 'middle' => __( 'Middle', 'formidable' ),
1928 + 'last' => __( 'Last', 'formidable' ),
1929 + );
1930 + $layout = FrmField::get_option( $field, 'name_layout' );
1931 +
1932 + if ( ! $layout ) {
1933 + $layout = 'first_last';
1934 + }
1935 +
1936 + // The layout option names the parts in use, in display order, like first_middle_last.
1937 + $parts = array();
1938 +
1939 + foreach ( explode( '_', $layout ) as $part ) {
1940 + if ( isset( $labels[ $part ] ) ) {
1941 + $parts[ $part ] = $labels[ $part ];
1942 + }
1943 + unset( $part );
1944 + }
1945 +
1946 + return $parts;
1947 + }
1948 +
1949 + /**
1950 + * Gets the parts of an Address field that are in use. The address type decides which
1951 + * parts are on the form, so the rest would always show as blank.
1952 + *
1953 + * @since 6.35
1954 + *
1955 + * @param stdClass $field
1956 + *
1957 + * @return array Part labels keyed by the show= option value.
1958 + */
1959 + private static function get_address_field_parts( $field ) {
1960 + $parts = FrmFieldAddress::get_part_labels();
1961 + $address_type = FrmField::get_option( $field, 'address_type' );
1962 +
1963 + if ( in_array( $address_type, array( 'us', 'generic' ), true ) ) {
1964 + unset( $parts['country'] );
1965 + } elseif ( 'europe' === $address_type ) {
1966 + unset( $parts['state'] );
1967 + }
1968 +
1969 + return $parts;
1970 + }
1971 +
1972 + /**
1810 1973 * Get an array of the options to display in the advanced tab
1811 1974 * of the customization panel
1812 1975 *
1813 1976 * @since 2.0.6
@@ -1862,12 +2025,13 @@
1862 2025 *
1863 2026 * @since 2.0.6
1864 2027 *
1865 2028 * @param bool $settings_tab
2029 + * @param int $form_id
1866 2030 *
1867 2031 * @return array
1868 2032 */
1869 - private static function get_shortcode_helpers( $settings_tab ) {
2033 + private static function get_shortcode_helpers( $settings_tab, $form_id = 0 ) {
1870 2034 $entry_shortcodes = array(
1871 2035 'id' => __( 'Entry ID', 'formidable' ),
1872 2036 'key' => __( 'Entry Key', 'formidable' ),
1873 2037 'post_id' => __( 'Post ID', 'formidable' ),
@@ -1893,10 +2057,11 @@
1893 2057 * @since 2.0.6
1894 2058 *
1895 2059 * @param array $entry_shortcodes
1896 2060 * @param bool $settings_tab
2061 + * @param int $form_id
1897 2062 */
1898 - return apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
2063 + return apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab, $form_id );
1899 2064 }
1900 2065
1901 2066 /**
1902 2067 * Insert the form class setting into the form.
@@ -3753,6 +3918,17 @@
3753 3918 */
3754 3919 public static function create( $values = array() ) {
3755 3920 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
3756 3921 self::update( $values );
3922 + }
3923 +
3924 + /**
3925 + * @deprecated 6.33
3926 + *
3927 + * @param array $values
3928 + *
3929 + * @return void
3930 + */
3931 + public static function render_spam_settings( $values ) {
3932 + _deprecated_function( __METHOD__, '6.33' );
3757 3933 }
3758 3934 }