'breznflow-themes', 'error' => 'invalid_file', ), admin_url( 'admin.php' ) ) ); exit; } if ( ! isset( $file['tmp_name'] ) || ! is_uploaded_file( $file['tmp_name'] ) ) { wp_safe_redirect( add_query_arg( array( 'page' => 'breznflow-themes', 'error' => 'upload_failed', ), admin_url( 'admin.php' ) ) ); exit; } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $raw = file_get_contents( $file['tmp_name'] ); if ( false === $raw ) { wp_safe_redirect( add_query_arg( array( 'page' => 'breznflow-themes', 'error' => 'read_failed', ), admin_url( 'admin.php' ) ) ); exit; } $data = json_decode( $raw, true ); if ( ! is_array( $data ) ) { wp_safe_redirect( add_query_arg( array( 'page' => 'breznflow-themes', 'error' => 'invalid_json', ), admin_url( 'admin.php' ) ) ); exit; } $result = ThemeImporter::import( $data ); if ( is_wp_error( $result ) ) { wp_safe_redirect( add_query_arg( array( 'page' => 'breznflow-themes', 'error' => 'validation', 'message' => rawurlencode( $result->get_error_message() ), ), admin_url( 'admin.php' ) ) ); exit; } wp_safe_redirect( add_query_arg( array( 'page' => 'breznflow-themes', 'imported' => '1', ), admin_url( 'admin.php' ) ) ); exit; } /** * Processes a theme delete action. */ public function handle_delete(): void { if ( ! isset( $_GET['page'] ) || 'breznflow-themes' !== $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } if ( empty( $_GET['action'] ) || 'delete_theme' !== $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } $id = isset( $_GET['theme_id'] ) ? sanitize_key( $_GET['theme_id'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( '' === $id ) { return; } check_admin_referer( 'breznflow_theme_delete_' . $id ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Insufficient permissions.', 'breznflow' ) ); } ThemeImporter::delete( $id ); wp_safe_redirect( add_query_arg( array( 'page' => 'breznflow-themes', 'deleted' => '1', ), admin_url( 'admin.php' ) ) ); exit; } /** * Renders the themes management page. * * @since 1.0.0 * @return void */ public function render(): void { require BREZNFLOW_DIR . 'includes/Admin/views/themes.php'; } }