-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
56 lines (52 loc) · 1.68 KB
/
plugin.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
<?php
defined('ABSPATH') or die("No script kiddies please!");
/**
* Plugin Name: Chunky
* Plugin URI: https://github.com/jlandrum/wp-chunky
* Description: Allows the creation of reusable blocks of code in Wordpress
* Version: 1.0.0
* Author: James Landrum
* Author URI: http://jameslandrum.com
* License: GPL2
*/
add_action( 'init', 'chunky_create_post_type' );
function chunky_create_post_type() {
register_post_type( 'chunk',
array(
'labels' => array(
'name' => __( 'Chunks' ),
'singular_name' => __( 'Chunk' ),
'add_new' => __( 'Add Chunk' ),
'add_new_item' => __( 'Add New Chunk' ),
'edit_item' => __( 'Edit Chunk' ),
'new_item' => __( 'New Chunk' ),
'view_item' => __( 'View Chunk' ),
'search_items' => __( 'Search Chunks' ),
'not_found' => __( 'No Chunks found' ),
'not_found_in_trash' => __( 'No Chunks found in Trash' ),
),
'rewrite' => array(
'slug' => '',
'with_front' => true
),
'supports' => array (
'title', 'editor'
),
'menu_icon' => plugin_dir_url( __FILE__ ) . "/images/dashicon.png",
'public' => true,
'has_archive' => false,
)
);
}
add_shortcode( 'chunk', function($attrs, $text="") {
if (isset($attrs['id'])) {
$post = get_post( $attrs['id'] );
} else if (isset($attrs['title'])) {
$post = get_page_by_title( $attrs['title'], 'OBJECT', 'chunk' );
} else { return "<!-- Chunk Missing -->"; }
$content = $post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = do_shortcode($content);
return $content;
});