post_content; if ( has_block( self::BLOCK, $post ) || has_shortcode( $content, self::SHORTCODE ) ) { wp_enqueue_style( self::STYLE ); } } public static function allow_dialog( $tags ) { if ( is_array( $tags ) && ! isset( $tags['dialog'] ) ) { $tags['dialog'] = array( 'class' => true, 'id' => true, 'aria-labelledby' => true, 'aria-describedby' => true, 'data-*' => true ); } if ( is_array( $tags ) ) { $tags['svg'] = ( $tags['svg'] ?? array() ) + array( 'class' => true, 'viewbox' => true, 'width' => true, 'height' => true, 'aria-hidden' => true, 'focusable' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true ); $tags['path'] = ( $tags['path'] ?? array() ) + array( 'd' => true ); } return $tags; } public static function allowed_html() { $tags = class_exists( 'AIEO_Form_Render' ) ? AIEO_Form_Render::allowed_html() : array(); $tags['dialog'] = array( 'class' => true, 'id' => true, 'aria-labelledby' => true, 'data-*' => true ); $tags['button'] = ( $tags['button'] ?? array() ) + array( 'type' => true, 'class' => true, 'aria-haspopup' => true, 'aria-controls' => true, 'aria-label' => true, 'data-*' => true ); $tags['a'] = ( $tags['a'] ?? array() ) + array( 'href' => true, 'class' => true, 'aria-label' => true ); $tags['h2'] = ( $tags['h2'] ?? array() ) + array( 'class' => true, 'id' => true ); $tags['svg'] = ( $tags['svg'] ?? array() ) + array( 'class' => true, 'viewbox' => true, 'width' => true, 'height' => true, 'aria-hidden' => true, 'focusable' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true ); $tags['path'] = ( $tags['path'] ?? array() ) + array( 'd' => true ); return $tags; } public static function shortcode( $atts ) { $atts = shortcode_atts( array( 'form' => '', 'label' => '', 'opens' => '', 'page' => '', 'contact' => '', 'location' => '', 'icons' => '' ), (array) $atts, self::SHORTCODE ); return self::render( $atts ); } public static function resolve( $form_id, array $a = array() ) { $words = AIEO_Form_CPT::words( (int) $form_id ); $label = trim( (string) ( $a['label'] ?? '' ) ); if ( '' === $label ) { $label = '' !== trim( (string) $words['cta_label'] ) ? (string) $words['cta_label'] : html_entity_decode( get_the_title( (int) $form_id ), ENT_QUOTES, 'UTF-8' ); } $opens = in_array( (string) ( $a['opens'] ?? '' ), array( 'modal', 'page' ), true ) ? (string) $a['opens'] : ( 'page' === (string) $words['cta_opens'] ? 'page' : 'modal' ); $page = absint( $a['page'] ?? 0 ); $page = $page > 0 ? $page : absint( $words['cta_page'] ); $url = ''; if ( 'page' === $opens && $page > 0 ) { $page = (int) apply_filters( 'wpml_object_id', $page, 'page', true ); if ( function_exists( 'pll_get_post' ) ) { $translated = (int) pll_get_post( $page ); $page = $translated > 0 ? $translated : $page; } $url = 'publish' === get_post_status( $page ) ? (string) get_permalink( $page ) : ''; } $contact = trim( (string) ( $a['contact'] ?? '' ) ); $contact = '' !== $contact ? $contact : (string) ( $words['cta_contact'] ?? '' ); $location = sanitize_key( (string) ( $a['location'] ?? '' ) ); return array( 'label' => $label, 'opens' => 'page' === $opens && '' !== $url ? 'page' : 'modal', 'url' => $url, 'contact' => class_exists( 'AIEO_Location_Contact' ) ? AIEO_Location_Contact::parse( $contact ) : array(), 'icons' => in_array( (string) ( $a['icons'] ?? '' ), array( 'show', 'hide' ), true ) ? 'show' === $a['icons'] : 'hide' !== (string) ( $words['cta_icons'] ?? '' ), 'location' => '' !== $location ? $location : sanitize_key( (string) ( $words['cta_location'] ?? '' ) ), ); } private static function contact_buttons( $loc, array $channels, $icons = true ) { if ( ! $loc || ! $channels ) { return ''; } $html = ''; foreach ( AIEO_Location_Contact::channels( $loc, $channels ) as $channel => $c ) { $icon = $icons ? AIEO_Location_Contact::icon( $channel ) : ''; $html .= '' . $icon . '' . esc_html( $c['text'] ) . ''; } return $html; } public static function render( array $a ) { $form_id = class_exists( 'AIEO_Form_Render' ) ? AIEO_Form_Render::find( $a['form'] ?? '' ) : 0; if ( ! $form_id ) { return ''; } $do = self::resolve( $form_id, $a ); wp_enqueue_style( self::STYLE ); $loc = class_exists( 'AIEO_Location_Contact' ) ? AIEO_Location_Contact::location( $do['location'] ) : null; $contact = self::contact_buttons( $loc, $do['contact'], $do['icons'] ); $where = $loc ? (string) $loc['slug'] : ''; $wrapper_class = trim( 'aieo-form-button-wrap ' . ( '' !== $contact ? 'has-contact ' : '' ) . (string) ( $a['class'] ?? '' ) ); $counted = ' data-aieo-form="' . esc_attr( 'aieo_form_' . (int) $form_id ) . '"'; if ( 'page' === $do['opens'] ) { $url = '' !== $where ? add_query_arg( AIEO_Form_Render::LOCATION_ARG, $where, $do['url'] ) : $do['url']; return '