'' ), $atts, 'codexta_form' ); $key = preg_replace( '/[^a-z0-9-]/', '', strtolower( (string) $atts['key'] ) ); if ( '' === $key ) { return self::problem( __( 'Codexta form: add the form key, e.g. [codexta_form key="contact-us"]. Copy it from Codexta > Settings > Forms.', 'codexta-assistant' ) ); } if ( ! Codexta_Connect::is_connected() ) { return self::problem( __( 'Codexta form: connect the shop first (WooCommerce > Codexta Assistant). Visitors see nothing until then.', 'codexta-assistant' ) ); } // One forms.js per page however many forms it has; it renders every div with data-codexta-form. wp_enqueue_script( 'codexta-forms', Codexta_Connect::base_url() . '/forms.js', array(), null, array( 'in_footer' => true, 'strategy' => 'async' ) ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion return sprintf( '
', esc_attr( $key ), esc_attr( Codexta_Connect::site_uuid() ), esc_url( Codexta_Connect::base_url() ) ); } /** * A form that cannot render: a notice for admins, only an HTML comment for visitors. * * @param string $message What is wrong. * @return string */ private static function problem( $message ) { if ( current_user_can( 'manage_options' ) ) { return '' . esc_html( $message ) . '
'; } return ''; } }