Changeset 3243448
- Timestamp:
- 02/19/2025 06:55:30 PM (12 months ago)
- Location:
- multi-connect
- Files:
-
- 1 added
- 4 edited
-
tags/1.0.45 (added)
-
trunk/.editorconfig (modified) (1 diff)
-
trunk/includes/class-multi-connect-api.php (modified) (25 diffs)
-
trunk/multi-connect.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
multi-connect/trunk/.editorconfig
r3217196 r3243448 4 4 trim_trailing_whitespace = true 5 5 indent_size = 4 6 indent_style = space6 indent_style = tab 7 7 insert_final_newline = true -
multi-connect/trunk/includes/class-multi-connect-api.php
r3243412 r3243448 23 23 */ 24 24 private string $namespace = 'wp/v2'; 25 private int $token_length = 32; 26 private int $token_expiry = 300; 25 27 26 28 /** … … 131 133 ) 132 134 ); 135 136 register_rest_route( 137 $this->namespace, 138 '/generate-login-token', 139 array( 140 'methods' => 'POST', 141 'callback' => [ $this, 'generate_login_token' ], 142 'permission_callback' => [ $this, 'check_authentication' ], 143 ) 144 ); 145 146 register_rest_route( 147 $this->namespace, 148 '/auto-login', 149 array( 150 'methods' => 'GET', 151 'callback' => [ $this, 'process_auto_login' ], 152 'permission_callback' => '__return_true', 153 ) 154 ); 133 155 } 134 156 … … 141 163 global $wpdb; 142 164 143 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching165 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 144 166 $tables = $wpdb->get_results( 'SHOW TABLES', ARRAY_N ); 145 167 $table_names = array_map( fn( $table ) => $table[0], $tables ); … … 157 179 * 158 180 * @param WP_REST_Request $request The request object. 181 * 159 182 * @return WP_REST_Response The response object. 160 183 * … … 191 214 break; 192 215 case 'core': 193 $selected_folders = array_merge( $selected_folders, glob( MULTICONNECT_PLUGIN_ABSPATH . 'wp-*.php' ) ); 216 $selected_folders = array_merge( $selected_folders, 217 glob( MULTICONNECT_PLUGIN_ABSPATH . 'wp-*.php' ) ); 194 218 break; 195 219 } … … 267 291 * 268 292 * @param string $zip_file The zip file path. 269 * @param array $folders The folders to backup.293 * @param array $folders The folders to backup. 270 294 * @param string $log_file The log file path. 295 * 271 296 * @return int The number of files added. 272 297 * … … 289 314 $relative_path = substr( $path, $base_length ); 290 315 if ( $zip->addFile( $path, $relative_path ) ) { 291 ++ $files_added;316 ++ $files_added; 292 317 } else { 293 318 $this->log( $log_file, "Failed to add file: $path" ); … … 308 333 309 334 if ( $zip->addFile( $file_path, $relative_path ) ) { 310 ++ $files_added;335 ++ $files_added; 311 336 } else { 312 337 $this->log( $log_file, "Failed to add file: $file_path" ); … … 328 353 * 329 354 * @param string $zip_file The zip file path. 330 * @param array $tables The tables to backup.355 * @param array $tables The tables to backup. 331 356 * @param string $log_file The log file path. 357 * 332 358 * @return bool True if the database backup is successful, false otherwise. 333 359 * … … 336 362 private function create_database_backup( $zip_file, $tables, $log_file ) { 337 363 $db_backup = $this->backup_database( $tables ); 338 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents339 $this->log( '', 'backup_database: ' . file_get_contents($db_backup));364 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents 365 $this->log( '', 'backup_database: ' . file_get_contents( $db_backup ) ); 340 366 if ( ! $db_backup ) { 341 367 $this->log( $log_file, 'Failed to create database dump' ); … … 371 397 * @param string $log_file The log file path. 372 398 * @param string $message The message to log. 399 * 373 400 * @return void 374 401 */ … … 376 403 if ( empty( $log_file ) ) { 377 404 $backup_dir = wp_upload_dir()['basedir'] . '/backups'; 378 $log_file = $backup_dir . '/backup.log';379 } 380 $enable_logging = get_option( 'multi_connect_log');381 if ( $enable_logging !== '1') {382 return;405 $log_file = $backup_dir . '/backup.log'; 406 } 407 $enable_logging = get_option( 'multi_connect_log' ); 408 if ( $enable_logging !== '1' ) { 409 return; 383 410 } 384 411 $timestamp = gmdate( 'Y-m-d H:i:s' ); … … 389 416 WP_Filesystem(); 390 417 } 391 $existing_content = $wp_filesystem->get_contents( $log_file) ?: '';418 $existing_content = $wp_filesystem->get_contents( $log_file ) ?: ''; 392 419 $wp_filesystem->put_contents( $log_file, $existing_content . $log_message, FS_CHMOD_FILE ); 393 420 } … … 397 424 * 398 425 * @param array $tables_name The tables to backup. 426 * 399 427 * @return string The backup file path. 400 428 */ … … 429 457 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 430 458 $create_table = $wpdb->get_row( 431 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange432 sprintf( 'SHOW CREATE TABLE %s', "`{$table_name}`"),459 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange 460 sprintf( 'SHOW CREATE TABLE %s', "`{$table_name}`" ), 433 461 ARRAY_N 434 462 ); 435 $content .= "DROP TABLE IF EXISTS `{$table_name}`;\n";436 $content .= $create_table[1] . ";\n\n";463 $content .= "DROP TABLE IF EXISTS `{$table_name}`;\n"; 464 $content .= $create_table[1] . ";\n\n"; 437 465 438 466 // Datos de la tabla. 439 467 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching 440 468 $rows = $wpdb->get_results( 441 sprintf( 'SELECT * FROM %s', "`{$table_name}`"),469 sprintf( 'SELECT * FROM %s', "`{$table_name}`" ), 442 470 ARRAY_A 443 471 ); … … 448 476 foreach ( $chunk as $row ) { 449 477 $values[] = '(' . implode( 450 ',',451 array_map(452 function ( $value ) use ( $wpdb ) {453 return is_null( $value ) ? 'NULL' : "'" . $wpdb->_real_escape( $value ) . "'";454 },455 $row456 )457 ) . ')';478 ',', 479 array_map( 480 function ( $value ) use ( $wpdb ) { 481 return is_null( $value ) ? 'NULL' : "'" . $wpdb->_real_escape( $value ) . "'"; 482 }, 483 $row 484 ) 485 ) . ')'; 458 486 } 459 487 … … 532 560 public function check_update_permission() { 533 561 return current_user_can( 'update_core' ) && 534 current_user_can( 'update_plugins' ) &&535 current_user_can( 'update_themes' );562 current_user_can( 'update_plugins' ) && 563 current_user_can( 'update_themes' ); 536 564 } 537 565 … … 545 573 546 574 // Forzar la verificación de actualizaciones. 547 delete_site_transient('update_core');548 delete_site_transient('update_plugins');549 delete_site_transient('update_themes');550 delete_site_transient('available_translations');551 552 // Limpiar la caché de actualizaciones553 wp_clean_update_cache();554 555 // Forzar la verificación de actualizaciones con tiempo actual556 wp_version_check(array(), true);557 wp_update_plugins();558 wp_update_themes();575 delete_site_transient( 'update_core' ); 576 delete_site_transient( 'update_plugins' ); 577 delete_site_transient( 'update_themes' ); 578 delete_site_transient( 'available_translations' ); 579 580 // Limpiar la caché de actualizaciones 581 wp_clean_update_cache(); 582 583 // Forzar la verificación de actualizaciones con tiempo actual 584 wp_version_check( array(), true ); 585 wp_update_plugins(); 586 wp_update_themes(); 559 587 560 588 … … 577 605 578 606 // Verificar actualizaciones de plugins. 579 get_plugin_updates();580 try {581 $transient = (object)[582 'last_checked' => time() - (13 * 3600),583 'checked' => ['default' => 'none'],584 'response' => ['default' => 'none'],585 ];586 apply_filters("pre_set_site_transient_update_plugins", $transient, "update_plugins");587 } catch (\Throwable $e) {588 $transient;589 }590 $plugins = get_site_transient( 'update_plugins' );591 if ( $plugins && ! empty( $plugins->response ) ) {607 get_plugin_updates(); 608 try { 609 $transient = (object) [ 610 'last_checked' => time() - ( 13 * 3600 ), 611 'checked' => [ 'default' => 'none' ], 612 'response' => [ 'default' => 'none' ], 613 ]; 614 apply_filters( "pre_set_site_transient_update_plugins", $transient, "update_plugins" ); 615 } catch ( Throwable $e ) { 616 $transient; 617 } 618 $plugins = get_site_transient( 'update_plugins' ); 619 if ( $plugins && ! empty( $plugins->response ) ) { 592 620 foreach ( $plugins->response as $plugin_file => $plugin_data ) { 593 621 $plugin_data = (array) $plugin_data; … … 604 632 // Verificar actualizaciones de temas. 605 633 get_theme_updates(); 606 try {607 $transient = (object)[608 'last_checked' => time() - (13 * 3600),609 'checked' => ['default' => 'none'],610 'response' => ['default' => 'none'],611 ];612 $updatesFromHook = apply_filters("pre_set_site_transient_update_themes", $transient, "update_themes");613 } catch (\Throwable $e) {614 $updatesFromHook = $transient;615 }616 $themes = get_site_transient( 'update_themes' );617 if ( $themes && ! empty( $themes->response ) ) {634 try { 635 $transient = (object) [ 636 'last_checked' => time() - ( 13 * 3600 ), 637 'checked' => [ 'default' => 'none' ], 638 'response' => [ 'default' => 'none' ], 639 ]; 640 $updatesFromHook = apply_filters( "pre_set_site_transient_update_themes", $transient, "update_themes" ); 641 } catch ( Throwable $e ) { 642 $updatesFromHook = $transient; 643 } 644 $themes = get_site_transient( 'update_themes' ); 645 if ( $themes && ! empty( $themes->response ) ) { 618 646 foreach ( $themes->response as $theme_slug => $theme_data ) { 619 647 $theme = wp_get_theme( $theme_slug ); … … 725 753 * 726 754 * @param WP_REST_Request $request The request object. 727 * @param string $type The type of translations to update. 728 * @param string $slug The slug of the translations to update. 755 * @param string $type The type of translations to update. 756 * @param string $slug The slug of the translations to update. 757 * 729 758 * @return WP_REST_Response The response object. 730 759 */ … … 802 831 ob_end_clean(); 803 832 804 $failed_translations = $skin->getErrors();833 $failed_translations = $skin->getErrors(); 805 834 $updated_translations = $skin->getSuccess(); 806 835 … … 834 863 * 835 864 * @param WP_REST_Request $request The request object. 865 * 836 866 * @return WP_REST_Response The response object. 837 867 */ … … 916 946 * 917 947 * @param WP_REST_Request $request The request object. 948 * 918 949 * @return WP_REST_Response The response object. 919 950 */ … … 1025 1056 WP_Filesystem(); 1026 1057 } 1058 1059 public function check_authentication($request) { 1060 // Verificar la autenticación por Application Password 1061 return current_user_can('administrator'); 1062 } 1063 1064 public function generate_login_token($request) { 1065 // Generar token único 1066 $token = wp_generate_password($this->token_length, false); 1067 1068 // Guardar el token en las opciones de WordPress con tiempo de expiración 1069 $token_data = [ 1070 'token' => $token, 1071 'expires' => time() + $this->token_expiry, 1072 'user_id' => get_current_user_id() 1073 ]; 1074 1075 set_transient('multi_wp_login_token_' . $token, $token_data, $this->token_expiry); 1076 1077 return rest_ensure_response(['token' => $token]); 1078 } 1079 1080 public function process_auto_login($request) { 1081 $token = $request->get_param('token'); 1082 1083 if (!$token) { 1084 wp_redirect(wp_login_url()); 1085 exit; 1086 } 1087 1088 $token_data = get_transient('multi_wp_login_token_' . $token); 1089 1090 if (!$token_data || time() > $token_data['expires']) { 1091 wp_redirect(wp_login_url()); 1092 exit; 1093 } 1094 1095 // Eliminar el token usado 1096 delete_transient('multi_wp_login_token_' . $token); 1097 1098 // Realizar el login 1099 $user = get_user_by('id', $token_data['user_id']); 1100 if ($user) { 1101 wp_set_current_user($user->ID); 1102 wp_set_auth_cookie($user->ID); 1103 1104 // Redirigir al admin 1105 wp_redirect(admin_url()); 1106 exit; 1107 } 1108 1109 wp_redirect(wp_login_url()); 1110 exit; 1111 } 1027 1112 } -
multi-connect/trunk/multi-connect.php
r3243412 r3243448 4 4 * Plugin URI: https://multi-wp.com 5 5 * Description: Connect your WordPress site with Multi-WP for centralized management and updates. 6 * Version: 1.0.4 46 * Version: 1.0.45 7 7 * Requires at least: 5.8 8 8 * Requires PHP: 7.4 -
multi-connect/trunk/readme.txt
r3243412 r3243448 5 5 Tested up to: 6.7 6 6 Requires PHP: 7.4 7 Stable tag: 1.0.4 47 Stable tag: 1.0.45 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 44 44 45 45 == Changelog == 46 47 = 1.0.45 = 48 * Auto login improvements. 46 49 47 50 = 1.0.44 =
Note: See TracChangeset
for help on using the changeset viewer.