*/ function optooki_default_settings(): array { return array( 'api_url' => '', 'site_id' => '', 'enabled' => true, 'auto_block_wp_scripts' => true, 'wp_consent_api' => false, 'exclude_logged_in_admins' => false, ); } /** * Current settings merged with the defaults. * * @return array */ function optooki_get_settings(): array { $saved = get_option( OPTOOKI_OPTION, array() ); if ( ! is_array( $saved ) ) { $saved = array(); } return array_merge( optooki_default_settings(), $saved ); } /** * URL of the banner script for this site, or an empty string when not configured. */ function optooki_script_url(): string { $settings = optooki_get_settings(); if ( empty( $settings['api_url'] ) || empty( $settings['site_id'] ) ) { return ''; } return untrailingslashit( $settings['api_url'] ) . '/s/' . rawurlencode( $settings['site_id'] ) . '.js'; } add_action( 'plugins_loaded', static function () { Optooki_Settings::init(); Optooki_Frontend::init(); Optooki_Shortcodes::init(); } ); // Declares compatibility with the WP Consent API. add_filter( 'wp_consent_api_registered_' . plugin_basename( __FILE__ ), '__return_true' ); register_activation_hook( __FILE__, static function () { if ( false === get_option( OPTOOKI_OPTION ) ) { add_option( OPTOOKI_OPTION, optooki_default_settings() ); } } );