| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* ConvertKit Tools Settings class |
| 5 |
* |
| 6 |
* @package ConvertKit |
| 7 |
* @author ConvertKit |
| 8 |
*/ |
| 9 |
|
| 10 |
/** |
| 11 |
* Class ConvertKit_Settings_Tools |
| 12 |
*/ |
| 13 |
class ConvertKit_Settings_Tools extends ConvertKit_Settings_Base { |
| 14 |
|
| 15 |
/** |
| 16 |
* We are hiding the submit button. |
| 17 |
* |
| 18 |
* @var bool |
| 19 |
*/ |
| 20 |
protected $show_submit = false; |
| 21 |
|
| 22 |
/** |
| 23 |
* Constructor |
| 24 |
*/ |
| 25 |
public function __construct() { |
| 26 |
$this->settings_key = '_wp_convertkit_integration_tools_settings'; |
| 27 |
$this->name = 'tools'; |
| 28 |
$this->title = __( 'Tools', 'convertkit' ); |
| 29 |
$this->tab_text = __( 'Tools', 'convertkit' ); |
| 30 |
|
| 31 |
parent::__construct(); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Register and add settings |
| 36 |
*/ |
| 37 |
public function register_fields() { |
| 38 |
add_settings_field( |
| 39 |
'log', |
| 40 |
'Log', |
| 41 |
array( $this, 'view_log' ), |
| 42 |
$this->settings_key, |
| 43 |
$this->name |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Prints help info for this section |
| 49 |
*/ |
| 50 |
public function print_section_info() { |
| 51 |
?> |
| 52 |
<p><?php esc_html_e( 'Tools to help you manage ConvertKit on your site.', 'convertkit' ); ?></p> |
| 53 |
<?php |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Renders the section |
| 58 |
*/ |
| 59 |
public function render() { |
| 60 |
settings_fields( $this->settings_key ); |
| 61 |
$this->view_log(); |
| 62 |
$this->view_server_info(); |
| 63 |
} |
| 64 |
|
| 65 |
/* |
| 66 |
* View the Log |
| 67 |
*/ |
| 68 |
public function view_log() { |
| 69 |
$log_file = trailingslashit( CONVERTKIT_PLUGIN_PATH ) . 'log.txt'; |
| 70 |
$log = file_get_contents( $log_file ); |
| 71 |
|
| 72 |
?> |
| 73 |
<div class="metabox-holder"> |
| 74 |
<div class="postbox ck-debug-log"> |
| 75 |
<h3><span><?php esc_html_e( 'Debug Log', 'convertkit' ); ?></span></h3> |
| 76 |
<div class="inside"> |
| 77 |
<p><?php _e( 'Use this tool to help debug ConvertKit plugin functionality.', 'convertkit' ); ?></p> |
| 78 |
<textarea readonly="readonly" class="large-text monospace" rows="15" |
| 79 |
name="convertkit-debug-log-contents"><?php echo esc_textarea( $log ); ?></textarea> |
| 80 |
<p class="submit"> |
| 81 |
<?php |
| 82 |
submit_button( |
| 83 |
__( 'Copy Log','convertkit' ), |
| 84 |
'primary', |
| 85 |
'convertkit-copy-debug-log', |
| 86 |
false, |
| 87 |
array( |
| 88 |
'onclick' => "this.form['convertkit-debug-log-contents'].focus();this.form['convertkit-debug-log-contents'].select();document.execCommand('copy');return false;" |
| 89 |
) |
| 90 |
); |
| 91 |
submit_button( |
| 92 |
__( 'Clear Log', 'convertkit' ), |
| 93 |
'secondary ck-inline-button', |
| 94 |
'convertkit-clear-debug-log', |
| 95 |
false |
| 96 |
); |
| 97 |
?> |
| 98 |
</p> |
| 99 |
<p><?php _e( 'Log file', 'convertkit' ); ?>: <code><?php echo $log_file; ?></code></p> |
| 100 |
</div><!-- .inside --> |
| 101 |
</div><!-- .postbox --> |
| 102 |
</div><!-- .metabox-holder --> |
| 103 |
<?php |
| 104 |
} |
| 105 |
|
| 106 |
public function view_server_info() { |
| 107 |
?> |
| 108 |
<div class="metabox-holder"> |
| 109 |
<div class="postbox ck-debug-log"> |
| 110 |
<h3><span><?php esc_html_e( 'System Info', 'convertkit' ); ?></span></h3> |
| 111 |
<div class="inside"> |
| 112 |
<p><?php _e( 'Use this tool to send system info to support when necessary.', 'convertkit' ); ?></p> |
| 113 |
<textarea readonly="readonly" onclick="this.focus(); this.select()" id="system-info-textarea" class="large-text monospace" rows="15" name="convertkit-sysinfo"><?php echo $this->get_system_info(); ?></textarea> |
| 114 |
<p class="submit"> |
| 115 |
<input type="hidden" name="convertkit-action" value="download_sysinfo" /> |
| 116 |
<?php |
| 117 |
submit_button( |
| 118 |
__( 'Copy System Info', 'convertkit' ), |
| 119 |
'primary', |
| 120 |
'convertkit-copy-system-info', |
| 121 |
false, |
| 122 |
array( |
| 123 |
'onclick' => "this.form['convertkit-sysinfo'].focus();this.form['convertkit-sysinfo'].select();document.execCommand('copy');return false;" |
| 124 |
) |
| 125 |
); |
| 126 |
?> |
| 127 |
</p> |
| 128 |
</div><!-- .inside --> |
| 129 |
</div><!-- .postbox --> |
| 130 |
</div><!-- .metabox-holder --> |
| 131 |
<?php |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Sanitizes the settings. |
| 136 |
* We are also using this to clear the Log file. |
| 137 |
* |
| 138 |
* @param array $settings The settings fields submitted. |
| 139 |
* @return array Sanitized settings. |
| 140 |
*/ |
| 141 |
public function sanitize_settings( $settings ) { |
| 142 |
|
| 143 |
$log_file = trailingslashit( CONVERTKIT_PLUGIN_PATH ) . 'log.txt'; |
| 144 |
|
| 145 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 146 |
return; |
| 147 |
} |
| 148 |
|
| 149 |
if ( isset( $_REQUEST['convertkit-clear-debug-log'] ) ) { |
| 150 |
|
| 151 |
$handle = fopen( $log_file, 'w' ); |
| 152 |
fclose( $handle ); |
| 153 |
|
| 154 |
wp_safe_redirect( admin_url( 'options-general.php?page=_wp_convertkit_settings&tab=tools' ) ); |
| 155 |
exit; |
| 156 |
|
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Get system info |
| 162 |
* |
| 163 |
* Adapted from Easy Digital Downloads |
| 164 |
* |
| 165 |
* @since 2.0 |
| 166 |
* @global object $wpdb Used to query the database using the WordPress Database API |
| 167 |
* @return string $return A string containing the info to output |
| 168 |
*/ |
| 169 |
function get_system_info() { |
| 170 |
global $wpdb; |
| 171 |
|
| 172 |
if ( ! class_exists( 'Browser' ) ) { |
| 173 |
require_once CONVERTKIT_PLUGIN_PATH . 'lib/browser.php'; |
| 174 |
} |
| 175 |
|
| 176 |
$browser = new Browser(); |
| 177 |
|
| 178 |
// Get theme info |
| 179 |
$theme_data = wp_get_theme(); |
| 180 |
$theme = $theme_data->Name . ' ' . $theme_data->Version; |
| 181 |
$parent_theme = $theme_data->Template; |
| 182 |
if ( ! empty( $parent_theme ) ) { |
| 183 |
$parent_theme_data = wp_get_theme( $parent_theme ); |
| 184 |
$parent_theme = $parent_theme_data->Name . ' ' . $parent_theme_data->Version; |
| 185 |
} |
| 186 |
|
| 187 |
// Try to identify the hosting provider |
| 188 |
$host = $this->get_host(); |
| 189 |
|
| 190 |
$return = '### Begin System Info ###' . "\n\n"; |
| 191 |
|
| 192 |
// Start with the basics... |
| 193 |
$return .= '-- Site Info' . "\n\n"; |
| 194 |
$return .= 'Site URL: ' . site_url() . "\n"; |
| 195 |
$return .= 'Home URL: ' . home_url() . "\n"; |
| 196 |
$return .= 'Multisite: ' . ( is_multisite() ? 'Yes' : 'No' ) . "\n"; |
| 197 |
|
| 198 |
$return = apply_filters( 'convertkit_sysinfo_after_site_info', $return ); |
| 199 |
|
| 200 |
// Can we determine the site's host? |
| 201 |
if( $host ) { |
| 202 |
$return .= "\n" . '-- Hosting Provider' . "\n\n"; |
| 203 |
$return .= 'Host: ' . $host . "\n"; |
| 204 |
|
| 205 |
$return = apply_filters( 'convertkit_sysinfo_after_host_info', $return ); |
| 206 |
} |
| 207 |
|
| 208 |
// The local users' browser information, handled by the Browser class |
| 209 |
$return .= "\n" . '-- User Browser' . "\n\n"; |
| 210 |
$return .= $browser; |
| 211 |
|
| 212 |
$return = apply_filters( 'convertkit_sysinfo_after_user_browser', $return ); |
| 213 |
|
| 214 |
$locale = get_locale(); |
| 215 |
|
| 216 |
// WordPress configuration |
| 217 |
$return .= "\n" . '-- WordPress Configuration' . "\n\n"; |
| 218 |
$return .= 'Version: ' . get_bloginfo( 'version' ) . "\n"; |
| 219 |
$return .= 'Language: ' . ( !empty( $locale ) ? $locale : 'en_US' ) . "\n"; |
| 220 |
$return .= 'Permalink Structure: ' . ( get_option( 'permalink_structure' ) ? get_option( 'permalink_structure' ) : 'Default' ) . "\n"; |
| 221 |
$return .= 'Active Theme: ' . $theme . "\n"; |
| 222 |
if ( $parent_theme !== $theme ) { |
| 223 |
$return .= 'Parent Theme: ' . $parent_theme . "\n"; |
| 224 |
} |
| 225 |
$return .= 'Show On Front: ' . get_option( 'show_on_front' ) . "\n"; |
| 226 |
|
| 227 |
// Only show page specs if frontpage is set to 'page' |
| 228 |
if( get_option( 'show_on_front' ) == 'page' ) { |
| 229 |
$front_page_id = get_option( 'page_on_front' ); |
| 230 |
$blog_page_id = get_option( 'page_for_posts' ); |
| 231 |
|
| 232 |
$return .= 'Page On Front: ' . ( $front_page_id != 0 ? get_the_title( $front_page_id ) . ' (#' . $front_page_id . ')' : 'Unset' ) . "\n"; |
| 233 |
$return .= 'Page For Posts: ' . ( $blog_page_id != 0 ? get_the_title( $blog_page_id ) . ' (#' . $blog_page_id . ')' : 'Unset' ) . "\n"; |
| 234 |
} |
| 235 |
|
| 236 |
$return .= 'ABSPATH: ' . ABSPATH . "\n"; |
| 237 |
|
| 238 |
// Make sure wp_remote_post() is working |
| 239 |
$request['cmd'] = '_notify-validate'; |
| 240 |
|
| 241 |
$params = array( |
| 242 |
'sslverify' => false, |
| 243 |
'timeout' => 60, |
| 244 |
'user-agent' => 'ConvertKit/' . CONVERTKIT_PLUGIN_VERSION, |
| 245 |
'body' => $request |
| 246 |
); |
| 247 |
|
| 248 |
$response = wp_remote_post( 'https://www.paypal.com/cgi-bin/webscr', $params ); |
| 249 |
|
| 250 |
if( !is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) { |
| 251 |
$WP_REMOTE_POST = 'wp_remote_post() works'; |
| 252 |
} else { |
| 253 |
$WP_REMOTE_POST = 'wp_remote_post() does not work'; |
| 254 |
} |
| 255 |
|
| 256 |
$return .= 'Remote Post: ' . $WP_REMOTE_POST . "\n"; |
| 257 |
$return .= 'Table Prefix: ' . 'Length: ' . strlen( $wpdb->prefix ) . ' Status: ' . ( strlen( $wpdb->prefix ) > 16 ? 'ERROR: Too long' : 'Acceptable' ) . "\n"; |
| 258 |
$return .= 'WP_DEBUG: ' . ( defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set' ) . "\n"; |
| 259 |
$return .= 'Memory Limit: ' . WP_MEMORY_LIMIT . "\n"; |
| 260 |
$return .= 'Registered Post Stati: ' . implode( ', ', get_post_stati() ) . "\n"; |
| 261 |
|
| 262 |
$return = apply_filters( 'convertkit_sysinfo_after_wordpress_config', $return ); |
| 263 |
|
| 264 |
// ConvertKit configuration |
| 265 |
$return .= "\n" . '-- ConvertKit Configuration' . "\n\n"; |
| 266 |
$return .= 'Version: ' . CONVERTKIT_PLUGIN_VERSION . "\n"; |
| 267 |
// @TODO add info on form settings, incl. integrations, etc. |
| 268 |
|
| 269 |
$return = apply_filters( 'convertkit_sysinfo_after_convertkit_config', $return ); |
| 270 |
|
| 271 |
// Get plugins that have an update |
| 272 |
$updates = get_plugin_updates(); |
| 273 |
|
| 274 |
// Must-use plugins |
| 275 |
// NOTE: MU plugins can't show updates! |
| 276 |
$muplugins = get_mu_plugins(); |
| 277 |
if( count( $muplugins ) > 0 ) { |
| 278 |
$return .= "\n" . '-- Must-Use Plugins' . "\n\n"; |
| 279 |
|
| 280 |
foreach( $muplugins as $plugin => $plugin_data ) { |
| 281 |
$return .= $plugin_data['Name'] . ': ' . $plugin_data['Version'] . "\n"; |
| 282 |
} |
| 283 |
|
| 284 |
$return = apply_filters( 'convertkit_sysinfo_after_wordpress_mu_plugins', $return ); |
| 285 |
} |
| 286 |
|
| 287 |
// WordPress active plugins |
| 288 |
$return .= "\n" . '-- WordPress Active Plugins' . "\n\n"; |
| 289 |
|
| 290 |
$plugins = get_plugins(); |
| 291 |
$active_plugins = get_option( 'active_plugins', array() ); |
| 292 |
|
| 293 |
foreach( $plugins as $plugin_path => $plugin ) { |
| 294 |
if( !in_array( $plugin_path, $active_plugins ) ) |
| 295 |
continue; |
| 296 |
|
| 297 |
$update = ( array_key_exists( $plugin_path, $updates ) ) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : ''; |
| 298 |
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n"; |
| 299 |
} |
| 300 |
|
| 301 |
$return = apply_filters( 'convertkit_sysinfo_after_wordpress_plugins', $return ); |
| 302 |
|
| 303 |
// WordPress inactive plugins |
| 304 |
$return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n"; |
| 305 |
|
| 306 |
foreach( $plugins as $plugin_path => $plugin ) { |
| 307 |
if( in_array( $plugin_path, $active_plugins ) ) |
| 308 |
continue; |
| 309 |
|
| 310 |
$update = ( array_key_exists( $plugin_path, $updates ) ) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : ''; |
| 311 |
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n"; |
| 312 |
} |
| 313 |
|
| 314 |
$return = apply_filters( 'convertkit_sysinfo_after_wordpress_plugins_inactive', $return ); |
| 315 |
|
| 316 |
if( is_multisite() ) { |
| 317 |
// WordPress Multisite active plugins |
| 318 |
$return .= "\n" . '-- Network Active Plugins' . "\n\n"; |
| 319 |
|
| 320 |
$plugins = wp_get_active_network_plugins(); |
| 321 |
$active_plugins = get_site_option( 'active_sitewide_plugins', array() ); |
| 322 |
|
| 323 |
foreach( $plugins as $plugin_path ) { |
| 324 |
$plugin_base = plugin_basename( $plugin_path ); |
| 325 |
|
| 326 |
if( !array_key_exists( $plugin_base, $active_plugins ) ) |
| 327 |
continue; |
| 328 |
|
| 329 |
$update = ( array_key_exists( $plugin_path, $updates ) ) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : ''; |
| 330 |
$plugin = get_plugin_data( $plugin_path ); |
| 331 |
$return .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n"; |
| 332 |
} |
| 333 |
|
| 334 |
$return = apply_filters( 'convertkit_sysinfo_after_wordpress_ms_plugins', $return ); |
| 335 |
} |
| 336 |
|
| 337 |
// Server configuration (really just versioning) |
| 338 |
$return .= "\n" . '-- Webserver Configuration' . "\n\n"; |
| 339 |
$return .= 'PHP Version: ' . PHP_VERSION . "\n"; |
| 340 |
$return .= 'MySQL Version: ' . $wpdb->db_version() . "\n"; |
| 341 |
$return .= 'Webserver Info: ' . $_SERVER['SERVER_SOFTWARE'] . "\n"; |
| 342 |
|
| 343 |
$return = apply_filters( 'convertkit_sysinfo_after_webserver_config', $return ); |
| 344 |
|
| 345 |
// PHP configs... now we're getting to the important stuff |
| 346 |
$return .= "\n" . '-- PHP Configuration' . "\n\n"; |
| 347 |
$return .= 'Memory Limit: ' . ini_get( 'memory_limit' ) . "\n"; |
| 348 |
$return .= 'Upload Max Size: ' . ini_get( 'upload_max_filesize' ) . "\n"; |
| 349 |
$return .= 'Post Max Size: ' . ini_get( 'post_max_size' ) . "\n"; |
| 350 |
$return .= 'Upload Max Filesize: ' . ini_get( 'upload_max_filesize' ) . "\n"; |
| 351 |
$return .= 'Time Limit: ' . ini_get( 'max_execution_time' ) . "\n"; |
| 352 |
$return .= 'Max Input Vars: ' . ini_get( 'max_input_vars' ) . "\n"; |
| 353 |
$return .= 'Display Errors: ' . ( ini_get( 'display_errors' ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A' ) . "\n"; |
| 354 |
$return .= 'PHP Arg Separator: ' . ini_get( 'arg_separator.output') . "\n"; |
| 355 |
|
| 356 |
$return = apply_filters( 'convertkit_sysinfo_after_php_config', $return ); |
| 357 |
|
| 358 |
// PHP extensions and such |
| 359 |
$return .= "\n" . '-- PHP Extensions' . "\n\n"; |
| 360 |
$return .= 'cURL: ' . ( function_exists( 'curl_init' ) ? 'Supported' : 'Not Supported' ) . "\n"; |
| 361 |
$return .= 'fsockopen: ' . ( function_exists( 'fsockopen' ) ? 'Supported' : 'Not Supported' ) . "\n"; |
| 362 |
$return .= 'SOAP Client: ' . ( class_exists( 'SoapClient' ) ? 'Installed' : 'Not Installed' ) . "\n"; |
| 363 |
$return .= 'Suhosin: ' . ( extension_loaded( 'suhosin' ) ? 'Installed' : 'Not Installed' ) . "\n"; |
| 364 |
|
| 365 |
$return = apply_filters( 'convertkit_sysinfo_after_php_ext', $return ); |
| 366 |
|
| 367 |
// Session stuff |
| 368 |
$return .= "\n" . '-- Session Configuration' . "\n\n"; |
| 369 |
|
| 370 |
// The rest of this is only relevant is session is enabled |
| 371 |
if( isset( $_SESSION ) ) { |
| 372 |
$return .= 'Session Name: ' . esc_html( ini_get( 'session.name' ) ) . "\n"; |
| 373 |
$return .= 'Cookie Path: ' . esc_html( ini_get( 'session.cookie_path' ) ) . "\n"; |
| 374 |
$return .= 'Save Path: ' . esc_html( ini_get( 'session.save_path' ) ) . "\n"; |
| 375 |
$return .= 'Use Cookies: ' . ( ini_get( 'session.use_cookies' ) ? 'On' : 'Off' ) . "\n"; |
| 376 |
$return .= 'Use Only Cookies: ' . ( ini_get( 'session.use_only_cookies' ) ? 'On' : 'Off' ) . "\n"; |
| 377 |
} |
| 378 |
|
| 379 |
$return = apply_filters( 'convertkit_sysinfo_after_session_config', $return ); |
| 380 |
|
| 381 |
$return .= "\n" . '### End System Info ###'; |
| 382 |
|
| 383 |
return $return; |
| 384 |
} |
| 385 |
|
| 386 |
/** |
| 387 |
* Get user host |
| 388 |
* |
| 389 |
* Adapted from Easy Digital Downloads |
| 390 |
* |
| 391 |
* Returns the webhost this site is using if possible |
| 392 |
* |
| 393 |
* @since 1.6.4 |
| 394 |
* @return mixed string $host if detected, false otherwise |
| 395 |
*/ |
| 396 |
function get_host() { |
| 397 |
$host = false; |
| 398 |
|
| 399 |
if( defined( 'WPE_APIKEY' ) ) { |
| 400 |
$host = 'WP Engine'; |
| 401 |
} elseif( defined( 'PAGELYBIN' ) ) { |
| 402 |
$host = 'Pagely'; |
| 403 |
} elseif( DB_HOST == 'localhost:/tmp/mysql5.sock' ) { |
| 404 |
$host = 'ICDSoft'; |
| 405 |
} elseif( DB_HOST == 'mysqlv5' ) { |
| 406 |
$host = 'NetworkSolutions'; |
| 407 |
} elseif( strpos( DB_HOST, 'ipagemysql.com' ) !== false ) { |
| 408 |
$host = 'iPage'; |
| 409 |
} elseif( strpos( DB_HOST, 'ipowermysql.com' ) !== false ) { |
| 410 |
$host = 'IPower'; |
| 411 |
} elseif( strpos( DB_HOST, '.gridserver.com' ) !== false ) { |
| 412 |
$host = 'MediaTemple Grid'; |
| 413 |
} elseif( strpos( DB_HOST, '.pair.com' ) !== false ) { |
| 414 |
$host = 'pair Networks'; |
| 415 |
} elseif( strpos( DB_HOST, '.stabletransit.com' ) !== false ) { |
| 416 |
$host = 'Rackspace Cloud'; |
| 417 |
} elseif( strpos( DB_HOST, '.sysfix.eu' ) !== false ) { |
| 418 |
$host = 'SysFix.eu Power Hosting'; |
| 419 |
} elseif( strpos( $_SERVER['SERVER_NAME'], 'Flywheel' ) !== false ) { |
| 420 |
$host = 'Flywheel'; |
| 421 |
} else { |
| 422 |
// Adding a general fallback for data gathering |
| 423 |
$host = 'DBH: ' . DB_HOST . ', SRV: ' . $_SERVER['SERVER_NAME']; |
| 424 |
} |
| 425 |
|
| 426 |
return $host; |
| 427 |
} |
| 428 |
} |
| 429 |
|