Settings', ); $actions = array_merge( $actions, $mylinks ); return $actions; } // --------------------------------------------------------------------------------- // ----- REGISTER NEW BLOCKS ------------------------------------------------------- // --------------------------------------------------------------------------------- function mbtnp_newsletter_register_blocks() { $mbtnp_blocks = [ "mbtnp-image", "mbtnp-posts-list", "mbtnp-text", "mbtnp-cover", "mbtnp-cta", "mbtnp-single-post" ]; $dir = __DIR__; foreach($mbtnp_blocks as $block){ if ( file_exists( $dir . '/blocks/' . $block ) ) { TNP_Composer::register_block( $dir . '/blocks/' . $block ); } } } add_action( 'newsletter_register_blocks', 'mbtnp_newsletter_register_blocks' ); // --------------------------------------------------------------------------------- // ----- ADD LIVE PREVIEW BUTTON TO COMPOSER --------------------------------------- // --------------------------------------------------------------------------------- function mbtnp_add_live_preview_button_in_admin() { // Get the current site's URL $site_url = get_site_url(); $acb_settings = get_option('acb_settings'); $acb_live_preview_disable = isset($acb_settings['acb_disable_live_preview']) ? $acb_settings['acb_disable_live_preview'] : false; if ($acb_live_preview_disable) { return; } // enqueue live preview script wp_enqueue_script( 'mbtnp-blocks-live-preview', plugin_dir_url( __FILE__ ) . 'js/mbtnp-blocks-live-preview.js', array('jquery'), '', true ); } add_action('admin_footer', 'mbtnp_add_live_preview_button_in_admin'); // --------------------------------------------------------------------------------- // ----- ADD COPY/PASTE BUTTONS TO COMPOSER BLOCKS --------------------------------- // --------------------------------------------------------------------------------- function mbtnp_add_blocks_copy_paste() { // enqueue live preview script and css wp_enqueue_script( 'mbtnp-blocks-copy-paste', plugin_dir_url( __FILE__ ) . 'js/mbtnp-blocks-copy-paste-block.js', array('jquery'), '', true ); wp_enqueue_style( 'mbtnp-blocks-copy-paste', plugin_dir_url( __FILE__ ) . 'css/mbtnp-blocks-copy-paste-block.css' ); } add_action('admin_footer', 'mbtnp_add_blocks_copy_paste'); // --------------------------------------------------------------------------------- // ----- GET SHORTENED EXCERPT ------------------------------------------------------------------------ // --------------------------------------------------------------------------------- function mbtnp_get_the_excerpt( $post_id, $count ) { $excerpt = get_the_content( '', '', $post_id ); $excerpt = wp_strip_all_tags( $excerpt ); if( strlen($excerpt) > $count ){ $excerpt = trim(substr($excerpt, 0, $count)); $excerpt .= '...'; } return $excerpt; } // --------------------------------------------------------------------------------- // ----- REPLACE CUSTOM TAGS (helper) ---------------------------------------------- // --------------------------------------------------------------------------------- function mbtnp_replace_tags( $content, $post_id = null ){ if( empty($post_id) ){ return $content; } $post = get_post($post_id); // replace {field_XYZ} with value from XYZ custom field $content = preg_replace_callback( '/\{field_([^}]+)\}/', function ($matches) use ($post) { return get_post_meta($post->ID, $matches[1], true); }, $content ); // replace {title} with post title $content = preg_replace_callback( '/\{title\}/', function ($matches) use ($post) { return get_the_title($post->ID); }, $content ); 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');