Skip to content

Commit

Permalink
Updates to 2.7.16
Browse files Browse the repository at this point in the history
  • Loading branch information
Gravity Forms committed Oct 26, 2023
1 parent 62a53d0 commit 2599f45
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 93 deletions.
9 changes: 9 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### 2.7.16 | 2023-10-25
- Updated the API endpoint for telemetry data.
- Fixed a bug that causes values of checkbox fields to appear twice on the entry list page.
- Fixed a bug that prevents form block style settings from being applied.
- Fixed jQuery deprecation notices in the form preview for the following fields: email, product, total, and stripe fields, as well as some conditional logic.
- Fixed "undefined index" errors that sometimes appear when a form is embedded with a shortcode. Credit: The GravityKit team.
- AF: Updated the background processor to include additional logging statements around batch processing.
- API: Added a new JavaScript action hook [gform_post_set_field_property](https://docs.gravityforms.com/gform_post_set_field_property/) in the form editor to listen for field property changes.

### 2.7.15 | 2023-10-05
- Added a new global setting to select the default form theme. On new sites, "Orbital" will be the default theme.
- Added a 'theme' parameter to the Gravity Forms shortcode.
Expand Down
2 changes: 1 addition & 1 deletion form_display.php
Original file line number Diff line number Diff line change
Expand Up @@ -3571,7 +3571,7 @@ public static function get_form_init_scripts( $form ) {
"} " . //keep the space. needed to prevent plugins from replacing }} with ]}
"} );" .

"jQuery(document).bind('gform_post_conditional_logic', function(event, formId, fields, isInit){";
"jQuery(document).on('gform_post_conditional_logic', function(event, formId, fields, isInit){";
foreach ( $init_scripts as $init_script ) {
if ( $init_script['location'] == self::ON_CONDITIONAL_LOGIC ) {
$script_body .= $init_script['script'];
Expand Down
4 changes: 2 additions & 2 deletions gravityforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Gravity Forms
Plugin URI: https://gravityforms.com
Description: Easily create web forms and manage form entries within the WordPress admin.
Version: 2.7.15
Version: 2.7.16
Requires at least: 4.0
Requires PHP: 5.6
Author: Gravity Forms
Expand Down Expand Up @@ -245,7 +245,7 @@ class GFForms {
*
* @var string $version The version number.
*/
public static $version = '2.7.15';
public static $version = '2.7.16';

/**
* Handles background upgrade tasks.
Expand Down
1 change: 0 additions & 1 deletion includes/fields/class-gf-field-checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ public function get_value_entry_list( $value, $entry, $field_id, $columns, $form

foreach ( $lead_field_keys as $input_id ) {
if ( is_numeric( $input_id ) && absint( $input_id ) == $field_id ) {
$items[] = GFCommon::selection_display( rgar( $entry, $input_id ), null, $entry['currency'], false );
$items[] = $this->get_selected_choice_output( rgar( $entry, $input_id ), rgar( $entry, 'currency' ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function handle() {

public function form_css_properties( $form_id, $settings, $block_settings, $form = array() ) {

if ( $form['styles'] === false ) {
if ( rgar( $form, 'styles' ) === false ) {
return array();
}

Expand Down
10 changes: 8 additions & 2 deletions includes/libraries/gf-background-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public function update( $key, $data ) {
if ( ! empty( $data ) ) {
$old_value = get_site_option( $key );
if ( $old_value ) {
GFCommon::log_debug( sprintf( '%s(): Updating batch %s. Tasks remaining: %d.', __METHOD__, $key, count( $data ) ) );
$data = array(
'blog_id' => get_current_blog_id(),
'data' => $data,
Expand All @@ -215,6 +216,7 @@ public function update( $key, $data ) {
* @return $this
*/
public function delete( $key ) {
GFCommon::log_debug( sprintf( '%s(): Deleting batch %s.', __METHOD__, $key ) );
delete_site_option( $key );

return $this;
Expand Down Expand Up @@ -432,15 +434,19 @@ protected function handle() {
}
}

GFCommon::log_debug( sprintf( '%s(): Processing batch for %s.', __METHOD__, $this->action ) );
GFCommon::log_debug( sprintf( '%s(): Processing batch %s; Tasks: %d.', __METHOD__, $batch->key, count( $batch->data ) ) );

foreach ( $batch->data as $key => $value ) {
$task_num = 0;

foreach ( $batch->data as $key => $value ) {
GFCommon::log_debug( sprintf( '%s(): Processing task %d.', __METHOD__, ++$task_num ) );
$task = $this->task( $value );

if ( $task !== false ) {
GFCommon::log_debug( sprintf( '%s(): Keeping task %d in batch.', __METHOD__, $task_num ) );
$batch->data[ $key ] = $task;
} else {
GFCommon::log_debug( sprintf( '%s(): Removing task %d from batch.', __METHOD__, $task_num ) );
unset( $batch->data[ $key ] );
}

Expand Down
44 changes: 29 additions & 15 deletions includes/telemetry/class-gf-telemetry-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ abstract class GF_Telemetry_Data {
*/
public $key = '';

/**
* @var string
*/
const TELEMETRY_ENDPOINT = 'https://in.gravity.io/';

/**
* Get the current telemetry data.
*
Expand Down Expand Up @@ -62,7 +67,7 @@ public static function save_data( GF_Telemetry_Data $data ) {
$existing_data['events'][] = $data;
}

update_option( 'gf_telemetry_data', $existing_data );
update_option( 'gf_telemetry_data', $existing_data, false );
}

/**
Expand All @@ -82,24 +87,33 @@ public static function take_snapshot() {
*
* @since 2.8
*
* @param array $data The data to send.
* @param string $endpoint The endpoint to send the data to.
* @param array $entries The data to send.
*
* @return array|WP_Error
*/
public static function send_data( $data, $endpoint = 'telemetry' ) {

$options = array(
'headers' => array(
'referrer' => 'GF_Telemetry',
'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),
'User-Agent' => 'WordPress/' . get_bloginfo( 'version' ),
),
'method' => 'POST',
'timeout' => 15,
'body' => $data,
public static function send_data( $entries ) {
// allow overriding the endpoint to use the local or staging environment for testing purposes.
$endpoint = defined( 'GF_TELEMETRY_ENDPOINT' ) ? GF_TELEMETRY_ENDPOINT : self::TELEMETRY_ENDPOINT;
$site_url = get_site_url();
$data = array(
'license_key_md5' => md5( get_option( 'rg_gforms_key', '' ) ),
'site_url' => $site_url,
'product' => 'gravityforms',
'tag' => 'system_report',
'data' => $entries,
);

return GFCommon::post_to_manager( $endpoint, 'nocache=1', $options );
return wp_remote_post(
$endpoint . 'api/telemetry_data_bulk',
array(
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => sha1( $site_url ),
),
'method' => 'POST',
'data_format' => 'body',
'body' => json_encode( $data ),
)
);
}
}
42 changes: 14 additions & 28 deletions includes/telemetry/class-gf-telemetry-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,29 @@ class GF_Telemetry_Processor extends \GF_Background_Process {
*/
protected function task( $batch ) {

if ( ! isset( $batch['data'] ) ) {
\GFCommon::log_debug( __METHOD__ . sprintf( '(): Batch data is missing. Aborting sending telemetry data.' ) );
return false;
if ( ! is_array( $batch ) ) {
$batch = array( $batch );
}

$raw_response = null;
if ( is_array( $batch['data'] ) ) {
\GFCommon::log_debug( __METHOD__ . sprintf( '(): Processing a batch of %d telemetry events.', count( $batch['data'] ) ) );
$data = array();
foreach ( $batch['data'] as $item ) {
\GFCommon::log_debug( __METHOD__ . sprintf( '(): Processing a batch of %d telemetry data.', count( $batch ) ) );
$data = array();
foreach ( $batch as $item ) {

if ( ! is_object( $item ) || ! property_exists( $item, 'data' ) ) {
continue;
}

$data[] = $item->data;
}
$raw_response = GF_Telemetry_Data::send_data( $data );
} else {
\GFCommon::log_debug( __METHOD__ . sprintf( '(): Processing a batch with snapshot data.' ) );

if ( ! is_object( $batch['data'] ) || ! property_exists( $batch['data'], 'data' ) ) {
\GFCommon::log_debug( __METHOD__ . sprintf( '(): Snapshot data is missing. Aborting sending telemetry data.' ) );
return false;
if ( ! is_object( $item ) || ! property_exists( $item, 'data' ) ) {
continue;
}

// snapshot data is sent to a different endpoint.
$raw_response = GF_Telemetry_Data::send_data( $batch['data']->data, 'version.php' );
}

if ( ! is_array( $batch['data'] ) ) {
$batch['data'] = array( $batch['data'] );
// attach type & tag, required by the telemetry API.
$item->data['type'] = $item->key === 'snapshot' ? 'snapshot' : 'event';
$item->data['tag'] = $item->key;
$data[] = $item->data;
}
$raw_response = GF_Telemetry_Data::send_data( $data );

foreach ( $batch['data'] as $item ) {
foreach ( $batch as $item ) {
if ( ! is_object( $item ) ) {
\GFCommon::log_debug( __METHOD__ . sprintf( '(): Snapshot data is missing. Aborting running data_sent method on this entry.' ) );
\GFCommon::log_debug( __METHOD__ . sprintf( '(): Telemetry data is missing. Aborting running data_sent method on this entry.' ) );
continue;
}
$classname = get_class( $item );
Expand Down
25 changes: 13 additions & 12 deletions includes/telemetry/class-gf-telemetry-service-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ public function init( GF_Service_Container $container ) {
}

/**
* Enqueue telemetry batches to be processed in the background.
* Enqueue batches of telemetry events to be processed in the background.
*
* @since
*
* @return void
*/
public function enqueue_telemetry_batches() {
// Only run once a week.
$last_run = get_option( 'gf_last_telemetry_run', 0 );
$current_time = time();
if ( $current_time - $last_run < 60 * 60 * 24 * 7 ) {
return;
}
update_option( 'gf_last_telemetry_run', $current_time );

\GFCommon::log_debug( __METHOD__ . sprintf( '(): Enqueuing telemetry batches' ) );
GF_Telemetry_Data::take_snapshot();

Expand All @@ -62,20 +70,12 @@ public function enqueue_telemetry_batches() {
$snapshot = $full_telemetry_data['snapshot'];

// Enqueue the snapshot first, alone, to be sent to its own endpoint.
$processor->push_to_queue(
array(
'data' => $snapshot,
)
);
$processor->push_to_queue( $snapshot );
$processor->save()->dispatch();

$full_telemetry_data = array_chunk( $full_telemetry_data['events'], self::BATCH_SIZE, true );
foreach ( $full_telemetry_data as $batch ) {
$processor->push_to_queue(
array(
'data' => $batch,
)
);
$processor->push_to_queue( $batch );
$processor->save()->dispatch();
}

Expand All @@ -85,7 +85,8 @@ public function enqueue_telemetry_batches() {
array(
'snapshot' => $snapshot,
'events' => array(),
)
),
false
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions js/conditional_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ function gf_do_action(action, targetId, useAnimation, defaultValues, isInit, cal

if(useAnimation && !isInit){
if($target.length > 0){
$target.find(':input:hidden:not(.gf-default-disabled)').removeAttr( 'disabled' );
$target.find(':input:hidden:not(.gf-default-disabled)').prop( 'disabled', false );
if ( $target.is( 'input[type="submit"]' ) || $target.hasClass( 'gform_next_button' ) ) {
$target.removeAttr( 'disabled' ).css( 'display', '' );
$target.prop( 'disabled', false ).css( 'display', '' );
$target.attr( 'data-conditional-logic', 'hidden' );
if ( '1' == gf_legacy.is_legacy ) {
// for legacy markup, remove screen reader class.
Expand All @@ -460,11 +460,11 @@ function gf_do_action(action, targetId, useAnimation, defaultValues, isInit, cal
if ( display == '' || display == 'none' ){
display = '1' === gf_legacy.is_legacy ? 'list-item' : 'block';
}
$target.find(':input:hidden:not(.gf-default-disabled)').removeAttr( 'disabled' ).attr( 'data-conditional-logic', 'visible' );
$target.find(':input:hidden:not(.gf-default-disabled)').prop( 'disabled', false ).attr( 'data-conditional-logic', 'visible' );

// Handle conditional submit and next buttons.
if ( $target.is( 'input[type="submit"]' ) || $target.hasClass( 'gform_next_button' ) ) {
$target.removeAttr( 'disabled' ).css( 'display', '' );
$target.prop( 'disabled', false ).css( 'display', '' );
$target.attr( 'data-conditional-logic', 'visible' );
if ( '1' == gf_legacy.is_legacy ) {
// for legacy markup, remove screen reader class.
Expand Down Expand Up @@ -614,7 +614,7 @@ function gf_reset_to_default(targetId, defaultValue){
if(radio_button_name == "gf_other_choice"){
val = element.attr("value");
}
else if( jQuery.isArray( defaultValue ) && ! element.is( 'select[multiple]' ) ) {
else if( Array.isArray( defaultValue ) && ! element.is( 'select[multiple]' ) ) {
val = defaultValue[target_index];
}
else if(jQuery.isPlainObject(defaultValue)){
Expand Down
Loading

0 comments on commit 2599f45

Please sign in to comment.