admin管理员组文章数量:1207718
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.
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.
Share Improve this question edited Mar 12, 2022 at 12:32 user557108 asked Mar 12, 2022 at 12:16 user557108user557108 1474 bronze badges1 Answer
Reset to default 2Are 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, '...
.
本文标签: plugin developmentShould action callbacks start with a verb
版权声明:本文标题:plugin development - Should action callbacks start with a verb? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738678725a2106418.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论