Skip to content

Instantly share code, notes, and snippets.

@Log1x
Created September 20, 2017 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Log1x/1a9e44a04e4618ae993564fa151efcac to your computer and use it in GitHub Desktop.
Save Log1x/1a9e44a04e4618ae993564fa151efcac to your computer and use it in GitHub Desktop.
<?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