Created
July 19, 2019 22:28
-
-
Save rdallaire/2eb3874591186b1f83b17d639019bbbb to your computer and use it in GitHub Desktop.
WordPress shortcodes for sage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use App\Controllers\App; | |
/** | |
* Return if Shortcodes already exists. | |
*/ | |
if (class_exists('Shortcodes')) { | |
return; | |
} | |
/** | |
* Shortcodes | |
*/ | |
class Shortcodes | |
{ | |
/** | |
* Constructor | |
*/ | |
public function __construct() | |
{ | |
$shortcodes = [ | |
'box', | |
'date', | |
'month', | |
'day', | |
'year' | |
]; | |
return collect($shortcodes) | |
->map(function ($shortcode) { | |
return add_shortcode($shortcode, [$this, strtr($shortcode, ['-' => '_'])]); | |
}); | |
} | |
/** | |
* Box | |
* Wraps content in a box. | |
* | |
* @param array $atts | |
* @param string $content | |
* @return string | |
*/ | |
public function box($atts, $content = null) | |
{ | |
return '<div class="box">' . do_shortcode($content) . '</div>'; | |
} | |
/** | |
* Date | |
* Returns the current date. | |
* | |
* @param array $atts | |
* @param string $content | |
* @return string | |
*/ | |
public function date($atts, $content = null) | |
{ | |
return date('F d, Y'); | |
} | |
/** | |
* Month | |
* Returns the current month. | |
* | |
* @param array $atts | |
* @param string $content | |
* @return string | |
*/ | |
public function month($atts, $content = null) | |
{ | |
return date('F'); | |
} | |
/** | |
* Day | |
* Returns the current day. | |
* | |
* @param array $atts | |
* @param string $content | |
* @return string | |
*/ | |
public function day($atts, $content = null) | |
{ | |
return date('d'); | |
} | |
/** | |
* Year | |
* Returns the current year. | |
* | |
* @param array $atts | |
* @param string $content | |
* @return string | |
*/ | |
public function year($atts, $content = null) | |
{ | |
return date('Y'); | |
} | |
} | |
new Shortcodes(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment