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.3 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 All 196 releases
← All changes | admin/section/class-convertkit-settings-tools.php +323 -263 2.3.11.9.0 View file →
@@ -1,7 +1,8 @@
1 1 <?php
2 +
2 3 /**
3 - * ConvertKit Settings Tools class.
4 + * ConvertKit Tools Settings class
4 5 *
5 6 * @package ConvertKit
6 7 * @author ConvertKit
7 8 */
@@ -6,371 +7,430 @@
6 7 * @author ConvertKit
7 8 */
8 9
9 10 /**
10 - * Registers Tools for debugging and system information that can be accessed at Settings > ConvertKit > Tools.
11 - *
12 - * @package ConvertKit
13 - * @author ConvertKit
11 + * Class ConvertKit_Settings_Tools
14 12 */
15 13 class ConvertKit_Settings_Tools extends ConvertKit_Settings_Base {
16 14
17 15 /**
16 + * We are hiding the submit button.
17 + *
18 + * @var bool
19 + */
20 + protected $show_submit = false;
21 +
22 + /**
18 23 * Constructor
19 24 */
20 25 public function __construct() {
21 -
22 - // Initialize WP_Filesystem.
23 - require_once ABSPATH . 'wp-admin/includes/file.php';
24 - WP_Filesystem();
25 -
26 - $this->settings_key = '_wp_convertkit_tools'; // Required for ConvertKit_Settings_Base, but we don't save settings on the Tools screen.
26 + $this->settings_key = '_wp_convertkit_integration_tools_settings';
27 27 $this->name = 'tools';
28 28 $this->title = __( 'Tools', 'convertkit' );
29 29 $this->tab_text = __( 'Tools', 'convertkit' );
30 30
31 - // Output notices.
32 - add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_notices' ) );
31 + parent::__construct();
32 + }
33 33
34 - parent::__construct();
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 + }
35 46
36 - $this->maybe_perform_actions();
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
37 54 }
38 55
39 56 /**
40 - * Possibly perform some actions, such as clearing the log, downloading the log,
41 - * downloading system information or any third party actions now.
42 - *
43 - * @since 1.9.7.4
57 + * Renders the section
44 58 */
45 - private function maybe_perform_actions() {
59 + public function render() {
60 + settings_fields( $this->settings_key );
61 + $this->view_log();
62 + $this->view_server_info();
63 + }
46 64
47 - // Bail if nonce is invalid.
48 - if ( ! $this->verify_nonce() ) {
49 - return;
50 - }
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 ) : '';
51 72
52 - $this->maybe_clear_log();
53 - $this->maybe_download_log();
54 - $this->maybe_download_system_info();
55 - $this->maybe_export_configuration();
56 - $this->maybe_import_configuration();
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 + }
57 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
58 133 }
59 134
60 135 /**
61 - * Clears the Log.
136 + * Sanitizes the settings.
137 + * We are also using this to clear the Log file.
62 138 *
63 - * @since 1.9.6
139 + * @param array $settings The settings fields submitted.
140 + * @return array Sanitized settings.
64 141 */
65 - private function maybe_clear_log() {
142 + public function sanitize_settings( $settings ) {
66 143
67 - // Bail if the submit button for clearing the debug log was not clicked.
68 - // Nonce verification already performed in maybe_perform_actions() which calls this function.
69 - if ( ! array_key_exists( 'convertkit-clear-debug-log', $_REQUEST ) ) { // phpcs:ignore WordPress.Security.NonceVerification
144 + $log_file = trailingslashit( CONVERTKIT_PLUGIN_PATH ) . 'log.txt';
145 +
146 + if ( ! current_user_can( 'manage_options' ) ) {
70 147 return;
71 148 }
72 149
73 - // Clear Log.
74 - $log = new ConvertKit_Log( CONVERTKIT_PLUGIN_PATH );
75 - $log->clear();
150 + if ( isset( $_REQUEST['convertkit-clear-debug-log'] ) ) {
76 151
77 - // Redirect to Tools screen.
78 - $this->redirect();
152 + $handle = fopen( $log_file, 'w' );
153 + fclose( $handle );
79 154
155 + wp_safe_redirect( admin_url( 'options-general.php?page=_wp_convertkit_settings&tab=tools' ) );
156 + exit;
157 +
158 + }
80 159 }
81 160
82 161 /**
83 - * Prompts a browser download for the log file, if the user clicked
84 - * the Download Log button.
162 + * Get system info
163 + *
164 + * Adapted from Easy Digital Downloads
85 165 *
86 - * @since 1.9.6
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
87 169 */
88 - private function maybe_download_log() {
170 + function get_system_info() {
171 + global $wpdb;
89 172
90 - global $wp_filesystem;
173 + if ( ! class_exists( 'Browser' ) ) {
174 + require_once CONVERTKIT_PLUGIN_PATH . '/lib/browser.php';
175 + }
91 176
92 - // Bail if the submit button for downloading the debug log was not clicked.
93 - // Nonce verification already performed in maybe_perform_actions() which calls this function.
94 - if ( ! array_key_exists( 'convertkit-download-debug-log', $_REQUEST ) ) { // phpcs:ignore WordPress.Security.NonceVerification
95 - return;
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;
96 186 }
97 187
98 - // Get Log and download.
99 - $log = new ConvertKit_Log( CONVERTKIT_PLUGIN_PATH );
188 + // Try to identify the hosting provider
189 + $host = $this->get_host();
100 190
101 - // Download.
102 - header( 'Content-type: application/octet-stream' );
103 - header( 'Content-Disposition: attachment; filename=convertkit-log.txt' );
104 - header( 'Pragma: no-cache' );
105 - header( 'Expires: 0' );
106 - echo esc_html( $wp_filesystem->get_contents( $log->get_filename() ) );
107 - exit();
191 + $return = '### Begin System Info ###' . "\n\n";
108 192
109 - }
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";
110 198
111 - /**
112 - * Prompts a browser download for the system information, if the user clicked
113 - * the Download System Info button.
114 - *
115 - * @since 1.9.6
116 - */
117 - private function maybe_download_system_info() {
199 + $return = apply_filters( 'convertkit_sysinfo_after_site_info', $return );
118 200
119 - global $wp_filesystem;
201 + // Can we determine the site's host?
202 + if( $host ) {
203 + $return .= "\n" . '-- Hosting Provider' . "\n\n";
204 + $return .= 'Host: ' . $host . "\n";
120 205
121 - // Bail if the submit button for downloading the system info was not clicked.
122 - // Nonce verification already performed in maybe_perform_actions() which calls this function.
123 - if ( ! array_key_exists( 'convertkit-download-system-info', $_REQUEST ) ) { // phpcs:ignore WordPress.Security.NonceVerification
124 - return;
206 + $return = apply_filters( 'convertkit_sysinfo_after_host_info', $return );
125 207 }
126 208
127 - // Get System Info.
128 - $system_info = $this->get_system_info();
209 + // The local users' browser information, handled by the Browser class
210 + $return .= "\n" . '-- User Browser' . "\n\n";
211 + $return .= $browser;
129 212
130 - // Write contents to temporary file.
131 - $tmpfile = tmpfile();
132 - $filename = stream_get_meta_data( $tmpfile )['uri'];
133 - $wp_filesystem->put_contents(
134 - $filename,
135 - esc_attr( $system_info )
136 - );
213 + $return = apply_filters( 'convertkit_sysinfo_after_user_browser', $return );
137 214
138 - // Download.
139 - header( 'Content-type: application/octet-stream' );
140 - header( 'Content-Disposition: attachment; filename=convertkit-system-info.txt' );
141 - header( 'Pragma: no-cache' );
142 - header( 'Expires: 0' );
143 - echo esc_html( $wp_filesystem->get_contents( $filename ) );
144 - $wp_filesystem->delete( $filename );
145 - exit();
215 + $locale = get_locale();
146 216
147 - }
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";
148 227
149 - /**
150 - * Prompts a browser download for the configuration file, if the user clicked
151 - * the Export button.
152 - *
153 - * @since 1.9.7.4
154 - */
155 - private function maybe_export_configuration() {
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' );
156 232
157 - // Bail if the submit button for exporting the configuration was not clicked.
158 - // Nonce verification already performed in maybe_perform_actions() which calls this function.
159 - if ( ! array_key_exists( 'convertkit-export', $_REQUEST ) ) { // phpcs:ignore WordPress.Security.NonceVerification
160 - return;
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";
161 235 }
162 236
163 - // Initialize classes that hold settings.
164 - $settings = new ConvertKit_Settings();
165 - $restrict_content_settings = new ConvertKit_Settings_Restrict_Content();
237 + $return .= 'ABSPATH: ' . ABSPATH . "\n";
166 238
167 - // Define configuration data to include in the export file.
168 - $json = wp_json_encode(
169 - array(
170 - 'settings' => $settings->get(),
171 - 'restrict_content' => $restrict_content_settings->get(),
172 - )
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
173 247 );
174 248
175 - // Download.
176 - header( 'Content-type: application/x-msdownload' );
177 - header( 'Content-Disposition: attachment; filename=convertkit-export.json' );
178 - header( 'Pragma: no-cache' );
179 - header( 'Expires: 0' );
180 - echo $json; // phpcs:ignore WordPress.Security.EscapeOutput
181 - exit();
249 + $response = wp_remote_post( 'https://www.paypal.com/cgi-bin/webscr', $params );
182 250
183 - }
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 + }
184 256
185 - /**
186 - * Imports the configuration file, if it's included in the form request
187 - * and has the expected structure.
188 - *
189 - * @since 1.9.7.4
190 - */
191 - private function maybe_import_configuration() {
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";
192 262
193 - // Allow us to easily interact with the filesystem.
194 - require_once ABSPATH . 'wp-admin/includes/file.php';
195 - WP_Filesystem();
196 - global $wp_filesystem;
263 + $return = apply_filters( 'convertkit_sysinfo_after_wordpress_config', $return );
197 264
198 - // Bail if the submit button for importing the configuration was not clicked.
199 - // Nonce verification already performed in maybe_perform_actions() which calls this function.
200 - if ( ! array_key_exists( 'convertkit-import', $_REQUEST ) ) { // phpcs:ignore WordPress.Security.NonceVerification
201 - return;
202 - }
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.
203 269
204 - // Bail if no configuration file was supplied.
205 - if ( ! is_array( $_FILES ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
206 - $this->redirect();
207 - }
208 - if ( $_FILES['import']['error'] !== 0 ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
209 - $this->redirect( 'import_configuration_upload_error' );
210 - }
270 + $return = apply_filters( 'convertkit_sysinfo_after_convertkit_config', $return );
211 271
212 - // Read file.
213 - $json = $wp_filesystem->get_contents( $_FILES['import']['tmp_name'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
272 + // Get plugins that have an update
273 + $updates = get_plugin_updates();
214 274
215 - // Decode.
216 - $import = json_decode( $json, true );
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";
217 280
218 - // Bail if the data isn't JSON.
219 - if ( is_null( $import ) ) {
220 - $this->redirect( 'import_configuration_invalid_file_type' );
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 );
221 286 }
222 287
223 - // Bail if no settings exist.
224 - if ( ! array_key_exists( 'settings', $import ) ) {
225 - $this->redirect( 'import_configuration_empty' );
226 - }
288 + // WordPress active plugins
289 + $return .= "\n" . '-- WordPress Active Plugins' . "\n\n";
227 290
228 - // Import: Settings.
229 - if ( array_key_exists( 'settings', $import ) ) {
230 - $settings = new ConvertKit_Settings();
231 - update_option( $settings::SETTINGS_NAME, $import['settings'] );
232 - }
291 + $plugins = get_plugins();
292 + $active_plugins = get_option( 'active_plugins', array() );
233 293
234 - // Import: Restrict Content Settings.
235 - if ( array_key_exists( 'restrict_content', $import ) ) {
236 - $restrict_content_settings = new ConvertKit_Settings_Restrict_Content();
237 - update_option( $restrict_content_settings::SETTINGS_NAME, $import['restrict_content'] );
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";
238 300 }
239 301
240 - // Redirect to Tools screen.
241 - $this->redirect( false, 'import_configuration_success' );
302 + $return = apply_filters( 'convertkit_sysinfo_after_wordpress_plugins', $return );
242 303
243 - }
304 + // WordPress inactive plugins
305 + $return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n";
244 306
245 - /**
246 - * Verifies if the _convertkit_settings_tools_nonce nonce was included in the request,
247 - * and if so whether the nonce action is valid.
248 - *
249 - * @since 1.9.6
250 - *
251 - * @return bool
252 - */
253 - private function verify_nonce() {
307 + foreach( $plugins as $plugin_path => $plugin ) {
308 + if( in_array( $plugin_path, $active_plugins ) )
309 + continue;
254 310
255 - // Bail if nonce verification fails.
256 - if ( ! isset( $_REQUEST['_convertkit_settings_tools_nonce'] ) ) {
257 - return false;
311 + $update = ( array_key_exists( $plugin_path, $updates ) ) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : '';
312 + $return .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n";
258 313 }
259 314
260 - return wp_verify_nonce( sanitize_key( $_REQUEST['_convertkit_settings_tools_nonce'] ), 'convertkit-settings-tools' );
315 + $return = apply_filters( 'convertkit_sysinfo_after_wordpress_plugins_inactive', $return );
261 316
262 - }
317 + if( is_multisite() ) {
318 + // WordPress Multisite active plugins
319 + $return .= "\n" . '-- Network Active Plugins' . "\n\n";
263 320
264 - /**
265 - * Register fields for this section
266 - */
267 - public function register_fields() {
321 + $plugins = wp_get_active_network_plugins();
322 + $active_plugins = get_site_option( 'active_sitewide_plugins', array() );
268 323
269 - // No fields are registered for the Debug Log.
270 - // This function is deliberately blank.
271 - }
324 + foreach( $plugins as $plugin_path ) {
325 + $plugin_base = plugin_basename( $plugin_path );
272 326
273 - /**
274 - * Outputs success and/or error notices if required.
275 - *
276 - * @since 2.0.0
277 - */
278 - public function maybe_output_notices() {
327 + if( !array_key_exists( $plugin_base, $active_plugins ) )
328 + continue;
279 329
280 - // Define messages that might be displayed as a notification.
281 - $messages = array(
282 - 'import_configuration_upload_error' => __( 'An error occured uploading the configuration file.', 'convertkit' ),
283 - 'import_configuration_invalid_file_type' => __( 'The uploaded configuration file isn\'t valid.', 'convertkit' ),
284 - 'import_configuration_empty' => __( 'The uploaded configuration file contains no settings.', 'convertkit' ),
285 - 'import_configuration_success' => __( 'Configuration imported successfully.', 'convertkit' ),
286 - );
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 + }
287 334
288 - // Output error notification if defined.
289 - if ( isset( $_REQUEST['error'] ) && array_key_exists( sanitize_text_field( $_REQUEST['error'] ), $messages ) ) { // phpcs:ignore WordPress.Security.NonceVerification
290 - $this->output_error( $messages[ sanitize_text_field( $_REQUEST['error'] ) ] ); // phpcs:ignore WordPress.Security.NonceVerification
335 + $return = apply_filters( 'convertkit_sysinfo_after_wordpress_ms_plugins', $return );
291 336 }
292 337
293 - // Output success notification if defined.
294 - if ( isset( $_REQUEST['success'] ) && array_key_exists( sanitize_text_field( $_REQUEST['success'] ), $messages ) ) { // phpcs:ignore WordPress.Security.NonceVerification
295 - $this->output_success( $messages[ sanitize_text_field( $_REQUEST['success'] ) ] ); // phpcs:ignore WordPress.Security.NonceVerification
296 - }
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";
297 343
298 - }
344 + $return = apply_filters( 'convertkit_sysinfo_after_webserver_config', $return );
299 345
300 - /**
301 - * Outputs the Debug Log and System Info view.
302 - *
303 - * @since 1.9.6
304 - */
305 - public function render() {
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";
306 356
307 - /**
308 - * Performs actions prior to rendering the settings form.
309 - *
310 - * @since 2.0.0
311 - */
312 - do_action( 'convertkit_settings_base_render_before' );
357 + $return = apply_filters( 'convertkit_sysinfo_after_php_config', $return );
313 358
314 - // Get Log and System Info.
315 - $log = new ConvertKit_Log( CONVERTKIT_PLUGIN_PATH );
316 - $system_info = $this->get_system_info();
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 + );
317 363
318 - // Output view.
319 - require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/settings/tools.php';
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";
320 372
321 - /**
322 - * Performs actions after rendering of the settings form.
323 - *
324 - * @since 2.0.0
325 - */
326 - do_action( 'convertkit_settings_base_render_after' );
373 + $return = apply_filters( 'convertkit_sysinfo_after_php_ext', $return );
327 374
328 - }
375 + // Session stuff
376 + $return .= "\n" . '-- Session Configuration' . "\n\n";
329 377
330 - /**
331 - * Prints help info for this section
332 - */
333 - public function print_section_info() {
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 + }
334 386
335 - ?>
336 - <p><?php esc_html_e( 'Tools to help you manage ConvertKit on your site.', 'convertkit' ); ?></p>
337 - <?php
387 + $return = apply_filters( 'convertkit_sysinfo_after_session_config', $return );
338 388
389 + $return .= "\n" . '### End System Info ###';
390 +
391 + return $return;
339 392 }
340 393
341 394 /**
342 - * Returns the URL for the ConvertKit documentation for this setting section.
395 + * Get user host
396 + *
397 + * Adapted from Easy Digital Downloads
343 398 *
344 - * @since 2.0.8
399 + * Returns the webhost this site is using if possible
345 400 *
346 - * @return string Documentation URL.
401 + * @since 1.6.4
402 + * @return mixed string $host if detected, false otherwise
347 403 */
348 - public function documentation_url() {
404 + function get_host() {
405 + $host = false;
349 406
350 - return 'https://help.convertkit.com/en/articles/2502591-the-convertkit-wordpress-plugin';
351 -
352 - }
353 -
354 - /**
355 - * Returns a string comprising of the WordPress system information, with Plugin information
356 - * prepended.
357 - *
358 - * @since 1.9.8.3
359 - */
360 - private function get_system_info() {
361 -
362 - // If we're using WordPress < 5.2, there's no WP_Debug_Data class to fetch system information from.
363 - if ( version_compare( get_bloginfo( 'version' ), '5.2', '<' ) ) {
364 - return __( 'WordPress 5.2 or higher is required for system information report.', 'convertkit' );
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'];
365 432 }
366 433
367 - // Use WordPress' debug_data() function to get system info, matching how Tools > Site Health > Info works.
368 - if ( ! class_exists( 'WP_Debug_Data' ) ) {
369 - require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php';
370 - }
371 -
372 - return str_replace( '`', '', WP_Debug_Data::format( WP_Debug_Data::debug_data(), 'debug' ) );
373 -
434 + return $host;
374 435 }
375 -
376 436 }