| @@ -24,11 +24,54 @@ | ||
| 24 | 24 | if ( array_key_exists( 'enable_google_adsense', $options ) ) { |
| 25 | 25 | add_action( 'wp_head', array( $this, 'add_adsense_code' ) ); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | + $enabled = (bool) get_option( '_wpcoder_enable_debug_log' ); | |
| 29 | + if ( $enabled ) { | |
| 30 | + add_action( 'plugins_loaded', [ $this, 'debug_log' ] ); | |
| 31 | + add_action( 'admin_bar_menu', [ $this, 'admin_menu_debug' ], 90 ); | |
| 32 | + } | |
| 33 | + | |
| 34 | + if ( array_key_exists( 'show_page_debug_info', $options ) ) { | |
| 35 | + new WPCoder_Page_Info; | |
| 36 | + } | |
| 37 | + | |
| 38 | + if ( array_key_exists( 'theme_switcher', $options ) ) { | |
| 39 | + new WPCoder_Theme_Switcher; | |
| 40 | + } | |
| 41 | + | |
| 42 | + if ( array_key_exists( 'markdown_editor', $options ) ) { | |
| 43 | + new WPCoder_Markdown_Editor($options); | |
| 44 | + } | |
| 45 | + | |
| 28 | 46 | } |
| 29 | 47 | |
| 48 | + public function debug_log(): void { | |
| 49 | + error_reporting( E_ALL ); | |
| 50 | + ini_set( 'log_errors', 1 ); | |
| 51 | + ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); // Log file path | |
| 52 | + } | |
| 30 | 53 | |
| 54 | + public function admin_menu_debug( $wp_admin_bar ): void { | |
| 55 | + if ( ! current_user_can( 'unfiltered_html' ) ) { | |
| 56 | + return; | |
| 57 | + } | |
| 58 | + | |
| 59 | + $log_file = WP_CONTENT_DIR . '/debug.log'; | |
| 60 | + if ( ! file_exists( $log_file ) || filesize( $log_file ) === 0 ) { | |
| 61 | + return; | |
| 62 | + } | |
| 63 | + | |
| 64 | + $wp_admin_bar->add_node( [ | |
| 65 | + 'id' => 'wpcoder-debug-log-link', | |
| 66 | + 'title' => '<span class="ab-icon dashicons-admin-tools" aria-hidden="true"></span><span class="ab-label">Debug Log</span>', | |
| 67 | + 'href' => admin_url( 'admin.php?page=' . WPCoder::SLUG . '-debug' ), | |
| 68 | + 'meta' => [ | |
| 69 | + 'title' => 'View Debug Log', // tooltip | |
| 70 | + ], | |
| 71 | + ] ); | |
| 72 | + } | |
| 73 | + | |
| 31 | 74 | public function add_tracking(): void { |
| 32 | 75 | |
| 33 | 76 | $user = wp_get_current_user(); |
| 34 | 77 | |
| @@ -111,13 +154,13 @@ | ||
| 111 | 154 | </noscript> |
| 112 | 155 | <?php } |
| 113 | 156 | } |
| 114 | 157 | |
| 115 | - public function add_adsense_code() { | |
| 158 | + public function add_adsense_code(): void { | |
| 116 | 159 | |
| 117 | - if(empty( $this->options['google_adsense_publisher'] )) { | |
| 118 | - return; | |
| 119 | - } | |
| 160 | + if ( empty( $this->options['google_adsense_publisher'] ) ) { | |
| 161 | + return; | |
| 162 | + } | |
| 120 | 163 | |
| 121 | 164 | $user = wp_get_current_user(); |
| 122 | 165 | |
| 123 | 166 | if ( ! empty( $user->roles ) ) { |
| @@ -127,11 +170,13 @@ | ||
| 127 | 170 | } |
| 128 | 171 | } |
| 129 | 172 | } |
| 130 | 173 | |
| 131 | - $output = '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-'.esc_attr($this->options['google_adsense_publisher']).'" crossorigin="anonymous"></script>'; | |
| 132 | - echo $output; | |
| 133 | - } | |
| 174 | + // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript | |
| 175 | + echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-' . esc_attr( $this->options['google_adsense_publisher'] ) . '" crossorigin="anonymous"></script>'; | |
| 176 | + // phpcs:enable | |
| 177 | + } | |
| 178 | + | |
| 134 | 179 | |
| 135 | 180 | } |
| 136 | 181 | |
| 137 | 182 | new WPCoder_Lite_Tools; |