文件操作 - import-export.php
返回文件管理
返回主菜单
删除本文件
文件: /storage/v12552/jimbrandstatter/public_html/wp-content/themes/Total/inc/admin/import-export.php
编辑文件内容
<?php namespace TotalTheme\Admin; \defined( 'ABSPATH' ) || exit; /** * Creates the admin panel for the customizer. */ class Import_Export { /** * Static-only class. */ private function __construct() {} /** * Init. */ public static function init() { \add_action( 'admin_menu', [ self::class, 'on_admin_menu' ], 9999 ); } /** * Runs on the "admin_menu" hook. */ public static function on_admin_menu() { $hook_suffix = \add_submenu_page( \WPEX_THEME_PANEL_SLUG, \esc_attr__( 'Import/Export', 'total' ), \esc_attr__( 'Import/Export', 'total' ), 'edit_theme_options', \WPEX_THEME_PANEL_SLUG . '-import-export', [ self::class, 'render_admin_page' ] ); add_action( "admin_print_scripts-{$hook_suffix}", [ self::class, 'enqueue_scripts' ] ); } /** * Register scripts. */ public static function enqueue_scripts() { \wp_enqueue_script( 'totaltheme-admin-import-export', \wpex_asset_url( 'js/admin/import-export.min.js' ), [ 'jquery' ], \WPEX_THEME_VERSION, true ); \wp_localize_script( 'totaltheme-admin-import-export', 'totaltheme_admin_import_export_vars', array( 'confirmReset' => esc_html__( 'Confirm Reset', 'total' ), 'importOptions' => esc_html__( 'Import Options', 'total' ), ) ); } /** * Perform actions. */ private static function perform_actions() { if ( ! wp_verify_nonce( $_POST['totaltheme-admin-import-export-nonce'] ?? '', 'totaltheme-admin-import-export' ) || ! \current_user_can( 'edit_theme_options' ) ) { return; } $form = $_POST['totaltheme_import_export'] ?? []; if ( ! is_array( $form ) ) { return; } // Delete options if import set to -1. if ( isset( $form['reset'] ) && '-1' == $form['reset'] ) { // Get menu locations. $locations = \get_theme_mod( 'nav_menu_locations' ); $save_menus = []; if ( $locations ) { foreach ( $locations as $key => $val ) { $save_menus[ $key ] = $val; } } // Get sidebars. $widget_areas = \get_theme_mod( 'widget_areas' ); // Remove all mods. \remove_theme_mods(); // WP fix. Logo doesn't get removed with \remove_theme_mods(); \set_theme_mod( 'custom_logo', '' ); \remove_theme_mod( 'custom_logo' ); // Re-add the menus. \set_theme_mod( 'nav_menu_locations', array_map( 'absint', $save_menus ) ); \set_theme_mod( 'widget_areas', $widget_areas ); // Error messages. $error_msg = \esc_attr__( 'All settings have been reset.', 'total' ); $error_type = 'updated'; } // Set theme mods based on json data. elseif ( ! empty( $form['import'] ) ) { // Decode input data. $theme_mods = \json_decode( \stripslashes_deep( $form['import'] ), true ); // Validate json file then set new theme options. if ( \function_exists( 'json_last_error' ) && \defined( 'JSON_ERROR_NONE' ) ) { if ( JSON_ERROR_NONE === \json_last_error() ) { // Loop through mods and add them. foreach ( $theme_mods as $theme_mod => $value ) { \set_theme_mod( $theme_mod, $value ); } // Success message. $error_msg = \esc_attr__( 'Settings imported successfully.', 'total' ); $error_type = 'updated'; } // Display invalid json data error. else { $error_msg = \esc_attr__( 'Invalid Import Data.', 'total' ); $error_type = 'error'; } } else { $error_msg = \esc_attr__( 'The version of PHP on your server is very outdated and can not support a proper import. Please make sure your server has been updated to the WordPress "supported" version of PHP.', 'total' ); $error_type = 'error'; } } // No json data entered. else { $error_msg = \esc_attr__( 'No import data found.', 'total' ); $error_type = 'error'; } if ( $error_msg ) { echo "<div class='notice {$error_type}'><p>{$error_msg}</p></div>"; } } /** * Settings page output. */ public static function render_admin_page() { if ( ! \current_user_can( 'edit_theme_options' ) ) { return; } if ( isset( $_POST['totaltheme_import_export'] ) ) { self::perform_actions(); } ?> <div class="wpex-theme-import-export wrap"> <?php // Need to insert h1 for notices. echo '<h1 style="display:none;" aria-hidden="true"></h1>'; ?> <div class="notice notice-warning"><p><?php \esc_html_e( 'This will export/import/delete ALL theme_mods that means if other plugins are adding settings in the Customizer it will export/import/delete those as well.', 'total' ); ?></p></div> <form method="post"> <table class="form-table"> <tr valign="top"> <th scope="row"><?php \esc_html_e( 'Export Settings', 'total' ); ?></th> <td> <?php // Get an array of all the theme mods. if ( $theme_mods = \get_theme_mods() ) { $mods = []; foreach ( $theme_mods as $theme_mod => $value ) { $mods[$theme_mod] = \maybe_unserialize( $value ); } $json = \json_encode( $mods ); $disabled = ''; } else { $json = \esc_attr__( 'No Settings Found', 'total' ); $disabled = ' disabled'; } echo '<textarea class="wpex-theme-import-export__settings" rows="10" cols="50" readonly style="width:100%;">' . $json . '</textarea>'; ?> <p class="submit"> <a href="#" class="wpex-theme-import-export__highlight button-primary<?php echo \esc_attr( $disabled ); ?>"><?php \esc_html_e( 'Highlight Options', 'total' ); ?></a> </p> </td> </tr> <tr valign="top"> <th scope="row"><?php \esc_html_e( 'Import Settings', 'total' ); ?></th> <td> <textarea name="totaltheme_import_export[import]" rows="10" cols="50" style="width:100%;"></textarea> <input class="wpex-theme-import-export__reset" name="totaltheme_import_export[reset]" type="hidden" value=""></input> <p class="submit"> <input type="submit" class="wpex-theme-import-export__submit button-primary" value="<?php \esc_attr_e( 'Import Options', 'total' ) ?>"> <a href="#" class="wpex-theme-import-export__delete button-secondary"><?php \esc_html_e( 'Reset Options', 'total' ); ?></a> <a href="#" class="wpex-theme-import-export__delete-cancel button-secondary" style="display:none;"><?php \esc_html_e( 'Cancel Reset', 'total' ); ?></a> </p> <div class="wpex-theme-import-export__warning error inline" style="display:none;"> <p style="margin:.5em 0;"><?php \esc_attr_e( 'Always make sure you have a backup of your settings before resetting, just incase! Your menu locations and widget areas will not reset and will remain intact. All customizer and addon settings will reset.', 'total' ); ?></p> </div> </td> </tr> </table> <?php \wp_nonce_field( 'totaltheme-admin-import-export', 'totaltheme-admin-import-export-nonce' ); ?> </form> </div> <?php } }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件