PluginProbe ʕ •ᴥ•ʔ
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More / 1.3.1.1
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More v1.3.1.1
1.10.1.1 1.10.1 1.10.0.5 trunk 1.1.4 1.1.4.2 1.1.5 1.1.5.1 1.1.6 1.1.6.1 1.1.7 1.1.7.1 1.1.7.2 1.1.8 1.1.8.1 1.1.8.2 1.1.8.3 1.1.8.4 1.10.0.1 1.10.0.2 1.10.0.3 1.10.0.4 1.2.0 1.2.0.1 1.2.1 1.2.2 1.2.2.1 1.2.2.2 1.2.3 1.2.3.1 1.2.3.2 1.2.4 1.2.4.1 1.2.5 1.2.5.1 1.2.6 1.2.7 1.2.8 1.2.8.1 1.2.9 1.3.0 1.3.1 1.3.1.1 1.3.1.2 1.3.2 1.3.3 1.3.5 1.3.6 1.3.6.1 1.3.6.2 1.3.7.2 1.3.7.3 1.3.7.4 1.3.8 1.3.9.1 1.4.0.1 1.4.1.1 1.4.2 1.4.2.1 1.4.2.2 1.4.3 1.4.4 1.4.4.1 1.4.5 1.4.5.1 1.4.5.2 1.4.5.3 1.4.6 1.4.7.1 1.4.7.2 1.4.8.1 1.4.9 1.5.0.1 1.5.0.3 1.5.0.4 1.5.1 1.5.1.1 1.5.1.3 1.5.2.1 1.5.2.2 1.5.2.3 1.5.3 1.5.3.1 1.5.4.1 1.5.4.2 1.5.5 1.5.5.1 1.5.6 1.5.6.2 1.5.7 1.5.8.2 1.5.9.1 1.5.9.4 1.5.9.5 1.6.0.1 1.6.0.2 1.6.1 1.6.2.2 1.6.2.3 1.6.3.1 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.7 1.6.7.1 1.6.7.2 1.6.7.3 1.6.8 1.6.8.1 1.6.9 1.7.0 1.7.1.1 1.7.1.2 1.7.2 1.7.2.1 1.7.3 1.7.4 1.7.4.1 1.7.4.2 1.7.5.1 1.7.5.2 1.7.5.3 1.7.5.5 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.7.9.1 1.8.0.1 1.8.0.2 1.8.1.1 1.8.1.2 1.8.1.3 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.3.1 1.8.4 1.8.4.1 1.8.5.2 1.8.5.3 1.8.5.4 1.8.6.2 1.8.6.3 1.8.6.4 1.8.7.2 1.8.8.2 1.8.8.3 1.8.9.1 1.8.9.2 1.8.9.4 1.8.9.5 1.8.9.6 1.9.0.1 1.9.0.2 1.9.0.3 1.9.0.4 1.9.1.1 1.9.1.2 1.9.1.3 1.9.1.4 1.9.1.5 1.9.1.6 1.9.2.1 1.9.2.2 1.9.2.3 1.9.3.1 1.9.3.2 1.9.4.1 1.9.4.2 1.9.5 1.9.5.1 1.9.5.2 1.9.6 1.9.6.1 1.9.6.2 1.9.7.1 1.9.7.2 1.9.7.3 1.9.8.1 1.9.8.2 1.9.8.4 1.9.8.7 1.9.9.2 1.9.9.3 1.9.9.4
wpforms-lite / includes / class-logging.php
wpforms-lite / includes Last commit date
admin 9 years ago emails 9 years ago fields 9 years ago templates 9 years ago class-fields.php 9 years ago class-form.php 9 years ago class-frontend.php 9 years ago class-install.php 9 years ago class-logging.php 9 years ago class-preview.php 9 years ago class-process.php 9 years ago class-smart-tags.php 9 years ago class-templates.php 9 years ago class-widget.php 10 years ago functions.php 9 years ago integrations.php 9 years ago
class-logging.php
336 lines
1 <?php
2 /**
3 * Class for logging events and errors
4 *
5 * This class is forked from Easy Digital Downloads / Pippin Williamson.
6 *
7 * @link https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/includes/class-edd-logging.php
8 * @package WPForms
9 * @author WPForms
10 * @since 1.0.0
11 * @license GPL-2.0+
12 * @copyright Copyright (c) 2016, WPForms LLC
13 */
14 class WPForms_Logging {
15
16 /**
17 * Set up the logging class.
18 *
19 * @since 1.0.0
20 */
21 public function __construct() {
22
23 // Create the log post type
24 add_action( 'init', array( $this, 'register_post_type' ), 1 );
25
26 // Create types taxonomy and default types
27 add_action( 'init', array( $this, 'register_taxonomy' ), 1 );
28 }
29
30 /**
31 * Registers the log post type.
32 *
33 * @since 1.0.0
34 */
35 public function register_post_type() {
36
37 $log_args = array(
38 'labels' => array( 'name' => __( 'WPForms Logs', 'wpforms' ), 'menu_name' => __( 'Logs', 'wpforms' ) ),
39 'public' => false,
40 'exclude_from_search' => true,
41 'publicly_queryable' => false,
42 'show_ui' => false,
43 'query_var' => false,
44 'rewrite' => false,
45 'capability_type' => 'post',
46 'supports' => array( 'title', 'editor' ),
47 'can_export' => false,
48 'show_in_menu' => 'wpforms-overview'
49 );
50
51 if ( wpforms_debug() ) {
52 $log_args['show_ui'] = true;
53 }
54
55 register_post_type( 'wpforms_log', apply_filters( 'wpforms_log_cpt', $log_args ) );
56 }
57
58 /**
59 * Registers the Log Type taxonomy.
60 *
61 * @since 1.0.0
62 */
63 public function register_taxonomy() {
64
65 register_taxonomy( 'wpforms_log_type', 'wpforms_log', array( 'public' => false ) );
66 }
67
68 /**
69 * Log types.
70 *
71 * @since 1.0.0
72 * @return array
73 */
74 public function log_types() {
75
76 $terms = array(
77 'payment',
78 'provider',
79 'spam',
80 'entry',
81 'error',
82 'conditional_logic'
83 );
84
85 return apply_filters( 'wpforms_log_types', $terms );
86 }
87
88 /**
89 * Check if a log type is valid.
90 *
91 * @since 1.0.0
92 * @param string $type
93 * @return bool
94 */
95 function valid_type( $type ) {
96
97 return in_array( $type, $this->log_types() );
98 }
99
100 /**
101 * Create new log entry.
102 *
103 * This is just a simple and fast way to log something. Use $this->insert_log()
104 * if you need to store custom meta data
105 *
106 * @since 1.0.0
107 * @param string $title Log entry title
108 * @param string $message Log entry message
109 * @param int $parent Log entry parent
110 * @param string $type Log type (default: null)
111 * @return int Log ID
112 */
113 public function add( $title = '', $message = '', $parent = 0, $type = null, $meta = '' ) {
114
115 $log_data = array(
116 'post_title' => $title,
117 'post_content' => $message,
118 'post_parent' => $parent,
119 'log_type' => $type
120 );
121 return $this->insert_log( $log_data, $meta );
122 }
123
124 /**
125 * Easily retrieves log items for a particular object ID.
126 *
127 * @since 1.0.0
128 * @param int $object_id (default: 0)
129 * @param string $type Log type (default: null)
130 * @param int $paged Page number (default: null)
131 * @return array Array of the connected logs
132 */
133 public function get_logs( $object_id = 0, $type = null, $paged = null ) {
134
135 return $this->get_connected_logs( array( 'post_parent' => $object_id, 'paged' => $paged, 'log_type' => $type ) );
136 }
137
138 /**
139 * Stores a log entry.
140 *
141 * @since 1.0.0
142 * @param array $log_data Log entry data
143 * @param array $log_meta Log entry meta
144 * @return int The ID of the newly created log item
145 */
146 function insert_log( $log_data = array(), $log_meta = array() ) {
147
148 $defaults = array(
149 'post_type' => 'wpforms_log',
150 'post_status' => 'publish',
151 'post_parent' => 0,
152 'post_content' => '',
153 'log_type' => false
154 );
155 $args = wp_parse_args( $log_data, $defaults );
156
157 do_action( 'wpforms_pre_insert_log', $log_data, $log_meta );
158
159 // Store the log entry
160 $log_id = wp_insert_post( $args );
161
162 // Set the log type, if any
163 if ( $log_data['log_type'] && $this->valid_type( $log_data['log_type'] ) ) {
164 wp_set_object_terms( $log_id, $log_data['log_type'], 'wpforms_log_type', false );
165 }
166
167 // Set log meta, if any
168 if ( $log_id && ! empty( $log_meta ) ) {
169 foreach ( (array) $log_meta as $key => $meta ) {
170 update_post_meta( $log_id, '_wpforms_log_' . sanitize_key( $key ), $meta );
171 }
172 }
173
174 do_action( 'wpforms_post_insert_log', $log_id, $log_data, $log_meta );
175
176 return $log_id;
177 }
178
179 /**
180 * Update and existing log item.
181 *
182 * @since 1.0.0
183 * @param array $log_data Log entry data
184 * @param array $log_meta Log entry meta
185 * @return bool True if successful, false otherwise
186 */
187 public function update_log( $log_data = array(), $log_meta = array() ) {
188
189 do_action( 'wpforms_pre_update_log', $log_data, $log_meta );
190
191 $defaults = array(
192 'post_type' => 'wpforms_log',
193 'post_status' => 'publish',
194 'post_parent' => 0
195 );
196
197 $args = wp_parse_args( $log_data, $defaults );
198
199 // Store the log entry
200 $log_id = wp_update_post( $args );
201
202 if ( $log_id && ! empty( $log_meta ) ) {
203 foreach ( (array) $log_meta as $key => $meta ) {
204 if ( ! empty( $meta ) )
205 update_post_meta( $log_id, '_wpforms_log_' . sanitize_key( $key ), $meta );
206 }
207 }
208
209 do_action( 'wpforms_post_update_log', $log_id, $log_data, $log_meta );
210 }
211
212 /**
213 * Retrieve all connected logs.
214 *
215 * Used for retrieving logs related to particular items, such as a specific purchase.
216 *
217 * @since 1.0.0
218 * @param array $args Query arguments
219 * @return mixed array if logs were found, false otherwise
220 */
221 public function get_connected_logs( $args = array() ) {
222 $defaults = array(
223 'post_type' => 'wpforms_log',
224 'posts_per_page' => 20,
225 'post_status' => 'publish',
226 'paged' => get_query_var( 'paged' ),
227 'log_type' => false
228 );
229
230 $query_args = wp_parse_args( $args, $defaults );
231
232 if ( $query_args['log_type'] && $this->valid_type( $query_args['log_type'] ) ) {
233 $query_args['tax_query'] = array(
234 array(
235 'taxonomy' => 'wpforms_log_type',
236 'field' => 'slug',
237 'terms' => $query_args['log_type']
238 )
239 );
240 }
241
242 $logs = get_posts( $query_args );
243
244 if ( $logs )
245 return $logs;
246
247 // No logs found
248 return false;
249 }
250
251 /**
252 * Retrieves number of log entries connected to particular object ID
253 *
254 * @since 1.0.0
255 * @param int $object_id (default: 0)
256 * @param string $type Log type (default: null)
257 * @param array $meta_query Log meta query (default: null)
258 * @param array $date_query Log data query (default: null) (since 1.9)
259 * @return int Log count
260 */
261 public function get_log_count( $object_id = 0, $type = null, $meta_query = null, $date_query = null ) {
262
263 global $pagenow, $typenow;
264
265 $query_args = array(
266 'post_parent' => $object_id,
267 'post_type' => 'wpforms_log',
268 'posts_per_page' => -1,
269 'post_status' => 'publish',
270 'fields' => 'ids',
271 );
272
273 if ( ! empty( $type ) && $this->valid_type( $type ) ) {
274 $query_args['tax_query'] = array(
275 array(
276 'taxonomy' => 'wpforms_log_type',
277 'field' => 'slug',
278 'terms' => $type
279 )
280 );
281 }
282
283 if ( ! empty( $meta_query ) ) {
284 $query_args['meta_query'] = $meta_query;
285 }
286
287 if ( ! empty( $date_query ) ) {
288 $query_args['date_query'] = $date_query;
289 }
290
291 $logs = new WP_Query( $query_args );
292
293 return (int) $logs->post_count;
294 }
295
296 /**
297 * Delete a log.
298 *
299 * @since 1.0.0
300 * @param int $object_id (default: 0)
301 * @param string $type Log type (default: null)
302 * @param array $meta_query Log meta query (default: null)
303 */
304 public function delete_logs( $object_id = 0, $type = null, $meta_query = null ) {
305
306 $query_args = array(
307 'post_parent' => $object_id,
308 'post_type' => 'wpforms_log',
309 'posts_per_page' => -1,
310 'post_status' => 'publish',
311 'fields' => 'ids'
312 );
313
314 if ( ! empty( $type ) && $this->valid_type( $type ) ) {
315 $query_args['tax_query'] = array(
316 array(
317 'taxonomy' => 'wpforms_log_type',
318 'field' => 'slug',
319 'terms' => $type,
320 )
321 );
322 }
323
324 if ( ! empty( $meta_query ) ) {
325 $query_args['meta_query'] = $meta_query;
326 }
327
328 $logs = get_posts( $query_args );
329
330 if ( $logs ) {
331 foreach ( $logs as $log ) {
332 wp_delete_post( $log, true );
333 }
334 }
335 }
336 }