-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshortcake-quote.php
More file actions
111 lines (102 loc) · 3.14 KB
/
shortcake-quote.php
File metadata and controls
111 lines (102 loc) · 3.14 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Plugin Name: Shortcake - Quote
* Version: 1.0
* Description: Adds [shortcake_quote] shortcode to WordPress to use with Shortcode UI (Shortcake)
* Author: Cross Media Cloud
* Author URI: http://www.cross-media-cloud.de
* Text Domain: shortcake_quote
* License: GPL v3 or later
*
* This plugin is based on the "Shortcode UI Example" by Fusion Engineering and community
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/*
* Load the translation
*/
load_plugin_textdomain(
'shortcake_quote',
false,
'shortcake-quote/languages'
);
/*
* The function it self
*/
add_action( 'init', 'dr_shortcake_quote_function' );
function dr_shortcake_quote_function() {
/*
* Check if Shortcode UI plugin is active
*/
if ( ! function_exists( 'shortcode_ui_register_for_shortcode' ) ) {
add_action( 'admin_notices', function () {
if ( current_user_can( 'activate_plugins' ) ) {
echo '<div class="error message"><p>' . __( 'Shortcode UI plugin must be active for Shortcode UI Example plugin to function.', 'shortcake_quote' ) . '</p></div>';
}
} );
return;
}
/**
* Register your shortcode as you would normally.
* This is a simple example for a pullquote with a citation.
*/
add_shortcode( 'shortcake_quote', function( $attr, $content = '' ) {
$attr = wp_parse_args( $attr, array(
'source' => '',
'attachment' => 0
) );
ob_start();
?>
<blockquote>
<?php
echo wpautop( wp_kses_post( $content ) );
if ( isset( $attr['source'] ) AND 0 < strlen( $attr['source'] ) ) { ?>
<footer>
<cite><?php echo esc_html( $attr['source'] ); ?></cite>
</footer>
<?php } ?>
</blockquote>
<?php
return ob_get_clean();
} );
/**
* Register a UI for the Shortcode.
* Pass the shortcode tag (string)
* and an array or args.
*/
shortcode_ui_register_for_shortcode(
'shortcake_quote',
array(
// Display label. String. Required.
'label' => __( 'Shortcake Quote', 'shortcake_quote' ),
// Icon/attachment for shortcode. Optional. src or dashicons-$icon. Defaults to carrot.
'listItemImage' => 'dashicons-editor-quote',
'inner_content' => array(
'label' => __( 'Quote', 'shortcake_quote' ),
),
'post_type' => array( 'post', ),
// Available shortcode attributes and default values. Required. Array.
// Attribute model expects 'attr', 'type' and 'label'
// Supported field types: text, checkbox, textarea, radio, select, email, url, number, and date.
'attrs' => array(
array(
'label' => __( 'Cite', 'shortcake_quote' ),
'attr' => 'source',
'type' => 'text',
'meta' => array(
'placeholder' => __( 'Who said that?', 'shortcake_quote' ),
'data-test' => 1,
),
),
),
)
);
}