File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ public function load_plugin() {
7070 new Widgets \WidgetLoader ();
7171
7272 // Load shortcodes
73- new Shortcodes \ShortcodeLoader ();
73+ new Shortcodes \Shortcode_Loader ();
7474
7575 }
7676
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace VendorName \PluginName \Shortcodes ;
3+ use VendorName \PluginName \Plugin ;
4+
5+ class CurrentYear_Shortcode extends Plugin
6+ {
7+
8+ public function __construct () {
9+
10+ // Usage: [current_year]
11+ if ( ! shortcode_exists ( 'current_year ' ) ) {
12+ add_shortcode ( 'current_year ' , array ( $ this , 'current_year_shortcode ' ) );
13+ }
14+
15+ }
16+
17+ /**
18+ * A short code that returns the current year
19+ *
20+ * @param $atts array Shortcode Attributes
21+ * @return string Output of shortcode
22+ * @since 0.4.0
23+ */
24+ public function current_year_shortcode ( $ atts ) {
25+
26+ return date ( 'Y ' );
27+
28+ }
29+
30+ }
Original file line number Diff line number Diff line change 22namespace VendorName \PluginName \Shortcodes ;
33use VendorName \PluginName \Plugin ;
44
5- class HelloShortcode extends Plugin
5+ class Hello_Shortcode extends Plugin
66{
77
88 public function __construct () {
99
1010 // Usage: [hello name="Daniel"]
1111 if ( ! shortcode_exists ( 'hello ' ) ) {
12- add_shortcode ( 'hello ' , array ( $ this , 'hello_world ' ) );
12+ add_shortcode ( 'hello ' , array ( $ this , 'hello_world_shortcode ' ) );
1313 }
1414
1515 }
1616
1717 /**
18- * A short code the returns "Hello {$name}!", if provided
18+ * A short code that returns "Hello {$name}!", if provided
1919 *
2020 * @param $atts array Shortcode Attributes
2121 * @return string Output of shortcode
2222 * @since 0.1.0
2323 */
24- public function hello_world ( $ atts ) {
24+ public function hello_world_shortcode ( $ atts ) {
2525 $ atts = shortcode_atts ( array (
2626 'name ' => 'world '
2727 ), $ atts , 'hello ' );
2828
29- return sprintf ( __ ( 'Hello ' , self ::$ textdomain ) . ' %s! ' , $ atts [ 'name ' ] );
29+ return sprintf ( __ ( 'Hello %s! ' , self ::$ textdomain ), $ atts [ 'name ' ] );
3030 }
3131
3232}
Original file line number Diff line number Diff line change 22namespace VendorName \PluginName \Shortcodes ;
33use VendorName \PluginName \Plugin ;
44
5- class ShortcodeLoader extends Plugin {
5+ class Shortcode_Loader extends Plugin {
66
77 /**
88 * @var array Shortcode class name to register
@@ -13,7 +13,8 @@ class ShortcodeLoader extends Plugin {
1313 public function __construct () {
1414
1515 $ this ->shortcodes = array (
16- HelloShortcode::class
16+ Hello_Shortcode::class,
17+ CurrentYear_Shortcode::class
1718 );
1819
1920 foreach ( $ this ->shortcodes as $ shortcodeClass ) {
@@ -22,7 +23,7 @@ public function __construct() {
2223 if ( $ shortcode instanceof ShortcodeInterface ) {
2324 new $ shortcode ();
2425 } else {
25- // You could log not added shortcodes here
26+ // Log or show error notices
2627 }
2728
2829 }
You can’t perform that action at this time.
0 commit comments