PluginProbe
Plugin Detective – Troubleshooting Conflicts / 1.2
Plugin Detective – Troubleshooting Conflicts v1.2
1.2.33 1.2.32 1.2.31 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2 1.2.1 1.2.10 1.2.12 1.2.13 1.2.14 1.2.16 1.2.19 1.2.20 1.2.22 1.2.23 1.2.24 1.2.25 All 53 releases
plugin-detective / includes / class-wp-admin.php

class-wp-admin.php in Plugin Detective – Troubleshooting Conflicts 1.2, at includes/class-wp-admin.php

152 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Detective Wp Admin.
4 *
5 * @since 0.0.0
6 * @package Plugin_Detective
7 */
8
9 /**
10 * Plugin Detective Wp Admin.
11 *
12 * @since 0.0.0
13 */
14 class PD_Wp_Admin {
15 /**
16 * Parent plugin class.
17 *
18 * @since 0.0.0
19 *
20 * @var Plugin_Detective
21 */
22 protected $plugin = null;
23
24 /**
25 * Constructor.
26 *
27 * @since 0.0.0
28 *
29 * @param Plugin_Detective $plugin Main plugin object.
30 */
31 public function __construct( $plugin ) {
32 $this->plugin = $plugin;
33 $this->hooks();
34 }
35
36 /**
37 * Initiate our hooks.
38 *
39 * @since 0.0.0
40 */
41 public function hooks() {
42 add_filter( 'plugin_action_links_' . $this->plugin->basename, array( $this, 'add_action_links' ) );
43 add_action( 'admin_menu', array( $this, 'register_tools_page' ), 1 );
44 add_action( 'admin_init', array( $this, 'redirect_tools_page' ), 1 );
45 add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 1000 );
46 }
47
48 public function register_tools_page() {
49 add_management_page( 'Plugin Detective', 'Plugin Detective', 'manage_options', 'plugin-detective', array( $this, 'render_tools_page' ) );
50 }
51
52 public function add_action_links ( $links ) {
53 $mylinks = array(
54 '<a href="' . $this->get_tools_page_url() . '"><strong>Troubleshoot Plugin Conflicts</strong></a>',
55 );
56
57 return array_merge( $links, $mylinks );
58 }
59
60 public function get_app_url( $troubleshoot_url='', $authenticated = true ) {
61 $url = $this->plugin->url( 'troubleshoot/' );
62
63 if ( !empty( $authenticated ) ) {
64 require_once $this->plugin->dir( 'troubleshoot/includes/class-auth.php' );
65 $nonce = PDT_Auth::create_nonce( 'pd_api' );
66 $url = add_query_arg( array(
67 'session' => get_current_user_id(),
68 'nonce' => $nonce,
69 ), $url );
70 }
71
72 if ( !empty( $troubleshoot_url ) ) {
73 $url = add_query_arg( array(
74 'url' => urlencode( $troubleshoot_url )
75 ), $url );
76 }
77
78 return $url;
79 }
80
81 public function render_tools_page() {
82 wp_redirect( $this->get_app_url() );
83 exit();
84 }
85
86 public function get_tools_page_url( $troubleshoot_url = '' ) {
87 $url = admin_url( 'tools.php?page=plugin-detective' );
88 if ( !empty( $troubleshoot_url ) ) {
89 $url = add_query_arg( array(
90 'url' => $troubleshoot_url,
91 ), $url );
92 }
93
94 return $url;
95 }
96
97 public function redirect_tools_page() {
98 if ( empty( $_GET['page'] ) || $_GET['page'] !== 'plugin-detective' ) {
99 return;
100 }
101
102 if ( class_exists( 'ITSEC_Core' ) && $itsec_storage = get_option( 'itsec-storage' ) ) {
103 if ( !empty( $itsec_storage['system-tweaks']['plugins_php'] ) ) {
104 echo '<h1>iThemes Security is preventing Plugin Detective from operating properly</h1>';
105 echo '<h3>To fix this: <code>Go to Security > Settings > System Tweaks</code> and <strong>uncheck</strong> the checkbox setting for <code>Disable PHP in Plugins</code></h3>';
106 echo '<h3><a href="'. admin_url( 'admin.php?page=itsec&module=system-tweaks&module_type=recommended' ).'">Go there now</a></h3>';
107 exit();
108 }
109 }
110
111 $troubleshoot_url = '';
112 if ( !empty( $_GET['url'] ) ) {
113 $troubleshoot_url = sanitize_text_field( $_GET['url'] );
114 }
115
116 wp_redirect( $this->get_app_url( $troubleshoot_url ) );
117 exit();
118 }
119
120 /**
121 * Add the admin bar menu
122 */
123 public function admin_bar_menu() {
124 global $wp_admin_bar;
125
126 $current_url = '';
127 if ( !empty( $_SERVER['REQUEST_URI'] ) ) {
128 $desired_relative_path = (string)$_SERVER['REQUEST_URI'];
129 $relative_path_to_wp_directory = (string)parse_url( site_url(), PHP_URL_PATH );
130
131 if ( ! empty( $relative_path_to_wp_directory ) && strpos( $desired_relative_path, $relative_path_to_wp_directory ) === 0 ) {
132 $desired_relative_path = substr( $desired_relative_path, strlen( $relative_path_to_wp_directory ) );
133 }
134
135 $current_url = site_url( $desired_relative_path );
136 }
137
138 // Add top menu
139 if ( current_user_can( 'activate_plugins' ) ) {
140 $wp_admin_bar->add_menu( array(
141 'id' => 'plugin-detective-bar',
142 'parent' => '',
143 'title' => __( 'Troubleshoot', 'plugin-detective' ),
144 'href' => $this->get_tools_page_url( $current_url )
145 ) );
146 }
147
148 wp_enqueue_style( 'plugin_detective', $this->plugin->url( 'assets/admin.css' ) );
149 }
150
151 }
152