/
linchpin-shortcodes.php
94 lines (81 loc) · 2.28 KB
/
linchpin-shortcodes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/*
Plugin Name: Linchpin Shortcodes
Plugin URI: http://wordpress.org/extend/plugins/linchpin-shortcodes
Description: A bunch of shortcodes the linchpin uses in most projects
Author: aware
Version: 1.0
Author URI: http://shortcodes.linchpinagency.com
*/
if ( ! class_exists( 'Linchpin_Shortcodes' ) ) {
/**
* Linchpin_Shortcodes class.
*/
class Linchpin_Shortcodes {
/**
* __construct function.
*
* @access public
* @return void
*/
function __construct() {
add_action( 'init', array( $this, 'register_shortcodes' ) );
add_filter( 'widget_text', 'do_shortcode'); // Allow our shortcodes to run in widgets
}
/**
* register_shortcodes function.
*
* @access public
* @return void
*/
function register_shortcodes() {
add_shortcode( 'email', array( $this, 'obfuscate_email_shortcode' ) );
add_shortcode( 'date', array( $this, 'output_date_shortcode' ) );
}
/**
* Hide email from Spam Bots using a shortcode.
* This is entirely from the codex and it's SUPER useful.
*
* @param array $atts Shortcode attributes. Not used.
* @param string $content The shortcode content. Should be an email address.
*
* Atrributes
* Label: The text of our link displayed to the user
* Title: The title of our link displayed as an attribute within the anchor tag
*
* @return string The obfuscated email address.
*/
function obfuscate_email_shortcode( $atts , $content = null ) {
if ( ! is_email ( $content ) )
return;
extract( shortcode_atts( array(
'label' => '',
'title' => ''
), $atts) );
$label = antispambot($content);
if( ! empty( $atts['label'] ) ) {
$label = $atts['label'];
}
if( ! empty( $atts['title'] ) ) {
$title_tag = ' title="' . $atts['label'] . '"';
}
return '<a href="mailto:' . antispambot($content) . '"' . $title_tag . '>' . $label . '</a>';
}
/**
* output_date_shortcode function.
* If no arguments are passed. the default return is Year
*
* @access public
* @param mixed $atts
* @return void
*/
function output_date_shortcode( $atts ) {
extract( shortcode_atts( array(
'format' => 'Y',
), $atts ) );
$date = date( $format );
return $date;
}
}
}
$linchpin_shortcodes = new Linchpin_Shortcodes();