pricing_monthly = [ 'compliance_monthly_notrial' => '14.95', 'compliance_monthly_5' => '29.95', 'compliance_monthly_10' => '49.95', 'compliance_monthly_20' => '69.95' ]; $this->pricing_yearly = [ 'compliance_yearly_notrial' => '149.50', 'compliance_yearly_5' => '299.50', 'compliance_yearly_10' => '499.50', 'compliance_yearly_20' => '699.50' ]; } /** * Load scripts and styles - admin. * * @return void */ public function admin_enqueue_scripts( $page ) { // get main instance $cn = Cookie_Notice(); if ( $cn->check_status( $cn->get_status() ) ) return; // Legacy welcome scripts only load when ui_mode is explicitly set to legacy. if ( $cn->options['general']['ui_mode'] !== 'legacy' ) return; // styles wp_enqueue_style( 'dashicons' ); wp_enqueue_style( 'cookie-notice-modaal', COOKIE_NOTICE_URL . '/assets/modaal/css/modaal.min.css', [], $cn->defaults['version'] ); wp_enqueue_style( 'cookie-notice-spectrum', COOKIE_NOTICE_URL . '/assets/spectrum/spectrum.min.css', [], $cn->defaults['version'] ); wp_enqueue_style( 'cookie-notice-microtip', COOKIE_NOTICE_URL . '/assets/microtip/microtip.min.css', [], $cn->defaults['version'] ); // scripts wp_enqueue_script( 'cookie-notice-modaal', COOKIE_NOTICE_URL . '/assets/modaal/js/modaal.min.js', [], $cn->defaults['version'] ); wp_enqueue_script( 'cookie-notice-spectrum', COOKIE_NOTICE_URL . '/assets/spectrum/spectrum.min.js', [], $cn->defaults['version'] ); wp_enqueue_script( 'cookie-notice-welcome', COOKIE_NOTICE_URL . '/js/admin-welcome.js', [ 'jquery', 'jquery-ui-core', 'jquery-ui-progressbar' ], $cn->defaults['version'] ); wp_enqueue_script( 'cookie-notice-braintree-client', 'https://js.braintreegateway.com/web/3.71.0/js/client.min.js', [], null, false ); wp_enqueue_script( 'cookie-notice-braintree-hostedfields', 'https://js.braintreegateway.com/web/3.71.0/js/hosted-fields.min.js', [], null, false ); wp_enqueue_script( 'cookie-notice-braintree-paypal', 'https://js.braintreegateway.com/web/3.71.0/js/paypal-checkout.min.js', [], null, false ); // check network $network = $cn->is_network_admin(); // prepare script data $script_data = [ 'ajaxURL' => admin_url( 'admin-ajax.php' ), 'network' => $network, 'nonce' => wp_create_nonce( 'cookie-notice-welcome' ), 'cnNonce' => wp_create_nonce( 'cookie-notice-welcome' ), 'initModal' => $network ? get_site_transient( 'cn_show_welcome' ) : get_transient( 'cn_show_welcome' ), // welcome modal 'error' => esc_html__( 'Unexpected error occurred. Please try again later.', 'cookie-notice' ), 'statusPassed' => esc_html__( 'Passed', 'cookie-notice' ), 'statusFailed' => esc_html__( 'Failed', 'cookie-notice' ), 'paidMonth' => esc_html__( 'monthly', 'cookie-notice' ), 'paidYear' => esc_html__( 'yearly', 'cookie-notice' ), 'pricingMonthly' => $this->pricing_monthly, 'pricingYearly' => $this->pricing_yearly, 'complianceStatus' => $cn->get_status(), 'complianceFailed' => sprintf( esc_html__( '%sCompliance Failed!%sYour website does not achieve minimum viable compliance. %sSign up to Compliance by Hu-manity.co%s to bring your site into compliance with the latest data privacy rules and regulations.', 'cookie-notice' ), '', '', '', '' ), 'compliancePassed' => sprintf( esc_html__( '%sCompliance Passed!%sCongratulations. Your website meets minimum viable compliance.', 'cookie-notice' ), '', '' ), 'licensesAvailable' => esc_html__( 'available', 'cookie-notice' ), 'invalidFields' => esc_html__( 'Please fill all the required fields.', 'cookie-notice' ), 'dismissed' => (bool) get_option( 'cookie_notice_welcome_dismissed', false ) ]; // delete the show modal transient if ( $network ) delete_site_transient( 'cn_show_welcome' ); else delete_transient( 'cn_show_welcome' ); wp_add_inline_script( 'cookie-notice-welcome', 'var cnWelcomeArgs = ' . wp_json_encode( $script_data ) . ";\n", 'before' ); wp_enqueue_style( 'cookie-notice-welcome', COOKIE_NOTICE_URL . '/css/admin-welcome.css', [], $cn->defaults['version'] ); } /** * Send user to the welcome page on first activation. * * @global string $pagenow * * @return void */ public function welcome() { global $pagenow; if ( $pagenow !== 'admin.php' ) return; // get page $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : ''; if ( $page !== 'cookie-notice' ) return; // bail if bulk activating or within an iframe if ( isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) return; // get action $action = isset( $_GET['action'] ) ? sanitize_key( $_GET['action'] ) : ''; // get plugin $plugin = isset( $_GET['plugin'] ) ? sanitize_file_name( $_GET['plugin'] ) : ''; if ( $action === 'upgrade-plugin' && strpos( $plugin, 'cookie-notice.php' ) !== false ) return; add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); add_action( 'admin_footer', [ $this, 'admin_footer' ] ); } /** * Welcome modal container. * * @return void */ public function admin_footer() { echo ''; } /** * Dismiss the welcome modal — AJAX handler. * Sets cookie_notice_welcome_dismissed option so the modal won't auto-fire again * when user navigates to ?welcome=1 after closing without completing. * * @return void */ public function dismiss_welcome() { if ( ! check_ajax_referer( 'cookie-notice-welcome', 'nonce', false ) ) wp_die( -1 ); if ( ! current_user_can( 'manage_options' ) ) wp_die( -1 ); update_option( 'cookie_notice_welcome_dismissed', true, false ); wp_die( 1 ); } /** * Render welcome screen sidebar step. * * @param int|string $screen * @param bool $echo * @return string|void */ public function welcome_screen( $screen, $echo = true ) { if ( ! current_user_can( 'install_plugins' ) ) wp_die( __( 'You do not have permission to access this page.', 'cookie-notice' ) ); $sidebars = [ 'about', 'login', 'register', 'configure', 'success' ]; $steps = [ 1, 2, 3, 4 ]; $screens = array_merge( $sidebars, $steps ); if ( ! empty( $screen ) ) { if ( is_numeric( $screen ) ) $screen = (int) $screen; else $screen = sanitize_key( $screen ); } else $screen = ''; if ( empty( $screen ) || ! in_array( $screen, $screens, true ) ) { if ( isset( $_REQUEST['screen'] ) ) { if ( is_numeric( $_REQUEST['screen'] ) ) $screen = (int) $_REQUEST['screen']; else $screen = sanitize_key( $_REQUEST['screen'] ); } else $screen = ''; if ( ! in_array( $screen, $screens, true ) ) $screen = ''; } if ( empty( $screen ) ) wp_die( __( 'You do not have permission to access this page.', 'cookie-notice' ) ); if ( wp_doing_ajax() && ! check_ajax_referer( 'cookie-notice-welcome', 'nonce' ) ) wp_die( __( 'You do not have permission to access this page.', 'cookie-notice' ) ); // step screens if ( in_array( $screen, $steps ) ) { $html = '