*/ class Epicformbuilder_Admin { /** * The ID of this plugin. * * @var string $page_hook_suffix The ID of this plugin. */ public $page_hook_suffix; /** * Register the JavaScript and CSS for the admin area. * * @since 1.0.0 */ public function register_scripts_and_styles() { Epicformbuilder_Vite::register( 'epicforms-admin-client', 'epicforms-admin-css', 'dist/admin.js', 'dist/admin.css', [ 'wp-api', 'wp-element' ] ); } /** * Register the stylesheets for the admin area. * * @since 1.0.0 * * @param string $hook_suffix The current admin page. */ public function enqueue_styles( $hook_suffix ) { if ( $hook_suffix !== $this->page_hook_suffix ) { return; } wp_enqueue_style( 'epicforms-admin-css' ); wp_add_inline_style( 'epicforms-admin-css', '#wpcontent { padding-left: 0; }' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 * * @param string $hook_suffix The current admin page. */ public function enqueue_scripts( $hook_suffix ) { if ( $hook_suffix !== $this->page_hook_suffix ) { return; } Epicformbuilder_Vite::enqueue( 'epicforms-admin-client', 'epicforms-admin-css', 'src/admin/index.jsx' ); } /** * Adds Epic Forms Builder WordPress admin menu items * @return void */ public function menu() { $this->page_hook_suffix = add_menu_page( 'Epic Forms', 'Epic Forms', 'manage_options', 'epicforms', [ $this, 'render' ], EPICFORMS_URL . 'assets/logo-20.svg' ); } /** * Handles protected file download requests * * @return void */ public function protected_download() { check_admin_referer( 'epicforms_protected_download' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( 'Unauthorized', 'Error', [ 'response' => 403 ] ); } $file = sanitize_file_name( wp_unslash( $_GET['file'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- verified by check_admin_referer() above. $type = sanitize_file_name( wp_unslash( $_GET['type'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- verified by check_admin_referer() above. if ( ! in_array( $type, [ 'exports', 'logs' ], true ) ) { wp_die( 'File not found', 'Error', [ 'response' => 404 ] ); } $filepath = Epicformbuilder_Services_Uploads::base_dir() . "{$type}/{$file}"; if ( ! $file || ! file_exists( $filepath ) ) { wp_die( 'File not found', 'Error', [ 'response' => 404 ] ); } nocache_headers(); header( 'Content-Description: File Transfer' ); $content_type = 'exports' === $type ? 'text/csv; charset=utf-8' : 'text/plain; charset=utf-8'; header( 'Content-Type: ' . $content_type ); header( 'Content-Disposition: attachment; filename="' . basename( $filepath ) . '"' ); header( 'Content-Length: ' . filesize( $filepath ) ); flush(); readfile( $filepath ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- streaming file download to browser exit; } /** * Renders Epic Forms Builder admin index page with ReactJS app on it * @return void */ public function render() { include_once __DIR__ . '/partials/epicformbuilder-admin-display.php'; } }