-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnamespace.php
More file actions
143 lines (126 loc) · 3.85 KB
/
namespace.php
File metadata and controls
143 lines (126 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Altis Security Audit Log.
*
* @package altis/security
*/
namespace Altis\Security\Stream;
use Altis;
use HM\Platform\XRay;
use WP_Admin_Bar;
use WP_CLI;
/**
* Bootstrap Stream plugin.
*
* @return void
*/
function bootstrap() {
// Handle activation.
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_hook( 'after_invoke:core multisite-install', __NAMESPACE__ . '\\setup_stream_db' );
add_action( 'altis.migrate', __NAMESPACE__ . '\\setup_stream_db' );
}
if ( defined( 'WP_INITIAL_INSTALL' ) && WP_INITIAL_INSTALL ) {
return;
}
add_filter( 'wp_stream_admin_menu_title', function () : string {
return __( 'Audit Log' );
} );
add_filter( 'wp_stream_admin_page_title', function () : string {
return __( 'Audit Log Records' );
} );
add_filter( 'wp_stream_is_network_activated', '__return_true' );
add_filter( 'site_option_wp_stream_network', __NAMESPACE__ . '\\default_stream_network_options' );
add_filter( 'default_site_option_wp_stream_network', __NAMESPACE__ . '\\default_stream_network_options' );
add_action( 'network_admin_menu', __NAMESPACE__ . '\\remove_stream_admin_pages', 11 );
add_action( 'admin_menu', __NAMESPACE__ . '\\remove_action_scheduler_menu', 11 );
add_action( 'admin_bar_menu', __NAMESPACE__ . '\\override_network_admin_bar_menu', 100 );
add_filter( 'wp_stream_record_array', __NAMESPACE__ . '\\filter_wp_stream_record_array', 10, 1 );
// Initialise Action Scheduler first so Stream can initialise.
require_once Altis\ROOT_DIR . '/vendor/xwp/stream/vendor/woocommerce/action-scheduler/action-scheduler.php';
action_scheduler_register_3_dot_8_dot_1();
action_scheduler_initialize_3_dot_8_dot_1();
require_once Altis\ROOT_DIR . '/vendor/xwp/stream/stream.php';
}
/**
* Set up stream database on migrate or install.
*
* @return void
*/
function setup_stream_db() {
if ( empty( $GLOBALS['wp_stream'] ) || empty( $GLOBALS['wp_stream']->install ) ) {
return;
}
// Ensure db is set up for stream.
$GLOBALS['wp_stream']->install->check();
}
/**
* Set default Stream plugin config options.
*
* @param array $options Stream configuration options.
* @return array
*/
function default_stream_network_options( array $options ) : array {
$options['general_site_access'] = 0;
$options['general_keep_records_indefinitely'] = true;
return $options;
}
/**
* Remove the stream network admin settings page.
*/
function remove_stream_admin_pages() {
/**
* Stream plugin instance.
*
* @var \Stream\Plugin
*/
global $wp_stream;
remove_submenu_page( $wp_stream->admin->records_page_slug, $wp_stream->admin->network->network_settings_page_slug );
}
/**
* Remove the Action Scheduler admin page.
*/
function remove_action_scheduler_menu() {
remove_submenu_page( 'tools.php', 'action-scheduler' );
}
/**
* Override the Stream admin bar menu.
*
* @param WP_Admin_Bar $wp_admin_bar The admin bar manager class.
*/
function override_network_admin_bar_menu( WP_Admin_Bar $wp_admin_bar ) {
// Menu item is only registered inside the admin, so don't try and replace
// it if it hasn't been registered.
if ( empty( wp_stream_get_instance()->admin ) ) {
return;
}
$wp_admin_bar->remove_menu( 'network-admin-stream' );
$href = add_query_arg(
[
'page' => wp_stream_get_instance()->admin->records_page_slug,
],
network_admin_url( wp_stream_get_instance()->admin->admin_parent_page )
);
$wp_admin_bar->add_menu(
[
'id' => 'network-admin-stream',
'parent' => 'network-admin',
'title' => esc_html__( 'Audit Log', 'altis' ),
'href' => esc_url( $href ),
]
);
}
/**
* Add the Xray ID to the log item meta data.
*
* @param array $record The stream log record to filter.
*
* @return array
*/
function filter_wp_stream_record_array( $record ) : array {
if ( ! function_exists( 'HM\\Platform\\XRay\\get_root_trace_id' ) ) {
return $record;
}
$record['meta']['xray'] = XRay\get_root_trace_id();
return $record;
}