Hope you forgive me. I tweaked it a little bit. May this will be useful for you too.
@@ -7,13 +7,13 @@ class WYSIWYG_Widgets_Widget extends WP_Widget {
*/
public function __construct() {
parent::__construct(
- 'Widget Blocks Widget', // Name
+ __('Widget Blocks Widget', 'wysiwyg-widgets'), // Name
array( 'description' => __('Displays one of your Widget Blocks.', 'wysiwyg-widgets') ) // Args
);
}
@@ -27,10 +27,9 @@ class WYSIWYG_Widgets_Widget extends WP_Widget {
$show_title = (isset($instance['show_title'])) ? $instance['show_title'] : 1;
$post = get_post( $id );
- echo $args['before_widget'];
-
- if( ! empty( $id ) && $post ) {
+
+ if( ! empty( $id ) && $post && ! empty( $post->post_content ) ) {
+ echo $args['before_widget'];
// Allow filtering of content
$content = apply_filters( 'ww_content', $post->post_content, $id );
@@ -45,6 +44,12 @@ class WYSIWYG_Widgets_Widget extends WP_Widget {
}
echo $content;
+
+ if ( current_user_can( 'manage_options' )) {
+ echo '<a target="_blank" class="wysiwyg-widgets-edit-link" href="' . get_edit_post_link($id) . '">' . __('Edit Widget Block', 'wysiwyg-widgets') . '</a>';
+ }
+
+ echo $args['after_widget'];
echo '<!-- / WYSIWYG Widgets -->';
} elseif( current_user_can( 'manage_options' ) ) { ?>
@@ -55,11 +60,9 @@ class WYSIWYG_Widgets_Widget extends WP_Widget {
printf( __( 'No widget block found with ID %d, please select an existing Widget Block in the widget settings.', 'wysiwyg-widgets' ), $id );
} ?>
</p>
<?php
}
- echo $args['after_widget'];
}
@@ -96,13 +99,13 @@ class WYSIWYG_Widgets_Widget extends WP_Widget {
$show_title = ( isset( $instance['show_title'] ) ) ? $instance['show_title'] : 1;
$selected_widget_id = ( isset( $instance['wysiwyg-widget-id'] ) ) ? $instance['wysiwyg-widget-id'] : 0;
- $title = ($selected_widget_id) ? get_the_title( $selected_widget_id ) : 'No widget block selected.';
+ $title = ($selected_widget_id) ? get_the_title( $selected_widget_id ) : __('No widget block selected.' , 'wysiwyg-widgets' );
?>
@@ -120,9 +123,10 @@ class WYSIWYG_Widgets_Widget extends WP_Widget {
<p>
<label><input type="checkbox" id="<?php echo $this->get_field_id( 'show_title' ); ?>" name="<?php echo $this->get_field_name( 'show_title' ); ?>" value="1" <?php checked( $show_title, 1 ); ?> /> <?php _e( "Show title?", "wysiwyg-widgets" ); ?></label>
</p>
+ <p class="help"><?php printf( __( 'Edit widget block: %s', 'wysiwyg-widgets' ), '<a target="_blank" href="' . get_edit_post_link($selected_widget_id) . '">' . $title . '</a>' ); ?></p>
<p class="help"><?php printf( __( 'Manage your widget blocks %shere%s', 'wysiwyg-widgets' ), '<a href="'. admin_url( 'edit.php?post_type=wysiwyg-widget' ) .'">', '</a>' ); ?></p>
<?php
}