diff --git a/blocks/mbtnp-single-post/block.php b/blocks/mbtnp-single-post/block.php
index 342f032..0298692 100644
--- a/blocks/mbtnp-single-post/block.php
+++ b/blocks/mbtnp-single-post/block.php
@@ -18,9 +18,11 @@ $default_options = array(
'wrap_padding_right' => 10,
'wrap_padding_top' => 10,
'wrap_padding_bottom' => 10,
+ 'wrap_background_color' => '#ffffff',
'wrap_border_width' => 0,
'wrap_border_color' => '#000000',
'wrap_border_radius' => 0,
+ 'post_list_row_gap' => 0,
'image_align' => 'center',
'image_size' => 'medium',
'link_image' => '',
@@ -29,14 +31,18 @@ $default_options = array(
'link_title' => '',
'title_font_size' => '24',
'title_font_align' => 'left',
+ 'title_font_color' => '#000000',
'post_date_font_size' => '16',
'post_date_font_align' => 'left',
+ 'show_post_date' => '',
'post_content_font_size' => '16',
'post_content_font_align' => 'left',
+ 'post_custom_html' => '',
'post_custom_html_font_size' => '16',
'post_custom_html_font_align' => 'left',
'post_custom_html_font_color' => '#000000',
'show_content' => 'excerpt',
+ 'excerpt_length' => '',
'hide_button' => '',
'button_text' => 'Read more',
'button_text_font_size' => '16',
@@ -44,6 +50,7 @@ $default_options = array(
'button_text_color' => '#ffffff',
'button_border_radius' => '3',
'button_align' => 'left',
+ 'button_width' => 'inline',
'block_padding_left'=>15,
'block_padding_right'=>15,
'block_padding_top' => 20,
@@ -53,6 +60,11 @@ $default_options = array(
$options = array_merge($default_options, $options);
+// Ensure composer variable is available for style functions
+if (!isset($composer)) {
+ $composer = array();
+}
+
$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);
@@ -73,7 +85,9 @@ $post_custom_html_style = TNP_Composer::get_style($options, 'post_custom_html',
border-radius: px;
}
.post-row {
- padding-bottom: px;
+
+ padding-bottom: px;
+
}
.featured-image-wrap {
text-align: ;
@@ -86,37 +100,37 @@ $post_custom_html_style = TNP_Composer::get_style($options, 'post_custom_html',
border-radius: px;
}
.title {
- echo_css() ) ?>
+ echo_css() ?>
line-height: normal;
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
}
.title-link {
- echo_css() ) ?>
+ echo_css() ?>
line-height: normal;
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
-
+
color: ;
}
.post-date {
- echo_css() ) ?>
+ echo_css() ?>
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
}
.post-excerpt {
- echo_css() ) ?>
+ echo_css() ?>
line-height: 1.4em;
margin: 0 !important;
padding-top: 10px;
padding-bottom: 10px;
}
.post-full {
- echo_css() ) ?>
+ echo_css() ?>
line-height: normal;
margin: 0 !important;
padding-top: 10px;
@@ -124,7 +138,7 @@ $post_custom_html_style = TNP_Composer::get_style($options, 'post_custom_html',
}
.post-custom-html {
mso-line-height-rule: exactly;
- echo_css() ) ?>
+ echo_css() ?>
line-height: normal;
margin: 0 !important;
padding-top: 10px;
@@ -137,20 +151,20 @@ $post_custom_html_style = TNP_Composer::get_style($options, 'post_custom_html',
text-align: ;
}
.post-button {
- echo_css() ) ?>
- echo_css() ) ?>
+ echo_css() ?>
+ echo_css() ?>
background: ;
color: ;
display: inline-block;
-
+
display: block;
padding: 12px 24px;
-
+
padding: px px;
text-decoration: none;
-
+
border-radius: px;
}
@@ -175,11 +189,14 @@ $post_custom_html_style = TNP_Composer::get_style($options, 'post_custom_html',
-
- ID) ) . '" inline-class="featured-image-link">'; } ?>
-  ); ?>)
- '; } ?>
-
+ ID, $options['image_size'] ); ?>
+
+
+ ID) ) . '" inline-class="featured-image-link">'; } ?>
+ ; ?>)
+ '; } ?>
+
+
diff --git a/blocks/mbtnp-single-post/options.php b/blocks/mbtnp-single-post/options.php
index c629417..a217ac1 100644
--- a/blocks/mbtnp-single-post/options.php
+++ b/blocks/mbtnp-single-post/options.php
@@ -29,14 +29,14 @@ $image_size_options['full'] = 'Full';
?>
-
+
+
text('post_id', __('Post ID', 'advanced-composer-blocks-for-newsletter')) ?>
-
-
-
-
-
-
+
@@ -242,6 +242,78 @@ jQuery(document).ready(function($){
$('#tnpc-block-options').hover(function(){
mbtnp_post_list_visibility();
});
+
+ // Post title search functionality
+ var searchTimeout;
+ var ajaxUrl = typeof ajaxurl !== 'undefined' ? ajaxurl : '';
+
+ $('#post-search-input').on('keyup', function() {
+ var searchTerm = $(this).val();
+ var $results = $('#post-search-results');
+
+ if (searchTerm.length < 2) {
+ $results.hide().empty();
+ return;
+ }
+
+ clearTimeout(searchTimeout);
+ searchTimeout = setTimeout(function() {
+ console.log('Sending AJAX request with:', {
+ action: 'mbtnp_search_posts',
+ search_term: searchTerm,
+ url: ajaxUrl
+ });
+
+ $.ajax({
+ url: ajaxUrl,
+ type: 'POST',
+ data: {
+ action: 'mbtnp_search_posts',
+ search_term: searchTerm
+ },
+ success: function(response) {
+ console.log('AJAX Success:', response);
+ if (response.success && response.data.length > 0) {
+ var html = '';
+ $.each(response.data, function(index, post) {
+ html += ' ';
+ html += '' + post.post_title + ' ';
+ html += 'ID: ' + post.ID + ' | ' + post.post_date + ' | ' + post.post_type + '';
+ html += ' ';
+ });
+ $results.html(html).show();
+ } else {
+ $results.html(' ').show();
+ }
+ },
+ error: function(jqXHR, textStatus, errorThrown) {
+ console.error('AJAX Error:', textStatus, errorThrown);
+ console.error('Response:', jqXHR.responseText);
+ $results.html(' ').show();
+ }
+ });
+ }, 300);
+ });
+
+ // Handle click on search results
+ $(document).on('click', '.post-search-result', function() {
+ var postId = $(this).data('post-id');
+ var postTitle = $(this).find('strong').text();
+
+ $('#options-post_id').val(postId);
+ $('#post-search-input').val(postTitle);
+ $('#post-search-results').hide();
+
+ // Trigger change event to update preview
+ $('#options-post_id').trigger('change');
+ });
+
+ // Hide search results when clicking outside
+ $(document).on('click', function(event) {
+ if (!$(event.target).closest('#post-search-input, #post-search-results').length) {
+ $('#post-search-results').hide();
+ }
+ });
});
diff --git a/mbtnp-blocks.php b/mbtnp-blocks.php
index 7ee92b9..3508777 100644
--- a/mbtnp-blocks.php
+++ b/mbtnp-blocks.php
@@ -147,4 +147,50 @@ function mbtnp_replace_tags( $content, $post_id = null ){
);
return $content;
-}
\ No newline at end of file
+}
+
+
+// ---------------------------------------------------------------------------------
+// ----- AJAX HANDLER FOR POST SEARCH ----------------------------------------------
+// ---------------------------------------------------------------------------------
+function mbtnp_search_posts_handler() {
+ // Check if user has capability to edit posts
+ if (!current_user_can('edit_posts')) {
+ wp_send_json_error(array('message' => 'Insufficient permissions'));
+ wp_die();
+ }
+
+ $search_term = isset($_POST['search_term']) ? sanitize_text_field($_POST['search_term']) : '';
+
+ if (empty($search_term) || strlen($search_term) < 2) {
+ wp_send_json_error(array('message' => 'Search term too short'));
+ wp_die();
+ }
+
+ // Search for posts
+ $args = array(
+ 'post_type' => 'any',
+ 'post_status' => 'publish',
+ 's' => $search_term,
+ 'posts_per_page' => 10,
+ 'orderby' => 'relevance'
+ );
+
+ $posts = get_posts($args);
+
+ $results = array();
+ foreach ($posts as $post) {
+ $results[] = array(
+ 'ID' => $post->ID,
+ 'post_title' => $post->post_title,
+ 'post_date' => get_the_date('Y-m-d', $post->ID),
+ 'post_type' => get_post_type($post->ID)
+ );
+ }
+
+ wp_send_json_success($results);
+ wp_die();
+}
+
+// Register AJAX handlers for logged-in users only
+add_action('wp_ajax_mbtnp_search_posts', 'mbtnp_search_posts_handler');
\ No newline at end of file
|