Version Description
Download this release
Release Info
Developer | vanderwijk |
Plugin | Content Blocks (Custom Post Widget) |
Version | 1.8.1 |
Comparing to | |
See all releases |
Code changes from version 1.7 to 1.8.1
- custom-post-widget.php +55 -57
- images/contentblock-13.png +0 -0
- popup.php +51 -0
- post-widget.php +200 -181
- readme.txt +6 -3
custom-post-widget.php
CHANGED
@@ -1,58 +1,56 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Custom Post Widget
|
4 |
-
Plugin URI: http://www.vanderwijk.com/services/web-design/wordpress-custom-post-widget/
|
5 |
-
Description: Show the content of a custom post of the type 'content_block' in a widget.
|
6 |
-
Version: 1.
|
7 |
-
Author: Johan van der Wijk
|
8 |
-
Author URI: http://www.vanderwijk.com
|
9 |
-
License: GPL2
|
10 |
-
|
11 |
-
Release notes: Version 1.
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
define( '
|
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 |
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Custom Post Widget
|
4 |
+
Plugin URI: http://www.vanderwijk.com/services/web-design/wordpress-custom-post-widget/
|
5 |
+
Description: Show the content of a custom post of the type 'content_block' in a widget.
|
6 |
+
Version: 1.8.1
|
7 |
+
Author: Johan van der Wijk
|
8 |
+
Author URI: http://www.vanderwijk.com
|
9 |
+
License: GPL2
|
10 |
+
|
11 |
+
Release notes: Version 1.8 Button added above content editor to easily insert the shortcode.
|
12 |
+
|
13 |
+
Copyright 2011 Johan van der Wijk (email: info@vanderwijk.com)
|
14 |
+
|
15 |
+
This program is free software; you can redistribute it and/or modify
|
16 |
+
it under the terms of the GNU General Public License, version 2, as
|
17 |
+
published by the Free Software Foundation.
|
18 |
+
|
19 |
+
This program is distributed in the hope that it will be useful,
|
20 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
+
GNU General Public License for more details.
|
23 |
+
|
24 |
+
You should have received a copy of the GNU General Public License
|
25 |
+
along with this program; if not, write to the Free Software
|
26 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
27 |
+
*/
|
28 |
+
|
29 |
+
/* Set constant path to the custom-post-widget plugin directory. */
|
30 |
+
define( 'CUSTOM_POST_WIDGET_DIR', plugin_dir_path( __FILE__ ) );
|
31 |
+
define( 'CUSTOM_POST_WIDGET_URL', WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),'',plugin_basename(__FILE__)) );
|
32 |
+
|
33 |
+
/* Launch the plugin. */
|
34 |
+
add_action( 'plugins_loaded', 'custom_post_widget_plugin_init' );
|
35 |
+
|
36 |
+
/**
|
37 |
+
Initialize the plugin. This function loads the required files needed for the plugin
|
38 |
+
to run in the proper order and adds needed functions to the required hooks.
|
39 |
+
*/
|
40 |
+
function custom_post_widget_plugin_init() {
|
41 |
+
|
42 |
+
/* Load the translation of the plugin. */
|
43 |
+
load_plugin_textdomain( 'custom-post-widget', false, 'custom-post-widget/languages' );
|
44 |
+
|
45 |
+
add_action( 'widgets_init', 'custom_post_widget_load_widgets' );
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
Loads the widgets packaged with the plugin.
|
50 |
+
*/
|
51 |
+
function custom_post_widget_load_widgets() {
|
52 |
+
require_once( CUSTOM_POST_WIDGET_DIR . '/post-widget.php' );
|
53 |
+
register_widget( 'custom_post_widget' );
|
54 |
+
}
|
55 |
+
|
|
|
|
|
56 |
?>
|
images/contentblock-13.png
ADDED
Binary file
|
popup.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
//Action target that displays the popup to insert a content block to a post/page
|
3 |
+
function add_mce_popup(){ ?>
|
4 |
+
|
5 |
+
<script>
|
6 |
+
function InsertContentBlockForm(){
|
7 |
+
var content_id = jQuery("#add_content_block_id").val();
|
8 |
+
if(content_id == ""){
|
9 |
+
alert("<?php _e("Please select a Content Block", 'custom-post-widget') ?>");
|
10 |
+
return;
|
11 |
+
}
|
12 |
+
|
13 |
+
var win = window.dialogArguments || opener || parent || top;
|
14 |
+
win.send_to_editor("[content_block id=" + content_id + "]");
|
15 |
+
}
|
16 |
+
</script>
|
17 |
+
|
18 |
+
<div id="select_form" style="display:none;">
|
19 |
+
<div class="wrap">
|
20 |
+
<div>
|
21 |
+
<div style="padding:15px 15px 0 15px;">
|
22 |
+
<h3 style="color:#5A5A5A!important; font-family:Georgia,Times New Roman,Times,serif!important; font-size:1.8em!important; font-weight:normal!important;"><?php _e("Insert Content Block", 'custom-post-widget'); ?></h3>
|
23 |
+
<span><?php _e("Select a Content Block below to add it to your post or page.", 'custom-post-widget'); ?></span>
|
24 |
+
</div>
|
25 |
+
<div style="padding:15px 15px 0 15px;">
|
26 |
+
<select id="add_content_block_id">
|
27 |
+
<option value=""><?php _e("Select a Content Block", 'custom-post-widget'); ?></option>
|
28 |
+
<?php query_posts('post_type=content_block&orderby=ID&order=ASC&showposts=-1');
|
29 |
+
if ( have_posts() ) : while ( have_posts() ) : the_post();
|
30 |
+
$currentID = get_the_ID();
|
31 |
+
if($currentID == $custom_post_id)
|
32 |
+
$extra = 'selected' and
|
33 |
+
$widgetExtraTitle = get_the_title();
|
34 |
+
else
|
35 |
+
$extra = '';
|
36 |
+
echo '<option value="'.$currentID.'" '.$extra.'>'.get_the_title().'</option>';
|
37 |
+
endwhile; else:
|
38 |
+
echo '<option value="empty">' . __('No content blocks available', 'custom-post-widget') . '</option>';
|
39 |
+
endif;
|
40 |
+
?>
|
41 |
+
</select>
|
42 |
+
<br/>
|
43 |
+
<div style="padding:15px;">
|
44 |
+
<input type="button" class="button-primary" value="Insert Content Block" onclick="InsertContentBlockForm();"/>
|
45 |
+
<a class="button" style="color:#bbb;" href="#" onclick="tb_remove(); return false;"><?php _e("Cancel", 'custom-post-widget'); ?></a>
|
46 |
+
</div>
|
47 |
+
</div>
|
48 |
+
</div>
|
49 |
+
</div>
|
50 |
+
<?php
|
51 |
+
}
|
post-widget.php
CHANGED
@@ -1,182 +1,201 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// First create the widget for the admin panel
|
4 |
-
class custom_post_widget extends WP_Widget
|
5 |
-
{
|
6 |
-
function custom_post_widget()
|
7 |
-
{
|
8 |
-
$widget_ops = array('description' => __('Displays custom post content in a widget',
|
9 |
-
$this->WP_Widget('custom_post_widget', __('Content Block',
|
10 |
-
}
|
11 |
-
|
12 |
-
function form($instance)
|
13 |
-
{
|
14 |
-
$custom_post_id = esc_attr($instance['custom_post_id']);
|
15 |
-
$show_custom_post_title = isset($instance['show_custom_post_title ']) ? $instance['show_custom_post_title '] : true;
|
16 |
-
|
17 |
-
?>
|
18 |
-
<p>
|
19 |
-
<label for="<?php echo $this->get_field_id('custom_post_id'); ?>"> <?php echo __('Content Block to Display:',
|
20 |
-
<select class="widefat" id="<?php echo $this->get_field_id('custom_post_id'); ?>" name="<?php echo $this->get_field_name('custom_post_id'); ?>">
|
21 |
-
<?php query_posts('post_type=content_block&orderby=ID&order=ASC&showposts=-1');
|
22 |
-
if ( have_posts() ) : while ( have_posts() ) : the_post();
|
23 |
-
$currentID = get_the_ID();
|
24 |
-
if($currentID == $custom_post_id)
|
25 |
-
$extra = 'selected' and
|
26 |
-
$widgetExtraTitle = get_the_title();
|
27 |
-
else
|
28 |
-
$extra = '';
|
29 |
-
echo '<option value="'.$currentID.'" '.$extra.'>'.get_the_title().'</option>';
|
30 |
-
endwhile; else:
|
31 |
-
echo '<option value="empty">' . __('No content blocks available',
|
32 |
-
endif;
|
33 |
-
?>
|
34 |
-
</select>
|
35 |
-
</label>
|
36 |
-
</p>
|
37 |
-
<?php ?>
|
38 |
-
<input type="hidden" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $widgetExtraTitle; ?>" />
|
39 |
-
<?php wp_reset_query(); ?>
|
40 |
-
<p>
|
41 |
-
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['show_custom_post_title'], true ); ?> id="<?php echo $this->get_field_id( 'show_custom_post_title' ); ?>" name="<?php echo $this->get_field_name( 'show_custom_post_title' ); ?>" />
|
42 |
-
<label for="<?php echo $this->get_field_id( 'show_custom_post_title' ); ?>"><?php echo __('Show Post Title',
|
43 |
-
</p>
|
44 |
-
|
45 |
-
<?php
|
46 |
-
}
|
47 |
-
|
48 |
-
function update($new_instance, $old_instance)
|
49 |
-
{
|
50 |
-
$instance = $old_instance;
|
51 |
-
$instance['custom_post_id'] = strip_tags($new_instance['custom_post_id']);
|
52 |
-
$instance['show_custom_post_title'] = $new_instance['show_custom_post_title'];
|
53 |
-
|
54 |
-
return $instance;
|
55 |
-
}
|
56 |
-
|
57 |
-
function widget($args, $instance)
|
58 |
-
{
|
59 |
-
extract($args);
|
60 |
-
|
61 |
-
$custom_post_id = ( $instance['custom_post_id'] != '' ) ? esc_attr($instance['custom_post_id']) : __('Find',
|
62 |
-
|
63 |
-
/* Variables from the widget settings. */
|
64 |
-
$show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : false;
|
65 |
-
|
66 |
-
$content_post = get_post($custom_post_id);
|
67 |
-
$content = $content_post->post_content;
|
68 |
-
$content = apply_filters('the_content', $content);
|
69 |
-
$content = str_replace(']]>', ']]>', $content);
|
70 |
-
|
71 |
-
echo $before_widget;
|
72 |
-
if ( $show_custom_post_title )
|
73 |
-
{
|
74 |
-
echo $before_title . $content_post->post_title . $after_title; // This is the line that displays the title (only if show title is set)
|
75 |
-
}
|
76 |
-
echo $content; // This is where the actual content of the custom post is being displayed
|
77 |
-
echo $after_widget;
|
78 |
-
|
79 |
-
}
|
80 |
-
}
|
81 |
-
|
82 |
-
// Create the Content Block custom post type
|
83 |
-
add_action('init', 'my_content_block_post_type_init');
|
84 |
-
|
85 |
-
function my_content_block_post_type_init()
|
86 |
-
{
|
87 |
-
$labels = array(
|
88 |
-
'name' => _x('Content Blocks', 'post type general name',
|
89 |
-
'singular_name' => _x('Content Block', 'post type singular name',
|
90 |
-
'plural_name' => _x('Content Blocks', 'post type plural name',
|
91 |
-
'add_new' => _x('Add Content Block', 'block',
|
92 |
-
'add_new_item' => __('Add New Content Block',
|
93 |
-
'edit_item' => __('Edit Content Block',
|
94 |
-
'new_item' => __('New Content Block',
|
95 |
-
'view_item' => __('View Content Block',
|
96 |
-
'search_items' => __('Search Content Blocks',
|
97 |
-
'not_found' => __('No Content Blocks Found',
|
98 |
-
'not_found_in_trash' => __('No Content Blocks found in Trash',
|
99 |
-
'parent_item_colon' => ''
|
100 |
-
);
|
101 |
-
$options = array(
|
102 |
-
'labels' => $labels,
|
103 |
-
'public' => false,
|
104 |
-
'publicly_queryable' => false,
|
105 |
-
'exclude_from_search' => true,
|
106 |
-
'show_ui' => true,
|
107 |
-
'query_var' => true,
|
108 |
-
'rewrite' => true,
|
109 |
-
'capability_type' => 'post',
|
110 |
-
'hierarchical' => false,
|
111 |
-
'menu_position' => null,
|
112 |
-
'supports' => array('title','editor','revisions','thumbnail','author')
|
113 |
-
);
|
114 |
-
register_post_type('content_block',$options);
|
115 |
-
}
|
116 |
-
|
117 |
-
|
118 |
-
// Add custom styles to admin screen and menu
|
119 |
-
add_action('admin_head', 'content_block_header');
|
120 |
-
|
121 |
-
function content_block_header() {
|
122 |
-
|
123 |
-
global $post_type; ?>
|
124 |
-
|
125 |
-
<style type="text/css"><!--
|
126 |
-
<?php if (($post_type == 'content_block')) : ?>
|
127 |
-
#icon-edit { background:transparent url('<?php echo CUSTOM_POST_WIDGET_URL; ?>images/contentblock-32.png') no-repeat 0 0 !important; }
|
128 |
-
<?php endif; ?>
|
129 |
-
#adminmenu #menu-posts-contentblock div.wp-menu-image{background:transparent url('<?php echo CUSTOM_POST_WIDGET_URL;?>images/contentblock.png') no-repeat center -32px;}
|
130 |
-
#adminmenu #menu-posts-contentblock:hover div.wp-menu-image,#adminmenu #menu-posts-contentblock.wp-has-current-submenu div.wp-menu-image{background:transparent url('<?php echo CUSTOM_POST_WIDGET_URL;?>images/contentblock.png') no-repeat center 0px;}
|
131 |
-
--></style><?php
|
132 |
-
|
133 |
-
}
|
134 |
-
|
135 |
-
add_filter('post_updated_messages', 'content_block_messages');
|
136 |
-
|
137 |
-
function content_block_messages( $messages ) {
|
138 |
-
|
139 |
-
$messages['content_block'] = array(
|
140 |
-
0 => '',
|
141 |
-
1 => sprintf( __('Content Block updated. <a href="%s">View Content Block</a>',
|
142 |
-
2 => __('Custom field updated.',
|
143 |
-
3 => __('Custom field deleted.',
|
144 |
-
4 => __('Content Block updated.',
|
145 |
-
5 => isset($_GET['revision']) ? sprintf( __('Content Block restored to revision from %s',
|
146 |
-
6 => sprintf( __('Content Block published. <a href="%s">View Content Block</a>',
|
147 |
-
7 => __('Block saved.',
|
148 |
-
8 => sprintf( __('Content Block submitted. <a target="_blank" href="%s">Preview Content Block</a>',
|
149 |
-
9 => sprintf( __('Content Block scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview block</a>',
|
150 |
-
10 => sprintf( __('Content Block draft updated. <a target="_blank" href="%s">Preview Content Block</a>',
|
151 |
-
);
|
152 |
-
|
153 |
-
return $messages;
|
154 |
-
}
|
155 |
-
|
156 |
-
// Add the ability to display the content block in a reqular post using a shortcode
|
157 |
-
function custom_post_widget_shortcode($atts) {
|
158 |
-
extract(shortcode_atts(array(
|
159 |
-
'id' => '',
|
160 |
-
), $atts));
|
161 |
-
|
162 |
-
$content = "";
|
163 |
-
|
164 |
-
if($id != "")
|
165 |
-
|
166 |
-
|
167 |
-
'
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// First create the widget for the admin panel
|
4 |
+
class custom_post_widget extends WP_Widget
|
5 |
+
{
|
6 |
+
function custom_post_widget()
|
7 |
+
{
|
8 |
+
$widget_ops = array('description' => __('Displays custom post content in a widget', 'custom-post-widget'));
|
9 |
+
$this->WP_Widget('custom_post_widget', __('Content Block', 'custom-post-widget'), $widget_ops);
|
10 |
+
}
|
11 |
+
|
12 |
+
function form($instance)
|
13 |
+
{
|
14 |
+
$custom_post_id = esc_attr($instance['custom_post_id']);
|
15 |
+
$show_custom_post_title = isset($instance['show_custom_post_title ']) ? $instance['show_custom_post_title '] : true;
|
16 |
+
|
17 |
+
?>
|
18 |
+
<p>
|
19 |
+
<label for="<?php echo $this->get_field_id('custom_post_id'); ?>"> <?php echo __('Content Block to Display:', 'custom-post-widget') ?>
|
20 |
+
<select class="widefat" id="<?php echo $this->get_field_id('custom_post_id'); ?>" name="<?php echo $this->get_field_name('custom_post_id'); ?>">
|
21 |
+
<?php query_posts('post_type=content_block&orderby=ID&order=ASC&showposts=-1');
|
22 |
+
if ( have_posts() ) : while ( have_posts() ) : the_post();
|
23 |
+
$currentID = get_the_ID();
|
24 |
+
if($currentID == $custom_post_id)
|
25 |
+
$extra = 'selected' and
|
26 |
+
$widgetExtraTitle = get_the_title();
|
27 |
+
else
|
28 |
+
$extra = '';
|
29 |
+
echo '<option value="'.$currentID.'" '.$extra.'>'.get_the_title().'</option>';
|
30 |
+
endwhile; else:
|
31 |
+
echo '<option value="empty">' . __('No content blocks available', 'custom-post-widget') . '</option>';
|
32 |
+
endif;
|
33 |
+
?>
|
34 |
+
</select>
|
35 |
+
</label>
|
36 |
+
</p>
|
37 |
+
<?php ?>
|
38 |
+
<input type="hidden" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $widgetExtraTitle; ?>" />
|
39 |
+
<?php wp_reset_query(); ?>
|
40 |
+
<p>
|
41 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) $instance['show_custom_post_title'], true ); ?> id="<?php echo $this->get_field_id( 'show_custom_post_title' ); ?>" name="<?php echo $this->get_field_name( 'show_custom_post_title' ); ?>" />
|
42 |
+
<label for="<?php echo $this->get_field_id( 'show_custom_post_title' ); ?>"><?php echo __('Show Post Title', 'custom-post-widget') ?></label>
|
43 |
+
</p>
|
44 |
+
|
45 |
+
<?php
|
46 |
+
}
|
47 |
+
|
48 |
+
function update($new_instance, $old_instance)
|
49 |
+
{
|
50 |
+
$instance = $old_instance;
|
51 |
+
$instance['custom_post_id'] = strip_tags($new_instance['custom_post_id']);
|
52 |
+
$instance['show_custom_post_title'] = $new_instance['show_custom_post_title'];
|
53 |
+
|
54 |
+
return $instance;
|
55 |
+
}
|
56 |
+
|
57 |
+
function widget($args, $instance)
|
58 |
+
{
|
59 |
+
extract($args);
|
60 |
+
|
61 |
+
$custom_post_id = ( $instance['custom_post_id'] != '' ) ? esc_attr($instance['custom_post_id']) : __('Find', 'custom-post-widget');
|
62 |
+
|
63 |
+
/* Variables from the widget settings. */
|
64 |
+
$show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : false;
|
65 |
+
|
66 |
+
$content_post = get_post($custom_post_id);
|
67 |
+
$content = $content_post->post_content;
|
68 |
+
$content = apply_filters('the_content', $content);
|
69 |
+
$content = str_replace(']]>', ']]>', $content);
|
70 |
+
|
71 |
+
echo $before_widget;
|
72 |
+
if ( $show_custom_post_title )
|
73 |
+
{
|
74 |
+
echo $before_title . $content_post->post_title . $after_title; // This is the line that displays the title (only if show title is set)
|
75 |
+
}
|
76 |
+
echo $content; // This is where the actual content of the custom post is being displayed
|
77 |
+
echo $after_widget;
|
78 |
+
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
+
// Create the Content Block custom post type
|
83 |
+
add_action('init', 'my_content_block_post_type_init');
|
84 |
+
|
85 |
+
function my_content_block_post_type_init()
|
86 |
+
{
|
87 |
+
$labels = array(
|
88 |
+
'name' => _x('Content Blocks', 'post type general name', 'custom-post-widget'),
|
89 |
+
'singular_name' => _x('Content Block', 'post type singular name', 'custom-post-widget'),
|
90 |
+
'plural_name' => _x('Content Blocks', 'post type plural name', 'custom-post-widget'),
|
91 |
+
'add_new' => _x('Add Content Block', 'block', 'custom-post-widget'),
|
92 |
+
'add_new_item' => __('Add New Content Block', 'custom-post-widget'),
|
93 |
+
'edit_item' => __('Edit Content Block', 'custom-post-widget'),
|
94 |
+
'new_item' => __('New Content Block', 'custom-post-widget'),
|
95 |
+
'view_item' => __('View Content Block', 'custom-post-widget'),
|
96 |
+
'search_items' => __('Search Content Blocks', 'custom-post-widget'),
|
97 |
+
'not_found' => __('No Content Blocks Found', 'custom-post-widget'),
|
98 |
+
'not_found_in_trash' => __('No Content Blocks found in Trash', 'custom-post-widget'),
|
99 |
+
'parent_item_colon' => ''
|
100 |
+
);
|
101 |
+
$options = array(
|
102 |
+
'labels' => $labels,
|
103 |
+
'public' => false,
|
104 |
+
'publicly_queryable' => false,
|
105 |
+
'exclude_from_search' => true,
|
106 |
+
'show_ui' => true,
|
107 |
+
'query_var' => true,
|
108 |
+
'rewrite' => true,
|
109 |
+
'capability_type' => 'post',
|
110 |
+
'hierarchical' => false,
|
111 |
+
'menu_position' => null,
|
112 |
+
'supports' => array('title','editor','revisions','thumbnail','author')
|
113 |
+
);
|
114 |
+
register_post_type('content_block',$options);
|
115 |
+
}
|
116 |
+
|
117 |
+
|
118 |
+
// Add custom styles to admin screen and menu
|
119 |
+
add_action('admin_head', 'content_block_header');
|
120 |
+
|
121 |
+
function content_block_header() {
|
122 |
+
|
123 |
+
global $post_type; ?>
|
124 |
+
|
125 |
+
<style type="text/css"><!--
|
126 |
+
<?php if (($post_type == 'content_block')) : ?>
|
127 |
+
#icon-edit { background:transparent url('<?php echo CUSTOM_POST_WIDGET_URL; ?>images/contentblock-32.png') no-repeat 0 0 !important; }
|
128 |
+
<?php endif; ?>
|
129 |
+
#adminmenu #menu-posts-contentblock div.wp-menu-image{background:transparent url('<?php echo CUSTOM_POST_WIDGET_URL;?>images/contentblock.png') no-repeat center -32px;}
|
130 |
+
#adminmenu #menu-posts-contentblock:hover div.wp-menu-image,#adminmenu #menu-posts-contentblock.wp-has-current-submenu div.wp-menu-image{background:transparent url('<?php echo CUSTOM_POST_WIDGET_URL;?>images/contentblock.png') no-repeat center 0px;}
|
131 |
+
--></style><?php
|
132 |
+
|
133 |
+
}
|
134 |
+
|
135 |
+
add_filter('post_updated_messages', 'content_block_messages');
|
136 |
+
|
137 |
+
function content_block_messages( $messages ) {
|
138 |
+
|
139 |
+
$messages['content_block'] = array(
|
140 |
+
0 => '',
|
141 |
+
1 => sprintf( __('Content Block updated. <a href="%s">View Content Block</a>', 'custom-post-widget'), esc_url( get_permalink(isset($post->ID) ? $post->ID : null) ) ),
|
142 |
+
2 => __('Custom field updated.', 'custom-post-widget'),
|
143 |
+
3 => __('Custom field deleted.', 'custom-post-widget'),
|
144 |
+
4 => __('Content Block updated.', 'custom-post-widget'),
|
145 |
+
5 => isset($_GET['revision']) ? sprintf( __('Content Block restored to revision from %s', 'custom-post-widget'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
|
146 |
+
6 => sprintf( __('Content Block published. <a href="%s">View Content Block</a>', 'custom-post-widget'), esc_url( get_permalink(isset($post->ID) ? $post->ID : null) ) ),
|
147 |
+
7 => __('Block saved.', 'custom-post-widget'),
|
148 |
+
8 => sprintf( __('Content Block submitted. <a target="_blank" href="%s">Preview Content Block</a>', 'custom-post-widget'), esc_url( add_query_arg( 'preview', 'true', get_permalink(isset($post->ID) ? $post->ID : null) ) ) ),
|
149 |
+
9 => sprintf( __('Content Block scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview block</a>', 'custom-post-widget'), date_i18n( __( 'M j, Y @ G:i' , 'custom-post-widget'), strtotime(isset($post->post_date) ? $post->post_date : null) ), esc_url( get_permalink(isset($post->ID) ? $post->ID : null) ) ),
|
150 |
+
10 => sprintf( __('Content Block draft updated. <a target="_blank" href="%s">Preview Content Block</a>', 'custom-post-widget'), esc_url( add_query_arg( 'preview', 'true', get_permalink(isset($post->ID) ? $post->ID : null) ) ) ),
|
151 |
+
);
|
152 |
+
|
153 |
+
return $messages;
|
154 |
+
}
|
155 |
+
|
156 |
+
// Add the ability to display the content block in a reqular post using a shortcode
|
157 |
+
function custom_post_widget_shortcode($atts) {
|
158 |
+
extract(shortcode_atts(array(
|
159 |
+
'id' => '',
|
160 |
+
), $atts));
|
161 |
+
|
162 |
+
$content = "";
|
163 |
+
|
164 |
+
if($id != "")
|
165 |
+
{
|
166 |
+
$args = array(
|
167 |
+
'post__in' => array($id),
|
168 |
+
'post_type' => 'content_block',
|
169 |
+
);
|
170 |
+
|
171 |
+
$content_post = get_posts($args);
|
172 |
+
|
173 |
+
foreach( $content_post as $post ) :
|
174 |
+
$content .= apply_filters('the_content', $post->post_content);
|
175 |
+
endforeach;
|
176 |
+
}
|
177 |
+
|
178 |
+
return $content;
|
179 |
+
}
|
180 |
+
|
181 |
+
add_shortcode('content_block', 'custom_post_widget_shortcode');
|
182 |
+
|
183 |
+
// Add button above editor
|
184 |
+
function add_content_block_icon($initcontext) {
|
185 |
+
return $initcontext.
|
186 |
+
'<a id="add_content_block" class="thickbox" title="' . __("Add Content Block", 'custom-post-widget') . '" href="' . CUSTOM_POST_WIDGET_URL . 'popup.php#TB_inline?width=450&inlineId=select_form">
|
187 |
+
<img onclick="return false;" alt="' . __("Add Content Block", 'custom-post-widget') . '" src="' . CUSTOM_POST_WIDGET_URL . 'images/contentblock-13.png">
|
188 |
+
</a>';
|
189 |
+
}
|
190 |
+
|
191 |
+
add_filter('media_buttons_context', 'add_content_block_icon');
|
192 |
+
|
193 |
+
require_once( CUSTOM_POST_WIDGET_DIR . '/popup.php' );
|
194 |
+
|
195 |
+
if(!defined( 'CUSTOM_POST_WIDGET_CURRENT_PAGE' ))
|
196 |
+
define( 'CUSTOM_POST_WIDGET_CURRENT_PAGE', basename($_SERVER['PHP_SELF']) );
|
197 |
+
|
198 |
+
if(in_array(CUSTOM_POST_WIDGET_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php'))) {
|
199 |
+
add_action('admin_footer', 'add_mce_popup');
|
200 |
+
}
|
201 |
?>
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Donate link: http://www.vanderwijk.com/wordpress/support/
|
|
5 |
Tags: custom-post, widget, sidebar
|
6 |
Requires at least: 2.9.2
|
7 |
Tested up to: 3.1
|
8 |
-
Stable tag: 1.
|
9 |
|
10 |
This plugin enables you to display the content of a custom post type called Content Block in a sidebar widget.
|
11 |
|
@@ -100,9 +100,12 @@ The Custom Post Widget plugin is now using the more efficient get_post instead o
|
|
100 |
= 1.7 =
|
101 |
This release fixes all the debug error messages Yoast discovered when [reviewing this plugin](http://yoast.com/wp-plugin-review/custom-post-widget/). As requested by Tony Allsopp the option of using the shortcode [content_block id= ] to pull in the content of a content block in a page or post has been added.
|
102 |
|
|
|
|
|
|
|
103 |
== Upgrade Notice ==
|
104 |
|
105 |
-
= 1.
|
106 |
-
|
107 |
|
108 |
|
5 |
Tags: custom-post, widget, sidebar
|
6 |
Requires at least: 2.9.2
|
7 |
Tested up to: 3.1
|
8 |
+
Stable tag: 1.8.1
|
9 |
|
10 |
This plugin enables you to display the content of a custom post type called Content Block in a sidebar widget.
|
11 |
|
100 |
= 1.7 =
|
101 |
This release fixes all the debug error messages Yoast discovered when [reviewing this plugin](http://yoast.com/wp-plugin-review/custom-post-widget/). As requested by Tony Allsopp the option of using the shortcode [content_block id= ] to pull in the content of a content block in a page or post has been added.
|
102 |
|
103 |
+
= 1.8 =
|
104 |
+
Added a button above to content editor to make it easier to add the shortcode (no need for looking up the id).
|
105 |
+
|
106 |
== Upgrade Notice ==
|
107 |
|
108 |
+
= 1.8 =
|
109 |
+
I would appreciate some feedback on the newly introduced shortcode functionality. Is this useful or not? Any issues found? Thanks!
|
110 |
|
111 |
|