options = $options;
if ( array_key_exists( 'enable_tracking_tool', $options ) ) {
add_action( 'wp_head', [ $this, 'add_tracking' ] );
}
if ( array_key_exists( 'enable_google_adsense', $options ) ) {
add_action( 'wp_head', array( $this, 'add_adsense_code' ) );
}
$enabled = (bool) get_option( '_wpcoder_enable_debug_log' );
if ( $enabled ) {
add_action( 'plugins_loaded', [ $this, 'debug_log' ] );
add_action( 'admin_bar_menu', [ $this, 'admin_menu_debug' ], 90 );
}
if ( array_key_exists( 'show_page_debug_info', $options ) ) {
new WPCoder_Page_Info;
}
if ( array_key_exists( 'theme_switcher', $options ) ) {
new WPCoder_Theme_Switcher;
}
if ( array_key_exists( 'markdown_editor', $options ) ) {
new WPCoder_Markdown_Editor($options);
}
}
public function debug_log(): void {
error_reporting( E_ALL );
ini_set( 'log_errors', 1 );
ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); // Log file path
}
public function admin_menu_debug( $wp_admin_bar ): void {
if ( ! current_user_can( 'unfiltered_html' ) ) {
return;
}
$log_file = WP_CONTENT_DIR . '/debug.log';
if ( ! file_exists( $log_file ) || filesize( $log_file ) === 0 ) {
return;
}
$wp_admin_bar->add_node( [
'id' => 'wpcoder-debug-log-link',
'title' => 'Debug Log',
'href' => admin_url( 'admin.php?page=' . WPCoder::SLUG . '-debug' ),
'meta' => [
'title' => 'View Debug Log', // tooltip
],
] );
}
public function add_tracking(): void {
$user = wp_get_current_user();
if ( ! empty( $user->roles ) ) {
foreach ( $user->roles as $role ) {
if ( array_key_exists( 'disable_tracking_tool_user_' . $role, $this->options ) ) {
return;
}
}
}
// Google Analytics code
if ( ! empty( $this->options['tracking_tool_google'] ) ) { ?>
options['tracking_tool_facebook'] ) ) { ?>
options['tracking_tool_pintrest'] ) ) { ?>
options['google_adsense_publisher'] ) ) {
return;
}
$user = wp_get_current_user();
if ( ! empty( $user->roles ) ) {
foreach ( $user->roles as $role ) {
if ( array_key_exists( 'disable_google_adsense_user_' . $role, $this->options ) ) {
return;
}
}
}
// phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
echo '';
// phpcs:enable
}
}
new WPCoder_Lite_Tools;