Plugin Directory

Changeset 2848034


Ignore:
Timestamp:
01/13/2023 03:47:51 PM (3 years ago)
Author:
gravitywp
Message:

Bump GravityWP - Count to version 0.9.9. PHP 8+ compatibility for calculations.

Location:
gravitywp-count
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • gravitywp-count/trunk/gravitywp-count.php

    r2734660 r2848034  
    55 * Description: Adds a shortcode to count, filter and display Gravity Forms entries or the total of a number field in multiple entries.
    66 * Author: GravityWP
    7  * Version: 0.9.8
     7 * Version: 0.9.9
    88 * Author URI: https://gravitywp.com/add-on/count/
    99 * License: GPL2
     
    1212if ( class_exists( 'GFForms' ) ) {
    1313
     14    /**
     15     * gravitywp_count_func.
     16     *
     17     * @param   array<mixed>    $atts       
     18     * @param   string|null $content    Default: null
     19     * @return  string
     20     */
    1421    function gravitywp_count_func( $atts, $content = null ) {
    1522        $atts = shortcode_atts(
     
    145152            $search_criteria['field_filters'][] = array(
    146153                'key'   => 'is_starred',
    147                 'value' => true,
     154                'value' => 1,
    148155            );
    149156        }
     
    151158            $search_criteria['field_filters'][] = array(
    152159                'key'   => 'is_starred',
    153                 'value' => false,
     160                'value' => 0,
    154161            );
    155162        }
     
    158165            $search_criteria['field_filters'][] = array(
    159166                'key'   => 'is_read',
    160                 'value' => true,
     167                'value' => 1,
    161168            );
    162169        }
     
    164171            $search_criteria['field_filters'][] = array(
    165172                'key'   => 'is_read',
    166                 'value' => false,
     173                'value' => 0,
    167174            );
    168175        }
     
    171178            if ( $is_approved === 'yes' ) {
    172179                $search_criteria['field_filters'][] = array(
    173                     'key'   => GravityView_Entry_Approval::meta_key,
    174                     'value' => GravityView_Entry_Approval_Status::APPROVED,
     180                    'key'   => 'is_approved', // GravityView_Entry_Approval::meta_key.
     181                    'value' => 1, // GravityView_Entry_Approval_Status::APPROVED.
    175182                );
    176183            }
    177184            if ( $is_approved === 'no' ) {
    178185                $search_criteria['field_filters'][] = array(
    179                     'key'   => GravityView_Entry_Approval::meta_key,
     186                    'key'   => 'is_approved', // GravityView_Entry_Approval::meta_key.
    180187                    'is_approved',
    181                     'value' => GravityView_Entry_Approval_Status::DISAPPROVED,
     188                    'value' => 2, // GravityView_Entry_Approval_Status::DISAPPROVED.
    182189                );
    183190            }
     
    232239        $formids      = explode( ',', $formids );
    233240        $countentries = GFAPI::count_entries( $formids, $search_criteria );
    234         $raw_value    = $add_number + $countentries;
     241        $raw_value    = floatval( $add_number ) + $countentries;
    235242
    236243        $sorting = null;
     
    250257            $entries = GFAPI::get_entries( $formids, $search_criteria, $sorting, $paging );
    251258
    252             $raw_value = $add_number;
     259            if ( is_wp_error( $entries ) ) {
     260                return 'ERROR';
     261            }
     262
     263            $raw_value = floatval( $add_number );
    253264
    254265            // Loop through each entry and add number to count.
    255266            for ( $row = 0; $row < $countentries; $row ++ ) {
    256                 $raw_value += is_numeric( $entries[ $row ][ $number_field ] ) ? $entries[ $row ][ $number_field ] : 0;
     267                $raw_value += is_numeric( $entries[ $row ][ $number_field ] ) ? floatval( $entries[ $row ][ $number_field ] ) : 0;
    257268            }
    258269            // Apply multiplier to value.
    259             $raw_value *= $multiply;
     270            $raw_value *= floatval( $multiply );
    260271            // Format raw value.
    261272            $formatted_value = number_format( $raw_value, (int) $decimals, $dec_point, $thousands_sep );
    262273        } else {
    263274            // Apply multiplier to value.
    264             $raw_value *= $multiply;
     275            $raw_value *= floatval( $multiply );
    265276            // Format raw value.
    266             $formatted_value = number_format( $raw_value, '0', '.', $thousands_sep );
     277            $formatted_value = number_format( $raw_value, 0, '.', $thousands_sep );
    267278        }
    268279
     
    270281         * Apply filter for result from count.
    271282         *
    272          * @param str $formatted_value
    273          * @param str $raw_value
    274          * @param array $formids
    275          * @return str
     283         * @param string $formatted_value
     284         * @param float $raw_value
     285         * @param array<string> $formids
     286         * @return string
    276287         */
    277 
    278288        return apply_filters( 'gwp_count_result', $formatted_value, $raw_value, $formids );
    279289    }
  • gravitywp-count/trunk/readme.txt

    r2734660 r2848034  
    44Tags: gravity forms, number field, count, form, forms, gravity form
    55Requires at least: 3.0.1
    6 Tested up to: 5.9
    7 Stable tag: 0.9.8
     6Tested up to: 6.1
     7Stable tag: 0.9.9
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3232
    3333== Changelog ==
     34
     35= 0.9.9 =
     36* PHP 8+ compatibility for calculations.
    3437
    3538= 0.9.8 =
Note: See TracChangeset for help on using the changeset viewer.