I am dividing my plugin code into multiple files and functions.
When I have a function and straight after it an action hook, or for example add_shortcode, should that line go straight after the function or in a plugin init function?
As an example, should I have something like this:
// Shortcodes.php file
function myplugin_shortcode( $atts ) {
if ( !empty ($atts) ) {
foreach ( $atts as $key => &$val ) {
$val = html_entity_decode($val);
}
}
myplugin_display_items( $atts );
}
// Register shortcodes
add_shortcode( 'output-items', 'myplugin_shortcode');
OR a combination of the following two:
// Shortcodes.php file
function myplugin_shortcode( $atts ) {
if ( !empty ($atts) ) {
foreach ( $atts as $key => &$val ) {
$val = html_entity_decode($val);
}
}
myplugin_display_items( $atts );
}
and
// Myplugin.php file
myplugin_init() {
// other initialisation code
add_shortcode( 'output-items', 'myplugin_shortcode');
}