ADDED Code of Version 2.0.0 of the Advanced Composer Blocks for Newsletter Plugin

This commit is contained in:
Daniel Reintanz 2025-10-01 11:43:20 +02:00
commit 028d595144
28 changed files with 2187 additions and 0 deletions

View file

@ -0,0 +1,234 @@
<?php
/*
* Name: Single Post
* Section: content
* Description: Extended text block
*
*/
// Don't access this file directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/* @var $options array */
$default_options = array(
'wrap_padding_left' => 10,
'wrap_padding_right' => 10,
'wrap_padding_top' => 10,
'wrap_padding_bottom' => 10,
'wrap_border_width' => 0,
'wrap_border_color' => '#000000',
'wrap_border_radius' => 0,
'image_align' => 'center',
'image_size' => 'medium',
'link_image' => '',
'border_radius' => 0,
'hide_title' => '',
'link_title' => '',
'title_font_size' => '24',
'title_font_align' => 'left',
'post_date_font_size' => '16',
'post_date_font_align' => 'left',
'post_content_font_size' => '16',
'post_content_font_align' => 'left',
'post_custom_html_font_size' => '16',
'post_custom_html_font_align' => 'left',
'post_custom_html_font_color' => '#000000',
'show_content' => 'excerpt',
'hide_button' => '',
'button_text' => 'Read more',
'button_text_font_size' => '16',
'button_color' => '#000000',
'button_text_color' => '#ffffff',
'button_border_radius' => '3',
'button_align' => 'left',
'block_padding_left'=>15,
'block_padding_right'=>15,
'block_padding_top' => 20,
'block_padding_bottom' => 20,
'block_background'=>'#eeeeee'
);
$options = array_merge($default_options, $options);
$title_style = TNP_Composer::get_title_style($options, 'title', $composer);
$post_date_style = TNP_Composer::get_title_style($options, 'post_date', $composer);
$post_content_style = TNP_Composer::get_title_style($options, 'post_content', $composer);
$button_text_style = TNP_Composer::get_title_style($options, 'button_text', $composer);
$text_style = TNP_Composer::get_style($options, '', $composer, 'text');
$post_custom_html_style = TNP_Composer::get_style($options, 'post_custom_html', $composer);
?>
<style>
.block-wrap {
padding: 10px;
padding-top: <?php echo esc_attr( $options['wrap_padding_top'] ); ?>px;
padding-bottom: <?php echo esc_attr( $options['wrap_padding_bottom'] ); ?>px;
padding-left: <?php echo esc_attr( $options['wrap_padding_left'] ); ?>px;
padding-right: <?php echo esc_attr( $options['wrap_padding_right'] ); ?>px;
background-color: <?php echo esc_attr( $options['wrap_background_color'] ); ?>;
border: <?php echo esc_attr( $options['wrap_border_width'] ) ?>px solid <?php echo esc_attr( $options['wrap_border_color'] ); ?>;
border-radius: <?php echo esc_attr( $options['wrap_border_radius'] ); ?>px;
}
.post-row {
padding-bottom: <?php echo esc_attr( $options['post_list_row_gap'] ); ?>px;
}
.featured-image-wrap {
text-align: <?php echo esc_attr( $options['image_align'] ); ?>;
line-height: normal;
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
}
.featured-image {
border-radius: <?php echo esc_attr( $options['border_radius'] ); ?>px;
}
.title {
<?php esc_html( $title_style->echo_css() ) ?>
line-height: normal;
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
}
.title-link {
<?php esc_html( $title_style->echo_css() ) ?>
line-height: normal;
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
<?php if( $options['title_font_color'] ){ ?>
color: <?php echo esc_attr( $options['title_font_color'] ); ?>;
<?php } ?>
}
.post-date {
<?php esc_html( $post_date_style->echo_css() ) ?>
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
}
.post-excerpt {
<?php esc_html( $post_content_style->echo_css() ) ?>
line-height: 1.4em;
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
}
.post-full {
<?php esc_html( $post_content_style->echo_css() ) ?>
line-height: normal;
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
}
.post-custom-html {
mso-line-height-rule: exactly;
<?php echo esc_html( $post_custom_html_style->echo_css() ) ?>
line-height: normal;
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
}
.post-button-wrap {
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
text-align: <?php echo esc_attr( $options['button_align'] ); ?>;
}
.post-button {
<?php echo esc_html( $text_style->echo_css() ) ?>
<?php echo esc_html( $button_text_style->echo_css() ) ?>
background: <?php echo esc_attr( $options['button_color'] ); ?>;
color: <?php echo esc_attr( $options['button_text_color'] ); ?>;
display: inline-block;
<?php if( $options['button_width'] == 'full_width' ){ ?>
display: block;
<?php } ?>
padding: 12px 24px;
<?php if( $options['button_text_font_size'] ){ ?>
padding: <?php echo esc_attr( $options['button_text_font_size'] ) * 0.5; ?>px <?php echo esc_attr( $options['button_text_font_size'] ) * 1; ?>px;
<?php } ?>
text-decoration: none;
<?php if( $options['button_border_radius'] ){ ?>
border-radius: <?php echo esc_attr( $options['button_border_radius'] ); ?>px;
<?php } ?>
}
</style>
<div inline-class="block-wrap">
<table width="100%" style="width: 100% !important;" border="0" cellpadding="0" cellspacing="0">
<?php if( $options['post_id'] ){ ?>
<?php if( get_post($options['post_id']) ){ ?>
<?php
$post_id = (int)$options['post_id'];
$post_arr[] = $post_id;
$post_type = get_post_type( $post_id );
$post_list_args = array(
'post__in' => $post_arr,
'posts_per_page' => 1,
'post_type' => $post_type
);
$posts_list = get_posts($post_list_args); ?>
<?php foreach($posts_list as $post){
$post_custom_html = $options['post_custom_html']; ?>
<tr>
<td width="100%" valign="top" align="left" class="post-row" inline-class="post-row">
<?php if($options['image_size'] != 'none'){ ?>
<div inline-class="featured-image-wrap">
<?php if( $options['link_image'] == 1 ){ echo '<a href="' . esc_url( get_the_permalink($post->ID) ) . '" inline-class="featured-image-link">'; } ?>
<img src="<?php echo esc_url( get_the_post_thumbnail_url( $post->ID, $options['image_size'] ) ); ?>" inline-class="featured-image" />
<?php if($options['link_image'] == 1){ echo '</a>'; } ?>
</div>
<?php } ?>
<?php if($options['hide_title'] != 1){ ?>
<p inline-class="title">
<?php if($options['link_title'] == 1){ echo '<a href="' . esc_url( get_the_permalink($post->ID) ) . '" inline-class="title-link">'; } ?>
<?php echo esc_html( $post->post_title ); ?>
<?php if( $options['link_title'] == 1 ){ echo '</a>'; } ?>
</p>
<?php } ?>
<?php if($options['show_post_date'] == 1){ ?>
<p inline-class="post-date">
<?php echo esc_html( gmdate("F j, Y", strtotime($post->post_date) ) ); ?>
</p>
<?php } ?>
<?php if($options['show_content'] == 'excerpt'){ ?>
<div inline-class="post-excerpt">
<?php if( $options['excerpt_length'] ){
echo wp_kses_post( mbtnp_get_the_excerpt( $post->ID, $options['excerpt_length'] ) );
} else {
echo wp_kses_post( get_the_excerpt( $post->ID ) );
} ?>
</div>
<?php } ?>
<?php if($options['show_content'] == 'full'){ ?>
<div inline-class="post-full">
<?php echo wp_kses_post( get_the_content('','',$post->ID) ); ?>
</div>
<?php } ?>
<?php if( !empty( trim($post_custom_html) ) ){ ?>
<div inline-class="post-custom-html">
<?php echo wp_kses_post( mbtnp_replace_tags( $post_custom_html, $post->ID ) ); ?>
</div>
<?php } ?>
<?php if( $options['hide_button'] != 1 ){ ?>
<div inline-class="post-button-wrap">
<a href="<?php echo esc_url( get_the_permalink($post->ID) ); ?>" inline-class="post-button"><?php echo esc_html( mbtnp_replace_tags( $options['button_text'], $post->ID ) ); ?></a>
</div>
<?php } ?>
</td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td><p>That post ID is not valid. <a href="https://mburnette.com/find-postid/" target="_blank">How to find your post ID.</a></p></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td><p>Please enter a post ID. <a href="https://mburnette.com/find-postid/" target="_blank">How to find your post ID.</a></p></td>
</tr>
<?php } ?>
</table>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View file

@ -0,0 +1,248 @@
<?php
/*
* @var $options array contains all the options the current block we're ediging contains
* @var $controls NewsletterControls
* @var $fields NewsletterFields
*/
// Don't access this file directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<?php
// get all post type options
$post_types = get_post_types( array( 'public' => true ), 'objects' );
$post_type_options = [];
foreach($post_types as $post_type){
$post_type_options[$post_type->name] = $post_type->label;
}
// get all thumbnail size options
$image_sizes = wp_get_registered_image_subsizes();
$image_size_options = ['none' => 'None'];
foreach($image_sizes as $name => $details){
$image_size_options[$name] = ucfirst(str_replace('_', ' ', $name)) . ' (' . $details['width'] . 'x' . $details['height'] . ')';
}
$image_size_options['full'] = 'Full';
?>
<div class="tnp-field-row">
<div class="tnp-field-col-3">
<?php $fields->text('post_id', __('Post ID', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
<div class="tnp-field-col-3">
&nbsp;
</div>
<div class="tnp-field-col-3">
&nbsp;
</div>
</div>
<p class="mbtnp-section-title">Featured image</p>
<div class="tnp-field-row">
<div class="tnp-field-col-2">
<?php $fields->select('image_size', __('Image size', 'advanced-composer-blocks-for-newsletter'), $image_size_options) ?>
</div>
<div class="tnp-field-col-2" id="o-link_image">
<?php $fields->checkbox('link_image', __('Link image to post', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
</div>
<div class="tnp-field-row">
<div class="tnp-field-col-2" id="o-image_align">
<?php $fields->select('image_align', __('Align', 'advanced-composer-blocks-for-newsletter'), ['center' => 'Center', 'left' => 'Left', 'right' => 'Right']) ?>
</div>
<div class="tnp-field-col-2" id="o-border_radius">
<?php $fields->size('border_radius', __('Border radius', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
</div>
<p class="mbtnp-section-title">Title</p>
<div class="tnp-field-row">
<div class="tnp-field-col-2">
<?php $fields->checkbox('hide_title', __('Hide title', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
<div class="tnp-field-col-2" id="o-link_title">
<?php $fields->checkbox('link_title', __('Link title to post', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
</div>
<div style="clear:both;" id="o-title_font">
<?php $fields->font('title_font', '', ['family_default'=>true, 'size_default'=>true, 'weight_default'=>true, 'align'=>true]) ?>
</div>
<p class="mbtnp-section-title">Post date</p>
<div class="tnp-field-row">
<div class="tnp-field-col-2">
<?php $fields->checkbox('show_post_date', __('Show post date', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
</div>
<div style="clear:both;" id="o-post_date_font">
<?php $fields->font('post_date_font', '', ['family_default'=>true, 'size_default'=>true, 'weight_default'=>true, 'align'=>true]) ?>
</div>
<p class="mbtnp-section-title">Post content</p>
<div class="tnp-field-row">
<div class="tnp-field-col-2">
<?php $fields->select('show_content', __('Show content', 'advanced-composer-blocks-for-newsletter'), ['none' => 'None', 'excerpt' => 'Excerpt', 'full' => 'Full']) ?>
</div>
<div class="tnp-field-col-2" id="o-excerpt_length">
<?php $fields->number('excerpt_length', __('Excerpt length (characters)', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
</div>
<div style="clear:both;" id="o-post_content_font">
<?php $fields->font('post_content_font', '', ['family_default'=>true, 'size_default'=>true, 'weight_default'=>true, 'align'=>true]) ?>
</div>
<p class="mbtnp-section-title">Custom content</p>
<p style="font-size: 0.9em; margin-top: 0;">Add custom fields by using brackets. Ex: for "custom_name", use <strong>{field_custom_name}</strong></p>
<?php $fields->wp_editor( 'post_custom_html', 'Content', [
'post_custom_html_font_family' => $composer['post_custom_html_font_family'],
'post_custom_html_font_size' => $composer['post_custom_html_font_size'],
'post_custom_html_font_weight' => $composer['post_custom_html_font_weight'],
'post_custom_html_font_color' => $composer['post_custom_html_font_color'],
] ) ?>
<p class="mbtnp-section-title">Button</p>
<?php $fields->checkbox('hide_button', __('Hide button', 'advanced-composer-blocks-for-newsletter')) ?>
<div id="o-button_text">
<?php $fields->text('button_text', __('Button text', 'advanced-composer-blocks-for-newsletter')) ?>
<?php $fields->font('button_text_font', '', [ 'family_default' => true, 'size_default' => true, 'weight_default' => true, 'align'=>false, 'color'=>false ] ) ?>
</div>
<div class="tnp-field-row">
<div class="tnp-field-col-3" id="o-button_text_color">
<?php $fields->color('button_text_color', __('Text color', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
<div class="tnp-field-col-3" id="o-button_color">
<?php $fields->color('button_color', __('Button color', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
<div class="tnp-field-col-3" id="o-button_border_color">
<?php $fields->size('button_border_radius', __('Border radius', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
</div>
<div class="tnp-field-row">
<div class="tnp-field-col-2" id="o-button_width">
<?php $fields->select('button_width', 'Width', ['inline' => __('Inline', 'advanced-composer-blocks-for-newsletter'), 'full_width' => __('Full width', 'advanced-composer-blocks-for-newsletter')]) ?>
</div>
<div class="tnp-field-col-2"id="o-button_align">
<?php $fields->select('button_align', 'Alignment', ['center' => __('Center'), 'left' => __('Left'), 'right' => __('Right')]) ?>
</div>
</div>
<p class="mbtnp-section-title">Layout</p>
<div class="tnp-field-row">
<div class="tnp-field-col-4">
<?php $fields->size('wrap_border_radius', __('Border radius', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
<div class="tnp-field-col-4">
<?php $fields->color('wrap_background_color', __('Background color', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
<div class="tnp-field-col-4">
<?php $fields->size('wrap_border_width', __('Border width', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
<div class="tnp-field-col-4">
<?php $fields->color('wrap_border_color', __('Border color', 'advanced-composer-blocks-for-newsletter')) ?>
</div>
</div>
<div class="tnp-field-row" style="padding: 10px;">
<div class="tnp-field-col">
<table width="100%">
<tr>
<td><?php $fields->size('wrap_padding_left', __('&larr; Left', 'advanced-composer-blocks-for-newsletter')) ?></td>
<td><?php $fields->size('wrap_padding_top', __('&uarr; Top', 'advanced-composer-blocks-for-newsletter')) ?><?php $fields->size('wrap_padding_bottom', __('&darr; Bottom', 'advanced-composer-blocks-for-newsletter')) ?></td>
<td><?php $fields->size('wrap_padding_right', __('&rarr; Right', 'advanced-composer-blocks-for-newsletter')) ?></td>
</tr>
</table>
</div>
</div>
<hr style="clear:both; margin:20px 0;" />
<script>
jQuery(document).ready(function($){
function mbtnp_post_list_visibility(){
// thumbnail rules
var image_size = $('#options-image_size').val();
if(image_size == 'none'){
$('#o-link_images').hide();
$('#o-image_align').hide();
$('#o-border_radius').hide();
} else {
$('#o-link_images').show();
$('#o-image_align').show();
$('#o-border_radius').show();
}
// title rules
var hide_title = $('#options-hide_title').is(':checked');
if(hide_title){
$('#o-link_title').hide();
$('#o-title_font').hide();
} else {
$('#o-link_title').show();
$('#o-title_font').show();
}
// post date rules
var show_post_date = $('#options-show_post_date').is(':checked');
if(show_post_date){
$('#o-post_date_font').show();
} else {
$('#o-post_date_font').hide();
}
// content rules
var show_content = $('#options-show_content').val();
if(show_content == 'none'){
$('#o-post_content_font').hide();
} else {
$('#o-post_content_font').show();
}
if(show_content == 'full' || show_content == 'none'){
$('#o-excerpt_length').hide();
} else {
$('#o-excerpt_length').show();
}
// button rules
var hide_button = $('#options-hide_button').is(':checked');
if(hide_button){
$('#o-button_text').hide();
$('#o-button_text_color').hide();
$('#o-button_color').hide();
$('#o-button_border_color').hide();
$('#o-button_width').hide();
$('#o-button_align').hide();
} else {
$('#o-button_text').show();
$('#o-button_text_color').show();
$('#o-button_color').show();
$('#o-button_border_color').show();
$('#o-button_width').show();
$('#o-button_align').show();
}
}
$(document).delegate('input, select', 'change', function(e){
e.preventDefault();
mbtnp_post_list_visibility();
});
// if mouse hovers #tnpc-block-options
$('#tnpc-block-options').hover(function(){
mbtnp_post_list_visibility();
});
});
</script>
<?php $fields->block_commons() ?>