PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.3
6.3 6.2.3 6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 All 157 releases
← All changes | class/class-mainwp-db.php +51 -6 6.2 → 6.2.3 View file →
@@ -176,11 +176,11 @@
176 176
177 177 /**
178 178 * Method get_wp_options_join().
179 179 *
180 - * @param array $fields Extra option fields.
181 - * @param string $view_query view query.
182 - * @param array<string, mixed> $params Additional parameters.
180 + * @param array $fields Extra option fields.
181 + * @param string $view_query view query.
182 + * @param array<string, mixed> $params Additional parameters.
183 183
184 184 *
185 185 * NOTE: This method is used to improve the performance of wp_options view, as the old view with subquery for each field will cause performance issue when there are many sites, and this method will generate the SQL with LEFT JOIN which will be much faster than subquery.
186 186 * The alias of wp table must be 'wp' to make sure the LEFT JOIN works, and the alias of wp_options table will be 'owp' + key of field in fields array, and the join condition is owp.wpid = wp.id AND owp.name = field name, and the select field is owp.value AS field name.
@@ -3316,8 +3316,26 @@
3316 3316 'groupid' => $groupid,
3317 3317 )
3318 3318 );
3319 3319 }
3320 +
3321 + // Add primary monitor, use global settings.
3322 + $success = MainWP_DB_Uptime_Monitoring::instance()->update_wp_monitor(
3323 + array(
3324 + 'wpid' => $websiteid,
3325 + 'suburl' => '',
3326 + )
3327 + );
3328 +
3329 + $opt_name = 'mainwp_primary_monitor_repair_attempts_for_wp_' . $websiteid;
3330 +
3331 + if ( ! $success ) {
3332 + update_option( $opt_name, 1 );
3333 + MainWP_Utility::unhide_mainwp_message( 'failed-attempt-create-primary-monitor-' . $websiteid );
3334 + } elseif ( get_option( $opt_name ) ) {
3335 + delete_option( $opt_name );
3336 + }
3337 +
3320 3338 MainWP_Manage_Sites_List_Table::invalidate_manage_sites_cache();
3321 3339 return $websiteid;
3322 3340 }
3323 3341 }
@@ -3340,9 +3358,9 @@
3340 3358 $this->wpdb->delete( $this->table_name( 'wp_group' ), array( 'wpid' => $websiteid ) );
3341 3359 $this->wpdb->delete( $this->table_name( 'wp_sync' ), array( 'wpid' => $websiteid ) );
3342 3360 $this->wpdb->delete( $this->table_name( 'wp_options' ), array( 'wpid' => $websiteid ) );
3343 3361 MainWP_Encrypt_Data_Lib::remove_key_file( $websiteid );
3344 - MainWP_DB_Uptime_Monitoring::instance()->delete_monitor( array( 'wpid' => $websiteid ) );
3362 + MainWP_DB_Uptime_Monitoring::instance()->delete_site_monitors( $websiteid );
3345 3363 MainWP_Manage_Sites_List_Table::invalidate_manage_sites_cache();
3346 3364 return $nr;
3347 3365 }
3348 3366
@@ -4173,10 +4191,12 @@
4173 4191 *
4174 4192 * @return array
4175 4193 */
4176 4194 public function update_rest_api_key( $key_id, $scope, $description, $enabled = 1 ) {
4195 + $key = $this->get_rest_api_key_by( $key_id );
4196 +
4177 4197 $permissions = in_array( $scope, array( 'read', 'write', 'delete', 'read_write' ), true ) ? sanitize_text_field( $scope ) : 'read';
4178 - return $this->wpdb->update(
4198 + $updated = $this->wpdb->update(
4179 4199 $this->table_name( 'api_keys' ),
4180 4200 array(
4181 4201 'description' => $description,
4182 4202 'permissions' => $permissions,
@@ -4185,8 +4205,12 @@
4185 4205 array(
4186 4206 'key_id' => $key_id,
4187 4207 )
4188 4208 );
4209 + if ( $key ) {
4210 + \MainWP_REST_Authentication::delete_api_key_cache( $key->consumer_key );
4211 + }
4212 + return $updated;
4189 4213 }
4190 4214
4191 4215
4192 4216 /**
@@ -4219,10 +4243,31 @@
4219 4243 *
4220 4244 * @return array
4221 4245 */
4222 4246 public function remove_rest_api_key( $id ) {
4247 + $key = $this->get_rest_api_key_by( $id );
4223 4248 $table_name = esc_sql( $this->table_name( 'api_keys' ) );
4224 - return $this->wpdb->query( $this->wpdb->prepare( "DELETE FROM {$table_name} WHERE key_id = %s", $id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name is esc_sql'd.
4249 + $deleted = $this->wpdb->query( $this->wpdb->prepare( "DELETE FROM {$table_name} WHERE key_id = %d", $id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name is esc_sql'd.
4250 + if ( $key ) {
4251 + \MainWP_REST_Authentication::delete_api_key_cache( $key->consumer_key );
4252 + }
4253 + return $deleted;
4254 + }
4255 +
4256 + /**
4257 + * Delete a user's REST API keys and return their stored consumer keys.
4258 + *
4259 + * @param int $user_id Owner ID.
4260 + * @param string|null $table_name Key table. Defaults to MainWP's captured table.
4261 + * @return array Removed key rows containing consumer_key.
4262 + */
4263 + public function remove_rest_api_keys_by_user( $user_id, $table_name = null ) {
4264 + $table_name = esc_sql( null === $table_name ? $this->table_name( 'api_keys' ) : $table_name );
4265 + // nosec - $table_name is MainWP's own api_keys table name, never request input.
4266 + $rows = $this->wpdb->get_results( $this->wpdb->prepare( "SELECT consumer_key FROM {$table_name} WHERE user_id = %d", $user_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name is esc_sql'd.
4267 + // nosec - $table_name is MainWP's own api_keys table name, never request input.
4268 + $this->wpdb->query( $this->wpdb->prepare( "DELETE FROM {$table_name} WHERE user_id = %d", $user_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name is esc_sql'd.
4269 + return $rows;
4225 4270 }
4226 4271
4227 4272 /**
4228 4273 * Method get_rest_api_keys().