PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.2
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.2
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 2.0.7 All 340 releases
profile-builder / admin / advanced-settings / includes / functions.php

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

134 lines 4.2 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 if ( ! current_user_can( 'manage_options' ) ) {
37 wp_send_json_error();
38 }
39
40 global $wpdb;
41
42 $query = '';
43 $step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
44 $batch_size = 500;
45 $rows_affected = 0;
46
47 if ( $step === 1 ) {
48
49 // First query - Social Connect meta
50 $query = $wpdb->prepare( "DELETE FROM {$wpdb->postmeta}
51 WHERE post_id IN (
52 SELECT ID FROM {$wpdb->posts}
53 WHERE post_type NOT IN (%s, %s)
54 )
55 AND meta_key = %s
56 LIMIT %d",
57 'wppb-rf-cpt',
58 'wppb-epf-cpt',
59 'wppb_sc_rf_epf_active',
60 $batch_size );
61
62 $rows_affected = $wpdb->query( $query );
63
64 if ( $rows_affected === 0 ) {
65
66 // Move to next step when no more rows to delete
67 wp_send_json_success( array( 'step' => 2 ) );
68
69 }
70
71 } else if ( $step === 2 ) {
72
73 // Second query - UserListing themes meta
74 $query = $wpdb->prepare( "DELETE FROM {$wpdb->postmeta}
75 WHERE post_id IN (
76 SELECT ID FROM {$wpdb->posts}
77 WHERE post_type != %s
78 )
79 AND meta_key IN (%s, %s, %s)
80 LIMIT %d",
81 'wppb-ul-cpt',
82 'wppb-ul-active-theme',
83 'wppb-ul-default-single-user-template',
84 'wppb-ul-default-all-users-template',
85 $batch_size );
86
87 $rows_affected = $wpdb->query( $query );
88
89 if ( $rows_affected === 0 ) {
90
91 // Move to next step when no more rows to delete
92 wp_send_json_success( array( 'step' => 3 ) );
93
94 }
95
96 } else if ( $step === 3 ) {
97
98 // Third query - Placeholder Labels meta
99 $query = $wpdb->prepare( "DELETE FROM {$wpdb->postmeta}
100 WHERE meta_key = %s
101 AND meta_value = %s
102 LIMIT %d",
103 'pbpl-active',
104 'no',
105 $batch_size );
106
107 $rows_affected = $wpdb->query( $query );
108
109 if ( $rows_affected === 0 ) {
110
111 // Save the new completion flag as non-autoloaded option
112 add_option( 'wppb_postmeta_cleanup_completed_v2', true, '', 'no' );
113
114 // Remove the old completion flag
115 delete_option( 'wppb_postmeta_cleanup_completed' );
116
117 // All done
118 wp_send_json_success( array(
119 'step' => 'done',
120 'hide_button' => true
121 ) );
122
123 }
124
125 }
126
127 // Continue with same step
128 wp_send_json_success( array(
129 'step' => $step,
130 'rows_affected' => $rows_affected
131 ) );
132 }
133 add_action( 'wp_ajax_wppb_cleanup_postmeta', 'wppb_cleanup_postmeta' );
134