WC_Debug Filters

Added some filters which allow extensions to tie into the debug page.
This commit is contained in:
Patrick Garman 2012-05-10 06:37:10 -05:00
parent ecf2a32466
commit fe1e12df18
1 changed files with 75 additions and 38 deletions

View File

@ -9,7 +9,20 @@
function woocommerce_debug() {
global $woocommerce;
$tools = apply_filters( 'wc_debug_tools', array(
'clear_transients' => array(
'name' => __('Transients','woocommerce'),
'button' => __('Clear Transients','woocommerce'),
'desc' => __( 'This tool will clear the product/shop transients cache.', 'woocommerce' ),
),
'reset_roles' => array(
'name' => __('Capabilities','woocommerce'),
'button' => __('Reset Capabilities','woocommerce'),
'desc' => __( 'This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.', 'woocommerce' ),
),
) );
$classes = array('alternate','');
$class = 0;
?>
<div class="wrap woocommerce">
<div class="icon32 icon32-woocommerce-status" id="icon-woocommerce"><br /></div>
@ -37,6 +50,19 @@ function woocommerce_debug() {
echo '<div class="updated"><p>' . __('Roles successfully reset', 'woocommerce') . '</p></div>';
break;
default:
if( isset( $tools[$_GET['action']]['callback'] ) ) {
$callback = $tools[$_GET['action']]['callback'];
$return = call_user_func( $callback );
if( $return === false ) {
if( is_array( $callback ) ) {
echo '<div class="error"><p>' . sprintf( __('There was an error calling %s::%s', 'woocommerce'), get_class( $callback[0] ), $callback[1] ) . '</p></div>';
} else {
echo '<div class="error"><p>' . sprintf( __('There was an error calling %s', 'woocommerce'), $callback ) . '</p></div>';
}
}
}
}
}
?>
@ -288,31 +314,49 @@ function woocommerce_debug() {
</tr>
</thead>
<?php
$posting = array();
// fsockopen/Curl
$posting['fsockopen_curl']['name'] = __('fsockopen/Curl','woocommerce');
if( function_exists('fsockopen') || function_exists('curl_init') ) {
$posting['fsockopen_curl']['note'] = __('Your server has fsockopen or Curl enabled.', 'woocommerce');
$posting['fsockopen_curl']['success'] = true;
} else {
$posting['fsockopen_curl']['note'] = __('Your server does not have fsockopen or Curl enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'woocommerce'). '</mark>';
$posting['fsockopen_curl']['success'] = false;
}
// WP Remote Post Check
$posting['wp_remote_post']['name'] = __('WP Remote Post Check','woocommerce');
$params = array(
'sslverify' => false,
'timeout' => 30,
'user-agent' => 'WooCommerce/'.$woocommerce->version
);
$response = wp_remote_post( 'https://www.paypal.com/cgi-bin/webscr', $params );
if ( ! is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
$posting['wp_remote_post']['note'] = __('wp_remote_post() was successful - PayPal IPN is working.', 'woocommerce');
$posting['wp_remote_post']['success'] = true;
} else {
$posting['wp_remote_post']['note'] = __('wp_remote_post() failed. PayPal IPN won\'t work with your server. Contact your hosting provider. Error: ', 'woocommerce') . $response->get_error_message();
$posting['wp_remote_post']['success'] = false;
}
$posting = apply_filters( 'wc_debug_posting', $posting );
?>
<tbody>
<tr class="alternate">
<td><?php _e('fsockopen/Curl','woocommerce')?></td>
<td><?php
if( function_exists('fsockopen') || function_exists('curl_init') )
echo '<mark class="yes">' . __('Your server has fsockopen or Curl enabled.', 'woocommerce'). '</mark>';
else
echo '<mark class="error">' . __('Your server does not have fsockopen or Curl enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'woocommerce'). '</mark>'; ?></td>
</tr>
<tr>
<td><?php _e('WP Remote Post Check','woocommerce')?></td>
<td><?php
$params = array(
'sslverify' => false,
'timeout' => 30,
'user-agent' => 'WooCommerce/'.$woocommerce->version
);
$response = wp_remote_post( 'https://www.paypal.com/cgi-bin/webscr', $params );
if ( ! is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 )
echo '<mark class="yes">' . __('wp_remote_post() was successful - PayPal IPN is working.', 'woocommerce'). '</mark>';
else
echo '<mark class="error">' . __('wp_remote_post() failed. PayPal IPN won\'t work with your server. Contact your hosting provider. Error: ', 'woocommerce') . $response->get_error_message() . '</mark>';
?></td>
<?php foreach($posting as $post) { $mark = ( isset( $post['success'] ) && $post['success'] == true ) ? 'yes' : 'error'; ?>
<tr class="<?php echo $classes[$class%2]; $class++; ?>">
<td><?php echo $post['name']; ?></td>
<td>
<mark class="<?php echo $mark; ?>">
<?php echo $post['note']; ?>
</mark>
</td>
</tr>
<?php } ?>
</tbody>
<thead class="tools">
@ -320,26 +364,19 @@ function woocommerce_debug() {
<th colspan="2"><?php _e( 'Tools', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody class="tools">
<tr class="alternate">
<td><?php _e('Transients','woocommerce')?></td>
<?php foreach($tools as $action => $tool) { ?>
<tr class="<?php echo $classes[$class%2]; $class++; ?>">
<td><?php echo $tool['name']; ?></td>
<td>
<p>
<a href="<?php echo wp_nonce_url( admin_url('tools.php?page=woocommerce_debug&action=clear_transients'), 'debug_action' ); ?>" class="button"><?php _e('Clear Transients','woocommerce')?></a>
<span class="description"><?php _e( 'This tool will clear the product/shop transients cache.', 'woocommerce' ); ?></span>
</p>
</td>
</tr>
<tr>
<td><?php _e('Capabilities','woocommerce')?></td>
<td>
<p>
<a href="<?php echo wp_nonce_url( admin_url('tools.php?page=woocommerce_debug&action=reset_roles'), 'debug_action' ); ?>" class="button"><?php _e('Reset Capabilities','woocommerce')?></a>
<span class="description"><?php _e( 'This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.', 'woocommerce' ); ?></span>
<a href="<?php echo wp_nonce_url( admin_url('tools.php?page=woocommerce_debug&action=' . $action ), 'debug_action' ); ?>" class="button"><?php echo $tool['button']; ?></a>
<span class="description"><?php echo $tool['desc']; ?></span>
</p>
</td>
</tr>
<?php } ?>
</tbody>
</table>