dynamisches suchfeld eingefügt - nocht
erstelle mit claude 4.5 - die auswahlfunktion funktioniert aber nicht das absenden nach dem auswählen in den beitrag hinein. -> "Block rendering failed"
This commit is contained in:
parent
9341afa1dc
commit
7437d10019
3 changed files with 161 additions and 26 deletions
|
|
@ -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: <?php echo esc_attr( $options['wrap_border_radius'] ); ?>px;
|
||||
}
|
||||
.post-row {
|
||||
padding-bottom: <?php echo esc_attr( $options['post_list_row_gap'] ); ?>px;
|
||||
<?php if( !empty($options['post_list_row_gap']) ){ ?>
|
||||
padding-bottom: <?php echo esc_attr( $options['post_list_row_gap'] ); ?>px;
|
||||
<?php } ?>
|
||||
}
|
||||
.featured-image-wrap {
|
||||
text-align: <?php echo esc_attr( $options['image_align'] ); ?>;
|
||||
|
|
@ -86,37 +100,37 @@ $post_custom_html_style = TNP_Composer::get_style($options, 'post_custom_html',
|
|||
border-radius: <?php echo esc_attr( $options['border_radius'] ); ?>px;
|
||||
}
|
||||
.title {
|
||||
<?php esc_html( $title_style->echo_css() ) ?>
|
||||
<?php echo $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() ) ?>
|
||||
<?php echo $title_style->echo_css() ?>
|
||||
line-height: normal;
|
||||
margin: 0 !important;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
<?php if( $options['title_font_color'] ){ ?>
|
||||
<?php if( !empty($options['title_font_color']) ){ ?>
|
||||
color: <?php echo esc_attr( $options['title_font_color'] ); ?>;
|
||||
<?php } ?>
|
||||
}
|
||||
.post-date {
|
||||
<?php esc_html( $post_date_style->echo_css() ) ?>
|
||||
<?php echo $post_date_style->echo_css() ?>
|
||||
margin: 0 !important;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.post-excerpt {
|
||||
<?php esc_html( $post_content_style->echo_css() ) ?>
|
||||
<?php echo $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() ) ?>
|
||||
<?php echo $post_content_style->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;
|
||||
<?php echo esc_html( $post_custom_html_style->echo_css() ) ?>
|
||||
<?php echo $post_custom_html_style->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: <?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() ) ?>
|
||||
<?php echo $text_style->echo_css() ?>
|
||||
<?php echo $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' ){ ?>
|
||||
<?php if( !empty($options['button_width']) && $options['button_width'] == 'full_width' ){ ?>
|
||||
display: block;
|
||||
<?php } ?>
|
||||
padding: 12px 24px;
|
||||
<?php if( $options['button_text_font_size'] ){ ?>
|
||||
<?php if( !empty($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'] ){ ?>
|
||||
<?php if( !empty($options['button_border_radius']) ){ ?>
|
||||
border-radius: <?php echo esc_attr( $options['button_border_radius'] ); ?>px;
|
||||
<?php } ?>
|
||||
}
|
||||
|
|
@ -175,11 +189,14 @@ $post_custom_html_style = TNP_Composer::get_style($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 $featured_image_url = get_the_post_thumbnail_url( $post->ID, $options['image_size'] ); ?>
|
||||
<?php if( $featured_image_url ){ ?>
|
||||
<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( $featured_image_url ); ?>" inline-class="featured-image" />
|
||||
<?php if($options['link_image'] == 1){ echo '</a>'; } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<?php if($options['hide_title'] != 1){ ?>
|
||||
<p inline-class="title">
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ $image_size_options['full'] = 'Full';
|
|||
?>
|
||||
|
||||
<div class="tnp-field-row">
|
||||
<div class="tnp-field-col-3">
|
||||
<div class="tnp-field-col-2">
|
||||
<label for="post-search-input"><?php _e('Search by post title', 'advanced-composer-blocks-for-newsletter') ?></label>
|
||||
<input type="text" id="post-search-input" placeholder="<?php _e('Type to search posts...', 'advanced-composer-blocks-for-newsletter') ?>" />
|
||||
<div id="post-search-results" style="display: none; position: relative; z-index: 1000; background: white; border: 1px solid #ccc; max-height: 200px; overflow-y: auto;"></div>
|
||||
</div>
|
||||
<div class="tnp-field-col-2">
|
||||
<?php $fields->text('post_id', __('Post ID', 'advanced-composer-blocks-for-newsletter')) ?>
|
||||
</div>
|
||||
<div class="tnp-field-col-3">
|
||||
|
||||
</div>
|
||||
<div class="tnp-field-col-3">
|
||||
|
||||
<small><?php _e('Or enter Post ID manually', 'advanced-composer-blocks-for-newsletter') ?></small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -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 : '<?php echo admin_url("admin-ajax.php"); ?>';
|
||||
|
||||
$('#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 += '<div class="post-search-result" data-post-id="' + post.ID + '" style="padding: 8px; cursor: pointer; border-bottom: 1px solid #eee;">';
|
||||
html += '<strong>' + post.post_title + '</strong><br>';
|
||||
html += '<small>ID: ' + post.ID + ' | ' + post.post_date + ' | ' + post.post_type + '</small>';
|
||||
html += '</div>';
|
||||
});
|
||||
$results.html(html).show();
|
||||
} else {
|
||||
$results.html('<div style="padding: 8px; color: #666;"><?php _e("No posts found", "advanced-composer-blocks-for-newsletter") ?></div>').show();
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
console.error('AJAX Error:', textStatus, errorThrown);
|
||||
console.error('Response:', jqXHR.responseText);
|
||||
$results.html('<div style="padding: 8px; color: #d63638;"><?php _e("Search failed", "advanced-composer-blocks-for-newsletter") ?></div>').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();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -147,4 +147,50 @@ function mbtnp_replace_tags( $content, $post_id = null ){
|
|||
);
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// ----- 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');
|
||||
Loading…
Add table
Add a link
Reference in a new issue