當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ITSEC_Modules::update_module_paths方法代碼示例

本文整理匯總了PHP中ITSEC_Modules::update_module_paths方法的典型用法代碼示例。如果您正苦於以下問題:PHP ITSEC_Modules::update_module_paths方法的具體用法?PHP ITSEC_Modules::update_module_paths怎麽用?PHP ITSEC_Modules::update_module_paths使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ITSEC_Modules的用法示例。


在下文中一共展示了ITSEC_Modules::update_module_paths方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: change_content_directory

 public static function change_content_directory($dir_name)
 {
     $dir_name = sanitize_file_name($dir_name);
     if (empty($dir_name)) {
         return new WP_Error('itsec-content-directory-utility-change-content-directory-empty-directory-name', __('The content directory cannot be changed to a blank directory name.', 'better-wp-security'));
     }
     if (preg_match('{^(?:/|\\|[a-z]:)}i', $dir_name)) {
         return new WP_Error('itsec-content-diraectory-utility-change-content-directory-received-absolute-path', sprintf(__('The new directory name cannot be an absolute path. Please supply a path that is relative to <code>ABSPATH</code> (<code>%s</code>).', 'better-wp-security'), esc_html(ABSPATH)));
     }
     if (0 === strpos(WP_CONTENT_DIR, ABSPATH)) {
         $old_name = substr(WP_CONTENT_DIR, strlen(ABSPATH));
         $new_name = $dir_name;
     } else {
         $old_name = WP_CONTENT_DIR;
         $new_name = ABSPATH . $dir_name;
     }
     $old_dir = WP_CONTENT_DIR;
     $new_dir = ABSPATH . $dir_name;
     if ($old_dir === $new_dir) {
         return new WP_Error('itsec-content-directory-utility-change-content-directory-received-same-directory', __('The new directory name cannot be the same as the current directory name. Please supply a new directory name.', 'better-wp-security'));
     }
     if (file_exists($new_dir)) {
         return new WP_Error('itsec-content-directory-utility-change-content-directory-path-already-exists', sprintf(__('A file or directory already exists at <code>%s</code>. No Directory Name changes have been made. Please choose a new Directory Name or remove the existing file or directory and try again.', 'better-wp-security'), esc_html($new_dir)));
     }
     require_once ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
     $old_permissions = ITSEC_Lib_Directory::get_permissions($old_dir);
     $result = rename($old_dir, $new_dir);
     if (!$result) {
         /* translators: 1: Old directory path, 2: New directory path */
         return new WP_Error('itsec-content-directory-utility-change-content-directory-cannot-rename-directory', sprintf(__('Unable to rename the <code>%1$s</code> directory to <code>%2$s</code>. This could indicate a file permission issue or that your server does not support the supplied name as a valid directory name. No config file or directory changes have been made.', 'better-wp-security'), esc_html($old_name), esc_html($new_name)));
     }
     // Make sure ITSEC_Core knows it's in a different place
     $plugin_file = str_replace($old_dir, $new_dir, ITSEC_Core::get_plugin_file());
     ITSEC_Core::set_plugin_file($plugin_file);
     ITSEC_Core::update_wp_upload_dir($old_dir, $new_dir);
     ITSEC_Modules::update_module_paths($old_dir, $new_dir);
     $new_permissions = ITSEC_Lib_Directory::get_permissions($new_dir);
     if (is_int($old_permissions) && is_int($new_permissions) && $old_permissions != $new_permissions) {
         $result = ITSEC_Lib_Directory::chmod($new_dir, $old_permissions);
         if (is_wp_error($result)) {
             /* translators: 1: Directory path, 2: Directory permissions */
             return new WP_Error('itsec-content-directory-utility-change-content-directory-unable-to-change-permissions', sprintf(__('Unable to set the permissions of the new Directory Name (<code>%1$s</code>) to match the permissions of the old Directory Name. You may have to manually change the permissions of the directory to <code>%2$s</code> in order for your site to function properly.', 'better-wp-security'), esc_html($new_name), esc_html($old_permissions)));
         }
     }
     if ('wp-content' === $dir_name) {
         // We're undoing the change.
         $expression = self::get_wp_config_define_expression();
         $expression = substr($expression, 0, -1);
         $expression .= "[\r\n]*|";
         $modification_result = ITSEC_Lib_Config_File::remove_from_wp_config($expression);
     } else {
         $modification = self::get_wp_config_modification($new_dir, get_option('siteurl') . "/{$dir_name}");
         $modification_result = ITSEC_Lib_Config_File::append_wp_config($modification, true);
     }
     if (is_wp_error($modification_result)) {
         $rename_result = rename($new_dir, $old_dir);
         if ($rename_result) {
             // Reset the ITSEC_Core plugin file back to its old setting.
             $plugin_file = str_replace($new_dir, $old_dir, ITSEC_Core::get_plugin_file());
             ITSEC_Core::set_plugin_file($plugin_file);
             ITSEC_Core::update_wp_upload_dir($new_dir, $old_dir);
             ITSEC_Modules::update_module_paths($new_dir, $old_dir);
             ITSEC_Lib_Directory::chmod($old_dir, $old_permissions);
             /* translators: 1: Specific error details */
             return new WP_Error($modification_result->get_error_code(), sprintf(__('Unable to update the <code>wp-config.php</code> file. No directory or config file changes have been made. The error that prevented the file from updating is as follows: %1$s', 'better-wp-security'), $modification_result->get_error_message()));
         } else {
             /* translators: 1: Old directory path, 2: New directory path, 3: Specific error details */
             return new WP_Error($modification_result->get_error_code(), sprintf(__('CRITICAL ERROR: The <code>%1$s</code> directory was successfully renamed to the new name (<code>%2$s</code>). However, an error occurred when updating the <code>wp-config.php</code> file to configure WordPress to use the new content directory. iThemes Security attempted to rename the directory back to its original name, but an unknown error prevented the rename from working as expected. In order for your site to function properly, you will either need to manually rename the <code>%2$s</code> directory back to <code>%1$s</code> or manually update the <code>wp-config.php</code> file with the necessary modifications. The error that prevented the file from updating is as follows: %3$s', 'better-wp-security'), $old_name, $new_name, $modification_result->get_error_message()));
         }
     }
     $backups_location = ITSEC_Modules::get_setting('backup', 'location');
     $backups_location = str_replace($old_dir, $new_dir, $backups_location);
     ITSEC_Modules::set_setting('backup', 'location', $backups_location);
     $log_location = ITSEC_Modules::get_setting('global', 'log_location');
     $log_location = str_replace($old_dir, $new_dir, $log_location);
     ITSEC_Modules::set_setting('global', 'log_location', $log_location);
     $nginx_file = ITSEC_Modules::get_setting('global', 'nginx_file');
     $nginx_file = str_replace($old_dir, $new_dir, $nginx_file);
     ITSEC_Modules::set_setting('global', 'nginx_file', $nginx_file);
     return $dir_name;
 }
開發者ID:Garth619,項目名稱:Femi9,代碼行數:81,代碼來源:utility.php


注:本文中的ITSEC_Modules::update_module_paths方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。