Version Description
Thanks to Bruce from Ingeni Web Solutions it is now possible to use your own template for embedding the custom post shortcode.
Download this release
Release Info
Developer | vanderwijk |
Plugin | Content Blocks (Custom Post Widget) |
Version | 3.2 |
Comparing to | |
See all releases |
Code changes from version 3.1.6 to 3.2
- custom-post-widget.php +26 -9
- meta-box.php +1 -1
- popup.php +1 -1
- post-type.php +53 -0
- post-widget.php +0 -230
- readme.txt +7 -2
- shortcode.php +82 -0
- widget.php +114 -0
custom-post-widget.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Content Blocks (Custom Post Widget)
|
4 |
Plugin URI: http://www.vanderwijk.com/wordpress/wordpress-custom-post-widget/?utm_source=wordpress&utm_medium=plugin&utm_campaign=custom_post_widget
|
5 |
Description: Show the content of a custom post of the type 'content_block' in a widget or with a shortcode.
|
6 |
-
Version: 3.
|
7 |
Author: Johan van der Wijk
|
8 |
Author URI: https://vanderwijk.nl
|
9 |
Donate link: https://www.paypal.me/vanderwijk
|
@@ -11,7 +11,7 @@
|
|
11 |
Domain Path: /languages
|
12 |
License: GPL2
|
13 |
|
14 |
-
Release notes:
|
15 |
|
16 |
Copyright 2021 Johan van der Wijk
|
17 |
|
@@ -29,22 +29,29 @@
|
|
29 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
30 |
*/
|
31 |
|
32 |
-
// Launch the plugin
|
33 |
function custom_post_widget_plugin_init() {
|
34 |
add_action( 'widgets_init', 'custom_post_widget_load_widgets' );
|
35 |
}
|
36 |
add_action( 'plugins_loaded', 'custom_post_widget_plugin_init' );
|
37 |
|
38 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
function custom_post_widget_load_textdomain() {
|
40 |
load_plugin_textdomain( 'custom-post-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
41 |
}
|
42 |
add_action( 'plugins_loaded', 'custom_post_widget_load_textdomain' );
|
43 |
|
44 |
-
//
|
45 |
-
|
46 |
-
|
47 |
-
register_widget( 'custom_post_widget' );
|
48 |
}
|
49 |
|
50 |
// Admin-only functions
|
@@ -77,4 +84,14 @@ if ( is_admin() ) {
|
|
77 |
}
|
78 |
add_action( 'admin_enqueue_scripts', 'cpw_enqueue' );
|
79 |
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
Plugin Name: Content Blocks (Custom Post Widget)
|
4 |
Plugin URI: http://www.vanderwijk.com/wordpress/wordpress-custom-post-widget/?utm_source=wordpress&utm_medium=plugin&utm_campaign=custom_post_widget
|
5 |
Description: Show the content of a custom post of the type 'content_block' in a widget or with a shortcode.
|
6 |
+
Version: 3.2
|
7 |
Author: Johan van der Wijk
|
8 |
Author URI: https://vanderwijk.nl
|
9 |
Donate link: https://www.paypal.me/vanderwijk
|
11 |
Domain Path: /languages
|
12 |
License: GPL2
|
13 |
|
14 |
+
Release notes: You can now use your own templates for outputting the shortcode contents
|
15 |
|
16 |
Copyright 2021 Johan van der Wijk
|
17 |
|
29 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
30 |
*/
|
31 |
|
32 |
+
// Launch the plugin
|
33 |
function custom_post_widget_plugin_init() {
|
34 |
add_action( 'widgets_init', 'custom_post_widget_load_widgets' );
|
35 |
}
|
36 |
add_action( 'plugins_loaded', 'custom_post_widget_plugin_init' );
|
37 |
|
38 |
+
// Loads the widgets packaged with the plugin
|
39 |
+
function custom_post_widget_load_widgets() {
|
40 |
+
require_once( 'post-type.php' );
|
41 |
+
require_once( 'shortcode.php' );
|
42 |
+
require_once( 'widget.php' );
|
43 |
+
register_widget( 'custom_post_widget' );
|
44 |
+
}
|
45 |
+
|
46 |
+
// Load plugin textdomain
|
47 |
function custom_post_widget_load_textdomain() {
|
48 |
load_plugin_textdomain( 'custom-post-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
49 |
}
|
50 |
add_action( 'plugins_loaded', 'custom_post_widget_load_textdomain' );
|
51 |
|
52 |
+
// Add featured image support
|
53 |
+
if ( function_exists( 'add_theme_support' ) ) {
|
54 |
+
add_theme_support( 'post-thumbnails' );
|
|
|
55 |
}
|
56 |
|
57 |
// Admin-only functions
|
84 |
}
|
85 |
add_action( 'admin_enqueue_scripts', 'cpw_enqueue' );
|
86 |
|
87 |
+
// Only add content_block icon above posts and pages
|
88 |
+
function cpw_add_content_block_button() {
|
89 |
+
global $current_screen;
|
90 |
+
if ( ( 'content_block' != $current_screen -> post_type ) && ( 'toplevel_page_revslider' != $current_screen -> id ) ) {
|
91 |
+
add_action( 'media_buttons', 'add_content_block_icon' );
|
92 |
+
add_action( 'admin_footer', 'add_content_block_popup' );
|
93 |
+
}
|
94 |
+
}
|
95 |
+
add_action( 'admin_head', 'cpw_add_content_block_button' );
|
96 |
+
|
97 |
+
}
|
meta-box.php
CHANGED
@@ -73,4 +73,4 @@ function cpw_modify_post_table_row( $column_name, $post_id ) {
|
|
73 |
break;
|
74 |
}
|
75 |
}
|
76 |
-
add_action( 'manage_posts_custom_column', 'cpw_modify_post_table_row', 10, 2 );
|
73 |
break;
|
74 |
}
|
75 |
}
|
76 |
+
add_action( 'manage_posts_custom_column', 'cpw_modify_post_table_row', 10, 2 );
|
popup.php
CHANGED
@@ -65,4 +65,4 @@ function add_content_block_popup() { ?>
|
|
65 |
</p>
|
66 |
</div>
|
67 |
|
68 |
-
<?php }
|
65 |
</p>
|
66 |
</div>
|
67 |
|
68 |
+
<?php }
|
post-type.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// Create the Content Block custom post type
|
4 |
+
function cpw_post_type_init() {
|
5 |
+
$labels = array(
|
6 |
+
'name' => _x( 'Content Blocks', 'post type general name', 'custom-post-widget' ),
|
7 |
+
'singular_name' => _x( 'Content Block', 'post type singular name', 'custom-post-widget' ),
|
8 |
+
'plural_name' => _x( 'Content Blocks', 'post type plural name', 'custom-post-widget' ),
|
9 |
+
'add_new' => _x( 'Add Content Block', 'block', 'custom-post-widget' ),
|
10 |
+
'add_new_item' => __( 'Add New Content Block', 'custom-post-widget' ),
|
11 |
+
'edit_item' => __( 'Edit Content Block', 'custom-post-widget' ),
|
12 |
+
'new_item' => __( 'New Content Block', 'custom-post-widget' ),
|
13 |
+
'view_item' => __( 'View Content Block', 'custom-post-widget' ),
|
14 |
+
'search_items' => __( 'Search Content Blocks', 'custom-post-widget' ),
|
15 |
+
'not_found' => __( 'No Content Blocks Found', 'custom-post-widget' ),
|
16 |
+
'not_found_in_trash' => __( 'No Content Blocks found in Trash', 'custom-post-widget' )
|
17 |
+
);
|
18 |
+
$content_block_public = false; // added to make this a filterable option
|
19 |
+
$options = array(
|
20 |
+
'labels' => $labels,
|
21 |
+
'public' => apply_filters( 'content_block_post_type', $content_block_public ),
|
22 |
+
'publicly_queryable' => false,
|
23 |
+
'exclude_from_search' => true,
|
24 |
+
'show_ui' => true,
|
25 |
+
'query_var' => true,
|
26 |
+
'rewrite' => true,
|
27 |
+
'capability_type' => 'post',
|
28 |
+
'show_in_rest' => true,
|
29 |
+
'hierarchical' => false,
|
30 |
+
'menu_icon' => 'dashicons-screenoptions',
|
31 |
+
'supports' => array( 'title','editor','revisions','thumbnail','author' )
|
32 |
+
);
|
33 |
+
register_post_type( 'content_block',$options );
|
34 |
+
}
|
35 |
+
add_action( 'init', 'cpw_post_type_init' );
|
36 |
+
|
37 |
+
function content_block_messages( $messages ) {
|
38 |
+
$messages['content_block'] = array(
|
39 |
+
0 => '',
|
40 |
+
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' ) ),
|
41 |
+
2 => __( 'Custom field updated.', 'custom-post-widget' ),
|
42 |
+
3 => __( 'Custom field deleted.', 'custom-post-widget' ),
|
43 |
+
4 => __( 'Content Block updated.', 'custom-post-widget' ),
|
44 |
+
5 => isset($_GET['revision']) ? sprintf( __( 'Content Block restored to revision from %s', 'custom-post-widget' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
|
45 |
+
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' ) ),
|
46 |
+
7 => __( 'Block saved.', 'custom-post-widget' ),
|
47 |
+
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' ) ),
|
48 |
+
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' ) ),
|
49 |
+
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' ) ),
|
50 |
+
);
|
51 |
+
return $messages;
|
52 |
+
}
|
53 |
+
add_filter( 'post_updated_messages', 'content_block_messages' );
|
post-widget.php
DELETED
@@ -1,230 +0,0 @@
|
|
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 __construct() {
|
11 |
-
$widget_ops = array( 'classname' => 'widget_custom_post_widget', 'description' => __( 'Displays custom post content in a widget', 'custom-post-widget' ) );
|
12 |
-
parent::__construct( '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 if ( !empty( $widgetExtraTitle ) ) { 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 |
-
// Display the content block content in the widget area
|
82 |
-
function widget($args, $instance) {
|
83 |
-
extract($args);
|
84 |
-
$custom_post_id = ( $instance['custom_post_id'] != '' ) ? esc_attr($instance['custom_post_id']) : __( 'Find', 'custom-post-widget' );
|
85 |
-
// Add support for WPML Plugin.
|
86 |
-
if ( function_exists( 'icl_object_id' ) ){
|
87 |
-
$custom_post_id = icl_object_id( $custom_post_id, 'content_block', true );
|
88 |
-
}
|
89 |
-
// Variables from the widget settings.
|
90 |
-
$show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : false;
|
91 |
-
$show_featured_image = isset($instance['show_featured_image']) ? $instance['show_featured_image'] : false;
|
92 |
-
$apply_content_filters = isset($instance['apply_content_filters']) ? $instance['apply_content_filters'] : false;
|
93 |
-
$content_post = get_post( $custom_post_id );
|
94 |
-
$post_status = get_post_status( $custom_post_id );
|
95 |
-
$content = $content_post->post_content;
|
96 |
-
if ( $post_status == 'publish' ) {
|
97 |
-
// Display custom widget frontend
|
98 |
-
if ( $located = locate_template( 'custom-post-widget.php' ) ) {
|
99 |
-
require $located;
|
100 |
-
return;
|
101 |
-
}
|
102 |
-
if ( !$apply_content_filters ) { // Don't apply the content filter if checkbox selected
|
103 |
-
$content = apply_filters( 'the_content', $content);
|
104 |
-
}
|
105 |
-
echo $before_widget;
|
106 |
-
if ( $show_custom_post_title ) {
|
107 |
-
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)
|
108 |
-
}
|
109 |
-
if ( $show_featured_image ) {
|
110 |
-
echo get_the_post_thumbnail( $content_post -> ID );
|
111 |
-
}
|
112 |
-
echo do_shortcode( $content ); // This is where the actual content of the custom post is being displayed
|
113 |
-
echo $after_widget;
|
114 |
-
}
|
115 |
-
}
|
116 |
-
}
|
117 |
-
|
118 |
-
// Create the Content Block custom post type
|
119 |
-
function cpw_post_type_init() {
|
120 |
-
$labels = array(
|
121 |
-
'name' => _x( 'Content Blocks', 'post type general name', 'custom-post-widget' ),
|
122 |
-
'singular_name' => _x( 'Content Block', 'post type singular name', 'custom-post-widget' ),
|
123 |
-
'plural_name' => _x( 'Content Blocks', 'post type plural name', 'custom-post-widget' ),
|
124 |
-
'add_new' => _x( 'Add Content Block', 'block', 'custom-post-widget' ),
|
125 |
-
'add_new_item' => __( 'Add New Content Block', 'custom-post-widget' ),
|
126 |
-
'edit_item' => __( 'Edit Content Block', 'custom-post-widget' ),
|
127 |
-
'new_item' => __( 'New Content Block', 'custom-post-widget' ),
|
128 |
-
'view_item' => __( 'View Content Block', 'custom-post-widget' ),
|
129 |
-
'search_items' => __( 'Search Content Blocks', 'custom-post-widget' ),
|
130 |
-
'not_found' => __( 'No Content Blocks Found', 'custom-post-widget' ),
|
131 |
-
'not_found_in_trash' => __( 'No Content Blocks found in Trash', 'custom-post-widget' )
|
132 |
-
);
|
133 |
-
$content_block_public = false; // added to make this a filterable option
|
134 |
-
$options = array(
|
135 |
-
'labels' => $labels,
|
136 |
-
'public' => apply_filters( 'content_block_post_type', $content_block_public ),
|
137 |
-
'publicly_queryable' => false,
|
138 |
-
'exclude_from_search' => true,
|
139 |
-
'show_ui' => true,
|
140 |
-
'query_var' => true,
|
141 |
-
'rewrite' => true,
|
142 |
-
'capability_type' => 'post',
|
143 |
-
'show_in_rest' => true,
|
144 |
-
'hierarchical' => false,
|
145 |
-
'menu_icon' => 'dashicons-screenoptions',
|
146 |
-
'supports' => array( 'title','editor','revisions','thumbnail','author' )
|
147 |
-
);
|
148 |
-
register_post_type( 'content_block',$options );
|
149 |
-
}
|
150 |
-
add_action( 'init', 'cpw_post_type_init' );
|
151 |
-
|
152 |
-
function content_block_messages( $messages ) {
|
153 |
-
$messages['content_block'] = array(
|
154 |
-
0 => '',
|
155 |
-
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' ) ),
|
156 |
-
2 => __( 'Custom field updated.', 'custom-post-widget' ),
|
157 |
-
3 => __( 'Custom field deleted.', 'custom-post-widget' ),
|
158 |
-
4 => __( 'Content Block updated.', 'custom-post-widget' ),
|
159 |
-
5 => isset($_GET['revision']) ? sprintf( __( 'Content Block restored to revision from %s', 'custom-post-widget' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
|
160 |
-
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' ) ),
|
161 |
-
7 => __( 'Block saved.', 'custom-post-widget' ),
|
162 |
-
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' ) ),
|
163 |
-
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' ) ),
|
164 |
-
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' ) ),
|
165 |
-
);
|
166 |
-
return $messages;
|
167 |
-
}
|
168 |
-
add_filter( 'post_updated_messages', 'content_block_messages' );
|
169 |
-
|
170 |
-
// Add the ability to display the content block in a reqular post using a shortcode
|
171 |
-
function custom_post_widget_shortcode( $atts ) {
|
172 |
-
extract( shortcode_atts( array(
|
173 |
-
'id' => '',
|
174 |
-
'slug' => '',
|
175 |
-
'class' => 'content_block',
|
176 |
-
'suppress_content_filters' => 'no',
|
177 |
-
'featured_image' => 'no',
|
178 |
-
'featured_image_size' => 'medium',
|
179 |
-
'title' => 'no',
|
180 |
-
'title_tag' => 'h3',
|
181 |
-
'markup' => 'div'
|
182 |
-
), $atts ) );
|
183 |
-
|
184 |
-
if ( $slug ) {
|
185 |
-
$block = get_page_by_path( $slug, OBJECT, 'content_block' );
|
186 |
-
if ( $block ) {
|
187 |
-
$id = $block->ID;
|
188 |
-
}
|
189 |
-
}
|
190 |
-
|
191 |
-
$content = "";
|
192 |
-
|
193 |
-
if( $id != "" ) {
|
194 |
-
$args = array(
|
195 |
-
'post__in' => array( $id ),
|
196 |
-
'post_type' => 'content_block',
|
197 |
-
);
|
198 |
-
|
199 |
-
$content_post = get_posts( $args );
|
200 |
-
|
201 |
-
foreach( $content_post as $post ) :
|
202 |
-
$content .= '<' . esc_attr( $markup ) . ' class="'. esc_attr( $class ) .'" id="custom_post_widget-' . $id . '">';
|
203 |
-
if ( $title === 'yes' ) {
|
204 |
-
$content .= '<' . esc_attr( $title_tag ) . '>' . $post -> post_title . '</' . esc_attr( $title_tag ) . '>';
|
205 |
-
}
|
206 |
-
if ( $featured_image === 'yes' ) {
|
207 |
-
$content .= get_the_post_thumbnail( $post -> ID, $featured_image_size );
|
208 |
-
}
|
209 |
-
if ( $suppress_content_filters === 'no' ) {
|
210 |
-
$content .= apply_filters( 'the_content', $post -> post_content );
|
211 |
-
} else {
|
212 |
-
$content .= $post -> post_content;
|
213 |
-
}
|
214 |
-
$content .= '</' . esc_attr( $markup ) . '>';
|
215 |
-
endforeach;
|
216 |
-
}
|
217 |
-
|
218 |
-
return $content;
|
219 |
-
}
|
220 |
-
add_shortcode( 'content_block', 'custom_post_widget_shortcode' );
|
221 |
-
|
222 |
-
// Only add content_block icon above posts and pages
|
223 |
-
function cpw_add_content_block_button() {
|
224 |
-
global $current_screen;
|
225 |
-
if ( ( 'content_block' != $current_screen -> post_type ) && ( 'toplevel_page_revslider' != $current_screen -> id ) ) {
|
226 |
-
add_action( 'media_buttons', 'add_content_block_icon' );
|
227 |
-
add_action( 'admin_footer', 'add_content_block_popup' );
|
228 |
-
}
|
229 |
-
}
|
230 |
-
add_action( 'admin_head', 'cpw_add_content_block_button' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: vanderwijk
|
|
3 |
Tags: widget, sidebar, content block, block, custom, post, shortcode, wysiwyg, wpml, featured image
|
4 |
Requires at least: 4.0
|
5 |
Tested up to: 5.7
|
6 |
-
Stable tag: 3.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -31,7 +31,7 @@ To add content to a widget, drag it to the required position in the sidebar and
|
|
31 |
* Spanish (es_ES) by [IBIDEM GROUP](https://www.ibidemgroup.com)
|
32 |
* Portuguese (pt_BR) by [Ronaldo Chevalier](http://www.hostmeta.com.br/)
|
33 |
* Polish (pl_PL) by [Kuba Skublicki](https://www.linkedin.com/in/kubecki)
|
34 |
-
* Dutch (nl_NL) by [Johan van der Wijk](
|
35 |
* Czech (cs_CZ) by [Martin Kucera](http://jsemweb.cz/)
|
36 |
|
37 |
[More translations are very welcome!](https://translate.wordpress.org/projects/wp-plugins/custom-post-widget)
|
@@ -81,6 +81,8 @@ Currently the shortcode function only outputs the post content and title of the
|
|
81 |
|
82 |
Yes, you can create your own template for the content blocks, you can do so by adding a file named custom-post-widget.php to your theme folder. More information about this can be found in this [support topic](https://wordpress.org/support/topic/patch-custom-widget-frontends/?replies=1)
|
83 |
|
|
|
|
|
84 |
= I have a feature request =
|
85 |
|
86 |
Please post your feature request on [the support forum](https://wordpress.org/support/plugin/custom-post-widget)
|
@@ -131,6 +133,9 @@ Creating and supporting this plugin takes up a lot of my free time, therefore I
|
|
131 |
|
132 |
== Changelog ==
|
133 |
|
|
|
|
|
|
|
134 |
= 3.1.6 =
|
135 |
Compatibility testing. Also tested on PHP8 and found no issues.
|
136 |
|
3 |
Tags: widget, sidebar, content block, block, custom, post, shortcode, wysiwyg, wpml, featured image
|
4 |
Requires at least: 4.0
|
5 |
Tested up to: 5.7
|
6 |
+
Stable tag: 3.2
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
31 |
* Spanish (es_ES) by [IBIDEM GROUP](https://www.ibidemgroup.com)
|
32 |
* Portuguese (pt_BR) by [Ronaldo Chevalier](http://www.hostmeta.com.br/)
|
33 |
* Polish (pl_PL) by [Kuba Skublicki](https://www.linkedin.com/in/kubecki)
|
34 |
+
* Dutch (nl_NL) by [Johan van der Wijk](https://vanderwijk.nl)
|
35 |
* Czech (cs_CZ) by [Martin Kucera](http://jsemweb.cz/)
|
36 |
|
37 |
[More translations are very welcome!](https://translate.wordpress.org/projects/wp-plugins/custom-post-widget)
|
81 |
|
82 |
Yes, you can create your own template for the content blocks, you can do so by adding a file named custom-post-widget.php to your theme folder. More information about this can be found in this [support topic](https://wordpress.org/support/topic/patch-custom-widget-frontends/?replies=1)
|
83 |
|
84 |
+
In these Gists you can find examples of templates for [shortcodes](https://gist.github.com/vanderwijk/18acd549b099253eb222daf7757f1689) and for [widgets](https://gist.github.com/vanderwijk/a396171845cf923c23d09dddb4269fb1)
|
85 |
+
|
86 |
= I have a feature request =
|
87 |
|
88 |
Please post your feature request on [the support forum](https://wordpress.org/support/plugin/custom-post-widget)
|
133 |
|
134 |
== Changelog ==
|
135 |
|
136 |
+
= 3.2 =
|
137 |
+
Thanks to Bruce from [Ingeni Web Solutions](https://ingeni.net/) it is now possible to use your own template for embedding the custom post shortcode.
|
138 |
+
|
139 |
= 3.1.6 =
|
140 |
Compatibility testing. Also tested on PHP8 and found no issues.
|
141 |
|
shortcode.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// Add the ability to display the content block in a reqular post using a shortcode
|
4 |
+
function custom_post_widget_shortcode( $atts ) {
|
5 |
+
$params = shortcode_atts( array(
|
6 |
+
'id' => '',
|
7 |
+
'slug' => '',
|
8 |
+
'class' => 'content_block',
|
9 |
+
'suppress_content_filters' => 'no',
|
10 |
+
'featured_image' => 'no',
|
11 |
+
'featured_image_size' => 'medium',
|
12 |
+
'title' => 'no',
|
13 |
+
'title_tag' => 'h3',
|
14 |
+
'markup' => 'div',
|
15 |
+
'template' => ''
|
16 |
+
), $atts );
|
17 |
+
|
18 |
+
$id = $params['id'];
|
19 |
+
$slug = $params['slug'];
|
20 |
+
$class = $params['class'];
|
21 |
+
$suppress_content_filters = $params['suppress_content_filters'];
|
22 |
+
$featured_image = $params['featured_image'];
|
23 |
+
$featured_image_size = $params['featured_image_size'];
|
24 |
+
$title = $params['title'];
|
25 |
+
$title_tag = $params['title_tag'];
|
26 |
+
$markup = $params['markup'];
|
27 |
+
$template = $params['template'];
|
28 |
+
|
29 |
+
if ( $slug ) {
|
30 |
+
$block = get_page_by_path( $slug, OBJECT, 'content_block' );
|
31 |
+
if ( $block ) {
|
32 |
+
$id = $block->ID;
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
$content = "";
|
37 |
+
|
38 |
+
// Attempt to load a template file
|
39 |
+
if ( $params['template'] != '' ) {
|
40 |
+
if ( $located = locate_template( $params['template'] ) ) {
|
41 |
+
include_once $located;
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
if ( $id != "" ) {
|
46 |
+
|
47 |
+
$args = array(
|
48 |
+
'post__in' => array( $id ),
|
49 |
+
'post_type' => 'content_block',
|
50 |
+
);
|
51 |
+
|
52 |
+
$content_post = get_posts( $args );
|
53 |
+
|
54 |
+
foreach( $content_post as $post ) :
|
55 |
+
|
56 |
+
if ( ( $located ) ) {
|
57 |
+
// Template-based content
|
58 |
+
$content .= call_user_func( 'shortcode_template', $post );
|
59 |
+
|
60 |
+
} else {
|
61 |
+
// Standard format content
|
62 |
+
$content .= '<' . esc_attr( $markup ) . ' class="'. esc_attr( $class ) .'" id="custom_post_widget-' . $id . '">';
|
63 |
+
if ( $title === 'yes' ) {
|
64 |
+
$content .= '<' . esc_attr( $title_tag ) . '>' . $post -> post_title . '</' . esc_attr( $title_tag ) . '>';
|
65 |
+
}
|
66 |
+
if ( $featured_image === 'yes' ) {
|
67 |
+
$content .= get_the_post_thumbnail( $post -> ID, $featured_image_size );
|
68 |
+
}
|
69 |
+
if ( $suppress_content_filters === 'no' ) {
|
70 |
+
$content .= apply_filters( 'the_content', $post -> post_content );
|
71 |
+
} else {
|
72 |
+
$content .= $post -> post_content;
|
73 |
+
}
|
74 |
+
$content .= '</' . esc_attr( $markup ) . '>';
|
75 |
+
}
|
76 |
+
endforeach;
|
77 |
+
|
78 |
+
}
|
79 |
+
|
80 |
+
return $content;
|
81 |
+
}
|
82 |
+
add_shortcode( 'content_block', 'custom_post_widget_shortcode' );
|
widget.php
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// First create the widget for the admin panel
|
4 |
+
class custom_post_widget extends WP_Widget {
|
5 |
+
function __construct() {
|
6 |
+
$widget_ops = array( 'classname' => 'widget_custom_post_widget', 'description' => __( 'Displays custom post content in a widget', 'custom-post-widget' ) );
|
7 |
+
parent::__construct( 'custom_post_widget', __( 'Content Block', 'custom-post-widget' ), $widget_ops );
|
8 |
+
}
|
9 |
+
|
10 |
+
function form( $instance ) {
|
11 |
+
$custom_post_id = ''; // Initialize the variable
|
12 |
+
if (isset($instance['custom_post_id'])) {
|
13 |
+
$custom_post_id = esc_attr($instance['custom_post_id']);
|
14 |
+
};
|
15 |
+
$show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : true;
|
16 |
+
$show_featured_image = isset( $instance['show_featured_image'] ) ? $instance['show_featured_image'] : true;
|
17 |
+
$apply_content_filters = isset( $instance['apply_content_filters'] ) ? $instance['apply_content_filters'] : true;
|
18 |
+
?>
|
19 |
+
|
20 |
+
<p>
|
21 |
+
<label for="<?php echo $this->get_field_id( 'custom_post_id' ); ?>"> <?php echo __( 'Content Block to Display:', 'custom-post-widget' ) ?>
|
22 |
+
<select class="widefat" id="<?php echo $this->get_field_id( 'custom_post_id' ); ?>" name="<?php echo $this->get_field_name( 'custom_post_id' ); ?>">
|
23 |
+
<?php
|
24 |
+
$args = array( 'post_type' => 'content_block', 'suppress_filters' => 0, 'numberposts' => -1, 'order' => 'ASC' );
|
25 |
+
$content_block = get_posts( $args );
|
26 |
+
if ($content_block) {
|
27 |
+
foreach( $content_block as $content_block ) : setup_postdata( $content_block );
|
28 |
+
echo '<option value="' . $content_block -> ID . '"';
|
29 |
+
if( $custom_post_id == $content_block -> ID ) {
|
30 |
+
echo ' selected';
|
31 |
+
$widgetExtraTitle = $content_block -> post_title;
|
32 |
+
};
|
33 |
+
echo '>' . $content_block -> post_title . '</option>';
|
34 |
+
endforeach;
|
35 |
+
} else {
|
36 |
+
echo '<option value="">' . __( 'No content blocks available', 'custom-post-widget' ) . '</option>';
|
37 |
+
};
|
38 |
+
?>
|
39 |
+
</select>
|
40 |
+
</label>
|
41 |
+
</p>
|
42 |
+
|
43 |
+
<input type="hidden" id="<?php echo $this -> get_field_id( 'title' ); ?>" name="<?php echo $this -> get_field_name( 'title' ); ?>" value="<?php if ( !empty( $widgetExtraTitle ) ) { echo $widgetExtraTitle; } ?>" />
|
44 |
+
|
45 |
+
<p>
|
46 |
+
<?php
|
47 |
+
echo '<a href="post.php?post=' . $custom_post_id . '&action=edit">' . __( 'Edit Content Block', 'custom-post-widget' ) . '</a>' ;
|
48 |
+
?>
|
49 |
+
</p>
|
50 |
+
|
51 |
+
<p>
|
52 |
+
<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' ); ?>" />
|
53 |
+
<label for="<?php echo $this->get_field_id( 'show_custom_post_title' ); ?>"><?php echo __( 'Show post title', 'custom-post-widget' ) ?></label>
|
54 |
+
</p>
|
55 |
+
|
56 |
+
<p>
|
57 |
+
<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' ); ?>" />
|
58 |
+
<label for="<?php echo $this->get_field_id( 'show_featured_image' ); ?>"><?php echo __( 'Show featured image', 'custom-post-widget' ) ?></label>
|
59 |
+
</p>
|
60 |
+
|
61 |
+
<p>
|
62 |
+
<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' ); ?>" />
|
63 |
+
<label for="<?php echo $this->get_field_id( 'apply_content_filters' ); ?>"><?php echo __( 'Do not apply content filters', 'custom-post-widget' ) ?></label>
|
64 |
+
</p> <?php
|
65 |
+
}
|
66 |
+
|
67 |
+
function update( $new_instance, $old_instance ) {
|
68 |
+
$instance = $old_instance;
|
69 |
+
$instance['custom_post_id'] = strip_tags( $new_instance['custom_post_id'] );
|
70 |
+
$instance['show_custom_post_title'] = $new_instance['show_custom_post_title'];
|
71 |
+
$instance['show_featured_image'] = $new_instance['show_featured_image'];
|
72 |
+
$instance['apply_content_filters'] = $new_instance['apply_content_filters'];
|
73 |
+
return $instance;
|
74 |
+
}
|
75 |
+
|
76 |
+
// Display the content block content in the widget area
|
77 |
+
function widget($args, $instance) {
|
78 |
+
extract($args);
|
79 |
+
$custom_post_id = ( $instance['custom_post_id'] != '' ) ? esc_attr($instance['custom_post_id']) : __( 'Find', 'custom-post-widget' );
|
80 |
+
// Add support for WPML Plugin.
|
81 |
+
if ( function_exists( 'icl_object_id' ) ){
|
82 |
+
$custom_post_id = icl_object_id( $custom_post_id, 'content_block', true );
|
83 |
+
}
|
84 |
+
// Variables from the widget settings.
|
85 |
+
$show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : false;
|
86 |
+
$show_featured_image = isset($instance['show_featured_image']) ? $instance['show_featured_image'] : false;
|
87 |
+
$apply_content_filters = isset($instance['apply_content_filters']) ? $instance['apply_content_filters'] : false;
|
88 |
+
$content_post = get_post( $custom_post_id );
|
89 |
+
$post_status = get_post_status( $custom_post_id );
|
90 |
+
$content = $content_post->post_content;
|
91 |
+
if ( $post_status == 'publish' ) {
|
92 |
+
// Display custom widget frontend
|
93 |
+
if ( $located = locate_template( 'custom-post-widget.php' ) ) {
|
94 |
+
require $located;
|
95 |
+
return;
|
96 |
+
}
|
97 |
+
if ( !$apply_content_filters ) { // Don't apply the content filter if checkbox selected
|
98 |
+
$content = apply_filters( 'the_content', $content);
|
99 |
+
}
|
100 |
+
echo $before_widget;
|
101 |
+
if ( $show_custom_post_title ) {
|
102 |
+
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)
|
103 |
+
}
|
104 |
+
if ( $show_featured_image ) {
|
105 |
+
echo get_the_post_thumbnail( $content_post -> ID );
|
106 |
+
}
|
107 |
+
echo do_shortcode( $content ); // This is where the actual content of the custom post is being displayed
|
108 |
+
echo $after_widget;
|
109 |
+
}
|
110 |
+
}
|
111 |
+
}
|
112 |
+
|
113 |
+
|
114 |
+
|