. * * Priority 0 is deliberate and is the single most important line in this plugin. * * The widget works by intercepting the DOM insertion APIs — createElement, appendChild and the * rest — so that a tracker is caught at the moment it tries to insert itself. It can only * intercept calls that happen after it has run. Enqueued scripts are printed by * wp_print_head_scripts() at wp_head priority 9, which is early enough to beat the priority-10 * injections most tag-manager plugins use, but not early enough to beat anything hooked at * priorities 1 to 8 — and several tag managers deliberately hook there to load early. * * So the script is registered with the loader in the normal way and then printed early by * handle. Everything the loader provides still applies: dependencies, the script_loader_tag * filter, and deregistration by the site owner. * * WP_Scripts::do_items() is used rather than wp_print_scripts() because the latter fires the * `wp_print_scripts` action, and firing that at priority 0 would run other plugins' callbacks * before `wp_enqueue_scripts` has fired, at a point where their own handles are not yet * registered. Printing one handle should not change when other plugins' code runs. */ function lexiscript_print_widget() { if ( ! wp_script_is( LEXISCRIPT_HANDLE, 'registered' ) ) { return; } wp_enqueue_script( LEXISCRIPT_HANDLE ); wp_scripts()->do_items( LEXISCRIPT_HANDLE ); } add_action( 'wp_head', 'lexiscript_print_widget', 0 ); /** * Admin notice while the plugin is installed but not configured. * * A consent widget that is silently absent is worse than one that was never installed, because * the site owner believes they are covered. Shown only to users who could actually fix it. */ function lexiscript_admin_notice() { if ( ! current_user_can( 'manage_options' ) ) { return; } if ( '' !== lexiscript_site_key() ) { return; } $screen = get_current_screen(); if ( $screen && 'settings_page_lexiscript' === $screen->id ) { return; // They are already on the page that fixes it. } printf( '
%s