nation_dir . '/' . $ext_dir['name']; { $source_ext_files = $wp_filesystem->dirlist( $source_extension_dir, true ); if ( $source_ext_files === false ) { return new WP_Error( $wp_error_id, __( 'Cannot access directory: ', 'fw' ) . $source_extension_dir ); } if ( empty( $source_ext_files ) ) { /** * Source extension directory is empty, do nothing. * This happens when the extension is a git submodule in repository * but in zip it comes as an empty directory. */ continue; } } // prepare destination { // create if not exists if ( ! $wp_filesystem->exists( $destination_extension_dir ) ) { if ( ! FW_WP_Filesystem::mkdir_recursive( $destination_extension_dir ) ) { return new WP_Error( $wp_error_id, __( 'Cannot create directory: ', 'fw' ) . $destination_extension_dir ); } } // remove everything except the extensions/ dir { $dest_ext_files = $wp_filesystem->dirlist( $destination_extension_dir, true ); if ( $dest_ext_files === false ) { return new WP_Error( $wp_error_id, __( 'Cannot access directory: ', 'fw' ) . $destination_extension_dir ); } $destination_has_extensions_dir = false; foreach ( $dest_ext_files as $dest_ext_file ) { if ( in_array( $dest_ext_file['name'], $this->skip_file_names ) ) { continue; } if ( $dest_ext_file['name'] === 'extensions' && $dest_ext_file['type'] === 'd' ) { $destination_has_extensions_dir = true; continue; } $dest_ext_file_path = $destination_extension_dir . '/' . $dest_ext_file['name']; if ( ! $wp_filesystem->delete( $dest_ext_file_path, true, $dest_ext_file['type'] ) ) { return new WP_Error( $wp_error_id, __( 'Cannot delete: ', 'fw' ) . $dest_ext_file_path ); } } } } // move files from source to destination extension directory { $source_has_extensions_dir = false; foreach ( $source_ext_files as $source_ext_file ) { if ( in_array( $source_ext_file['name'], $this->skip_file_names ) ) { continue; } if ( $source_ext_file['name'] === 'extensions' && $source_ext_file['type'] === 'd' ) { $source_has_extensions_dir = true; continue; } $source_ext_file_path = $source_extension_dir . '/' . $source_ext_file['name']; $dest_ext_file_path = $destination_extension_dir . '/' . $source_ext_file['name']; if ( ! $wp_filesystem->move( $source_ext_file_path, $dest_ext_file_path ) ) { return new WP_Error( $wp_error_id, sprintf( __( 'Cannot move "%s" to "%s"', 'fw' ), $source_ext_file_path, $dest_ext_file_path ) ); } } } if ( $source_has_extensions_dir ) { if ( $destination_has_extensions_dir ) { $merge_result = $this->merge_extensions( $source_extension_dir . '/extensions', $destination_extension_dir . '/extensions' ); if ( $merge_result !== true ) { return $merge_result; } } else { if ( ! $wp_filesystem->move( $source_extension_dir . '/extensions', $destination_extension_dir . '/extensions' ) ) { return new WP_Error( $wp_error_id, sprintf( __( 'Cannot move "%s" to "%s"', 'fw' ), $source_extension_dir . '/extensions', $destination_extension_dir . '/extensions' ) ); } } } } return true; } /** * @internal */ public function _action_update_framework() { $nonce_name = '_nonce_fw_ext_update_framework'; if ( ! isset( $_POST[ $nonce_name ] ) || ! wp_verify_nonce( $_POST[ $nonce_name ] ) ) { wp_die( __( 'Invalid nonce.', 'fw' ) ); } { if ( ! class_exists( '_FW_Ext_Update_Framework_Upgrader_Skin' ) ) { fw_include_file_isolated( $this->get_declared_path( '/includes/classes/class--fw-ext-update-framework-upgrader-skin.php' ) ); } $skin = new _FW_Ext_Update_Framework_Upgrader_Skin( array( 'title' => __( 'Framework Update', 'fw' ), ) ); } require_once ABSPATH . 'wp-admin/admin-header.php'; $skin->header(); do { if ( ! FW_WP_Filesystem::request_access( fw_get_framework_directory(), fw_current_url(), array( $nonce_name ) ) ) { break; } $update = $this->get_framework_update(); if ( $update === false ) { $skin->error( __( 'Failed to get framework latest version.', 'fw' ) ); break; } elseif ( is_wp_error( $update ) ) { $skin->error( $update ); break; } /** @var FW_Ext_Update_Service $service */ $service = $this->get_child( $update['service'] ); $update_result = $this->update( array( 'wp_fs_destination_dir' => FW_WP_Filesystem::real_path_to_filesystem_path( fw_get_framework_directory() ), 'download_callback' => array( $service, '_download_framework' ), 'download_callback_args' => array( $update['latest_version'], $this->get_wp_fs_tmp_dir() ), 'skin' => $skin, 'title' => __( 'Framework', 'fw' ), ) ); if ( is_wp_error( $update_result ) ) { $skin->error( $update_result ); break; } $skin->set_result( true ); $skin->after(); } while ( false ); $skin->footer(); require_once( ABSPATH . 'wp-admin/admin-footer.php' ); } /** * @internal */ public function _action_update_theme() { $nonce_name = '_nonce_fw_ext_update_theme'; if ( ! isset( $_POST[ $nonce_name ] ) || ! wp_verify_nonce( $_POST[ $nonce_name ] ) ) { wp_die( __( 'Invalid nonce.', 'fw' ) ); } { if ( ! class_exists( '_FW_Ext_Update_Theme_Upgrader_Skin' ) ) { fw_include_file_isolated( $this->get_declared_path( '/includes/classes/class--fw-ext-update-theme-upgrader-skin.php' ) ); } $skin = new _FW_Ext_Update_Theme_Upgrader_Skin( array( 'title' => __( 'Theme Update', 'fw' ), ) ); } require_once( ABSPATH . 'wp-admin/admin-header.php' ); $skin->header(); do { if ( ! FW_WP_Filesystem::request_access( get_template_directory(), fw_current_url(), array( $nonce_name ) ) ) { break; } $update = $this->get_theme_update(); if ( $update === false ) { $skin->error( __( 'Failed to get theme latest version.', 'fw' ) ); break; } elseif ( is_wp_error( $update ) ) { $skin->error( $update ); break; } /** @var FW_Ext_Update_Service $service */ $service = $this->get_child( $update['service'] ); $update_result = $this->update( array( 'wp_fs_destination_dir' => FW_WP_Filesystem::real_path_to_filesystem_path( get_template_directory() ), 'download_callback' => array( $service, '_download_theme' ), 'download_callback_args' => array( $update['latest_version'], $this->get_wp_fs_tmp_dir() ), 'skin' => $skin, 'title' => __( 'Theme', 'fw' ), ) ); if ( is_wp_error( $update_result ) ) { $skin->error( $update_result ); break; } $skin->set_result( true ); $skin->after(); } while ( false ); $skin->footer(); require_once( ABSPATH . 'wp-admin/admin-footer.php' ); } /** * @internal * @param string $skin */ public function _action_update_extensions( $skin = '' ) { $nonce_name = '_nonce_fw_ext_update_extensions'; if ( ! isset( $_POST[ $nonce_name ] ) || ! wp_verify_nonce( $_POST[ $nonce_name ] ) ) { wp_die( __( 'Invalid nonce.', 'fw' ) ); } $form_input_name = 'extensions'; $extensions_list = FW_Request::POST( $form_input_name ); if ( empty( $extensions_list ) ) { FW_Flash_Messages::add( 'fw_ext_update', __( 'Please check the extensions you want to update.', 'fw' ), 'warning' ); wp_redirect( self_admin_url( 'update-core.php' ) ); exit; } // handle changes by the hack below { if ( is_string( $extensions_list ) ) { $extensions_list = json_decode( $extensions_list ); } else { $extensions_list = array_keys( $extensions_list ); } } { if ( ! class_exists( '_FW_Ext_Update_Extensions_Upgrader_Skin' ) ) { fw_include_file_isolated( $this->get_declared_path( '/includes/classes/class--fw-ext-update-extensions-upgrader-skin.php' ) ); } if ( ! $skin ) { $skin = new _FW_Ext_Update_Extensions_Upgrader_Skin( array( 'title' => __( 'Extensions Update', 'fw' ), ) ); } } if ( ! fw_is_cli() ) { require_once( ABSPATH . 'wp-admin/admin-header.php' ); } $skin->header(); do { /** * Hack for the ftp credentials template that does not support array post values * https://github.com/WordPress/WordPress/blob/3949a8b6cc50a021ed93798287b4ef9ea8a560d9/wp-admin/includes/file.php#L1144 */ $original_post_value = $_POST[ $form_input_name ]; $_POST[ $form_input_name ] = wp_slash( json_encode( $extensions_list ) ); if ( ! FW_WP_Filesystem::request_access( fw_get_framework_directory( '/extensions' ), fw_current_url(), array( $nonce_name, $form_input_name ) ) ) { // revert hack changes $_POST[ $form_input_name ] = $original_post_value; unset( $original_post_value ); break; } // revert hack changes $_POST[ $form_input_name ] = $original_post_value; unset( $original_post_value ); $updates = $this->get_extensions_with_updates(); if ( empty( $updates ) ) { $skin->error( __( 'No extensions updates found.', 'fw' ) ); break; } foreach ( $extensions_list as $extension_name ) { if ( ! ( $extension = fw()->extensions->get( $extension_name ) ) ) { $skin->error( sprintf( __( 'Extension "%s" does not exist or is disabled.', 'fw' ), $extension_name ) ); continue; } if ( ! isset( $updates[ $extension_name ] ) ) { $skin->error( sprintf( __( 'No update found for the "%s" extension.', 'fw' ), $extension->manifest->get_name() ) ); continue; } $update = $updates[ $extension_name ]; if ( is_wp_error( $update ) ) { $skin->error( $update ); continue; } /** @var FW_Ext_Update_Service $service */ $service = $this->get_child( $update['service'] ); $update_result = $this->update( array( 'wp_fs_destination_dir' => FW_WP_Filesystem::real_path_to_filesystem_path( $extension->get_declared_path() ), 'download_callback' => array( $service, '_download_extension' ), 'download_callback_args' => array( $extension, $update['latest_version'], $this->get_wp_fs_tmp_dir() ), 'skin' => $skin, 'title' => sprintf( __( '%s extension', 'fw' ), $extension->manifest->get_name() ), ), true ); if ( is_wp_error( $update_result ) ) { $skin->error( $update_result ); continue; } $skin->set_result( true ); if ( ! $this->ext_as_one_update() ) { $skin->decrement_extension_update_count( $extension_name ); } } if ( $this->ext_as_one_update() ) { $skin->decrement_extension_update_count( $extension_name ); } $skin->after(); } while ( false ); $skin->footer(); if ( ! fw_is_cli() ) { require_once( ABSPATH . 'wp-admin/admin-footer.php' ); } } public function _action_admin_notices() { $updates = $this->get_updates(); if ( ( empty( $updates['extensions'] ) && empty( $updates['theme'] ) ) || strpos( get_current_screen()->id, 'update-core' ) !== false || ( isset( $_GET['page'] ) && $_GET['page'] === 'fw-update' ) ) { return; } foreach ( $updates['extensions'] as $ext_name => $ext_update ) { if ( is_wp_error( $ext_update ) ) { return; } break; } $slug = is_multisite() && ! is_plugin_active_for_network( 'unyson/unyson.php' ) ? '?page=fw-update' : 'update-core.php#fw-ext-update-extensions'; if ( ! empty( $updates['extensions'] ) && empty( $updates['theme'] ) ) { $text = 'extensions updates'; } elseif ( empty( $updates['extensions'] ) && ! empty( $updates['theme'] ) ) { $text = 'theme update'; } else { $text = 'extensions/theme updates'; } echo '
' . sprintf( esc_html__( 'New %s available. %s', 'fw' ), $text, fw_html_tag( 'a', array( 'href' => self_admin_url( $slug ) ), esc_html__( 'Go to Updates page', 'fw' ) ) ) . '