Content Blocks (Custom Post Widget) - Version 1.7

Version Description

This release fixes all the debug error messages Yoast discovered when reviewing this plugin. As requested by Tony Allsopp the option of using the shortcode [content_block id

Download this release

Release Info

Developer vanderwijk
Plugin Icon 128x128 Content Blocks (Custom Post Widget)
Version 1.7
Comparing to
See all releases

Code changes from version 1.6 to 1.7

Files changed (3) hide show
  1. custom-post-widget.php +57 -57
  2. post-widget.php +181 -156
  3. readme.txt +4 -2
custom-post-widget.php CHANGED
@@ -1,58 +1,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.6
7
- Author: Johan van der Wijk
8
- Author URI: http://www.vanderwijk.com
9
- License: GPL2
10
-
11
- Release notes: Version 1.6 of the Custom Post Widget plugin now uses the much more efficient
12
- get_post instead of query_post to display the widget content.
13
-
14
- Copyright 2011 Johan van der Wijk (email: info@vanderwijk.com)
15
-
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License, version 2, as
18
- published by the Free Software Foundation.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
- */
29
-
30
- /* Set constant path to the custom-post-widget plugin directory. */
31
- define( 'CUSTOM_POST_WIDGET_DIR', plugin_dir_path( __FILE__ ) );
32
- define( 'CUSTOM_POST_WIDGET_URL', WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),'',plugin_basename(__FILE__)) );
33
- define( 'CUSTOM_POST_WIDGET_TEXTDOMAIN', 'custom-post-widget' );
34
-
35
- /* Launch the plugin. */
36
- add_action( 'plugins_loaded', 'custom_post_widget_plugin_init' );
37
-
38
- /**
39
- Initialize the plugin. This function loads the required files needed for the plugin
40
- to run in the proper order and adds needed functions to the required hooks.
41
- */
42
- function custom_post_widget_plugin_init() {
43
-
44
- /* Load the translation of the plugin. */
45
- load_plugin_textdomain( CUSTOM_POST_WIDGET_TEXTDOMAIN, false, 'custom-post-widget/languages' );
46
-
47
- add_action( 'widgets_init', 'custom_post_widget_load_widgets' );
48
- }
49
-
50
- /**
51
- Loads the widgets packaged with the plugin.
52
- */
53
- function custom_post_widget_load_widgets() {
54
- require_once( CUSTOM_POST_WIDGET_DIR . '/post-widget.php' );
55
- register_widget( 'custom_post_widget' );
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.7
7
+ Author: Johan van der Wijk
8
+ Author URI: http://www.vanderwijk.com
9
+ License: GPL2
10
+
11
+ Release notes: Version 1.7 fixes all the error messages that Yoast discovered when reviewing this plugin.
12
+ It also adds the option to use the [content_block id= ] shortcode to insert a content block in a post.
13
+
14
+ Copyright 2011 Johan van der Wijk (email: info@vanderwijk.com)
15
+
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License, version 2, as
18
+ published by the Free Software Foundation.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
+ */
29
+
30
+ /* Set constant path to the custom-post-widget plugin directory. */
31
+ define( 'CUSTOM_POST_WIDGET_DIR', plugin_dir_path( __FILE__ ) );
32
+ define( 'CUSTOM_POST_WIDGET_URL', WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),'',plugin_basename(__FILE__)) );
33
+ define( 'CUSTOM_POST_WIDGET_TEXTDOMAIN', 'custom-post-widget' );
34
+
35
+ /* Launch the plugin. */
36
+ add_action( 'plugins_loaded', 'custom_post_widget_plugin_init' );
37
+
38
+ /**
39
+ Initialize the plugin. This function loads the required files needed for the plugin
40
+ to run in the proper order and adds needed functions to the required hooks.
41
+ */
42
+ function custom_post_widget_plugin_init() {
43
+
44
+ /* Load the translation of the plugin. */
45
+ load_plugin_textdomain( CUSTOM_POST_WIDGET_TEXTDOMAIN, false, 'custom-post-widget/languages' );
46
+
47
+ add_action( 'widgets_init', 'custom_post_widget_load_widgets' );
48
+ }
49
+
50
+ /**
51
+ Loads the widgets packaged with the plugin.
52
+ */
53
+ function custom_post_widget_load_widgets() {
54
+ require_once( CUSTOM_POST_WIDGET_DIR . '/post-widget.php' );
55
+ register_widget( 'custom_post_widget' );
56
+ }
57
+
58
  ?>
post-widget.php CHANGED
@@ -1,157 +1,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_TEXTDOMAIN));
9
- $this->WP_Widget('custom_post_widget', __('Content Block', CUSTOM_POST_WIDGET_TEXTDOMAIN), $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_TEXTDOMAIN) ?>
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_TEXTDOMAIN) . '</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_TEXTDOMAIN) ?></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_TEXTDOMAIN);
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_TEXTDOMAIN),
89
- 'singular_name' => _x('Content Block', 'post type singular name', CUSTOM_POST_WIDGET_TEXTDOMAIN),
90
- 'plural_name' => _x('Content Blocks', 'post type plural name', CUSTOM_POST_WIDGET_TEXTDOMAIN),
91
- 'add_new' => _x('Add Content Block', 'block', CUSTOM_POST_WIDGET_TEXTDOMAIN),
92
- 'add_new_item' => __('Add New Content Block', CUSTOM_POST_WIDGET_TEXTDOMAIN),
93
- 'edit_item' => __('Edit Content Block', CUSTOM_POST_WIDGET_TEXTDOMAIN),
94
- 'new_item' => __('New Content Block', CUSTOM_POST_WIDGET_TEXTDOMAIN),
95
- 'view_item' => __('View Content Block', CUSTOM_POST_WIDGET_TEXTDOMAIN),
96
- 'search_items' => __('Search Content Blocks', CUSTOM_POST_WIDGET_TEXTDOMAIN),
97
- 'not_found' => __('No Content Blocks Found', CUSTOM_POST_WIDGET_TEXTDOMAIN),
98
- 'not_found_in_trash' => __('No Content Blocks found in Trash', CUSTOM_POST_WIDGET_TEXTDOMAIN),
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_TEXTDOMAIN), esc_url( get_permalink($post_ID) ) ),
142
- 2 => __('Custom field updated.', CUSTOM_POST_WIDGET_TEXTDOMAIN),
143
- 3 => __('Custom field deleted.', CUSTOM_POST_WIDGET_TEXTDOMAIN),
144
- 4 => __('Content Block updated.', CUSTOM_POST_WIDGET_TEXTDOMAIN),
145
- 5 => isset($_GET['revision']) ? sprintf( __('Content Block restored to revision from %s', CUSTOM_POST_WIDGET_TEXTDOMAIN), 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_TEXTDOMAIN), esc_url( get_permalink($post_ID) ) ),
147
- 7 => __('Block saved.', CUSTOM_POST_WIDGET_TEXTDOMAIN),
148
- 8 => sprintf( __('Content Block submitted. <a target="_blank" href="%s">Preview Content Block</a>', CUSTOM_POST_WIDGET_TEXTDOMAIN), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
149
- 9 => sprintf( __('Content Block scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview block</a>', CUSTOM_POST_WIDGET_TEXTDOMAIN),
150
- date_i18n( __( 'M j, Y @ G:i' , CUSTOM_POST_WIDGET_TEXTDOMAIN), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
151
- 10 => sprintf( __('Content Block draft updated. <a target="_blank" href="%s">Preview Content Block</a>', CUSTOM_POST_WIDGET_TEXTDOMAIN), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
152
- );
153
-
154
- return $messages;
155
- }
156
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  ?>
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_TEXTDOMAIN));
9
+ $this->WP_Widget('custom_post_widget', __('Content Block', CUSTOM_POST_WIDGET_TEXTDOMAIN), $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_TEXTDOMAIN) ?>
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_TEXTDOMAIN) . '</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_TEXTDOMAIN) ?></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_TEXTDOMAIN);
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_TEXTDOMAIN),
89
+ 'singular_name' => _x('Content Block', 'post type singular name', CUSTOM_POST_WIDGET_TEXTDOMAIN),
90
+ 'plural_name' => _x('Content Blocks', 'post type plural name', CUSTOM_POST_WIDGET_TEXTDOMAIN),
91
+ 'add_new' => _x('Add Content Block', 'block', CUSTOM_POST_WIDGET_TEXTDOMAIN),
92
+ 'add_new_item' => __('Add New Content Block', CUSTOM_POST_WIDGET_TEXTDOMAIN),
93
+ 'edit_item' => __('Edit Content Block', CUSTOM_POST_WIDGET_TEXTDOMAIN),
94
+ 'new_item' => __('New Content Block', CUSTOM_POST_WIDGET_TEXTDOMAIN),
95
+ 'view_item' => __('View Content Block', CUSTOM_POST_WIDGET_TEXTDOMAIN),
96
+ 'search_items' => __('Search Content Blocks', CUSTOM_POST_WIDGET_TEXTDOMAIN),
97
+ 'not_found' => __('No Content Blocks Found', CUSTOM_POST_WIDGET_TEXTDOMAIN),
98
+ 'not_found_in_trash' => __('No Content Blocks found in Trash', CUSTOM_POST_WIDGET_TEXTDOMAIN),
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_TEXTDOMAIN), esc_url( get_permalink(isset($post->ID) ? $post->ID : null) ) ),
142
+ 2 => __('Custom field updated.', CUSTOM_POST_WIDGET_TEXTDOMAIN),
143
+ 3 => __('Custom field deleted.', CUSTOM_POST_WIDGET_TEXTDOMAIN),
144
+ 4 => __('Content Block updated.', CUSTOM_POST_WIDGET_TEXTDOMAIN),
145
+ 5 => isset($_GET['revision']) ? sprintf( __('Content Block restored to revision from %s', CUSTOM_POST_WIDGET_TEXTDOMAIN), 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_TEXTDOMAIN), esc_url( get_permalink(isset($post->ID) ? $post->ID : null) ) ),
147
+ 7 => __('Block saved.', CUSTOM_POST_WIDGET_TEXTDOMAIN),
148
+ 8 => sprintf( __('Content Block submitted. <a target="_blank" href="%s">Preview Content Block</a>', CUSTOM_POST_WIDGET_TEXTDOMAIN), 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_TEXTDOMAIN), date_i18n( __( 'M j, Y @ G:i' , CUSTOM_POST_WIDGET_TEXTDOMAIN), 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_TEXTDOMAIN), 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
+ $args = array(
166
+ 'post__in' => array($id),
167
+ 'post_type' => 'content_block',
168
+ );
169
+
170
+ $content_post = get_posts($args);
171
+
172
+ foreach( $content_post as $post ) :
173
+ $content .= apply_filters('the_content', $post->post_content);
174
+ endforeach;
175
+ }
176
+
177
+ return $content;
178
+ }
179
+
180
+ add_shortcode('content_block', 'custom_post_widget_shortcode');
181
+
182
  ?>
readme.txt CHANGED
@@ -15,8 +15,8 @@ The Custom Post Widget allows you to display the contents of a specific custom p
15
 
16
  Even though you could use the text widget that comes with the default WordPress install, this plugin has some clear benefits:
17
 
18
- * If you are using widgets to display content on various areas of your template, this content can only be edited by users with administrator access. If you would like editors to modify the widget content, you can use this plugin to provide them access to the custom posts that provide the content for the widget areas.
19
- * It enables users to use the WYSIWYG editor for editing the content and adding images
20
 
21
  This plugin creates a 'content_block' custom post type. The title is never displayed, use this to describe the position of the widget on the page. Note that these content blocks can only be displayed in the context of the page. I have added 'public' => false to the custom post type which means that it is not accessible outside the page context.
22
 
@@ -97,6 +97,8 @@ now has its own icon and as requested by Stephen James the author field has been
97
  = 1.6 =
98
  The Custom Post Widget plugin is now using the more efficient get_post instead of query_posts to display the content block on the page. A code example for this change has been graciously provided by Paul de Wouters.
99
 
 
 
100
 
101
  == Upgrade Notice ==
102
 
15
 
16
  Even though you could use the text widget that comes with the default WordPress install, this plugin has some clear benefits:
17
 
18
+ * If you are using the standard WordPress text widgets to display content on various areas of your template, this content can only be edited by users with administrator access. If you would like editors to modify the widget content, you can use this plugin to provide them access to the custom posts that provide the content for the widget areas.
19
+ * The Custom Post Widget plugin enables users to use the WYSIWYG editor for editing the content and adding images.
20
 
21
  This plugin creates a 'content_block' custom post type. The title is never displayed, use this to describe the position of the widget on the page. Note that these content blocks can only be displayed in the context of the page. I have added 'public' => false to the custom post type which means that it is not accessible outside the page context.
22
 
97
  = 1.6 =
98
  The Custom Post Widget plugin is now using the more efficient get_post instead of query_posts to display the content block on the page. A code example for this change has been graciously provided by Paul de Wouters.
99
 
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