Skip to content

Commit

Permalink
WPCasa Ninja Forms 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
codestylist committed Nov 17, 2024
1 parent c99b79b commit e3ccb3c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 31 deletions.
4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions includes/admin/class-wpsight-ninja-forms-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
68 changes: 43 additions & 25 deletions wpcasa-ninja-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__ ) ) ) );

Expand All @@ -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 );

}

/**
Expand All @@ -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()
*
Expand Down Expand Up @@ -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()
*
Expand Down

0 comments on commit e3ccb3c

Please sign in to comment.