buffer
1 year ago
script_loader_tag
1 year ago
traits
1 year ago
Consent_API_Helper.php
1 year ago
Cookie_Consent.php
1 year ago
Cookie_Consent_Interface.php
1 year ago
Cookiebot_Activated.php
1 year ago
Cookiebot_Admin_Links.php
1 year ago
Cookiebot_Automatic_Updates.php
1 year ago
Cookiebot_Deactivated.php
1 year ago
Cookiebot_Frame.php
1 year ago
Cookiebot_Javascript_Helper.php
1 year ago
Cookiebot_Review.php
1 year ago
Cookiebot_WP.php
1 year ago
Dependency_Container.php
1 year ago
Settings_Page_Tab.php
1 year ago
Settings_Service.php
1 year ago
Settings_Service_Interface.php
1 year ago
Supported_Languages.php
1 year ago
Supported_Regions.php
1 year ago
WP_Rocket_Helper.php
1 year ago
Widgets.php
1 year ago
global-deprecations.php
1 year ago
helper.php
1 year ago
Cookiebot_Admin_Links.php
139 lines
| 1 | <?php |
| 2 | |
| 3 | namespace cybot\cookiebot\lib; |
| 4 | |
| 5 | class Cookiebot_Admin_Links { |
| 6 | |
| 7 | /** |
| 8 | * Extra admin links |
| 9 | * |
| 10 | * @var array |
| 11 | */ |
| 12 | protected $admin_links; |
| 13 | protected $menu_links; |
| 14 | |
| 15 | public function __construct() { |
| 16 | $this->admin_links = $this->add_links(); |
| 17 | $this->menu_links = $this->add_menu_links(); |
| 18 | } |
| 19 | |
| 20 | public function register_hooks() { |
| 21 | add_filter( 'plugin_action_links_cookiebot/cookiebot.php', array( $this, 'set_settings_action_link' ) ); |
| 22 | add_action( 'admin_init', array( $this, 'handle_external_redirects' ) ); |
| 23 | add_action( 'admin_menu', array( $this, 'add_extra_menu' ) ); |
| 24 | } |
| 25 | |
| 26 | public function handle_external_redirects() { |
| 27 | //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 28 | if ( empty( $_GET['page'] ) ) { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 33 | foreach ( $this->menu_links as $slug => $link ) { |
| 34 | //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 35 | if ( $slug === $_GET['page'] ) { |
| 36 | $link = $link['override'] && $link['condition'] ? $link['over_url'] : $link['url']; |
| 37 | //phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect |
| 38 | wp_redirect( $link ); |
| 39 | exit; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | public function display() { |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | public function add_extra_menu() { |
| 49 | foreach ( $this->menu_links as $slug => $link ) { |
| 50 | add_submenu_page( |
| 51 | 'cookiebot', |
| 52 | $link['label'], |
| 53 | $link['override'] && $link['condition'] ? |
| 54 | // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings,WordPress.WP.I18n.MissingTranslatorsComment |
| 55 | esc_html( sprintf( __( '%s', 'cookiebot' ), $link['over_label'] ) ) : |
| 56 | // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings,WordPress.WP.I18n.MissingTranslatorsComment |
| 57 | esc_html( sprintf( __( '%s', 'cookiebot' ), $link['label'] ) ), |
| 58 | 'manage_options', |
| 59 | $slug, |
| 60 | array( $this, 'display' ), |
| 61 | 20 |
| 62 | ); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | public function set_settings_action_link( $actions ) { |
| 67 | $cb_actions = array(); |
| 68 | |
| 69 | foreach ( $this->admin_links as $link ) { |
| 70 | $item = array( |
| 71 | 'url' => $link['override'] && $link['condition'] ? $link['over_url'] : $link['url'], |
| 72 | 'label' => $link['override'] && $link['condition'] ? $link['over_label'] : $link['label'], |
| 73 | 'strong' => $link['strong'], |
| 74 | ); |
| 75 | |
| 76 | $cb_actions[ $link['index'] ] = $this->get_link_html( $item ); |
| 77 | } |
| 78 | |
| 79 | $actions = array_merge( $actions, $cb_actions ); |
| 80 | ksort( $actions ); |
| 81 | |
| 82 | return $actions; |
| 83 | } |
| 84 | |
| 85 | private function add_menu_links() { |
| 86 | return array( |
| 87 | 'cookiebot_upgrade' => array( |
| 88 | 'url' => Cookiebot_Frame::is_cb_frame_type() === true ? self::CB_FRAME_UPGRADE_URL : self::UC_FRAME_UPGRADE_URL, |
| 89 | 'label' => 'Upgrade a plan', |
| 90 | 'override' => false, |
| 91 | 'condition' => false, |
| 92 | ), |
| 93 | ); |
| 94 | } |
| 95 | |
| 96 | private function add_links() { |
| 97 | return array( |
| 98 | array( |
| 99 | 'url' => add_query_arg( 'page', 'cookiebot', admin_url( 'admin.php' ) ), |
| 100 | 'label' => 'Dashboard', |
| 101 | 'strong' => false, |
| 102 | 'override' => false, |
| 103 | 'condition' => false, |
| 104 | 'index' => 'dashboard', |
| 105 | ), |
| 106 | array( |
| 107 | 'url' => Cookiebot_Frame::is_cb_frame_type() === true ? self::CB_FRAME_UPGRADE_URL : self::UC_FRAME_UPGRADE_URL, |
| 108 | 'label' => 'Upgrade your plan', |
| 109 | 'strong' => true, |
| 110 | 'override' => false, |
| 111 | 'condition' => false, |
| 112 | 'index' => 'a', |
| 113 | ), |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | private function get_link_html( $link ) { |
| 118 | $link_html = '<a href="' . esc_url( $link['url'] ) . '">'; |
| 119 | |
| 120 | if ( $link['strong'] ) { |
| 121 | $link_html .= '<b>'; |
| 122 | } |
| 123 | |
| 124 | // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings,WordPress.WP.I18n.MissingTranslatorsComment |
| 125 | $link_html .= esc_html( sprintf( __( '%s', 'cookiebot' ), $link['label'] ) ); |
| 126 | |
| 127 | if ( $link['strong'] ) { |
| 128 | $link_html .= '</b>'; |
| 129 | } |
| 130 | |
| 131 | $link_html .= '</a>'; |
| 132 | |
| 133 | return $link_html; |
| 134 | } |
| 135 | |
| 136 | const CB_FRAME_UPGRADE_URL = 'https://admin.cookiebot.com/signup/?utm_source=wordpress&utm_medium=referral&utm_campaign=banner'; |
| 137 | const UC_FRAME_UPGRADE_URL = 'https://account.usercentrics.eu/?trial=standard&uc_subscription_type=web&pricing_plan=FreeExtended&utm_source=wordpress&utm_medium=referral&utm_campaign=banner'; |
| 138 | } |
| 139 |