PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 1.9.0
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v1.9.0
3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 All 195 releases
convertkit / admin / section / class-convertkit-settings-tools.php

class-convertkit-settings-tools.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 1.9.0, at admin/section/class-convertkit-settings-tools.php

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