plugin = $plugin; $this->hooks(); } /** * Initiate our hooks. * * @since 0.0.0 */ public function hooks() { add_filter( 'plugin_action_links_' . $this->plugin->basename, array( $this, 'add_action_links' ) ); add_action( 'admin_menu', array( $this, 'register_tools_page' ), 1 ); add_action( 'admin_init', array( $this, 'redirect_tools_page' ), 1 ); add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 ); } public function register_tools_page() { add_management_page( 'Plugin Detective', 'Plugin Detective', 'manage_options', 'plugin-detective', array( $this, 'render_tools_page' ) ); } public function add_action_links ( $links ) { $mylinks = array( 'Troubleshoot Plugin Conflicts', ); return array_merge( $links, $mylinks ); } public function get_app_url( $troubleshoot_url='', $authenticated = true ) { $url = $this->plugin->url( 'troubleshoot/' ); if ( !empty( $authenticated ) ) { require_once $this->plugin->dir( 'troubleshoot/includes/class-auth.php' ); $nonce = PDT_Auth::create_nonce( 'pd_api' ); $url = add_query_arg( array( 'session' => get_current_user_id(), 'nonce' => $nonce, ), $url ); } if ( !empty( $troubleshoot_url ) ) { $url = add_query_arg( array( 'url' => urlencode( $troubleshoot_url ) ), $url ); } return $url; } public function render_tools_page() { wp_safe_redirect( $this->get_app_url() ); exit(); } public function get_tools_page_url( $troubleshoot_url = '' ) { $url = admin_url( 'tools.php?page=plugin-detective' ); if ( !empty( $troubleshoot_url ) ) { $url = add_query_arg( array( 'url' => $troubleshoot_url, ), $url ); } return $url; } public function redirect_tools_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only routing check on admin_init; no state change. if ( empty( $_GET['page'] ) || $_GET['page'] !== 'plugin-detective' ) { return; } // Defense in depth: this handler mints an authenticated pd_api token, so gate // it on the same capability the API enforces. WordPress's admin-menu access // check already blocks low-privileged users from this page, but don't rely on // that ordering — never mint a token for a user who couldn't use it anyway. if ( ! current_user_can( 'activate_plugins' ) ) { return; } if ( class_exists( 'ITSEC_Core' ) && $itsec_storage = get_option( 'itsec-storage' ) ) { if ( !empty( $itsec_storage['system-tweaks']['plugins_php'] ) ) { echo '
Go to Security > Settings > System Tweaks and uncheck the checkbox setting for Disable PHP in Plugins