From e3ccb3c4e328dad9f2d363b4b823a6c04ed292ee Mon Sep 17 00:00:00 2001 From: Sandro Date: Sun, 17 Nov 2024 18:43:50 +0100 Subject: [PATCH] WPCasa Ninja Forms 2.0.1 --- README.txt | 4 ++ .../admin/class-wpsight-ninja-forms-admin.php | 15 ++-- wpcasa-ninja-forms.php | 68 ++++++++++++------- 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/README.txt b/README.txt index 17c1c63..d55190f 100644 --- a/README.txt +++ b/README.txt @@ -58,6 +58,10 @@ Starting with version 2.0 of WPCasa Ninja Forms we have dropped the support for 4. Ninja Forms form editor == Changelog == += 2.0.1 = +* fixed Ninja Form issue where required astrix does appear with escaped html tags +* fixed that the hidden field could not be pre-filled with the real estate agent's email (thank you to Jimmi08) +* added support for translation on [WordPress GlotPress](https://translate.wordpress.org/projects/wp-plugins/wpcasa-ninja-forms/) = 2.0.0 = * fixed guideline violations diff --git a/includes/admin/class-wpsight-ninja-forms-admin.php b/includes/admin/class-wpsight-ninja-forms-admin.php index f9fd204..a55c9e2 100644 --- a/includes/admin/class-wpsight-ninja-forms-admin.php +++ b/includes/admin/class-wpsight-ninja-forms-admin.php @@ -74,14 +74,17 @@ public function ninja_options( $options ): array { if( $form_id ) { $form_fields = array( '' => __( 'None', 'wpcasa-ninja-forms' ) ); - - foreach( Ninja_Forms()->form( absint( $form_id ) )->get_fields() as $key => $field ) { + + foreach( Ninja_Forms()->form( absint( $form_id ) )->get_fields() as $key => $field ) { $form_field_id = $field->get_id(); - - if( '_hidden' == $field->get_type() ) - $form_fields[ $form_field_id ] = $field['data']['label']; + + if( 'hidden' == $field->get_setting( 'type' ) ) { + + $form_fields[ $form_field_id ] = $field->get_setting( 'label' ); + + } } - + $options_ninja['ninja_listing_field_id'] = array( 'name' => __( 'Agent Email', 'wpcasa-ninja-forms' ), 'desc' => __( 'Select the hidden form field that contains the agent email.', 'wpcasa-ninja-forms' ), diff --git a/wpcasa-ninja-forms.php b/wpcasa-ninja-forms.php index 00a2451..3a2e3cb 100644 --- a/wpcasa-ninja-forms.php +++ b/wpcasa-ninja-forms.php @@ -11,7 +11,7 @@ * Plugin Name: WPCasa Ninja Forms * Plugin URI: https://wpcasa.com/downloads/wpcasa-ninja-forms * Description: Add support for Ninja Forms plugin (v3.0.34.1 or higher) to attach property details to the contact email sent from WPCasa listing pages. - * Version: 2.0.0 + * Version: 2.0.1 * Requires at least: 4.0 * Requires Plugins: wpcasa, ninja-forms * Requires PHP: 5.6 @@ -49,7 +49,7 @@ public function __construct() { if ( ! defined( 'WPSIGHT_DOMAIN' ) ) define( 'WPSIGHT_DOMAIN', 'wpcasa' ); - define( 'WPSIGHT_NINJA_FORMS_VERSION', '2.0.0' ); + define( 'WPSIGHT_NINJA_FORMS_VERSION', '2.0.1' ); define( 'WPSIGHT_NINJA_FORMS_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); define( 'WPSIGHT_NINJA_FORMS_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); @@ -59,14 +59,16 @@ public function __construct() { } // Actions - add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) ); add_action( 'template_redirect', array( $this, 'listing_form_display' ) ); - add_action( 'ninja_forms_display_pre_init', array( $this, 'listing_form_agent' ) ); - + // Remove Actions remove_action('init', 'ninja_forms_register_display_req_items'); + // Filters + add_filter( 'ninja_forms_display_form_settings', array( $this, 'decode_ninja_forms_display_form_settings' ), 10, 2); + add_filter( 'ninja_forms_display_fields', array( $this, 'listing_form_agent'), 10, 2 ); + } /** @@ -90,20 +92,24 @@ public static function init( $wpsight ) { } /** - * load_plugin_textdomain() - * - * Set up localization for this plugin - * loading the text domain. - * - * @uses load_plugin_textdomain() - * - * @since 1.0.0 + * decode_ninja_forms_display_form_settings() + * + * Fix Ninja Form issue with required fields asterix + * + * @param $settings + * @param $form_id + * + * @return mixed + * + * @since 2.0.1 */ + public function decode_ninja_forms_display_form_settings( $settings, $form_id ) { - public function load_plugin_textdomain() { - load_plugin_textdomain( 'wpcasa-ninja-forms', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); + $settings[ 'fieldsMarkedRequired' ] = html_entity_decode( $settings[ 'fieldsMarkedRequired' ] ); + + return $settings; } - + /** * frontend_scripts() * @@ -170,23 +176,35 @@ public function listing_form() { * on the settings page. * * @uses wpsight_get_option() - * @uses $ninja_forms_loading->update_field_value() * @uses get_the_author_meta() - * @uses antispambot() * * @since 1.0.0 + * @updated 2.0.1 */ - public function listing_form_agent( $form_id ) { - global $ninja_forms_loading; - + public function listing_form_agent( $fields, $form_id ) : array { + $_form_id = absint( wpsight_get_option( 'ninja_listing_form_id' ) ); $_field_id = absint( wpsight_get_option( 'ninja_listing_field_id' ) ); - - if( $_form_id && $_field_id && $_form_id == $form_id ) - $ninja_forms_loading->update_field_value( $_field_id, antispambot( get_the_author_meta( 'email' ) ) ); - + + if( !$_form_id || !$_field_id || $_form_id != $form_id ) { + return $fields; + } + + foreach( $fields as $key => $field ) { + + if( $_field_id == $field[ 'id' ] ) { + + $fields[ $key ][ 'value' ] = get_the_author_meta( 'email' ); + + } + + } + + return $fields; + } + /** * activation() *