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