Completed
Pull Request — develop (#1713)
by Zack
17:42
created
includes/class-gravityview-gfformsmodel.php 3 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -6,184 +6,184 @@
 block discarded – undo
6 6
  */
7 7
 class GravityView_GFFormsModel extends GFFormsModel
8 8
 {
9
-    /**
10
-     * Make sure the method exists, regardless of GF version.
11
-     *
12
-     * @since 1.22.2
13
-     *
14
-     * @return string|false False if not set, version string otherwise
15
-     */
16
-    public static function get_database_version()
17
-    {
18
-        if (is_callable('parent::get_database_version')) {
19
-            return parent::get_database_version();
20
-        }
21
-
22
-        return get_option('gf_db_version');
23
-    }
24
-
25
-    /**
26
-     * Determines if the field value matches the conditional logic rule value.
27
-     *
28
-     * @since 1.22.3
29
-     *
30
-     * @param mixed                $field_value  The field value to be checked.
31
-     * @param mixed                $target_value The conditional logic rule value.
32
-     * @param string               $operation    The conditional logic rule operator.
33
-     * @param null|GF_Field|string $source_field The field the rule is based on, or the entry meta
34
-     * @param null|array           $rule         The conditional logic rule properties.
35
-     * @param null|array           $form         The current form.
36
-     *
37
-     * @return bool
38
-     */
39
-    public static function is_value_match($field_value, $target_value, $operation = 'is', $source_field = null, $rule = null, $form = null)
40
-    {
41
-        if (in_array($source_field, ['date_created', 'date_updated', 'payment_date'], true)) {
42
-            $field_value = is_int($field_value) ? $field_value : strtotime($field_value);
43
-            $target_value = is_int($target_value) ? $target_value : strtotime($target_value);
44
-        }
45
-
46
-        if ($source_field instanceof GF_Field && $source_field->type == 'date') {
47
-            $field_value = is_int($field_value) ? $field_value : strtotime($field_value);
48
-            $target_value = is_int($target_value) ? $target_value : strtotime($target_value);
49
-        }
50
-
51
-        if (in_array($_operation = str_replace(' ', '_', trim($operation)), ['in', 'not_in'])) {
52
-            return GVCommon::matches_operation((array) $field_value, (array) $target_value, $_operation);
53
-        }
54
-
55
-        return parent::is_value_match($field_value, $target_value, $operation, $source_field, $rule, $form);
56
-    }
57
-
58
-    /**
59
-     * Given information provided in an entry, get array of media IDs.
60
-     *
61
-     * This is necessary because GF doesn't expect to need to update post images, only to create them.
62
-     *
63
-     * @see GFFormsModel::create_post()
64
-     * @since 1.17
65
-     *
66
-     * @param array $form  Gravity Forms form array
67
-     * @param array $entry Gravity Forms entry array
68
-     *
69
-     * @return array Array of "Field ID" => "Media IDs"
70
-     */
71
-    public static function get_post_field_images($form, $entry)
72
-    {
73
-        $post_data = self::get_post_fields($form, $entry);
74
-
75
-        $media = get_attached_media('image', $entry['post_id']);
76
-
77
-        $post_images = [];
78
-
79
-        foreach ($media as $media_item) {
80
-            foreach ((array) $post_data['images'] as $post_data_item) {
81
-                if (
82
-                    \GV\Utils::get($post_data_item, 'title') === $media_item->post_title &&
83
-                    \GV\Utils::get($post_data_item, 'description') === $media_item->post_content &&
84
-                    \GV\Utils::get($post_data_item, 'caption') === $media_item->post_excerpt
85
-                ) {
86
-                    $post_images["{$post_data_item['field_id']}"] = $media_item->ID;
87
-                }
88
-            }
89
-        }
90
-
91
-        return $post_images;
92
-    }
93
-
94
-    /**
95
-     * Alias of GFFormsModel::get_post_fields(); just making it public.
96
-     *
97
-     * @see GFFormsModel::get_post_fields()
98
-     * @since 1.17
99
-     *
100
-     * @param array $form  Gravity Forms form array
101
-     * @param array $entry Gravity Forms entry array
102
-     *
103
-     * @return array
104
-     */
105
-    public static function get_post_fields($form, $entry)
106
-    {
107
-        $reflection = new ReflectionMethod('GFFormsModel', 'get_post_fields');
108
-
109
-        /**
110
-         * If the method changes to public, use Gravity Forms' method.
111
-         *
112
-         * @todo: If/when the method is public, remove the unneeded copied code.
113
-         */
114
-        if ($reflection->isPublic()) {
115
-            return parent::get_post_fields($form, $entry);
116
-        }
117
-
118
-        // It was private; let's make it public
119
-        $reflection->setAccessible(true);
120
-
121
-        return $reflection->invoke(new GFFormsModel(), $form, $entry);
122
-    }
123
-
124
-    /**
125
-     * Copied function from Gravity Forms plugin \GFFormsModel::copy_post_image since the method is private.
126
-     *
127
-     * @since 1.16.2
128
-     *
129
-     * @param string $url     URL of the post image to update
130
-     * @param int    $post_id ID of the post image to update
131
-     *
132
-     * @return array|bool Array with `file`, `url` and `type` keys. False: failed to copy file to final directory path.
133
-     */
134
-    public static function copy_post_image($url, $post_id)
135
-    {
136
-        $reflection = new ReflectionMethod('GFFormsModel', 'copy_post_image');
137
-
138
-        /**
139
-         * If the method changes to public, use Gravity Forms' method.
140
-         *
141
-         * @todo: If/when the method is public, remove the unneeded copied code.
142
-         */
143
-        if ($reflection->isPublic()) {
144
-            return parent::copy_post_image($url, $post_id);
145
-        }
146
-
147
-        // It was private; let's make it public
148
-        $reflection->setAccessible(true);
149
-
150
-        return $reflection->invoke(new GFFormsModel(), $url, $post_id);
151
-    }
152
-
153
-    /**
154
-     * Copied function from Gravity Forms plugin \GFFormsModel::media_handle_upload since the method is private.
155
-     *
156
-     * Note: The method became public in GF 1.9.17.7
157
-     *
158
-     * @see GFFormsModel::media_handle_upload
159
-     * @see GravityView_Edit_Entry_Render::maybe_update_post_fields
160
-     *
161
-     * @uses copy_post_image
162
-     * @uses wp_insert_attachment
163
-     * @uses wp_update_attachment_metadata
164
-     *
165
-     * @param string $url       URL of the post image to update
166
-     * @param int    $post_id   ID of the post image to update
167
-     * @param array  $post_data Array of data for the eventual attachment post type that is created using {@see wp_insert_attachment}. Supports `post_mime_type`, `guid`, `post_parent`, `post_title`, `post_content` keys.
168
-     *
169
-     * @return bool|int ID of attachment Post created. Returns false if file not created by copy_post_image
170
-     */
171
-    public static function media_handle_upload($url, $post_id, $post_data = [])
172
-    {
173
-        $reflection = new ReflectionMethod('GFFormsModel', 'media_handle_upload');
174
-
175
-        /**
176
-         * If the method changes to public, use Gravity Forms' method.
177
-         *
178
-         * @todo: If/when the method is public, remove the unneeded copied code.
179
-         */
180
-        if ($reflection->isPublic()) {
181
-            return parent::media_handle_upload($url, $post_id, $post_data);
182
-        }
183
-
184
-        // It was private; let's make it public
185
-        $reflection->setAccessible(true);
186
-
187
-        return $reflection->invoke(new GFFormsModel(), $url, $post_id, $post_data);
188
-    }
9
+	/**
10
+	 * Make sure the method exists, regardless of GF version.
11
+	 *
12
+	 * @since 1.22.2
13
+	 *
14
+	 * @return string|false False if not set, version string otherwise
15
+	 */
16
+	public static function get_database_version()
17
+	{
18
+		if (is_callable('parent::get_database_version')) {
19
+			return parent::get_database_version();
20
+		}
21
+
22
+		return get_option('gf_db_version');
23
+	}
24
+
25
+	/**
26
+	 * Determines if the field value matches the conditional logic rule value.
27
+	 *
28
+	 * @since 1.22.3
29
+	 *
30
+	 * @param mixed                $field_value  The field value to be checked.
31
+	 * @param mixed                $target_value The conditional logic rule value.
32
+	 * @param string               $operation    The conditional logic rule operator.
33
+	 * @param null|GF_Field|string $source_field The field the rule is based on, or the entry meta
34
+	 * @param null|array           $rule         The conditional logic rule properties.
35
+	 * @param null|array           $form         The current form.
36
+	 *
37
+	 * @return bool
38
+	 */
39
+	public static function is_value_match($field_value, $target_value, $operation = 'is', $source_field = null, $rule = null, $form = null)
40
+	{
41
+		if (in_array($source_field, ['date_created', 'date_updated', 'payment_date'], true)) {
42
+			$field_value = is_int($field_value) ? $field_value : strtotime($field_value);
43
+			$target_value = is_int($target_value) ? $target_value : strtotime($target_value);
44
+		}
45
+
46
+		if ($source_field instanceof GF_Field && $source_field->type == 'date') {
47
+			$field_value = is_int($field_value) ? $field_value : strtotime($field_value);
48
+			$target_value = is_int($target_value) ? $target_value : strtotime($target_value);
49
+		}
50
+
51
+		if (in_array($_operation = str_replace(' ', '_', trim($operation)), ['in', 'not_in'])) {
52
+			return GVCommon::matches_operation((array) $field_value, (array) $target_value, $_operation);
53
+		}
54
+
55
+		return parent::is_value_match($field_value, $target_value, $operation, $source_field, $rule, $form);
56
+	}
57
+
58
+	/**
59
+	 * Given information provided in an entry, get array of media IDs.
60
+	 *
61
+	 * This is necessary because GF doesn't expect to need to update post images, only to create them.
62
+	 *
63
+	 * @see GFFormsModel::create_post()
64
+	 * @since 1.17
65
+	 *
66
+	 * @param array $form  Gravity Forms form array
67
+	 * @param array $entry Gravity Forms entry array
68
+	 *
69
+	 * @return array Array of "Field ID" => "Media IDs"
70
+	 */
71
+	public static function get_post_field_images($form, $entry)
72
+	{
73
+		$post_data = self::get_post_fields($form, $entry);
74
+
75
+		$media = get_attached_media('image', $entry['post_id']);
76
+
77
+		$post_images = [];
78
+
79
+		foreach ($media as $media_item) {
80
+			foreach ((array) $post_data['images'] as $post_data_item) {
81
+				if (
82
+					\GV\Utils::get($post_data_item, 'title') === $media_item->post_title &&
83
+					\GV\Utils::get($post_data_item, 'description') === $media_item->post_content &&
84
+					\GV\Utils::get($post_data_item, 'caption') === $media_item->post_excerpt
85
+				) {
86
+					$post_images["{$post_data_item['field_id']}"] = $media_item->ID;
87
+				}
88
+			}
89
+		}
90
+
91
+		return $post_images;
92
+	}
93
+
94
+	/**
95
+	 * Alias of GFFormsModel::get_post_fields(); just making it public.
96
+	 *
97
+	 * @see GFFormsModel::get_post_fields()
98
+	 * @since 1.17
99
+	 *
100
+	 * @param array $form  Gravity Forms form array
101
+	 * @param array $entry Gravity Forms entry array
102
+	 *
103
+	 * @return array
104
+	 */
105
+	public static function get_post_fields($form, $entry)
106
+	{
107
+		$reflection = new ReflectionMethod('GFFormsModel', 'get_post_fields');
108
+
109
+		/**
110
+		 * If the method changes to public, use Gravity Forms' method.
111
+		 *
112
+		 * @todo: If/when the method is public, remove the unneeded copied code.
113
+		 */
114
+		if ($reflection->isPublic()) {
115
+			return parent::get_post_fields($form, $entry);
116
+		}
117
+
118
+		// It was private; let's make it public
119
+		$reflection->setAccessible(true);
120
+
121
+		return $reflection->invoke(new GFFormsModel(), $form, $entry);
122
+	}
123
+
124
+	/**
125
+	 * Copied function from Gravity Forms plugin \GFFormsModel::copy_post_image since the method is private.
126
+	 *
127
+	 * @since 1.16.2
128
+	 *
129
+	 * @param string $url     URL of the post image to update
130
+	 * @param int    $post_id ID of the post image to update
131
+	 *
132
+	 * @return array|bool Array with `file`, `url` and `type` keys. False: failed to copy file to final directory path.
133
+	 */
134
+	public static function copy_post_image($url, $post_id)
135
+	{
136
+		$reflection = new ReflectionMethod('GFFormsModel', 'copy_post_image');
137
+
138
+		/**
139
+		 * If the method changes to public, use Gravity Forms' method.
140
+		 *
141
+		 * @todo: If/when the method is public, remove the unneeded copied code.
142
+		 */
143
+		if ($reflection->isPublic()) {
144
+			return parent::copy_post_image($url, $post_id);
145
+		}
146
+
147
+		// It was private; let's make it public
148
+		$reflection->setAccessible(true);
149
+
150
+		return $reflection->invoke(new GFFormsModel(), $url, $post_id);
151
+	}
152
+
153
+	/**
154
+	 * Copied function from Gravity Forms plugin \GFFormsModel::media_handle_upload since the method is private.
155
+	 *
156
+	 * Note: The method became public in GF 1.9.17.7
157
+	 *
158
+	 * @see GFFormsModel::media_handle_upload
159
+	 * @see GravityView_Edit_Entry_Render::maybe_update_post_fields
160
+	 *
161
+	 * @uses copy_post_image
162
+	 * @uses wp_insert_attachment
163
+	 * @uses wp_update_attachment_metadata
164
+	 *
165
+	 * @param string $url       URL of the post image to update
166
+	 * @param int    $post_id   ID of the post image to update
167
+	 * @param array  $post_data Array of data for the eventual attachment post type that is created using {@see wp_insert_attachment}. Supports `post_mime_type`, `guid`, `post_parent`, `post_title`, `post_content` keys.
168
+	 *
169
+	 * @return bool|int ID of attachment Post created. Returns false if file not created by copy_post_image
170
+	 */
171
+	public static function media_handle_upload($url, $post_id, $post_data = [])
172
+	{
173
+		$reflection = new ReflectionMethod('GFFormsModel', 'media_handle_upload');
174
+
175
+		/**
176
+		 * If the method changes to public, use Gravity Forms' method.
177
+		 *
178
+		 * @todo: If/when the method is public, remove the unneeded copied code.
179
+		 */
180
+		if ($reflection->isPublic()) {
181
+			return parent::media_handle_upload($url, $post_id, $post_data);
182
+		}
183
+
184
+		// It was private; let's make it public
185
+		$reflection->setAccessible(true);
186
+
187
+		return $reflection->invoke(new GFFormsModel(), $url, $post_id, $post_data);
188
+	}
189 189
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
      */
16 16
     public static function get_database_version()
17 17
     {
18
-        if (is_callable('parent::get_database_version')) {
18
+        if ( is_callable( 'parent::get_database_version' ) ) {
19 19
             return parent::get_database_version();
20 20
         }
21 21
 
22
-        return get_option('gf_db_version');
22
+        return get_option( 'gf_db_version' );
23 23
     }
24 24
 
25 25
     /**
@@ -36,23 +36,23 @@  discard block
 block discarded – undo
36 36
      *
37 37
      * @return bool
38 38
      */
39
-    public static function is_value_match($field_value, $target_value, $operation = 'is', $source_field = null, $rule = null, $form = null)
39
+    public static function is_value_match( $field_value, $target_value, $operation = 'is', $source_field = null, $rule = null, $form = null )
40 40
     {
41
-        if (in_array($source_field, ['date_created', 'date_updated', 'payment_date'], true)) {
42
-            $field_value = is_int($field_value) ? $field_value : strtotime($field_value);
43
-            $target_value = is_int($target_value) ? $target_value : strtotime($target_value);
41
+        if ( in_array( $source_field, [ 'date_created', 'date_updated', 'payment_date' ], true ) ) {
42
+            $field_value = is_int( $field_value ) ? $field_value : strtotime( $field_value );
43
+            $target_value = is_int( $target_value ) ? $target_value : strtotime( $target_value );
44 44
         }
45 45
 
46
-        if ($source_field instanceof GF_Field && $source_field->type == 'date') {
47
-            $field_value = is_int($field_value) ? $field_value : strtotime($field_value);
48
-            $target_value = is_int($target_value) ? $target_value : strtotime($target_value);
46
+        if ( $source_field instanceof GF_Field && $source_field->type == 'date' ) {
47
+            $field_value = is_int( $field_value ) ? $field_value : strtotime( $field_value );
48
+            $target_value = is_int( $target_value ) ? $target_value : strtotime( $target_value );
49 49
         }
50 50
 
51
-        if (in_array($_operation = str_replace(' ', '_', trim($operation)), ['in', 'not_in'])) {
52
-            return GVCommon::matches_operation((array) $field_value, (array) $target_value, $_operation);
51
+        if ( in_array( $_operation = str_replace( ' ', '_', trim( $operation ) ), [ 'in', 'not_in' ] ) ) {
52
+            return GVCommon::matches_operation( (array)$field_value, (array)$target_value, $_operation );
53 53
         }
54 54
 
55
-        return parent::is_value_match($field_value, $target_value, $operation, $source_field, $rule, $form);
55
+        return parent::is_value_match( $field_value, $target_value, $operation, $source_field, $rule, $form );
56 56
     }
57 57
 
58 58
     /**
@@ -68,22 +68,22 @@  discard block
 block discarded – undo
68 68
      *
69 69
      * @return array Array of "Field ID" => "Media IDs"
70 70
      */
71
-    public static function get_post_field_images($form, $entry)
71
+    public static function get_post_field_images( $form, $entry )
72 72
     {
73
-        $post_data = self::get_post_fields($form, $entry);
73
+        $post_data = self::get_post_fields( $form, $entry );
74 74
 
75
-        $media = get_attached_media('image', $entry['post_id']);
75
+        $media = get_attached_media( 'image', $entry[ 'post_id' ] );
76 76
 
77
-        $post_images = [];
77
+        $post_images = [ ];
78 78
 
79
-        foreach ($media as $media_item) {
80
-            foreach ((array) $post_data['images'] as $post_data_item) {
79
+        foreach ( $media as $media_item ) {
80
+            foreach ( (array)$post_data[ 'images' ] as $post_data_item ) {
81 81
                 if (
82
-                    \GV\Utils::get($post_data_item, 'title') === $media_item->post_title &&
83
-                    \GV\Utils::get($post_data_item, 'description') === $media_item->post_content &&
84
-                    \GV\Utils::get($post_data_item, 'caption') === $media_item->post_excerpt
82
+                    \GV\Utils::get( $post_data_item, 'title' ) === $media_item->post_title &&
83
+                    \GV\Utils::get( $post_data_item, 'description' ) === $media_item->post_content &&
84
+                    \GV\Utils::get( $post_data_item, 'caption' ) === $media_item->post_excerpt
85 85
                 ) {
86
-                    $post_images["{$post_data_item['field_id']}"] = $media_item->ID;
86
+                    $post_images[ "{$post_data_item[ 'field_id' ]}" ] = $media_item->ID;
87 87
                 }
88 88
             }
89 89
         }
@@ -102,23 +102,23 @@  discard block
 block discarded – undo
102 102
      *
103 103
      * @return array
104 104
      */
105
-    public static function get_post_fields($form, $entry)
105
+    public static function get_post_fields( $form, $entry )
106 106
     {
107
-        $reflection = new ReflectionMethod('GFFormsModel', 'get_post_fields');
107
+        $reflection = new ReflectionMethod( 'GFFormsModel', 'get_post_fields' );
108 108
 
109 109
         /**
110 110
          * If the method changes to public, use Gravity Forms' method.
111 111
          *
112 112
          * @todo: If/when the method is public, remove the unneeded copied code.
113 113
          */
114
-        if ($reflection->isPublic()) {
115
-            return parent::get_post_fields($form, $entry);
114
+        if ( $reflection->isPublic() ) {
115
+            return parent::get_post_fields( $form, $entry );
116 116
         }
117 117
 
118 118
         // It was private; let's make it public
119
-        $reflection->setAccessible(true);
119
+        $reflection->setAccessible( true );
120 120
 
121
-        return $reflection->invoke(new GFFormsModel(), $form, $entry);
121
+        return $reflection->invoke( new GFFormsModel(), $form, $entry );
122 122
     }
123 123
 
124 124
     /**
@@ -131,23 +131,23 @@  discard block
 block discarded – undo
131 131
      *
132 132
      * @return array|bool Array with `file`, `url` and `type` keys. False: failed to copy file to final directory path.
133 133
      */
134
-    public static function copy_post_image($url, $post_id)
134
+    public static function copy_post_image( $url, $post_id )
135 135
     {
136
-        $reflection = new ReflectionMethod('GFFormsModel', 'copy_post_image');
136
+        $reflection = new ReflectionMethod( 'GFFormsModel', 'copy_post_image' );
137 137
 
138 138
         /**
139 139
          * If the method changes to public, use Gravity Forms' method.
140 140
          *
141 141
          * @todo: If/when the method is public, remove the unneeded copied code.
142 142
          */
143
-        if ($reflection->isPublic()) {
144
-            return parent::copy_post_image($url, $post_id);
143
+        if ( $reflection->isPublic() ) {
144
+            return parent::copy_post_image( $url, $post_id );
145 145
         }
146 146
 
147 147
         // It was private; let's make it public
148
-        $reflection->setAccessible(true);
148
+        $reflection->setAccessible( true );
149 149
 
150
-        return $reflection->invoke(new GFFormsModel(), $url, $post_id);
150
+        return $reflection->invoke( new GFFormsModel(), $url, $post_id );
151 151
     }
152 152
 
153 153
     /**
@@ -168,22 +168,22 @@  discard block
 block discarded – undo
168 168
      *
169 169
      * @return bool|int ID of attachment Post created. Returns false if file not created by copy_post_image
170 170
      */
171
-    public static function media_handle_upload($url, $post_id, $post_data = [])
171
+    public static function media_handle_upload( $url, $post_id, $post_data = [ ] )
172 172
     {
173
-        $reflection = new ReflectionMethod('GFFormsModel', 'media_handle_upload');
173
+        $reflection = new ReflectionMethod( 'GFFormsModel', 'media_handle_upload' );
174 174
 
175 175
         /**
176 176
          * If the method changes to public, use Gravity Forms' method.
177 177
          *
178 178
          * @todo: If/when the method is public, remove the unneeded copied code.
179 179
          */
180
-        if ($reflection->isPublic()) {
181
-            return parent::media_handle_upload($url, $post_id, $post_data);
180
+        if ( $reflection->isPublic() ) {
181
+            return parent::media_handle_upload( $url, $post_id, $post_data );
182 182
         }
183 183
 
184 184
         // It was private; let's make it public
185
-        $reflection->setAccessible(true);
185
+        $reflection->setAccessible( true );
186 186
 
187
-        return $reflection->invoke(new GFFormsModel(), $url, $post_id, $post_data);
187
+        return $reflection->invoke( new GFFormsModel(), $url, $post_id, $post_data );
188 188
     }
189 189
 }
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -4,8 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  * @since 1.16.2
6 6
  */
7
-class GravityView_GFFormsModel extends GFFormsModel
8
-{
7
+class GravityView_GFFormsModel extends GFFormsModel {
9 8
     /**
10 9
      * Make sure the method exists, regardless of GF version.
11 10
      *
@@ -13,8 +12,7 @@  discard block
 block discarded – undo
13 12
      *
14 13
      * @return string|false False if not set, version string otherwise
15 14
      */
16
-    public static function get_database_version()
17
-    {
15
+    public static function get_database_version() {
18 16
         if (is_callable('parent::get_database_version')) {
19 17
             return parent::get_database_version();
20 18
         }
@@ -36,8 +34,7 @@  discard block
 block discarded – undo
36 34
      *
37 35
      * @return bool
38 36
      */
39
-    public static function is_value_match($field_value, $target_value, $operation = 'is', $source_field = null, $rule = null, $form = null)
40
-    {
37
+    public static function is_value_match($field_value, $target_value, $operation = 'is', $source_field = null, $rule = null, $form = null) {
41 38
         if (in_array($source_field, ['date_created', 'date_updated', 'payment_date'], true)) {
42 39
             $field_value = is_int($field_value) ? $field_value : strtotime($field_value);
43 40
             $target_value = is_int($target_value) ? $target_value : strtotime($target_value);
@@ -68,8 +65,7 @@  discard block
 block discarded – undo
68 65
      *
69 66
      * @return array Array of "Field ID" => "Media IDs"
70 67
      */
71
-    public static function get_post_field_images($form, $entry)
72
-    {
68
+    public static function get_post_field_images($form, $entry) {
73 69
         $post_data = self::get_post_fields($form, $entry);
74 70
 
75 71
         $media = get_attached_media('image', $entry['post_id']);
@@ -102,8 +98,7 @@  discard block
 block discarded – undo
102 98
      *
103 99
      * @return array
104 100
      */
105
-    public static function get_post_fields($form, $entry)
106
-    {
101
+    public static function get_post_fields($form, $entry) {
107 102
         $reflection = new ReflectionMethod('GFFormsModel', 'get_post_fields');
108 103
 
109 104
         /**
@@ -131,8 +126,7 @@  discard block
 block discarded – undo
131 126
      *
132 127
      * @return array|bool Array with `file`, `url` and `type` keys. False: failed to copy file to final directory path.
133 128
      */
134
-    public static function copy_post_image($url, $post_id)
135
-    {
129
+    public static function copy_post_image($url, $post_id) {
136 130
         $reflection = new ReflectionMethod('GFFormsModel', 'copy_post_image');
137 131
 
138 132
         /**
@@ -168,8 +162,7 @@  discard block
 block discarded – undo
168 162
      *
169 163
      * @return bool|int ID of attachment Post created. Returns false if file not created by copy_post_image
170 164
      */
171
-    public static function media_handle_upload($url, $post_id, $post_data = [])
172
-    {
165
+    public static function media_handle_upload($url, $post_id, $post_data = []) {
173 166
         $reflection = new ReflectionMethod('GFFormsModel', 'media_handle_upload');
174 167
 
175 168
         /**
Please login to merge, or discard this patch.
includes/class-admin-add-shortcode.php 3 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -14,81 +14,81 @@  discard block
 block discarded – undo
14 14
 
15 15
 /** If this file is called directly, abort. */
16 16
 if (!defined('ABSPATH')) {
17
-    exit;
17
+	exit;
18 18
 }
19 19
 
20 20
 class GravityView_Admin_Add_Shortcode
21 21
 {
22
-    public function __construct()
23
-    {
24
-        add_action('media_buttons', [$this, 'add_shortcode_button'], 30);
25
-
26
-        add_action('admin_footer', [$this, 'add_shortcode_popup']);
27
-
28
-        // adding styles and scripts
29
-        add_action('admin_enqueue_scripts', [$this, 'add_scripts_and_styles']);
30
-
31
-        // ajax - populate sort fields based on the selected view
32
-        add_action('wp_ajax_gv_sortable_fields', [$this, 'get_sortable_fields']);
33
-    }
34
-
35
-    /**
36
-     * check if screen post editor and is not related with post type 'gravityview'.
37
-     *
38
-     * @return bool
39
-     */
40
-    public function is_post_editor_screen()
41
-    {
42
-        global $current_screen, $pagenow;
43
-
44
-        return !empty($current_screen->post_type) && 'gravityview' != $current_screen->post_type && in_array($pagenow, ['post.php', 'post-new.php']);
45
-    }
46
-
47
-    /**
48
-     * Add shortcode button to the Add Media right.
49
-     *
50
-     * @return void
51
-     */
52
-    public function add_shortcode_button()
53
-    {
54
-
55
-        /**
56
-         * @since 1.15.3
57
-         */
58
-        if (!GVCommon::has_cap(['publish_gravityviews'])) {
59
-            return;
60
-        }
61
-
62
-        if (!$this->is_post_editor_screen()) {
63
-            return;
64
-        } ?>
22
+	public function __construct()
23
+	{
24
+		add_action('media_buttons', [$this, 'add_shortcode_button'], 30);
25
+
26
+		add_action('admin_footer', [$this, 'add_shortcode_popup']);
27
+
28
+		// adding styles and scripts
29
+		add_action('admin_enqueue_scripts', [$this, 'add_scripts_and_styles']);
30
+
31
+		// ajax - populate sort fields based on the selected view
32
+		add_action('wp_ajax_gv_sortable_fields', [$this, 'get_sortable_fields']);
33
+	}
34
+
35
+	/**
36
+	 * check if screen post editor and is not related with post type 'gravityview'.
37
+	 *
38
+	 * @return bool
39
+	 */
40
+	public function is_post_editor_screen()
41
+	{
42
+		global $current_screen, $pagenow;
43
+
44
+		return !empty($current_screen->post_type) && 'gravityview' != $current_screen->post_type && in_array($pagenow, ['post.php', 'post-new.php']);
45
+	}
46
+
47
+	/**
48
+	 * Add shortcode button to the Add Media right.
49
+	 *
50
+	 * @return void
51
+	 */
52
+	public function add_shortcode_button()
53
+	{
54
+
55
+		/**
56
+		 * @since 1.15.3
57
+		 */
58
+		if (!GVCommon::has_cap(['publish_gravityviews'])) {
59
+			return;
60
+		}
61
+
62
+		if (!$this->is_post_editor_screen()) {
63
+			return;
64
+		} ?>
65 65
 		<a href="#TB_inline?width=600&amp;height=800&amp;inlineId=select_gravityview_view" class="thickbox hide-if-no-js button gform_media_link" id="add_gravityview" title="<?php esc_attr_e('Insert View', 'gravityview'); ?>"><span class="icon gv-icon-astronaut-head"></span><?php esc_html_e('Add View', 'gravityview'); ?></a>
66 66
 		<?php
67
-    }
67
+	}
68 68
 
69
-    /**
70
-     * Add shortcode popup div.
71
-     *
72
-     * @return void
73
-     */
74
-    public function add_shortcode_popup()
75
-    {
76
-        global $post;
69
+	/**
70
+	 * Add shortcode popup div.
71
+	 *
72
+	 * @return void
73
+	 */
74
+	public function add_shortcode_popup()
75
+	{
76
+		global $post;
77 77
 
78
-        if (!$this->is_post_editor_screen()) {
79
-            return;
80
-        }
78
+		if (!$this->is_post_editor_screen()) {
79
+			return;
80
+		}
81 81
 
82
-        $post_type = get_post_type_object($post->post_type);
82
+		$post_type = get_post_type_object($post->post_type);
83 83
 
84
-        $views = get_posts(['post_type' => 'gravityview', 'posts_per_page' => -1]);
84
+		$views = get_posts(['post_type' => 'gravityview', 'posts_per_page' => -1]);
85 85
 
86
-        // If there are no views set up yet, we get outta here.
87
-        if (empty($views)) {
88
-            echo '<div id="select_gravityview_view"><div class="wrap">'.GravityView_Admin::no_views_text().'</div></div>';
86
+		// If there are no views set up yet, we get outta here.
87
+		if (empty($views)) {
88
+			echo '<div id="select_gravityview_view"><div class="wrap">'.GravityView_Admin::no_views_text().'</div></div>';
89 89
 
90
-            return;
91
-        } ?>
90
+			return;
91
+		} ?>
92 92
 		<div id="select_gravityview_view">
93 93
 			<form action="#" method="get" id="select_gravityview_view_form">
94 94
 				<div class="wrap">
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
 						<select name="gravityview_id" id="gravityview_id">
103 103
 							<option value=""><?php esc_html_e('&mdash; Select a View to Insert &mdash;', 'gravityview'); ?></option>
104 104
 							<?php
105
-                            foreach ($views as $view) {
106
-                                $title = empty($view->post_title) ? __('(no title)', 'gravityview') : $view->post_title;
107
-                                echo '<option value="'.$view->ID.'">'.esc_html(sprintf('%s #%d', $title, $view->ID)).'</option>';
108
-                            } ?>
105
+							foreach ($views as $view) {
106
+								$title = empty($view->post_title) ? __('(no title)', 'gravityview') : $view->post_title;
107
+								echo '<option value="'.$view->ID.'">'.esc_html(sprintf('%s #%d', $title, $view->ID)).'</option>';
108
+							} ?>
109 109
 						</select>
110 110
 					</div>
111 111
 
@@ -115,15 +115,15 @@  discard block
 block discarded – undo
115 115
 
116 116
 						<?php
117 117
 
118
-                        $settings = \GV\View_Settings::defaults(true);
118
+						$settings = \GV\View_Settings::defaults(true);
119 119
 
120
-        foreach ($settings as $key => $setting) {
121
-            if (empty($setting['show_in_shortcode'])) {
122
-                continue;
123
-            }
120
+		foreach ($settings as $key => $setting) {
121
+			if (empty($setting['show_in_shortcode'])) {
122
+				continue;
123
+			}
124 124
 
125
-            GravityView_Render_Settings::render_setting_row($key, [], null, 'gravityview_%s', 'gravityview_%s');
126
-        } ?>
125
+			GravityView_Render_Settings::render_setting_row($key, [], null, 'gravityview_%s', 'gravityview_%s');
126
+		} ?>
127 127
 
128 128
 					</table>
129 129
 
@@ -136,76 +136,76 @@  discard block
 block discarded – undo
136 136
 			</form>
137 137
 		</div>
138 138
 		<?php
139
-    }
140
-
141
-    /**
142
-     * Enqueue scripts and styles.
143
-     *
144
-     * @return void
145
-     */
146
-    public function add_scripts_and_styles()
147
-    {
148
-        if (!$this->is_post_editor_screen()) {
149
-            return;
150
-        }
151
-
152
-        wp_enqueue_style('dashicons');
153
-
154
-        // date picker
155
-        wp_enqueue_script('jquery-ui-datepicker');
156
-
157
-        $protocol = is_ssl() ? 'https://' : 'http://';
158
-
159
-        wp_enqueue_style('jquery-ui-datepicker', $protocol.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css', [], GravityView_Plugin::version);
160
-
161
-        //enqueue styles
162
-        wp_register_style('gravityview_postedit_styles', plugins_url('assets/css/admin-post-edit.css', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
163
-        wp_enqueue_style('gravityview_postedit_styles');
164
-
165
-        $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
166
-
167
-        // custom js
168
-        wp_register_script('gravityview_postedit_scripts', plugins_url('assets/js/admin-post-edit'.$script_debug.'.js', GRAVITYVIEW_FILE), ['jquery', 'jquery-ui-datepicker'], GravityView_Plugin::version);
169
-        wp_enqueue_script('gravityview_postedit_scripts');
170
-        wp_localize_script('gravityview_postedit_scripts', 'gvGlobals', [
171
-            'nonce'        => wp_create_nonce('gravityview_ajaxaddshortcode'),
172
-            'loading_text' => esc_html__('Loading&hellip;', 'gravityview'),
173
-            'alert_1'      => esc_html__('Please select a View', 'gravityview'),
174
-        ]);
175
-    }
176
-
177
-    /**
178
-     * Ajax
179
-     * Given a View id, calculates the assigned form, and returns the form fields (only the sortable ones ).
180
-     *
181
-     * @return void
182
-     */
183
-    public function get_sortable_fields()
184
-    {
185
-
186
-        // Not properly formatted request
187
-        if (empty($_POST['viewid']) || !is_numeric($_POST['viewid'])) {
188
-            exit(false);
189
-        }
190
-
191
-        // Not valid request
192
-        if (empty($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'gravityview_ajaxaddshortcode')) {
193
-            exit(false);
194
-        }
195
-
196
-        $viewid = (int) $_POST['viewid'];
197
-
198
-        // fetch form id assigned to the view
199
-        $formid = gravityview_get_form_id($viewid);
200
-
201
-        // Get the default sort field for the view
202
-        $sort_field = gravityview_get_template_setting($viewid, 'sort_field');
203
-
204
-        // Generate the output `<option>`s
205
-        $response = gravityview_get_sortable_fields($formid, $sort_field);
206
-
207
-        exit($response);
208
-    }
139
+	}
140
+
141
+	/**
142
+	 * Enqueue scripts and styles.
143
+	 *
144
+	 * @return void
145
+	 */
146
+	public function add_scripts_and_styles()
147
+	{
148
+		if (!$this->is_post_editor_screen()) {
149
+			return;
150
+		}
151
+
152
+		wp_enqueue_style('dashicons');
153
+
154
+		// date picker
155
+		wp_enqueue_script('jquery-ui-datepicker');
156
+
157
+		$protocol = is_ssl() ? 'https://' : 'http://';
158
+
159
+		wp_enqueue_style('jquery-ui-datepicker', $protocol.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css', [], GravityView_Plugin::version);
160
+
161
+		//enqueue styles
162
+		wp_register_style('gravityview_postedit_styles', plugins_url('assets/css/admin-post-edit.css', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
163
+		wp_enqueue_style('gravityview_postedit_styles');
164
+
165
+		$script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
166
+
167
+		// custom js
168
+		wp_register_script('gravityview_postedit_scripts', plugins_url('assets/js/admin-post-edit'.$script_debug.'.js', GRAVITYVIEW_FILE), ['jquery', 'jquery-ui-datepicker'], GravityView_Plugin::version);
169
+		wp_enqueue_script('gravityview_postedit_scripts');
170
+		wp_localize_script('gravityview_postedit_scripts', 'gvGlobals', [
171
+			'nonce'        => wp_create_nonce('gravityview_ajaxaddshortcode'),
172
+			'loading_text' => esc_html__('Loading&hellip;', 'gravityview'),
173
+			'alert_1'      => esc_html__('Please select a View', 'gravityview'),
174
+		]);
175
+	}
176
+
177
+	/**
178
+	 * Ajax
179
+	 * Given a View id, calculates the assigned form, and returns the form fields (only the sortable ones ).
180
+	 *
181
+	 * @return void
182
+	 */
183
+	public function get_sortable_fields()
184
+	{
185
+
186
+		// Not properly formatted request
187
+		if (empty($_POST['viewid']) || !is_numeric($_POST['viewid'])) {
188
+			exit(false);
189
+		}
190
+
191
+		// Not valid request
192
+		if (empty($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'gravityview_ajaxaddshortcode')) {
193
+			exit(false);
194
+		}
195
+
196
+		$viewid = (int) $_POST['viewid'];
197
+
198
+		// fetch form id assigned to the view
199
+		$formid = gravityview_get_form_id($viewid);
200
+
201
+		// Get the default sort field for the view
202
+		$sort_field = gravityview_get_template_setting($viewid, 'sort_field');
203
+
204
+		// Generate the output `<option>`s
205
+		$response = gravityview_get_sortable_fields($formid, $sort_field);
206
+
207
+		exit($response);
208
+	}
209 209
 }
210 210
 
211 211
 new GravityView_Admin_Add_Shortcode();
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 /** If this file is called directly, abort. */
16
-if (!defined('ABSPATH')) {
16
+if ( ! defined( 'ABSPATH' ) ) {
17 17
     exit;
18 18
 }
19 19
 
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
 {
22 22
     public function __construct()
23 23
     {
24
-        add_action('media_buttons', [$this, 'add_shortcode_button'], 30);
24
+        add_action( 'media_buttons', [ $this, 'add_shortcode_button' ], 30 );
25 25
 
26
-        add_action('admin_footer', [$this, 'add_shortcode_popup']);
26
+        add_action( 'admin_footer', [ $this, 'add_shortcode_popup' ] );
27 27
 
28 28
         // adding styles and scripts
29
-        add_action('admin_enqueue_scripts', [$this, 'add_scripts_and_styles']);
29
+        add_action( 'admin_enqueue_scripts', [ $this, 'add_scripts_and_styles' ] );
30 30
 
31 31
         // ajax - populate sort fields based on the selected view
32
-        add_action('wp_ajax_gv_sortable_fields', [$this, 'get_sortable_fields']);
32
+        add_action( 'wp_ajax_gv_sortable_fields', [ $this, 'get_sortable_fields' ] );
33 33
     }
34 34
 
35 35
     /**
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     {
42 42
         global $current_screen, $pagenow;
43 43
 
44
-        return !empty($current_screen->post_type) && 'gravityview' != $current_screen->post_type && in_array($pagenow, ['post.php', 'post-new.php']);
44
+        return ! empty( $current_screen->post_type ) && 'gravityview' != $current_screen->post_type && in_array( $pagenow, [ 'post.php', 'post-new.php' ] );
45 45
     }
46 46
 
47 47
     /**
@@ -55,14 +55,14 @@  discard block
 block discarded – undo
55 55
         /**
56 56
          * @since 1.15.3
57 57
          */
58
-        if (!GVCommon::has_cap(['publish_gravityviews'])) {
58
+        if ( ! GVCommon::has_cap( [ 'publish_gravityviews' ] ) ) {
59 59
             return;
60 60
         }
61 61
 
62
-        if (!$this->is_post_editor_screen()) {
62
+        if ( ! $this->is_post_editor_screen() ) {
63 63
             return;
64 64
         } ?>
65
-		<a href="#TB_inline?width=600&amp;height=800&amp;inlineId=select_gravityview_view" class="thickbox hide-if-no-js button gform_media_link" id="add_gravityview" title="<?php esc_attr_e('Insert View', 'gravityview'); ?>"><span class="icon gv-icon-astronaut-head"></span><?php esc_html_e('Add View', 'gravityview'); ?></a>
65
+		<a href="#TB_inline?width=600&amp;height=800&amp;inlineId=select_gravityview_view" class="thickbox hide-if-no-js button gform_media_link" id="add_gravityview" title="<?php esc_attr_e( 'Insert View', 'gravityview' ); ?>"><span class="icon gv-icon-astronaut-head"></span><?php esc_html_e( 'Add View', 'gravityview' ); ?></a>
66 66
 		<?php
67 67
     }
68 68
 
@@ -75,17 +75,17 @@  discard block
 block discarded – undo
75 75
     {
76 76
         global $post;
77 77
 
78
-        if (!$this->is_post_editor_screen()) {
78
+        if ( ! $this->is_post_editor_screen() ) {
79 79
             return;
80 80
         }
81 81
 
82
-        $post_type = get_post_type_object($post->post_type);
82
+        $post_type = get_post_type_object( $post->post_type );
83 83
 
84
-        $views = get_posts(['post_type' => 'gravityview', 'posts_per_page' => -1]);
84
+        $views = get_posts( [ 'post_type' => 'gravityview', 'posts_per_page' => -1 ] );
85 85
 
86 86
         // If there are no views set up yet, we get outta here.
87
-        if (empty($views)) {
88
-            echo '<div id="select_gravityview_view"><div class="wrap">'.GravityView_Admin::no_views_text().'</div></div>';
87
+        if ( empty( $views ) ) {
88
+            echo '<div id="select_gravityview_view"><div class="wrap">' . GravityView_Admin::no_views_text() . '</div></div>';
89 89
 
90 90
             return;
91 91
         } ?>
@@ -93,43 +93,43 @@  discard block
 block discarded – undo
93 93
 			<form action="#" method="get" id="select_gravityview_view_form">
94 94
 				<div class="wrap">
95 95
 
96
-					<h2 class=""><?php esc_html_e('Embed a View', 'gravityview'); ?></h2>
97
-					<p class="subtitle"><?php printf(esc_attr(__('Use this form to embed a View into this %s. %sLearn more about using shortcodes.%s', 'gravityview')), $post_type->labels->singular_name, '<a href="https://docs.gravityview.co/article/73-using-the-shortcode" target="_blank" rel="noopener noreferrer">', '</a>'); ?></p>
96
+					<h2 class=""><?php esc_html_e( 'Embed a View', 'gravityview' ); ?></h2>
97
+					<p class="subtitle"><?php printf( esc_attr( __( 'Use this form to embed a View into this %s. %sLearn more about using shortcodes.%s', 'gravityview' ) ), $post_type->labels->singular_name, '<a href="https://docs.gravityview.co/article/73-using-the-shortcode" target="_blank" rel="noopener noreferrer">', '</a>' ); ?></p>
98 98
 
99 99
 					<div>
100
-						<h3><label for="gravityview_id"><?php esc_html_e('Select a View', 'gravityview'); ?></label></h3>
100
+						<h3><label for="gravityview_id"><?php esc_html_e( 'Select a View', 'gravityview' ); ?></label></h3>
101 101
 
102 102
 						<select name="gravityview_id" id="gravityview_id">
103
-							<option value=""><?php esc_html_e('&mdash; Select a View to Insert &mdash;', 'gravityview'); ?></option>
103
+							<option value=""><?php esc_html_e( '&mdash; Select a View to Insert &mdash;', 'gravityview' ); ?></option>
104 104
 							<?php
105
-                            foreach ($views as $view) {
106
-                                $title = empty($view->post_title) ? __('(no title)', 'gravityview') : $view->post_title;
107
-                                echo '<option value="'.$view->ID.'">'.esc_html(sprintf('%s #%d', $title, $view->ID)).'</option>';
105
+                            foreach ( $views as $view ) {
106
+                                $title = empty( $view->post_title ) ? __( '(no title)', 'gravityview' ) : $view->post_title;
107
+                                echo '<option value="' . $view->ID . '">' . esc_html( sprintf( '%s #%d', $title, $view->ID ) ) . '</option>';
108 108
                             } ?>
109 109
 						</select>
110 110
 					</div>
111 111
 
112 112
 					<table class="form-table hide-if-js">
113 113
 
114
-						<caption><?php esc_html_e('View Settings', 'gravityview'); ?></caption>
114
+						<caption><?php esc_html_e( 'View Settings', 'gravityview' ); ?></caption>
115 115
 
116 116
 						<?php
117 117
 
118
-                        $settings = \GV\View_Settings::defaults(true);
118
+                        $settings = \GV\View_Settings::defaults( true );
119 119
 
120
-        foreach ($settings as $key => $setting) {
121
-            if (empty($setting['show_in_shortcode'])) {
120
+        foreach ( $settings as $key => $setting ) {
121
+            if ( empty( $setting[ 'show_in_shortcode' ] ) ) {
122 122
                 continue;
123 123
             }
124 124
 
125
-            GravityView_Render_Settings::render_setting_row($key, [], null, 'gravityview_%s', 'gravityview_%s');
125
+            GravityView_Render_Settings::render_setting_row( $key, [ ], null, 'gravityview_%s', 'gravityview_%s' );
126 126
         } ?>
127 127
 
128 128
 					</table>
129 129
 
130 130
 					<div class="submit">
131
-						<input type="submit" class="button button-primary button-large alignleft hide-if-js" value="<?php esc_attr_e('Insert View', 'gravityview'); ?>" id="insert_gravityview_view" />
132
-						<input class="button button-secondary alignright" type="submit" onclick="tb_remove(); return false;" value="<?php esc_attr_e('Cancel', 'gravityview'); ?>" />
131
+						<input type="submit" class="button button-primary button-large alignleft hide-if-js" value="<?php esc_attr_e( 'Insert View', 'gravityview' ); ?>" id="insert_gravityview_view" />
132
+						<input class="button button-secondary alignright" type="submit" onclick="tb_remove(); return false;" value="<?php esc_attr_e( 'Cancel', 'gravityview' ); ?>" />
133 133
 					</div>
134 134
 
135 135
 				</div>
@@ -145,33 +145,33 @@  discard block
 block discarded – undo
145 145
      */
146 146
     public function add_scripts_and_styles()
147 147
     {
148
-        if (!$this->is_post_editor_screen()) {
148
+        if ( ! $this->is_post_editor_screen() ) {
149 149
             return;
150 150
         }
151 151
 
152
-        wp_enqueue_style('dashicons');
152
+        wp_enqueue_style( 'dashicons' );
153 153
 
154 154
         // date picker
155
-        wp_enqueue_script('jquery-ui-datepicker');
155
+        wp_enqueue_script( 'jquery-ui-datepicker' );
156 156
 
157 157
         $protocol = is_ssl() ? 'https://' : 'http://';
158 158
 
159
-        wp_enqueue_style('jquery-ui-datepicker', $protocol.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css', [], GravityView_Plugin::version);
159
+        wp_enqueue_style( 'jquery-ui-datepicker', $protocol . 'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css', [ ], GravityView_Plugin::version );
160 160
 
161 161
         //enqueue styles
162
-        wp_register_style('gravityview_postedit_styles', plugins_url('assets/css/admin-post-edit.css', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
163
-        wp_enqueue_style('gravityview_postedit_styles');
162
+        wp_register_style( 'gravityview_postedit_styles', plugins_url( 'assets/css/admin-post-edit.css', GRAVITYVIEW_FILE ), [ ], GravityView_Plugin::version );
163
+        wp_enqueue_style( 'gravityview_postedit_styles' );
164 164
 
165
-        $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
165
+        $script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
166 166
 
167 167
         // custom js
168
-        wp_register_script('gravityview_postedit_scripts', plugins_url('assets/js/admin-post-edit'.$script_debug.'.js', GRAVITYVIEW_FILE), ['jquery', 'jquery-ui-datepicker'], GravityView_Plugin::version);
169
-        wp_enqueue_script('gravityview_postedit_scripts');
170
-        wp_localize_script('gravityview_postedit_scripts', 'gvGlobals', [
171
-            'nonce'        => wp_create_nonce('gravityview_ajaxaddshortcode'),
172
-            'loading_text' => esc_html__('Loading&hellip;', 'gravityview'),
173
-            'alert_1'      => esc_html__('Please select a View', 'gravityview'),
174
-        ]);
168
+        wp_register_script( 'gravityview_postedit_scripts', plugins_url( 'assets/js/admin-post-edit' . $script_debug . '.js', GRAVITYVIEW_FILE ), [ 'jquery', 'jquery-ui-datepicker' ], GravityView_Plugin::version );
169
+        wp_enqueue_script( 'gravityview_postedit_scripts' );
170
+        wp_localize_script( 'gravityview_postedit_scripts', 'gvGlobals', [
171
+            'nonce'        => wp_create_nonce( 'gravityview_ajaxaddshortcode' ),
172
+            'loading_text' => esc_html__( 'Loading&hellip;', 'gravityview' ),
173
+            'alert_1'      => esc_html__( 'Please select a View', 'gravityview' ),
174
+        ] );
175 175
     }
176 176
 
177 177
     /**
@@ -184,27 +184,27 @@  discard block
 block discarded – undo
184 184
     {
185 185
 
186 186
         // Not properly formatted request
187
-        if (empty($_POST['viewid']) || !is_numeric($_POST['viewid'])) {
188
-            exit(false);
187
+        if ( empty( $_POST[ 'viewid' ] ) || ! is_numeric( $_POST[ 'viewid' ] ) ) {
188
+            exit( false );
189 189
         }
190 190
 
191 191
         // Not valid request
192
-        if (empty($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'gravityview_ajaxaddshortcode')) {
193
-            exit(false);
192
+        if ( empty( $_POST[ 'nonce' ] ) || ! wp_verify_nonce( $_POST[ 'nonce' ], 'gravityview_ajaxaddshortcode' ) ) {
193
+            exit( false );
194 194
         }
195 195
 
196
-        $viewid = (int) $_POST['viewid'];
196
+        $viewid = (int)$_POST[ 'viewid' ];
197 197
 
198 198
         // fetch form id assigned to the view
199
-        $formid = gravityview_get_form_id($viewid);
199
+        $formid = gravityview_get_form_id( $viewid );
200 200
 
201 201
         // Get the default sort field for the view
202
-        $sort_field = gravityview_get_template_setting($viewid, 'sort_field');
202
+        $sort_field = gravityview_get_template_setting( $viewid, 'sort_field' );
203 203
 
204 204
         // Generate the output `<option>`s
205
-        $response = gravityview_get_sortable_fields($formid, $sort_field);
205
+        $response = gravityview_get_sortable_fields( $formid, $sort_field );
206 206
 
207
-        exit($response);
207
+        exit( $response );
208 208
     }
209 209
 }
210 210
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -17,10 +17,8 @@  discard block
 block discarded – undo
17 17
     exit;
18 18
 }
19 19
 
20
-class GravityView_Admin_Add_Shortcode
21
-{
22
-    public function __construct()
23
-    {
20
+class GravityView_Admin_Add_Shortcode {
21
+    public function __construct() {
24 22
         add_action('media_buttons', [$this, 'add_shortcode_button'], 30);
25 23
 
26 24
         add_action('admin_footer', [$this, 'add_shortcode_popup']);
@@ -37,8 +35,7 @@  discard block
 block discarded – undo
37 35
      *
38 36
      * @return bool
39 37
      */
40
-    public function is_post_editor_screen()
41
-    {
38
+    public function is_post_editor_screen() {
42 39
         global $current_screen, $pagenow;
43 40
 
44 41
         return !empty($current_screen->post_type) && 'gravityview' != $current_screen->post_type && in_array($pagenow, ['post.php', 'post-new.php']);
@@ -49,8 +46,7 @@  discard block
 block discarded – undo
49 46
      *
50 47
      * @return void
51 48
      */
52
-    public function add_shortcode_button()
53
-    {
49
+    public function add_shortcode_button() {
54 50
 
55 51
         /**
56 52
          * @since 1.15.3
@@ -71,8 +67,7 @@  discard block
 block discarded – undo
71 67
      *
72 68
      * @return void
73 69
      */
74
-    public function add_shortcode_popup()
75
-    {
70
+    public function add_shortcode_popup() {
76 71
         global $post;
77 72
 
78 73
         if (!$this->is_post_editor_screen()) {
@@ -143,8 +138,7 @@  discard block
 block discarded – undo
143 138
      *
144 139
      * @return void
145 140
      */
146
-    public function add_scripts_and_styles()
147
-    {
141
+    public function add_scripts_and_styles() {
148 142
         if (!$this->is_post_editor_screen()) {
149 143
             return;
150 144
         }
@@ -180,8 +174,7 @@  discard block
 block discarded – undo
180 174
      *
181 175
      * @return void
182 176
      */
183
-    public function get_sortable_fields()
184
-    {
177
+    public function get_sortable_fields() {
185 178
 
186 179
         // Not properly formatted request
187 180
         if (empty($_POST['viewid']) || !is_numeric($_POST['viewid'])) {
Please login to merge, or discard this patch.
includes/class-gravityview-admin-duplicate-view.php 3 patches
Indentation   +360 added lines, -360 removed lines patch added patch discarded remove patch
@@ -10,366 +10,366 @@
 block discarded – undo
10 10
  */
11 11
 class GravityView_Admin_Duplicate_View
12 12
 {
13
-    public function __construct()
14
-    {
15
-
16
-        // Only run on Admin
17
-        if (!is_admin()) {
18
-            return;
19
-        }
20
-
21
-        // If the Duplicate Post plugin is active, don't run.
22
-        if (defined('DUPLICATE_POST_CURRENT_VERSION')) {
23
-            return;
24
-        }
25
-
26
-        $this->add_hooks();
27
-    }
28
-
29
-    /**
30
-     * Add actions & filters.
31
-     *
32
-     * @since 1.15
33
-     *
34
-     * @return void
35
-     */
36
-    private function add_hooks()
37
-    {
38
-        add_filter('post_row_actions', [$this, 'make_duplicate_link_row'], 10, 2);
39
-
40
-        /**
41
-         * Connect actions to functions.
42
-         */
43
-        add_action('admin_action_duplicate_view', [$this, 'save_as_new_view']);
44
-        add_action('admin_action_duplicate_view_as_draft', [$this, 'save_as_new_view_draft']);
45
-
46
-        // Using our action hooks to copy meta fields
47
-        add_action('gv_duplicate_view', [$this, 'copy_view_meta_info'], 10, 2);
48
-
49
-        add_filter('gravityview_connected_form_links', [$this, 'connected_form_links'], 10, 2);
50
-    }
51
-
52
-    /**
53
-     * Add Duplicate View link to the Data Source metabox.
54
-     *
55
-     * @param array $links Array of link HTML to display in the Data Source metabox
56
-     * @param array $form  Gravity Forms form array
57
-     *
58
-     * @return array If it's the All Views page, return unedited. Otherwise, add a link to create cloned draft of View
59
-     */
60
-    public function connected_form_links($links = [], $form = [])
61
-    {
62
-        /** @global WP_Post $post */
63
-        global $post;
64
-
65
-        // We only want to add Clone links to the Edit View metabox
66
-        if (!$this->is_all_views_page()) {
67
-            if ($duplicate_links = $this->make_duplicate_link_row([], $post)) {
68
-                $links[] = '<span>'.$duplicate_links['edit_as_new_draft'].'</span>';
69
-            }
70
-        }
71
-
72
-        return $links;
73
-    }
74
-
75
-    /**
76
-     * Is the current screen the All Views screen?
77
-     *
78
-     * @return bool
79
-     */
80
-    private function is_all_views_page()
81
-    {
82
-        global $pagenow;
83
-
84
-        return $pagenow === 'edit.php';
85
-    }
86
-
87
-    /**
88
-     * Test if the user is allowed to copy Views.
89
-     *
90
-     * @since 1.6
91
-     *
92
-     * @param WP_Post|int Post ID or Post object
93
-     *
94
-     * @return bool True: user can copy the View; false: nope.
95
-     */
96
-    private function current_user_can_copy($post)
97
-    {
98
-        $id = is_object($post) ? $post->ID : $post;
99
-
100
-        // Can't edit this current View
101
-        return GVCommon::has_cap('copy_gravityviews', $id);
102
-    }
103
-
104
-    /**
105
-     * Create a duplicate from a View $post.
106
-     *
107
-     * @param WP_Post $post
108
-     * @param string  $status The post status
109
-     *
110
-     * @since 1.6
111
-     */
112
-    private function create_duplicate($post, $status = '')
113
-    {
114
-
115
-        // We only want to clone Views
116
-        if ($post->post_type !== 'gravityview') {
117
-            return;
118
-        }
119
-
120
-        $new_view_author = wp_get_current_user();
121
-
122
-        /**
123
-         * @filter `gravityview/duplicate-view/status` Modify the default status for a new View. Return empty for the new View to inherit existing View status
124
-         *
125
-         * @since 1.6
126
-         *
127
-         * @param string|null If string, the status to set for the new View. If empty, use existing View status.
128
-         * @param WP_Post $post View being cloned
129
-         */
130
-        $new_view_status = apply_filters('gravityview/duplicate-view/status', $status, $post);
131
-
132
-        $new_view = [
133
-            'menu_order'     => $post->menu_order,
134
-            'comment_status' => $post->comment_status,
135
-            'ping_status'    => $post->ping_status,
136
-            'post_author'    => $new_view_author->ID,
137
-            'post_content'   => $post->post_content,
138
-            'post_excerpt'   => $post->post_excerpt,
139
-            'post_mime_type' => $post->post_mime_type,
140
-            'post_parent'    => $post->post_parent,
141
-            'post_password'  => $post->post_password,
142
-            'post_status'    => (empty($new_view_status)) ? $post->post_status : $new_view_status,
143
-            'post_title'     => $post->post_title,
144
-            'post_type'      => $post->post_type,
145
-        ];
146
-
147
-        /**
148
-         * @filter `gravityview/duplicate-view/copy-date` When copying a View, should the date also be copied?
149
-         *
150
-         * @since 1.6
151
-         *
152
-         * @param bool    $copy_date Whether the copy the date from the existing View. Default: `false`
153
-         * @param WP_Post $post      View being cloned
154
-         */
155
-        $copy_date = apply_filters('gravityview/duplicate-view/copy-date', false, $post);
156
-
157
-        if ($copy_date) {
158
-            $new_view['post_date'] = $new_post_date = $post->post_date;
159
-            $new_view['post_date_gmt'] = get_gmt_from_date($new_post_date);
160
-        }
161
-
162
-        /**
163
-         * @filter `gravityview/duplicate-view/new-view` Modify View configuration before creating the duplicated View.
164
-         *
165
-         * @since 1.6
166
-         *
167
-         * @param array   $new_view Array of settings to be passed to wp_insert_post()
168
-         * @param WP_Post $post     View being cloned
169
-         */
170
-        $new_view = apply_filters('gravityview/duplicate-view/new-view', $new_view, $post);
171
-
172
-        // Magic happens here.
173
-        $new_view_id = wp_insert_post($new_view);
174
-
175
-        // If the copy is published or scheduled, we have to set a proper slug.
176
-        if ($new_view_status == 'publish' || $new_view_status == 'future') {
177
-            $view_name = wp_unique_post_slug($post->post_name, $new_view_id, $new_view_status, $post->post_type, $post->post_parent);
178
-
179
-            $new_view_name_array = [
180
-                'ID'        => $new_view_id,
181
-                'post_name' => $view_name,
182
-            ];
183
-
184
-            // Update the post into the database
185
-            wp_update_post($new_view_name_array);
186
-        }
187
-
188
-        /**
189
-         * @action `gv_duplicate_view` After a View is duplicated, perform an action
190
-         *
191
-         * @since 1.6
192
-         * @see GravityView_Admin_Duplicate_View::copy_view_meta_info
193
-         *
194
-         * @param int     $new_view_id The ID of the newly created View
195
-         * @param WP_Post $post        The View that was just cloned
196
-         */
197
-        do_action('gv_duplicate_view', $new_view_id, $post);
198
-
199
-        delete_post_meta($new_view_id, '_dp_original');
200
-
201
-        add_post_meta($new_view_id, '_dp_original', $post->ID, false);
202
-
203
-        return $new_view_id;
204
-    }
205
-
206
-    /**
207
-     * Copy the meta information of a post to another View.
208
-     *
209
-     * @since 1.6
210
-     *
211
-     * @param int     $new_view_id The ID of the newly created View
212
-     * @param WP_Post $post        The View that was just cloned
213
-     *
214
-     * @return void
215
-     */
216
-    public function copy_view_meta_info($new_id, $post)
217
-    {
218
-        $post_meta_keys = get_post_custom_keys($post->ID);
219
-
220
-        if (empty($post_meta_keys)) {
221
-            return;
222
-        }
223
-
224
-        foreach ($post_meta_keys as $meta_key) {
225
-            $meta_values = get_post_custom_values($meta_key, $post->ID);
226
-
227
-            foreach ($meta_values as $meta_value) {
228
-                $meta_value = maybe_unserialize($meta_value);
229
-
230
-                add_post_meta($new_id, $meta_key, $meta_value);
231
-            }
232
-        }
233
-    }
234
-
235
-    /**
236
-     * Add the link to action list for post_row_actions.
237
-     *
238
-     * @since 1.6
239
-     *
240
-     * @param array   $actions Row action links. Defaults are 'Edit', 'Quick Edit', 'Restore, 'Trash', 'Delete Permanently', 'Preview', and 'View'
241
-     * @param WP_Post $post
242
-     */
243
-    public function make_duplicate_link_row($actions, $post)
244
-    {
245
-
246
-        // Only process on GravityView Views
247
-        if (get_post_type($post) === 'gravityview' && $this->current_user_can_copy($post)) {
248
-            $clone_link = $this->get_clone_view_link($post->ID, 'display', false);
249
-            $clone_text = __('Clone', 'gravityview');
250
-            $clone_title = __('Clone this View', 'gravityview');
251
-
252
-            $actions['clone'] = gravityview_get_link($clone_link, $clone_text, 'title='.$clone_title);
253
-
254
-            $clone_draft_link = $this->get_clone_view_link($post->ID);
255
-            $clone_draft_text = $this->is_all_views_page() ? __('New Draft', 'gravityview') : __('Clone View', 'gravityview');
256
-            $clone_draft_title = __('Copy as a new draft View', 'gravityview');
257
-
258
-            $actions['edit_as_new_draft'] = gravityview_get_link($clone_draft_link, esc_html($clone_draft_text), 'title='.$clone_draft_title);
259
-        }
260
-
261
-        return $actions;
262
-    }
263
-
264
-    /**
265
-     * Retrieve duplicate post link for post.
266
-     *
267
-     * @since 1.6
268
-     *
269
-     * @param int    $id      Optional. Post ID.
270
-     * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
271
-     * @param string $draft   Optional, default to true
272
-     *
273
-     * @return string
274
-     */
275
-    private function get_clone_view_link($id = 0, $context = 'display', $draft = true)
276
-    {
277
-
278
-        // Make sure they have permission
279
-        if (false === $this->current_user_can_copy($id)) {
280
-            return '';
281
-        }
282
-
283
-        // Verify the View exists
284
-        if (!$view = get_post($id)) {
285
-            return '';
286
-        }
287
-
288
-        $action_name = $draft ? 'duplicate_view_as_draft' : 'duplicate_view';
289
-
290
-        $action = '?action='.$action_name.'&post='.$view->ID;
291
-
292
-        if ('display' == $context) {
293
-            $action = esc_html($action);
294
-        }
295
-
296
-        $post_type_object = get_post_type_object($view->post_type);
297
-
298
-        /** If there's no gravityview post type for some reason, abort! */
299
-        if (!$post_type_object) {
300
-            gravityview()->log->error('No gravityview post type exists when trying to clone the View.', ['data' => $view]);
301
-
302
-            return '';
303
-        }
304
-
305
-        /**
306
-         * @filter `gravityview/duplicate-view/get_clone_view_link` Modify the Clone View URL that is generated
307
-         *
308
-         * @since 1.6
309
-         *
310
-         * @param string $clone_view_link Link with `admin_url("admin.php")`, plus the action query string
311
-         * @param int    $view_id         View ID
312
-         * @param string $context         How to display the link. If "display", the URL is run through esc_html(). Default: `display`
313
-         */
314
-        $clone_view_link = apply_filters('gravityview/duplicate-view/get_clone_view_link', admin_url('admin.php'.$action), $view->ID, $context);
315
-
316
-        return $clone_view_link;
317
-    }
318
-
319
-    /**
320
-     * This function calls the creation of a new copy of the selected post (as a draft)
321
-     * then redirects to the edit post screen.
322
-     *
323
-     * @since 1.6
324
-     *
325
-     * @return void
326
-     */
327
-    public function save_as_new_view_draft()
328
-    {
329
-        $this->save_as_new_view('draft');
330
-    }
331
-
332
-    /**
333
-     * This function calls the creation of a new copy of the selected post (by default preserving the original publish status)
334
-     * then redirects to the post list.
335
-     *
336
-     * @since 1.6
337
-     *
338
-     * @param string $status The status to set for the new View
339
-     *
340
-     * @return void
341
-     */
342
-    public function save_as_new_view($status = '')
343
-    {
344
-        if (!(isset($_GET['post']) || isset($_POST['post']))) {
345
-            wp_die(__('No post to duplicate has been supplied!', 'gravityview'));
346
-        }
347
-
348
-        // Get the original post
349
-        $id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
350
-
351
-        if (!$this->current_user_can_copy($id)) {
352
-            wp_die(__('You don\'t have permission to copy this View.', 'gravityview'));
353
-        }
354
-
355
-        $post = get_post($id);
356
-
357
-        // Copy the post and insert it
358
-        if (isset($post) && $post != null) {
359
-            $new_id = $this->create_duplicate($post, $status);
360
-
361
-            if ($status == '') {
362
-                // Redirect to the post list screen
363
-                wp_redirect(admin_url('edit.php?post_type='.$post->post_type));
364
-            } else {
365
-                // Redirect to the edit screen for the new draft post
366
-                wp_redirect(admin_url('post.php?action=edit&post='.$new_id));
367
-            }
368
-            exit;
369
-        } else {
370
-            wp_die(sprintf(esc_attr__('Copy creation failed, could not find original View with ID #%d', 'gravityview'), $id));
371
-        }
372
-    }
13
+	public function __construct()
14
+	{
15
+
16
+		// Only run on Admin
17
+		if (!is_admin()) {
18
+			return;
19
+		}
20
+
21
+		// If the Duplicate Post plugin is active, don't run.
22
+		if (defined('DUPLICATE_POST_CURRENT_VERSION')) {
23
+			return;
24
+		}
25
+
26
+		$this->add_hooks();
27
+	}
28
+
29
+	/**
30
+	 * Add actions & filters.
31
+	 *
32
+	 * @since 1.15
33
+	 *
34
+	 * @return void
35
+	 */
36
+	private function add_hooks()
37
+	{
38
+		add_filter('post_row_actions', [$this, 'make_duplicate_link_row'], 10, 2);
39
+
40
+		/**
41
+		 * Connect actions to functions.
42
+		 */
43
+		add_action('admin_action_duplicate_view', [$this, 'save_as_new_view']);
44
+		add_action('admin_action_duplicate_view_as_draft', [$this, 'save_as_new_view_draft']);
45
+
46
+		// Using our action hooks to copy meta fields
47
+		add_action('gv_duplicate_view', [$this, 'copy_view_meta_info'], 10, 2);
48
+
49
+		add_filter('gravityview_connected_form_links', [$this, 'connected_form_links'], 10, 2);
50
+	}
51
+
52
+	/**
53
+	 * Add Duplicate View link to the Data Source metabox.
54
+	 *
55
+	 * @param array $links Array of link HTML to display in the Data Source metabox
56
+	 * @param array $form  Gravity Forms form array
57
+	 *
58
+	 * @return array If it's the All Views page, return unedited. Otherwise, add a link to create cloned draft of View
59
+	 */
60
+	public function connected_form_links($links = [], $form = [])
61
+	{
62
+		/** @global WP_Post $post */
63
+		global $post;
64
+
65
+		// We only want to add Clone links to the Edit View metabox
66
+		if (!$this->is_all_views_page()) {
67
+			if ($duplicate_links = $this->make_duplicate_link_row([], $post)) {
68
+				$links[] = '<span>'.$duplicate_links['edit_as_new_draft'].'</span>';
69
+			}
70
+		}
71
+
72
+		return $links;
73
+	}
74
+
75
+	/**
76
+	 * Is the current screen the All Views screen?
77
+	 *
78
+	 * @return bool
79
+	 */
80
+	private function is_all_views_page()
81
+	{
82
+		global $pagenow;
83
+
84
+		return $pagenow === 'edit.php';
85
+	}
86
+
87
+	/**
88
+	 * Test if the user is allowed to copy Views.
89
+	 *
90
+	 * @since 1.6
91
+	 *
92
+	 * @param WP_Post|int Post ID or Post object
93
+	 *
94
+	 * @return bool True: user can copy the View; false: nope.
95
+	 */
96
+	private function current_user_can_copy($post)
97
+	{
98
+		$id = is_object($post) ? $post->ID : $post;
99
+
100
+		// Can't edit this current View
101
+		return GVCommon::has_cap('copy_gravityviews', $id);
102
+	}
103
+
104
+	/**
105
+	 * Create a duplicate from a View $post.
106
+	 *
107
+	 * @param WP_Post $post
108
+	 * @param string  $status The post status
109
+	 *
110
+	 * @since 1.6
111
+	 */
112
+	private function create_duplicate($post, $status = '')
113
+	{
114
+
115
+		// We only want to clone Views
116
+		if ($post->post_type !== 'gravityview') {
117
+			return;
118
+		}
119
+
120
+		$new_view_author = wp_get_current_user();
121
+
122
+		/**
123
+		 * @filter `gravityview/duplicate-view/status` Modify the default status for a new View. Return empty for the new View to inherit existing View status
124
+		 *
125
+		 * @since 1.6
126
+		 *
127
+		 * @param string|null If string, the status to set for the new View. If empty, use existing View status.
128
+		 * @param WP_Post $post View being cloned
129
+		 */
130
+		$new_view_status = apply_filters('gravityview/duplicate-view/status', $status, $post);
131
+
132
+		$new_view = [
133
+			'menu_order'     => $post->menu_order,
134
+			'comment_status' => $post->comment_status,
135
+			'ping_status'    => $post->ping_status,
136
+			'post_author'    => $new_view_author->ID,
137
+			'post_content'   => $post->post_content,
138
+			'post_excerpt'   => $post->post_excerpt,
139
+			'post_mime_type' => $post->post_mime_type,
140
+			'post_parent'    => $post->post_parent,
141
+			'post_password'  => $post->post_password,
142
+			'post_status'    => (empty($new_view_status)) ? $post->post_status : $new_view_status,
143
+			'post_title'     => $post->post_title,
144
+			'post_type'      => $post->post_type,
145
+		];
146
+
147
+		/**
148
+		 * @filter `gravityview/duplicate-view/copy-date` When copying a View, should the date also be copied?
149
+		 *
150
+		 * @since 1.6
151
+		 *
152
+		 * @param bool    $copy_date Whether the copy the date from the existing View. Default: `false`
153
+		 * @param WP_Post $post      View being cloned
154
+		 */
155
+		$copy_date = apply_filters('gravityview/duplicate-view/copy-date', false, $post);
156
+
157
+		if ($copy_date) {
158
+			$new_view['post_date'] = $new_post_date = $post->post_date;
159
+			$new_view['post_date_gmt'] = get_gmt_from_date($new_post_date);
160
+		}
161
+
162
+		/**
163
+		 * @filter `gravityview/duplicate-view/new-view` Modify View configuration before creating the duplicated View.
164
+		 *
165
+		 * @since 1.6
166
+		 *
167
+		 * @param array   $new_view Array of settings to be passed to wp_insert_post()
168
+		 * @param WP_Post $post     View being cloned
169
+		 */
170
+		$new_view = apply_filters('gravityview/duplicate-view/new-view', $new_view, $post);
171
+
172
+		// Magic happens here.
173
+		$new_view_id = wp_insert_post($new_view);
174
+
175
+		// If the copy is published or scheduled, we have to set a proper slug.
176
+		if ($new_view_status == 'publish' || $new_view_status == 'future') {
177
+			$view_name = wp_unique_post_slug($post->post_name, $new_view_id, $new_view_status, $post->post_type, $post->post_parent);
178
+
179
+			$new_view_name_array = [
180
+				'ID'        => $new_view_id,
181
+				'post_name' => $view_name,
182
+			];
183
+
184
+			// Update the post into the database
185
+			wp_update_post($new_view_name_array);
186
+		}
187
+
188
+		/**
189
+		 * @action `gv_duplicate_view` After a View is duplicated, perform an action
190
+		 *
191
+		 * @since 1.6
192
+		 * @see GravityView_Admin_Duplicate_View::copy_view_meta_info
193
+		 *
194
+		 * @param int     $new_view_id The ID of the newly created View
195
+		 * @param WP_Post $post        The View that was just cloned
196
+		 */
197
+		do_action('gv_duplicate_view', $new_view_id, $post);
198
+
199
+		delete_post_meta($new_view_id, '_dp_original');
200
+
201
+		add_post_meta($new_view_id, '_dp_original', $post->ID, false);
202
+
203
+		return $new_view_id;
204
+	}
205
+
206
+	/**
207
+	 * Copy the meta information of a post to another View.
208
+	 *
209
+	 * @since 1.6
210
+	 *
211
+	 * @param int     $new_view_id The ID of the newly created View
212
+	 * @param WP_Post $post        The View that was just cloned
213
+	 *
214
+	 * @return void
215
+	 */
216
+	public function copy_view_meta_info($new_id, $post)
217
+	{
218
+		$post_meta_keys = get_post_custom_keys($post->ID);
219
+
220
+		if (empty($post_meta_keys)) {
221
+			return;
222
+		}
223
+
224
+		foreach ($post_meta_keys as $meta_key) {
225
+			$meta_values = get_post_custom_values($meta_key, $post->ID);
226
+
227
+			foreach ($meta_values as $meta_value) {
228
+				$meta_value = maybe_unserialize($meta_value);
229
+
230
+				add_post_meta($new_id, $meta_key, $meta_value);
231
+			}
232
+		}
233
+	}
234
+
235
+	/**
236
+	 * Add the link to action list for post_row_actions.
237
+	 *
238
+	 * @since 1.6
239
+	 *
240
+	 * @param array   $actions Row action links. Defaults are 'Edit', 'Quick Edit', 'Restore, 'Trash', 'Delete Permanently', 'Preview', and 'View'
241
+	 * @param WP_Post $post
242
+	 */
243
+	public function make_duplicate_link_row($actions, $post)
244
+	{
245
+
246
+		// Only process on GravityView Views
247
+		if (get_post_type($post) === 'gravityview' && $this->current_user_can_copy($post)) {
248
+			$clone_link = $this->get_clone_view_link($post->ID, 'display', false);
249
+			$clone_text = __('Clone', 'gravityview');
250
+			$clone_title = __('Clone this View', 'gravityview');
251
+
252
+			$actions['clone'] = gravityview_get_link($clone_link, $clone_text, 'title='.$clone_title);
253
+
254
+			$clone_draft_link = $this->get_clone_view_link($post->ID);
255
+			$clone_draft_text = $this->is_all_views_page() ? __('New Draft', 'gravityview') : __('Clone View', 'gravityview');
256
+			$clone_draft_title = __('Copy as a new draft View', 'gravityview');
257
+
258
+			$actions['edit_as_new_draft'] = gravityview_get_link($clone_draft_link, esc_html($clone_draft_text), 'title='.$clone_draft_title);
259
+		}
260
+
261
+		return $actions;
262
+	}
263
+
264
+	/**
265
+	 * Retrieve duplicate post link for post.
266
+	 *
267
+	 * @since 1.6
268
+	 *
269
+	 * @param int    $id      Optional. Post ID.
270
+	 * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
271
+	 * @param string $draft   Optional, default to true
272
+	 *
273
+	 * @return string
274
+	 */
275
+	private function get_clone_view_link($id = 0, $context = 'display', $draft = true)
276
+	{
277
+
278
+		// Make sure they have permission
279
+		if (false === $this->current_user_can_copy($id)) {
280
+			return '';
281
+		}
282
+
283
+		// Verify the View exists
284
+		if (!$view = get_post($id)) {
285
+			return '';
286
+		}
287
+
288
+		$action_name = $draft ? 'duplicate_view_as_draft' : 'duplicate_view';
289
+
290
+		$action = '?action='.$action_name.'&post='.$view->ID;
291
+
292
+		if ('display' == $context) {
293
+			$action = esc_html($action);
294
+		}
295
+
296
+		$post_type_object = get_post_type_object($view->post_type);
297
+
298
+		/** If there's no gravityview post type for some reason, abort! */
299
+		if (!$post_type_object) {
300
+			gravityview()->log->error('No gravityview post type exists when trying to clone the View.', ['data' => $view]);
301
+
302
+			return '';
303
+		}
304
+
305
+		/**
306
+		 * @filter `gravityview/duplicate-view/get_clone_view_link` Modify the Clone View URL that is generated
307
+		 *
308
+		 * @since 1.6
309
+		 *
310
+		 * @param string $clone_view_link Link with `admin_url("admin.php")`, plus the action query string
311
+		 * @param int    $view_id         View ID
312
+		 * @param string $context         How to display the link. If "display", the URL is run through esc_html(). Default: `display`
313
+		 */
314
+		$clone_view_link = apply_filters('gravityview/duplicate-view/get_clone_view_link', admin_url('admin.php'.$action), $view->ID, $context);
315
+
316
+		return $clone_view_link;
317
+	}
318
+
319
+	/**
320
+	 * This function calls the creation of a new copy of the selected post (as a draft)
321
+	 * then redirects to the edit post screen.
322
+	 *
323
+	 * @since 1.6
324
+	 *
325
+	 * @return void
326
+	 */
327
+	public function save_as_new_view_draft()
328
+	{
329
+		$this->save_as_new_view('draft');
330
+	}
331
+
332
+	/**
333
+	 * This function calls the creation of a new copy of the selected post (by default preserving the original publish status)
334
+	 * then redirects to the post list.
335
+	 *
336
+	 * @since 1.6
337
+	 *
338
+	 * @param string $status The status to set for the new View
339
+	 *
340
+	 * @return void
341
+	 */
342
+	public function save_as_new_view($status = '')
343
+	{
344
+		if (!(isset($_GET['post']) || isset($_POST['post']))) {
345
+			wp_die(__('No post to duplicate has been supplied!', 'gravityview'));
346
+		}
347
+
348
+		// Get the original post
349
+		$id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
350
+
351
+		if (!$this->current_user_can_copy($id)) {
352
+			wp_die(__('You don\'t have permission to copy this View.', 'gravityview'));
353
+		}
354
+
355
+		$post = get_post($id);
356
+
357
+		// Copy the post and insert it
358
+		if (isset($post) && $post != null) {
359
+			$new_id = $this->create_duplicate($post, $status);
360
+
361
+			if ($status == '') {
362
+				// Redirect to the post list screen
363
+				wp_redirect(admin_url('edit.php?post_type='.$post->post_type));
364
+			} else {
365
+				// Redirect to the edit screen for the new draft post
366
+				wp_redirect(admin_url('post.php?action=edit&post='.$new_id));
367
+			}
368
+			exit;
369
+		} else {
370
+			wp_die(sprintf(esc_attr__('Copy creation failed, could not find original View with ID #%d', 'gravityview'), $id));
371
+		}
372
+	}
373 373
 }
374 374
 
375 375
 new GravityView_Admin_Duplicate_View();
Please login to merge, or discard this patch.
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
     {
15 15
 
16 16
         // Only run on Admin
17
-        if (!is_admin()) {
17
+        if ( ! is_admin() ) {
18 18
             return;
19 19
         }
20 20
 
21 21
         // If the Duplicate Post plugin is active, don't run.
22
-        if (defined('DUPLICATE_POST_CURRENT_VERSION')) {
22
+        if ( defined( 'DUPLICATE_POST_CURRENT_VERSION' ) ) {
23 23
             return;
24 24
         }
25 25
 
@@ -35,18 +35,18 @@  discard block
 block discarded – undo
35 35
      */
36 36
     private function add_hooks()
37 37
     {
38
-        add_filter('post_row_actions', [$this, 'make_duplicate_link_row'], 10, 2);
38
+        add_filter( 'post_row_actions', [ $this, 'make_duplicate_link_row' ], 10, 2 );
39 39
 
40 40
         /**
41 41
          * Connect actions to functions.
42 42
          */
43
-        add_action('admin_action_duplicate_view', [$this, 'save_as_new_view']);
44
-        add_action('admin_action_duplicate_view_as_draft', [$this, 'save_as_new_view_draft']);
43
+        add_action( 'admin_action_duplicate_view', [ $this, 'save_as_new_view' ] );
44
+        add_action( 'admin_action_duplicate_view_as_draft', [ $this, 'save_as_new_view_draft' ] );
45 45
 
46 46
         // Using our action hooks to copy meta fields
47
-        add_action('gv_duplicate_view', [$this, 'copy_view_meta_info'], 10, 2);
47
+        add_action( 'gv_duplicate_view', [ $this, 'copy_view_meta_info' ], 10, 2 );
48 48
 
49
-        add_filter('gravityview_connected_form_links', [$this, 'connected_form_links'], 10, 2);
49
+        add_filter( 'gravityview_connected_form_links', [ $this, 'connected_form_links' ], 10, 2 );
50 50
     }
51 51
 
52 52
     /**
@@ -57,15 +57,15 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @return array If it's the All Views page, return unedited. Otherwise, add a link to create cloned draft of View
59 59
      */
60
-    public function connected_form_links($links = [], $form = [])
60
+    public function connected_form_links( $links = [ ], $form = [ ] )
61 61
     {
62 62
         /** @global WP_Post $post */
63 63
         global $post;
64 64
 
65 65
         // We only want to add Clone links to the Edit View metabox
66
-        if (!$this->is_all_views_page()) {
67
-            if ($duplicate_links = $this->make_duplicate_link_row([], $post)) {
68
-                $links[] = '<span>'.$duplicate_links['edit_as_new_draft'].'</span>';
66
+        if ( ! $this->is_all_views_page() ) {
67
+            if ( $duplicate_links = $this->make_duplicate_link_row( [ ], $post ) ) {
68
+                $links[ ] = '<span>' . $duplicate_links[ 'edit_as_new_draft' ] . '</span>';
69 69
             }
70 70
         }
71 71
 
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @return bool True: user can copy the View; false: nope.
95 95
      */
96
-    private function current_user_can_copy($post)
96
+    private function current_user_can_copy( $post )
97 97
     {
98
-        $id = is_object($post) ? $post->ID : $post;
98
+        $id = is_object( $post ) ? $post->ID : $post;
99 99
 
100 100
         // Can't edit this current View
101
-        return GVCommon::has_cap('copy_gravityviews', $id);
101
+        return GVCommon::has_cap( 'copy_gravityviews', $id );
102 102
     }
103 103
 
104 104
     /**
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
      *
110 110
      * @since 1.6
111 111
      */
112
-    private function create_duplicate($post, $status = '')
112
+    private function create_duplicate( $post, $status = '' )
113 113
     {
114 114
 
115 115
         // We only want to clone Views
116
-        if ($post->post_type !== 'gravityview') {
116
+        if ( $post->post_type !== 'gravityview' ) {
117 117
             return;
118 118
         }
119 119
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
          * @param string|null If string, the status to set for the new View. If empty, use existing View status.
128 128
          * @param WP_Post $post View being cloned
129 129
          */
130
-        $new_view_status = apply_filters('gravityview/duplicate-view/status', $status, $post);
130
+        $new_view_status = apply_filters( 'gravityview/duplicate-view/status', $status, $post );
131 131
 
132 132
         $new_view = [
133 133
             'menu_order'     => $post->menu_order,
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
             'post_mime_type' => $post->post_mime_type,
140 140
             'post_parent'    => $post->post_parent,
141 141
             'post_password'  => $post->post_password,
142
-            'post_status'    => (empty($new_view_status)) ? $post->post_status : $new_view_status,
142
+            'post_status'    => ( empty( $new_view_status ) ) ? $post->post_status : $new_view_status,
143 143
             'post_title'     => $post->post_title,
144 144
             'post_type'      => $post->post_type,
145 145
         ];
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
          * @param bool    $copy_date Whether the copy the date from the existing View. Default: `false`
153 153
          * @param WP_Post $post      View being cloned
154 154
          */
155
-        $copy_date = apply_filters('gravityview/duplicate-view/copy-date', false, $post);
155
+        $copy_date = apply_filters( 'gravityview/duplicate-view/copy-date', false, $post );
156 156
 
157
-        if ($copy_date) {
158
-            $new_view['post_date'] = $new_post_date = $post->post_date;
159
-            $new_view['post_date_gmt'] = get_gmt_from_date($new_post_date);
157
+        if ( $copy_date ) {
158
+            $new_view[ 'post_date' ] = $new_post_date = $post->post_date;
159
+            $new_view[ 'post_date_gmt' ] = get_gmt_from_date( $new_post_date );
160 160
         }
161 161
 
162 162
         /**
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
          * @param array   $new_view Array of settings to be passed to wp_insert_post()
168 168
          * @param WP_Post $post     View being cloned
169 169
          */
170
-        $new_view = apply_filters('gravityview/duplicate-view/new-view', $new_view, $post);
170
+        $new_view = apply_filters( 'gravityview/duplicate-view/new-view', $new_view, $post );
171 171
 
172 172
         // Magic happens here.
173
-        $new_view_id = wp_insert_post($new_view);
173
+        $new_view_id = wp_insert_post( $new_view );
174 174
 
175 175
         // If the copy is published or scheduled, we have to set a proper slug.
176
-        if ($new_view_status == 'publish' || $new_view_status == 'future') {
177
-            $view_name = wp_unique_post_slug($post->post_name, $new_view_id, $new_view_status, $post->post_type, $post->post_parent);
176
+        if ( $new_view_status == 'publish' || $new_view_status == 'future' ) {
177
+            $view_name = wp_unique_post_slug( $post->post_name, $new_view_id, $new_view_status, $post->post_type, $post->post_parent );
178 178
 
179 179
             $new_view_name_array = [
180 180
                 'ID'        => $new_view_id,
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
             ];
183 183
 
184 184
             // Update the post into the database
185
-            wp_update_post($new_view_name_array);
185
+            wp_update_post( $new_view_name_array );
186 186
         }
187 187
 
188 188
         /**
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
          * @param int     $new_view_id The ID of the newly created View
195 195
          * @param WP_Post $post        The View that was just cloned
196 196
          */
197
-        do_action('gv_duplicate_view', $new_view_id, $post);
197
+        do_action( 'gv_duplicate_view', $new_view_id, $post );
198 198
 
199
-        delete_post_meta($new_view_id, '_dp_original');
199
+        delete_post_meta( $new_view_id, '_dp_original' );
200 200
 
201
-        add_post_meta($new_view_id, '_dp_original', $post->ID, false);
201
+        add_post_meta( $new_view_id, '_dp_original', $post->ID, false );
202 202
 
203 203
         return $new_view_id;
204 204
     }
@@ -213,21 +213,21 @@  discard block
 block discarded – undo
213 213
      *
214 214
      * @return void
215 215
      */
216
-    public function copy_view_meta_info($new_id, $post)
216
+    public function copy_view_meta_info( $new_id, $post )
217 217
     {
218
-        $post_meta_keys = get_post_custom_keys($post->ID);
218
+        $post_meta_keys = get_post_custom_keys( $post->ID );
219 219
 
220
-        if (empty($post_meta_keys)) {
220
+        if ( empty( $post_meta_keys ) ) {
221 221
             return;
222 222
         }
223 223
 
224
-        foreach ($post_meta_keys as $meta_key) {
225
-            $meta_values = get_post_custom_values($meta_key, $post->ID);
224
+        foreach ( $post_meta_keys as $meta_key ) {
225
+            $meta_values = get_post_custom_values( $meta_key, $post->ID );
226 226
 
227
-            foreach ($meta_values as $meta_value) {
228
-                $meta_value = maybe_unserialize($meta_value);
227
+            foreach ( $meta_values as $meta_value ) {
228
+                $meta_value = maybe_unserialize( $meta_value );
229 229
 
230
-                add_post_meta($new_id, $meta_key, $meta_value);
230
+                add_post_meta( $new_id, $meta_key, $meta_value );
231 231
             }
232 232
         }
233 233
     }
@@ -240,22 +240,22 @@  discard block
 block discarded – undo
240 240
      * @param array   $actions Row action links. Defaults are 'Edit', 'Quick Edit', 'Restore, 'Trash', 'Delete Permanently', 'Preview', and 'View'
241 241
      * @param WP_Post $post
242 242
      */
243
-    public function make_duplicate_link_row($actions, $post)
243
+    public function make_duplicate_link_row( $actions, $post )
244 244
     {
245 245
 
246 246
         // Only process on GravityView Views
247
-        if (get_post_type($post) === 'gravityview' && $this->current_user_can_copy($post)) {
248
-            $clone_link = $this->get_clone_view_link($post->ID, 'display', false);
249
-            $clone_text = __('Clone', 'gravityview');
250
-            $clone_title = __('Clone this View', 'gravityview');
247
+        if ( get_post_type( $post ) === 'gravityview' && $this->current_user_can_copy( $post ) ) {
248
+            $clone_link = $this->get_clone_view_link( $post->ID, 'display', false );
249
+            $clone_text = __( 'Clone', 'gravityview' );
250
+            $clone_title = __( 'Clone this View', 'gravityview' );
251 251
 
252
-            $actions['clone'] = gravityview_get_link($clone_link, $clone_text, 'title='.$clone_title);
252
+            $actions[ 'clone' ] = gravityview_get_link( $clone_link, $clone_text, 'title=' . $clone_title );
253 253
 
254
-            $clone_draft_link = $this->get_clone_view_link($post->ID);
255
-            $clone_draft_text = $this->is_all_views_page() ? __('New Draft', 'gravityview') : __('Clone View', 'gravityview');
256
-            $clone_draft_title = __('Copy as a new draft View', 'gravityview');
254
+            $clone_draft_link = $this->get_clone_view_link( $post->ID );
255
+            $clone_draft_text = $this->is_all_views_page() ? __( 'New Draft', 'gravityview' ) : __( 'Clone View', 'gravityview' );
256
+            $clone_draft_title = __( 'Copy as a new draft View', 'gravityview' );
257 257
 
258
-            $actions['edit_as_new_draft'] = gravityview_get_link($clone_draft_link, esc_html($clone_draft_text), 'title='.$clone_draft_title);
258
+            $actions[ 'edit_as_new_draft' ] = gravityview_get_link( $clone_draft_link, esc_html( $clone_draft_text ), 'title=' . $clone_draft_title );
259 259
         }
260 260
 
261 261
         return $actions;
@@ -272,32 +272,32 @@  discard block
 block discarded – undo
272 272
      *
273 273
      * @return string
274 274
      */
275
-    private function get_clone_view_link($id = 0, $context = 'display', $draft = true)
275
+    private function get_clone_view_link( $id = 0, $context = 'display', $draft = true )
276 276
     {
277 277
 
278 278
         // Make sure they have permission
279
-        if (false === $this->current_user_can_copy($id)) {
279
+        if ( false === $this->current_user_can_copy( $id ) ) {
280 280
             return '';
281 281
         }
282 282
 
283 283
         // Verify the View exists
284
-        if (!$view = get_post($id)) {
284
+        if ( ! $view = get_post( $id ) ) {
285 285
             return '';
286 286
         }
287 287
 
288 288
         $action_name = $draft ? 'duplicate_view_as_draft' : 'duplicate_view';
289 289
 
290
-        $action = '?action='.$action_name.'&post='.$view->ID;
290
+        $action = '?action=' . $action_name . '&post=' . $view->ID;
291 291
 
292
-        if ('display' == $context) {
293
-            $action = esc_html($action);
292
+        if ( 'display' == $context ) {
293
+            $action = esc_html( $action );
294 294
         }
295 295
 
296
-        $post_type_object = get_post_type_object($view->post_type);
296
+        $post_type_object = get_post_type_object( $view->post_type );
297 297
 
298 298
         /** If there's no gravityview post type for some reason, abort! */
299
-        if (!$post_type_object) {
300
-            gravityview()->log->error('No gravityview post type exists when trying to clone the View.', ['data' => $view]);
299
+        if ( ! $post_type_object ) {
300
+            gravityview()->log->error( 'No gravityview post type exists when trying to clone the View.', [ 'data' => $view ] );
301 301
 
302 302
             return '';
303 303
         }
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
          * @param int    $view_id         View ID
312 312
          * @param string $context         How to display the link. If "display", the URL is run through esc_html(). Default: `display`
313 313
          */
314
-        $clone_view_link = apply_filters('gravityview/duplicate-view/get_clone_view_link', admin_url('admin.php'.$action), $view->ID, $context);
314
+        $clone_view_link = apply_filters( 'gravityview/duplicate-view/get_clone_view_link', admin_url( 'admin.php' . $action ), $view->ID, $context );
315 315
 
316 316
         return $clone_view_link;
317 317
     }
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
      */
327 327
     public function save_as_new_view_draft()
328 328
     {
329
-        $this->save_as_new_view('draft');
329
+        $this->save_as_new_view( 'draft' );
330 330
     }
331 331
 
332 332
     /**
@@ -339,35 +339,35 @@  discard block
 block discarded – undo
339 339
      *
340 340
      * @return void
341 341
      */
342
-    public function save_as_new_view($status = '')
342
+    public function save_as_new_view( $status = '' )
343 343
     {
344
-        if (!(isset($_GET['post']) || isset($_POST['post']))) {
345
-            wp_die(__('No post to duplicate has been supplied!', 'gravityview'));
344
+        if ( ! ( isset( $_GET[ 'post' ] ) || isset( $_POST[ 'post' ] ) ) ) {
345
+            wp_die( __( 'No post to duplicate has been supplied!', 'gravityview' ) );
346 346
         }
347 347
 
348 348
         // Get the original post
349
-        $id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']);
349
+        $id = ( isset( $_GET[ 'post' ] ) ? $_GET[ 'post' ] : $_POST[ 'post' ] );
350 350
 
351
-        if (!$this->current_user_can_copy($id)) {
352
-            wp_die(__('You don\'t have permission to copy this View.', 'gravityview'));
351
+        if ( ! $this->current_user_can_copy( $id ) ) {
352
+            wp_die( __( 'You don\'t have permission to copy this View.', 'gravityview' ) );
353 353
         }
354 354
 
355
-        $post = get_post($id);
355
+        $post = get_post( $id );
356 356
 
357 357
         // Copy the post and insert it
358
-        if (isset($post) && $post != null) {
359
-            $new_id = $this->create_duplicate($post, $status);
358
+        if ( isset( $post ) && $post != null ) {
359
+            $new_id = $this->create_duplicate( $post, $status );
360 360
 
361
-            if ($status == '') {
361
+            if ( $status == '' ) {
362 362
                 // Redirect to the post list screen
363
-                wp_redirect(admin_url('edit.php?post_type='.$post->post_type));
363
+                wp_redirect( admin_url( 'edit.php?post_type=' . $post->post_type ) );
364 364
             } else {
365 365
                 // Redirect to the edit screen for the new draft post
366
-                wp_redirect(admin_url('post.php?action=edit&post='.$new_id));
366
+                wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_id ) );
367 367
             }
368 368
             exit;
369 369
         } else {
370
-            wp_die(sprintf(esc_attr__('Copy creation failed, could not find original View with ID #%d', 'gravityview'), $id));
370
+            wp_die( sprintf( esc_attr__( 'Copy creation failed, could not find original View with ID #%d', 'gravityview' ), $id ) );
371 371
         }
372 372
     }
373 373
 }
Please login to merge, or discard this patch.
Braces   +12 added lines, -24 removed lines patch added patch discarded remove patch
@@ -8,10 +8,8 @@  discard block
 block discarded – undo
8 8
  *
9 9
  * @since 1.6
10 10
  */
11
-class GravityView_Admin_Duplicate_View
12
-{
13
-    public function __construct()
14
-    {
11
+class GravityView_Admin_Duplicate_View {
12
+    public function __construct() {
15 13
 
16 14
         // Only run on Admin
17 15
         if (!is_admin()) {
@@ -33,8 +31,7 @@  discard block
 block discarded – undo
33 31
      *
34 32
      * @return void
35 33
      */
36
-    private function add_hooks()
37
-    {
34
+    private function add_hooks() {
38 35
         add_filter('post_row_actions', [$this, 'make_duplicate_link_row'], 10, 2);
39 36
 
40 37
         /**
@@ -57,8 +54,7 @@  discard block
 block discarded – undo
57 54
      *
58 55
      * @return array If it's the All Views page, return unedited. Otherwise, add a link to create cloned draft of View
59 56
      */
60
-    public function connected_form_links($links = [], $form = [])
61
-    {
57
+    public function connected_form_links($links = [], $form = []) {
62 58
         /** @global WP_Post $post */
63 59
         global $post;
64 60
 
@@ -77,8 +73,7 @@  discard block
 block discarded – undo
77 73
      *
78 74
      * @return bool
79 75
      */
80
-    private function is_all_views_page()
81
-    {
76
+    private function is_all_views_page() {
82 77
         global $pagenow;
83 78
 
84 79
         return $pagenow === 'edit.php';
@@ -93,8 +88,7 @@  discard block
 block discarded – undo
93 88
      *
94 89
      * @return bool True: user can copy the View; false: nope.
95 90
      */
96
-    private function current_user_can_copy($post)
97
-    {
91
+    private function current_user_can_copy($post) {
98 92
         $id = is_object($post) ? $post->ID : $post;
99 93
 
100 94
         // Can't edit this current View
@@ -109,8 +103,7 @@  discard block
 block discarded – undo
109 103
      *
110 104
      * @since 1.6
111 105
      */
112
-    private function create_duplicate($post, $status = '')
113
-    {
106
+    private function create_duplicate($post, $status = '') {
114 107
 
115 108
         // We only want to clone Views
116 109
         if ($post->post_type !== 'gravityview') {
@@ -213,8 +206,7 @@  discard block
 block discarded – undo
213 206
      *
214 207
      * @return void
215 208
      */
216
-    public function copy_view_meta_info($new_id, $post)
217
-    {
209
+    public function copy_view_meta_info($new_id, $post) {
218 210
         $post_meta_keys = get_post_custom_keys($post->ID);
219 211
 
220 212
         if (empty($post_meta_keys)) {
@@ -240,8 +232,7 @@  discard block
 block discarded – undo
240 232
      * @param array   $actions Row action links. Defaults are 'Edit', 'Quick Edit', 'Restore, 'Trash', 'Delete Permanently', 'Preview', and 'View'
241 233
      * @param WP_Post $post
242 234
      */
243
-    public function make_duplicate_link_row($actions, $post)
244
-    {
235
+    public function make_duplicate_link_row($actions, $post) {
245 236
 
246 237
         // Only process on GravityView Views
247 238
         if (get_post_type($post) === 'gravityview' && $this->current_user_can_copy($post)) {
@@ -272,8 +263,7 @@  discard block
 block discarded – undo
272 263
      *
273 264
      * @return string
274 265
      */
275
-    private function get_clone_view_link($id = 0, $context = 'display', $draft = true)
276
-    {
266
+    private function get_clone_view_link($id = 0, $context = 'display', $draft = true) {
277 267
 
278 268
         // Make sure they have permission
279 269
         if (false === $this->current_user_can_copy($id)) {
@@ -324,8 +314,7 @@  discard block
 block discarded – undo
324 314
      *
325 315
      * @return void
326 316
      */
327
-    public function save_as_new_view_draft()
328
-    {
317
+    public function save_as_new_view_draft() {
329 318
         $this->save_as_new_view('draft');
330 319
     }
331 320
 
@@ -339,8 +328,7 @@  discard block
 block discarded – undo
339 328
      *
340 329
      * @return void
341 330
      */
342
-    public function save_as_new_view($status = '')
343
-    {
331
+    public function save_as_new_view($status = '') {
344 332
         if (!(isset($_GET['post']) || isset($_POST['post']))) {
345 333
             wp_die(__('No post to duplicate has been supplied!', 'gravityview'));
346 334
         }
Please login to merge, or discard this patch.
includes/import-functions.php 3 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -49,49 +49,49 @@  discard block
 block discarded – undo
49 49
  */
50 50
 function gravityview_import_helper_fix_line_breaks($postmeta = [], $post_id = 0, $post = [])
51 51
 {
52
-    if (empty($post['postmeta'])) {
53
-        return $postmeta;
54
-    }
52
+	if (empty($post['postmeta'])) {
53
+		return $postmeta;
54
+	}
55 55
 
56
-    if ('gravityview' !== $post['post_type']) {
57
-        return $postmeta;
58
-    }
56
+	if ('gravityview' !== $post['post_type']) {
57
+		return $postmeta;
58
+	}
59 59
 
60
-    $keys_to_fix = [
61
-        '_gravityview_directory_fields',
62
-        '_gravityview_directory_widgets',
63
-    ];
60
+	$keys_to_fix = [
61
+		'_gravityview_directory_fields',
62
+		'_gravityview_directory_widgets',
63
+	];
64 64
 
65
-    $performed_fix = false;
65
+	$performed_fix = false;
66 66
 
67
-    foreach ($postmeta as &$meta) {
68
-        $key = $meta['key'];
67
+	foreach ($postmeta as &$meta) {
68
+		$key = $meta['key'];
69 69
 
70
-        if (!in_array($key, $keys_to_fix, true)) {
71
-            continue;
72
-        }
70
+		if (!in_array($key, $keys_to_fix, true)) {
71
+			continue;
72
+		}
73 73
 
74
-        $is_valid_serialized_data = maybe_unserialize($meta['value']);
74
+		$is_valid_serialized_data = maybe_unserialize($meta['value']);
75 75
 
76
-        // The values are not corrupted serialized data. No need to fix.
77
-        if (false !== $is_valid_serialized_data) {
78
-            continue;
79
-        }
76
+		// The values are not corrupted serialized data. No need to fix.
77
+		if (false !== $is_valid_serialized_data) {
78
+			continue;
79
+		}
80 80
 
81
-        $meta['value'] = str_replace("\n", "\n\n", $meta['value']);
81
+		$meta['value'] = str_replace("\n", "\n\n", $meta['value']);
82 82
 
83
-        $performed_fix = true;
84
-    }
83
+		$performed_fix = true;
84
+	}
85 85
 
86
-    // Leave a note that this modification has been done. We'll use it later.
87
-    if ($performed_fix) {
88
-        $postmeta[] = [
89
-            'key'   => '_gravityview_fixed_import_serialization',
90
-            'value' => 1,
91
-        ];
92
-    }
86
+	// Leave a note that this modification has been done. We'll use it later.
87
+	if ($performed_fix) {
88
+		$postmeta[] = [
89
+			'key'   => '_gravityview_fixed_import_serialization',
90
+			'value' => 1,
91
+		];
92
+	}
93 93
 
94
-    return $postmeta;
94
+	return $postmeta;
95 95
 }
96 96
 
97 97
 add_action('import_post_meta', 'gravityview_import_helper_restore_line_breaks', 10, 3);
@@ -108,29 +108,29 @@  discard block
 block discarded – undo
108 108
  */
109 109
 function gravityview_import_helper_restore_line_breaks($post_id, $key, $value)
110 110
 {
111
-    $keys_to_fix = [
112
-        '_gravityview_directory_fields',
113
-        '_gravityview_directory_widgets',
114
-    ];
111
+	$keys_to_fix = [
112
+		'_gravityview_directory_fields',
113
+		'_gravityview_directory_widgets',
114
+	];
115 115
 
116
-    if (!in_array($key, $keys_to_fix, true)) {
117
-        return;
118
-    }
116
+	if (!in_array($key, $keys_to_fix, true)) {
117
+		return;
118
+	}
119 119
 
120
-    if (false === get_post_meta($post_id, '_gravityview_fixed_import_serialization')) {
121
-        return;
122
-    }
120
+	if (false === get_post_meta($post_id, '_gravityview_fixed_import_serialization')) {
121
+		return;
122
+	}
123 123
 
124
-    if (empty($value) || !is_string($value)) {
125
-        return;
126
-    }
124
+	if (empty($value) || !is_string($value)) {
125
+		return;
126
+	}
127 127
 
128
-    if (false === strpos($value, "\n\n")) {
129
-        return;
130
-    }
128
+	if (false === strpos($value, "\n\n")) {
129
+		return;
130
+	}
131 131
 
132
-    // Restore the single new line.
133
-    $updated_value = str_replace("\n\n", "\n", $value);
132
+	// Restore the single new line.
133
+	$updated_value = str_replace("\n\n", "\n", $value);
134 134
 
135
-    update_post_meta($updated_value, $key, $updated_value);
135
+	update_post_meta($updated_value, $key, $updated_value);
136 136
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  *
12 12
  * @copyright Copyright 2021, Katz Web Services, Inc.
13 13
  */
14
-add_action('wp_import_post_meta', 'gravityview_import_helper_fix_line_breaks', 10, 3);
14
+add_action( 'wp_import_post_meta', 'gravityview_import_helper_fix_line_breaks', 10, 3 );
15 15
 
16 16
 /**
17 17
  * Fixes broken serialization character counts when new line characters are in the exported XML.
@@ -47,13 +47,13 @@  discard block
 block discarded – undo
47 47
  *
48 48
  * @return array Modified array, if GravityView
49 49
  */
50
-function gravityview_import_helper_fix_line_breaks($postmeta = [], $post_id = 0, $post = [])
50
+function gravityview_import_helper_fix_line_breaks( $postmeta = [ ], $post_id = 0, $post = [ ] )
51 51
 {
52
-    if (empty($post['postmeta'])) {
52
+    if ( empty( $post[ 'postmeta' ] ) ) {
53 53
         return $postmeta;
54 54
     }
55 55
 
56
-    if ('gravityview' !== $post['post_type']) {
56
+    if ( 'gravityview' !== $post[ 'post_type' ] ) {
57 57
         return $postmeta;
58 58
     }
59 59
 
@@ -64,28 +64,28 @@  discard block
 block discarded – undo
64 64
 
65 65
     $performed_fix = false;
66 66
 
67
-    foreach ($postmeta as &$meta) {
68
-        $key = $meta['key'];
67
+    foreach ( $postmeta as &$meta ) {
68
+        $key = $meta[ 'key' ];
69 69
 
70
-        if (!in_array($key, $keys_to_fix, true)) {
70
+        if ( ! in_array( $key, $keys_to_fix, true ) ) {
71 71
             continue;
72 72
         }
73 73
 
74
-        $is_valid_serialized_data = maybe_unserialize($meta['value']);
74
+        $is_valid_serialized_data = maybe_unserialize( $meta[ 'value' ] );
75 75
 
76 76
         // The values are not corrupted serialized data. No need to fix.
77
-        if (false !== $is_valid_serialized_data) {
77
+        if ( false !== $is_valid_serialized_data ) {
78 78
             continue;
79 79
         }
80 80
 
81
-        $meta['value'] = str_replace("\n", "\n\n", $meta['value']);
81
+        $meta[ 'value' ] = str_replace( "\n", "\n\n", $meta[ 'value' ] );
82 82
 
83 83
         $performed_fix = true;
84 84
     }
85 85
 
86 86
     // Leave a note that this modification has been done. We'll use it later.
87
-    if ($performed_fix) {
88
-        $postmeta[] = [
87
+    if ( $performed_fix ) {
88
+        $postmeta[ ] = [
89 89
             'key'   => '_gravityview_fixed_import_serialization',
90 90
             'value' => 1,
91 91
         ];
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     return $postmeta;
95 95
 }
96 96
 
97
-add_action('import_post_meta', 'gravityview_import_helper_restore_line_breaks', 10, 3);
97
+add_action( 'import_post_meta', 'gravityview_import_helper_restore_line_breaks', 10, 3 );
98 98
 
99 99
 /**
100 100
  * Restores the single new line for imported Views that have been modified.
@@ -106,31 +106,31 @@  discard block
 block discarded – undo
106 106
  * @param string $key
107 107
  * @param mixed  $value
108 108
  */
109
-function gravityview_import_helper_restore_line_breaks($post_id, $key, $value)
109
+function gravityview_import_helper_restore_line_breaks( $post_id, $key, $value )
110 110
 {
111 111
     $keys_to_fix = [
112 112
         '_gravityview_directory_fields',
113 113
         '_gravityview_directory_widgets',
114 114
     ];
115 115
 
116
-    if (!in_array($key, $keys_to_fix, true)) {
116
+    if ( ! in_array( $key, $keys_to_fix, true ) ) {
117 117
         return;
118 118
     }
119 119
 
120
-    if (false === get_post_meta($post_id, '_gravityview_fixed_import_serialization')) {
120
+    if ( false === get_post_meta( $post_id, '_gravityview_fixed_import_serialization' ) ) {
121 121
         return;
122 122
     }
123 123
 
124
-    if (empty($value) || !is_string($value)) {
124
+    if ( empty( $value ) || ! is_string( $value ) ) {
125 125
         return;
126 126
     }
127 127
 
128
-    if (false === strpos($value, "\n\n")) {
128
+    if ( false === strpos( $value, "\n\n" ) ) {
129 129
         return;
130 130
     }
131 131
 
132 132
     // Restore the single new line.
133
-    $updated_value = str_replace("\n\n", "\n", $value);
133
+    $updated_value = str_replace( "\n\n", "\n", $value );
134 134
 
135
-    update_post_meta($updated_value, $key, $updated_value);
135
+    update_post_meta( $updated_value, $key, $updated_value );
136 136
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -47,8 +47,7 @@  discard block
 block discarded – undo
47 47
  *
48 48
  * @return array Modified array, if GravityView
49 49
  */
50
-function gravityview_import_helper_fix_line_breaks($postmeta = [], $post_id = 0, $post = [])
51
-{
50
+function gravityview_import_helper_fix_line_breaks($postmeta = [], $post_id = 0, $post = []) {
52 51
     if (empty($post['postmeta'])) {
53 52
         return $postmeta;
54 53
     }
@@ -106,8 +105,7 @@  discard block
 block discarded – undo
106 105
  * @param string $key
107 106
  * @param mixed  $value
108 107
  */
109
-function gravityview_import_helper_restore_line_breaks($post_id, $key, $value)
110
-{
108
+function gravityview_import_helper_restore_line_breaks($post_id, $key, $value) {
111 109
     $keys_to_fix = [
112 110
         '_gravityview_directory_fields',
113 111
         '_gravityview_directory_widgets',
Please login to merge, or discard this patch.
includes/class-cache.php 3 patches
Indentation   +560 added lines, -560 removed lines patch added patch discarded remove patch
@@ -5,523 +5,523 @@  discard block
 block discarded – undo
5 5
  */
6 6
 class GravityView_Cache
7 7
 {
8
-    /** @deprecated 2.14 - use BLOCKLIST_OPTION_NAME instead! */
9
-    const BLACKLIST_OPTION_NAME = 'gravityview_cache_blocklist';
10
-
11
-    const BLOCKLIST_OPTION_NAME = 'gravityview_cache_blocklist';
12
-
13
-    /**
14
-     * Form ID, or array of Form IDs.
15
-     *
16
-     * @var mixed
17
-     */
18
-    protected $form_ids;
19
-
20
-    /**
21
-     * Extra request parameters used to generate the query. This is used to generate the unique transient key.
22
-     *
23
-     * @var array
24
-     */
25
-    protected $args;
26
-
27
-    /**
28
-     * The transient key used to store the cached item. 45 characters long.
29
-     *
30
-     * @var string
31
-     */
32
-    private $key = '';
33
-
34
-    /**
35
-     * @since 1.13.1
36
-     *
37
-     * @var array Columns in the database for leads
38
-     */
39
-    private $lead_db_columns = ['id', 'form_id', 'post_id', 'date_created', 'is_starred', 'is_read', 'ip', 'source_url', 'user_agent', 'currency', 'payment_status', 'payment_date', 'payment_amount', 'transaction_id', 'is_fulfilled', 'created_by', 'transaction_type', 'status'];
40
-
41
-    /**
42
-     * @param array|int $form_ids Form ID or array of form IDs used in a request
43
-     * @param array     $args     Extra request parameters used to generate the query. This is used to generate the unique transient key.
44
-     */
45
-    public function __construct($form_ids = null, $args = [])
46
-    {
47
-        $this->add_hooks();
48
-
49
-        if (!is_null($form_ids)) {
50
-            $this->form_ids = $form_ids;
51
-
52
-            $this->args = $args;
53
-
54
-            $this->set_key();
55
-        }
56
-    }
57
-
58
-    /**
59
-     * Add actions for clearing out caches when entries are updated.
60
-     */
61
-    public function add_hooks()
62
-    {
63
-
64
-        // Schedule cleanup of expired transients
65
-        add_action('wp', [$this, 'schedule_transient_cleanup']);
66
-
67
-        // Hook in to the scheduled cleanup, if scheduled
68
-        add_action('gravityview-expired-transients', [$this, 'delete_expired_transients']);
69
-
70
-        // Trigger this when you need to prevent any results from being cached with forms that have been modified
71
-        add_action('gravityview_clear_form_cache', [$this, 'blocklist_add']);
72
-
73
-        /**
74
-         * @since 1.14
75
-         */
76
-        add_action('gravityview_clear_entry_cache', [$this, 'entry_status_changed']);
77
-
78
-        add_action('gform_after_update_entry', [$this, 'entry_updated'], 10, 2);
79
-
80
-        add_action('gform_entry_created', [$this, 'entry_created'], 10, 2);
81
-
82
-        add_action('gform_post_add_entry', [$this, 'entry_added'], 10, 2);
83
-
84
-        /**
85
-         * @see RGFormsModel::update_lead_property() Trigger when any entry property changes
86
-         */
87
-        foreach ($this->lead_db_columns as $column) {
88
-            add_action('gform_update_'.$column, [$this, 'entry_status_changed'], 10, 3);
89
-        }
90
-
91
-        add_action('gform_delete_lead', [$this, 'entry_status_changed'], 10);
92
-    }
93
-
94
-    /**
95
-     * Force refreshing a cache when an entry is deleted.
96
-     *
97
-     * The `gform_delete_lead` action is called before the lead is deleted; we fetch the entry to find out the form ID so it can be added to the blocklist.
98
-     *
99
-     * @since  1.5.1
100
-     *
101
-     * @param int    $lead_id        Entry ID
102
-     * @param string $property_value Previous value of the lead status passed by gform_update_status hook
103
-     * @param string $previous_value Previous value of the lead status passed by gform_update_status hook
104
-     *
105
-     * @return void
106
-     */
107
-    public function entry_status_changed($lead_id, $property_value = '', $previous_value = '')
108
-    {
109
-        $entry = GFAPI::get_entry($lead_id);
110
-
111
-        if (is_wp_error($entry)) {
112
-            gravityview()->log->error('Could not retrieve entry {entry_id} to delete it: {error}', ['entry_id' => $lead_id, 'error' => $entry->get_error_message()]);
113
-
114
-            return;
115
-        }
116
-
117
-        gravityview()->log->debug('adding form {form_id} to blocklist because entry #{lead_id} was deleted', ['form_id' => $entry['form_id'], 'entry_id' => $lead_id, 'data' => ['value' => $property_value, 'previous' => $previous_value]]);
118
-
119
-        $this->blocklist_add($entry['form_id']);
120
-    }
121
-
122
-    /**
123
-     * When an entry is updated, add the entry's form to the cache blocklist.
124
-     *
125
-     * @param array $form    GF form array
126
-     * @param int   $lead_id Entry ID
127
-     *
128
-     * @return void
129
-     */
130
-    public function entry_updated($form, $lead_id)
131
-    {
132
-        gravityview()->log->debug(' adding form {form_id} to blocklist because entry #{entry_id} was updated', ['form_id' => $form['id'], 'entry_id' => $lead_id]);
133
-
134
-        $this->blocklist_add($form['id']);
135
-    }
136
-
137
-    /**
138
-     * When an entry is created, add the entry's form to the cache blocklist.
139
-     *
140
-     * We don't want old caches; when an entry is added, we want to clear the cache.
141
-     *
142
-     * @param array $entry GF entry array
143
-     * @param array $form  GF form array
144
-     *
145
-     * @return void
146
-     */
147
-    public function entry_created($entry, $form)
148
-    {
149
-        gravityview()->log->debug('adding form {form_id} to blocklist because entry #{entry_id} was created', ['form_id' => $form['id'], 'entry_id' => $entry['id']]);
150
-
151
-        $this->blocklist_add($form['id']);
152
-    }
153
-
154
-    /**
155
-     * Clear the cache when entries are added via GFAPI::add_entry().
156
-     *
157
-     * @param array $entry The GF Entry array
158
-     * @param array $form  The GF Form array
159
-     *
160
-     * @return void
161
-     */
162
-    public function entry_added($entry, $form)
163
-    {
164
-        if (is_wp_error($entry)) {
165
-            return;
166
-        }
167
-
168
-        gravityview()->log->debug('adding form {form_id} to blocklist because entry #{entry_id} was added', ['form_id' => $form['id'], 'entry_id' => $entry['id']]);
169
-
170
-        $this->blocklist_add($form['id']);
171
-    }
172
-
173
-    /**
174
-     * Calculate the prefix based on the Form IDs.
175
-     *
176
-     * @param int|array $form_ids Form IDs to generate prefix for
177
-     *
178
-     * @return string Prefix for the cache string used in set_key()
179
-     */
180
-    protected function get_cache_key_prefix($form_ids = null)
181
-    {
182
-        if (is_null($form_ids)) {
183
-            $form_ids = $this->form_ids;
184
-        }
185
-
186
-        // Normally just one form, but supports multiple forms
187
-        //
188
-        // Array of IDs 12, 5, 14 would result in `f:12-f:5-f:14`
189
-        $forms = 'f:'.implode('-f:', (array) $form_ids);
190
-
191
-        // Prefix for transient keys
192
-        // Now the prefix would be: `gv-cache-f:12-f:5-f:14-`
193
-        return 'gv-cache-'.$forms.'-';
194
-    }
195
-
196
-    /**
197
-     * Set the transient key based on the form IDs and the arguments passed to the class.
198
-     */
199
-    protected function set_key()
200
-    {
201
-
202
-        // Don't set key if no forms have been set.
203
-        if (empty($this->form_ids)) {
204
-            return;
205
-        }
206
-
207
-        $key = $this->get_cache_key_prefix().sha1(serialize($this->args));
208
-
209
-        // The transient name column can handle up to 64 characters.
210
-        // The `_transient_timeout_` prefix that is prepended to the string is 11 characters.
211
-        // 64 - 19 = 45
212
-        // We make sure the key isn't too long or else WP doesn't store data.
213
-        $this->key = substr($key, 0, 45);
214
-    }
215
-
216
-    /**
217
-     * Allow public access to get transient key.
218
-     *
219
-     * @return string Transient key
220
-     */
221
-    public function get_key()
222
-    {
223
-        return $this->key;
224
-    }
225
-
226
-    /**
227
-     * Add form IDs to a "blocklist" to force the cache to be refreshed.
228
-     *
229
-     * @param int|array $form_ids Form IDs to force to be updated
230
-     *
231
-     * @return bool False if value was not updated and true if value was updated.
232
-     */
233
-    public function blocklist_add($form_ids)
234
-    {
235
-        $blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
236
-
237
-        $form_ids = is_array($form_ids) ? $form_ids : [$form_ids];
238
-
239
-        // Add the passed form IDs
240
-        $blocklist = array_merge((array) $blocklist, $form_ids);
241
-
242
-        // Don't duplicate
243
-        $blocklist = array_unique($blocklist);
244
-
245
-        // Remove empty items from blocklist
246
-        $blocklist = array_filter($blocklist);
247
-
248
-        $updated = update_option(self::BLOCKLIST_OPTION_NAME, $blocklist);
249
-
250
-        if (false !== $updated) {
251
-            gravityview()->log->debug('Added form IDs to cache blocklist', ['data' => [
252
-                '$form_ids'  => $form_ids,
253
-                '$blocklist' => $blocklist,
254
-            ]]);
255
-        }
256
-
257
-        return $updated;
258
-    }
259
-
260
-    /**
261
-     * @deprecated 2.14 {@see GravityView_Cache::blocklist_add()}
262
-     *
263
-     * @param int|array $form_ids Form IDs to force to be updated
264
-     *
265
-     * @return bool Whether the removal was successful
266
-     */
267
-    public function blacklist_add($form_ids)
268
-    {
269
-        _deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::blocklist_add()');
270
-
271
-        return $this->blocklist_remove($form_ids);
272
-    }
273
-
274
-    /**
275
-     * Remove Form IDs from blocklist.
276
-     *
277
-     * @param int|array $form_ids Form IDs to remove
278
-     *
279
-     * @return bool Whether the removal was successful
280
-     */
281
-    public function blocklist_remove($form_ids)
282
-    {
283
-        $blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
284
-
285
-        $updated_list = array_diff($blocklist, (array) $form_ids);
286
-
287
-        gravityview()->log->debug('Removing form IDs from cache blocklist', ['data' => [
288
-            '$form_ids'     => $form_ids,
289
-            '$blocklist'    => $blocklist,
290
-            '$updated_list' => $updated_list,
291
-        ]]);
292
-
293
-        return update_option(self::BLOCKLIST_OPTION_NAME, $updated_list);
294
-    }
295
-
296
-    /**
297
-     * @deprecated 2.14 {@see GravityView_Cache::blocklist_remove()}
298
-     *
299
-     * @param int|array $form_ids Form IDs to add
300
-     *
301
-     * @return bool Whether the removal was successful
302
-     */
303
-    public function blacklist_remove($form_ids)
304
-    {
305
-        _deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::blocklist_remove()');
306
-
307
-        return $this->blocklist_remove($form_ids);
308
-    }
309
-
310
-    /**
311
-     * Is a form ID in the cache blocklist?
312
-     *
313
-     * @param int|array $form_ids Form IDs to check if in blocklist
314
-     *
315
-     * @deprecated 2.14 Use {@see GravityView_Cache::in_blocklist()}
316
-     *
317
-     * @return bool
318
-     */
319
-    public function in_blacklist($form_ids = null)
320
-    {
321
-        _deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::in_blocklist()');
322
-
323
-        return $this->in_blocklist($form_ids);
324
-    }
325
-
326
-    /**
327
-     * Is a form ID in the cache blocklist.
328
-     *
329
-     * @param int|array $form_ids Form IDs to check if in blocklist
330
-     *
331
-     * @return bool
332
-     */
333
-    public function in_blocklist($form_ids = null)
334
-    {
335
-        $blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
336
-
337
-        // Use object var if exists
338
-        $form_ids = is_null($form_ids) ? $this->form_ids : $form_ids;
339
-
340
-        if (empty($form_ids)) {
341
-            gravityview()->log->debug('Did not add form to blocklist; empty form ID', ['data' => $form_ids]);
342
-
343
-            return false;
344
-        }
345
-
346
-        foreach ((array) $form_ids as $form_id) {
347
-            if (in_array($form_id, $blocklist)) {
348
-                gravityview()->log->debug('Form #{form_id} is in the cache blocklist', ['form_id' => $form_id]);
349
-
350
-                return true;
351
-            }
352
-        }
353
-
354
-        return false;
355
-    }
356
-
357
-    /**
358
-     * Get transient result.
359
-     *
360
-     * @param string $key Transient key to fetch
361
-     *
362
-     * @return mixed False: Not using cache or cache was a WP_Error object; NULL: no results found; Mixed: cache value
363
-     */
364
-    public function get($key = null)
365
-    {
366
-        $key = is_null($key) ? $this->key : $key;
367
-
368
-        if (!$this->use_cache()) {
369
-            gravityview()->log->debug('Not using cached results because of GravityView_Cache->use_cache() results');
370
-
371
-            return false;
372
-        }
373
-
374
-        gravityview()->log->debug('Fetching request with transient key {key}', ['key' => $key]);
375
-
376
-        $result = get_transient($key);
377
-
378
-        if (is_wp_error($result)) {
379
-            gravityview()->log->debug('Fetching request resulted in error:', ['data' => $result]);
380
-
381
-            return false;
382
-        } elseif ($result) {
383
-            gravityview()->log->debug('Cached results found for  transient key {key}', ['key' => $key]);
384
-
385
-            return $result;
386
-        }
387
-
388
-        gravityview()->log->debug('No cached results found for  transient key {key}', ['key' => $key]);
389
-
390
-        return null;
391
-    }
392
-
393
-    /**
394
-     * Cache content as a transient.
395
-     *
396
-     * Cache time defaults to 1 week
397
-     *
398
-     * @param mixed  $content     [description]
399
-     * @param string $filter_name Name used to modify the cache time. Will be set to `gravityview_cache_time_{$filter_name}`.
400
-     *
401
-     * @return bool If $content is not set, false. Otherwise, returns true if transient was set and false if not.
402
-     */
403
-    public function set($content, $filter_name = '')
404
-    {
405
-
406
-        // Don't cache empty results
407
-        if (!empty($content)) {
408
-
409
-            /**
410
-             * @filter `gravityview_cache_time_{$filter_name}` Modify the cache time for a type of cache
411
-             *
412
-             * @param int $time_in_seconds Default: `DAY_IN_SECONDS`
413
-             */
414
-            $cache_time = (int) apply_filters('gravityview_cache_time_'.$filter_name, DAY_IN_SECONDS);
415
-
416
-            gravityview()->log->debug('Setting cache with transient key {key} for {cache_time} seconds', ['key' => $this->key, 'cache_time' => $cache_time]);
417
-
418
-            return set_transient($this->key, $content, $cache_time);
419
-        }
420
-
421
-        gravityview()->log->debug('Cache not set; content is empty');
422
-
423
-        return false;
424
-    }
425
-
426
-    /**
427
-     * Delete cached transients based on form IDs.
428
-     *
429
-     * @todo Use REGEX to match forms when array of form IDs is passed, instead of using a simple LIKE
430
-     * @todo  Rate limit deleting to prevent abuse
431
-     *
432
-     * @param int|array $form_ids Form IDs to delete
433
-     *
434
-     * @return void
435
-     */
436
-    public function delete($form_ids = null)
437
-    {
438
-        global $wpdb;
439
-
440
-        // Use object var if exists
441
-        $form_ids = is_null($form_ids) ? $this->form_ids : $form_ids;
442
-
443
-        if (empty($form_ids)) {
444
-            gravityview()->log->debug('Did not delete cache; empty form IDs');
445
-
446
-            return;
447
-        }
448
-
449
-        foreach ((array) $form_ids as $form_id) {
450
-            $key = '_transient_gv-cache-';
451
-
452
-            $key = $wpdb->esc_like($key);
453
-
454
-            $form_id = intval($form_id);
455
-
456
-            // Find the transients containing this form
457
-            $key = "$key%f:$form_id-%"; // \_transient\_gv-cache-%f:1-% for example
458
-            $sql = $wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE `option_name` LIKE %s", $key);
459
-
460
-            foreach (($transients = $wpdb->get_col($sql)) as $transient) {
461
-                // We have to delete it via the API to make sure the object cache is updated appropriately
462
-                delete_transient(preg_replace('#^_transient_#', '', $transient));
463
-            }
464
-
465
-            gravityview()->log->debug('Deleting cache for form #{form_id}', ['form_id' => $form_id, 'data' => [
466
-                $sql,
467
-                sprintf('Deleted results: %d', count($transients)),
468
-            ]]);
469
-        }
470
-    }
471
-
472
-    /**
473
-     * Schedule expired transient cleanup twice a day.
474
-     *
475
-     * Can be overruled by the `gravityview_cleanup_transients` filter (returns boolean)
476
-     *
477
-     * @return void
478
-     */
479
-    public function schedule_transient_cleanup()
480
-    {
481
-
482
-        /**
483
-         * @filter `gravityview_cleanup_transients` Override GravityView cleanup of transients by setting this to false
484
-         *
485
-         * @param bool $cleanup Whether to run the GravityView auto-cleanup of transients. Default: `true`
486
-         */
487
-        $cleanup = apply_filters('gravityview_cleanup_transients', true);
488
-
489
-        if (!$cleanup) {
490
-            return;
491
-        }
492
-
493
-        if (!wp_next_scheduled('gravityview-expired-transients')) {
494
-            wp_schedule_event(time(), 'daily', 'gravityview-expired-transients');
495
-        }
496
-    }
497
-
498
-    /**
499
-     * Delete expired transients.
500
-     *
501
-     * The code is copied from the Delete Expired Transients, with slight modifications to track # of results and to get the blog ID dynamically
502
-     *
503
-     * @see https://wordpress.org/plugins/delete-expired-transients/ Plugin where the code was taken from
504
-     * @see  DelxtransCleaners::clearBlogExpired()
505
-     *
506
-     * @return void
507
-     */
508
-    public function delete_expired_transients()
509
-    {
510
-        global $wpdb;
511
-
512
-        // Added this line, which isn't in the plugin
513
-        $blog_id = get_current_blog_id();
514
-
515
-        $num_results = 0;
516
-
517
-        // get current PHP time, offset by a minute to avoid clashes with other tasks
518
-        $threshold = time() - 60;
519
-
520
-        // get table name for options on specified blog
521
-        $table = $wpdb->get_blog_prefix($blog_id).'options';
522
-
523
-        // delete expired transients, using the paired timeout record to find them
524
-        $sql = "
8
+	/** @deprecated 2.14 - use BLOCKLIST_OPTION_NAME instead! */
9
+	const BLACKLIST_OPTION_NAME = 'gravityview_cache_blocklist';
10
+
11
+	const BLOCKLIST_OPTION_NAME = 'gravityview_cache_blocklist';
12
+
13
+	/**
14
+	 * Form ID, or array of Form IDs.
15
+	 *
16
+	 * @var mixed
17
+	 */
18
+	protected $form_ids;
19
+
20
+	/**
21
+	 * Extra request parameters used to generate the query. This is used to generate the unique transient key.
22
+	 *
23
+	 * @var array
24
+	 */
25
+	protected $args;
26
+
27
+	/**
28
+	 * The transient key used to store the cached item. 45 characters long.
29
+	 *
30
+	 * @var string
31
+	 */
32
+	private $key = '';
33
+
34
+	/**
35
+	 * @since 1.13.1
36
+	 *
37
+	 * @var array Columns in the database for leads
38
+	 */
39
+	private $lead_db_columns = ['id', 'form_id', 'post_id', 'date_created', 'is_starred', 'is_read', 'ip', 'source_url', 'user_agent', 'currency', 'payment_status', 'payment_date', 'payment_amount', 'transaction_id', 'is_fulfilled', 'created_by', 'transaction_type', 'status'];
40
+
41
+	/**
42
+	 * @param array|int $form_ids Form ID or array of form IDs used in a request
43
+	 * @param array     $args     Extra request parameters used to generate the query. This is used to generate the unique transient key.
44
+	 */
45
+	public function __construct($form_ids = null, $args = [])
46
+	{
47
+		$this->add_hooks();
48
+
49
+		if (!is_null($form_ids)) {
50
+			$this->form_ids = $form_ids;
51
+
52
+			$this->args = $args;
53
+
54
+			$this->set_key();
55
+		}
56
+	}
57
+
58
+	/**
59
+	 * Add actions for clearing out caches when entries are updated.
60
+	 */
61
+	public function add_hooks()
62
+	{
63
+
64
+		// Schedule cleanup of expired transients
65
+		add_action('wp', [$this, 'schedule_transient_cleanup']);
66
+
67
+		// Hook in to the scheduled cleanup, if scheduled
68
+		add_action('gravityview-expired-transients', [$this, 'delete_expired_transients']);
69
+
70
+		// Trigger this when you need to prevent any results from being cached with forms that have been modified
71
+		add_action('gravityview_clear_form_cache', [$this, 'blocklist_add']);
72
+
73
+		/**
74
+		 * @since 1.14
75
+		 */
76
+		add_action('gravityview_clear_entry_cache', [$this, 'entry_status_changed']);
77
+
78
+		add_action('gform_after_update_entry', [$this, 'entry_updated'], 10, 2);
79
+
80
+		add_action('gform_entry_created', [$this, 'entry_created'], 10, 2);
81
+
82
+		add_action('gform_post_add_entry', [$this, 'entry_added'], 10, 2);
83
+
84
+		/**
85
+		 * @see RGFormsModel::update_lead_property() Trigger when any entry property changes
86
+		 */
87
+		foreach ($this->lead_db_columns as $column) {
88
+			add_action('gform_update_'.$column, [$this, 'entry_status_changed'], 10, 3);
89
+		}
90
+
91
+		add_action('gform_delete_lead', [$this, 'entry_status_changed'], 10);
92
+	}
93
+
94
+	/**
95
+	 * Force refreshing a cache when an entry is deleted.
96
+	 *
97
+	 * The `gform_delete_lead` action is called before the lead is deleted; we fetch the entry to find out the form ID so it can be added to the blocklist.
98
+	 *
99
+	 * @since  1.5.1
100
+	 *
101
+	 * @param int    $lead_id        Entry ID
102
+	 * @param string $property_value Previous value of the lead status passed by gform_update_status hook
103
+	 * @param string $previous_value Previous value of the lead status passed by gform_update_status hook
104
+	 *
105
+	 * @return void
106
+	 */
107
+	public function entry_status_changed($lead_id, $property_value = '', $previous_value = '')
108
+	{
109
+		$entry = GFAPI::get_entry($lead_id);
110
+
111
+		if (is_wp_error($entry)) {
112
+			gravityview()->log->error('Could not retrieve entry {entry_id} to delete it: {error}', ['entry_id' => $lead_id, 'error' => $entry->get_error_message()]);
113
+
114
+			return;
115
+		}
116
+
117
+		gravityview()->log->debug('adding form {form_id} to blocklist because entry #{lead_id} was deleted', ['form_id' => $entry['form_id'], 'entry_id' => $lead_id, 'data' => ['value' => $property_value, 'previous' => $previous_value]]);
118
+
119
+		$this->blocklist_add($entry['form_id']);
120
+	}
121
+
122
+	/**
123
+	 * When an entry is updated, add the entry's form to the cache blocklist.
124
+	 *
125
+	 * @param array $form    GF form array
126
+	 * @param int   $lead_id Entry ID
127
+	 *
128
+	 * @return void
129
+	 */
130
+	public function entry_updated($form, $lead_id)
131
+	{
132
+		gravityview()->log->debug(' adding form {form_id} to blocklist because entry #{entry_id} was updated', ['form_id' => $form['id'], 'entry_id' => $lead_id]);
133
+
134
+		$this->blocklist_add($form['id']);
135
+	}
136
+
137
+	/**
138
+	 * When an entry is created, add the entry's form to the cache blocklist.
139
+	 *
140
+	 * We don't want old caches; when an entry is added, we want to clear the cache.
141
+	 *
142
+	 * @param array $entry GF entry array
143
+	 * @param array $form  GF form array
144
+	 *
145
+	 * @return void
146
+	 */
147
+	public function entry_created($entry, $form)
148
+	{
149
+		gravityview()->log->debug('adding form {form_id} to blocklist because entry #{entry_id} was created', ['form_id' => $form['id'], 'entry_id' => $entry['id']]);
150
+
151
+		$this->blocklist_add($form['id']);
152
+	}
153
+
154
+	/**
155
+	 * Clear the cache when entries are added via GFAPI::add_entry().
156
+	 *
157
+	 * @param array $entry The GF Entry array
158
+	 * @param array $form  The GF Form array
159
+	 *
160
+	 * @return void
161
+	 */
162
+	public function entry_added($entry, $form)
163
+	{
164
+		if (is_wp_error($entry)) {
165
+			return;
166
+		}
167
+
168
+		gravityview()->log->debug('adding form {form_id} to blocklist because entry #{entry_id} was added', ['form_id' => $form['id'], 'entry_id' => $entry['id']]);
169
+
170
+		$this->blocklist_add($form['id']);
171
+	}
172
+
173
+	/**
174
+	 * Calculate the prefix based on the Form IDs.
175
+	 *
176
+	 * @param int|array $form_ids Form IDs to generate prefix for
177
+	 *
178
+	 * @return string Prefix for the cache string used in set_key()
179
+	 */
180
+	protected function get_cache_key_prefix($form_ids = null)
181
+	{
182
+		if (is_null($form_ids)) {
183
+			$form_ids = $this->form_ids;
184
+		}
185
+
186
+		// Normally just one form, but supports multiple forms
187
+		//
188
+		// Array of IDs 12, 5, 14 would result in `f:12-f:5-f:14`
189
+		$forms = 'f:'.implode('-f:', (array) $form_ids);
190
+
191
+		// Prefix for transient keys
192
+		// Now the prefix would be: `gv-cache-f:12-f:5-f:14-`
193
+		return 'gv-cache-'.$forms.'-';
194
+	}
195
+
196
+	/**
197
+	 * Set the transient key based on the form IDs and the arguments passed to the class.
198
+	 */
199
+	protected function set_key()
200
+	{
201
+
202
+		// Don't set key if no forms have been set.
203
+		if (empty($this->form_ids)) {
204
+			return;
205
+		}
206
+
207
+		$key = $this->get_cache_key_prefix().sha1(serialize($this->args));
208
+
209
+		// The transient name column can handle up to 64 characters.
210
+		// The `_transient_timeout_` prefix that is prepended to the string is 11 characters.
211
+		// 64 - 19 = 45
212
+		// We make sure the key isn't too long or else WP doesn't store data.
213
+		$this->key = substr($key, 0, 45);
214
+	}
215
+
216
+	/**
217
+	 * Allow public access to get transient key.
218
+	 *
219
+	 * @return string Transient key
220
+	 */
221
+	public function get_key()
222
+	{
223
+		return $this->key;
224
+	}
225
+
226
+	/**
227
+	 * Add form IDs to a "blocklist" to force the cache to be refreshed.
228
+	 *
229
+	 * @param int|array $form_ids Form IDs to force to be updated
230
+	 *
231
+	 * @return bool False if value was not updated and true if value was updated.
232
+	 */
233
+	public function blocklist_add($form_ids)
234
+	{
235
+		$blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
236
+
237
+		$form_ids = is_array($form_ids) ? $form_ids : [$form_ids];
238
+
239
+		// Add the passed form IDs
240
+		$blocklist = array_merge((array) $blocklist, $form_ids);
241
+
242
+		// Don't duplicate
243
+		$blocklist = array_unique($blocklist);
244
+
245
+		// Remove empty items from blocklist
246
+		$blocklist = array_filter($blocklist);
247
+
248
+		$updated = update_option(self::BLOCKLIST_OPTION_NAME, $blocklist);
249
+
250
+		if (false !== $updated) {
251
+			gravityview()->log->debug('Added form IDs to cache blocklist', ['data' => [
252
+				'$form_ids'  => $form_ids,
253
+				'$blocklist' => $blocklist,
254
+			]]);
255
+		}
256
+
257
+		return $updated;
258
+	}
259
+
260
+	/**
261
+	 * @deprecated 2.14 {@see GravityView_Cache::blocklist_add()}
262
+	 *
263
+	 * @param int|array $form_ids Form IDs to force to be updated
264
+	 *
265
+	 * @return bool Whether the removal was successful
266
+	 */
267
+	public function blacklist_add($form_ids)
268
+	{
269
+		_deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::blocklist_add()');
270
+
271
+		return $this->blocklist_remove($form_ids);
272
+	}
273
+
274
+	/**
275
+	 * Remove Form IDs from blocklist.
276
+	 *
277
+	 * @param int|array $form_ids Form IDs to remove
278
+	 *
279
+	 * @return bool Whether the removal was successful
280
+	 */
281
+	public function blocklist_remove($form_ids)
282
+	{
283
+		$blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
284
+
285
+		$updated_list = array_diff($blocklist, (array) $form_ids);
286
+
287
+		gravityview()->log->debug('Removing form IDs from cache blocklist', ['data' => [
288
+			'$form_ids'     => $form_ids,
289
+			'$blocklist'    => $blocklist,
290
+			'$updated_list' => $updated_list,
291
+		]]);
292
+
293
+		return update_option(self::BLOCKLIST_OPTION_NAME, $updated_list);
294
+	}
295
+
296
+	/**
297
+	 * @deprecated 2.14 {@see GravityView_Cache::blocklist_remove()}
298
+	 *
299
+	 * @param int|array $form_ids Form IDs to add
300
+	 *
301
+	 * @return bool Whether the removal was successful
302
+	 */
303
+	public function blacklist_remove($form_ids)
304
+	{
305
+		_deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::blocklist_remove()');
306
+
307
+		return $this->blocklist_remove($form_ids);
308
+	}
309
+
310
+	/**
311
+	 * Is a form ID in the cache blocklist?
312
+	 *
313
+	 * @param int|array $form_ids Form IDs to check if in blocklist
314
+	 *
315
+	 * @deprecated 2.14 Use {@see GravityView_Cache::in_blocklist()}
316
+	 *
317
+	 * @return bool
318
+	 */
319
+	public function in_blacklist($form_ids = null)
320
+	{
321
+		_deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::in_blocklist()');
322
+
323
+		return $this->in_blocklist($form_ids);
324
+	}
325
+
326
+	/**
327
+	 * Is a form ID in the cache blocklist.
328
+	 *
329
+	 * @param int|array $form_ids Form IDs to check if in blocklist
330
+	 *
331
+	 * @return bool
332
+	 */
333
+	public function in_blocklist($form_ids = null)
334
+	{
335
+		$blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
336
+
337
+		// Use object var if exists
338
+		$form_ids = is_null($form_ids) ? $this->form_ids : $form_ids;
339
+
340
+		if (empty($form_ids)) {
341
+			gravityview()->log->debug('Did not add form to blocklist; empty form ID', ['data' => $form_ids]);
342
+
343
+			return false;
344
+		}
345
+
346
+		foreach ((array) $form_ids as $form_id) {
347
+			if (in_array($form_id, $blocklist)) {
348
+				gravityview()->log->debug('Form #{form_id} is in the cache blocklist', ['form_id' => $form_id]);
349
+
350
+				return true;
351
+			}
352
+		}
353
+
354
+		return false;
355
+	}
356
+
357
+	/**
358
+	 * Get transient result.
359
+	 *
360
+	 * @param string $key Transient key to fetch
361
+	 *
362
+	 * @return mixed False: Not using cache or cache was a WP_Error object; NULL: no results found; Mixed: cache value
363
+	 */
364
+	public function get($key = null)
365
+	{
366
+		$key = is_null($key) ? $this->key : $key;
367
+
368
+		if (!$this->use_cache()) {
369
+			gravityview()->log->debug('Not using cached results because of GravityView_Cache->use_cache() results');
370
+
371
+			return false;
372
+		}
373
+
374
+		gravityview()->log->debug('Fetching request with transient key {key}', ['key' => $key]);
375
+
376
+		$result = get_transient($key);
377
+
378
+		if (is_wp_error($result)) {
379
+			gravityview()->log->debug('Fetching request resulted in error:', ['data' => $result]);
380
+
381
+			return false;
382
+		} elseif ($result) {
383
+			gravityview()->log->debug('Cached results found for  transient key {key}', ['key' => $key]);
384
+
385
+			return $result;
386
+		}
387
+
388
+		gravityview()->log->debug('No cached results found for  transient key {key}', ['key' => $key]);
389
+
390
+		return null;
391
+	}
392
+
393
+	/**
394
+	 * Cache content as a transient.
395
+	 *
396
+	 * Cache time defaults to 1 week
397
+	 *
398
+	 * @param mixed  $content     [description]
399
+	 * @param string $filter_name Name used to modify the cache time. Will be set to `gravityview_cache_time_{$filter_name}`.
400
+	 *
401
+	 * @return bool If $content is not set, false. Otherwise, returns true if transient was set and false if not.
402
+	 */
403
+	public function set($content, $filter_name = '')
404
+	{
405
+
406
+		// Don't cache empty results
407
+		if (!empty($content)) {
408
+
409
+			/**
410
+			 * @filter `gravityview_cache_time_{$filter_name}` Modify the cache time for a type of cache
411
+			 *
412
+			 * @param int $time_in_seconds Default: `DAY_IN_SECONDS`
413
+			 */
414
+			$cache_time = (int) apply_filters('gravityview_cache_time_'.$filter_name, DAY_IN_SECONDS);
415
+
416
+			gravityview()->log->debug('Setting cache with transient key {key} for {cache_time} seconds', ['key' => $this->key, 'cache_time' => $cache_time]);
417
+
418
+			return set_transient($this->key, $content, $cache_time);
419
+		}
420
+
421
+		gravityview()->log->debug('Cache not set; content is empty');
422
+
423
+		return false;
424
+	}
425
+
426
+	/**
427
+	 * Delete cached transients based on form IDs.
428
+	 *
429
+	 * @todo Use REGEX to match forms when array of form IDs is passed, instead of using a simple LIKE
430
+	 * @todo  Rate limit deleting to prevent abuse
431
+	 *
432
+	 * @param int|array $form_ids Form IDs to delete
433
+	 *
434
+	 * @return void
435
+	 */
436
+	public function delete($form_ids = null)
437
+	{
438
+		global $wpdb;
439
+
440
+		// Use object var if exists
441
+		$form_ids = is_null($form_ids) ? $this->form_ids : $form_ids;
442
+
443
+		if (empty($form_ids)) {
444
+			gravityview()->log->debug('Did not delete cache; empty form IDs');
445
+
446
+			return;
447
+		}
448
+
449
+		foreach ((array) $form_ids as $form_id) {
450
+			$key = '_transient_gv-cache-';
451
+
452
+			$key = $wpdb->esc_like($key);
453
+
454
+			$form_id = intval($form_id);
455
+
456
+			// Find the transients containing this form
457
+			$key = "$key%f:$form_id-%"; // \_transient\_gv-cache-%f:1-% for example
458
+			$sql = $wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE `option_name` LIKE %s", $key);
459
+
460
+			foreach (($transients = $wpdb->get_col($sql)) as $transient) {
461
+				// We have to delete it via the API to make sure the object cache is updated appropriately
462
+				delete_transient(preg_replace('#^_transient_#', '', $transient));
463
+			}
464
+
465
+			gravityview()->log->debug('Deleting cache for form #{form_id}', ['form_id' => $form_id, 'data' => [
466
+				$sql,
467
+				sprintf('Deleted results: %d', count($transients)),
468
+			]]);
469
+		}
470
+	}
471
+
472
+	/**
473
+	 * Schedule expired transient cleanup twice a day.
474
+	 *
475
+	 * Can be overruled by the `gravityview_cleanup_transients` filter (returns boolean)
476
+	 *
477
+	 * @return void
478
+	 */
479
+	public function schedule_transient_cleanup()
480
+	{
481
+
482
+		/**
483
+		 * @filter `gravityview_cleanup_transients` Override GravityView cleanup of transients by setting this to false
484
+		 *
485
+		 * @param bool $cleanup Whether to run the GravityView auto-cleanup of transients. Default: `true`
486
+		 */
487
+		$cleanup = apply_filters('gravityview_cleanup_transients', true);
488
+
489
+		if (!$cleanup) {
490
+			return;
491
+		}
492
+
493
+		if (!wp_next_scheduled('gravityview-expired-transients')) {
494
+			wp_schedule_event(time(), 'daily', 'gravityview-expired-transients');
495
+		}
496
+	}
497
+
498
+	/**
499
+	 * Delete expired transients.
500
+	 *
501
+	 * The code is copied from the Delete Expired Transients, with slight modifications to track # of results and to get the blog ID dynamically
502
+	 *
503
+	 * @see https://wordpress.org/plugins/delete-expired-transients/ Plugin where the code was taken from
504
+	 * @see  DelxtransCleaners::clearBlogExpired()
505
+	 *
506
+	 * @return void
507
+	 */
508
+	public function delete_expired_transients()
509
+	{
510
+		global $wpdb;
511
+
512
+		// Added this line, which isn't in the plugin
513
+		$blog_id = get_current_blog_id();
514
+
515
+		$num_results = 0;
516
+
517
+		// get current PHP time, offset by a minute to avoid clashes with other tasks
518
+		$threshold = time() - 60;
519
+
520
+		// get table name for options on specified blog
521
+		$table = $wpdb->get_blog_prefix($blog_id).'options';
522
+
523
+		// delete expired transients, using the paired timeout record to find them
524
+		$sql = "
525 525
 			delete from t1, t2
526 526
 			using $table t1
527 527
 			join $table t2 on t2.option_name = replace(t1.option_name, '_timeout', '')
@@ -529,11 +529,11 @@  discard block
 block discarded – undo
529 529
 			and t1.option_value < '$threshold'
530 530
 		";
531 531
 
532
-        $num_results = $wpdb->query($sql);
532
+		$num_results = $wpdb->query($sql);
533 533
 
534
-        // delete orphaned transient expirations
535
-        // also delete NextGEN Gallery 2.x display cache timeout aliases
536
-        $sql = "
534
+		// delete orphaned transient expirations
535
+		// also delete NextGEN Gallery 2.x display cache timeout aliases
536
+		$sql = "
537 537
 			delete from $table
538 538
 			where (
539 539
 				   option_name like '\_transient\_timeout\_%'
@@ -544,56 +544,56 @@  discard block
 block discarded – undo
544 544
 			and option_value < '$threshold'
545 545
 		";
546 546
 
547
-        $num_results += $wpdb->query($sql);
547
+		$num_results += $wpdb->query($sql);
548 548
 
549
-        gravityview()->log->debug('Deleted {count} expired transient records from the database', ['count' => $num_results]);
550
-    }
549
+		gravityview()->log->debug('Deleted {count} expired transient records from the database', ['count' => $num_results]);
550
+	}
551 551
 
552
-    /**
553
-     * Check whether to use cached results, if available.
554
-     *
555
-     * If the user can edit posts, they are able to override whether to cache results by adding `cache` or `nocache` to the URL requested.
556
-     *
557
-     * @return bool True: use cache; False: don't use cache
558
-     */
559
-    public function use_cache()
560
-    {
552
+	/**
553
+	 * Check whether to use cached results, if available.
554
+	 *
555
+	 * If the user can edit posts, they are able to override whether to cache results by adding `cache` or `nocache` to the URL requested.
556
+	 *
557
+	 * @return bool True: use cache; False: don't use cache
558
+	 */
559
+	public function use_cache()
560
+	{
561 561
 
562
-        // Exit early if debugging (unless running PHPUnit)
563
-        if (defined('WP_DEBUG') && WP_DEBUG && !(defined('DOING_GRAVITYVIEW_TESTS') && DOING_GRAVITYVIEW_TESTS)) {
564
-            return apply_filters('gravityview_use_cache', false, $this);
565
-        }
562
+		// Exit early if debugging (unless running PHPUnit)
563
+		if (defined('WP_DEBUG') && WP_DEBUG && !(defined('DOING_GRAVITYVIEW_TESTS') && DOING_GRAVITYVIEW_TESTS)) {
564
+			return apply_filters('gravityview_use_cache', false, $this);
565
+		}
566 566
 
567
-        $use_cache = true;
567
+		$use_cache = true;
568 568
 
569
-        if (GVCommon::has_cap('edit_gravityviews')) {
570
-            if (isset($_GET['cache']) || isset($_GET['nocache'])) {
571
-                gravityview()->log->debug('Not using cache: ?cache or ?nocache is in the URL');
569
+		if (GVCommon::has_cap('edit_gravityviews')) {
570
+			if (isset($_GET['cache']) || isset($_GET['nocache'])) {
571
+				gravityview()->log->debug('Not using cache: ?cache or ?nocache is in the URL');
572 572
 
573
-                $use_cache = false;
574
-            }
575
-        }
573
+				$use_cache = false;
574
+			}
575
+		}
576 576
 
577
-        // Has the form been flagged as having changed items in it?
578
-        if ($this->in_blocklist() || !$use_cache) {
577
+		// Has the form been flagged as having changed items in it?
578
+		if ($this->in_blocklist() || !$use_cache) {
579 579
 
580
-            // Delete caches for all items with form IDs XYZ
581
-            $this->delete($this->form_ids);
580
+			// Delete caches for all items with form IDs XYZ
581
+			$this->delete($this->form_ids);
582 582
 
583
-            // Remove the form from
584
-            $this->blocklist_remove($this->form_ids);
585
-        }
583
+			// Remove the form from
584
+			$this->blocklist_remove($this->form_ids);
585
+		}
586 586
 
587
-        /**
588
-         * @filter `gravityview_use_cache` Modify whether to use the cache or not
589
-         *
590
-         * @param bool              $use_cache Previous setting
591
-         * @param GravityView_Cache $this      The GravityView_Cache object
592
-         */
593
-        $use_cache = apply_filters('gravityview_use_cache', $use_cache, $this);
587
+		/**
588
+		 * @filter `gravityview_use_cache` Modify whether to use the cache or not
589
+		 *
590
+		 * @param bool              $use_cache Previous setting
591
+		 * @param GravityView_Cache $this      The GravityView_Cache object
592
+		 */
593
+		$use_cache = apply_filters('gravityview_use_cache', $use_cache, $this);
594 594
 
595
-        return (bool) $use_cache;
596
-    }
595
+		return (bool) $use_cache;
596
+	}
597 597
 }
598 598
 
599 599
 new GravityView_Cache();
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -36,17 +36,17 @@  discard block
 block discarded – undo
36 36
      *
37 37
      * @var array Columns in the database for leads
38 38
      */
39
-    private $lead_db_columns = ['id', 'form_id', 'post_id', 'date_created', 'is_starred', 'is_read', 'ip', 'source_url', 'user_agent', 'currency', 'payment_status', 'payment_date', 'payment_amount', 'transaction_id', 'is_fulfilled', 'created_by', 'transaction_type', 'status'];
39
+    private $lead_db_columns = [ 'id', 'form_id', 'post_id', 'date_created', 'is_starred', 'is_read', 'ip', 'source_url', 'user_agent', 'currency', 'payment_status', 'payment_date', 'payment_amount', 'transaction_id', 'is_fulfilled', 'created_by', 'transaction_type', 'status' ];
40 40
 
41 41
     /**
42 42
      * @param array|int $form_ids Form ID or array of form IDs used in a request
43 43
      * @param array     $args     Extra request parameters used to generate the query. This is used to generate the unique transient key.
44 44
      */
45
-    public function __construct($form_ids = null, $args = [])
45
+    public function __construct( $form_ids = null, $args = [ ] )
46 46
     {
47 47
         $this->add_hooks();
48 48
 
49
-        if (!is_null($form_ids)) {
49
+        if ( ! is_null( $form_ids ) ) {
50 50
             $this->form_ids = $form_ids;
51 51
 
52 52
             $this->args = $args;
@@ -62,33 +62,33 @@  discard block
 block discarded – undo
62 62
     {
63 63
 
64 64
         // Schedule cleanup of expired transients
65
-        add_action('wp', [$this, 'schedule_transient_cleanup']);
65
+        add_action( 'wp', [ $this, 'schedule_transient_cleanup' ] );
66 66
 
67 67
         // Hook in to the scheduled cleanup, if scheduled
68
-        add_action('gravityview-expired-transients', [$this, 'delete_expired_transients']);
68
+        add_action( 'gravityview-expired-transients', [ $this, 'delete_expired_transients' ] );
69 69
 
70 70
         // Trigger this when you need to prevent any results from being cached with forms that have been modified
71
-        add_action('gravityview_clear_form_cache', [$this, 'blocklist_add']);
71
+        add_action( 'gravityview_clear_form_cache', [ $this, 'blocklist_add' ] );
72 72
 
73 73
         /**
74 74
          * @since 1.14
75 75
          */
76
-        add_action('gravityview_clear_entry_cache', [$this, 'entry_status_changed']);
76
+        add_action( 'gravityview_clear_entry_cache', [ $this, 'entry_status_changed' ] );
77 77
 
78
-        add_action('gform_after_update_entry', [$this, 'entry_updated'], 10, 2);
78
+        add_action( 'gform_after_update_entry', [ $this, 'entry_updated' ], 10, 2 );
79 79
 
80
-        add_action('gform_entry_created', [$this, 'entry_created'], 10, 2);
80
+        add_action( 'gform_entry_created', [ $this, 'entry_created' ], 10, 2 );
81 81
 
82
-        add_action('gform_post_add_entry', [$this, 'entry_added'], 10, 2);
82
+        add_action( 'gform_post_add_entry', [ $this, 'entry_added' ], 10, 2 );
83 83
 
84 84
         /**
85 85
          * @see RGFormsModel::update_lead_property() Trigger when any entry property changes
86 86
          */
87
-        foreach ($this->lead_db_columns as $column) {
88
-            add_action('gform_update_'.$column, [$this, 'entry_status_changed'], 10, 3);
87
+        foreach ( $this->lead_db_columns as $column ) {
88
+            add_action( 'gform_update_' . $column, [ $this, 'entry_status_changed' ], 10, 3 );
89 89
         }
90 90
 
91
-        add_action('gform_delete_lead', [$this, 'entry_status_changed'], 10);
91
+        add_action( 'gform_delete_lead', [ $this, 'entry_status_changed' ], 10 );
92 92
     }
93 93
 
94 94
     /**
@@ -104,19 +104,19 @@  discard block
 block discarded – undo
104 104
      *
105 105
      * @return void
106 106
      */
107
-    public function entry_status_changed($lead_id, $property_value = '', $previous_value = '')
107
+    public function entry_status_changed( $lead_id, $property_value = '', $previous_value = '' )
108 108
     {
109
-        $entry = GFAPI::get_entry($lead_id);
109
+        $entry = GFAPI::get_entry( $lead_id );
110 110
 
111
-        if (is_wp_error($entry)) {
112
-            gravityview()->log->error('Could not retrieve entry {entry_id} to delete it: {error}', ['entry_id' => $lead_id, 'error' => $entry->get_error_message()]);
111
+        if ( is_wp_error( $entry ) ) {
112
+            gravityview()->log->error( 'Could not retrieve entry {entry_id} to delete it: {error}', [ 'entry_id' => $lead_id, 'error' => $entry->get_error_message() ] );
113 113
 
114 114
             return;
115 115
         }
116 116
 
117
-        gravityview()->log->debug('adding form {form_id} to blocklist because entry #{lead_id} was deleted', ['form_id' => $entry['form_id'], 'entry_id' => $lead_id, 'data' => ['value' => $property_value, 'previous' => $previous_value]]);
117
+        gravityview()->log->debug( 'adding form {form_id} to blocklist because entry #{lead_id} was deleted', [ 'form_id' => $entry[ 'form_id' ], 'entry_id' => $lead_id, 'data' => [ 'value' => $property_value, 'previous' => $previous_value ] ] );
118 118
 
119
-        $this->blocklist_add($entry['form_id']);
119
+        $this->blocklist_add( $entry[ 'form_id' ] );
120 120
     }
121 121
 
122 122
     /**
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
      *
128 128
      * @return void
129 129
      */
130
-    public function entry_updated($form, $lead_id)
130
+    public function entry_updated( $form, $lead_id )
131 131
     {
132
-        gravityview()->log->debug(' adding form {form_id} to blocklist because entry #{entry_id} was updated', ['form_id' => $form['id'], 'entry_id' => $lead_id]);
132
+        gravityview()->log->debug( ' adding form {form_id} to blocklist because entry #{entry_id} was updated', [ 'form_id' => $form[ 'id' ], 'entry_id' => $lead_id ] );
133 133
 
134
-        $this->blocklist_add($form['id']);
134
+        $this->blocklist_add( $form[ 'id' ] );
135 135
     }
136 136
 
137 137
     /**
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
      *
145 145
      * @return void
146 146
      */
147
-    public function entry_created($entry, $form)
147
+    public function entry_created( $entry, $form )
148 148
     {
149
-        gravityview()->log->debug('adding form {form_id} to blocklist because entry #{entry_id} was created', ['form_id' => $form['id'], 'entry_id' => $entry['id']]);
149
+        gravityview()->log->debug( 'adding form {form_id} to blocklist because entry #{entry_id} was created', [ 'form_id' => $form[ 'id' ], 'entry_id' => $entry[ 'id' ] ] );
150 150
 
151
-        $this->blocklist_add($form['id']);
151
+        $this->blocklist_add( $form[ 'id' ] );
152 152
     }
153 153
 
154 154
     /**
@@ -159,15 +159,15 @@  discard block
 block discarded – undo
159 159
      *
160 160
      * @return void
161 161
      */
162
-    public function entry_added($entry, $form)
162
+    public function entry_added( $entry, $form )
163 163
     {
164
-        if (is_wp_error($entry)) {
164
+        if ( is_wp_error( $entry ) ) {
165 165
             return;
166 166
         }
167 167
 
168
-        gravityview()->log->debug('adding form {form_id} to blocklist because entry #{entry_id} was added', ['form_id' => $form['id'], 'entry_id' => $entry['id']]);
168
+        gravityview()->log->debug( 'adding form {form_id} to blocklist because entry #{entry_id} was added', [ 'form_id' => $form[ 'id' ], 'entry_id' => $entry[ 'id' ] ] );
169 169
 
170
-        $this->blocklist_add($form['id']);
170
+        $this->blocklist_add( $form[ 'id' ] );
171 171
     }
172 172
 
173 173
     /**
@@ -177,20 +177,20 @@  discard block
 block discarded – undo
177 177
      *
178 178
      * @return string Prefix for the cache string used in set_key()
179 179
      */
180
-    protected function get_cache_key_prefix($form_ids = null)
180
+    protected function get_cache_key_prefix( $form_ids = null )
181 181
     {
182
-        if (is_null($form_ids)) {
182
+        if ( is_null( $form_ids ) ) {
183 183
             $form_ids = $this->form_ids;
184 184
         }
185 185
 
186 186
         // Normally just one form, but supports multiple forms
187 187
         //
188 188
         // Array of IDs 12, 5, 14 would result in `f:12-f:5-f:14`
189
-        $forms = 'f:'.implode('-f:', (array) $form_ids);
189
+        $forms = 'f:' . implode( '-f:', (array)$form_ids );
190 190
 
191 191
         // Prefix for transient keys
192 192
         // Now the prefix would be: `gv-cache-f:12-f:5-f:14-`
193
-        return 'gv-cache-'.$forms.'-';
193
+        return 'gv-cache-' . $forms . '-';
194 194
     }
195 195
 
196 196
     /**
@@ -200,17 +200,17 @@  discard block
 block discarded – undo
200 200
     {
201 201
 
202 202
         // Don't set key if no forms have been set.
203
-        if (empty($this->form_ids)) {
203
+        if ( empty( $this->form_ids ) ) {
204 204
             return;
205 205
         }
206 206
 
207
-        $key = $this->get_cache_key_prefix().sha1(serialize($this->args));
207
+        $key = $this->get_cache_key_prefix() . sha1( serialize( $this->args ) );
208 208
 
209 209
         // The transient name column can handle up to 64 characters.
210 210
         // The `_transient_timeout_` prefix that is prepended to the string is 11 characters.
211 211
         // 64 - 19 = 45
212 212
         // We make sure the key isn't too long or else WP doesn't store data.
213
-        $this->key = substr($key, 0, 45);
213
+        $this->key = substr( $key, 0, 45 );
214 214
     }
215 215
 
216 216
     /**
@@ -230,28 +230,28 @@  discard block
 block discarded – undo
230 230
      *
231 231
      * @return bool False if value was not updated and true if value was updated.
232 232
      */
233
-    public function blocklist_add($form_ids)
233
+    public function blocklist_add( $form_ids )
234 234
     {
235
-        $blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
235
+        $blocklist = get_option( self::BLOCKLIST_OPTION_NAME, [ ] );
236 236
 
237
-        $form_ids = is_array($form_ids) ? $form_ids : [$form_ids];
237
+        $form_ids = is_array( $form_ids ) ? $form_ids : [ $form_ids ];
238 238
 
239 239
         // Add the passed form IDs
240
-        $blocklist = array_merge((array) $blocklist, $form_ids);
240
+        $blocklist = array_merge( (array)$blocklist, $form_ids );
241 241
 
242 242
         // Don't duplicate
243
-        $blocklist = array_unique($blocklist);
243
+        $blocklist = array_unique( $blocklist );
244 244
 
245 245
         // Remove empty items from blocklist
246
-        $blocklist = array_filter($blocklist);
246
+        $blocklist = array_filter( $blocklist );
247 247
 
248
-        $updated = update_option(self::BLOCKLIST_OPTION_NAME, $blocklist);
248
+        $updated = update_option( self::BLOCKLIST_OPTION_NAME, $blocklist );
249 249
 
250
-        if (false !== $updated) {
251
-            gravityview()->log->debug('Added form IDs to cache blocklist', ['data' => [
250
+        if ( false !== $updated ) {
251
+            gravityview()->log->debug( 'Added form IDs to cache blocklist', [ 'data' => [
252 252
                 '$form_ids'  => $form_ids,
253 253
                 '$blocklist' => $blocklist,
254
-            ]]);
254
+            ] ] );
255 255
         }
256 256
 
257 257
         return $updated;
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
      *
265 265
      * @return bool Whether the removal was successful
266 266
      */
267
-    public function blacklist_add($form_ids)
267
+    public function blacklist_add( $form_ids )
268 268
     {
269
-        _deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::blocklist_add()');
269
+        _deprecated_function( __METHOD__, '2.14', 'GravityView_Cache::blocklist_add()' );
270 270
 
271
-        return $this->blocklist_remove($form_ids);
271
+        return $this->blocklist_remove( $form_ids );
272 272
     }
273 273
 
274 274
     /**
@@ -278,19 +278,19 @@  discard block
 block discarded – undo
278 278
      *
279 279
      * @return bool Whether the removal was successful
280 280
      */
281
-    public function blocklist_remove($form_ids)
281
+    public function blocklist_remove( $form_ids )
282 282
     {
283
-        $blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
283
+        $blocklist = get_option( self::BLOCKLIST_OPTION_NAME, [ ] );
284 284
 
285
-        $updated_list = array_diff($blocklist, (array) $form_ids);
285
+        $updated_list = array_diff( $blocklist, (array)$form_ids );
286 286
 
287
-        gravityview()->log->debug('Removing form IDs from cache blocklist', ['data' => [
287
+        gravityview()->log->debug( 'Removing form IDs from cache blocklist', [ 'data' => [
288 288
             '$form_ids'     => $form_ids,
289 289
             '$blocklist'    => $blocklist,
290 290
             '$updated_list' => $updated_list,
291
-        ]]);
291
+        ] ] );
292 292
 
293
-        return update_option(self::BLOCKLIST_OPTION_NAME, $updated_list);
293
+        return update_option( self::BLOCKLIST_OPTION_NAME, $updated_list );
294 294
     }
295 295
 
296 296
     /**
@@ -300,11 +300,11 @@  discard block
 block discarded – undo
300 300
      *
301 301
      * @return bool Whether the removal was successful
302 302
      */
303
-    public function blacklist_remove($form_ids)
303
+    public function blacklist_remove( $form_ids )
304 304
     {
305
-        _deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::blocklist_remove()');
305
+        _deprecated_function( __METHOD__, '2.14', 'GravityView_Cache::blocklist_remove()' );
306 306
 
307
-        return $this->blocklist_remove($form_ids);
307
+        return $this->blocklist_remove( $form_ids );
308 308
     }
309 309
 
310 310
     /**
@@ -316,11 +316,11 @@  discard block
 block discarded – undo
316 316
      *
317 317
      * @return bool
318 318
      */
319
-    public function in_blacklist($form_ids = null)
319
+    public function in_blacklist( $form_ids = null )
320 320
     {
321
-        _deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::in_blocklist()');
321
+        _deprecated_function( __METHOD__, '2.14', 'GravityView_Cache::in_blocklist()' );
322 322
 
323
-        return $this->in_blocklist($form_ids);
323
+        return $this->in_blocklist( $form_ids );
324 324
     }
325 325
 
326 326
     /**
@@ -330,22 +330,22 @@  discard block
 block discarded – undo
330 330
      *
331 331
      * @return bool
332 332
      */
333
-    public function in_blocklist($form_ids = null)
333
+    public function in_blocklist( $form_ids = null )
334 334
     {
335
-        $blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
335
+        $blocklist = get_option( self::BLOCKLIST_OPTION_NAME, [ ] );
336 336
 
337 337
         // Use object var if exists
338
-        $form_ids = is_null($form_ids) ? $this->form_ids : $form_ids;
338
+        $form_ids = is_null( $form_ids ) ? $this->form_ids : $form_ids;
339 339
 
340
-        if (empty($form_ids)) {
341
-            gravityview()->log->debug('Did not add form to blocklist; empty form ID', ['data' => $form_ids]);
340
+        if ( empty( $form_ids ) ) {
341
+            gravityview()->log->debug( 'Did not add form to blocklist; empty form ID', [ 'data' => $form_ids ] );
342 342
 
343 343
             return false;
344 344
         }
345 345
 
346
-        foreach ((array) $form_ids as $form_id) {
347
-            if (in_array($form_id, $blocklist)) {
348
-                gravityview()->log->debug('Form #{form_id} is in the cache blocklist', ['form_id' => $form_id]);
346
+        foreach ( (array)$form_ids as $form_id ) {
347
+            if ( in_array( $form_id, $blocklist ) ) {
348
+                gravityview()->log->debug( 'Form #{form_id} is in the cache blocklist', [ 'form_id' => $form_id ] );
349 349
 
350 350
                 return true;
351 351
             }
@@ -361,31 +361,31 @@  discard block
 block discarded – undo
361 361
      *
362 362
      * @return mixed False: Not using cache or cache was a WP_Error object; NULL: no results found; Mixed: cache value
363 363
      */
364
-    public function get($key = null)
364
+    public function get( $key = null )
365 365
     {
366
-        $key = is_null($key) ? $this->key : $key;
366
+        $key = is_null( $key ) ? $this->key : $key;
367 367
 
368
-        if (!$this->use_cache()) {
369
-            gravityview()->log->debug('Not using cached results because of GravityView_Cache->use_cache() results');
368
+        if ( ! $this->use_cache() ) {
369
+            gravityview()->log->debug( 'Not using cached results because of GravityView_Cache->use_cache() results' );
370 370
 
371 371
             return false;
372 372
         }
373 373
 
374
-        gravityview()->log->debug('Fetching request with transient key {key}', ['key' => $key]);
374
+        gravityview()->log->debug( 'Fetching request with transient key {key}', [ 'key' => $key ] );
375 375
 
376
-        $result = get_transient($key);
376
+        $result = get_transient( $key );
377 377
 
378
-        if (is_wp_error($result)) {
379
-            gravityview()->log->debug('Fetching request resulted in error:', ['data' => $result]);
378
+        if ( is_wp_error( $result ) ) {
379
+            gravityview()->log->debug( 'Fetching request resulted in error:', [ 'data' => $result ] );
380 380
 
381 381
             return false;
382
-        } elseif ($result) {
383
-            gravityview()->log->debug('Cached results found for  transient key {key}', ['key' => $key]);
382
+        } elseif ( $result ) {
383
+            gravityview()->log->debug( 'Cached results found for  transient key {key}', [ 'key' => $key ] );
384 384
 
385 385
             return $result;
386 386
         }
387 387
 
388
-        gravityview()->log->debug('No cached results found for  transient key {key}', ['key' => $key]);
388
+        gravityview()->log->debug( 'No cached results found for  transient key {key}', [ 'key' => $key ] );
389 389
 
390 390
         return null;
391 391
     }
@@ -400,25 +400,25 @@  discard block
 block discarded – undo
400 400
      *
401 401
      * @return bool If $content is not set, false. Otherwise, returns true if transient was set and false if not.
402 402
      */
403
-    public function set($content, $filter_name = '')
403
+    public function set( $content, $filter_name = '' )
404 404
     {
405 405
 
406 406
         // Don't cache empty results
407
-        if (!empty($content)) {
407
+        if ( ! empty( $content ) ) {
408 408
 
409 409
             /**
410 410
              * @filter `gravityview_cache_time_{$filter_name}` Modify the cache time for a type of cache
411 411
              *
412 412
              * @param int $time_in_seconds Default: `DAY_IN_SECONDS`
413 413
              */
414
-            $cache_time = (int) apply_filters('gravityview_cache_time_'.$filter_name, DAY_IN_SECONDS);
414
+            $cache_time = (int)apply_filters( 'gravityview_cache_time_' . $filter_name, DAY_IN_SECONDS );
415 415
 
416
-            gravityview()->log->debug('Setting cache with transient key {key} for {cache_time} seconds', ['key' => $this->key, 'cache_time' => $cache_time]);
416
+            gravityview()->log->debug( 'Setting cache with transient key {key} for {cache_time} seconds', [ 'key' => $this->key, 'cache_time' => $cache_time ] );
417 417
 
418
-            return set_transient($this->key, $content, $cache_time);
418
+            return set_transient( $this->key, $content, $cache_time );
419 419
         }
420 420
 
421
-        gravityview()->log->debug('Cache not set; content is empty');
421
+        gravityview()->log->debug( 'Cache not set; content is empty' );
422 422
 
423 423
         return false;
424 424
     }
@@ -433,39 +433,39 @@  discard block
 block discarded – undo
433 433
      *
434 434
      * @return void
435 435
      */
436
-    public function delete($form_ids = null)
436
+    public function delete( $form_ids = null )
437 437
     {
438 438
         global $wpdb;
439 439
 
440 440
         // Use object var if exists
441
-        $form_ids = is_null($form_ids) ? $this->form_ids : $form_ids;
441
+        $form_ids = is_null( $form_ids ) ? $this->form_ids : $form_ids;
442 442
 
443
-        if (empty($form_ids)) {
444
-            gravityview()->log->debug('Did not delete cache; empty form IDs');
443
+        if ( empty( $form_ids ) ) {
444
+            gravityview()->log->debug( 'Did not delete cache; empty form IDs' );
445 445
 
446 446
             return;
447 447
         }
448 448
 
449
-        foreach ((array) $form_ids as $form_id) {
449
+        foreach ( (array)$form_ids as $form_id ) {
450 450
             $key = '_transient_gv-cache-';
451 451
 
452
-            $key = $wpdb->esc_like($key);
452
+            $key = $wpdb->esc_like( $key );
453 453
 
454
-            $form_id = intval($form_id);
454
+            $form_id = intval( $form_id );
455 455
 
456 456
             // Find the transients containing this form
457 457
             $key = "$key%f:$form_id-%"; // \_transient\_gv-cache-%f:1-% for example
458
-            $sql = $wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE `option_name` LIKE %s", $key);
458
+            $sql = $wpdb->prepare( "SELECT option_name FROM {$wpdb->options} WHERE `option_name` LIKE %s", $key );
459 459
 
460
-            foreach (($transients = $wpdb->get_col($sql)) as $transient) {
460
+            foreach ( ( $transients = $wpdb->get_col( $sql ) ) as $transient ) {
461 461
                 // We have to delete it via the API to make sure the object cache is updated appropriately
462
-                delete_transient(preg_replace('#^_transient_#', '', $transient));
462
+                delete_transient( preg_replace( '#^_transient_#', '', $transient ) );
463 463
             }
464 464
 
465
-            gravityview()->log->debug('Deleting cache for form #{form_id}', ['form_id' => $form_id, 'data' => [
465
+            gravityview()->log->debug( 'Deleting cache for form #{form_id}', [ 'form_id' => $form_id, 'data' => [
466 466
                 $sql,
467
-                sprintf('Deleted results: %d', count($transients)),
468
-            ]]);
467
+                sprintf( 'Deleted results: %d', count( $transients ) ),
468
+            ] ] );
469 469
         }
470 470
     }
471 471
 
@@ -484,14 +484,14 @@  discard block
 block discarded – undo
484 484
          *
485 485
          * @param bool $cleanup Whether to run the GravityView auto-cleanup of transients. Default: `true`
486 486
          */
487
-        $cleanup = apply_filters('gravityview_cleanup_transients', true);
487
+        $cleanup = apply_filters( 'gravityview_cleanup_transients', true );
488 488
 
489
-        if (!$cleanup) {
489
+        if ( ! $cleanup ) {
490 490
             return;
491 491
         }
492 492
 
493
-        if (!wp_next_scheduled('gravityview-expired-transients')) {
494
-            wp_schedule_event(time(), 'daily', 'gravityview-expired-transients');
493
+        if ( ! wp_next_scheduled( 'gravityview-expired-transients' ) ) {
494
+            wp_schedule_event( time(), 'daily', 'gravityview-expired-transients' );
495 495
         }
496 496
     }
497 497
 
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
         $threshold = time() - 60;
519 519
 
520 520
         // get table name for options on specified blog
521
-        $table = $wpdb->get_blog_prefix($blog_id).'options';
521
+        $table = $wpdb->get_blog_prefix( $blog_id ) . 'options';
522 522
 
523 523
         // delete expired transients, using the paired timeout record to find them
524 524
         $sql = "
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 			and t1.option_value < '$threshold'
530 530
 		";
531 531
 
532
-        $num_results = $wpdb->query($sql);
532
+        $num_results = $wpdb->query( $sql );
533 533
 
534 534
         // delete orphaned transient expirations
535 535
         // also delete NextGEN Gallery 2.x display cache timeout aliases
@@ -544,9 +544,9 @@  discard block
 block discarded – undo
544 544
 			and option_value < '$threshold'
545 545
 		";
546 546
 
547
-        $num_results += $wpdb->query($sql);
547
+        $num_results += $wpdb->query( $sql );
548 548
 
549
-        gravityview()->log->debug('Deleted {count} expired transient records from the database', ['count' => $num_results]);
549
+        gravityview()->log->debug( 'Deleted {count} expired transient records from the database', [ 'count' => $num_results ] );
550 550
     }
551 551
 
552 552
     /**
@@ -560,28 +560,28 @@  discard block
 block discarded – undo
560 560
     {
561 561
 
562 562
         // Exit early if debugging (unless running PHPUnit)
563
-        if (defined('WP_DEBUG') && WP_DEBUG && !(defined('DOING_GRAVITYVIEW_TESTS') && DOING_GRAVITYVIEW_TESTS)) {
564
-            return apply_filters('gravityview_use_cache', false, $this);
563
+        if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! ( defined( 'DOING_GRAVITYVIEW_TESTS' ) && DOING_GRAVITYVIEW_TESTS ) ) {
564
+            return apply_filters( 'gravityview_use_cache', false, $this );
565 565
         }
566 566
 
567 567
         $use_cache = true;
568 568
 
569
-        if (GVCommon::has_cap('edit_gravityviews')) {
570
-            if (isset($_GET['cache']) || isset($_GET['nocache'])) {
571
-                gravityview()->log->debug('Not using cache: ?cache or ?nocache is in the URL');
569
+        if ( GVCommon::has_cap( 'edit_gravityviews' ) ) {
570
+            if ( isset( $_GET[ 'cache' ] ) || isset( $_GET[ 'nocache' ] ) ) {
571
+                gravityview()->log->debug( 'Not using cache: ?cache or ?nocache is in the URL' );
572 572
 
573 573
                 $use_cache = false;
574 574
             }
575 575
         }
576 576
 
577 577
         // Has the form been flagged as having changed items in it?
578
-        if ($this->in_blocklist() || !$use_cache) {
578
+        if ( $this->in_blocklist() || ! $use_cache ) {
579 579
 
580 580
             // Delete caches for all items with form IDs XYZ
581
-            $this->delete($this->form_ids);
581
+            $this->delete( $this->form_ids );
582 582
 
583 583
             // Remove the form from
584
-            $this->blocklist_remove($this->form_ids);
584
+            $this->blocklist_remove( $this->form_ids );
585 585
         }
586 586
 
587 587
         /**
@@ -590,9 +590,9 @@  discard block
 block discarded – undo
590 590
          * @param bool              $use_cache Previous setting
591 591
          * @param GravityView_Cache $this      The GravityView_Cache object
592 592
          */
593
-        $use_cache = apply_filters('gravityview_use_cache', $use_cache, $this);
593
+        $use_cache = apply_filters( 'gravityview_use_cache', $use_cache, $this );
594 594
 
595
-        return (bool) $use_cache;
595
+        return (bool)$use_cache;
596 596
     }
597 597
 }
598 598
 
Please login to merge, or discard this patch.
Braces   +22 added lines, -44 removed lines patch added patch discarded remove patch
@@ -3,8 +3,7 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  * Handle caching using transients for GravityView.
5 5
  */
6
-class GravityView_Cache
7
-{
6
+class GravityView_Cache {
8 7
     /** @deprecated 2.14 - use BLOCKLIST_OPTION_NAME instead! */
9 8
     const BLACKLIST_OPTION_NAME = 'gravityview_cache_blocklist';
10 9
 
@@ -42,8 +41,7 @@  discard block
 block discarded – undo
42 41
      * @param array|int $form_ids Form ID or array of form IDs used in a request
43 42
      * @param array     $args     Extra request parameters used to generate the query. This is used to generate the unique transient key.
44 43
      */
45
-    public function __construct($form_ids = null, $args = [])
46
-    {
44
+    public function __construct($form_ids = null, $args = []) {
47 45
         $this->add_hooks();
48 46
 
49 47
         if (!is_null($form_ids)) {
@@ -58,8 +56,7 @@  discard block
 block discarded – undo
58 56
     /**
59 57
      * Add actions for clearing out caches when entries are updated.
60 58
      */
61
-    public function add_hooks()
62
-    {
59
+    public function add_hooks() {
63 60
 
64 61
         // Schedule cleanup of expired transients
65 62
         add_action('wp', [$this, 'schedule_transient_cleanup']);
@@ -104,8 +101,7 @@  discard block
 block discarded – undo
104 101
      *
105 102
      * @return void
106 103
      */
107
-    public function entry_status_changed($lead_id, $property_value = '', $previous_value = '')
108
-    {
104
+    public function entry_status_changed($lead_id, $property_value = '', $previous_value = '') {
109 105
         $entry = GFAPI::get_entry($lead_id);
110 106
 
111 107
         if (is_wp_error($entry)) {
@@ -127,8 +123,7 @@  discard block
 block discarded – undo
127 123
      *
128 124
      * @return void
129 125
      */
130
-    public function entry_updated($form, $lead_id)
131
-    {
126
+    public function entry_updated($form, $lead_id) {
132 127
         gravityview()->log->debug(' adding form {form_id} to blocklist because entry #{entry_id} was updated', ['form_id' => $form['id'], 'entry_id' => $lead_id]);
133 128
 
134 129
         $this->blocklist_add($form['id']);
@@ -144,8 +139,7 @@  discard block
 block discarded – undo
144 139
      *
145 140
      * @return void
146 141
      */
147
-    public function entry_created($entry, $form)
148
-    {
142
+    public function entry_created($entry, $form) {
149 143
         gravityview()->log->debug('adding form {form_id} to blocklist because entry #{entry_id} was created', ['form_id' => $form['id'], 'entry_id' => $entry['id']]);
150 144
 
151 145
         $this->blocklist_add($form['id']);
@@ -159,8 +153,7 @@  discard block
 block discarded – undo
159 153
      *
160 154
      * @return void
161 155
      */
162
-    public function entry_added($entry, $form)
163
-    {
156
+    public function entry_added($entry, $form) {
164 157
         if (is_wp_error($entry)) {
165 158
             return;
166 159
         }
@@ -177,8 +170,7 @@  discard block
 block discarded – undo
177 170
      *
178 171
      * @return string Prefix for the cache string used in set_key()
179 172
      */
180
-    protected function get_cache_key_prefix($form_ids = null)
181
-    {
173
+    protected function get_cache_key_prefix($form_ids = null) {
182 174
         if (is_null($form_ids)) {
183 175
             $form_ids = $this->form_ids;
184 176
         }
@@ -196,8 +188,7 @@  discard block
 block discarded – undo
196 188
     /**
197 189
      * Set the transient key based on the form IDs and the arguments passed to the class.
198 190
      */
199
-    protected function set_key()
200
-    {
191
+    protected function set_key() {
201 192
 
202 193
         // Don't set key if no forms have been set.
203 194
         if (empty($this->form_ids)) {
@@ -218,8 +209,7 @@  discard block
 block discarded – undo
218 209
      *
219 210
      * @return string Transient key
220 211
      */
221
-    public function get_key()
222
-    {
212
+    public function get_key() {
223 213
         return $this->key;
224 214
     }
225 215
 
@@ -230,8 +220,7 @@  discard block
 block discarded – undo
230 220
      *
231 221
      * @return bool False if value was not updated and true if value was updated.
232 222
      */
233
-    public function blocklist_add($form_ids)
234
-    {
223
+    public function blocklist_add($form_ids) {
235 224
         $blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
236 225
 
237 226
         $form_ids = is_array($form_ids) ? $form_ids : [$form_ids];
@@ -264,8 +253,7 @@  discard block
 block discarded – undo
264 253
      *
265 254
      * @return bool Whether the removal was successful
266 255
      */
267
-    public function blacklist_add($form_ids)
268
-    {
256
+    public function blacklist_add($form_ids) {
269 257
         _deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::blocklist_add()');
270 258
 
271 259
         return $this->blocklist_remove($form_ids);
@@ -278,8 +266,7 @@  discard block
 block discarded – undo
278 266
      *
279 267
      * @return bool Whether the removal was successful
280 268
      */
281
-    public function blocklist_remove($form_ids)
282
-    {
269
+    public function blocklist_remove($form_ids) {
283 270
         $blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
284 271
 
285 272
         $updated_list = array_diff($blocklist, (array) $form_ids);
@@ -300,8 +287,7 @@  discard block
 block discarded – undo
300 287
      *
301 288
      * @return bool Whether the removal was successful
302 289
      */
303
-    public function blacklist_remove($form_ids)
304
-    {
290
+    public function blacklist_remove($form_ids) {
305 291
         _deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::blocklist_remove()');
306 292
 
307 293
         return $this->blocklist_remove($form_ids);
@@ -316,8 +302,7 @@  discard block
 block discarded – undo
316 302
      *
317 303
      * @return bool
318 304
      */
319
-    public function in_blacklist($form_ids = null)
320
-    {
305
+    public function in_blacklist($form_ids = null) {
321 306
         _deprecated_function(__METHOD__, '2.14', 'GravityView_Cache::in_blocklist()');
322 307
 
323 308
         return $this->in_blocklist($form_ids);
@@ -330,8 +315,7 @@  discard block
 block discarded – undo
330 315
      *
331 316
      * @return bool
332 317
      */
333
-    public function in_blocklist($form_ids = null)
334
-    {
318
+    public function in_blocklist($form_ids = null) {
335 319
         $blocklist = get_option(self::BLOCKLIST_OPTION_NAME, []);
336 320
 
337 321
         // Use object var if exists
@@ -361,8 +345,7 @@  discard block
 block discarded – undo
361 345
      *
362 346
      * @return mixed False: Not using cache or cache was a WP_Error object; NULL: no results found; Mixed: cache value
363 347
      */
364
-    public function get($key = null)
365
-    {
348
+    public function get($key = null) {
366 349
         $key = is_null($key) ? $this->key : $key;
367 350
 
368 351
         if (!$this->use_cache()) {
@@ -400,8 +383,7 @@  discard block
 block discarded – undo
400 383
      *
401 384
      * @return bool If $content is not set, false. Otherwise, returns true if transient was set and false if not.
402 385
      */
403
-    public function set($content, $filter_name = '')
404
-    {
386
+    public function set($content, $filter_name = '') {
405 387
 
406 388
         // Don't cache empty results
407 389
         if (!empty($content)) {
@@ -433,8 +415,7 @@  discard block
 block discarded – undo
433 415
      *
434 416
      * @return void
435 417
      */
436
-    public function delete($form_ids = null)
437
-    {
418
+    public function delete($form_ids = null) {
438 419
         global $wpdb;
439 420
 
440 421
         // Use object var if exists
@@ -476,8 +457,7 @@  discard block
 block discarded – undo
476 457
      *
477 458
      * @return void
478 459
      */
479
-    public function schedule_transient_cleanup()
480
-    {
460
+    public function schedule_transient_cleanup() {
481 461
 
482 462
         /**
483 463
          * @filter `gravityview_cleanup_transients` Override GravityView cleanup of transients by setting this to false
@@ -505,8 +485,7 @@  discard block
 block discarded – undo
505 485
      *
506 486
      * @return void
507 487
      */
508
-    public function delete_expired_transients()
509
-    {
488
+    public function delete_expired_transients() {
510 489
         global $wpdb;
511 490
 
512 491
         // Added this line, which isn't in the plugin
@@ -556,8 +535,7 @@  discard block
 block discarded – undo
556 535
      *
557 536
      * @return bool True: use cache; False: don't use cache
558 537
      */
559
-    public function use_cache()
560
-    {
538
+    public function use_cache() {
561 539
 
562 540
         // Exit early if debugging (unless running PHPUnit)
563 541
         if (defined('WP_DEBUG') && WP_DEBUG && !(defined('DOING_GRAVITYVIEW_TESTS') && DOING_GRAVITYVIEW_TESTS)) {
Please login to merge, or discard this patch.
includes/class-admin-approve-entries.php 3 patches
Indentation   +428 added lines, -428 removed lines patch added patch discarded remove patch
@@ -13,194 +13,194 @@  discard block
 block discarded – undo
13 13
  */
14 14
 class GravityView_Admin_ApproveEntries
15 15
 {
16
-    // hold notification messages
17
-    public $bulk_update_message = '';
18
-
19
-    /**
20
-     * @var array Set the prefixes here instead of spread across the class
21
-     *
22
-     * @since 1.17
23
-     */
24
-    private $bulk_action_prefixes = [
25
-        'approve'    => 'gvapprove',
26
-        'disapprove' => 'gvdisapprove',
27
-        'unapprove'  => 'gvunapprove',
28
-    ];
29
-
30
-    public function __construct()
31
-    {
32
-        $this->add_hooks();
33
-    }
34
-
35
-    private function add_hooks()
36
-    {
37
-        /** Edit Gravity Form page */
38
-
39
-        // Add button to left menu
40
-        add_filter('gform_add_field_buttons', [$this, 'add_field_buttons']);
41
-        // Set defaults
42
-        add_action('gform_editor_js_set_default_values', [$this, 'set_defaults']);
43
-
44
-        /** gf_entries page - entries table screen */
45
-
46
-        // add hidden field with approve status
47
-        add_action('gform_entries_first_column_actions', [$this, 'add_entry_approved_hidden_input'], 1, 5);
48
-
49
-        add_filter('gravityview/metaboxes/tooltips', [$this, 'tooltips']);
50
-
51
-        // adding styles and scripts
52
-        add_action('admin_enqueue_scripts', [$this, 'add_scripts_and_styles']);
53
-        // bypass Gravity Forms no-conflict mode
54
-        add_filter('gform_noconflict_scripts', [$this, 'register_gform_noconflict_script']);
55
-        add_filter('gform_noconflict_styles', [$this, 'register_gform_noconflict_style']);
56
-
57
-        add_filter('gform_filter_links_entry_list', [$this, 'filter_links_entry_list'], 10, 3);
58
-    }
59
-
60
-    /**
61
-     * Add filter links to the Entries page.
62
-     *
63
-     * Can be disabled by returning false on the `gravityview/approve_entries/show_filter_links_entry_list` filter
64
-     *
65
-     * @since 1.17.1
66
-     *
67
-     * @param array $filter_links   Array of links to include in the subsubsub filter list. Includes `id`, `field_filters`, `count`, and `label` keys
68
-     * @param array $form           GF Form object of current form
69
-     * @param bool  $include_counts Whether to include counts in the output
70
-     *
71
-     * @return array Filter links, with GravityView approved/disapproved links added
72
-     */
73
-    public function filter_links_entry_list($filter_links = [], $form = [], $include_counts = true)
74
-    {
75
-
76
-        /**
77
-         * @filter `gravityview/approve_entries/show_filter_links_entry_list` Disable filter links
78
-         *
79
-         * @since 1.17.1
80
-         *
81
-         * @param bool  $show_filter_links True: show the "approved"/"disapproved" filter links. False: hide them.
82
-         * @param array $form              GF Form object of current form
83
-         */
84
-        if (false === apply_filters('gravityview/approve_entries/show_filter_links_entry_list', true, $form)) {
85
-            return $filter_links;
86
-        }
87
-
88
-        $field_filters_approved = [
89
-            [
90
-                'key'   => GravityView_Entry_Approval::meta_key,
91
-                'value' => GravityView_Entry_Approval_Status::APPROVED,
92
-            ],
93
-        ];
94
-
95
-        $field_filters_disapproved = [
96
-            [
97
-                'key'      => GravityView_Entry_Approval::meta_key,
98
-                'value'    => GravityView_Entry_Approval_Status::DISAPPROVED,
99
-            ],
100
-        ];
101
-
102
-        $field_filters_unapproved = [
103
-            [
104
-                'key'      => GravityView_Entry_Approval::meta_key,
105
-                'value'    => GravityView_Entry_Approval_Status::UNAPPROVED,
106
-            ],
107
-        ];
108
-
109
-        $approved_count = $disapproved_count = $unapproved_count = 0;
110
-
111
-        // Only count if necessary
112
-        if ($include_counts) {
113
-            $approved_count = count(gravityview_get_entry_ids($form['id'], ['status' => 'active', 'field_filters' => $field_filters_approved]));
114
-            $disapproved_count = count(gravityview_get_entry_ids($form['id'], ['status' => 'active', 'field_filters' => $field_filters_disapproved]));
115
-            $unapproved_count = count(gravityview_get_entry_ids($form['id'], ['status' => 'active', 'field_filters' => $field_filters_unapproved]));
116
-        }
117
-
118
-        $filter_links[] = [
119
-            'id'            => 'gv_approved',
120
-            'field_filters' => $field_filters_approved,
121
-            'count'         => $approved_count,
122
-            'label'         => GravityView_Entry_Approval_Status::get_label(GravityView_Entry_Approval_Status::APPROVED),
123
-        ];
124
-
125
-        $filter_links[] = [
126
-            'id'            => 'gv_disapproved',
127
-            'field_filters' => $field_filters_disapproved,
128
-            'count'         => $disapproved_count,
129
-            'label'         => GravityView_Entry_Approval_Status::get_label(GravityView_Entry_Approval_Status::DISAPPROVED),
130
-        ];
131
-
132
-        $filter_links[] = [
133
-            'id'            => 'gv_unapproved',
134
-            'field_filters' => $field_filters_unapproved,
135
-            'count'         => $unapproved_count,
136
-            'label'         => GravityView_Entry_Approval_Status::get_label(GravityView_Entry_Approval_Status::UNAPPROVED),
137
-        ];
138
-
139
-        return $filter_links;
140
-    }
141
-
142
-    /**
143
-     * Add the GravityView Fields group tooltip.
144
-     *
145
-     * @param $tooltips
146
-     *
147
-     * @return array Tooltips array with GravityView fields tooltip
148
-     */
149
-    public function tooltips($tooltips)
150
-    {
151
-        $tooltips['form_gravityview_fields'] = [
152
-            'title' => __('GravityView Fields', 'gravityview'),
153
-            'value' => __('Allow administrators to approve or reject entries and users to opt-in or opt-out of their entries being displayed.', 'gravityview'),
154
-        ];
155
-
156
-        return $tooltips;
157
-    }
158
-
159
-    /**
160
-     * Inject new add field buttons in the gravity form editor page.
161
-     *
162
-     * @param mixed $field_groups
163
-     *
164
-     * @return array Array of fields
165
-     */
166
-    public function add_field_buttons($field_groups)
167
-    {
168
-        $gravityview_fields = [
169
-            'name'   => 'gravityview_fields',
170
-            'label'  => 'GravityView',
171
-            'fields' => [
172
-                [
173
-                    'class'     => 'button',
174
-                    'value'     => __('Approve/Reject', 'gravityview'),
175
-                    'onclick'   => "StartAddField('gravityviewapproved_admin');",
176
-                    'data-type' => 'gravityviewapproved_admin',
177
-                    'data-icon' => 'dashicons-yes-alt',
178
-                ],
179
-                [
180
-                    'class'     => 'button',
181
-                    'value'     => __('User Opt-In', 'gravityview'),
182
-                    'onclick'   => "StartAddField('gravityviewapproved');",
183
-                    'data-type' => 'gravityviewapproved',
184
-                    'data-icon' => 'dashicons-media-text',
185
-                ],
186
-            ],
187
-        ];
188
-
189
-        array_push($field_groups, $gravityview_fields);
190
-
191
-        return $field_groups;
192
-    }
193
-
194
-    /**
195
-     * At edit form page, set the field Approve defaults.
196
-     *
197
-     * @todo Convert to a partial include file
198
-     *
199
-     * @return void
200
-     */
201
-    public function set_defaults()
202
-    {
203
-        ?>
16
+	// hold notification messages
17
+	public $bulk_update_message = '';
18
+
19
+	/**
20
+	 * @var array Set the prefixes here instead of spread across the class
21
+	 *
22
+	 * @since 1.17
23
+	 */
24
+	private $bulk_action_prefixes = [
25
+		'approve'    => 'gvapprove',
26
+		'disapprove' => 'gvdisapprove',
27
+		'unapprove'  => 'gvunapprove',
28
+	];
29
+
30
+	public function __construct()
31
+	{
32
+		$this->add_hooks();
33
+	}
34
+
35
+	private function add_hooks()
36
+	{
37
+		/** Edit Gravity Form page */
38
+
39
+		// Add button to left menu
40
+		add_filter('gform_add_field_buttons', [$this, 'add_field_buttons']);
41
+		// Set defaults
42
+		add_action('gform_editor_js_set_default_values', [$this, 'set_defaults']);
43
+
44
+		/** gf_entries page - entries table screen */
45
+
46
+		// add hidden field with approve status
47
+		add_action('gform_entries_first_column_actions', [$this, 'add_entry_approved_hidden_input'], 1, 5);
48
+
49
+		add_filter('gravityview/metaboxes/tooltips', [$this, 'tooltips']);
50
+
51
+		// adding styles and scripts
52
+		add_action('admin_enqueue_scripts', [$this, 'add_scripts_and_styles']);
53
+		// bypass Gravity Forms no-conflict mode
54
+		add_filter('gform_noconflict_scripts', [$this, 'register_gform_noconflict_script']);
55
+		add_filter('gform_noconflict_styles', [$this, 'register_gform_noconflict_style']);
56
+
57
+		add_filter('gform_filter_links_entry_list', [$this, 'filter_links_entry_list'], 10, 3);
58
+	}
59
+
60
+	/**
61
+	 * Add filter links to the Entries page.
62
+	 *
63
+	 * Can be disabled by returning false on the `gravityview/approve_entries/show_filter_links_entry_list` filter
64
+	 *
65
+	 * @since 1.17.1
66
+	 *
67
+	 * @param array $filter_links   Array of links to include in the subsubsub filter list. Includes `id`, `field_filters`, `count`, and `label` keys
68
+	 * @param array $form           GF Form object of current form
69
+	 * @param bool  $include_counts Whether to include counts in the output
70
+	 *
71
+	 * @return array Filter links, with GravityView approved/disapproved links added
72
+	 */
73
+	public function filter_links_entry_list($filter_links = [], $form = [], $include_counts = true)
74
+	{
75
+
76
+		/**
77
+		 * @filter `gravityview/approve_entries/show_filter_links_entry_list` Disable filter links
78
+		 *
79
+		 * @since 1.17.1
80
+		 *
81
+		 * @param bool  $show_filter_links True: show the "approved"/"disapproved" filter links. False: hide them.
82
+		 * @param array $form              GF Form object of current form
83
+		 */
84
+		if (false === apply_filters('gravityview/approve_entries/show_filter_links_entry_list', true, $form)) {
85
+			return $filter_links;
86
+		}
87
+
88
+		$field_filters_approved = [
89
+			[
90
+				'key'   => GravityView_Entry_Approval::meta_key,
91
+				'value' => GravityView_Entry_Approval_Status::APPROVED,
92
+			],
93
+		];
94
+
95
+		$field_filters_disapproved = [
96
+			[
97
+				'key'      => GravityView_Entry_Approval::meta_key,
98
+				'value'    => GravityView_Entry_Approval_Status::DISAPPROVED,
99
+			],
100
+		];
101
+
102
+		$field_filters_unapproved = [
103
+			[
104
+				'key'      => GravityView_Entry_Approval::meta_key,
105
+				'value'    => GravityView_Entry_Approval_Status::UNAPPROVED,
106
+			],
107
+		];
108
+
109
+		$approved_count = $disapproved_count = $unapproved_count = 0;
110
+
111
+		// Only count if necessary
112
+		if ($include_counts) {
113
+			$approved_count = count(gravityview_get_entry_ids($form['id'], ['status' => 'active', 'field_filters' => $field_filters_approved]));
114
+			$disapproved_count = count(gravityview_get_entry_ids($form['id'], ['status' => 'active', 'field_filters' => $field_filters_disapproved]));
115
+			$unapproved_count = count(gravityview_get_entry_ids($form['id'], ['status' => 'active', 'field_filters' => $field_filters_unapproved]));
116
+		}
117
+
118
+		$filter_links[] = [
119
+			'id'            => 'gv_approved',
120
+			'field_filters' => $field_filters_approved,
121
+			'count'         => $approved_count,
122
+			'label'         => GravityView_Entry_Approval_Status::get_label(GravityView_Entry_Approval_Status::APPROVED),
123
+		];
124
+
125
+		$filter_links[] = [
126
+			'id'            => 'gv_disapproved',
127
+			'field_filters' => $field_filters_disapproved,
128
+			'count'         => $disapproved_count,
129
+			'label'         => GravityView_Entry_Approval_Status::get_label(GravityView_Entry_Approval_Status::DISAPPROVED),
130
+		];
131
+
132
+		$filter_links[] = [
133
+			'id'            => 'gv_unapproved',
134
+			'field_filters' => $field_filters_unapproved,
135
+			'count'         => $unapproved_count,
136
+			'label'         => GravityView_Entry_Approval_Status::get_label(GravityView_Entry_Approval_Status::UNAPPROVED),
137
+		];
138
+
139
+		return $filter_links;
140
+	}
141
+
142
+	/**
143
+	 * Add the GravityView Fields group tooltip.
144
+	 *
145
+	 * @param $tooltips
146
+	 *
147
+	 * @return array Tooltips array with GravityView fields tooltip
148
+	 */
149
+	public function tooltips($tooltips)
150
+	{
151
+		$tooltips['form_gravityview_fields'] = [
152
+			'title' => __('GravityView Fields', 'gravityview'),
153
+			'value' => __('Allow administrators to approve or reject entries and users to opt-in or opt-out of their entries being displayed.', 'gravityview'),
154
+		];
155
+
156
+		return $tooltips;
157
+	}
158
+
159
+	/**
160
+	 * Inject new add field buttons in the gravity form editor page.
161
+	 *
162
+	 * @param mixed $field_groups
163
+	 *
164
+	 * @return array Array of fields
165
+	 */
166
+	public function add_field_buttons($field_groups)
167
+	{
168
+		$gravityview_fields = [
169
+			'name'   => 'gravityview_fields',
170
+			'label'  => 'GravityView',
171
+			'fields' => [
172
+				[
173
+					'class'     => 'button',
174
+					'value'     => __('Approve/Reject', 'gravityview'),
175
+					'onclick'   => "StartAddField('gravityviewapproved_admin');",
176
+					'data-type' => 'gravityviewapproved_admin',
177
+					'data-icon' => 'dashicons-yes-alt',
178
+				],
179
+				[
180
+					'class'     => 'button',
181
+					'value'     => __('User Opt-In', 'gravityview'),
182
+					'onclick'   => "StartAddField('gravityviewapproved');",
183
+					'data-type' => 'gravityviewapproved',
184
+					'data-icon' => 'dashicons-media-text',
185
+				],
186
+			],
187
+		];
188
+
189
+		array_push($field_groups, $gravityview_fields);
190
+
191
+		return $field_groups;
192
+	}
193
+
194
+	/**
195
+	 * At edit form page, set the field Approve defaults.
196
+	 *
197
+	 * @todo Convert to a partial include file
198
+	 *
199
+	 * @return void
200
+	 */
201
+	public function set_defaults()
202
+	{
203
+		?>
204 204
 		case 'gravityviewapproved_admin':
205 205
 			field.label = "<?php echo esc_js(__('Approved? (Admin-only)', 'gravityview')); ?>";
206 206
 
@@ -248,246 +248,246 @@  discard block
 block discarded – undo
248 248
 
249 249
 			break;
250 250
 		<?php
251
-    }
252
-
253
-    /**
254
-     * update_approved function.
255
-     *
256
-     * @since 1.18 Moved to GravityView_Entry_Approval::update_approved
257
-     * @see GravityView_Entry_Approval::update_approved
258
-     *
259
-     * @param int $entry_id       (default: 0)
260
-     * @param int $approved       (default: 0)
261
-     * @param int $form_id        (default: 0)
262
-     * @param int $approvedcolumn (default: 0)
263
-     *
264
-     * @return bool True: It worked; False: it failed
265
-     */
266
-    public static function update_approved($entry_id = 0, $approved = 0, $form_id = 0, $approvedcolumn = 0)
267
-    {
268
-        return GravityView_Entry_Approval::update_approved($entry_id, $approved, $form_id, $approvedcolumn);
269
-    }
270
-
271
-    /**
272
-     * Calculate the approve field.input id.
273
-     *
274
-     * @since 1.18 Moved to GravityView_Entry_Approval::get_approved_column
275
-     * @see GravityView_Entry_Approval::get_approved_column
276
-     *
277
-     * @param mixed $form GF Form or Form ID
278
-     *
279
-     * @return false|null|string Returns the input ID of the approved field. Returns NULL if no approved fields were found. Returns false if $form_id wasn't set.
280
-     */
281
-    public static function get_approved_column($form)
282
-    {
283
-        return GravityView_Entry_Approval::get_approved_column($form);
284
-    }
285
-
286
-    /**
287
-     * Add a hidden input that is used in the Javascript to show approved/disapproved entries checkbox.
288
-     *
289
-     * See the /assets/js/admin-entries-list.js setInitialApprovedEntries method
290
-     *
291
-     * @param $form_id
292
-     * @param $field_id
293
-     * @param $value
294
-     * @param $entry
295
-     * @param $query_string
296
-     *
297
-     * @return void
298
-     */
299
-    public static function add_entry_approved_hidden_input($form_id, $field_id, $value, $entry, $query_string)
300
-    {
301
-        if (!GVCommon::has_cap('gravityview_moderate_entries', $entry['id'])) {
302
-            return;
303
-        }
304
-
305
-        if (empty($entry['id'])) {
306
-            return;
307
-        }
308
-
309
-        $status_value = GravityView_Entry_Approval::get_entry_status($entry, 'value');
310
-
311
-        if ($status_value) {
312
-            echo '<input type="hidden" class="entry_approval" id="entry_approved_'.$entry['id'].'" value="'.esc_attr($status_value).'" />';
313
-        }
314
-    }
315
-
316
-    /**
317
-     * Get the form ID of the form currently being displayed.
318
-     *
319
-     * @since 1.17.1
320
-     *
321
-     * @return int ID of the current form being displayed. `0` is returned if no forms are found.
322
-     */
323
-    private function get_form_id()
324
-    {
325
-        $form_id = GFForms::get('id');
326
-
327
-        // If there are no forms identified, use the first form. That's how GF does it.
328
-        if (empty($form_id) && class_exists('RGFormsModel')) {
329
-            $form_id = $this->get_first_form_id();
330
-        }
331
-
332
-        return absint($form_id);
333
-    }
334
-
335
-    /**
336
-     * Get the first form ID from Gravity Forms, sorted in the same order as in the All Forms page.
337
-     *
338
-     * @see GFEntryList::all_entries_page() This method is based on the form-selecting code here
339
-     * @since 1.17.2
340
-     *
341
-     * @return int ID of the first form, sorted by title. `0` if no forms were found.
342
-     */
343
-    private function get_first_form_id()
344
-    {
345
-        $forms = RGFormsModel::get_forms(null, 'title');
346
-
347
-        if (!isset($forms[0])) {
348
-            gravityview()->log->error('No forms were found');
349
-
350
-            return 0;
351
-        }
352
-
353
-        $first_form = $forms[0];
354
-
355
-        $form_id = is_object($forms[0]) ? $first_form->id : $first_form['id'];
356
-
357
-        return intval($form_id);
358
-    }
359
-
360
-    public function add_scripts_and_styles($hook)
361
-    {
362
-        if (!class_exists('GFForms')) {
363
-            gravityview()->log->error('GFForms does not exist.');
364
-
365
-            return;
366
-        }
367
-
368
-        // enqueue styles & scripts gf_entries
369
-        // But only if we're on the main Entries page, not on reports pages
370
-        if (GFForms::get_page() !== 'entry_list') {
371
-            return;
372
-        }
373
-
374
-        $form_id = $this->get_form_id();
375
-
376
-        // Things are broken; no forms were found
377
-        if (empty($form_id)) {
378
-            return;
379
-        }
380
-
381
-        wp_enqueue_style('gravityview_entries_list', plugins_url('assets/css/admin-entries-list.css', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
382
-
383
-        $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
384
-
385
-        wp_enqueue_script('gravityview_gf_entries_scripts', plugins_url('assets/js/admin-entries-list'.$script_debug.'.js', GRAVITYVIEW_FILE), ['jquery'], GravityView_Plugin::version);
386
-
387
-        wp_enqueue_script('gravityview_entries_list-popper', plugins_url('assets/lib/tippy/popper.min.js', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
388
-        wp_enqueue_script('gravityview_entries_list-tippy', plugins_url('assets/lib/tippy/tippy.min.js', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
389
-        wp_enqueue_style('gravityview_entries_list-tippy', plugins_url('assets/lib/tippy/tippy.css', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
390
-
391
-        wp_localize_script('gravityview_gf_entries_scripts', 'gvGlobals', [
392
-            'nonce'                    => wp_create_nonce('gravityview_entry_approval'),
393
-            'admin_nonce'              => wp_create_nonce('gravityview_admin_entry_approval'),
394
-            'form_id'                  => $form_id,
395
-            'show_column'              => (int) $this->show_approve_entry_column($form_id),
396
-            'add_bulk_action'          => (int) GVCommon::has_cap('gravityview_moderate_entries'),
397
-            'status_approved'          => GravityView_Entry_Approval_Status::APPROVED,
398
-            'status_disapproved'       => GravityView_Entry_Approval_Status::DISAPPROVED,
399
-            'status_unapproved'        => GravityView_Entry_Approval_Status::UNAPPROVED,
400
-            'bulk_actions'             => GravityView_Bulk_Actions::get_bulk_actions($form_id),
401
-            'bulk_message'             => $this->bulk_update_message,
402
-            'unapprove_title'          => GravityView_Entry_Approval_Status::get_title_attr('unapproved'),
403
-            'approve_title'            => GravityView_Entry_Approval_Status::get_title_attr('disapproved'),
404
-            'disapprove_title'         => GravityView_Entry_Approval_Status::get_title_attr('approved'),
405
-            'column_title'             => __('Show entry in directory view?', 'gravityview'),
406
-            'column_link'              => esc_url($this->get_sort_link()),
407
-            'status_popover_template'  => GravityView_Entry_Approval::get_popover_template(),
408
-            'status_popover_placement' => GravityView_Entry_Approval::get_popover_placement(),
409
-        ]);
410
-    }
411
-
412
-    /**
413
-     * Generate a link to sort by approval status.
414
-     *
415
-     * Note: Sorting by approval will never be great because it's not possible currently to declare the sorting as
416
-     * numeric, but it does group the approved entries together.
417
-     *
418
-     * @since 2.0.14 Remove need for approval field for sorting by approval status
419
-     *
420
-     * @param int $form_id [NO LONGER USED]
421
-     *
422
-     * @return string Sorting link
423
-     */
424
-    private function get_sort_link($form_id = 0)
425
-    {
426
-        $args = [
427
-            'orderby' => 'is_approved',
428
-            'order'   => ('desc' === \GV\Utils::_GET('order')) ? 'asc' : 'desc',
429
-        ];
430
-
431
-        return add_query_arg($args);
432
-    }
433
-
434
-    /**
435
-     * Should the Approve/Reject Entry column be shown in the GF Entries page?
436
-     *
437
-     * @since 1.7.2
438
-     *
439
-     * @param int $form_id The ID of the Gravity Forms form for which entries are being shown
440
-     *
441
-     * @return bool True: Show column; False: hide column
442
-     */
443
-    private function show_approve_entry_column($form_id)
444
-    {
445
-        $show_approve_column = GVCommon::has_cap('gravityview_moderate_entries');
446
-
447
-        /**
448
-         * @filter `gravityview/approve_entries/hide-if-no-connections` Return true to hide reject/approve if there are no connected Views
449
-         *
450
-         * @since 1.7.2
451
-         *
452
-         * @param bool $hide_if_no_connections
453
-         */
454
-        $hide_if_no_connections = apply_filters('gravityview/approve_entries/hide-if-no-connections', false);
455
-
456
-        if ($hide_if_no_connections) {
457
-            $connected_views = gravityview_get_connected_views($form_id);
458
-
459
-            if (empty($connected_views)) {
460
-                $show_approve_column = false;
461
-            }
462
-        }
463
-
464
-        /**
465
-         * @filter `gravityview/approve_entries/show-column` Override whether the column is shown
466
-         *
467
-         * @param bool $show_approve_column Whether the column will be shown
468
-         * @param int  $form_id             The ID of the Gravity Forms form for which entries are being shown
469
-         */
470
-        $show_approve_column = apply_filters('gravityview/approve_entries/show-column', $show_approve_column, $form_id);
471
-
472
-        return $show_approve_column;
473
-    }
474
-
475
-    public function register_gform_noconflict_script($scripts)
476
-    {
477
-        $scripts[] = 'gravityview_gf_entries_scripts';
478
-        $scripts[] = 'gravityview_entries_list-popper';
479
-        $scripts[] = 'gravityview_entries_list-tippy';
480
-
481
-        return $scripts;
482
-    }
483
-
484
-    public function register_gform_noconflict_style($styles)
485
-    {
486
-        $styles[] = 'gravityview_entries_list';
487
-        $styles[] = 'gravityview_entries_list-tippy';
488
-
489
-        return $styles;
490
-    }
251
+	}
252
+
253
+	/**
254
+	 * update_approved function.
255
+	 *
256
+	 * @since 1.18 Moved to GravityView_Entry_Approval::update_approved
257
+	 * @see GravityView_Entry_Approval::update_approved
258
+	 *
259
+	 * @param int $entry_id       (default: 0)
260
+	 * @param int $approved       (default: 0)
261
+	 * @param int $form_id        (default: 0)
262
+	 * @param int $approvedcolumn (default: 0)
263
+	 *
264
+	 * @return bool True: It worked; False: it failed
265
+	 */
266
+	public static function update_approved($entry_id = 0, $approved = 0, $form_id = 0, $approvedcolumn = 0)
267
+	{
268
+		return GravityView_Entry_Approval::update_approved($entry_id, $approved, $form_id, $approvedcolumn);
269
+	}
270
+
271
+	/**
272
+	 * Calculate the approve field.input id.
273
+	 *
274
+	 * @since 1.18 Moved to GravityView_Entry_Approval::get_approved_column
275
+	 * @see GravityView_Entry_Approval::get_approved_column
276
+	 *
277
+	 * @param mixed $form GF Form or Form ID
278
+	 *
279
+	 * @return false|null|string Returns the input ID of the approved field. Returns NULL if no approved fields were found. Returns false if $form_id wasn't set.
280
+	 */
281
+	public static function get_approved_column($form)
282
+	{
283
+		return GravityView_Entry_Approval::get_approved_column($form);
284
+	}
285
+
286
+	/**
287
+	 * Add a hidden input that is used in the Javascript to show approved/disapproved entries checkbox.
288
+	 *
289
+	 * See the /assets/js/admin-entries-list.js setInitialApprovedEntries method
290
+	 *
291
+	 * @param $form_id
292
+	 * @param $field_id
293
+	 * @param $value
294
+	 * @param $entry
295
+	 * @param $query_string
296
+	 *
297
+	 * @return void
298
+	 */
299
+	public static function add_entry_approved_hidden_input($form_id, $field_id, $value, $entry, $query_string)
300
+	{
301
+		if (!GVCommon::has_cap('gravityview_moderate_entries', $entry['id'])) {
302
+			return;
303
+		}
304
+
305
+		if (empty($entry['id'])) {
306
+			return;
307
+		}
308
+
309
+		$status_value = GravityView_Entry_Approval::get_entry_status($entry, 'value');
310
+
311
+		if ($status_value) {
312
+			echo '<input type="hidden" class="entry_approval" id="entry_approved_'.$entry['id'].'" value="'.esc_attr($status_value).'" />';
313
+		}
314
+	}
315
+
316
+	/**
317
+	 * Get the form ID of the form currently being displayed.
318
+	 *
319
+	 * @since 1.17.1
320
+	 *
321
+	 * @return int ID of the current form being displayed. `0` is returned if no forms are found.
322
+	 */
323
+	private function get_form_id()
324
+	{
325
+		$form_id = GFForms::get('id');
326
+
327
+		// If there are no forms identified, use the first form. That's how GF does it.
328
+		if (empty($form_id) && class_exists('RGFormsModel')) {
329
+			$form_id = $this->get_first_form_id();
330
+		}
331
+
332
+		return absint($form_id);
333
+	}
334
+
335
+	/**
336
+	 * Get the first form ID from Gravity Forms, sorted in the same order as in the All Forms page.
337
+	 *
338
+	 * @see GFEntryList::all_entries_page() This method is based on the form-selecting code here
339
+	 * @since 1.17.2
340
+	 *
341
+	 * @return int ID of the first form, sorted by title. `0` if no forms were found.
342
+	 */
343
+	private function get_first_form_id()
344
+	{
345
+		$forms = RGFormsModel::get_forms(null, 'title');
346
+
347
+		if (!isset($forms[0])) {
348
+			gravityview()->log->error('No forms were found');
349
+
350
+			return 0;
351
+		}
352
+
353
+		$first_form = $forms[0];
354
+
355
+		$form_id = is_object($forms[0]) ? $first_form->id : $first_form['id'];
356
+
357
+		return intval($form_id);
358
+	}
359
+
360
+	public function add_scripts_and_styles($hook)
361
+	{
362
+		if (!class_exists('GFForms')) {
363
+			gravityview()->log->error('GFForms does not exist.');
364
+
365
+			return;
366
+		}
367
+
368
+		// enqueue styles & scripts gf_entries
369
+		// But only if we're on the main Entries page, not on reports pages
370
+		if (GFForms::get_page() !== 'entry_list') {
371
+			return;
372
+		}
373
+
374
+		$form_id = $this->get_form_id();
375
+
376
+		// Things are broken; no forms were found
377
+		if (empty($form_id)) {
378
+			return;
379
+		}
380
+
381
+		wp_enqueue_style('gravityview_entries_list', plugins_url('assets/css/admin-entries-list.css', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
382
+
383
+		$script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
384
+
385
+		wp_enqueue_script('gravityview_gf_entries_scripts', plugins_url('assets/js/admin-entries-list'.$script_debug.'.js', GRAVITYVIEW_FILE), ['jquery'], GravityView_Plugin::version);
386
+
387
+		wp_enqueue_script('gravityview_entries_list-popper', plugins_url('assets/lib/tippy/popper.min.js', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
388
+		wp_enqueue_script('gravityview_entries_list-tippy', plugins_url('assets/lib/tippy/tippy.min.js', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
389
+		wp_enqueue_style('gravityview_entries_list-tippy', plugins_url('assets/lib/tippy/tippy.css', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
390
+
391
+		wp_localize_script('gravityview_gf_entries_scripts', 'gvGlobals', [
392
+			'nonce'                    => wp_create_nonce('gravityview_entry_approval'),
393
+			'admin_nonce'              => wp_create_nonce('gravityview_admin_entry_approval'),
394
+			'form_id'                  => $form_id,
395
+			'show_column'              => (int) $this->show_approve_entry_column($form_id),
396
+			'add_bulk_action'          => (int) GVCommon::has_cap('gravityview_moderate_entries'),
397
+			'status_approved'          => GravityView_Entry_Approval_Status::APPROVED,
398
+			'status_disapproved'       => GravityView_Entry_Approval_Status::DISAPPROVED,
399
+			'status_unapproved'        => GravityView_Entry_Approval_Status::UNAPPROVED,
400
+			'bulk_actions'             => GravityView_Bulk_Actions::get_bulk_actions($form_id),
401
+			'bulk_message'             => $this->bulk_update_message,
402
+			'unapprove_title'          => GravityView_Entry_Approval_Status::get_title_attr('unapproved'),
403
+			'approve_title'            => GravityView_Entry_Approval_Status::get_title_attr('disapproved'),
404
+			'disapprove_title'         => GravityView_Entry_Approval_Status::get_title_attr('approved'),
405
+			'column_title'             => __('Show entry in directory view?', 'gravityview'),
406
+			'column_link'              => esc_url($this->get_sort_link()),
407
+			'status_popover_template'  => GravityView_Entry_Approval::get_popover_template(),
408
+			'status_popover_placement' => GravityView_Entry_Approval::get_popover_placement(),
409
+		]);
410
+	}
411
+
412
+	/**
413
+	 * Generate a link to sort by approval status.
414
+	 *
415
+	 * Note: Sorting by approval will never be great because it's not possible currently to declare the sorting as
416
+	 * numeric, but it does group the approved entries together.
417
+	 *
418
+	 * @since 2.0.14 Remove need for approval field for sorting by approval status
419
+	 *
420
+	 * @param int $form_id [NO LONGER USED]
421
+	 *
422
+	 * @return string Sorting link
423
+	 */
424
+	private function get_sort_link($form_id = 0)
425
+	{
426
+		$args = [
427
+			'orderby' => 'is_approved',
428
+			'order'   => ('desc' === \GV\Utils::_GET('order')) ? 'asc' : 'desc',
429
+		];
430
+
431
+		return add_query_arg($args);
432
+	}
433
+
434
+	/**
435
+	 * Should the Approve/Reject Entry column be shown in the GF Entries page?
436
+	 *
437
+	 * @since 1.7.2
438
+	 *
439
+	 * @param int $form_id The ID of the Gravity Forms form for which entries are being shown
440
+	 *
441
+	 * @return bool True: Show column; False: hide column
442
+	 */
443
+	private function show_approve_entry_column($form_id)
444
+	{
445
+		$show_approve_column = GVCommon::has_cap('gravityview_moderate_entries');
446
+
447
+		/**
448
+		 * @filter `gravityview/approve_entries/hide-if-no-connections` Return true to hide reject/approve if there are no connected Views
449
+		 *
450
+		 * @since 1.7.2
451
+		 *
452
+		 * @param bool $hide_if_no_connections
453
+		 */
454
+		$hide_if_no_connections = apply_filters('gravityview/approve_entries/hide-if-no-connections', false);
455
+
456
+		if ($hide_if_no_connections) {
457
+			$connected_views = gravityview_get_connected_views($form_id);
458
+
459
+			if (empty($connected_views)) {
460
+				$show_approve_column = false;
461
+			}
462
+		}
463
+
464
+		/**
465
+		 * @filter `gravityview/approve_entries/show-column` Override whether the column is shown
466
+		 *
467
+		 * @param bool $show_approve_column Whether the column will be shown
468
+		 * @param int  $form_id             The ID of the Gravity Forms form for which entries are being shown
469
+		 */
470
+		$show_approve_column = apply_filters('gravityview/approve_entries/show-column', $show_approve_column, $form_id);
471
+
472
+		return $show_approve_column;
473
+	}
474
+
475
+	public function register_gform_noconflict_script($scripts)
476
+	{
477
+		$scripts[] = 'gravityview_gf_entries_scripts';
478
+		$scripts[] = 'gravityview_entries_list-popper';
479
+		$scripts[] = 'gravityview_entries_list-tippy';
480
+
481
+		return $scripts;
482
+	}
483
+
484
+	public function register_gform_noconflict_style($styles)
485
+	{
486
+		$styles[] = 'gravityview_entries_list';
487
+		$styles[] = 'gravityview_entries_list-tippy';
488
+
489
+		return $styles;
490
+	}
491 491
 }
492 492
 
493 493
 new GravityView_Admin_ApproveEntries();
Please login to merge, or discard this patch.
Spacing   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
         /** Edit Gravity Form page */
38 38
 
39 39
         // Add button to left menu
40
-        add_filter('gform_add_field_buttons', [$this, 'add_field_buttons']);
40
+        add_filter( 'gform_add_field_buttons', [ $this, 'add_field_buttons' ] );
41 41
         // Set defaults
42
-        add_action('gform_editor_js_set_default_values', [$this, 'set_defaults']);
42
+        add_action( 'gform_editor_js_set_default_values', [ $this, 'set_defaults' ] );
43 43
 
44 44
         /** gf_entries page - entries table screen */
45 45
 
46 46
         // add hidden field with approve status
47
-        add_action('gform_entries_first_column_actions', [$this, 'add_entry_approved_hidden_input'], 1, 5);
47
+        add_action( 'gform_entries_first_column_actions', [ $this, 'add_entry_approved_hidden_input' ], 1, 5 );
48 48
 
49
-        add_filter('gravityview/metaboxes/tooltips', [$this, 'tooltips']);
49
+        add_filter( 'gravityview/metaboxes/tooltips', [ $this, 'tooltips' ] );
50 50
 
51 51
         // adding styles and scripts
52
-        add_action('admin_enqueue_scripts', [$this, 'add_scripts_and_styles']);
52
+        add_action( 'admin_enqueue_scripts', [ $this, 'add_scripts_and_styles' ] );
53 53
         // bypass Gravity Forms no-conflict mode
54
-        add_filter('gform_noconflict_scripts', [$this, 'register_gform_noconflict_script']);
55
-        add_filter('gform_noconflict_styles', [$this, 'register_gform_noconflict_style']);
54
+        add_filter( 'gform_noconflict_scripts', [ $this, 'register_gform_noconflict_script' ] );
55
+        add_filter( 'gform_noconflict_styles', [ $this, 'register_gform_noconflict_style' ] );
56 56
 
57
-        add_filter('gform_filter_links_entry_list', [$this, 'filter_links_entry_list'], 10, 3);
57
+        add_filter( 'gform_filter_links_entry_list', [ $this, 'filter_links_entry_list' ], 10, 3 );
58 58
     }
59 59
 
60 60
     /**
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      *
71 71
      * @return array Filter links, with GravityView approved/disapproved links added
72 72
      */
73
-    public function filter_links_entry_list($filter_links = [], $form = [], $include_counts = true)
73
+    public function filter_links_entry_list( $filter_links = [ ], $form = [ ], $include_counts = true )
74 74
     {
75 75
 
76 76
         /**
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
          * @param bool  $show_filter_links True: show the "approved"/"disapproved" filter links. False: hide them.
82 82
          * @param array $form              GF Form object of current form
83 83
          */
84
-        if (false === apply_filters('gravityview/approve_entries/show_filter_links_entry_list', true, $form)) {
84
+        if ( false === apply_filters( 'gravityview/approve_entries/show_filter_links_entry_list', true, $form ) ) {
85 85
             return $filter_links;
86 86
         }
87 87
 
@@ -109,31 +109,31 @@  discard block
 block discarded – undo
109 109
         $approved_count = $disapproved_count = $unapproved_count = 0;
110 110
 
111 111
         // Only count if necessary
112
-        if ($include_counts) {
113
-            $approved_count = count(gravityview_get_entry_ids($form['id'], ['status' => 'active', 'field_filters' => $field_filters_approved]));
114
-            $disapproved_count = count(gravityview_get_entry_ids($form['id'], ['status' => 'active', 'field_filters' => $field_filters_disapproved]));
115
-            $unapproved_count = count(gravityview_get_entry_ids($form['id'], ['status' => 'active', 'field_filters' => $field_filters_unapproved]));
112
+        if ( $include_counts ) {
113
+            $approved_count = count( gravityview_get_entry_ids( $form[ 'id' ], [ 'status' => 'active', 'field_filters' => $field_filters_approved ] ) );
114
+            $disapproved_count = count( gravityview_get_entry_ids( $form[ 'id' ], [ 'status' => 'active', 'field_filters' => $field_filters_disapproved ] ) );
115
+            $unapproved_count = count( gravityview_get_entry_ids( $form[ 'id' ], [ 'status' => 'active', 'field_filters' => $field_filters_unapproved ] ) );
116 116
         }
117 117
 
118
-        $filter_links[] = [
118
+        $filter_links[ ] = [
119 119
             'id'            => 'gv_approved',
120 120
             'field_filters' => $field_filters_approved,
121 121
             'count'         => $approved_count,
122
-            'label'         => GravityView_Entry_Approval_Status::get_label(GravityView_Entry_Approval_Status::APPROVED),
122
+            'label'         => GravityView_Entry_Approval_Status::get_label( GravityView_Entry_Approval_Status::APPROVED ),
123 123
         ];
124 124
 
125
-        $filter_links[] = [
125
+        $filter_links[ ] = [
126 126
             'id'            => 'gv_disapproved',
127 127
             'field_filters' => $field_filters_disapproved,
128 128
             'count'         => $disapproved_count,
129
-            'label'         => GravityView_Entry_Approval_Status::get_label(GravityView_Entry_Approval_Status::DISAPPROVED),
129
+            'label'         => GravityView_Entry_Approval_Status::get_label( GravityView_Entry_Approval_Status::DISAPPROVED ),
130 130
         ];
131 131
 
132
-        $filter_links[] = [
132
+        $filter_links[ ] = [
133 133
             'id'            => 'gv_unapproved',
134 134
             'field_filters' => $field_filters_unapproved,
135 135
             'count'         => $unapproved_count,
136
-            'label'         => GravityView_Entry_Approval_Status::get_label(GravityView_Entry_Approval_Status::UNAPPROVED),
136
+            'label'         => GravityView_Entry_Approval_Status::get_label( GravityView_Entry_Approval_Status::UNAPPROVED ),
137 137
         ];
138 138
 
139 139
         return $filter_links;
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
      *
147 147
      * @return array Tooltips array with GravityView fields tooltip
148 148
      */
149
-    public function tooltips($tooltips)
149
+    public function tooltips( $tooltips )
150 150
     {
151
-        $tooltips['form_gravityview_fields'] = [
152
-            'title' => __('GravityView Fields', 'gravityview'),
153
-            'value' => __('Allow administrators to approve or reject entries and users to opt-in or opt-out of their entries being displayed.', 'gravityview'),
151
+        $tooltips[ 'form_gravityview_fields' ] = [
152
+            'title' => __( 'GravityView Fields', 'gravityview' ),
153
+            'value' => __( 'Allow administrators to approve or reject entries and users to opt-in or opt-out of their entries being displayed.', 'gravityview' ),
154 154
         ];
155 155
 
156 156
         return $tooltips;
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      *
164 164
      * @return array Array of fields
165 165
      */
166
-    public function add_field_buttons($field_groups)
166
+    public function add_field_buttons( $field_groups )
167 167
     {
168 168
         $gravityview_fields = [
169 169
             'name'   => 'gravityview_fields',
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
             'fields' => [
172 172
                 [
173 173
                     'class'     => 'button',
174
-                    'value'     => __('Approve/Reject', 'gravityview'),
174
+                    'value'     => __( 'Approve/Reject', 'gravityview' ),
175 175
                     'onclick'   => "StartAddField('gravityviewapproved_admin');",
176 176
                     'data-type' => 'gravityviewapproved_admin',
177 177
                     'data-icon' => 'dashicons-yes-alt',
178 178
                 ],
179 179
                 [
180 180
                     'class'     => 'button',
181
-                    'value'     => __('User Opt-In', 'gravityview'),
181
+                    'value'     => __( 'User Opt-In', 'gravityview' ),
182 182
                     'onclick'   => "StartAddField('gravityviewapproved');",
183 183
                     'data-type' => 'gravityviewapproved',
184 184
                     'data-icon' => 'dashicons-media-text',
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
             ],
187 187
         ];
188 188
 
189
-        array_push($field_groups, $gravityview_fields);
189
+        array_push( $field_groups, $gravityview_fields );
190 190
 
191 191
         return $field_groups;
192 192
     }
@@ -202,16 +202,16 @@  discard block
 block discarded – undo
202 202
     {
203 203
         ?>
204 204
 		case 'gravityviewapproved_admin':
205
-			field.label = "<?php echo esc_js(__('Approved? (Admin-only)', 'gravityview')); ?>";
205
+			field.label = "<?php echo esc_js( __( 'Approved? (Admin-only)', 'gravityview' ) ); ?>";
206 206
 
207
-			field.adminLabel = "<?php echo esc_js(__('Approved?', 'gravityview')); ?>";
207
+			field.adminLabel = "<?php echo esc_js( __( 'Approved?', 'gravityview' ) ); ?>";
208 208
 			field.adminOnly = true;
209 209
 
210 210
 			field.choices = null;
211 211
 			field.inputs = null;
212 212
 
213 213
 			if( !field.choices ) {
214
-				field.choices = new Array( new Choice("<?php echo esc_js(GravityView_Entry_Approval_Status::get_label(GravityView_Entry_Approval_Status::APPROVED)); ?>") );
214
+				field.choices = new Array( new Choice("<?php echo esc_js( GravityView_Entry_Approval_Status::get_label( GravityView_Entry_Approval_Status::APPROVED ) ); ?>") );
215 215
 			}
216 216
 
217 217
 			field.inputs = new Array();
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
 
225 225
 			break;
226 226
 		case 'gravityviewapproved':
227
-			field.label = "<?php echo esc_js(__('Show Entry on Website', 'gravityview')); ?>";
227
+			field.label = "<?php echo esc_js( __( 'Show Entry on Website', 'gravityview' ) ); ?>";
228 228
 
229
-			field.adminLabel = "<?php echo esc_js(__('Opt-In', 'gravityview')); ?>";
229
+			field.adminLabel = "<?php echo esc_js( __( 'Opt-In', 'gravityview' ) ); ?>";
230 230
 			field.adminOnly = false;
231 231
 
232 232
 			field.choices = null;
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 
235 235
 			if( !field.choices ) {
236 236
 				field.choices = new Array(
237
-					new Choice("<?php echo esc_js(__('Yes, display my entry on the website', 'gravityview')); ?>")
237
+					new Choice("<?php echo esc_js( __( 'Yes, display my entry on the website', 'gravityview' ) ); ?>")
238 238
 				);
239 239
 			}
240 240
 
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
      *
264 264
      * @return bool True: It worked; False: it failed
265 265
      */
266
-    public static function update_approved($entry_id = 0, $approved = 0, $form_id = 0, $approvedcolumn = 0)
266
+    public static function update_approved( $entry_id = 0, $approved = 0, $form_id = 0, $approvedcolumn = 0 )
267 267
     {
268
-        return GravityView_Entry_Approval::update_approved($entry_id, $approved, $form_id, $approvedcolumn);
268
+        return GravityView_Entry_Approval::update_approved( $entry_id, $approved, $form_id, $approvedcolumn );
269 269
     }
270 270
 
271 271
     /**
@@ -278,9 +278,9 @@  discard block
 block discarded – undo
278 278
      *
279 279
      * @return false|null|string Returns the input ID of the approved field. Returns NULL if no approved fields were found. Returns false if $form_id wasn't set.
280 280
      */
281
-    public static function get_approved_column($form)
281
+    public static function get_approved_column( $form )
282 282
     {
283
-        return GravityView_Entry_Approval::get_approved_column($form);
283
+        return GravityView_Entry_Approval::get_approved_column( $form );
284 284
     }
285 285
 
286 286
     /**
@@ -296,20 +296,20 @@  discard block
 block discarded – undo
296 296
      *
297 297
      * @return void
298 298
      */
299
-    public static function add_entry_approved_hidden_input($form_id, $field_id, $value, $entry, $query_string)
299
+    public static function add_entry_approved_hidden_input( $form_id, $field_id, $value, $entry, $query_string )
300 300
     {
301
-        if (!GVCommon::has_cap('gravityview_moderate_entries', $entry['id'])) {
301
+        if ( ! GVCommon::has_cap( 'gravityview_moderate_entries', $entry[ 'id' ] ) ) {
302 302
             return;
303 303
         }
304 304
 
305
-        if (empty($entry['id'])) {
305
+        if ( empty( $entry[ 'id' ] ) ) {
306 306
             return;
307 307
         }
308 308
 
309
-        $status_value = GravityView_Entry_Approval::get_entry_status($entry, 'value');
309
+        $status_value = GravityView_Entry_Approval::get_entry_status( $entry, 'value' );
310 310
 
311
-        if ($status_value) {
312
-            echo '<input type="hidden" class="entry_approval" id="entry_approved_'.$entry['id'].'" value="'.esc_attr($status_value).'" />';
311
+        if ( $status_value ) {
312
+            echo '<input type="hidden" class="entry_approval" id="entry_approved_' . $entry[ 'id' ] . '" value="' . esc_attr( $status_value ) . '" />';
313 313
         }
314 314
     }
315 315
 
@@ -322,14 +322,14 @@  discard block
 block discarded – undo
322 322
      */
323 323
     private function get_form_id()
324 324
     {
325
-        $form_id = GFForms::get('id');
325
+        $form_id = GFForms::get( 'id' );
326 326
 
327 327
         // If there are no forms identified, use the first form. That's how GF does it.
328
-        if (empty($form_id) && class_exists('RGFormsModel')) {
328
+        if ( empty( $form_id ) && class_exists( 'RGFormsModel' ) ) {
329 329
             $form_id = $this->get_first_form_id();
330 330
         }
331 331
 
332
-        return absint($form_id);
332
+        return absint( $form_id );
333 333
     }
334 334
 
335 335
     /**
@@ -342,71 +342,71 @@  discard block
 block discarded – undo
342 342
      */
343 343
     private function get_first_form_id()
344 344
     {
345
-        $forms = RGFormsModel::get_forms(null, 'title');
345
+        $forms = RGFormsModel::get_forms( null, 'title' );
346 346
 
347
-        if (!isset($forms[0])) {
348
-            gravityview()->log->error('No forms were found');
347
+        if ( ! isset( $forms[ 0 ] ) ) {
348
+            gravityview()->log->error( 'No forms were found' );
349 349
 
350 350
             return 0;
351 351
         }
352 352
 
353
-        $first_form = $forms[0];
353
+        $first_form = $forms[ 0 ];
354 354
 
355
-        $form_id = is_object($forms[0]) ? $first_form->id : $first_form['id'];
355
+        $form_id = is_object( $forms[ 0 ] ) ? $first_form->id : $first_form[ 'id' ];
356 356
 
357
-        return intval($form_id);
357
+        return intval( $form_id );
358 358
     }
359 359
 
360
-    public function add_scripts_and_styles($hook)
360
+    public function add_scripts_and_styles( $hook )
361 361
     {
362
-        if (!class_exists('GFForms')) {
363
-            gravityview()->log->error('GFForms does not exist.');
362
+        if ( ! class_exists( 'GFForms' ) ) {
363
+            gravityview()->log->error( 'GFForms does not exist.' );
364 364
 
365 365
             return;
366 366
         }
367 367
 
368 368
         // enqueue styles & scripts gf_entries
369 369
         // But only if we're on the main Entries page, not on reports pages
370
-        if (GFForms::get_page() !== 'entry_list') {
370
+        if ( GFForms::get_page() !== 'entry_list' ) {
371 371
             return;
372 372
         }
373 373
 
374 374
         $form_id = $this->get_form_id();
375 375
 
376 376
         // Things are broken; no forms were found
377
-        if (empty($form_id)) {
377
+        if ( empty( $form_id ) ) {
378 378
             return;
379 379
         }
380 380
 
381
-        wp_enqueue_style('gravityview_entries_list', plugins_url('assets/css/admin-entries-list.css', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
381
+        wp_enqueue_style( 'gravityview_entries_list', plugins_url( 'assets/css/admin-entries-list.css', GRAVITYVIEW_FILE ), [ ], GravityView_Plugin::version );
382 382
 
383
-        $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
383
+        $script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
384 384
 
385
-        wp_enqueue_script('gravityview_gf_entries_scripts', plugins_url('assets/js/admin-entries-list'.$script_debug.'.js', GRAVITYVIEW_FILE), ['jquery'], GravityView_Plugin::version);
385
+        wp_enqueue_script( 'gravityview_gf_entries_scripts', plugins_url( 'assets/js/admin-entries-list' . $script_debug . '.js', GRAVITYVIEW_FILE ), [ 'jquery' ], GravityView_Plugin::version );
386 386
 
387
-        wp_enqueue_script('gravityview_entries_list-popper', plugins_url('assets/lib/tippy/popper.min.js', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
388
-        wp_enqueue_script('gravityview_entries_list-tippy', plugins_url('assets/lib/tippy/tippy.min.js', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
389
-        wp_enqueue_style('gravityview_entries_list-tippy', plugins_url('assets/lib/tippy/tippy.css', GRAVITYVIEW_FILE), [], GravityView_Plugin::version);
387
+        wp_enqueue_script( 'gravityview_entries_list-popper', plugins_url( 'assets/lib/tippy/popper.min.js', GRAVITYVIEW_FILE ), [ ], GravityView_Plugin::version );
388
+        wp_enqueue_script( 'gravityview_entries_list-tippy', plugins_url( 'assets/lib/tippy/tippy.min.js', GRAVITYVIEW_FILE ), [ ], GravityView_Plugin::version );
389
+        wp_enqueue_style( 'gravityview_entries_list-tippy', plugins_url( 'assets/lib/tippy/tippy.css', GRAVITYVIEW_FILE ), [ ], GravityView_Plugin::version );
390 390
 
391
-        wp_localize_script('gravityview_gf_entries_scripts', 'gvGlobals', [
392
-            'nonce'                    => wp_create_nonce('gravityview_entry_approval'),
393
-            'admin_nonce'              => wp_create_nonce('gravityview_admin_entry_approval'),
391
+        wp_localize_script( 'gravityview_gf_entries_scripts', 'gvGlobals', [
392
+            'nonce'                    => wp_create_nonce( 'gravityview_entry_approval' ),
393
+            'admin_nonce'              => wp_create_nonce( 'gravityview_admin_entry_approval' ),
394 394
             'form_id'                  => $form_id,
395
-            'show_column'              => (int) $this->show_approve_entry_column($form_id),
396
-            'add_bulk_action'          => (int) GVCommon::has_cap('gravityview_moderate_entries'),
395
+            'show_column'              => (int)$this->show_approve_entry_column( $form_id ),
396
+            'add_bulk_action'          => (int)GVCommon::has_cap( 'gravityview_moderate_entries' ),
397 397
             'status_approved'          => GravityView_Entry_Approval_Status::APPROVED,
398 398
             'status_disapproved'       => GravityView_Entry_Approval_Status::DISAPPROVED,
399 399
             'status_unapproved'        => GravityView_Entry_Approval_Status::UNAPPROVED,
400
-            'bulk_actions'             => GravityView_Bulk_Actions::get_bulk_actions($form_id),
400
+            'bulk_actions'             => GravityView_Bulk_Actions::get_bulk_actions( $form_id ),
401 401
             'bulk_message'             => $this->bulk_update_message,
402
-            'unapprove_title'          => GravityView_Entry_Approval_Status::get_title_attr('unapproved'),
403
-            'approve_title'            => GravityView_Entry_Approval_Status::get_title_attr('disapproved'),
404
-            'disapprove_title'         => GravityView_Entry_Approval_Status::get_title_attr('approved'),
405
-            'column_title'             => __('Show entry in directory view?', 'gravityview'),
406
-            'column_link'              => esc_url($this->get_sort_link()),
402
+            'unapprove_title'          => GravityView_Entry_Approval_Status::get_title_attr( 'unapproved' ),
403
+            'approve_title'            => GravityView_Entry_Approval_Status::get_title_attr( 'disapproved' ),
404
+            'disapprove_title'         => GravityView_Entry_Approval_Status::get_title_attr( 'approved' ),
405
+            'column_title'             => __( 'Show entry in directory view?', 'gravityview' ),
406
+            'column_link'              => esc_url( $this->get_sort_link() ),
407 407
             'status_popover_template'  => GravityView_Entry_Approval::get_popover_template(),
408 408
             'status_popover_placement' => GravityView_Entry_Approval::get_popover_placement(),
409
-        ]);
409
+        ] );
410 410
     }
411 411
 
412 412
     /**
@@ -421,14 +421,14 @@  discard block
 block discarded – undo
421 421
      *
422 422
      * @return string Sorting link
423 423
      */
424
-    private function get_sort_link($form_id = 0)
424
+    private function get_sort_link( $form_id = 0 )
425 425
     {
426 426
         $args = [
427 427
             'orderby' => 'is_approved',
428
-            'order'   => ('desc' === \GV\Utils::_GET('order')) ? 'asc' : 'desc',
428
+            'order'   => ( 'desc' === \GV\Utils::_GET( 'order' ) ) ? 'asc' : 'desc',
429 429
         ];
430 430
 
431
-        return add_query_arg($args);
431
+        return add_query_arg( $args );
432 432
     }
433 433
 
434 434
     /**
@@ -440,9 +440,9 @@  discard block
 block discarded – undo
440 440
      *
441 441
      * @return bool True: Show column; False: hide column
442 442
      */
443
-    private function show_approve_entry_column($form_id)
443
+    private function show_approve_entry_column( $form_id )
444 444
     {
445
-        $show_approve_column = GVCommon::has_cap('gravityview_moderate_entries');
445
+        $show_approve_column = GVCommon::has_cap( 'gravityview_moderate_entries' );
446 446
 
447 447
         /**
448 448
          * @filter `gravityview/approve_entries/hide-if-no-connections` Return true to hide reject/approve if there are no connected Views
@@ -451,12 +451,12 @@  discard block
 block discarded – undo
451 451
          *
452 452
          * @param bool $hide_if_no_connections
453 453
          */
454
-        $hide_if_no_connections = apply_filters('gravityview/approve_entries/hide-if-no-connections', false);
454
+        $hide_if_no_connections = apply_filters( 'gravityview/approve_entries/hide-if-no-connections', false );
455 455
 
456
-        if ($hide_if_no_connections) {
457
-            $connected_views = gravityview_get_connected_views($form_id);
456
+        if ( $hide_if_no_connections ) {
457
+            $connected_views = gravityview_get_connected_views( $form_id );
458 458
 
459
-            if (empty($connected_views)) {
459
+            if ( empty( $connected_views ) ) {
460 460
                 $show_approve_column = false;
461 461
             }
462 462
         }
@@ -467,24 +467,24 @@  discard block
 block discarded – undo
467 467
          * @param bool $show_approve_column Whether the column will be shown
468 468
          * @param int  $form_id             The ID of the Gravity Forms form for which entries are being shown
469 469
          */
470
-        $show_approve_column = apply_filters('gravityview/approve_entries/show-column', $show_approve_column, $form_id);
470
+        $show_approve_column = apply_filters( 'gravityview/approve_entries/show-column', $show_approve_column, $form_id );
471 471
 
472 472
         return $show_approve_column;
473 473
     }
474 474
 
475
-    public function register_gform_noconflict_script($scripts)
475
+    public function register_gform_noconflict_script( $scripts )
476 476
     {
477
-        $scripts[] = 'gravityview_gf_entries_scripts';
478
-        $scripts[] = 'gravityview_entries_list-popper';
479
-        $scripts[] = 'gravityview_entries_list-tippy';
477
+        $scripts[ ] = 'gravityview_gf_entries_scripts';
478
+        $scripts[ ] = 'gravityview_entries_list-popper';
479
+        $scripts[ ] = 'gravityview_entries_list-tippy';
480 480
 
481 481
         return $scripts;
482 482
     }
483 483
 
484
-    public function register_gform_noconflict_style($styles)
484
+    public function register_gform_noconflict_style( $styles )
485 485
     {
486
-        $styles[] = 'gravityview_entries_list';
487
-        $styles[] = 'gravityview_entries_list-tippy';
486
+        $styles[ ] = 'gravityview_entries_list';
487
+        $styles[ ] = 'gravityview_entries_list-tippy';
488 488
 
489 489
         return $styles;
490 490
     }
Please login to merge, or discard this patch.
Braces   +17 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,8 +11,7 @@  discard block
 block discarded – undo
11 11
  *
12 12
  * @since 1.0.0
13 13
  */
14
-class GravityView_Admin_ApproveEntries
15
-{
14
+class GravityView_Admin_ApproveEntries {
16 15
     // hold notification messages
17 16
     public $bulk_update_message = '';
18 17
 
@@ -27,13 +26,11 @@  discard block
 block discarded – undo
27 26
         'unapprove'  => 'gvunapprove',
28 27
     ];
29 28
 
30
-    public function __construct()
31
-    {
29
+    public function __construct() {
32 30
         $this->add_hooks();
33 31
     }
34 32
 
35
-    private function add_hooks()
36
-    {
33
+    private function add_hooks() {
37 34
         /** Edit Gravity Form page */
38 35
 
39 36
         // Add button to left menu
@@ -70,8 +67,7 @@  discard block
 block discarded – undo
70 67
      *
71 68
      * @return array Filter links, with GravityView approved/disapproved links added
72 69
      */
73
-    public function filter_links_entry_list($filter_links = [], $form = [], $include_counts = true)
74
-    {
70
+    public function filter_links_entry_list($filter_links = [], $form = [], $include_counts = true) {
75 71
 
76 72
         /**
77 73
          * @filter `gravityview/approve_entries/show_filter_links_entry_list` Disable filter links
@@ -146,8 +142,7 @@  discard block
 block discarded – undo
146 142
      *
147 143
      * @return array Tooltips array with GravityView fields tooltip
148 144
      */
149
-    public function tooltips($tooltips)
150
-    {
145
+    public function tooltips($tooltips) {
151 146
         $tooltips['form_gravityview_fields'] = [
152 147
             'title' => __('GravityView Fields', 'gravityview'),
153 148
             'value' => __('Allow administrators to approve or reject entries and users to opt-in or opt-out of their entries being displayed.', 'gravityview'),
@@ -163,8 +158,7 @@  discard block
 block discarded – undo
163 158
      *
164 159
      * @return array Array of fields
165 160
      */
166
-    public function add_field_buttons($field_groups)
167
-    {
161
+    public function add_field_buttons($field_groups) {
168 162
         $gravityview_fields = [
169 163
             'name'   => 'gravityview_fields',
170 164
             'label'  => 'GravityView',
@@ -198,8 +192,7 @@  discard block
 block discarded – undo
198 192
      *
199 193
      * @return void
200 194
      */
201
-    public function set_defaults()
202
-    {
195
+    public function set_defaults() {
203 196
         ?>
204 197
 		case 'gravityviewapproved_admin':
205 198
 			field.label = "<?php echo esc_js(__('Approved? (Admin-only)', 'gravityview')); ?>";
@@ -263,8 +256,7 @@  discard block
 block discarded – undo
263 256
      *
264 257
      * @return bool True: It worked; False: it failed
265 258
      */
266
-    public static function update_approved($entry_id = 0, $approved = 0, $form_id = 0, $approvedcolumn = 0)
267
-    {
259
+    public static function update_approved($entry_id = 0, $approved = 0, $form_id = 0, $approvedcolumn = 0) {
268 260
         return GravityView_Entry_Approval::update_approved($entry_id, $approved, $form_id, $approvedcolumn);
269 261
     }
270 262
 
@@ -278,8 +270,7 @@  discard block
 block discarded – undo
278 270
      *
279 271
      * @return false|null|string Returns the input ID of the approved field. Returns NULL if no approved fields were found. Returns false if $form_id wasn't set.
280 272
      */
281
-    public static function get_approved_column($form)
282
-    {
273
+    public static function get_approved_column($form) {
283 274
         return GravityView_Entry_Approval::get_approved_column($form);
284 275
     }
285 276
 
@@ -296,8 +287,7 @@  discard block
 block discarded – undo
296 287
      *
297 288
      * @return void
298 289
      */
299
-    public static function add_entry_approved_hidden_input($form_id, $field_id, $value, $entry, $query_string)
300
-    {
290
+    public static function add_entry_approved_hidden_input($form_id, $field_id, $value, $entry, $query_string) {
301 291
         if (!GVCommon::has_cap('gravityview_moderate_entries', $entry['id'])) {
302 292
             return;
303 293
         }
@@ -320,8 +310,7 @@  discard block
 block discarded – undo
320 310
      *
321 311
      * @return int ID of the current form being displayed. `0` is returned if no forms are found.
322 312
      */
323
-    private function get_form_id()
324
-    {
313
+    private function get_form_id() {
325 314
         $form_id = GFForms::get('id');
326 315
 
327 316
         // If there are no forms identified, use the first form. That's how GF does it.
@@ -340,8 +329,7 @@  discard block
 block discarded – undo
340 329
      *
341 330
      * @return int ID of the first form, sorted by title. `0` if no forms were found.
342 331
      */
343
-    private function get_first_form_id()
344
-    {
332
+    private function get_first_form_id() {
345 333
         $forms = RGFormsModel::get_forms(null, 'title');
346 334
 
347 335
         if (!isset($forms[0])) {
@@ -357,8 +345,7 @@  discard block
 block discarded – undo
357 345
         return intval($form_id);
358 346
     }
359 347
 
360
-    public function add_scripts_and_styles($hook)
361
-    {
348
+    public function add_scripts_and_styles($hook) {
362 349
         if (!class_exists('GFForms')) {
363 350
             gravityview()->log->error('GFForms does not exist.');
364 351
 
@@ -421,8 +408,7 @@  discard block
 block discarded – undo
421 408
      *
422 409
      * @return string Sorting link
423 410
      */
424
-    private function get_sort_link($form_id = 0)
425
-    {
411
+    private function get_sort_link($form_id = 0) {
426 412
         $args = [
427 413
             'orderby' => 'is_approved',
428 414
             'order'   => ('desc' === \GV\Utils::_GET('order')) ? 'asc' : 'desc',
@@ -440,8 +426,7 @@  discard block
 block discarded – undo
440 426
      *
441 427
      * @return bool True: Show column; False: hide column
442 428
      */
443
-    private function show_approve_entry_column($form_id)
444
-    {
429
+    private function show_approve_entry_column($form_id) {
445 430
         $show_approve_column = GVCommon::has_cap('gravityview_moderate_entries');
446 431
 
447 432
         /**
@@ -472,8 +457,7 @@  discard block
 block discarded – undo
472 457
         return $show_approve_column;
473 458
     }
474 459
 
475
-    public function register_gform_noconflict_script($scripts)
476
-    {
460
+    public function register_gform_noconflict_script($scripts) {
477 461
         $scripts[] = 'gravityview_gf_entries_scripts';
478 462
         $scripts[] = 'gravityview_entries_list-popper';
479 463
         $scripts[] = 'gravityview_entries_list-tippy';
@@ -481,8 +465,7 @@  discard block
 block discarded – undo
481 465
         return $scripts;
482 466
     }
483 467
 
484
-    public function register_gform_noconflict_style($styles)
485
-    {
468
+    public function register_gform_noconflict_style($styles) {
486 469
         $styles[] = 'gravityview_entries_list';
487 470
         $styles[] = 'gravityview_entries_list-tippy';
488 471
 
Please login to merge, or discard this patch.
includes/class-gravityview-admin-bar.php 3 patches
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -7,70 +7,70 @@  discard block
 block discarded – undo
7 7
  */
8 8
 class GravityView_Admin_Bar
9 9
 {
10
-    /**
11
-     * @var GravityView_frontend|null
12
-     */
13
-    public $gravityview_view = null;
14
-
15
-    public function __construct()
16
-    {
17
-        $this->gravityview_view = GravityView_frontend::getInstance();
18
-
19
-        $this->add_hooks();
20
-    }
21
-
22
-    /**
23
-     * @since 1.13
24
-     */
25
-    private function add_hooks()
26
-    {
27
-        add_action('add_admin_bar_menus', [$this, 'remove_links'], 80);
28
-        add_action('admin_bar_menu', [$this, 'add_links'], 85);
29
-        add_action('wp_after_admin_bar_render', [$this, 'add_floaty_icon']);
30
-    }
31
-
32
-    /**
33
-     * Add helpful GV links to the menu bar, like Edit Entry on single entry page.
34
-     *
35
-     * @since 1.13
36
-     *
37
-     * @return void
38
-     */
39
-    public function add_links()
40
-    {
41
-        /** @var WP_Admin_Bar $wp_admin_bar */
42
-        global $wp_admin_bar;
43
-
44
-        if (is_admin() || !GVCommon::has_cap(['edit_gravityviews', 'gravityview_edit_entry', 'gravityforms_edit_forms'])) {
45
-            return;
46
-        }
47
-
48
-        $view_data = GravityView_View_Data::getInstance()->get_views();
49
-        if (empty($view_data)) {
50
-            return;
51
-        }
52
-
53
-        $wp_admin_bar->add_menu([
54
-            'id'    => 'gravityview',
55
-            'title' => __('GravityView', 'gravityview'),
56
-            'href'  => admin_url('edit.php?post_type=gravityview&page=gravityview_settings'),
57
-        ]);
58
-
59
-        $this->add_edit_view_and_form_link();
60
-
61
-        $this->add_edit_entry_link();
62
-    }
63
-
64
-    /**
65
-     * Add the Floaty icon to the toolbar without loading the whole icon font.
66
-     *
67
-     * @since 1.17
68
-     *
69
-     * @return void
70
-     */
71
-    public function add_floaty_icon()
72
-    {
73
-        ?>
10
+	/**
11
+	 * @var GravityView_frontend|null
12
+	 */
13
+	public $gravityview_view = null;
14
+
15
+	public function __construct()
16
+	{
17
+		$this->gravityview_view = GravityView_frontend::getInstance();
18
+
19
+		$this->add_hooks();
20
+	}
21
+
22
+	/**
23
+	 * @since 1.13
24
+	 */
25
+	private function add_hooks()
26
+	{
27
+		add_action('add_admin_bar_menus', [$this, 'remove_links'], 80);
28
+		add_action('admin_bar_menu', [$this, 'add_links'], 85);
29
+		add_action('wp_after_admin_bar_render', [$this, 'add_floaty_icon']);
30
+	}
31
+
32
+	/**
33
+	 * Add helpful GV links to the menu bar, like Edit Entry on single entry page.
34
+	 *
35
+	 * @since 1.13
36
+	 *
37
+	 * @return void
38
+	 */
39
+	public function add_links()
40
+	{
41
+		/** @var WP_Admin_Bar $wp_admin_bar */
42
+		global $wp_admin_bar;
43
+
44
+		if (is_admin() || !GVCommon::has_cap(['edit_gravityviews', 'gravityview_edit_entry', 'gravityforms_edit_forms'])) {
45
+			return;
46
+		}
47
+
48
+		$view_data = GravityView_View_Data::getInstance()->get_views();
49
+		if (empty($view_data)) {
50
+			return;
51
+		}
52
+
53
+		$wp_admin_bar->add_menu([
54
+			'id'    => 'gravityview',
55
+			'title' => __('GravityView', 'gravityview'),
56
+			'href'  => admin_url('edit.php?post_type=gravityview&page=gravityview_settings'),
57
+		]);
58
+
59
+		$this->add_edit_view_and_form_link();
60
+
61
+		$this->add_edit_entry_link();
62
+	}
63
+
64
+	/**
65
+	 * Add the Floaty icon to the toolbar without loading the whole icon font.
66
+	 *
67
+	 * @since 1.17
68
+	 *
69
+	 * @return void
70
+	 */
71
+	public function add_floaty_icon()
72
+	{
73
+		?>
74 74
 		<style>
75 75
 			#wp-admin-bar-gravityview > .ab-item:before {
76 76
 				content: '';
@@ -83,111 +83,111 @@  discard block
 block discarded – undo
83 83
 			}
84 84
 		</style>
85 85
 		<?php
86
-    }
87
-
88
-    /**
89
-     * Add Edit Entry links when on a single entry.
90
-     *
91
-     * @since 1.13
92
-     *
93
-     * @return void
94
-     */
95
-    public function add_edit_entry_link()
96
-    {
97
-        /** @var WP_Admin_Bar $wp_admin_bar */
98
-        global $wp_admin_bar;
99
-
100
-        $entry = gravityview()->request->is_entry();
101
-
102
-        if ($entry && GVCommon::has_cap(['gravityforms_edit_entries', 'gravityview_edit_entries'], $entry->ID)) {
103
-            $wp_admin_bar->add_menu([
104
-                'id'     => 'edit-entry',
105
-                'parent' => 'gravityview',
106
-                'title'  => __('Edit Entry', 'gravityview'),
107
-                'meta'   => [
108
-                    'title' => sprintf(__('Edit Entry %s', 'gravityview'), $entry->get_slug()),
109
-                ],
110
-                'href' => esc_url_raw(admin_url(sprintf('admin.php?page=gf_entries&amp;screen_mode=edit&amp;view=entry&amp;id=%d&lid=%d', $entry['form_id'], $entry['id']))),
111
-            ]);
112
-        }
113
-    }
114
-
115
-    /**
116
-     * Add Edit View link when in embedded View.
117
-     *
118
-     * @since 1.13
119
-     *
120
-     * @return void
121
-     */
122
-    public function add_edit_view_and_form_link()
123
-    {
124
-        /** @var WP_Admin_Bar $wp_admin_bar */
125
-        global $wp_admin_bar;
126
-
127
-        if (GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview', 'gravityforms_edit_forms'])) {
128
-            $view_data = GravityView_View_Data::getInstance();
129
-            $views = $view_data->get_views();
130
-
131
-            // If there is a View embed, show Edit View link.
132
-            if (!empty($views)) {
133
-                $added_forms = [];
134
-                $added_views = [];
135
-
136
-                foreach ($views as $view) {
137
-                    $view = \GV\View::by_id($view['id']);
138
-                    $view_id = $view->ID;
139
-                    $form_id = $view->form ? $view->form->ID : null;
140
-
141
-                    $edit_view_title = __('Edit View', 'gravityview');
142
-                    $edit_form_title = __('Edit Form', 'gravityview');
143
-
144
-                    if (sizeof($views) > 1) {
145
-                        $edit_view_title = sprintf(_x('Edit View #%d', 'Edit View with the ID of %d', 'gravityview'), $view_id);
146
-                        $edit_form_title = sprintf(__('Edit Form #%d', 'Edit Form with the ID of %d', 'gravityview'), $form_id);
147
-                    }
148
-
149
-                    if (GVCommon::has_cap('edit_gravityview', $view_id) && !in_array($view_id, $added_views)) {
150
-                        $added_views[] = $view_id;
151
-
152
-                        $wp_admin_bar->add_menu([
153
-                            'id'     => 'edit-view-'.$view_id,
154
-                            'parent' => 'gravityview',
155
-                            'title'  => $edit_view_title,
156
-                            'href'   => esc_url_raw(admin_url(sprintf('post.php?post=%d&action=edit', $view_id))),
157
-                        ]);
158
-                    }
159
-
160
-                    if (!empty($form_id) && GVCommon::has_cap(['gravityforms_edit_forms'], $form_id) && !in_array($form_id, $added_forms)) {
161
-                        $added_forms[] = $form_id;
162
-
163
-                        $wp_admin_bar->add_menu([
164
-                            'id'     => 'edit-form-'.$form_id,
165
-                            'parent' => 'gravityview',
166
-                            'title'  => $edit_form_title,
167
-                            'href'   => esc_url_raw(admin_url(sprintf('admin.php?page=gf_edit_forms&id=%d', $form_id))),
168
-                        ]);
169
-                    }
170
-                }
171
-            }
172
-        }
173
-    }
174
-
175
-    /**
176
-     * Remove "Edit Page" or "Edit View" links when on single entry.
177
-     *
178
-     * @since 1.17 Also remove when on GravityView post type; the new GravityView menu will be the one-stop shop.
179
-     * @since 1.13
180
-     *
181
-     * @return void
182
-     */
183
-    public function remove_links()
184
-    {
185
-
186
-        // If we're on the single entry page, we don't want to cause confusion.
187
-        if ($this->gravityview_view->getSingleEntry() || $this->gravityview_view->isGravityviewPostType()) {
188
-            remove_action('admin_bar_menu', 'wp_admin_bar_edit_menu', 80);
189
-        }
190
-    }
86
+	}
87
+
88
+	/**
89
+	 * Add Edit Entry links when on a single entry.
90
+	 *
91
+	 * @since 1.13
92
+	 *
93
+	 * @return void
94
+	 */
95
+	public function add_edit_entry_link()
96
+	{
97
+		/** @var WP_Admin_Bar $wp_admin_bar */
98
+		global $wp_admin_bar;
99
+
100
+		$entry = gravityview()->request->is_entry();
101
+
102
+		if ($entry && GVCommon::has_cap(['gravityforms_edit_entries', 'gravityview_edit_entries'], $entry->ID)) {
103
+			$wp_admin_bar->add_menu([
104
+				'id'     => 'edit-entry',
105
+				'parent' => 'gravityview',
106
+				'title'  => __('Edit Entry', 'gravityview'),
107
+				'meta'   => [
108
+					'title' => sprintf(__('Edit Entry %s', 'gravityview'), $entry->get_slug()),
109
+				],
110
+				'href' => esc_url_raw(admin_url(sprintf('admin.php?page=gf_entries&amp;screen_mode=edit&amp;view=entry&amp;id=%d&lid=%d', $entry['form_id'], $entry['id']))),
111
+			]);
112
+		}
113
+	}
114
+
115
+	/**
116
+	 * Add Edit View link when in embedded View.
117
+	 *
118
+	 * @since 1.13
119
+	 *
120
+	 * @return void
121
+	 */
122
+	public function add_edit_view_and_form_link()
123
+	{
124
+		/** @var WP_Admin_Bar $wp_admin_bar */
125
+		global $wp_admin_bar;
126
+
127
+		if (GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview', 'gravityforms_edit_forms'])) {
128
+			$view_data = GravityView_View_Data::getInstance();
129
+			$views = $view_data->get_views();
130
+
131
+			// If there is a View embed, show Edit View link.
132
+			if (!empty($views)) {
133
+				$added_forms = [];
134
+				$added_views = [];
135
+
136
+				foreach ($views as $view) {
137
+					$view = \GV\View::by_id($view['id']);
138
+					$view_id = $view->ID;
139
+					$form_id = $view->form ? $view->form->ID : null;
140
+
141
+					$edit_view_title = __('Edit View', 'gravityview');
142
+					$edit_form_title = __('Edit Form', 'gravityview');
143
+
144
+					if (sizeof($views) > 1) {
145
+						$edit_view_title = sprintf(_x('Edit View #%d', 'Edit View with the ID of %d', 'gravityview'), $view_id);
146
+						$edit_form_title = sprintf(__('Edit Form #%d', 'Edit Form with the ID of %d', 'gravityview'), $form_id);
147
+					}
148
+
149
+					if (GVCommon::has_cap('edit_gravityview', $view_id) && !in_array($view_id, $added_views)) {
150
+						$added_views[] = $view_id;
151
+
152
+						$wp_admin_bar->add_menu([
153
+							'id'     => 'edit-view-'.$view_id,
154
+							'parent' => 'gravityview',
155
+							'title'  => $edit_view_title,
156
+							'href'   => esc_url_raw(admin_url(sprintf('post.php?post=%d&action=edit', $view_id))),
157
+						]);
158
+					}
159
+
160
+					if (!empty($form_id) && GVCommon::has_cap(['gravityforms_edit_forms'], $form_id) && !in_array($form_id, $added_forms)) {
161
+						$added_forms[] = $form_id;
162
+
163
+						$wp_admin_bar->add_menu([
164
+							'id'     => 'edit-form-'.$form_id,
165
+							'parent' => 'gravityview',
166
+							'title'  => $edit_form_title,
167
+							'href'   => esc_url_raw(admin_url(sprintf('admin.php?page=gf_edit_forms&id=%d', $form_id))),
168
+						]);
169
+					}
170
+				}
171
+			}
172
+		}
173
+	}
174
+
175
+	/**
176
+	 * Remove "Edit Page" or "Edit View" links when on single entry.
177
+	 *
178
+	 * @since 1.17 Also remove when on GravityView post type; the new GravityView menu will be the one-stop shop.
179
+	 * @since 1.13
180
+	 *
181
+	 * @return void
182
+	 */
183
+	public function remove_links()
184
+	{
185
+
186
+		// If we're on the single entry page, we don't want to cause confusion.
187
+		if ($this->gravityview_view->getSingleEntry() || $this->gravityview_view->isGravityviewPostType()) {
188
+			remove_action('admin_bar_menu', 'wp_admin_bar_edit_menu', 80);
189
+		}
190
+	}
191 191
 }
192 192
 
193 193
 new GravityView_Admin_Bar();
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
      */
25 25
     private function add_hooks()
26 26
     {
27
-        add_action('add_admin_bar_menus', [$this, 'remove_links'], 80);
28
-        add_action('admin_bar_menu', [$this, 'add_links'], 85);
29
-        add_action('wp_after_admin_bar_render', [$this, 'add_floaty_icon']);
27
+        add_action( 'add_admin_bar_menus', [ $this, 'remove_links' ], 80 );
28
+        add_action( 'admin_bar_menu', [ $this, 'add_links' ], 85 );
29
+        add_action( 'wp_after_admin_bar_render', [ $this, 'add_floaty_icon' ] );
30 30
     }
31 31
 
32 32
     /**
@@ -41,20 +41,20 @@  discard block
 block discarded – undo
41 41
         /** @var WP_Admin_Bar $wp_admin_bar */
42 42
         global $wp_admin_bar;
43 43
 
44
-        if (is_admin() || !GVCommon::has_cap(['edit_gravityviews', 'gravityview_edit_entry', 'gravityforms_edit_forms'])) {
44
+        if ( is_admin() || ! GVCommon::has_cap( [ 'edit_gravityviews', 'gravityview_edit_entry', 'gravityforms_edit_forms' ] ) ) {
45 45
             return;
46 46
         }
47 47
 
48 48
         $view_data = GravityView_View_Data::getInstance()->get_views();
49
-        if (empty($view_data)) {
49
+        if ( empty( $view_data ) ) {
50 50
             return;
51 51
         }
52 52
 
53
-        $wp_admin_bar->add_menu([
53
+        $wp_admin_bar->add_menu( [
54 54
             'id'    => 'gravityview',
55
-            'title' => __('GravityView', 'gravityview'),
56
-            'href'  => admin_url('edit.php?post_type=gravityview&page=gravityview_settings'),
57
-        ]);
55
+            'title' => __( 'GravityView', 'gravityview' ),
56
+            'href'  => admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ),
57
+        ] );
58 58
 
59 59
         $this->add_edit_view_and_form_link();
60 60
 
@@ -99,16 +99,16 @@  discard block
 block discarded – undo
99 99
 
100 100
         $entry = gravityview()->request->is_entry();
101 101
 
102
-        if ($entry && GVCommon::has_cap(['gravityforms_edit_entries', 'gravityview_edit_entries'], $entry->ID)) {
103
-            $wp_admin_bar->add_menu([
102
+        if ( $entry && GVCommon::has_cap( [ 'gravityforms_edit_entries', 'gravityview_edit_entries' ], $entry->ID ) ) {
103
+            $wp_admin_bar->add_menu( [
104 104
                 'id'     => 'edit-entry',
105 105
                 'parent' => 'gravityview',
106
-                'title'  => __('Edit Entry', 'gravityview'),
106
+                'title'  => __( 'Edit Entry', 'gravityview' ),
107 107
                 'meta'   => [
108
-                    'title' => sprintf(__('Edit Entry %s', 'gravityview'), $entry->get_slug()),
108
+                    'title' => sprintf( __( 'Edit Entry %s', 'gravityview' ), $entry->get_slug() ),
109 109
                 ],
110
-                'href' => esc_url_raw(admin_url(sprintf('admin.php?page=gf_entries&amp;screen_mode=edit&amp;view=entry&amp;id=%d&lid=%d', $entry['form_id'], $entry['id']))),
111
-            ]);
110
+                'href' => esc_url_raw( admin_url( sprintf( 'admin.php?page=gf_entries&amp;screen_mode=edit&amp;view=entry&amp;id=%d&lid=%d', $entry[ 'form_id' ], $entry[ 'id' ] ) ) ),
111
+            ] );
112 112
         }
113 113
     }
114 114
 
@@ -124,48 +124,48 @@  discard block
 block discarded – undo
124 124
         /** @var WP_Admin_Bar $wp_admin_bar */
125 125
         global $wp_admin_bar;
126 126
 
127
-        if (GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview', 'gravityforms_edit_forms'])) {
127
+        if ( GVCommon::has_cap( [ 'edit_gravityviews', 'edit_gravityview', 'gravityforms_edit_forms' ] ) ) {
128 128
             $view_data = GravityView_View_Data::getInstance();
129 129
             $views = $view_data->get_views();
130 130
 
131 131
             // If there is a View embed, show Edit View link.
132
-            if (!empty($views)) {
133
-                $added_forms = [];
134
-                $added_views = [];
132
+            if ( ! empty( $views ) ) {
133
+                $added_forms = [ ];
134
+                $added_views = [ ];
135 135
 
136
-                foreach ($views as $view) {
137
-                    $view = \GV\View::by_id($view['id']);
136
+                foreach ( $views as $view ) {
137
+                    $view = \GV\View::by_id( $view[ 'id' ] );
138 138
                     $view_id = $view->ID;
139 139
                     $form_id = $view->form ? $view->form->ID : null;
140 140
 
141
-                    $edit_view_title = __('Edit View', 'gravityview');
142
-                    $edit_form_title = __('Edit Form', 'gravityview');
141
+                    $edit_view_title = __( 'Edit View', 'gravityview' );
142
+                    $edit_form_title = __( 'Edit Form', 'gravityview' );
143 143
 
144
-                    if (sizeof($views) > 1) {
145
-                        $edit_view_title = sprintf(_x('Edit View #%d', 'Edit View with the ID of %d', 'gravityview'), $view_id);
146
-                        $edit_form_title = sprintf(__('Edit Form #%d', 'Edit Form with the ID of %d', 'gravityview'), $form_id);
144
+                    if ( sizeof( $views ) > 1 ) {
145
+                        $edit_view_title = sprintf( _x( 'Edit View #%d', 'Edit View with the ID of %d', 'gravityview' ), $view_id );
146
+                        $edit_form_title = sprintf( __( 'Edit Form #%d', 'Edit Form with the ID of %d', 'gravityview' ), $form_id );
147 147
                     }
148 148
 
149
-                    if (GVCommon::has_cap('edit_gravityview', $view_id) && !in_array($view_id, $added_views)) {
150
-                        $added_views[] = $view_id;
149
+                    if ( GVCommon::has_cap( 'edit_gravityview', $view_id ) && ! in_array( $view_id, $added_views ) ) {
150
+                        $added_views[ ] = $view_id;
151 151
 
152
-                        $wp_admin_bar->add_menu([
153
-                            'id'     => 'edit-view-'.$view_id,
152
+                        $wp_admin_bar->add_menu( [
153
+                            'id'     => 'edit-view-' . $view_id,
154 154
                             'parent' => 'gravityview',
155 155
                             'title'  => $edit_view_title,
156
-                            'href'   => esc_url_raw(admin_url(sprintf('post.php?post=%d&action=edit', $view_id))),
157
-                        ]);
156
+                            'href'   => esc_url_raw( admin_url( sprintf( 'post.php?post=%d&action=edit', $view_id ) ) ),
157
+                        ] );
158 158
                     }
159 159
 
160
-                    if (!empty($form_id) && GVCommon::has_cap(['gravityforms_edit_forms'], $form_id) && !in_array($form_id, $added_forms)) {
161
-                        $added_forms[] = $form_id;
160
+                    if ( ! empty( $form_id ) && GVCommon::has_cap( [ 'gravityforms_edit_forms' ], $form_id ) && ! in_array( $form_id, $added_forms ) ) {
161
+                        $added_forms[ ] = $form_id;
162 162
 
163
-                        $wp_admin_bar->add_menu([
164
-                            'id'     => 'edit-form-'.$form_id,
163
+                        $wp_admin_bar->add_menu( [
164
+                            'id'     => 'edit-form-' . $form_id,
165 165
                             'parent' => 'gravityview',
166 166
                             'title'  => $edit_form_title,
167
-                            'href'   => esc_url_raw(admin_url(sprintf('admin.php?page=gf_edit_forms&id=%d', $form_id))),
168
-                        ]);
167
+                            'href'   => esc_url_raw( admin_url( sprintf( 'admin.php?page=gf_edit_forms&id=%d', $form_id ) ) ),
168
+                        ] );
169 169
                     }
170 170
                 }
171 171
             }
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
     {
185 185
 
186 186
         // If we're on the single entry page, we don't want to cause confusion.
187
-        if ($this->gravityview_view->getSingleEntry() || $this->gravityview_view->isGravityviewPostType()) {
188
-            remove_action('admin_bar_menu', 'wp_admin_bar_edit_menu', 80);
187
+        if ( $this->gravityview_view->getSingleEntry() || $this->gravityview_view->isGravityviewPostType() ) {
188
+            remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 80 );
189 189
         }
190 190
     }
191 191
 }
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -5,15 +5,13 @@  discard block
 block discarded – undo
5 5
  *
6 6
  * @since 1.13
7 7
  */
8
-class GravityView_Admin_Bar
9
-{
8
+class GravityView_Admin_Bar {
10 9
     /**
11 10
      * @var GravityView_frontend|null
12 11
      */
13 12
     public $gravityview_view = null;
14 13
 
15
-    public function __construct()
16
-    {
14
+    public function __construct() {
17 15
         $this->gravityview_view = GravityView_frontend::getInstance();
18 16
 
19 17
         $this->add_hooks();
@@ -22,8 +20,7 @@  discard block
 block discarded – undo
22 20
     /**
23 21
      * @since 1.13
24 22
      */
25
-    private function add_hooks()
26
-    {
23
+    private function add_hooks() {
27 24
         add_action('add_admin_bar_menus', [$this, 'remove_links'], 80);
28 25
         add_action('admin_bar_menu', [$this, 'add_links'], 85);
29 26
         add_action('wp_after_admin_bar_render', [$this, 'add_floaty_icon']);
@@ -36,8 +33,7 @@  discard block
 block discarded – undo
36 33
      *
37 34
      * @return void
38 35
      */
39
-    public function add_links()
40
-    {
36
+    public function add_links() {
41 37
         /** @var WP_Admin_Bar $wp_admin_bar */
42 38
         global $wp_admin_bar;
43 39
 
@@ -68,8 +64,7 @@  discard block
 block discarded – undo
68 64
      *
69 65
      * @return void
70 66
      */
71
-    public function add_floaty_icon()
72
-    {
67
+    public function add_floaty_icon() {
73 68
         ?>
74 69
 		<style>
75 70
 			#wp-admin-bar-gravityview > .ab-item:before {
@@ -92,8 +87,7 @@  discard block
 block discarded – undo
92 87
      *
93 88
      * @return void
94 89
      */
95
-    public function add_edit_entry_link()
96
-    {
90
+    public function add_edit_entry_link() {
97 91
         /** @var WP_Admin_Bar $wp_admin_bar */
98 92
         global $wp_admin_bar;
99 93
 
@@ -119,8 +113,7 @@  discard block
 block discarded – undo
119 113
      *
120 114
      * @return void
121 115
      */
122
-    public function add_edit_view_and_form_link()
123
-    {
116
+    public function add_edit_view_and_form_link() {
124 117
         /** @var WP_Admin_Bar $wp_admin_bar */
125 118
         global $wp_admin_bar;
126 119
 
@@ -180,8 +173,7 @@  discard block
 block discarded – undo
180 173
      *
181 174
      * @return void
182 175
      */
183
-    public function remove_links()
184
-    {
176
+    public function remove_links() {
185 177
 
186 178
         // If we're on the single entry page, we don't want to cause confusion.
187 179
         if ($this->gravityview_view->getSingleEntry() || $this->gravityview_view->isGravityviewPostType()) {
Please login to merge, or discard this patch.
includes/default-widgets.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,4 +4,4 @@
 block discarded – undo
4 4
  *
5 5
  * @deprecated 1.7.5
6 6
  */
7
-include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget.php';
7
+include_once GRAVITYVIEW_DIR . 'includes/widgets/class-gravityview-widget.php';
Please login to merge, or discard this patch.
includes/class-template.php 3 patches
Indentation   +999 added lines, -999 removed lines patch added patch discarded remove patch
@@ -14,1021 +14,1021 @@
 block discarded – undo
14 14
 
15 15
 /** If this file is called directly, abort. */
16 16
 if (!defined('ABSPATH')) {
17
-    exit;
17
+	exit;
18 18
 }
19 19
 
20 20
 if (!class_exists('\GV\Gamajo_Template_Loader')) {
21
-    require GRAVITYVIEW_DIR.'future/lib/class-gamajo-template-loader.php';
21
+	require GRAVITYVIEW_DIR.'future/lib/class-gamajo-template-loader.php';
22 22
 }
23 23
 
24 24
 class GravityView_View extends \GV\Gamajo_Template_Loader
25 25
 {
26
-    /**
27
-     * Prefix for filter names.
28
-     *
29
-     * @var string
30
-     */
31
-    protected $filter_prefix = 'gravityview';
32
-
33
-    /**
34
-     * Directory name where custom templates for this plugin should be found in the theme.
35
-     *
36
-     * @var string
37
-     */
38
-    protected $theme_template_directory = 'gravityview';
39
-
40
-    /**
41
-     * Reference to the root directory path of this plugin.
42
-     *
43
-     * @var string
44
-     */
45
-    protected $plugin_directory = GRAVITYVIEW_DIR;
46
-
47
-    /**
48
-     * Store templates locations that have already been located.
49
-     *
50
-     * @var array
51
-     */
52
-    protected $located_templates = [];
53
-
54
-    /**
55
-     * The name of the template, like "list", "table", or "datatables".
56
-     *
57
-     * @var string
58
-     */
59
-    protected $template_part_slug = '';
60
-
61
-    /**
62
-     * The name of the file part, like "body" or "single".
63
-     *
64
-     * @var string
65
-     */
66
-    protected $template_part_name = '';
67
-
68
-    /**
69
-     * @var int Gravity Forms form ID
70
-     */
71
-    protected $form_id = null;
72
-
73
-    /**
74
-     * @var int View ID
75
-     * @todo: this needs to be public until extensions support 1.7+
76
-     */
77
-    public $view_id = null;
78
-
79
-    /**
80
-     * @var array Fields for the form
81
-     */
82
-    protected $fields = [];
83
-
84
-    /**
85
-     * @var string Current screen. Defaults to "directory" or "single"
86
-     */
87
-    protected $context = 'directory';
88
-
89
-    /**
90
-     * @var int|null If in embedded post or page, the ID of it
91
-     */
92
-    protected $post_id = null;
93
-
94
-    /**
95
-     * @var array Gravity Forms form array at ID_id
96
-     */
97
-    protected $form = null;
98
-
99
-    /**
100
-     * @var array Configuration for the View
101
-     */
102
-    protected $atts = [];
103
-
104
-    /**
105
-     * @var array Entries for the current result. Single item in array for single entry View
106
-     */
107
-    protected $entries = [];
108
-
109
-    /**
110
-     * @var int Total entries count for the current result.
111
-     */
112
-    protected $total_entries = 0;
113
-
114
-    /**
115
-     * @var string The label to display back links
116
-     */
117
-    protected $back_link_label = '';
118
-
119
-    /**
120
-     * @var array Array with `offset` and `page_size` keys
121
-     */
122
-    protected $paging = [];
123
-
124
-    /**
125
-     * @var array Array with `sort_field` and `sort_direction` keys
126
-     */
127
-    protected $sorting = [];
128
-
129
-    /**
130
-     * @var bool Whether to hide the results until a search is performed
131
-     *
132
-     * @since 1.5.4
133
-     */
134
-    protected $hide_until_searched = false;
135
-
136
-    /**
137
-     * Current entry in the loop.
138
-     *
139
-     * @var array
140
-     */
141
-    protected $_current_entry = [];
142
-
143
-    /**
144
-     * @var array
145
-     */
146
-    protected $_current_field = [];
147
-
148
-    /**
149
-     * @var GravityView_View $instance
150
-     */
151
-    public static $instance = null;
152
-
153
-    /**
154
-     * Construct the view object.
155
-     *
156
-     * @param array $atts Associative array to set the data of
157
-     */
158
-    public function __construct($atts = [])
159
-    {
160
-        $atts = wp_parse_args($atts, [
161
-            'form_id' => null,
162
-            'view_id' => null,
163
-            'fields'  => null,
164
-            'context' => null,
165
-            'post_id' => null,
166
-            'form'    => null,
167
-            'atts'	   => null,
168
-        ]);
169
-
170
-        foreach ($atts as $key => $value) {
171
-            if (is_null($value)) {
172
-                continue;
173
-            }
174
-            $this->{$key} = $value;
175
-        }
176
-
177
-        // Add granular overrides
178
-        add_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates'], 10, 3);
179
-
180
-        // widget logic
181
-        add_action('gravityview/template/before', [$this, 'render_widget_hooks']);
182
-        add_action('gravityview/template/after', [$this, 'render_widget_hooks']);
183
-
184
-        /**
185
-         * Clear the current entry after the loop is done.
186
-         *
187
-         * @since 1.7.3
188
-         */
189
-        add_action('gravityview_footer', [$this, 'clearCurrentEntry'], 500);
190
-
191
-        self::$instance = &$this;
192
-    }
193
-
194
-    /**
195
-     * @param null $passed_post
196
-     *
197
-     * @return GravityView_View
198
-     */
199
-    public static function getInstance($passed_post = null)
200
-    {
201
-        if (empty(self::$instance)) {
202
-            self::$instance = new self($passed_post);
203
-        }
204
-
205
-        return self::$instance;
206
-    }
207
-
208
-    /**
209
-     * @param string|null $key The key to a specific attribute of the current field
210
-     *
211
-     * @return array|mixed|null If $key is set and attribute exists at $key, return that. If not set, return NULL. Otherwise, return current field array
212
-     */
213
-    public function getCurrentField($key = null)
214
-    {
215
-        if (!empty($key)) {
216
-            if (isset($this->_current_field[$key])) {
217
-                return $this->_current_field[$key];
218
-            }
219
-
220
-            return null;
221
-        }
222
-
223
-        return $this->_current_field;
224
-    }
225
-
226
-    public function setCurrentFieldSetting($key, $value)
227
-    {
228
-        if (!empty($this->_current_field)) {
229
-            $this->_current_field['field_settings'][$key] = $value;
230
-        }
231
-    }
232
-
233
-    public function getCurrentFieldSetting($key)
234
-    {
235
-        $settings = $this->getCurrentField('field_settings');
236
-
237
-        if ($settings && !empty($settings[$key])) {
238
-            return $settings[$key];
239
-        }
240
-
241
-        return null;
242
-    }
243
-
244
-    /**
245
-     * @param array $passed_field
246
-     */
247
-    public function setCurrentField($passed_field)
248
-    {
249
-        $existing_field = $this->getCurrentField();
250
-
251
-        $set_field = wp_parse_args($passed_field, $existing_field);
252
-
253
-        $this->_current_field = $set_field;
254
-
255
-        /**
256
-         * Backward compatibility.
257
-         *
258
-         * @deprecated 1.6.2
259
-         */
260
-        $this->field_data = $set_field;
261
-    }
262
-
263
-    /**
264
-     * @param string|null $key The key to a specific field in the fields array
265
-     *
266
-     * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
267
-     */
268
-    public function getAtts($key = null)
269
-    {
270
-        if (!empty($key)) {
271
-            if (isset($this->atts[$key])) {
272
-                return $this->atts[$key];
273
-            }
274
-
275
-            return null;
276
-        }
277
-
278
-        return $this->atts;
279
-    }
280
-
281
-    /**
282
-     * @param array $atts
283
-     */
284
-    public function setAtts($atts)
285
-    {
286
-        $this->atts = $atts;
287
-    }
288
-
289
-    /**
290
-     * @return array
291
-     */
292
-    public function getForm()
293
-    {
294
-        return $this->form;
295
-    }
296
-
297
-    /**
298
-     * @param array $form
299
-     */
300
-    public function setForm($form)
301
-    {
302
-        $this->form = $form;
303
-    }
304
-
305
-    /**
306
-     * @return int|null
307
-     */
308
-    public function getPostId()
309
-    {
310
-        return $this->post_id;
311
-    }
312
-
313
-    /**
314
-     * @param int|null $post_id
315
-     */
316
-    public function setPostId($post_id)
317
-    {
318
-        $this->post_id = $post_id;
319
-    }
320
-
321
-    /**
322
-     * @return string
323
-     */
324
-    public function getContext()
325
-    {
326
-        return $this->context;
327
-    }
328
-
329
-    /**
330
-     * @param string $context
331
-     */
332
-    public function setContext($context)
333
-    {
334
-        $this->context = $context;
335
-    }
336
-
337
-    /**
338
-     * @param string|null $key The key to a specific field in the fields array
339
-     *
340
-     * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
341
-     */
342
-    public function getFields($key = null)
343
-    {
344
-        $fields = empty($this->fields) ? null : $this->fields;
345
-
346
-        if ($fields && !empty($key)) {
347
-            $fields = isset($fields[$key]) ? $fields[$key] : null;
348
-        }
349
-
350
-        return $fields;
351
-    }
352
-
353
-    /**
354
-     * Get the fields for a specific context.
355
-     *
356
-     * @since 1.19.2
357
-     *
358
-     * @param string $context [Optional] "directory", "single", or "edit"
359
-     *
360
-     * @return array Array of GravityView field layout configurations
361
-     */
362
-    public function getContextFields($context = '')
363
-    {
364
-        if ('' === $context) {
365
-            $context = $this->getContext();
366
-        }
367
-
368
-        $fields = $this->getFields();
369
-
370
-        foreach ((array) $fields as $key => $context_fields) {
371
-
372
-            // Formatted as `{context}_{template id}-{zone name}`, so we want just the $context to match against
373
-            $matches = explode('_', $key);
374
-
375
-            if (isset($matches[0]) && $matches[0] === $context) {
376
-                return $context_fields;
377
-            }
378
-        }
379
-
380
-        return [];
381
-    }
382
-
383
-    /**
384
-     * @param array $fields
385
-     */
386
-    public function setFields($fields)
387
-    {
388
-        $this->fields = $fields;
389
-    }
390
-
391
-    /**
392
-     * @param string $key The key to a specific field in the fields array
393
-     *
394
-     * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
395
-     */
396
-    public function getField($key)
397
-    {
398
-        if (!empty($key)) {
399
-            if (isset($this->fields[$key])) {
400
-                return $this->fields[$key];
401
-            }
402
-        }
403
-
404
-        return null;
405
-    }
406
-
407
-    /**
408
-     * @param string $key   The key to a specific field in the fields array
409
-     * @param mixed  $value The value to set for the field
410
-     */
411
-    public function setField($key, $value)
412
-    {
413
-        $this->fields[$key] = $value;
414
-    }
415
-
416
-    /**
417
-     * @return int
418
-     */
419
-    public function getViewId()
420
-    {
421
-        return absint($this->view_id);
422
-    }
423
-
424
-    /**
425
-     * @param int $view_id
426
-     */
427
-    public function setViewId($view_id)
428
-    {
429
-        $this->view_id = intval($view_id);
430
-    }
431
-
432
-    /**
433
-     * @return int
434
-     */
435
-    public function getFormId()
436
-    {
437
-        return $this->form_id;
438
-    }
439
-
440
-    /**
441
-     * @param int $form_id
442
-     */
443
-    public function setFormId($form_id)
444
-    {
445
-        $this->form_id = $form_id;
446
-    }
447
-
448
-    /**
449
-     * @return array
450
-     */
451
-    public function getEntries()
452
-    {
453
-        return $this->entries;
454
-    }
455
-
456
-    /**
457
-     * @param array $entries
458
-     */
459
-    public function setEntries($entries)
460
-    {
461
-        $this->entries = $entries;
462
-    }
463
-
464
-    /**
465
-     * @return int
466
-     */
467
-    public function getTotalEntries()
468
-    {
469
-        return (int) $this->total_entries;
470
-    }
471
-
472
-    /**
473
-     * @param int $total_entries
474
-     */
475
-    public function setTotalEntries($total_entries)
476
-    {
477
-        $this->total_entries = intval($total_entries);
478
-    }
479
-
480
-    /**
481
-     * @return array
482
-     */
483
-    public function getPaging()
484
-    {
485
-        $default_params = [
486
-            'offset'    => 0,
487
-            'page_size' => 20,
488
-        ];
489
-
490
-        return wp_parse_args($this->paging, $default_params);
491
-    }
492
-
493
-    /**
494
-     * @param array $paging
495
-     */
496
-    public function setPaging($paging)
497
-    {
498
-        $this->paging = $paging;
499
-    }
500
-
501
-    /**
502
-     * Get an array with pagination information.
503
-     *
504
-     * @since 1.13
505
-     *
506
-     * @return array {
507
-     *
508
-     *  @var int $first The starting entry number (counter, not ID)
509
-     *  @var int $last The last displayed entry number (counter, not ID)
510
-     *  @var int $total The total number of entries
511
-     * }
512
-     */
513
-    public function getPaginationCounts()
514
-    {
515
-        $paging = $this->getPaging();
516
-        $offset = $paging['offset'];
517
-        $page_size = $paging['page_size'];
518
-        $total = $this->getTotalEntries();
519
-
520
-        if (empty($total)) {
521
-            gravityview()->log->debug('No entries. Returning empty array.');
522
-
523
-            return [];
524
-        }
525
-
526
-        $first = empty($offset) ? 1 : $offset + 1;
527
-
528
-        // If the page size + starting entry is larger than total, the total is the max.
529
-        $last = ($offset + $page_size > $total) ? $total : $offset + $page_size;
530
-
531
-        /**
532
-         * @filter `gravityview_pagination_counts` Modify the displayed pagination numbers
533
-         *
534
-         * @since 1.13
535
-         *
536
-         * @param array $counts Array with $first, $last, $total numbers in that order
537
-         */
538
-        list($first, $last, $total) = apply_filters('gravityview_pagination_counts', [$first, $last, $total]);
539
-
540
-        return ['first' => (int) $first, 'last' => (int) $last, 'total' => (int) $total];
541
-    }
542
-
543
-    /**
544
-     * @return array
545
-     */
546
-    public function getSorting()
547
-    {
548
-        $defaults_params = [
549
-            'sort_field'     => 'date_created',
550
-            'sort_direction' => 'ASC',
551
-            'is_numeric'     => false,
552
-        ];
553
-
554
-        return wp_parse_args($this->sorting, $defaults_params);
555
-    }
556
-
557
-    /**
558
-     * @param array $sorting
559
-     */
560
-    public function setSorting($sorting)
561
-    {
562
-        $this->sorting = $sorting;
563
-    }
564
-
565
-    /**
566
-     * @param bool $do_replace Perform merge tag and shortcode processing on the label. Default: true.
567
-     *
568
-     * @since 2.0
569
-     * @deprecated Use $template->get_back_label();
570
-     *
571
-     * @return string
572
-     */
573
-    public function getBackLinkLabel($do_replace = true)
574
-    {
575
-        if ($do_replace) {
576
-            $back_link_label = GravityView_API::replace_variables($this->back_link_label, $this->getForm(), $this->getCurrentEntry());
577
-
578
-            return do_shortcode($back_link_label);
579
-        }
580
-
581
-        return $this->back_link_label;
582
-    }
583
-
584
-    /**
585
-     * @param string $back_link_label
586
-     */
587
-    public function setBackLinkLabel($back_link_label)
588
-    {
589
-        $this->back_link_label = $back_link_label;
590
-    }
591
-
592
-    /**
593
-     * @return bool
594
-     */
595
-    public function isHideUntilSearched()
596
-    {
597
-        return $this->hide_until_searched;
598
-    }
599
-
600
-    /**
601
-     * @param bool $hide_until_searched
602
-     */
603
-    public function setHideUntilSearched($hide_until_searched)
604
-    {
605
-        $this->hide_until_searched = $hide_until_searched;
606
-    }
607
-
608
-    /**
609
-     * @return string
610
-     */
611
-    public function getTemplatePartSlug()
612
-    {
613
-        return $this->template_part_slug;
614
-    }
615
-
616
-    /**
617
-     * @param string $template_part_slug
618
-     */
619
-    public function setTemplatePartSlug($template_part_slug)
620
-    {
621
-        $this->template_part_slug = $template_part_slug;
622
-    }
623
-
624
-    /**
625
-     * @return string
626
-     */
627
-    public function getTemplatePartName()
628
-    {
629
-        return $this->template_part_name;
630
-    }
631
-
632
-    /**
633
-     * @param string $template_part_name
634
-     */
635
-    public function setTemplatePartName($template_part_name)
636
-    {
637
-        $this->template_part_name = $template_part_name;
638
-    }
639
-
640
-    /**
641
-     * Return the current entry. If in the loop, the current entry. If single entry, the currently viewed entry.
642
-     *
643
-     * @return array
644
-     */
645
-    public function getCurrentEntry()
646
-    {
647
-        if (in_array($this->getContext(), ['edit', 'single'])) {
648
-            $entries = $this->getEntries();
649
-            $entry = $entries[0];
650
-        } else {
651
-            $entry = $this->_current_entry;
652
-        }
653
-
654
-        /** @since 1.16 Fixes DataTables empty entry issue */
655
-        if (empty($entry) && !empty($this->_current_field['entry'])) {
656
-            $entry = $this->_current_field['entry'];
657
-        }
658
-
659
-        return $entry;
660
-    }
661
-
662
-    /**
663
-     * @param array $current_entry
664
-     *
665
-     * @return void
666
-     */
667
-    public function setCurrentEntry($current_entry)
668
-    {
669
-        $this->_current_entry = $current_entry;
670
-    }
671
-
672
-    /**
673
-     * Clear the current entry after all entries in the loop have been displayed.
674
-     *
675
-     * @since 1.7.3
676
-     *
677
-     * @return void
678
-     */
679
-    public function clearCurrentEntry()
680
-    {
681
-        $this->_current_entry = null;
682
-    }
683
-
684
-    /**
685
-     * Render an output zone, as configured in the Admin.
686
-     *
687
-     * @since 1.16.4 Added $echo parameter
688
-     *
689
-     * @param string $zone The zone name, like 'footer-left'
690
-     * @param array  $atts
691
-     * @param bool   $echo Whether to print the output
692
-     *
693
-     * @deprecated This will never get called in new templates.
694
-     *
695
-     * @return string|null
696
-     */
697
-    public function renderZone($zone = '', $atts = [], $echo = true)
698
-    {
699
-        if (empty($zone)) {
700
-            gravityview()->log->error('No zone defined.');
701
-
702
-            return null;
703
-        }
704
-
705
-        $defaults = [
706
-            'slug'       => $this->getTemplatePartSlug(),
707
-            'context'    => $this->getContext(),
708
-            'entry'      => $this->getCurrentEntry(),
709
-            'form'       => $this->getForm(),
710
-            'hide_empty' => $this->getAtts('hide_empty'),
711
-        ];
712
-
713
-        $final_atts = wp_parse_args($atts, $defaults);
714
-
715
-        $output = '';
716
-
717
-        $final_atts['zone_id'] = "{$final_atts['context']}_{$final_atts['slug']}-{$zone}";
718
-
719
-        $fields = $this->getField($final_atts['zone_id']);
720
-
721
-        // Backward compatibility
722
-        if ('table' === $this->getTemplatePartSlug()) {
723
-            /**
724
-             * @filter `gravityview_table_cells` Modify the fields displayed in a table
725
-             *
726
-             * @param array             $fields
727
-             * @param \GravityView_View $this
728
-             *
729
-             * @deprecated Use `gravityview/template/table/fields`
730
-             */
731
-            $fields = apply_filters('gravityview_table_cells', $fields, $this);
732
-        }
733
-
734
-        if (empty($fields)) {
735
-            gravityview()->log->error('Empty zone configuration for {zone_id}.', ['zone_id' => $final_atts['zone_id']]);
736
-
737
-            return null;
738
-        }
739
-
740
-        $field_output = '';
741
-        foreach ($fields as $field) {
742
-            $final_atts['field'] = $field;
743
-
744
-            $field_output .= gravityview_field_output($final_atts);
745
-        }
746
-
747
-        /**
748
-         * If a zone has no field output, choose whether to show wrapper
749
-         * False by default to keep backward compatibility.
750
-         *
751
-         * @since 1.7.6
752
-         *
753
-         * @param bool $hide_empty_zone Default: false
754
-         *
755
-         * @since 2.0
756
-         *
757
-         * @param \GV\Template_Context $context The context. Null here. Since this path is deprecated.
758
-         */
759
-        if (empty($field_output) && apply_filters('gravityview/render/hide-empty-zone', false, null)) {
760
-            return null;
761
-        }
762
-
763
-        if (!empty($final_atts['wrapper_class'])) {
764
-            $output .= '<div class="'.gravityview_sanitize_html_class($final_atts['wrapper_class']).'">';
765
-        }
766
-
767
-        $output .= $field_output;
768
-
769
-        if (!empty($final_atts['wrapper_class'])) {
770
-            $output .= '</div>';
771
-        }
772
-
773
-        if ($echo) {
774
-            echo $output;
775
-        }
776
-
777
-        return $output;
778
-    }
779
-
780
-    /**
781
-     * In order to improve lookup times, we store located templates in a local array.
782
-     *
783
-     * This improves performance by up to 1/2 second on a 250 entry View with 7 columns showing
784
-     *
785
-     * @inheritdoc
786
-     *
787
-     * @see Gamajo_Template_Loader::locate_template()
788
-     *
789
-     * @return null|string NULL: Template not found; String: path to template
790
-     */
791
-    public function locate_template($template_names, $load = false, $require_once = true)
792
-    {
793
-        if (is_string($template_names) && isset($this->located_templates[$template_names])) {
794
-            $located = $this->located_templates[$template_names];
795
-        } else {
796
-
797
-            // Set $load to always false so we handle it here.
798
-            $located = parent::locate_template($template_names, false, $require_once);
799
-
800
-            if (is_string($template_names)) {
801
-                $this->located_templates[$template_names] = $located;
802
-            }
803
-        }
804
-
805
-        if ($load && $located) {
806
-            load_template($located, $require_once);
807
-        }
808
-
809
-        return $located;
810
-    }
811
-
812
-    /**
813
-     * Magic Method: Instead of throwing an error when a variable isn't set, return null.
814
-     *
815
-     * @param string $name Key for the data retrieval.
816
-     *
817
-     * @return mixed|null The stored data.
818
-     */
819
-    public function __get($name)
820
-    {
821
-        if (isset($this->{$name})) {
822
-            return $this->{$name};
823
-        } else {
824
-            return null;
825
-        }
826
-    }
827
-
828
-    /**
829
-     * Enable overrides of GravityView templates on a granular basis.
830
-     *
831
-     * The loading order is:
832
-     *
833
-     * - view-[View ID]-table-footer.php
834
-     * - form-[Form ID]-table-footer.php
835
-     * - page-[ID of post or page where view is embedded]-table-footer.php
836
-     * - table-footer.php
837
-     *
838
-     * @see  Gamajo_Template_Loader::get_template_file_names() Where the filter is
839
-     *
840
-     * @param array  $templates Existing list of templates.
841
-     * @param string $slug      Name of the template base, example: `table`, `list`, `datatables`, `map`
842
-     * @param string $name      Name of the template part, example: `body`, `footer`, `head`, `single`
843
-     *
844
-     * @return array $templates Modified template array, merged with existing $templates values
845
-     */
846
-    public function add_id_specific_templates($templates, $slug, $name)
847
-    {
848
-        $additional = [];
849
-
850
-        // form-19-table-body.php
851
-        $additional[] = sprintf('form-%d-%s-%s.php', $this->getFormId(), $slug, $name);
852
-
853
-        if ($view_id = $this->getViewId()) {
854
-            // view-3-table-body.php
855
-            $additional[] = sprintf('view-%d-%s-%s.php', $view_id, $slug, $name);
856
-        }
857
-
858
-        if ($this->getPostId()) {
859
-
860
-            // page-19-table-body.php
861
-            $additional[] = sprintf('page-%d-%s-%s.php', $this->getPostId(), $slug, $name);
862
-        }
863
-
864
-        // Combine with existing table-body.php and table.php
865
-        $templates = array_merge($additional, $templates);
866
-
867
-        gravityview()->log->debug('List of Template Files', ['data' => $templates]);
868
-
869
-        return $templates;
870
-    }
871
-
872
-    // Load the template
873
-    public function render($slug, $name, $require_once = true)
874
-    {
875
-        $this->setTemplatePartSlug($slug);
876
-
877
-        $this->setTemplatePartName($name);
878
-
879
-        $template_file = $this->get_template_part($slug, $name, false);
880
-
881
-        gravityview()->log->debug('Rendering Template File: {path}', ['path' => $template_file]);
882
-
883
-        if (!empty($template_file)) {
884
-            if ($require_once) {
885
-                require_once $template_file;
886
-            } else {
887
-                require $template_file;
888
-            }
889
-        }
890
-    }
891
-
892
-    /**
893
-     * Output the widgets on before/after hooks.
894
-     *
895
-     * @param int|\GV\Template_Context $view_id_or_context The View ID or the context.
896
-     *
897
-     * @return void
898
-     */
899
-    public function render_widget_hooks($view_id_or_context)
900
-    {
901
-
902
-        /**
903
-         * @deprecated Numeric argument is deprecated. Pass a \GV\Template_Context instead.
904
-         */
905
-        if (is_numeric($view_id_or_context)) {
906
-            $view = \GV\View::by_id($view_id_or_context);
907
-            $is_single = gravityview_get_context() == 'single';
908
-            $total_entries = GravityView_View::getInstance()->getTotalEntries();
909
-
910
-            /**
911
-             * Fake new context for legacy template code.
912
-             */
913
-            $view_id_or_context = \GV\Template_Context::from_template([
914
-                'view' => $view,
915
-            ]);
916
-        } elseif ($view_id_or_context instanceof \GV\Template_Context) {
917
-            $view = $view_id_or_context->view;
918
-            $is_single = (bool) $view_id_or_context->request->is_entry();
919
-            $total_entries = $view_id_or_context->entries ? $view_id_or_context->entries->count() : 0;
920
-        } else {
921
-            gravityview()->log->error('No View ID or template context provided to render_widget_hooks');
922
-
923
-            return;
924
-        }
925
-
926
-        if ($is_single) {
927
-            gravityview()->log->debug('Not rendering widgets; single entry');
928
-
929
-            return;
930
-        }
931
-
932
-        switch (current_filter()) {
933
-            default:
934
-            case 'gravityview/template/before':
935
-            case 'gravityview_before':
936
-                $zone = 'header';
937
-                break;
938
-            case 'gravityview/template/after':
939
-            case 'gravityview_after':
940
-                $zone = 'footer';
941
-                break;
942
-        }
943
-
944
-        $widgets = $view->widgets->by_position("$zone*");
945
-
946
-        /**
947
-         * Prevent output if no widgets to show.
948
-         *
949
-         * @since 1.16
950
-         */
951
-        if (!$widgets->count()) {
952
-            gravityview()->log->debug('No widgets for View #{view_id} in zone {zone}', ['view_id' => $view->ID, 'zone' => $zone]);
953
-
954
-            return;
955
-        }
956
-
957
-        // Prevent being called twice
958
-        if (did_action("gravityview/widgets/$zone/{$view->ID}/rendered")) {
959
-            gravityview()->log->debug('Not rendering {zone}; already rendered', ['zone' => $zone.'_'.$view->ID.'_widgets']);
960
-
961
-            return;
962
-        }
963
-
964
-        $rows = \GV\Widget::get_default_widget_areas();
965
-
966
-        // TODO: Move to sep. method, use an action instead
967
-        wp_enqueue_style('gravityview_default_style');
968
-
969
-        $default_css_class = 'gv-grid gv-widgets-'.$zone;
970
-
971
-        if (!$total_entries) {
972
-            $default_css_class .= ' gv-widgets-no-results';
973
-        }
974
-
975
-        /**
976
-         * @filter `gravityview/widgets/wrapper_css_class` The CSS class applied to the widget container `<div>`.
977
-         *
978
-         * @since 1.16.2
979
-         *
980
-         * @param string $css_class Default: `gv-grid gv-widgets-{zone}` where `{zone}` is replaced by the current `$zone` value. If the View has no results, adds ` gv-widgets-no-results`
981
-         * @param string $zone      Current widget zone, either `header` or `footer`
982
-         * @param array  $widgets   Array of widget configurations for the current zone, as set by `gravityview_get_current_view_data()['widgets']`
983
-         */
984
-        $css_class = apply_filters('gravityview/widgets/wrapper_css_class', $default_css_class, $zone, $widgets->as_configuration());
985
-
986
-        $css_class = gravityview_sanitize_html_class($css_class);
987
-
988
-        // TODO Convert to partials?>
26
+	/**
27
+	 * Prefix for filter names.
28
+	 *
29
+	 * @var string
30
+	 */
31
+	protected $filter_prefix = 'gravityview';
32
+
33
+	/**
34
+	 * Directory name where custom templates for this plugin should be found in the theme.
35
+	 *
36
+	 * @var string
37
+	 */
38
+	protected $theme_template_directory = 'gravityview';
39
+
40
+	/**
41
+	 * Reference to the root directory path of this plugin.
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $plugin_directory = GRAVITYVIEW_DIR;
46
+
47
+	/**
48
+	 * Store templates locations that have already been located.
49
+	 *
50
+	 * @var array
51
+	 */
52
+	protected $located_templates = [];
53
+
54
+	/**
55
+	 * The name of the template, like "list", "table", or "datatables".
56
+	 *
57
+	 * @var string
58
+	 */
59
+	protected $template_part_slug = '';
60
+
61
+	/**
62
+	 * The name of the file part, like "body" or "single".
63
+	 *
64
+	 * @var string
65
+	 */
66
+	protected $template_part_name = '';
67
+
68
+	/**
69
+	 * @var int Gravity Forms form ID
70
+	 */
71
+	protected $form_id = null;
72
+
73
+	/**
74
+	 * @var int View ID
75
+	 * @todo: this needs to be public until extensions support 1.7+
76
+	 */
77
+	public $view_id = null;
78
+
79
+	/**
80
+	 * @var array Fields for the form
81
+	 */
82
+	protected $fields = [];
83
+
84
+	/**
85
+	 * @var string Current screen. Defaults to "directory" or "single"
86
+	 */
87
+	protected $context = 'directory';
88
+
89
+	/**
90
+	 * @var int|null If in embedded post or page, the ID of it
91
+	 */
92
+	protected $post_id = null;
93
+
94
+	/**
95
+	 * @var array Gravity Forms form array at ID_id
96
+	 */
97
+	protected $form = null;
98
+
99
+	/**
100
+	 * @var array Configuration for the View
101
+	 */
102
+	protected $atts = [];
103
+
104
+	/**
105
+	 * @var array Entries for the current result. Single item in array for single entry View
106
+	 */
107
+	protected $entries = [];
108
+
109
+	/**
110
+	 * @var int Total entries count for the current result.
111
+	 */
112
+	protected $total_entries = 0;
113
+
114
+	/**
115
+	 * @var string The label to display back links
116
+	 */
117
+	protected $back_link_label = '';
118
+
119
+	/**
120
+	 * @var array Array with `offset` and `page_size` keys
121
+	 */
122
+	protected $paging = [];
123
+
124
+	/**
125
+	 * @var array Array with `sort_field` and `sort_direction` keys
126
+	 */
127
+	protected $sorting = [];
128
+
129
+	/**
130
+	 * @var bool Whether to hide the results until a search is performed
131
+	 *
132
+	 * @since 1.5.4
133
+	 */
134
+	protected $hide_until_searched = false;
135
+
136
+	/**
137
+	 * Current entry in the loop.
138
+	 *
139
+	 * @var array
140
+	 */
141
+	protected $_current_entry = [];
142
+
143
+	/**
144
+	 * @var array
145
+	 */
146
+	protected $_current_field = [];
147
+
148
+	/**
149
+	 * @var GravityView_View $instance
150
+	 */
151
+	public static $instance = null;
152
+
153
+	/**
154
+	 * Construct the view object.
155
+	 *
156
+	 * @param array $atts Associative array to set the data of
157
+	 */
158
+	public function __construct($atts = [])
159
+	{
160
+		$atts = wp_parse_args($atts, [
161
+			'form_id' => null,
162
+			'view_id' => null,
163
+			'fields'  => null,
164
+			'context' => null,
165
+			'post_id' => null,
166
+			'form'    => null,
167
+			'atts'	   => null,
168
+		]);
169
+
170
+		foreach ($atts as $key => $value) {
171
+			if (is_null($value)) {
172
+				continue;
173
+			}
174
+			$this->{$key} = $value;
175
+		}
176
+
177
+		// Add granular overrides
178
+		add_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates'], 10, 3);
179
+
180
+		// widget logic
181
+		add_action('gravityview/template/before', [$this, 'render_widget_hooks']);
182
+		add_action('gravityview/template/after', [$this, 'render_widget_hooks']);
183
+
184
+		/**
185
+		 * Clear the current entry after the loop is done.
186
+		 *
187
+		 * @since 1.7.3
188
+		 */
189
+		add_action('gravityview_footer', [$this, 'clearCurrentEntry'], 500);
190
+
191
+		self::$instance = &$this;
192
+	}
193
+
194
+	/**
195
+	 * @param null $passed_post
196
+	 *
197
+	 * @return GravityView_View
198
+	 */
199
+	public static function getInstance($passed_post = null)
200
+	{
201
+		if (empty(self::$instance)) {
202
+			self::$instance = new self($passed_post);
203
+		}
204
+
205
+		return self::$instance;
206
+	}
207
+
208
+	/**
209
+	 * @param string|null $key The key to a specific attribute of the current field
210
+	 *
211
+	 * @return array|mixed|null If $key is set and attribute exists at $key, return that. If not set, return NULL. Otherwise, return current field array
212
+	 */
213
+	public function getCurrentField($key = null)
214
+	{
215
+		if (!empty($key)) {
216
+			if (isset($this->_current_field[$key])) {
217
+				return $this->_current_field[$key];
218
+			}
219
+
220
+			return null;
221
+		}
222
+
223
+		return $this->_current_field;
224
+	}
225
+
226
+	public function setCurrentFieldSetting($key, $value)
227
+	{
228
+		if (!empty($this->_current_field)) {
229
+			$this->_current_field['field_settings'][$key] = $value;
230
+		}
231
+	}
232
+
233
+	public function getCurrentFieldSetting($key)
234
+	{
235
+		$settings = $this->getCurrentField('field_settings');
236
+
237
+		if ($settings && !empty($settings[$key])) {
238
+			return $settings[$key];
239
+		}
240
+
241
+		return null;
242
+	}
243
+
244
+	/**
245
+	 * @param array $passed_field
246
+	 */
247
+	public function setCurrentField($passed_field)
248
+	{
249
+		$existing_field = $this->getCurrentField();
250
+
251
+		$set_field = wp_parse_args($passed_field, $existing_field);
252
+
253
+		$this->_current_field = $set_field;
254
+
255
+		/**
256
+		 * Backward compatibility.
257
+		 *
258
+		 * @deprecated 1.6.2
259
+		 */
260
+		$this->field_data = $set_field;
261
+	}
262
+
263
+	/**
264
+	 * @param string|null $key The key to a specific field in the fields array
265
+	 *
266
+	 * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
267
+	 */
268
+	public function getAtts($key = null)
269
+	{
270
+		if (!empty($key)) {
271
+			if (isset($this->atts[$key])) {
272
+				return $this->atts[$key];
273
+			}
274
+
275
+			return null;
276
+		}
277
+
278
+		return $this->atts;
279
+	}
280
+
281
+	/**
282
+	 * @param array $atts
283
+	 */
284
+	public function setAtts($atts)
285
+	{
286
+		$this->atts = $atts;
287
+	}
288
+
289
+	/**
290
+	 * @return array
291
+	 */
292
+	public function getForm()
293
+	{
294
+		return $this->form;
295
+	}
296
+
297
+	/**
298
+	 * @param array $form
299
+	 */
300
+	public function setForm($form)
301
+	{
302
+		$this->form = $form;
303
+	}
304
+
305
+	/**
306
+	 * @return int|null
307
+	 */
308
+	public function getPostId()
309
+	{
310
+		return $this->post_id;
311
+	}
312
+
313
+	/**
314
+	 * @param int|null $post_id
315
+	 */
316
+	public function setPostId($post_id)
317
+	{
318
+		$this->post_id = $post_id;
319
+	}
320
+
321
+	/**
322
+	 * @return string
323
+	 */
324
+	public function getContext()
325
+	{
326
+		return $this->context;
327
+	}
328
+
329
+	/**
330
+	 * @param string $context
331
+	 */
332
+	public function setContext($context)
333
+	{
334
+		$this->context = $context;
335
+	}
336
+
337
+	/**
338
+	 * @param string|null $key The key to a specific field in the fields array
339
+	 *
340
+	 * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
341
+	 */
342
+	public function getFields($key = null)
343
+	{
344
+		$fields = empty($this->fields) ? null : $this->fields;
345
+
346
+		if ($fields && !empty($key)) {
347
+			$fields = isset($fields[$key]) ? $fields[$key] : null;
348
+		}
349
+
350
+		return $fields;
351
+	}
352
+
353
+	/**
354
+	 * Get the fields for a specific context.
355
+	 *
356
+	 * @since 1.19.2
357
+	 *
358
+	 * @param string $context [Optional] "directory", "single", or "edit"
359
+	 *
360
+	 * @return array Array of GravityView field layout configurations
361
+	 */
362
+	public function getContextFields($context = '')
363
+	{
364
+		if ('' === $context) {
365
+			$context = $this->getContext();
366
+		}
367
+
368
+		$fields = $this->getFields();
369
+
370
+		foreach ((array) $fields as $key => $context_fields) {
371
+
372
+			// Formatted as `{context}_{template id}-{zone name}`, so we want just the $context to match against
373
+			$matches = explode('_', $key);
374
+
375
+			if (isset($matches[0]) && $matches[0] === $context) {
376
+				return $context_fields;
377
+			}
378
+		}
379
+
380
+		return [];
381
+	}
382
+
383
+	/**
384
+	 * @param array $fields
385
+	 */
386
+	public function setFields($fields)
387
+	{
388
+		$this->fields = $fields;
389
+	}
390
+
391
+	/**
392
+	 * @param string $key The key to a specific field in the fields array
393
+	 *
394
+	 * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
395
+	 */
396
+	public function getField($key)
397
+	{
398
+		if (!empty($key)) {
399
+			if (isset($this->fields[$key])) {
400
+				return $this->fields[$key];
401
+			}
402
+		}
403
+
404
+		return null;
405
+	}
406
+
407
+	/**
408
+	 * @param string $key   The key to a specific field in the fields array
409
+	 * @param mixed  $value The value to set for the field
410
+	 */
411
+	public function setField($key, $value)
412
+	{
413
+		$this->fields[$key] = $value;
414
+	}
415
+
416
+	/**
417
+	 * @return int
418
+	 */
419
+	public function getViewId()
420
+	{
421
+		return absint($this->view_id);
422
+	}
423
+
424
+	/**
425
+	 * @param int $view_id
426
+	 */
427
+	public function setViewId($view_id)
428
+	{
429
+		$this->view_id = intval($view_id);
430
+	}
431
+
432
+	/**
433
+	 * @return int
434
+	 */
435
+	public function getFormId()
436
+	{
437
+		return $this->form_id;
438
+	}
439
+
440
+	/**
441
+	 * @param int $form_id
442
+	 */
443
+	public function setFormId($form_id)
444
+	{
445
+		$this->form_id = $form_id;
446
+	}
447
+
448
+	/**
449
+	 * @return array
450
+	 */
451
+	public function getEntries()
452
+	{
453
+		return $this->entries;
454
+	}
455
+
456
+	/**
457
+	 * @param array $entries
458
+	 */
459
+	public function setEntries($entries)
460
+	{
461
+		$this->entries = $entries;
462
+	}
463
+
464
+	/**
465
+	 * @return int
466
+	 */
467
+	public function getTotalEntries()
468
+	{
469
+		return (int) $this->total_entries;
470
+	}
471
+
472
+	/**
473
+	 * @param int $total_entries
474
+	 */
475
+	public function setTotalEntries($total_entries)
476
+	{
477
+		$this->total_entries = intval($total_entries);
478
+	}
479
+
480
+	/**
481
+	 * @return array
482
+	 */
483
+	public function getPaging()
484
+	{
485
+		$default_params = [
486
+			'offset'    => 0,
487
+			'page_size' => 20,
488
+		];
489
+
490
+		return wp_parse_args($this->paging, $default_params);
491
+	}
492
+
493
+	/**
494
+	 * @param array $paging
495
+	 */
496
+	public function setPaging($paging)
497
+	{
498
+		$this->paging = $paging;
499
+	}
500
+
501
+	/**
502
+	 * Get an array with pagination information.
503
+	 *
504
+	 * @since 1.13
505
+	 *
506
+	 * @return array {
507
+	 *
508
+	 *  @var int $first The starting entry number (counter, not ID)
509
+	 *  @var int $last The last displayed entry number (counter, not ID)
510
+	 *  @var int $total The total number of entries
511
+	 * }
512
+	 */
513
+	public function getPaginationCounts()
514
+	{
515
+		$paging = $this->getPaging();
516
+		$offset = $paging['offset'];
517
+		$page_size = $paging['page_size'];
518
+		$total = $this->getTotalEntries();
519
+
520
+		if (empty($total)) {
521
+			gravityview()->log->debug('No entries. Returning empty array.');
522
+
523
+			return [];
524
+		}
525
+
526
+		$first = empty($offset) ? 1 : $offset + 1;
527
+
528
+		// If the page size + starting entry is larger than total, the total is the max.
529
+		$last = ($offset + $page_size > $total) ? $total : $offset + $page_size;
530
+
531
+		/**
532
+		 * @filter `gravityview_pagination_counts` Modify the displayed pagination numbers
533
+		 *
534
+		 * @since 1.13
535
+		 *
536
+		 * @param array $counts Array with $first, $last, $total numbers in that order
537
+		 */
538
+		list($first, $last, $total) = apply_filters('gravityview_pagination_counts', [$first, $last, $total]);
539
+
540
+		return ['first' => (int) $first, 'last' => (int) $last, 'total' => (int) $total];
541
+	}
542
+
543
+	/**
544
+	 * @return array
545
+	 */
546
+	public function getSorting()
547
+	{
548
+		$defaults_params = [
549
+			'sort_field'     => 'date_created',
550
+			'sort_direction' => 'ASC',
551
+			'is_numeric'     => false,
552
+		];
553
+
554
+		return wp_parse_args($this->sorting, $defaults_params);
555
+	}
556
+
557
+	/**
558
+	 * @param array $sorting
559
+	 */
560
+	public function setSorting($sorting)
561
+	{
562
+		$this->sorting = $sorting;
563
+	}
564
+
565
+	/**
566
+	 * @param bool $do_replace Perform merge tag and shortcode processing on the label. Default: true.
567
+	 *
568
+	 * @since 2.0
569
+	 * @deprecated Use $template->get_back_label();
570
+	 *
571
+	 * @return string
572
+	 */
573
+	public function getBackLinkLabel($do_replace = true)
574
+	{
575
+		if ($do_replace) {
576
+			$back_link_label = GravityView_API::replace_variables($this->back_link_label, $this->getForm(), $this->getCurrentEntry());
577
+
578
+			return do_shortcode($back_link_label);
579
+		}
580
+
581
+		return $this->back_link_label;
582
+	}
583
+
584
+	/**
585
+	 * @param string $back_link_label
586
+	 */
587
+	public function setBackLinkLabel($back_link_label)
588
+	{
589
+		$this->back_link_label = $back_link_label;
590
+	}
591
+
592
+	/**
593
+	 * @return bool
594
+	 */
595
+	public function isHideUntilSearched()
596
+	{
597
+		return $this->hide_until_searched;
598
+	}
599
+
600
+	/**
601
+	 * @param bool $hide_until_searched
602
+	 */
603
+	public function setHideUntilSearched($hide_until_searched)
604
+	{
605
+		$this->hide_until_searched = $hide_until_searched;
606
+	}
607
+
608
+	/**
609
+	 * @return string
610
+	 */
611
+	public function getTemplatePartSlug()
612
+	{
613
+		return $this->template_part_slug;
614
+	}
615
+
616
+	/**
617
+	 * @param string $template_part_slug
618
+	 */
619
+	public function setTemplatePartSlug($template_part_slug)
620
+	{
621
+		$this->template_part_slug = $template_part_slug;
622
+	}
623
+
624
+	/**
625
+	 * @return string
626
+	 */
627
+	public function getTemplatePartName()
628
+	{
629
+		return $this->template_part_name;
630
+	}
631
+
632
+	/**
633
+	 * @param string $template_part_name
634
+	 */
635
+	public function setTemplatePartName($template_part_name)
636
+	{
637
+		$this->template_part_name = $template_part_name;
638
+	}
639
+
640
+	/**
641
+	 * Return the current entry. If in the loop, the current entry. If single entry, the currently viewed entry.
642
+	 *
643
+	 * @return array
644
+	 */
645
+	public function getCurrentEntry()
646
+	{
647
+		if (in_array($this->getContext(), ['edit', 'single'])) {
648
+			$entries = $this->getEntries();
649
+			$entry = $entries[0];
650
+		} else {
651
+			$entry = $this->_current_entry;
652
+		}
653
+
654
+		/** @since 1.16 Fixes DataTables empty entry issue */
655
+		if (empty($entry) && !empty($this->_current_field['entry'])) {
656
+			$entry = $this->_current_field['entry'];
657
+		}
658
+
659
+		return $entry;
660
+	}
661
+
662
+	/**
663
+	 * @param array $current_entry
664
+	 *
665
+	 * @return void
666
+	 */
667
+	public function setCurrentEntry($current_entry)
668
+	{
669
+		$this->_current_entry = $current_entry;
670
+	}
671
+
672
+	/**
673
+	 * Clear the current entry after all entries in the loop have been displayed.
674
+	 *
675
+	 * @since 1.7.3
676
+	 *
677
+	 * @return void
678
+	 */
679
+	public function clearCurrentEntry()
680
+	{
681
+		$this->_current_entry = null;
682
+	}
683
+
684
+	/**
685
+	 * Render an output zone, as configured in the Admin.
686
+	 *
687
+	 * @since 1.16.4 Added $echo parameter
688
+	 *
689
+	 * @param string $zone The zone name, like 'footer-left'
690
+	 * @param array  $atts
691
+	 * @param bool   $echo Whether to print the output
692
+	 *
693
+	 * @deprecated This will never get called in new templates.
694
+	 *
695
+	 * @return string|null
696
+	 */
697
+	public function renderZone($zone = '', $atts = [], $echo = true)
698
+	{
699
+		if (empty($zone)) {
700
+			gravityview()->log->error('No zone defined.');
701
+
702
+			return null;
703
+		}
704
+
705
+		$defaults = [
706
+			'slug'       => $this->getTemplatePartSlug(),
707
+			'context'    => $this->getContext(),
708
+			'entry'      => $this->getCurrentEntry(),
709
+			'form'       => $this->getForm(),
710
+			'hide_empty' => $this->getAtts('hide_empty'),
711
+		];
712
+
713
+		$final_atts = wp_parse_args($atts, $defaults);
714
+
715
+		$output = '';
716
+
717
+		$final_atts['zone_id'] = "{$final_atts['context']}_{$final_atts['slug']}-{$zone}";
718
+
719
+		$fields = $this->getField($final_atts['zone_id']);
720
+
721
+		// Backward compatibility
722
+		if ('table' === $this->getTemplatePartSlug()) {
723
+			/**
724
+			 * @filter `gravityview_table_cells` Modify the fields displayed in a table
725
+			 *
726
+			 * @param array             $fields
727
+			 * @param \GravityView_View $this
728
+			 *
729
+			 * @deprecated Use `gravityview/template/table/fields`
730
+			 */
731
+			$fields = apply_filters('gravityview_table_cells', $fields, $this);
732
+		}
733
+
734
+		if (empty($fields)) {
735
+			gravityview()->log->error('Empty zone configuration for {zone_id}.', ['zone_id' => $final_atts['zone_id']]);
736
+
737
+			return null;
738
+		}
739
+
740
+		$field_output = '';
741
+		foreach ($fields as $field) {
742
+			$final_atts['field'] = $field;
743
+
744
+			$field_output .= gravityview_field_output($final_atts);
745
+		}
746
+
747
+		/**
748
+		 * If a zone has no field output, choose whether to show wrapper
749
+		 * False by default to keep backward compatibility.
750
+		 *
751
+		 * @since 1.7.6
752
+		 *
753
+		 * @param bool $hide_empty_zone Default: false
754
+		 *
755
+		 * @since 2.0
756
+		 *
757
+		 * @param \GV\Template_Context $context The context. Null here. Since this path is deprecated.
758
+		 */
759
+		if (empty($field_output) && apply_filters('gravityview/render/hide-empty-zone', false, null)) {
760
+			return null;
761
+		}
762
+
763
+		if (!empty($final_atts['wrapper_class'])) {
764
+			$output .= '<div class="'.gravityview_sanitize_html_class($final_atts['wrapper_class']).'">';
765
+		}
766
+
767
+		$output .= $field_output;
768
+
769
+		if (!empty($final_atts['wrapper_class'])) {
770
+			$output .= '</div>';
771
+		}
772
+
773
+		if ($echo) {
774
+			echo $output;
775
+		}
776
+
777
+		return $output;
778
+	}
779
+
780
+	/**
781
+	 * In order to improve lookup times, we store located templates in a local array.
782
+	 *
783
+	 * This improves performance by up to 1/2 second on a 250 entry View with 7 columns showing
784
+	 *
785
+	 * @inheritdoc
786
+	 *
787
+	 * @see Gamajo_Template_Loader::locate_template()
788
+	 *
789
+	 * @return null|string NULL: Template not found; String: path to template
790
+	 */
791
+	public function locate_template($template_names, $load = false, $require_once = true)
792
+	{
793
+		if (is_string($template_names) && isset($this->located_templates[$template_names])) {
794
+			$located = $this->located_templates[$template_names];
795
+		} else {
796
+
797
+			// Set $load to always false so we handle it here.
798
+			$located = parent::locate_template($template_names, false, $require_once);
799
+
800
+			if (is_string($template_names)) {
801
+				$this->located_templates[$template_names] = $located;
802
+			}
803
+		}
804
+
805
+		if ($load && $located) {
806
+			load_template($located, $require_once);
807
+		}
808
+
809
+		return $located;
810
+	}
811
+
812
+	/**
813
+	 * Magic Method: Instead of throwing an error when a variable isn't set, return null.
814
+	 *
815
+	 * @param string $name Key for the data retrieval.
816
+	 *
817
+	 * @return mixed|null The stored data.
818
+	 */
819
+	public function __get($name)
820
+	{
821
+		if (isset($this->{$name})) {
822
+			return $this->{$name};
823
+		} else {
824
+			return null;
825
+		}
826
+	}
827
+
828
+	/**
829
+	 * Enable overrides of GravityView templates on a granular basis.
830
+	 *
831
+	 * The loading order is:
832
+	 *
833
+	 * - view-[View ID]-table-footer.php
834
+	 * - form-[Form ID]-table-footer.php
835
+	 * - page-[ID of post or page where view is embedded]-table-footer.php
836
+	 * - table-footer.php
837
+	 *
838
+	 * @see  Gamajo_Template_Loader::get_template_file_names() Where the filter is
839
+	 *
840
+	 * @param array  $templates Existing list of templates.
841
+	 * @param string $slug      Name of the template base, example: `table`, `list`, `datatables`, `map`
842
+	 * @param string $name      Name of the template part, example: `body`, `footer`, `head`, `single`
843
+	 *
844
+	 * @return array $templates Modified template array, merged with existing $templates values
845
+	 */
846
+	public function add_id_specific_templates($templates, $slug, $name)
847
+	{
848
+		$additional = [];
849
+
850
+		// form-19-table-body.php
851
+		$additional[] = sprintf('form-%d-%s-%s.php', $this->getFormId(), $slug, $name);
852
+
853
+		if ($view_id = $this->getViewId()) {
854
+			// view-3-table-body.php
855
+			$additional[] = sprintf('view-%d-%s-%s.php', $view_id, $slug, $name);
856
+		}
857
+
858
+		if ($this->getPostId()) {
859
+
860
+			// page-19-table-body.php
861
+			$additional[] = sprintf('page-%d-%s-%s.php', $this->getPostId(), $slug, $name);
862
+		}
863
+
864
+		// Combine with existing table-body.php and table.php
865
+		$templates = array_merge($additional, $templates);
866
+
867
+		gravityview()->log->debug('List of Template Files', ['data' => $templates]);
868
+
869
+		return $templates;
870
+	}
871
+
872
+	// Load the template
873
+	public function render($slug, $name, $require_once = true)
874
+	{
875
+		$this->setTemplatePartSlug($slug);
876
+
877
+		$this->setTemplatePartName($name);
878
+
879
+		$template_file = $this->get_template_part($slug, $name, false);
880
+
881
+		gravityview()->log->debug('Rendering Template File: {path}', ['path' => $template_file]);
882
+
883
+		if (!empty($template_file)) {
884
+			if ($require_once) {
885
+				require_once $template_file;
886
+			} else {
887
+				require $template_file;
888
+			}
889
+		}
890
+	}
891
+
892
+	/**
893
+	 * Output the widgets on before/after hooks.
894
+	 *
895
+	 * @param int|\GV\Template_Context $view_id_or_context The View ID or the context.
896
+	 *
897
+	 * @return void
898
+	 */
899
+	public function render_widget_hooks($view_id_or_context)
900
+	{
901
+
902
+		/**
903
+		 * @deprecated Numeric argument is deprecated. Pass a \GV\Template_Context instead.
904
+		 */
905
+		if (is_numeric($view_id_or_context)) {
906
+			$view = \GV\View::by_id($view_id_or_context);
907
+			$is_single = gravityview_get_context() == 'single';
908
+			$total_entries = GravityView_View::getInstance()->getTotalEntries();
909
+
910
+			/**
911
+			 * Fake new context for legacy template code.
912
+			 */
913
+			$view_id_or_context = \GV\Template_Context::from_template([
914
+				'view' => $view,
915
+			]);
916
+		} elseif ($view_id_or_context instanceof \GV\Template_Context) {
917
+			$view = $view_id_or_context->view;
918
+			$is_single = (bool) $view_id_or_context->request->is_entry();
919
+			$total_entries = $view_id_or_context->entries ? $view_id_or_context->entries->count() : 0;
920
+		} else {
921
+			gravityview()->log->error('No View ID or template context provided to render_widget_hooks');
922
+
923
+			return;
924
+		}
925
+
926
+		if ($is_single) {
927
+			gravityview()->log->debug('Not rendering widgets; single entry');
928
+
929
+			return;
930
+		}
931
+
932
+		switch (current_filter()) {
933
+			default:
934
+			case 'gravityview/template/before':
935
+			case 'gravityview_before':
936
+				$zone = 'header';
937
+				break;
938
+			case 'gravityview/template/after':
939
+			case 'gravityview_after':
940
+				$zone = 'footer';
941
+				break;
942
+		}
943
+
944
+		$widgets = $view->widgets->by_position("$zone*");
945
+
946
+		/**
947
+		 * Prevent output if no widgets to show.
948
+		 *
949
+		 * @since 1.16
950
+		 */
951
+		if (!$widgets->count()) {
952
+			gravityview()->log->debug('No widgets for View #{view_id} in zone {zone}', ['view_id' => $view->ID, 'zone' => $zone]);
953
+
954
+			return;
955
+		}
956
+
957
+		// Prevent being called twice
958
+		if (did_action("gravityview/widgets/$zone/{$view->ID}/rendered")) {
959
+			gravityview()->log->debug('Not rendering {zone}; already rendered', ['zone' => $zone.'_'.$view->ID.'_widgets']);
960
+
961
+			return;
962
+		}
963
+
964
+		$rows = \GV\Widget::get_default_widget_areas();
965
+
966
+		// TODO: Move to sep. method, use an action instead
967
+		wp_enqueue_style('gravityview_default_style');
968
+
969
+		$default_css_class = 'gv-grid gv-widgets-'.$zone;
970
+
971
+		if (!$total_entries) {
972
+			$default_css_class .= ' gv-widgets-no-results';
973
+		}
974
+
975
+		/**
976
+		 * @filter `gravityview/widgets/wrapper_css_class` The CSS class applied to the widget container `<div>`.
977
+		 *
978
+		 * @since 1.16.2
979
+		 *
980
+		 * @param string $css_class Default: `gv-grid gv-widgets-{zone}` where `{zone}` is replaced by the current `$zone` value. If the View has no results, adds ` gv-widgets-no-results`
981
+		 * @param string $zone      Current widget zone, either `header` or `footer`
982
+		 * @param array  $widgets   Array of widget configurations for the current zone, as set by `gravityview_get_current_view_data()['widgets']`
983
+		 */
984
+		$css_class = apply_filters('gravityview/widgets/wrapper_css_class', $default_css_class, $zone, $widgets->as_configuration());
985
+
986
+		$css_class = gravityview_sanitize_html_class($css_class);
987
+
988
+		// TODO Convert to partials?>
989 989
 		<div class="<?php echo $css_class; ?>">
990 990
 			<?php
991
-            foreach ($rows as $row) {
992
-                foreach ($row as $col => $areas) {
993
-                    $column = ($col == '2-2') ? '1-2 gv-right' : "$col gv-left"; ?>
991
+			foreach ($rows as $row) {
992
+				foreach ($row as $col => $areas) {
993
+					$column = ($col == '2-2') ? '1-2 gv-right' : "$col gv-left"; ?>
994 994
 					<div class="gv-grid-col-<?php echo esc_attr($column); ?>">
995 995
 						<?php
996
-                        if (!empty($areas)) {
997
-                            foreach ($areas as $area) {
998
-                                foreach ($widgets->by_position($zone.'_'.$area['areaid'])->all() as $widget) {
999
-                                    do_action(sprintf('gravityview/widgets/%s/render', $widget->get_widget_id()), $widget->configuration->all(), null, $view_id_or_context);
1000
-                                }
1001
-                            }
1002
-                        } ?>
996
+						if (!empty($areas)) {
997
+							foreach ($areas as $area) {
998
+								foreach ($widgets->by_position($zone.'_'.$area['areaid'])->all() as $widget) {
999
+									do_action(sprintf('gravityview/widgets/%s/render', $widget->get_widget_id()), $widget->configuration->all(), null, $view_id_or_context);
1000
+								}
1001
+							}
1002
+						} ?>
1003 1003
 					</div>
1004 1004
 				<?php
1005
-                } // $row?>
1005
+				} // $row?>
1006 1006
 			<?php
1007
-            } // $rows?>
1007
+			} // $rows?>
1008 1008
 		</div>
1009 1009
 
1010 1010
 		<?php
1011 1011
 
1012
-        /**
1013
-         * Prevent widgets from being called twice.
1014
-         * Checking for loop_start prevents themes and plugins that pre-process shortcodes from triggering the action before displaying. Like, ahem, the Divi theme and WordPress SEO plugin.
1015
-         */
1016
-        if (did_action('wp_head')) {
1017
-            do_action("gravityview/widgets/$zone/{$view->ID}/rendered");
1018
-        }
1019
-    }
1020
-
1021
-    /**
1022
-     * Include a file inside this context.
1023
-     *
1024
-     * @param string $path A path to the legacy template to include.
1025
-     *
1026
-     * @return void
1027
-     */
1028
-    public function _include($path)
1029
-    {
1030
-        if (file_exists($path)) {
1031
-            include $path;
1032
-        }
1033
-    }
1012
+		/**
1013
+		 * Prevent widgets from being called twice.
1014
+		 * Checking for loop_start prevents themes and plugins that pre-process shortcodes from triggering the action before displaying. Like, ahem, the Divi theme and WordPress SEO plugin.
1015
+		 */
1016
+		if (did_action('wp_head')) {
1017
+			do_action("gravityview/widgets/$zone/{$view->ID}/rendered");
1018
+		}
1019
+	}
1020
+
1021
+	/**
1022
+	 * Include a file inside this context.
1023
+	 *
1024
+	 * @param string $path A path to the legacy template to include.
1025
+	 *
1026
+	 * @return void
1027
+	 */
1028
+	public function _include($path)
1029
+	{
1030
+		if (file_exists($path)) {
1031
+			include $path;
1032
+		}
1033
+	}
1034 1034
 }
Please login to merge, or discard this patch.
Spacing   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 /** If this file is called directly, abort. */
16
-if (!defined('ABSPATH')) {
16
+if ( ! defined( 'ABSPATH' ) ) {
17 17
     exit;
18 18
 }
19 19
 
20
-if (!class_exists('\GV\Gamajo_Template_Loader')) {
21
-    require GRAVITYVIEW_DIR.'future/lib/class-gamajo-template-loader.php';
20
+if ( ! class_exists( '\GV\Gamajo_Template_Loader' ) ) {
21
+    require GRAVITYVIEW_DIR . 'future/lib/class-gamajo-template-loader.php';
22 22
 }
23 23
 
24 24
 class GravityView_View extends \GV\Gamajo_Template_Loader
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      *
50 50
      * @var array
51 51
      */
52
-    protected $located_templates = [];
52
+    protected $located_templates = [ ];
53 53
 
54 54
     /**
55 55
      * The name of the template, like "list", "table", or "datatables".
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     /**
80 80
      * @var array Fields for the form
81 81
      */
82
-    protected $fields = [];
82
+    protected $fields = [ ];
83 83
 
84 84
     /**
85 85
      * @var string Current screen. Defaults to "directory" or "single"
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
     /**
100 100
      * @var array Configuration for the View
101 101
      */
102
-    protected $atts = [];
102
+    protected $atts = [ ];
103 103
 
104 104
     /**
105 105
      * @var array Entries for the current result. Single item in array for single entry View
106 106
      */
107
-    protected $entries = [];
107
+    protected $entries = [ ];
108 108
 
109 109
     /**
110 110
      * @var int Total entries count for the current result.
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
     /**
120 120
      * @var array Array with `offset` and `page_size` keys
121 121
      */
122
-    protected $paging = [];
122
+    protected $paging = [ ];
123 123
 
124 124
     /**
125 125
      * @var array Array with `sort_field` and `sort_direction` keys
126 126
      */
127
-    protected $sorting = [];
127
+    protected $sorting = [ ];
128 128
 
129 129
     /**
130 130
      * @var bool Whether to hide the results until a search is performed
@@ -138,12 +138,12 @@  discard block
 block discarded – undo
138 138
      *
139 139
      * @var array
140 140
      */
141
-    protected $_current_entry = [];
141
+    protected $_current_entry = [ ];
142 142
 
143 143
     /**
144 144
      * @var array
145 145
      */
146
-    protected $_current_field = [];
146
+    protected $_current_field = [ ];
147 147
 
148 148
     /**
149 149
      * @var GravityView_View $instance
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
      *
156 156
      * @param array $atts Associative array to set the data of
157 157
      */
158
-    public function __construct($atts = [])
158
+    public function __construct( $atts = [ ] )
159 159
     {
160
-        $atts = wp_parse_args($atts, [
160
+        $atts = wp_parse_args( $atts, [
161 161
             'form_id' => null,
162 162
             'view_id' => null,
163 163
             'fields'  => null,
@@ -165,28 +165,28 @@  discard block
 block discarded – undo
165 165
             'post_id' => null,
166 166
             'form'    => null,
167 167
             'atts'	   => null,
168
-        ]);
168
+        ] );
169 169
 
170
-        foreach ($atts as $key => $value) {
171
-            if (is_null($value)) {
170
+        foreach ( $atts as $key => $value ) {
171
+            if ( is_null( $value ) ) {
172 172
                 continue;
173 173
             }
174 174
             $this->{$key} = $value;
175 175
         }
176 176
 
177 177
         // Add granular overrides
178
-        add_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates'], 10, 3);
178
+        add_filter( $this->filter_prefix . '_get_template_part', [ $this, 'add_id_specific_templates' ], 10, 3 );
179 179
 
180 180
         // widget logic
181
-        add_action('gravityview/template/before', [$this, 'render_widget_hooks']);
182
-        add_action('gravityview/template/after', [$this, 'render_widget_hooks']);
181
+        add_action( 'gravityview/template/before', [ $this, 'render_widget_hooks' ] );
182
+        add_action( 'gravityview/template/after', [ $this, 'render_widget_hooks' ] );
183 183
 
184 184
         /**
185 185
          * Clear the current entry after the loop is done.
186 186
          *
187 187
          * @since 1.7.3
188 188
          */
189
-        add_action('gravityview_footer', [$this, 'clearCurrentEntry'], 500);
189
+        add_action( 'gravityview_footer', [ $this, 'clearCurrentEntry' ], 500 );
190 190
 
191 191
         self::$instance = &$this;
192 192
     }
@@ -196,10 +196,10 @@  discard block
 block discarded – undo
196 196
      *
197 197
      * @return GravityView_View
198 198
      */
199
-    public static function getInstance($passed_post = null)
199
+    public static function getInstance( $passed_post = null )
200 200
     {
201
-        if (empty(self::$instance)) {
202
-            self::$instance = new self($passed_post);
201
+        if ( empty( self::$instance ) ) {
202
+            self::$instance = new self( $passed_post );
203 203
         }
204 204
 
205 205
         return self::$instance;
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
      *
211 211
      * @return array|mixed|null If $key is set and attribute exists at $key, return that. If not set, return NULL. Otherwise, return current field array
212 212
      */
213
-    public function getCurrentField($key = null)
213
+    public function getCurrentField( $key = null )
214 214
     {
215
-        if (!empty($key)) {
216
-            if (isset($this->_current_field[$key])) {
217
-                return $this->_current_field[$key];
215
+        if ( ! empty( $key ) ) {
216
+            if ( isset( $this->_current_field[ $key ] ) ) {
217
+                return $this->_current_field[ $key ];
218 218
             }
219 219
 
220 220
             return null;
@@ -223,19 +223,19 @@  discard block
 block discarded – undo
223 223
         return $this->_current_field;
224 224
     }
225 225
 
226
-    public function setCurrentFieldSetting($key, $value)
226
+    public function setCurrentFieldSetting( $key, $value )
227 227
     {
228
-        if (!empty($this->_current_field)) {
229
-            $this->_current_field['field_settings'][$key] = $value;
228
+        if ( ! empty( $this->_current_field ) ) {
229
+            $this->_current_field[ 'field_settings' ][ $key ] = $value;
230 230
         }
231 231
     }
232 232
 
233
-    public function getCurrentFieldSetting($key)
233
+    public function getCurrentFieldSetting( $key )
234 234
     {
235
-        $settings = $this->getCurrentField('field_settings');
235
+        $settings = $this->getCurrentField( 'field_settings' );
236 236
 
237
-        if ($settings && !empty($settings[$key])) {
238
-            return $settings[$key];
237
+        if ( $settings && ! empty( $settings[ $key ] ) ) {
238
+            return $settings[ $key ];
239 239
         }
240 240
 
241 241
         return null;
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
     /**
245 245
      * @param array $passed_field
246 246
      */
247
-    public function setCurrentField($passed_field)
247
+    public function setCurrentField( $passed_field )
248 248
     {
249 249
         $existing_field = $this->getCurrentField();
250 250
 
251
-        $set_field = wp_parse_args($passed_field, $existing_field);
251
+        $set_field = wp_parse_args( $passed_field, $existing_field );
252 252
 
253 253
         $this->_current_field = $set_field;
254 254
 
@@ -265,11 +265,11 @@  discard block
 block discarded – undo
265 265
      *
266 266
      * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
267 267
      */
268
-    public function getAtts($key = null)
268
+    public function getAtts( $key = null )
269 269
     {
270
-        if (!empty($key)) {
271
-            if (isset($this->atts[$key])) {
272
-                return $this->atts[$key];
270
+        if ( ! empty( $key ) ) {
271
+            if ( isset( $this->atts[ $key ] ) ) {
272
+                return $this->atts[ $key ];
273 273
             }
274 274
 
275 275
             return null;
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
     /**
282 282
      * @param array $atts
283 283
      */
284
-    public function setAtts($atts)
284
+    public function setAtts( $atts )
285 285
     {
286 286
         $this->atts = $atts;
287 287
     }
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     /**
298 298
      * @param array $form
299 299
      */
300
-    public function setForm($form)
300
+    public function setForm( $form )
301 301
     {
302 302
         $this->form = $form;
303 303
     }
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
     /**
314 314
      * @param int|null $post_id
315 315
      */
316
-    public function setPostId($post_id)
316
+    public function setPostId( $post_id )
317 317
     {
318 318
         $this->post_id = $post_id;
319 319
     }
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
     /**
330 330
      * @param string $context
331 331
      */
332
-    public function setContext($context)
332
+    public function setContext( $context )
333 333
     {
334 334
         $this->context = $context;
335 335
     }
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
      *
340 340
      * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
341 341
      */
342
-    public function getFields($key = null)
342
+    public function getFields( $key = null )
343 343
     {
344
-        $fields = empty($this->fields) ? null : $this->fields;
344
+        $fields = empty( $this->fields ) ? null : $this->fields;
345 345
 
346
-        if ($fields && !empty($key)) {
347
-            $fields = isset($fields[$key]) ? $fields[$key] : null;
346
+        if ( $fields && ! empty( $key ) ) {
347
+            $fields = isset( $fields[ $key ] ) ? $fields[ $key ] : null;
348 348
         }
349 349
 
350 350
         return $fields;
@@ -359,31 +359,31 @@  discard block
 block discarded – undo
359 359
      *
360 360
      * @return array Array of GravityView field layout configurations
361 361
      */
362
-    public function getContextFields($context = '')
362
+    public function getContextFields( $context = '' )
363 363
     {
364
-        if ('' === $context) {
364
+        if ( '' === $context ) {
365 365
             $context = $this->getContext();
366 366
         }
367 367
 
368 368
         $fields = $this->getFields();
369 369
 
370
-        foreach ((array) $fields as $key => $context_fields) {
370
+        foreach ( (array)$fields as $key => $context_fields ) {
371 371
 
372 372
             // Formatted as `{context}_{template id}-{zone name}`, so we want just the $context to match against
373
-            $matches = explode('_', $key);
373
+            $matches = explode( '_', $key );
374 374
 
375
-            if (isset($matches[0]) && $matches[0] === $context) {
375
+            if ( isset( $matches[ 0 ] ) && $matches[ 0 ] === $context ) {
376 376
                 return $context_fields;
377 377
             }
378 378
         }
379 379
 
380
-        return [];
380
+        return [ ];
381 381
     }
382 382
 
383 383
     /**
384 384
      * @param array $fields
385 385
      */
386
-    public function setFields($fields)
386
+    public function setFields( $fields )
387 387
     {
388 388
         $this->fields = $fields;
389 389
     }
@@ -393,11 +393,11 @@  discard block
 block discarded – undo
393 393
      *
394 394
      * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
395 395
      */
396
-    public function getField($key)
396
+    public function getField( $key )
397 397
     {
398
-        if (!empty($key)) {
399
-            if (isset($this->fields[$key])) {
400
-                return $this->fields[$key];
398
+        if ( ! empty( $key ) ) {
399
+            if ( isset( $this->fields[ $key ] ) ) {
400
+                return $this->fields[ $key ];
401 401
             }
402 402
         }
403 403
 
@@ -408,9 +408,9 @@  discard block
 block discarded – undo
408 408
      * @param string $key   The key to a specific field in the fields array
409 409
      * @param mixed  $value The value to set for the field
410 410
      */
411
-    public function setField($key, $value)
411
+    public function setField( $key, $value )
412 412
     {
413
-        $this->fields[$key] = $value;
413
+        $this->fields[ $key ] = $value;
414 414
     }
415 415
 
416 416
     /**
@@ -418,15 +418,15 @@  discard block
 block discarded – undo
418 418
      */
419 419
     public function getViewId()
420 420
     {
421
-        return absint($this->view_id);
421
+        return absint( $this->view_id );
422 422
     }
423 423
 
424 424
     /**
425 425
      * @param int $view_id
426 426
      */
427
-    public function setViewId($view_id)
427
+    public function setViewId( $view_id )
428 428
     {
429
-        $this->view_id = intval($view_id);
429
+        $this->view_id = intval( $view_id );
430 430
     }
431 431
 
432 432
     /**
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
     /**
441 441
      * @param int $form_id
442 442
      */
443
-    public function setFormId($form_id)
443
+    public function setFormId( $form_id )
444 444
     {
445 445
         $this->form_id = $form_id;
446 446
     }
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
     /**
457 457
      * @param array $entries
458 458
      */
459
-    public function setEntries($entries)
459
+    public function setEntries( $entries )
460 460
     {
461 461
         $this->entries = $entries;
462 462
     }
@@ -466,15 +466,15 @@  discard block
 block discarded – undo
466 466
      */
467 467
     public function getTotalEntries()
468 468
     {
469
-        return (int) $this->total_entries;
469
+        return (int)$this->total_entries;
470 470
     }
471 471
 
472 472
     /**
473 473
      * @param int $total_entries
474 474
      */
475
-    public function setTotalEntries($total_entries)
475
+    public function setTotalEntries( $total_entries )
476 476
     {
477
-        $this->total_entries = intval($total_entries);
477
+        $this->total_entries = intval( $total_entries );
478 478
     }
479 479
 
480 480
     /**
@@ -487,13 +487,13 @@  discard block
 block discarded – undo
487 487
             'page_size' => 20,
488 488
         ];
489 489
 
490
-        return wp_parse_args($this->paging, $default_params);
490
+        return wp_parse_args( $this->paging, $default_params );
491 491
     }
492 492
 
493 493
     /**
494 494
      * @param array $paging
495 495
      */
496
-    public function setPaging($paging)
496
+    public function setPaging( $paging )
497 497
     {
498 498
         $this->paging = $paging;
499 499
     }
@@ -513,20 +513,20 @@  discard block
 block discarded – undo
513 513
     public function getPaginationCounts()
514 514
     {
515 515
         $paging = $this->getPaging();
516
-        $offset = $paging['offset'];
517
-        $page_size = $paging['page_size'];
516
+        $offset = $paging[ 'offset' ];
517
+        $page_size = $paging[ 'page_size' ];
518 518
         $total = $this->getTotalEntries();
519 519
 
520
-        if (empty($total)) {
521
-            gravityview()->log->debug('No entries. Returning empty array.');
520
+        if ( empty( $total ) ) {
521
+            gravityview()->log->debug( 'No entries. Returning empty array.' );
522 522
 
523
-            return [];
523
+            return [ ];
524 524
         }
525 525
 
526
-        $first = empty($offset) ? 1 : $offset + 1;
526
+        $first = empty( $offset ) ? 1 : $offset + 1;
527 527
 
528 528
         // If the page size + starting entry is larger than total, the total is the max.
529
-        $last = ($offset + $page_size > $total) ? $total : $offset + $page_size;
529
+        $last = ( $offset + $page_size > $total ) ? $total : $offset + $page_size;
530 530
 
531 531
         /**
532 532
          * @filter `gravityview_pagination_counts` Modify the displayed pagination numbers
@@ -535,9 +535,9 @@  discard block
 block discarded – undo
535 535
          *
536 536
          * @param array $counts Array with $first, $last, $total numbers in that order
537 537
          */
538
-        list($first, $last, $total) = apply_filters('gravityview_pagination_counts', [$first, $last, $total]);
538
+        list( $first, $last, $total ) = apply_filters( 'gravityview_pagination_counts', [ $first, $last, $total ] );
539 539
 
540
-        return ['first' => (int) $first, 'last' => (int) $last, 'total' => (int) $total];
540
+        return [ 'first' => (int)$first, 'last' => (int)$last, 'total' => (int)$total ];
541 541
     }
542 542
 
543 543
     /**
@@ -551,13 +551,13 @@  discard block
 block discarded – undo
551 551
             'is_numeric'     => false,
552 552
         ];
553 553
 
554
-        return wp_parse_args($this->sorting, $defaults_params);
554
+        return wp_parse_args( $this->sorting, $defaults_params );
555 555
     }
556 556
 
557 557
     /**
558 558
      * @param array $sorting
559 559
      */
560
-    public function setSorting($sorting)
560
+    public function setSorting( $sorting )
561 561
     {
562 562
         $this->sorting = $sorting;
563 563
     }
@@ -570,12 +570,12 @@  discard block
 block discarded – undo
570 570
      *
571 571
      * @return string
572 572
      */
573
-    public function getBackLinkLabel($do_replace = true)
573
+    public function getBackLinkLabel( $do_replace = true )
574 574
     {
575
-        if ($do_replace) {
576
-            $back_link_label = GravityView_API::replace_variables($this->back_link_label, $this->getForm(), $this->getCurrentEntry());
575
+        if ( $do_replace ) {
576
+            $back_link_label = GravityView_API::replace_variables( $this->back_link_label, $this->getForm(), $this->getCurrentEntry() );
577 577
 
578
-            return do_shortcode($back_link_label);
578
+            return do_shortcode( $back_link_label );
579 579
         }
580 580
 
581 581
         return $this->back_link_label;
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
     /**
585 585
      * @param string $back_link_label
586 586
      */
587
-    public function setBackLinkLabel($back_link_label)
587
+    public function setBackLinkLabel( $back_link_label )
588 588
     {
589 589
         $this->back_link_label = $back_link_label;
590 590
     }
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
     /**
601 601
      * @param bool $hide_until_searched
602 602
      */
603
-    public function setHideUntilSearched($hide_until_searched)
603
+    public function setHideUntilSearched( $hide_until_searched )
604 604
     {
605 605
         $this->hide_until_searched = $hide_until_searched;
606 606
     }
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
     /**
617 617
      * @param string $template_part_slug
618 618
      */
619
-    public function setTemplatePartSlug($template_part_slug)
619
+    public function setTemplatePartSlug( $template_part_slug )
620 620
     {
621 621
         $this->template_part_slug = $template_part_slug;
622 622
     }
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
     /**
633 633
      * @param string $template_part_name
634 634
      */
635
-    public function setTemplatePartName($template_part_name)
635
+    public function setTemplatePartName( $template_part_name )
636 636
     {
637 637
         $this->template_part_name = $template_part_name;
638 638
     }
@@ -644,16 +644,16 @@  discard block
 block discarded – undo
644 644
      */
645 645
     public function getCurrentEntry()
646 646
     {
647
-        if (in_array($this->getContext(), ['edit', 'single'])) {
647
+        if ( in_array( $this->getContext(), [ 'edit', 'single' ] ) ) {
648 648
             $entries = $this->getEntries();
649
-            $entry = $entries[0];
649
+            $entry = $entries[ 0 ];
650 650
         } else {
651 651
             $entry = $this->_current_entry;
652 652
         }
653 653
 
654 654
         /** @since 1.16 Fixes DataTables empty entry issue */
655
-        if (empty($entry) && !empty($this->_current_field['entry'])) {
656
-            $entry = $this->_current_field['entry'];
655
+        if ( empty( $entry ) && ! empty( $this->_current_field[ 'entry' ] ) ) {
656
+            $entry = $this->_current_field[ 'entry' ];
657 657
         }
658 658
 
659 659
         return $entry;
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
      *
665 665
      * @return void
666 666
      */
667
-    public function setCurrentEntry($current_entry)
667
+    public function setCurrentEntry( $current_entry )
668 668
     {
669 669
         $this->_current_entry = $current_entry;
670 670
     }
@@ -694,10 +694,10 @@  discard block
 block discarded – undo
694 694
      *
695 695
      * @return string|null
696 696
      */
697
-    public function renderZone($zone = '', $atts = [], $echo = true)
697
+    public function renderZone( $zone = '', $atts = [ ], $echo = true )
698 698
     {
699
-        if (empty($zone)) {
700
-            gravityview()->log->error('No zone defined.');
699
+        if ( empty( $zone ) ) {
700
+            gravityview()->log->error( 'No zone defined.' );
701 701
 
702 702
             return null;
703 703
         }
@@ -707,19 +707,19 @@  discard block
 block discarded – undo
707 707
             'context'    => $this->getContext(),
708 708
             'entry'      => $this->getCurrentEntry(),
709 709
             'form'       => $this->getForm(),
710
-            'hide_empty' => $this->getAtts('hide_empty'),
710
+            'hide_empty' => $this->getAtts( 'hide_empty' ),
711 711
         ];
712 712
 
713
-        $final_atts = wp_parse_args($atts, $defaults);
713
+        $final_atts = wp_parse_args( $atts, $defaults );
714 714
 
715 715
         $output = '';
716 716
 
717
-        $final_atts['zone_id'] = "{$final_atts['context']}_{$final_atts['slug']}-{$zone}";
717
+        $final_atts[ 'zone_id' ] = "{$final_atts[ 'context' ]}_{$final_atts[ 'slug' ]}-{$zone}";
718 718
 
719
-        $fields = $this->getField($final_atts['zone_id']);
719
+        $fields = $this->getField( $final_atts[ 'zone_id' ] );
720 720
 
721 721
         // Backward compatibility
722
-        if ('table' === $this->getTemplatePartSlug()) {
722
+        if ( 'table' === $this->getTemplatePartSlug() ) {
723 723
             /**
724 724
              * @filter `gravityview_table_cells` Modify the fields displayed in a table
725 725
              *
@@ -728,20 +728,20 @@  discard block
 block discarded – undo
728 728
              *
729 729
              * @deprecated Use `gravityview/template/table/fields`
730 730
              */
731
-            $fields = apply_filters('gravityview_table_cells', $fields, $this);
731
+            $fields = apply_filters( 'gravityview_table_cells', $fields, $this );
732 732
         }
733 733
 
734
-        if (empty($fields)) {
735
-            gravityview()->log->error('Empty zone configuration for {zone_id}.', ['zone_id' => $final_atts['zone_id']]);
734
+        if ( empty( $fields ) ) {
735
+            gravityview()->log->error( 'Empty zone configuration for {zone_id}.', [ 'zone_id' => $final_atts[ 'zone_id' ] ] );
736 736
 
737 737
             return null;
738 738
         }
739 739
 
740 740
         $field_output = '';
741
-        foreach ($fields as $field) {
742
-            $final_atts['field'] = $field;
741
+        foreach ( $fields as $field ) {
742
+            $final_atts[ 'field' ] = $field;
743 743
 
744
-            $field_output .= gravityview_field_output($final_atts);
744
+            $field_output .= gravityview_field_output( $final_atts );
745 745
         }
746 746
 
747 747
         /**
@@ -756,21 +756,21 @@  discard block
 block discarded – undo
756 756
          *
757 757
          * @param \GV\Template_Context $context The context. Null here. Since this path is deprecated.
758 758
          */
759
-        if (empty($field_output) && apply_filters('gravityview/render/hide-empty-zone', false, null)) {
759
+        if ( empty( $field_output ) && apply_filters( 'gravityview/render/hide-empty-zone', false, null ) ) {
760 760
             return null;
761 761
         }
762 762
 
763
-        if (!empty($final_atts['wrapper_class'])) {
764
-            $output .= '<div class="'.gravityview_sanitize_html_class($final_atts['wrapper_class']).'">';
763
+        if ( ! empty( $final_atts[ 'wrapper_class' ] ) ) {
764
+            $output .= '<div class="' . gravityview_sanitize_html_class( $final_atts[ 'wrapper_class' ] ) . '">';
765 765
         }
766 766
 
767 767
         $output .= $field_output;
768 768
 
769
-        if (!empty($final_atts['wrapper_class'])) {
769
+        if ( ! empty( $final_atts[ 'wrapper_class' ] ) ) {
770 770
             $output .= '</div>';
771 771
         }
772 772
 
773
-        if ($echo) {
773
+        if ( $echo ) {
774 774
             echo $output;
775 775
         }
776 776
 
@@ -788,22 +788,22 @@  discard block
 block discarded – undo
788 788
      *
789 789
      * @return null|string NULL: Template not found; String: path to template
790 790
      */
791
-    public function locate_template($template_names, $load = false, $require_once = true)
791
+    public function locate_template( $template_names, $load = false, $require_once = true )
792 792
     {
793
-        if (is_string($template_names) && isset($this->located_templates[$template_names])) {
794
-            $located = $this->located_templates[$template_names];
793
+        if ( is_string( $template_names ) && isset( $this->located_templates[ $template_names ] ) ) {
794
+            $located = $this->located_templates[ $template_names ];
795 795
         } else {
796 796
 
797 797
             // Set $load to always false so we handle it here.
798
-            $located = parent::locate_template($template_names, false, $require_once);
798
+            $located = parent::locate_template( $template_names, false, $require_once );
799 799
 
800
-            if (is_string($template_names)) {
801
-                $this->located_templates[$template_names] = $located;
800
+            if ( is_string( $template_names ) ) {
801
+                $this->located_templates[ $template_names ] = $located;
802 802
             }
803 803
         }
804 804
 
805
-        if ($load && $located) {
806
-            load_template($located, $require_once);
805
+        if ( $load && $located ) {
806
+            load_template( $located, $require_once );
807 807
         }
808 808
 
809 809
         return $located;
@@ -816,9 +816,9 @@  discard block
 block discarded – undo
816 816
      *
817 817
      * @return mixed|null The stored data.
818 818
      */
819
-    public function __get($name)
819
+    public function __get( $name )
820 820
     {
821
-        if (isset($this->{$name})) {
821
+        if ( isset( $this->{$name}) ) {
822 822
             return $this->{$name};
823 823
         } else {
824 824
             return null;
@@ -843,45 +843,45 @@  discard block
 block discarded – undo
843 843
      *
844 844
      * @return array $templates Modified template array, merged with existing $templates values
845 845
      */
846
-    public function add_id_specific_templates($templates, $slug, $name)
846
+    public function add_id_specific_templates( $templates, $slug, $name )
847 847
     {
848
-        $additional = [];
848
+        $additional = [ ];
849 849
 
850 850
         // form-19-table-body.php
851
-        $additional[] = sprintf('form-%d-%s-%s.php', $this->getFormId(), $slug, $name);
851
+        $additional[ ] = sprintf( 'form-%d-%s-%s.php', $this->getFormId(), $slug, $name );
852 852
 
853
-        if ($view_id = $this->getViewId()) {
853
+        if ( $view_id = $this->getViewId() ) {
854 854
             // view-3-table-body.php
855
-            $additional[] = sprintf('view-%d-%s-%s.php', $view_id, $slug, $name);
855
+            $additional[ ] = sprintf( 'view-%d-%s-%s.php', $view_id, $slug, $name );
856 856
         }
857 857
 
858
-        if ($this->getPostId()) {
858
+        if ( $this->getPostId() ) {
859 859
 
860 860
             // page-19-table-body.php
861
-            $additional[] = sprintf('page-%d-%s-%s.php', $this->getPostId(), $slug, $name);
861
+            $additional[ ] = sprintf( 'page-%d-%s-%s.php', $this->getPostId(), $slug, $name );
862 862
         }
863 863
 
864 864
         // Combine with existing table-body.php and table.php
865
-        $templates = array_merge($additional, $templates);
865
+        $templates = array_merge( $additional, $templates );
866 866
 
867
-        gravityview()->log->debug('List of Template Files', ['data' => $templates]);
867
+        gravityview()->log->debug( 'List of Template Files', [ 'data' => $templates ] );
868 868
 
869 869
         return $templates;
870 870
     }
871 871
 
872 872
     // Load the template
873
-    public function render($slug, $name, $require_once = true)
873
+    public function render( $slug, $name, $require_once = true )
874 874
     {
875
-        $this->setTemplatePartSlug($slug);
875
+        $this->setTemplatePartSlug( $slug );
876 876
 
877
-        $this->setTemplatePartName($name);
877
+        $this->setTemplatePartName( $name );
878 878
 
879
-        $template_file = $this->get_template_part($slug, $name, false);
879
+        $template_file = $this->get_template_part( $slug, $name, false );
880 880
 
881
-        gravityview()->log->debug('Rendering Template File: {path}', ['path' => $template_file]);
881
+        gravityview()->log->debug( 'Rendering Template File: {path}', [ 'path' => $template_file ] );
882 882
 
883
-        if (!empty($template_file)) {
884
-            if ($require_once) {
883
+        if ( ! empty( $template_file ) ) {
884
+            if ( $require_once ) {
885 885
                 require_once $template_file;
886 886
             } else {
887 887
                 require $template_file;
@@ -896,40 +896,40 @@  discard block
 block discarded – undo
896 896
      *
897 897
      * @return void
898 898
      */
899
-    public function render_widget_hooks($view_id_or_context)
899
+    public function render_widget_hooks( $view_id_or_context )
900 900
     {
901 901
 
902 902
         /**
903 903
          * @deprecated Numeric argument is deprecated. Pass a \GV\Template_Context instead.
904 904
          */
905
-        if (is_numeric($view_id_or_context)) {
906
-            $view = \GV\View::by_id($view_id_or_context);
905
+        if ( is_numeric( $view_id_or_context ) ) {
906
+            $view = \GV\View::by_id( $view_id_or_context );
907 907
             $is_single = gravityview_get_context() == 'single';
908 908
             $total_entries = GravityView_View::getInstance()->getTotalEntries();
909 909
 
910 910
             /**
911 911
              * Fake new context for legacy template code.
912 912
              */
913
-            $view_id_or_context = \GV\Template_Context::from_template([
913
+            $view_id_or_context = \GV\Template_Context::from_template( [
914 914
                 'view' => $view,
915
-            ]);
916
-        } elseif ($view_id_or_context instanceof \GV\Template_Context) {
915
+            ] );
916
+        } elseif ( $view_id_or_context instanceof \GV\Template_Context ) {
917 917
             $view = $view_id_or_context->view;
918
-            $is_single = (bool) $view_id_or_context->request->is_entry();
918
+            $is_single = (bool)$view_id_or_context->request->is_entry();
919 919
             $total_entries = $view_id_or_context->entries ? $view_id_or_context->entries->count() : 0;
920 920
         } else {
921
-            gravityview()->log->error('No View ID or template context provided to render_widget_hooks');
921
+            gravityview()->log->error( 'No View ID or template context provided to render_widget_hooks' );
922 922
 
923 923
             return;
924 924
         }
925 925
 
926
-        if ($is_single) {
927
-            gravityview()->log->debug('Not rendering widgets; single entry');
926
+        if ( $is_single ) {
927
+            gravityview()->log->debug( 'Not rendering widgets; single entry' );
928 928
 
929 929
             return;
930 930
         }
931 931
 
932
-        switch (current_filter()) {
932
+        switch ( current_filter() ) {
933 933
             default:
934 934
             case 'gravityview/template/before':
935 935
             case 'gravityview_before':
@@ -941,22 +941,22 @@  discard block
 block discarded – undo
941 941
                 break;
942 942
         }
943 943
 
944
-        $widgets = $view->widgets->by_position("$zone*");
944
+        $widgets = $view->widgets->by_position( "$zone*" );
945 945
 
946 946
         /**
947 947
          * Prevent output if no widgets to show.
948 948
          *
949 949
          * @since 1.16
950 950
          */
951
-        if (!$widgets->count()) {
952
-            gravityview()->log->debug('No widgets for View #{view_id} in zone {zone}', ['view_id' => $view->ID, 'zone' => $zone]);
951
+        if ( ! $widgets->count() ) {
952
+            gravityview()->log->debug( 'No widgets for View #{view_id} in zone {zone}', [ 'view_id' => $view->ID, 'zone' => $zone ] );
953 953
 
954 954
             return;
955 955
         }
956 956
 
957 957
         // Prevent being called twice
958
-        if (did_action("gravityview/widgets/$zone/{$view->ID}/rendered")) {
959
-            gravityview()->log->debug('Not rendering {zone}; already rendered', ['zone' => $zone.'_'.$view->ID.'_widgets']);
958
+        if ( did_action( "gravityview/widgets/$zone/{$view->ID}/rendered" ) ) {
959
+            gravityview()->log->debug( 'Not rendering {zone}; already rendered', [ 'zone' => $zone . '_' . $view->ID . '_widgets' ] );
960 960
 
961 961
             return;
962 962
         }
@@ -964,11 +964,11 @@  discard block
 block discarded – undo
964 964
         $rows = \GV\Widget::get_default_widget_areas();
965 965
 
966 966
         // TODO: Move to sep. method, use an action instead
967
-        wp_enqueue_style('gravityview_default_style');
967
+        wp_enqueue_style( 'gravityview_default_style' );
968 968
 
969
-        $default_css_class = 'gv-grid gv-widgets-'.$zone;
969
+        $default_css_class = 'gv-grid gv-widgets-' . $zone;
970 970
 
971
-        if (!$total_entries) {
971
+        if ( ! $total_entries ) {
972 972
             $default_css_class .= ' gv-widgets-no-results';
973 973
         }
974 974
 
@@ -981,22 +981,22 @@  discard block
 block discarded – undo
981 981
          * @param string $zone      Current widget zone, either `header` or `footer`
982 982
          * @param array  $widgets   Array of widget configurations for the current zone, as set by `gravityview_get_current_view_data()['widgets']`
983 983
          */
984
-        $css_class = apply_filters('gravityview/widgets/wrapper_css_class', $default_css_class, $zone, $widgets->as_configuration());
984
+        $css_class = apply_filters( 'gravityview/widgets/wrapper_css_class', $default_css_class, $zone, $widgets->as_configuration() );
985 985
 
986
-        $css_class = gravityview_sanitize_html_class($css_class);
986
+        $css_class = gravityview_sanitize_html_class( $css_class );
987 987
 
988 988
         // TODO Convert to partials?>
989 989
 		<div class="<?php echo $css_class; ?>">
990 990
 			<?php
991
-            foreach ($rows as $row) {
992
-                foreach ($row as $col => $areas) {
993
-                    $column = ($col == '2-2') ? '1-2 gv-right' : "$col gv-left"; ?>
994
-					<div class="gv-grid-col-<?php echo esc_attr($column); ?>">
991
+            foreach ( $rows as $row ) {
992
+                foreach ( $row as $col => $areas ) {
993
+                    $column = ( $col == '2-2' ) ? '1-2 gv-right' : "$col gv-left"; ?>
994
+					<div class="gv-grid-col-<?php echo esc_attr( $column ); ?>">
995 995
 						<?php
996
-                        if (!empty($areas)) {
997
-                            foreach ($areas as $area) {
998
-                                foreach ($widgets->by_position($zone.'_'.$area['areaid'])->all() as $widget) {
999
-                                    do_action(sprintf('gravityview/widgets/%s/render', $widget->get_widget_id()), $widget->configuration->all(), null, $view_id_or_context);
996
+                        if ( ! empty( $areas ) ) {
997
+                            foreach ( $areas as $area ) {
998
+                                foreach ( $widgets->by_position( $zone . '_' . $area[ 'areaid' ] )->all() as $widget ) {
999
+                                    do_action( sprintf( 'gravityview/widgets/%s/render', $widget->get_widget_id() ), $widget->configuration->all(), null, $view_id_or_context );
1000 1000
                                 }
1001 1001
                             }
1002 1002
                         } ?>
@@ -1013,8 +1013,8 @@  discard block
 block discarded – undo
1013 1013
          * Prevent widgets from being called twice.
1014 1014
          * Checking for loop_start prevents themes and plugins that pre-process shortcodes from triggering the action before displaying. Like, ahem, the Divi theme and WordPress SEO plugin.
1015 1015
          */
1016
-        if (did_action('wp_head')) {
1017
-            do_action("gravityview/widgets/$zone/{$view->ID}/rendered");
1016
+        if ( did_action( 'wp_head' ) ) {
1017
+            do_action( "gravityview/widgets/$zone/{$view->ID}/rendered" );
1018 1018
         }
1019 1019
     }
1020 1020
 
@@ -1025,9 +1025,9 @@  discard block
 block discarded – undo
1025 1025
      *
1026 1026
      * @return void
1027 1027
      */
1028
-    public function _include($path)
1028
+    public function _include( $path )
1029 1029
     {
1030
-        if (file_exists($path)) {
1030
+        if ( file_exists( $path ) ) {
1031 1031
             include $path;
1032 1032
         }
1033 1033
     }
Please login to merge, or discard this patch.
Braces   +50 added lines, -100 removed lines patch added patch discarded remove patch
@@ -155,8 +155,7 @@  discard block
 block discarded – undo
155 155
      *
156 156
      * @param array $atts Associative array to set the data of
157 157
      */
158
-    public function __construct($atts = [])
159
-    {
158
+    public function __construct($atts = []) {
160 159
         $atts = wp_parse_args($atts, [
161 160
             'form_id' => null,
162 161
             'view_id' => null,
@@ -196,8 +195,7 @@  discard block
 block discarded – undo
196 195
      *
197 196
      * @return GravityView_View
198 197
      */
199
-    public static function getInstance($passed_post = null)
200
-    {
198
+    public static function getInstance($passed_post = null) {
201 199
         if (empty(self::$instance)) {
202 200
             self::$instance = new self($passed_post);
203 201
         }
@@ -210,8 +208,7 @@  discard block
 block discarded – undo
210 208
      *
211 209
      * @return array|mixed|null If $key is set and attribute exists at $key, return that. If not set, return NULL. Otherwise, return current field array
212 210
      */
213
-    public function getCurrentField($key = null)
214
-    {
211
+    public function getCurrentField($key = null) {
215 212
         if (!empty($key)) {
216 213
             if (isset($this->_current_field[$key])) {
217 214
                 return $this->_current_field[$key];
@@ -223,15 +220,13 @@  discard block
 block discarded – undo
223 220
         return $this->_current_field;
224 221
     }
225 222
 
226
-    public function setCurrentFieldSetting($key, $value)
227
-    {
223
+    public function setCurrentFieldSetting($key, $value) {
228 224
         if (!empty($this->_current_field)) {
229 225
             $this->_current_field['field_settings'][$key] = $value;
230 226
         }
231 227
     }
232 228
 
233
-    public function getCurrentFieldSetting($key)
234
-    {
229
+    public function getCurrentFieldSetting($key) {
235 230
         $settings = $this->getCurrentField('field_settings');
236 231
 
237 232
         if ($settings && !empty($settings[$key])) {
@@ -244,8 +239,7 @@  discard block
 block discarded – undo
244 239
     /**
245 240
      * @param array $passed_field
246 241
      */
247
-    public function setCurrentField($passed_field)
248
-    {
242
+    public function setCurrentField($passed_field) {
249 243
         $existing_field = $this->getCurrentField();
250 244
 
251 245
         $set_field = wp_parse_args($passed_field, $existing_field);
@@ -265,8 +259,7 @@  discard block
 block discarded – undo
265 259
      *
266 260
      * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
267 261
      */
268
-    public function getAtts($key = null)
269
-    {
262
+    public function getAtts($key = null) {
270 263
         if (!empty($key)) {
271 264
             if (isset($this->atts[$key])) {
272 265
                 return $this->atts[$key];
@@ -281,56 +274,49 @@  discard block
 block discarded – undo
281 274
     /**
282 275
      * @param array $atts
283 276
      */
284
-    public function setAtts($atts)
285
-    {
277
+    public function setAtts($atts) {
286 278
         $this->atts = $atts;
287 279
     }
288 280
 
289 281
     /**
290 282
      * @return array
291 283
      */
292
-    public function getForm()
293
-    {
284
+    public function getForm() {
294 285
         return $this->form;
295 286
     }
296 287
 
297 288
     /**
298 289
      * @param array $form
299 290
      */
300
-    public function setForm($form)
301
-    {
291
+    public function setForm($form) {
302 292
         $this->form = $form;
303 293
     }
304 294
 
305 295
     /**
306 296
      * @return int|null
307 297
      */
308
-    public function getPostId()
309
-    {
298
+    public function getPostId() {
310 299
         return $this->post_id;
311 300
     }
312 301
 
313 302
     /**
314 303
      * @param int|null $post_id
315 304
      */
316
-    public function setPostId($post_id)
317
-    {
305
+    public function setPostId($post_id) {
318 306
         $this->post_id = $post_id;
319 307
     }
320 308
 
321 309
     /**
322 310
      * @return string
323 311
      */
324
-    public function getContext()
325
-    {
312
+    public function getContext() {
326 313
         return $this->context;
327 314
     }
328 315
 
329 316
     /**
330 317
      * @param string $context
331 318
      */
332
-    public function setContext($context)
333
-    {
319
+    public function setContext($context) {
334 320
         $this->context = $context;
335 321
     }
336 322
 
@@ -339,8 +325,7 @@  discard block
 block discarded – undo
339 325
      *
340 326
      * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
341 327
      */
342
-    public function getFields($key = null)
343
-    {
328
+    public function getFields($key = null) {
344 329
         $fields = empty($this->fields) ? null : $this->fields;
345 330
 
346 331
         if ($fields && !empty($key)) {
@@ -359,8 +344,7 @@  discard block
 block discarded – undo
359 344
      *
360 345
      * @return array Array of GravityView field layout configurations
361 346
      */
362
-    public function getContextFields($context = '')
363
-    {
347
+    public function getContextFields($context = '') {
364 348
         if ('' === $context) {
365 349
             $context = $this->getContext();
366 350
         }
@@ -383,8 +367,7 @@  discard block
 block discarded – undo
383 367
     /**
384 368
      * @param array $fields
385 369
      */
386
-    public function setFields($fields)
387
-    {
370
+    public function setFields($fields) {
388 371
         $this->fields = $fields;
389 372
     }
390 373
 
@@ -393,8 +376,7 @@  discard block
 block discarded – undo
393 376
      *
394 377
      * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
395 378
      */
396
-    public function getField($key)
397
-    {
379
+    public function getField($key) {
398 380
         if (!empty($key)) {
399 381
             if (isset($this->fields[$key])) {
400 382
                 return $this->fields[$key];
@@ -408,80 +390,70 @@  discard block
 block discarded – undo
408 390
      * @param string $key   The key to a specific field in the fields array
409 391
      * @param mixed  $value The value to set for the field
410 392
      */
411
-    public function setField($key, $value)
412
-    {
393
+    public function setField($key, $value) {
413 394
         $this->fields[$key] = $value;
414 395
     }
415 396
 
416 397
     /**
417 398
      * @return int
418 399
      */
419
-    public function getViewId()
420
-    {
400
+    public function getViewId() {
421 401
         return absint($this->view_id);
422 402
     }
423 403
 
424 404
     /**
425 405
      * @param int $view_id
426 406
      */
427
-    public function setViewId($view_id)
428
-    {
407
+    public function setViewId($view_id) {
429 408
         $this->view_id = intval($view_id);
430 409
     }
431 410
 
432 411
     /**
433 412
      * @return int
434 413
      */
435
-    public function getFormId()
436
-    {
414
+    public function getFormId() {
437 415
         return $this->form_id;
438 416
     }
439 417
 
440 418
     /**
441 419
      * @param int $form_id
442 420
      */
443
-    public function setFormId($form_id)
444
-    {
421
+    public function setFormId($form_id) {
445 422
         $this->form_id = $form_id;
446 423
     }
447 424
 
448 425
     /**
449 426
      * @return array
450 427
      */
451
-    public function getEntries()
452
-    {
428
+    public function getEntries() {
453 429
         return $this->entries;
454 430
     }
455 431
 
456 432
     /**
457 433
      * @param array $entries
458 434
      */
459
-    public function setEntries($entries)
460
-    {
435
+    public function setEntries($entries) {
461 436
         $this->entries = $entries;
462 437
     }
463 438
 
464 439
     /**
465 440
      * @return int
466 441
      */
467
-    public function getTotalEntries()
468
-    {
442
+    public function getTotalEntries() {
469 443
         return (int) $this->total_entries;
470 444
     }
471 445
 
472 446
     /**
473 447
      * @param int $total_entries
474 448
      */
475
-    public function setTotalEntries($total_entries)
476
-    {
449
+    public function setTotalEntries($total_entries) {
477 450
         $this->total_entries = intval($total_entries);
478 451
     }
479 452
 
480 453
     /**
481 454
      * @return array
482 455
      */
483
-    public function getPaging()
484
-    {
456
+    public function getPaging() {
485 457
         $default_params = [
486 458
             'offset'    => 0,
487 459
             'page_size' => 20,
@@ -493,8 +465,7 @@  discard block
 block discarded – undo
493 465
     /**
494 466
      * @param array $paging
495 467
      */
496
-    public function setPaging($paging)
497
-    {
468
+    public function setPaging($paging) {
498 469
         $this->paging = $paging;
499 470
     }
500 471
 
@@ -510,8 +481,7 @@  discard block
 block discarded – undo
510 481
      *  @var int $total The total number of entries
511 482
      * }
512 483
      */
513
-    public function getPaginationCounts()
514
-    {
484
+    public function getPaginationCounts() {
515 485
         $paging = $this->getPaging();
516 486
         $offset = $paging['offset'];
517 487
         $page_size = $paging['page_size'];
@@ -543,8 +513,7 @@  discard block
 block discarded – undo
543 513
     /**
544 514
      * @return array
545 515
      */
546
-    public function getSorting()
547
-    {
516
+    public function getSorting() {
548 517
         $defaults_params = [
549 518
             'sort_field'     => 'date_created',
550 519
             'sort_direction' => 'ASC',
@@ -557,8 +526,7 @@  discard block
 block discarded – undo
557 526
     /**
558 527
      * @param array $sorting
559 528
      */
560
-    public function setSorting($sorting)
561
-    {
529
+    public function setSorting($sorting) {
562 530
         $this->sorting = $sorting;
563 531
     }
564 532
 
@@ -570,8 +538,7 @@  discard block
 block discarded – undo
570 538
      *
571 539
      * @return string
572 540
      */
573
-    public function getBackLinkLabel($do_replace = true)
574
-    {
541
+    public function getBackLinkLabel($do_replace = true) {
575 542
         if ($do_replace) {
576 543
             $back_link_label = GravityView_API::replace_variables($this->back_link_label, $this->getForm(), $this->getCurrentEntry());
577 544
 
@@ -584,56 +551,49 @@  discard block
 block discarded – undo
584 551
     /**
585 552
      * @param string $back_link_label
586 553
      */
587
-    public function setBackLinkLabel($back_link_label)
588
-    {
554
+    public function setBackLinkLabel($back_link_label) {
589 555
         $this->back_link_label = $back_link_label;
590 556
     }
591 557
 
592 558
     /**
593 559
      * @return bool
594 560
      */
595
-    public function isHideUntilSearched()
596
-    {
561
+    public function isHideUntilSearched() {
597 562
         return $this->hide_until_searched;
598 563
     }
599 564
 
600 565
     /**
601 566
      * @param bool $hide_until_searched
602 567
      */
603
-    public function setHideUntilSearched($hide_until_searched)
604
-    {
568
+    public function setHideUntilSearched($hide_until_searched) {
605 569
         $this->hide_until_searched = $hide_until_searched;
606 570
     }
607 571
 
608 572
     /**
609 573
      * @return string
610 574
      */
611
-    public function getTemplatePartSlug()
612
-    {
575
+    public function getTemplatePartSlug() {
613 576
         return $this->template_part_slug;
614 577
     }
615 578
 
616 579
     /**
617 580
      * @param string $template_part_slug
618 581
      */
619
-    public function setTemplatePartSlug($template_part_slug)
620
-    {
582
+    public function setTemplatePartSlug($template_part_slug) {
621 583
         $this->template_part_slug = $template_part_slug;
622 584
     }
623 585
 
624 586
     /**
625 587
      * @return string
626 588
      */
627
-    public function getTemplatePartName()
628
-    {
589
+    public function getTemplatePartName() {
629 590
         return $this->template_part_name;
630 591
     }
631 592
 
632 593
     /**
633 594
      * @param string $template_part_name
634 595
      */
635
-    public function setTemplatePartName($template_part_name)
636
-    {
596
+    public function setTemplatePartName($template_part_name) {
637 597
         $this->template_part_name = $template_part_name;
638 598
     }
639 599
 
@@ -642,8 +602,7 @@  discard block
 block discarded – undo
642 602
      *
643 603
      * @return array
644 604
      */
645
-    public function getCurrentEntry()
646
-    {
605
+    public function getCurrentEntry() {
647 606
         if (in_array($this->getContext(), ['edit', 'single'])) {
648 607
             $entries = $this->getEntries();
649 608
             $entry = $entries[0];
@@ -664,8 +623,7 @@  discard block
 block discarded – undo
664 623
      *
665 624
      * @return void
666 625
      */
667
-    public function setCurrentEntry($current_entry)
668
-    {
626
+    public function setCurrentEntry($current_entry) {
669 627
         $this->_current_entry = $current_entry;
670 628
     }
671 629
 
@@ -676,8 +634,7 @@  discard block
 block discarded – undo
676 634
      *
677 635
      * @return void
678 636
      */
679
-    public function clearCurrentEntry()
680
-    {
637
+    public function clearCurrentEntry() {
681 638
         $this->_current_entry = null;
682 639
     }
683 640
 
@@ -694,8 +651,7 @@  discard block
 block discarded – undo
694 651
      *
695 652
      * @return string|null
696 653
      */
697
-    public function renderZone($zone = '', $atts = [], $echo = true)
698
-    {
654
+    public function renderZone($zone = '', $atts = [], $echo = true) {
699 655
         if (empty($zone)) {
700 656
             gravityview()->log->error('No zone defined.');
701 657
 
@@ -788,8 +744,7 @@  discard block
 block discarded – undo
788 744
      *
789 745
      * @return null|string NULL: Template not found; String: path to template
790 746
      */
791
-    public function locate_template($template_names, $load = false, $require_once = true)
792
-    {
747
+    public function locate_template($template_names, $load = false, $require_once = true) {
793 748
         if (is_string($template_names) && isset($this->located_templates[$template_names])) {
794 749
             $located = $this->located_templates[$template_names];
795 750
         } else {
@@ -816,8 +771,7 @@  discard block
 block discarded – undo
816 771
      *
817 772
      * @return mixed|null The stored data.
818 773
      */
819
-    public function __get($name)
820
-    {
774
+    public function __get($name) {
821 775
         if (isset($this->{$name})) {
822 776
             return $this->{$name};
823 777
         } else {
@@ -843,8 +797,7 @@  discard block
 block discarded – undo
843 797
      *
844 798
      * @return array $templates Modified template array, merged with existing $templates values
845 799
      */
846
-    public function add_id_specific_templates($templates, $slug, $name)
847
-    {
800
+    public function add_id_specific_templates($templates, $slug, $name) {
848 801
         $additional = [];
849 802
 
850 803
         // form-19-table-body.php
@@ -870,8 +823,7 @@  discard block
 block discarded – undo
870 823
     }
871 824
 
872 825
     // Load the template
873
-    public function render($slug, $name, $require_once = true)
874
-    {
826
+    public function render($slug, $name, $require_once = true) {
875 827
         $this->setTemplatePartSlug($slug);
876 828
 
877 829
         $this->setTemplatePartName($name);
@@ -896,8 +848,7 @@  discard block
 block discarded – undo
896 848
      *
897 849
      * @return void
898 850
      */
899
-    public function render_widget_hooks($view_id_or_context)
900
-    {
851
+    public function render_widget_hooks($view_id_or_context) {
901 852
 
902 853
         /**
903 854
          * @deprecated Numeric argument is deprecated. Pass a \GV\Template_Context instead.
@@ -1025,8 +976,7 @@  discard block
 block discarded – undo
1025 976
      *
1026 977
      * @return void
1027 978
      */
1028
-    public function _include($path)
1029
-    {
979
+    public function _include($path) {
1030 980
         if (file_exists($path)) {
1031 981
             include $path;
1032 982
         }
Please login to merge, or discard this patch.