PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
← All changes | includes/fields/class-charitable-field-sorter.php +20 -14 1.6.6 → 1.8.13 View file →
@@ -2,13 +2,13 @@
2 2 /**
3 3 * A class that is responsible for taking a set of fields and sorting them by priority.
4 4 *
5 5 * @package Charitable/Classes/Charitable_Field_Sorter
6 - * @author Eric Daams
7 - * @copyright Copyright (c) 2018, Studio 164a
6 + * @author David Bisset
7 + * @copyright Copyright (c) 2023, WP Charitable LLC
8 8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 9 * @since 1.6.0
10 - * @version 1.6.0
10 + * @version 1.6.27
11 11 */
12 12
13 13 // Exit if accessed directly.
14 14 if ( ! defined( 'ABSPATH' ) ) {
@@ -76,18 +76,14 @@
76 76 * @param Charitable_Field $field The field to set the priority for.
77 77 * @return void
78 78 */
79 79 public function set_field_priority( $field ) {
80 - $property = $this->property;
81 80 $settings = $field->{$this->property};
82 81
83 - /* The field was defined with a priority, we don't need to do anything else. */
84 - if ( array_key_exists( 'priority', $settings ) ) {
85 - return;
86 - }
82 + /* The field was defined with a priority, so we will use that as default. */
83 + $default = array_key_exists( 'priority', $settings ) ? $settings['priority'] : false;
84 + $priority = $this->calculate_field_priority( $settings, $default );
87 85
88 - $priority = $this->calculate_field_priority( $settings );
89 -
90 86 $field->set( $this->property, 'priority', $priority );
91 87 }
92 88
93 89 /**
@@ -93,13 +89,15 @@
93 89 /**
94 90 * Determine a field's priority based on its `show_after` and `show_before` settings.
95 91 *
96 92 * @since 1.6.0
93 + * @since 1.6.27 Added $default parameter for priority.
97 94 *
98 - * @param array $settings The field settings.
95 + * @param array $settings The field settings.
96 + * @param int|false $default The default priority.
99 97 * @return int
100 98 */
101 - private function calculate_field_priority( $settings ) {
99 + private function calculate_field_priority( $settings, $default ) {
102 100 $after = $this->get_referenced_field( 'show_after', $settings );
103 101 $before = $this->get_referenced_field( 'show_before', $settings );
104 102
105 103 /* If the field was set to show after a certain field and before another field. */
@@ -106,16 +104,23 @@
106 104 if ( $after && $before ) {
107 105 return ( $after->{$this->property}['priority'] + $before->{$this->property}['priority'] ) / 2;
108 106 }
109 107
110 - if ( $after ) {
108 + $property = $this->property; // Store the property name in a variable.
109 +
110 + if ( $after && isset( $after->$property['priority'] ) && ! empty( $after->$property['priority'] ) ) {
111 111 return $after->{$this->property}['priority'] + 0.5;
112 112 }
113 113
114 - if ( $before ) {
114 + if ( $before && isset( $before->$property['priority'] ) && ! empty( $before->$property['priority'] ) ) {
115 115 return $before->{$this->property}['priority'] - 0.5;
116 116 }
117 117
118 + /* Neither show_after or show_before was set, so return the default if one was set. */
119 + if ( $default ) {
120 + return $default;
121 + }
122 +
118 123 /* Otherwise, put it 2 after the most recently registered field. */
119 124 foreach ( array_reverse( $this->fields ) as $field ) {
120 125 if ( array_key_exists( 'priority', $field->{$this->property} ) ) {
121 126 return $field->{$this->property}['priority'] + 2;
@@ -121,8 +126,9 @@
121 126 return $field->{$this->property}['priority'] + 2;
122 127 }
123 128 }
124 129
130 + /* Still no luck? Set priority to 2. */
125 131 return 2;
126 132 }
127 133
128 134 /**