menu_title ) ) { $this->menu_title = $this->page_title; } $this->hooks(); } /** * Add hooks to register the page and output content. * * @return void */ public function hooks() { add_action( 'admin_menu', array( $this, 'add_page' ) ); $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended // Only load if we are actually on the desired page. if ( $this->page_slug !== $page ) { return; } if ( ! current_user_can( $this->capability ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', 'wpconsent-cookies-banner-privacy-suite' ) ); } remove_all_actions( 'admin_notices' ); remove_all_actions( 'all_admin_notices' ); add_action( 'wpconsent_admin_page', array( $this, 'output' ) ); add_action( 'wpconsent_admin_page', array( $this, 'output_footer' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'page_scripts' ) ); add_filter( 'admin_body_class', array( $this, 'page_specific_body_class' ) ); add_action( 'in_admin_footer', array( $this, 'wpconsent_footer' ) ); $this->setup_views(); $this->page_hooks(); $this->set_current_view(); } /** * If the page has views, this is where you should assign them to $this->views. * * @return void */ protected function setup_views() { } /** * Set the current view from the query param also checking it's a registered view for this page. * * @return void */ protected function set_current_view() { // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( ! isset( $_GET['view'] ) ) { return; } $view = sanitize_text_field( wp_unslash( $_GET['view'] ) ); // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( array_key_exists( $view, $this->views ) ) { $this->view = $view; } } /** * Override in child class to define page-specific hooks that will run only * after checks have been passed. * * @return void */ public function page_hooks() { } /** * Add the submenu page. * * @return void */ public function add_page() { add_submenu_page( 'wpconsent', $this->page_title, $this->menu_title, $this->capability, $this->page_slug, array( wpconsent()->admin_page_loader, 'admin_menu_page', ) ); } /** * Output the page content. * * @return void */ public function output() { $this->output_header(); ?>
maybe_output_message(); ?> logo_image(); } /** * Logo image. * * @return void */ public function logo_image() { wpconsent_icon( 'logo-text', 194, 34, '0 0 395 66' ); } /** * Top right area of the header, by default the notifications and help icons. * * @return void */ public function output_header_right() { $notifications_count = wpconsent()->notifications->get_count(); $dismissed_count = wpconsent()->notifications->get_dismissed_count(); $data_count = ''; if ( $notifications_count > 0 ) { $data_count = sprintf( 'data-count="%d"', absint( $notifications_count ) ); } $this->language_picker_button(); ?> get_error_message(); $success_message = $this->get_success_message(); ?>' . wp_kses_post( $description ) . '
'; } return $markup; } /** * Get the full URL for a view of an admin page. * * @param string $view The view slug. * * @return string */ public function get_view_link( $view ) { return add_query_arg( array( 'page' => $this->page_slug, 'view' => $view, ), $this->admin_url( 'admin.php' ) ); } /** * Get a textarea field. * * @param string $id The id of the select field. * @param string $value The value of the textarea field. * @param string $description The description of the textarea field. * @param bool $wide Whether the textarea field should be wide. * @param array $attributes Additional attributes for the textarea field. * * @return string */ public function get_input_textarea( $id, $value = '', $description = '', $wide = false, $attributes = array() ) { $class = 'wpconsent-input-textarea wpconsent-regular-text'; if ( $wide ) { $class .= ' wpconsent-wide-text'; } $attributes_string = ''; foreach ( $attributes as $key => $attribute_value ) { $attributes_string .= sprintf( ' %s="%s"', esc_attr( $key ), esc_attr( $attribute_value ) ); } $markup = ''; if ( ! empty( $description ) ) { $markup .= '' . wp_kses_post( $description ) . '
'; } return $markup; } /** * Get an email field. * * @param string $id The id of the text field. * @param string $value The value of the text field. * @param string $description The description of the text field. * @param bool $wide Whether the text field should be wide. * * @return string */ public function get_input_email( $id, $value = '', $description = '', $wide = false ) { return $this->get_input_text( $id, $value, $description, $wide, 'email' ); } /** * Get a number field. * * @param string $id The id of the text field. * @param string $value The value of the text field. * @param string $description The description of the text field. * @param bool $wide Whether the text field should be wide. * * @return string */ public function get_input_number( $id, $value = '', $description = '', $wide = false ) { return $this->get_input_text( $id, $value, $description, $wide, 'number' ); } /** * Get a text field markup. * * @param string $id The id of the text field. * @param string $value The value of the text field. * @param string $description The description of the text field. * @param bool $wide Whether the text field should be wide. * @param string $type The type of the text field. * @param array $attributes Additional attributes for the input field. * * @return string */ public function get_input_text( $id, $value = '', $description = '', $wide = false, $type = 'text', $attributes = array() ) { $allowed_types = array( 'text', 'email', 'url', 'number', 'password', ); if ( in_array( $type, $allowed_types, true ) ) { $type = esc_attr( $type ); } else { $type = 'text'; } $class = 'wpconsent-regular-text'; if ( $wide ) { $class .= ' wpconsent-wide-text'; } $class .= ' wpconsent-input-' . $type; $attributes_string = ''; foreach ( $attributes as $key => $attribute_value ) { $attributes_string .= sprintf( ' %s="%s"', esc_attr( $key ), esc_attr( $attribute_value ) ); } $markup = ''; if ( ! empty( $description ) ) { $markup .= '' . wp_kses_post( $description ) . '
'; } return $markup; } /** * Get the page URL for any wpconsent page by its slug. * * @param string $slug The page slug. * @param string $view The view slug. * * @return string */ public function get_page_url( $slug, $view = '' ) { $args = array( 'page' => $slug, ); if ( ! empty( $view ) ) { $args['view'] = $view; } return add_query_arg( $args, $this->admin_url( 'admin.php' ) ); } /** * Output a separator row in a metabox. * * @return void */ public function metabox_row_separator() { ?> ', esc_attr( implode( ' ', $container_class ) ) ); $html .= ''; // .wpconsent-upsell-text-content $html .= ''; // .wpconsent-upsell-buttons $html .= ''; return $html; } /** * Get a button for the list of items. * * @param array $args Arguments for the button. * @param bool $echo_output (optional) Whether to echo the button or return it. * * @return void|string */ public static function get_list_item_button( $args, $echo_output = true ) { $button_settings = wp_parse_args( $args, array( 'tag' => 'button', 'url' => '', 'text' => '', 'class' => 'wpconsent-button', 'attributes' => array(), ) ); if ( empty( $button_settings['text'] ) ) { return; } $button_settings['class'] = esc_attr( $button_settings['class'] ); $parsed_attributes = "class='{$button_settings['class']}' "; if ( ! empty( $button_settings['url'] ) && 'a' === $button_settings['tag'] ) { $parsed_attributes .= 'href="' . esc_url( $button_settings['url'] ) . '" '; } if ( ! empty( $button_settings['attributes'] ) ) { foreach ( $button_settings['attributes'] as $key => $value ) { $parsed_attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; } } if ( $echo_output ) { printf( '<%1$s %2$s>%3$s%1$s>', $button_settings['tag'], // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $parsed_attributes, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped wp_kses( $button_settings['text'], wpconsent_get_icon_allowed_tags() ) ); } else { return sprintf( '<%1$s %2$s>%3$s%1$s>', $button_settings['tag'], // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $parsed_attributes, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped wp_kses( $button_settings['text'], wpconsent_get_icon_allowed_tags() ) ); } } }