PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.16.1
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.16.1
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / admin / advanced-settings / includes / functions.php

functions.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.16.1, at admin/advanced-settings/includes/functions.php

130 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3
4 /**
5 * @param string $context Name of the folder where the code file is placed (tab slug).
6 * @param string $setting Name of the file where the code is placed.
7 * @return string|false Returns false if settings are empty (shouldn't reach this point in that case anyway), else returns the setting.
8 */
9 function wppb_toolbox_get_settings( $context, $setting ) {
10 $option = 'wppb_toolbox_' . $context . '_settings';
11
12 $settings = get_option( $option );
13
14 if ( $settings == false ) return false;
15
16 if ( isset( $settings[ $setting ] ) )
17 return $settings[ $setting ];
18
19 return false;
20 }
21
22
23 /**
24 * Clean unnecessary extra post meta from unrelated posts
25 *
26 * - wppb_sc_rf_epf_active
27 * - wppb-content-restrict-message-purchasing_restricted
28 * - wppb-ul-active-theme
29 * - wppb-ul-default-single-user-template
30 * - wppb-ul-default-all-users-template
31 *
32 */
33 function wppb_cleanup_postmeta() {
34 check_ajax_referer( 'wppb_cleanup_postmeta', 'nonce' );
35
36 global $wpdb;
37
38 $query = '';
39 $step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
40 $batch_size = 500;
41 $rows_affected = 0;
42
43 if ( $step === 1 ) {
44
45 // First query - Social Connect meta
46 $query = $wpdb->prepare( "DELETE FROM {$wpdb->postmeta}
47 WHERE post_id IN (
48 SELECT ID FROM {$wpdb->posts}
49 WHERE post_type NOT IN (%s, %s)
50 )
51 AND meta_key = %s
52 LIMIT %d",
53 'wppb-rf-cpt',
54 'wppb-epf-cpt',
55 'wppb_sc_rf_epf_active',
56 $batch_size );
57
58 $rows_affected = $wpdb->query( $query );
59
60 if ( $rows_affected === 0 ) {
61
62 // Move to next step when no more rows to delete
63 wp_send_json_success( array( 'step' => 2 ) );
64
65 }
66
67 } else if ( $step === 2 ) {
68
69 // Second query - UserListing themes meta
70 $query = $wpdb->prepare( "DELETE FROM {$wpdb->postmeta}
71 WHERE post_id IN (
72 SELECT ID FROM {$wpdb->posts}
73 WHERE post_type != %s
74 )
75 AND meta_key IN (%s, %s, %s)
76 LIMIT %d",
77 'wppb-ul-cpt',
78 'wppb-ul-active-theme',
79 'wppb-ul-default-single-user-template',
80 'wppb-ul-default-all-users-template',
81 $batch_size );
82
83 $rows_affected = $wpdb->query( $query );
84
85 if ( $rows_affected === 0 ) {
86
87 // Move to next step when no more rows to delete
88 wp_send_json_success( array( 'step' => 3 ) );
89
90 }
91
92 } else if ( $step === 3 ) {
93
94 // Third query - Placeholder Labels meta
95 $query = $wpdb->prepare( "DELETE FROM {$wpdb->postmeta}
96 WHERE meta_key = %s
97 AND meta_value = %s
98 LIMIT %d",
99 'pbpl-active',
100 'no',
101 $batch_size );
102
103 $rows_affected = $wpdb->query( $query );
104
105 if ( $rows_affected === 0 ) {
106
107 // Save the new completion flag as non-autoloaded option
108 add_option( 'wppb_postmeta_cleanup_completed_v2', true, '', 'no' );
109
110 // Remove the old completion flag
111 delete_option( 'wppb_postmeta_cleanup_completed' );
112
113 // All done
114 wp_send_json_success( array(
115 'step' => 'done',
116 'hide_button' => true
117 ) );
118
119 }
120
121 }
122
123 // Continue with same step
124 wp_send_json_success( array(
125 'step' => $step,
126 'rows_affected' => $rows_affected
127 ) );
128 }
129 add_action( 'wp_ajax_wppb_cleanup_postmeta', 'wppb_cleanup_postmeta' );
130