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() { function woocommerce_debug() {
global $woocommerce; 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="wrap woocommerce">
<div class="icon32 icon32-woocommerce-status" id="icon-woocommerce"><br /></div> <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>'; echo '<div class="updated"><p>' . __('Roles successfully reset', 'woocommerce') . '</p></div>';
break; 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> </tr>
</thead> </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> <tbody>
<tr class="alternate"> <?php foreach($posting as $post) { $mark = ( isset( $post['success'] ) && $post['success'] == true ) ? 'yes' : 'error'; ?>
<td><?php _e('fsockopen/Curl','woocommerce')?></td> <tr class="<?php echo $classes[$class%2]; $class++; ?>">
<td><?php <td><?php echo $post['name']; ?></td>
if( function_exists('fsockopen') || function_exists('curl_init') ) <td>
echo '<mark class="yes">' . __('Your server has fsockopen or Curl enabled.', 'woocommerce'). '</mark>'; <mark class="<?php echo $mark; ?>">
else <?php echo $post['note']; ?>
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> </mark>
</tr> </td>
<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>
</tr> </tr>
<?php } ?>
</tbody> </tbody>
<thead class="tools"> <thead class="tools">
@ -320,26 +364,19 @@ function woocommerce_debug() {
<th colspan="2"><?php _e( 'Tools', 'woocommerce' ); ?></th> <th colspan="2"><?php _e( 'Tools', 'woocommerce' ); ?></th>
</tr> </tr>
</thead> </thead>
<tbody class="tools"> <tbody class="tools">
<tr class="alternate"> <?php foreach($tools as $action => $tool) { ?>
<td><?php _e('Transients','woocommerce')?></td> <tr class="<?php echo $classes[$class%2]; $class++; ?>">
<td><?php echo $tool['name']; ?></td>
<td> <td>
<p> <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> <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 _e( 'This tool will clear the product/shop transients cache.', 'woocommerce' ); ?></span> <span class="description"><?php echo $tool['desc']; ?></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>
</p> </p>
</td> </td>
</tr> </tr>
<?php } ?>
</tbody> </tbody>
</table> </table>