'' ), $atts, 'aivastark' ); $key = sanitize_text_field( (string) $atts['key'] ); // The on/off switch and the audience rules apply here too; page rules // don't, because placing the shortcode on a page is itself a page rule. if ( aivastark_widget_should_render( true ) ) { aivastark_widget_enqueue( $key ); } return ''; } ); /** * Site-wide rendering — runs on every front-end page when a key is configured. * * Must hook on wp_enqueue_scripts (not wp_footer): WordPress prints footer * scripts at wp_footer priority 20, so anything enqueued later in wp_footer * silently never reaches the page. Priority 20 here fires after the script * registration above (default priority 10). */ add_action( 'wp_enqueue_scripts', function () { if ( is_admin() ) { return; } $opts = aivastark_widget_get_options(); $key = trim( (string) $opts['widget_key'] ); if ( '' === $key ) { return; } if ( ! aivastark_widget_should_render( false ) ) { return; } aivastark_widget_enqueue( $key ); }, 20 ); /** * Whether the Display rules let the widget load on this request. * * Filterable: `aivastark_widget_should_render` receives the decision, the * options and the request context, for rules the settings screen can't express * (a membership level, a cookie, an A/B bucket). * * @param bool $shortcode Whether the [aivastark] shortcode is asking. * @return bool */ function aivastark_widget_should_render( $shortcode ) { $opts = aivastark_widget_get_options(); $ctx = Aivastark_Widget_Display_Rules::context( $shortcode ); return (bool) apply_filters( 'aivastark_widget_should_render', Aivastark_Widget_Display_Rules::decide( $opts, $ctx ), $opts, $ctx ); }