Skip to content

Commit

Permalink
Don't register actions when WooCommerce isn't active
Browse files Browse the repository at this point in the history
Otherwise it will result in fatal errors like this:

```
[08-Mar-2017 15:03:35 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function wc_get_order() in /srv/git/_wordpoints-modules/woocommerce/src/classes/hook/action/order/delete.php:23
Stack trace:
#0 /srv/git/wordpoints/src/classes/hook/router.php(147): WordPoints_WooCommerce_Hook_Action_Order_Delete->should_fire()
#1 /srv/git/wordpoints/src/classes/hook/router.php(94): WordPoints_Hook_Router->route_action('delete_post,10', Array)
#2 /srv/www/wordpress-develop/src/wp-includes/class-wp-hook.php(298): WordPoints_Hook_Router->__call('delete_post,10', Array)
#3 /srv/www/wordpress-develop/src/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array)
#4 /srv/www/wordpress-develop/src/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#5 /srv/www/wordpress-develop/src/wp-includes/post.php(2508): do_action('delete_post', '143')
#6 /srv/www/wordpress-develop/src/wp-includes/post.php(6048): wp_delete_post('143', true)
#7 /srv/www/wordpress-develop/src/wp-includes/class-wp-hook.php(298): wp_delete_auto_drafts()
#8 /srv/www/wordpress-develo in /srv/git/_wordpoints-modules/woocommerce/src/classes/hook/action/order/delete.php on line 23
```

If WooCommerce isn't active, our events and actions won't operate properly, and neither will our entities, etc. So there is no since in registering them.
  • Loading branch information
JDGrimes committed Mar 8, 2017
1 parent 0f38a28 commit 5ffcd7e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/includes/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
* @since 1.1.0
*/

// Don't hook up the actions if WooCommerce isn't active.
if ( ! function_exists( 'wc_get_order' ) ) {
return;
}

add_action( 'wordpoints_init_app_registry-apps-entities', 'wordpoints_woocommerce_entities_init' );
add_action( 'wordpoints_init_app_registry-entities-restrictions-know', 'wordpoints_woocommerce_entity_restrictions_know_init' );

Expand Down

0 comments on commit 5ffcd7e

Please sign in to comment.