true, 'strategy' => 'defer', ) ); $config = array( 'restUrl' => esc_url_raw( rest_url( 'fillaro/v1/' ) ), 'i18n' => array( 'required' => __( 'This field is required.', 'fillaro' ), 'email' => __( 'Enter a valid email address.', 'fillaro' ), 'url' => __( 'Enter a valid web address.', 'fillaro' ), 'number' => __( 'Enter a number.', 'fillaro' ), 'fix' => __( 'Please fix the highlighted fields.', 'fillaro' ), 'network' => __( 'Connection problem. Check your internet and try again.', 'fillaro' ), 'sending' => __( 'Sending…', 'fillaro' ), ), ); if ( is_user_logged_in() ) { // Logged-in REST requests need a nonce, or WordPress treats them as guests. $config['nonce'] = wp_create_nonce( 'wp_rest' ); } wp_add_inline_script( self::HANDLE, 'window.fillaroConfig = ' . wp_json_encode( $config ) . ';', 'before' ); } /** * Enqueue in the head when the current post contains a form, so the * style loads before the form paints. */ public function maybe_enqueue_early() { $post = get_post(); if ( $post && ( has_shortcode( $post->post_content, 'fillaro' ) || has_block( 'fillaro/form', $post ) ) ) { self::enqueue(); } } /** * Enqueue the front-end assets. */ public static function enqueue() { wp_enqueue_style( self::HANDLE ); wp_enqueue_script( self::HANDLE ); } /** * Read a build/*.asset.php file. * * @param string $name Entry name. * @return array{dependencies:array,version:string} */ public static function asset_file( $name ) { $path = FILLARO_DIR . 'build/' . $name . '.asset.php'; if ( is_readable( $path ) ) { $asset = require $path; if ( is_array( $asset ) ) { return $asset; } } return array( 'dependencies' => array(), 'version' => FILLARO_VERSION, ); } }