Created
September 20, 2017 00:17
-
-
Save Log1x/1a9e44a04e4618ae993564fa151efcac to your computer and use it in GitHub Desktop.
This file contains 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 Samrap\Acf\Acf; | |
/** | |
* Shortcodes | |
*/ | |
if (!class_exists('Shortcodes')) { | |
class Shortcodes | |
{ | |
/** | |
* Constructor | |
*/ | |
public function __construct() | |
{ | |
$shortcodes = [ | |
'date', | |
'month', | |
'day', | |
'year', | |
'sitename', | |
'color', | |
'bold' | |
]; | |
return array_map(function($shortcode) { | |
add_shortcode($shortcode, [$this, strtr($shortcode, ['-' => '_'])]); | |
}, $shortcodes); | |
} | |
/** | |
* Date | |
* Returns the current date. | |
* | |
* @param array $atts | |
* @param string $content | |
* @return string | |
*/ | |
function date($atts, $content = null) | |
{ | |
return date('F d, Y'); | |
} | |
/** | |
* Month | |
* Returns the current month. | |
* | |
* @param array $atts | |
* @param string $content | |
* @return string | |
*/ | |
function month($atts, $content = null) | |
{ | |
return date('F'); | |
} | |
/** | |
* Day | |
* Returns the current day. | |
* | |
* @param array $atts | |
* @param string $content | |
* @return string | |
*/ | |
function day($atts, $content = null) | |
{ | |
return date('d'); | |
} | |
/** | |
* Year | |
* Returns the current year. | |
* | |
* @param array $atts | |
* @param string $content | |
* @return string | |
*/ | |
function year($atts, $content = null) | |
{ | |
return date('Y'); | |
} | |
/** | |
* Site Name | |
* Returns the site name. | |
* | |
* @param array $atts | |
* @param string $content | |
* @return string | |
*/ | |
function sitename($atts, $content = null) | |
{ | |
return get_bloginfo('name'); | |
} | |
/** | |
* Color | |
* Wraps text in a colored span | |
* | |
* @param array $atts | |
* @param string $content | |
* @param string $tag | |
* @return string | |
*/ | |
public function color($atts, $content = null, $tag = '') | |
{ | |
return "<span class=\"color\">{$content}</span>"; | |
} | |
/** | |
* Bold | |
* Wraps text in a <strong> element | |
* | |
* @param array $atts | |
* @param string $content | |
* @param string $tag | |
* @return string | |
*/ | |
public function bold($atts, $content = null, $tags = '') | |
{ | |
return "<strong>{$content}</strong>"; | |
} | |
} | |
} | |
new Shortcodes(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment