parent_id = add_submenu_page( $parent_slug, esc_html__( 'WebberZone Snippetz Tools', 'add-to-all' ), $menu_title, 'manage_options', 'ata_tools', array( $this, 'render_page' ) ); } /** * Render the tools page. * * @since 2.3.0 * * @return void */ public function render_page() { /* Message for successful file import */ if ( isset( $_GET['settings_import'] ) && 'success' === $_GET['settings_import'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended add_settings_error( 'ata-notices', '', esc_html__( 'Settings have been imported successfully', 'add-to-all' ), 'updated' ); } if ( isset( $_GET['assets_regenerated'] ) && isset( $_GET['snippet_files'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $snippet_count = absint( wp_unslash( $_GET['snippet_files'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $notice = sprintf( /* translators: %d: number of snippet files regenerated. */ _n( 'Regenerated assets and %d snippet file.', 'Regenerated assets and %d snippet files.', $snippet_count, 'add-to-all' ), $snippet_count ); add_settings_error( 'ata-notices', '', esc_html( $notice ), 'updated' ); } ob_start(); ?>

array( 'title' => esc_html__( 'CSS File', 'add-to-all' ), 'filename' => 'combined.min.css', ), 'js' => array( 'title' => esc_html__( 'JS File', 'add-to-all' ), 'filename' => 'combined.min.js', ), ); foreach ( $files as $type => $file ) { $stats = Minifier::get_file_stats( $file['filename'] ); ?>

:




1, 'snippet_files' => $snippet_files, ), $redirect_url ); wp_safe_redirect( $redirect_url ); exit; } /** * Process a settings export that generates a .json file of the plugin settings. * * @since 2.3.0 */ public function process_settings_export() { if ( ! isset( $_POST['ata_export_settings_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['ata_export_settings_nonce'] ), 'ata_export_settings_nonce' ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } $settings = get_option( 'ata_settings' ); ignore_user_abort( true ); nocache_headers(); header( 'Content-Type: application/json; charset=utf-8' ); header( 'Content-Disposition: attachment; filename=ata-settings-export-' . gmdate( 'm-d-Y' ) . '.json' ); header( 'Expires: 0' ); echo wp_json_encode( $settings ); exit; } /** * Process a settings import from a json file. * * @since 2.3.0 */ public function process_settings_import() { if ( ! isset( $_POST['ata_import_settings_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['ata_import_settings_nonce'] ) ), 'ata_import_settings_nonce' ) ) { wp_die( esc_html__( 'Nonce verification failed', 'add-to-all' ) ); } if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to perform this action.', 'add-to-all' ) ); } $filename = 'import_settings_file'; $tmp = isset( $_FILES[ $filename ]['name'] ) ? explode( '.', sanitize_file_name( wp_unslash( $_FILES[ $filename ]['name'] ) ) ) : array(); $extension = end( $tmp ); if ( 'json' !== $extension ) { wp_die( esc_html__( 'Please upload a valid .json file', 'add-to-all' ) ); } $import_file = isset( $_FILES[ $filename ]['tmp_name'] ) ? ( wp_unslash( $_FILES[ $filename ]['tmp_name'] ) ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized if ( empty( $import_file ) ) { wp_die( esc_html__( 'Please upload a file to import', 'add-to-all' ) ); } // Retrieve the settings from the file and convert the json object to an array. $settings = (array) json_decode( file_get_contents( $import_file ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $settings = Settings::sanitize_all( $settings ); update_option( 'ata_settings', $settings ); if ( \WebberZone\Snippetz\Util\Helpers::is_snippets_enabled() ) { $redirect_url = admin_url( 'edit.php?post_type=ata_snippets&page=ata_tools&settings_import=success' ); } else { $redirect_url = admin_url( 'tools.php?page=ata_tools&settings_import=success' ); } wp_safe_redirect( $redirect_url ); exit; } /** * Enqueue scripts and styles. * * @since 2.3.0 * * @param string $hook The current screen hook. */ public function admin_enqueue_scripts( $hook ) { $screen = get_current_screen(); if ( $this->parent_id === $screen->id || $this->parent_id === $hook ) { wp_enqueue_style( 'wp-spinner' ); } } /** * Clear generated assets and cached data. * * @since 2.3.0 */ public function clear_assets() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to perform this action.', 'add-to-all' ) ); } check_admin_referer( 'ata_clear_assets' ); // Clear all cache transients. $cache_keys = array( 'ata_combined_css', 'ata_combined_js', 'ata_first_post_year', ); foreach ( $cache_keys as $key ) { delete_transient( $key ); } // Clear stored combined file URLs. delete_option( 'ata_combined_css_url' ); delete_option( 'ata_combined_js_url' ); // Delete all generated files. Minifier::delete_generated_files(); Minifier::clear_snippet_file_meta(); if ( \WebberZone\Snippetz\Util\Helpers::is_snippets_enabled() ) { $redirect_url = admin_url( 'edit.php?post_type=ata_snippets&page=ata_tools' ); } else { $redirect_url = admin_url( 'tools.php?page=ata_tools' ); } wp_safe_redirect( $redirect_url ); exit; } }