1
class Singleton {
    public function __construct() {
        // Case #1
        add_action( 'woocommerce_before_shop_loop_item', [ $this, 'open_product_wrapper' ], 10 );
        add_action( 'woocommerce_shop_loop_item_title', [ $this, 'render_product_title' ], 10 );
        
        // Case #2
        add_action( 'woocommerce_before_shop_loop_item', [ $this, 'product_wrapper_open' ], 10 );
        add_action( 'woocommerce_shop_loop_item_title', [ $this, 'product_title' ], 10 );
    }
}

Are there any conventions or should I strive for consistency?

NOTE: In Laravel projects I always use verbs because each method is doing something.

1 Answer 1

2

Are there any conventions or should I strive for consistency?

No, as long as your actions are readable, unique, and it's clear what they do, there is no rule to follow.

Ideally the names you choose are consistent within the code you write. E.g. WooCommerce has chosen to use the woocommerce_ prefix, or when ACF uses acf\. If you think verbs works for you then use verbs, just do it consistently and clearly.

The one thing I would say, is never have a fully dynamic name, e.g. passing a variable from a separate source assuming they're all unique, e.g. add_action( $form_name, '....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.