Version Description
Fix for bug caused by the 'Advanced Custom Fields' plugin. Thanks to creativexperience for troubleshooting this issue. Cleanup of lightbox popup, changed all instances of query_posts to get_post and get_posts. Support for featured image in custom post widget area.
Download this release
Release Info
Developer | vanderwijk |
Plugin | Content Blocks (Custom Post Widget) |
Version | 2.0 |
Comparing to | |
See all releases |
Code changes from version 1.9.8 to 2.0
- custom-post-widget.php +47 -47
- popup.php +47 -61
- post-widget.php +240 -240
- readme.txt +6 -1
custom-post-widget.php
CHANGED
@@ -1,48 +1,48 @@
|
|
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:
|
7 |
-
Author: Johan van der Wijk
|
8 |
-
Author URI: http://www.vanderwijk.com
|
9 |
-
License: GPL2
|
10 |
-
|
11 |
-
Release notes: Version
|
12 |
-
|
13 |
-
Copyright 2012 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 |
-
// Load the required files needed for the plugin to run in the proper order and add needed functions to the required hooks.
|
37 |
-
function custom_post_widget_plugin_init() {
|
38 |
-
// Load the translation of the plugin.
|
39 |
-
load_plugin_textdomain( 'custom-post-widget', false, 'custom-post-widget/languages' );
|
40 |
-
add_action( 'widgets_init', 'custom_post_widget_load_widgets' );
|
41 |
-
}
|
42 |
-
|
43 |
-
// Loads the widgets packaged with the plugin.
|
44 |
-
function custom_post_widget_load_widgets() {
|
45 |
-
require_once( CUSTOM_POST_WIDGET_DIR . '/post-widget.php' );
|
46 |
-
register_widget( 'custom_post_widget' );
|
47 |
-
}
|
48 |
?>
|
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: 2.0
|
7 |
+
Author: Johan van der Wijk
|
8 |
+
Author URI: http://www.vanderwijk.com
|
9 |
+
License: GPL2
|
10 |
+
|
11 |
+
Release notes: Version 2.0 Added support for featured images
|
12 |
+
|
13 |
+
Copyright 2012 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 |
+
// Load the required files needed for the plugin to run in the proper order and add needed functions to the required hooks.
|
37 |
+
function custom_post_widget_plugin_init() {
|
38 |
+
// Load the translation of the plugin.
|
39 |
+
load_plugin_textdomain( 'custom-post-widget', false, 'custom-post-widget/languages' );
|
40 |
+
add_action( 'widgets_init', 'custom_post_widget_load_widgets' );
|
41 |
+
}
|
42 |
+
|
43 |
+
// Loads the widgets packaged with the plugin.
|
44 |
+
function custom_post_widget_load_widgets() {
|
45 |
+
require_once( CUSTOM_POST_WIDGET_DIR . '/post-widget.php' );
|
46 |
+
register_widget( 'custom_post_widget' );
|
47 |
+
}
|
48 |
?>
|
popup.php
CHANGED
@@ -1,61 +1,47 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function add_content_block_popup(){ ?>
|
4 |
-
|
5 |
-
<script>
|
6 |
-
function InsertContentBlockForm(){
|
7 |
-
var content_id = jQuery("#
|
8 |
-
if(content_id == ""){
|
9 |
-
alert("<?php _e(
|
10 |
-
return;
|
11 |
-
}
|
12 |
-
var win = window.dialogArguments || opener || parent || top;
|
13 |
-
win.send_to_editor("[content_block id=" + content_id + "]");
|
14 |
-
}
|
15 |
-
</script>
|
16 |
-
|
17 |
-
<div id="
|
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 |
-
endif; ?>
|
49 |
-
</select>
|
50 |
-
<br />
|
51 |
-
<div style="padding:15px;">
|
52 |
-
<input type="button" class="button-primary" value="<?php _e("Insert Content Block", 'custom-post-widget') ?>" onclick="InsertContentBlockForm();"/>
|
53 |
-
<a class="button" style="color:#bbb;" href="#" onclick="tb_remove(); return false;">
|
54 |
-
<?php _e("Cancel", 'custom-post-widget'); ?>
|
55 |
-
</a>
|
56 |
-
</div>
|
57 |
-
</div>
|
58 |
-
</div>
|
59 |
-
</div>
|
60 |
-
</div>
|
61 |
-
<?php } ?>
|
1 |
+
<?php
|
2 |
+
// Displays the lightbox popup to insert a content block shortcode to a post/page
|
3 |
+
function add_content_block_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 |
+
var win = window.dialogArguments || opener || parent || top;
|
13 |
+
win.send_to_editor("[content_block id=" + content_id + "]");
|
14 |
+
}
|
15 |
+
</script>
|
16 |
+
|
17 |
+
<div id="content-block-form" style="display: none;">
|
18 |
+
<h3>
|
19 |
+
<?php _e( 'Insert Content Block', 'custom-post-widget' ); ?>
|
20 |
+
</h3>
|
21 |
+
<p>
|
22 |
+
<?php _e( 'Select a Content Block below to add it to your post or page.', 'custom-post-widget' ); ?>
|
23 |
+
</p>
|
24 |
+
<p>
|
25 |
+
<select id="add-content-block-id">
|
26 |
+
<option value="">
|
27 |
+
<?php _e( 'Select a Content Block', 'custom-post-widget' ); ?>
|
28 |
+
</option>
|
29 |
+
<?php
|
30 |
+
$args = array('post_type' => 'content_block', 'suppress_filters' => 0, 'numberposts' => -1, 'order' => 'ASC');
|
31 |
+
$content_block = get_posts( $args );
|
32 |
+
if ($content_block) {
|
33 |
+
foreach( $content_block as $content_block ) : setup_postdata( $content_block );
|
34 |
+
echo '<option value="' . $content_block->ID . '">' . $content_block->post_title . '</option>';
|
35 |
+
endforeach;
|
36 |
+
} else {
|
37 |
+
echo '<option value="">' . __( 'No content blocks available', 'custom-post-widget' ) . '</option>';
|
38 |
+
};
|
39 |
+
?>
|
40 |
+
</select>
|
41 |
+
</p>
|
42 |
+
<p>
|
43 |
+
<input type="button" class="button-primary" value="<?php _e( 'Insert Content Block', 'custom-post-widget' ) ?>" onclick="InsertContentBlockForm();"/>
|
44 |
+
</p>
|
45 |
+
</div>
|
46 |
+
|
47 |
+
<?php };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
post-widget.php
CHANGED
@@ -1,240 +1,240 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
// Add featured image support
|
4 |
-
if ( function_exists( 'add_theme_support' ) ) {
|
5 |
-
add_theme_support( 'post-thumbnails' );
|
6 |
-
}
|
7 |
-
|
8 |
-
// First create the widget for the admin panel
|
9 |
-
class custom_post_widget extends WP_Widget {
|
10 |
-
function custom_post_widget() {
|
11 |
-
$widget_ops = array( 'description' => __( 'Displays custom post content in a widget', 'custom-post-widget' ) );
|
12 |
-
$this->WP_Widget( 'custom_post_widget', __( 'Content Block', 'custom-post-widget' ), $widget_ops );
|
13 |
-
}
|
14 |
-
|
15 |
-
function form( $instance ) {
|
16 |
-
$custom_post_id = ''; //
|
17 |
-
if (isset($instance['custom_post_id'])) {
|
18 |
-
$custom_post_id = esc_attr($instance['custom_post_id']);
|
19 |
-
};
|
20 |
-
$show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : true;
|
21 |
-
$show_featured_image = isset( $instance['show_featured_image'] ) ? $instance['show_featured_image'] : true;
|
22 |
-
$apply_content_filters = isset( $instance['apply_content_filters'] ) ? $instance['apply_content_filters'] : true;
|
23 |
-
?>
|
24 |
-
|
25 |
-
<p>
|
26 |
-
<label for="<?php echo $this->get_field_id( 'custom_post_id' ); ?>"> <?php echo __( 'Content Block to Display:', 'custom-post-widget' ) ?>
|
27 |
-
<select class="widefat" id="<?php echo $this->get_field_id( 'custom_post_id' ); ?>" name="<?php echo $this->get_field_name( 'custom_post_id' ); ?>">
|
28 |
-
<?php
|
29 |
-
|
30 |
-
$
|
31 |
-
if(
|
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 |
-
$instance
|
74 |
-
$instance['
|
75 |
-
$instance['
|
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 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
'
|
126 |
-
|
127 |
-
|
128 |
-
'
|
129 |
-
'
|
130 |
-
'
|
131 |
-
'
|
132 |
-
'
|
133 |
-
'
|
134 |
-
'
|
135 |
-
'
|
136 |
-
'
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
)
|
151 |
-
|
152 |
-
}
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
<
|
224 |
-
|
225 |
-
|
226 |
-
// Only add content_block icon above posts and pages
|
227 |
-
function check_post_type_and_remove_media_buttons() {
|
228 |
-
global $current_screen;
|
229 |
-
if( 'content_block' != $current_screen->post_type ) add_filter('media_buttons_context', 'add_content_block_icon' );
|
230 |
-
}
|
231 |
-
add_action('admin_head','check_post_type_and_remove_media_buttons');
|
232 |
-
|
233 |
-
require_once( CUSTOM_POST_WIDGET_DIR . '/popup.php' );
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// Add featured image support
|
4 |
+
if ( function_exists( 'add_theme_support' ) ) {
|
5 |
+
add_theme_support( 'post-thumbnails' );
|
6 |
+
}
|
7 |
+
|
8 |
+
// First create the widget for the admin panel
|
9 |
+
class custom_post_widget extends WP_Widget {
|
10 |
+
function custom_post_widget() {
|
11 |
+
$widget_ops = array( 'description' => __( 'Displays custom post content in a widget', 'custom-post-widget' ) );
|
12 |
+
$this->WP_Widget( 'custom_post_widget', __( 'Content Block', 'custom-post-widget' ), $widget_ops );
|
13 |
+
}
|
14 |
+
|
15 |
+
function form( $instance ) {
|
16 |
+
$custom_post_id = ''; // Initialize the variable
|
17 |
+
if (isset($instance['custom_post_id'])) {
|
18 |
+
$custom_post_id = esc_attr($instance['custom_post_id']);
|
19 |
+
};
|
20 |
+
$show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : true;
|
21 |
+
$show_featured_image = isset( $instance['show_featured_image'] ) ? $instance['show_featured_image'] : true;
|
22 |
+
$apply_content_filters = isset( $instance['apply_content_filters'] ) ? $instance['apply_content_filters'] : true;
|
23 |
+
?>
|
24 |
+
|
25 |
+
<p>
|
26 |
+
<label for="<?php echo $this->get_field_id( 'custom_post_id' ); ?>"> <?php echo __( 'Content Block to Display:', 'custom-post-widget' ) ?>
|
27 |
+
<select class="widefat" id="<?php echo $this->get_field_id( 'custom_post_id' ); ?>" name="<?php echo $this->get_field_name( 'custom_post_id' ); ?>">
|
28 |
+
<?php
|
29 |
+
$args = array('post_type' => 'content_block', 'suppress_filters' => 0, 'numberposts' => -1, 'order' => 'ASC');
|
30 |
+
$content_block = get_posts( $args );
|
31 |
+
if ($content_block) {
|
32 |
+
foreach( $content_block as $content_block ) : setup_postdata( $content_block );
|
33 |
+
echo '<option value="' . $content_block->ID . '"';
|
34 |
+
if( $custom_post_id == $content_block->ID ) {
|
35 |
+
echo ' selected';
|
36 |
+
$widgetExtraTitle = $content_block->post_title;
|
37 |
+
};
|
38 |
+
echo '>' . $content_block->post_title . '</option>';
|
39 |
+
endforeach;
|
40 |
+
} else {
|
41 |
+
echo '<option value="">' . __( 'No content blocks available', 'custom-post-widget' ) . '</option>';
|
42 |
+
};
|
43 |
+
?>
|
44 |
+
</select>
|
45 |
+
</label>
|
46 |
+
</p>
|
47 |
+
|
48 |
+
<input type="hidden" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $widgetExtraTitle ?>" />
|
49 |
+
|
50 |
+
<p>
|
51 |
+
<?php
|
52 |
+
echo '<a href="post.php?post=' . $custom_post_id . '&action=edit">' . __( 'Edit Content Block', 'custom-post-widget' ) . '</a>' ;
|
53 |
+
?>
|
54 |
+
</p>
|
55 |
+
|
56 |
+
<p>
|
57 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) isset( $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' ); ?>" />
|
58 |
+
<label for="<?php echo $this->get_field_id( 'show_custom_post_title' ); ?>"><?php echo __( 'Show Post Title', 'custom-post-widget' ) ?></label>
|
59 |
+
</p>
|
60 |
+
|
61 |
+
<p>
|
62 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) isset( $instance['show_featured_image'] ), true ); ?> id="<?php echo $this->get_field_id( 'show_featured_image' ); ?>" name="<?php echo $this->get_field_name( 'show_featured_image' ); ?>" />
|
63 |
+
<label for="<?php echo $this->get_field_id( 'show_featured_image' ); ?>"><?php echo __( 'Show featured image', 'custom-post-widget' ) ?></label>
|
64 |
+
</p>
|
65 |
+
|
66 |
+
<p>
|
67 |
+
<input class="checkbox" type="checkbox" <?php checked( (bool) isset( $instance['apply_content_filters'] ), true ); ?> id="<?php echo $this->get_field_id( 'apply_content_filters' ); ?>" name="<?php echo $this->get_field_name( 'apply_content_filters' ); ?>" />
|
68 |
+
<label for="<?php echo $this->get_field_id( 'apply_content_filters' ); ?>"><?php echo __( 'Do not apply content filters', 'custom-post-widget' ) ?></label>
|
69 |
+
</p> <?php
|
70 |
+
}
|
71 |
+
|
72 |
+
function update( $new_instance, $old_instance ) {
|
73 |
+
$instance = $old_instance;
|
74 |
+
$instance['custom_post_id'] = strip_tags( $new_instance['custom_post_id'] );
|
75 |
+
$instance['show_custom_post_title'] = $new_instance['show_custom_post_title'];
|
76 |
+
$instance['show_featured_image'] = $new_instance['show_featured_image'];
|
77 |
+
$instance['apply_content_filters'] = $new_instance['apply_content_filters'];
|
78 |
+
return $instance;
|
79 |
+
}
|
80 |
+
|
81 |
+
function widget($args, $instance) {
|
82 |
+
extract($args);
|
83 |
+
$custom_post_id = ( $instance['custom_post_id'] != '' ) ? esc_attr($instance['custom_post_id']) : __('Find', 'custom-post-widget');
|
84 |
+
// Add support for WPML Plugin.
|
85 |
+
if ( function_exists( 'icl_object_id' ) ){
|
86 |
+
$custom_post_id = icl_object_id( $custom_post_id, 'content_block', true );
|
87 |
+
}
|
88 |
+
// Variables from the widget settings.
|
89 |
+
$show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : false;
|
90 |
+
$show_featured_image = isset($instance['show_featured_image']) ? $instance['show_featured_image'] : false;
|
91 |
+
$apply_content_filters = isset($instance['apply_content_filters']) ? $instance['apply_content_filters'] : false;
|
92 |
+
$content_post = get_post($custom_post_id);
|
93 |
+
$content = $content_post->post_content;
|
94 |
+
if ( !$apply_content_filters ) { // Don't apply the content filter if checkbox selected
|
95 |
+
$content = apply_filters('the_content', $content);
|
96 |
+
}
|
97 |
+
echo $before_widget;
|
98 |
+
if ( $show_custom_post_title ) {
|
99 |
+
echo $before_title . apply_filters('widget_title',$content_post->post_title) . $after_title; // This is the line that displays the title (only if show title is set)
|
100 |
+
}
|
101 |
+
if ( $show_featured_image ) {
|
102 |
+
echo get_the_post_thumbnail($content_post->ID);
|
103 |
+
}
|
104 |
+
echo do_shortcode($content); // This is where the actual content of the custom post is being displayed
|
105 |
+
echo $after_widget;
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
// Create the Content Block custom post type
|
110 |
+
add_action('init', 'my_content_block_post_type_init');
|
111 |
+
|
112 |
+
function my_content_block_post_type_init() {
|
113 |
+
$labels = array(
|
114 |
+
'name' => _x('Content Blocks', 'post type general name', 'custom-post-widget'),
|
115 |
+
'singular_name' => _x('Content Block', 'post type singular name', 'custom-post-widget'),
|
116 |
+
'plural_name' => _x('Content Blocks', 'post type plural name', 'custom-post-widget'),
|
117 |
+
'add_new' => _x('Add Content Block', 'block', 'custom-post-widget'),
|
118 |
+
'add_new_item' => __('Add New Content Block', 'custom-post-widget'),
|
119 |
+
'edit_item' => __('Edit Content Block', 'custom-post-widget'),
|
120 |
+
'new_item' => __('New Content Block', 'custom-post-widget'),
|
121 |
+
'view_item' => __('View Content Block', 'custom-post-widget'),
|
122 |
+
'search_items' => __('Search Content Blocks', 'custom-post-widget'),
|
123 |
+
'not_found' => __('No Content Blocks Found', 'custom-post-widget'),
|
124 |
+
'not_found_in_trash' => __('No Content Blocks found in Trash', 'custom-post-widget'),
|
125 |
+
'parent_item_colon' => ''
|
126 |
+
);
|
127 |
+
$options = array(
|
128 |
+
'labels' => $labels,
|
129 |
+
'public' => false,
|
130 |
+
'publicly_queryable' => false,
|
131 |
+
'exclude_from_search' => true,
|
132 |
+
'show_ui' => true,
|
133 |
+
'query_var' => true,
|
134 |
+
'rewrite' => true,
|
135 |
+
'capability_type' => 'post',
|
136 |
+
'hierarchical' => false,
|
137 |
+
'menu_position' => null,
|
138 |
+
'supports' => array('title','editor','revisions','thumbnail','author')
|
139 |
+
);
|
140 |
+
register_post_type('content_block',$options);
|
141 |
+
}
|
142 |
+
|
143 |
+
// Add custom styles to admin screen and menu
|
144 |
+
add_action('admin_head', 'content_block_header');
|
145 |
+
|
146 |
+
function content_block_header() {
|
147 |
+
global $post_type; ?>
|
148 |
+
<style type="text/css">
|
149 |
+
<!--
|
150 |
+
<?php if (($post_type == 'content_block')) : ?>
|
151 |
+
#icon-edit { background:transparent url('<?php echo CUSTOM_POST_WIDGET_URL; ?>images/contentblock-32.png') no-repeat 0 0 !important;}
|
152 |
+
#minor-publishing-actions { display:none; /* Hide the Save Draft and Preview buttons */}
|
153 |
+
<?php endif; ?>
|
154 |
+
#adminmenu #menu-posts-content_block div.wp-menu-image{background:transparent url('<?php echo CUSTOM_POST_WIDGET_URL;?>images/contentblock.png') no-repeat center -32px;}
|
155 |
+
#adminmenu #menu-posts-content_block:hover div.wp-menu-image,#adminmenu #menu-posts-content_block.wp-has-current-submenu div.wp-menu-image{background:transparent url('<?php echo CUSTOM_POST_WIDGET_URL;?>images/contentblock.png') no-repeat center 0px;}
|
156 |
+
-->
|
157 |
+
</style>
|
158 |
+
<?php
|
159 |
+
}
|
160 |
+
|
161 |
+
add_filter('post_updated_messages', 'content_block_messages');
|
162 |
+
|
163 |
+
function content_block_messages( $messages ) {
|
164 |
+
$messages['content_block'] = array(
|
165 |
+
0 => '',
|
166 |
+
1 => current_user_can( 'edit_theme_options' ) ? sprintf( __('Content Block updated. <a href="%s">Manage Widgets</a>', 'custom-post-widget'), esc_url( 'widgets.php' ) ) : sprintf( __('Content Block updated.', 'custom-post-widget'), esc_url( 'widgets.php' ) ),
|
167 |
+
2 => __('Custom field updated.', 'custom-post-widget'),
|
168 |
+
3 => __('Custom field deleted.', 'custom-post-widget'),
|
169 |
+
4 => __('Content Block updated.', 'custom-post-widget'),
|
170 |
+
5 => isset($_GET['revision']) ? sprintf( __('Content Block restored to revision from %s', 'custom-post-widget'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
|
171 |
+
6 => current_user_can( 'edit_theme_options' ) ? sprintf( __('Content Block published. <a href="%s">Manage Widgets</a>', 'custom-post-widget'), esc_url( 'widgets.php' ) ) : sprintf( __('Content Block published.', 'custom-post-widget'), esc_url( 'widgets.php' ) ),
|
172 |
+
7 => __('Block saved.', 'custom-post-widget'),
|
173 |
+
8 => current_user_can( 'edit_theme_options' ) ? sprintf( __('Content Block submitted. <a href="%s">Manage Widgets</a>', 'custom-post-widget'), esc_url( 'widgets.php' ) ) : sprintf( __('Content Block submitted.', 'custom-post-widget'), esc_url( 'widgets.php' ) ),
|
174 |
+
9 => sprintf( __('Content Block scheduled for: <strong>%1$s</strong>.', 'custom-post-widget'), date_i18n( __( 'M j, Y @ G:i' , 'custom-post-widget'), strtotime(isset($post->post_date) ? $post->post_date : null) ), esc_url( 'widgets.php' ) ),
|
175 |
+
10 => current_user_can( 'edit_theme_options' ) ? sprintf( __('Content Block draft updated. <a href="%s">Manage Widgets</a>', 'custom-post-widget'), esc_url( 'widgets.php' ) ) : sprintf( __('Content Block draft updated.', 'custom-post-widget'), esc_url( 'widgets.php' ) ),
|
176 |
+
);
|
177 |
+
return $messages;
|
178 |
+
}
|
179 |
+
|
180 |
+
// Add the ability to display the content block in a reqular post using a shortcode
|
181 |
+
function custom_post_widget_shortcode($atts) {
|
182 |
+
extract(shortcode_atts(array(
|
183 |
+
'id' => '',
|
184 |
+
'class' => 'content_block'
|
185 |
+
), $atts));
|
186 |
+
|
187 |
+
$content = "";
|
188 |
+
|
189 |
+
if($id != "") {
|
190 |
+
$args = array(
|
191 |
+
'post__in' => array($id),
|
192 |
+
'post_type' => 'content_block',
|
193 |
+
);
|
194 |
+
|
195 |
+
$content_post = get_posts($args);
|
196 |
+
|
197 |
+
foreach( $content_post as $post ) :
|
198 |
+
$content .= '<div class="'. esc_attr($class) .'">';
|
199 |
+
$content .= apply_filters('the_content', $post->post_content);
|
200 |
+
$content .= '</div>';
|
201 |
+
endforeach;
|
202 |
+
}
|
203 |
+
|
204 |
+
return $content;
|
205 |
+
}
|
206 |
+
add_shortcode('content_block', 'custom_post_widget_shortcode');
|
207 |
+
|
208 |
+
// Add button above editor if not editing content_block
|
209 |
+
function add_content_block_icon() {
|
210 |
+
echo '<style>
|
211 |
+
#add-content-block .wp-media-buttons-icon {
|
212 |
+
background: url(../../wp-content/plugins/custom-post-widget/images/contentblock.png) no-repeat -7px -40px;
|
213 |
+
margin-right: 3px;
|
214 |
+
}
|
215 |
+
#add-content-block:hover .wp-media-buttons-icon {
|
216 |
+
background: url(../../wp-content/plugins/custom-post-widget/images/contentblock.png) no-repeat -7px -8px;
|
217 |
+
}
|
218 |
+
#add-content-block {
|
219 |
+
padding-left: 0.4em;
|
220 |
+
}
|
221 |
+
</style>
|
222 |
+
<a id="add-content-block" class="button thickbox" title="' . __("Add Content Block", 'custom-post-widget') . '" href="' . CUSTOM_POST_WIDGET_URL . 'popup.php?type=add_content_block_popup&TB_inline=true&inlineId=content-block-form">
|
223 |
+
<span class="wp-media-buttons-icon"></span>' . __("Add Content Block", "custom-post-widget") . '</a>';
|
224 |
+
}
|
225 |
+
|
226 |
+
// Only add content_block icon above posts and pages
|
227 |
+
function check_post_type_and_remove_media_buttons() {
|
228 |
+
global $current_screen;
|
229 |
+
if( 'content_block' != $current_screen->post_type ) add_filter('media_buttons_context', 'add_content_block_icon' );
|
230 |
+
}
|
231 |
+
add_action('admin_head','check_post_type_and_remove_media_buttons');
|
232 |
+
|
233 |
+
require_once( CUSTOM_POST_WIDGET_DIR . '/popup.php' );
|
234 |
+
|
235 |
+
// Only add content block popup action on page and post edit
|
236 |
+
if(!defined( 'CUSTOM_POST_WIDGET_CURRENT_PAGE' ))
|
237 |
+
define( 'CUSTOM_POST_WIDGET_CURRENT_PAGE', basename($_SERVER['PHP_SELF']) );
|
238 |
+
if(in_array(CUSTOM_POST_WIDGET_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php'))) {
|
239 |
+
add_action('admin_footer', 'add_content_block_popup');
|
240 |
+
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Author URI: http://www.vanderwijk.com/
|
|
4 |
Donate link: http://www.vanderwijk.com/wordpress/support/
|
5 |
Tags: custom-post, widget, sidebar, content block, content, block, custom, post, shortcode
|
6 |
Requires at least: 2.9.2
|
7 |
-
Tested up to: 3.
|
8 |
Stable tag: 1.9.5
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -79,6 +79,11 @@ If your social media sharing plugin adds buttons to the widget areas you could c
|
|
79 |
|
80 |
== Changelog ==
|
81 |
|
|
|
|
|
|
|
|
|
|
|
82 |
= 1.9.8 =
|
83 |
Fix for error when using shortcode with the WPML plugin
|
84 |
|
4 |
Donate link: http://www.vanderwijk.com/wordpress/support/
|
5 |
Tags: custom-post, widget, sidebar, content block, content, block, custom, post, shortcode
|
6 |
Requires at least: 2.9.2
|
7 |
+
Tested up to: 3.5
|
8 |
Stable tag: 1.9.5
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
79 |
|
80 |
== Changelog ==
|
81 |
|
82 |
+
= 2.0 =
|
83 |
+
Fix for bug caused by the 'Advanced Custom Fields' plugin. Thanks to creativexperience for troubleshooting this issue.
|
84 |
+
Cleanup of lightbox popup, changed all instances of query_posts to get_post and get_posts.
|
85 |
+
Support for featured image in custom post widget area.
|
86 |
+
|
87 |
= 1.9.8 =
|
88 |
Fix for error when using shortcode with the WPML plugin
|
89 |
|