| 1 |
<?php |
| 2 |
namespace ABlocksCookieConsent; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* The addon's place in the aBlocks admin. |
| 10 |
* |
| 11 |
* One submenu entry, appearing only while the addon is on, plus the data the |
| 12 |
* React screen needs at boot so it does not have to make a request before it |
| 13 |
* can render anything. |
| 14 |
*/ |
| 15 |
class Admin { |
| 16 |
|
| 17 |
public static function init() { |
| 18 |
$self = new self(); |
| 19 |
add_filter( 'ablocks/admin_menu_list', [ $self, 'admin_menu' ] ); |
| 20 |
add_filter( 'ablocks/assets/dashboard_scripts_data', [ $self, 'dashboard_data' ] ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Insert the screen directly after Theme Builder, so the two addon screens |
| 25 |
* sit together rather than one of them landing under Settings. |
| 26 |
* |
| 27 |
* @param array $menu Menu registry. |
| 28 |
* @return array |
| 29 |
*/ |
| 30 |
public function admin_menu( $menu ) { |
| 31 |
$entry = [ |
| 32 |
ABLOCKS_PLUGIN_SLUG . '-cookie-consent' => [ |
| 33 |
'parent_slug' => ABLOCKS_PLUGIN_SLUG, |
| 34 |
'title' => __( 'Cookie Consent', 'ablocks' ), |
| 35 |
'capability' => 'manage_options', |
| 36 |
], |
| 37 |
]; |
| 38 |
|
| 39 |
$anchor = ABLOCKS_PLUGIN_SLUG . '-theme-builder'; |
| 40 |
if ( ! isset( $menu[ $anchor ] ) ) { |
| 41 |
$anchor = ABLOCKS_PLUGIN_SLUG . '-addons'; |
| 42 |
} |
| 43 |
if ( ! isset( $menu[ $anchor ] ) ) { |
| 44 |
return array_merge( $menu, $entry ); |
| 45 |
} |
| 46 |
|
| 47 |
$position = array_search( $anchor, array_keys( $menu ), true ) + 1; |
| 48 |
|
| 49 |
return array_merge( |
| 50 |
array_slice( $menu, 0, $position, true ), |
| 51 |
$entry, |
| 52 |
array_slice( $menu, $position, null, true ) |
| 53 |
); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* @param array $data Localised dashboard data. |
| 58 |
* @return array |
| 59 |
*/ |
| 60 |
public function dashboard_data( $data ) { |
| 61 |
$data['cookie_consent'] = [ |
| 62 |
'defaults' => Helper::defaults(), |
| 63 |
'settings' => Helper::get_settings(), |
| 64 |
'consent_signals' => ConsentMode::signal_map(), |
| 65 |
'pro' => Helper::pro_features(), |
| 66 |
'record_count' => Record::count(), |
| 67 |
'table_ready' => Database::table_exists(), |
| 68 |
// Still needed by the notice that asks a site to move a tag it |
| 69 |
// entered before aBlocks stopped placing them. |
| 70 |
'tag_providers' => Tags::detected_providers(), |
| 71 |
'embed_defaults' => [ |
| 72 |
'embed' => Embeds::default_rules(), |
| 73 |
'pixel' => Embeds::default_pixel_rules(), |
| 74 |
], |
| 75 |
]; |
| 76 |
return $data; |
| 77 |
} |
| 78 |
} |
| 79 |
|