• Resolved mumbomedia

    (@mumbomedia)


    Dear Newsletter-Team,

    is there a way I could filter the templates for the composer.
    Actually it shows me “Simple Call To Action”, “Invite to an event” “A big announcement”,”Last news from your blog”,”A big offer”,”Product”,”Your favourite band tour dates”,”Story or full article”,”Start with an empty project”.

    I want to have two templates, which consists of the header and footer and between them our customer can add whatever block he needs.

    Btw. There are many dead links in your developer docs. Please check and correct this links e.g on https://www.thenewsletterplugin.com/documentation/developers/dev-newsletter-hooks/ when it click on “the Composer Blocks documentation” I got a 404 error page.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Stefano Lissa

    (@satollo)

    Hi, no actually it is not possible to filter the templates. We’re working to make it possibile to register new templates.

    Stefano.

    Thread Starter mumbomedia

    (@mumbomedia)

    Hi Stefano,

    thanks for the fast reply and your fantastic plugin.
    It’s our standard newsletter plugin.
    We are using it on each site our customer wants to send newsletter.

    Good to hear, that you are working on it.
    When do you think, this is possible?

    In the meantime I have found a way to archieve this.

    I hooked into the newsletter_init hook and then deregister and register and new handler for wp_ajax_tnpc_presets. In this function I got the instance of NewsletterEmails via its static function get_instance.
    For testing I reduce the $PRESETS_LIST to array(“blank”) so only the blank preset is shown.

    Actually I’m working to make custom blocks for preheader, header, footer and legal notice.

    As I have saw in the code I could use the filter “newsletter_blocks_dir” to disable unwanted blocks.

    Here’s my actual code:

    function mjm_hook_wp_ajax_tnpc_presets(){
    	$content = '';
    	$newsletter_emails = NewsletterEmails::instance();
    	$newsletter_emails::$PRESETS_LIST = array('blank');
    	if(!empty($_REQUEST['id'])){
    		$preset = $newsletter_emails->get_preset($_REQUEST['id']);
    		foreach($preset->blocks as $item){
    			$newsletter_emails->render_block($item->block,true,(array) $item->options);
    		}
    	}
    	else{
    		$content = "<div class='clear tnpc-presets-title'>" . __('Choose a preset:', 'newsletter') . "</div>";
    		foreach ($newsletter_emails::$PRESETS_LIST as $id) {
    			
    			$preset = $newsletter_emails->get_preset($id);
    			
    			$content .= "<div class='tnpc-preset' onclick='tnpc_load_preset(\"$id\")'>";
    			$content .= "<img src='$preset->icon' title='$preset->name' />";
    			$content .= "<span class='tnpc-preset-label'>$preset->name</span>";
    			$content .= '</div>';
    		}
    		
    		$content .= '<div class="clear"></div>';
    		echo $content;
    	}
    	wp_die();
    }
    
    function mjm_override_newsletter(){
    	$newsletter_emails = NewsletterEmails::instance();	remove_action('wp_ajax_tnpc_presets',array($newsletter_emails,'hook_wp_ajax_tnpc_presets'));
    	add_action('wp_ajax_tnpc_presets','mjm_hook_wp_ajax_tnpc_presets');
    }
    add_action('newsletter_init','mjm_override_newsletter');
    Thread Starter mumbomedia

    (@mumbomedia)

    There is a performance improvement opportunity in /newsletter/emails/emails.php:741 – 756
    There scan_blocks_dir is unnecessarily called 3 times.
    In my opinion, lines 748 – 752 can be omitted.

    The directories to search for should instead be set using the existing filter “newsletter_blocks_dir”.
    The advantage of this solution would be that you could now remove the standard filter using the “newsletter_init” filter and register your own filter for it, making it possible to overwrite existing blocks.

    Plugin Author Stefano Lissa

    (@satollo)

    Hi, our idea is to let people register or save presets (model, templates) but we won’t let to hide our presets. There is a reason for that: constantly we get support request for missing or bad working things cause by improper use of hooks, core file modifications and so on.

    Now imagine is a plugin or a theme, for any reason, starts to hide the presets. The problem seems located in our plugin and it’s a nightmare to debug it. So for each “extension point” we need even to have a way to detect it in a way to know it is active when something “wrong” is happening.

    Thank you for reporting the performance improvement, I definitively get into it.

    Stefano.
    ps: the scan block dir will be probably removed, it reveaaled to not be a good choice…

    Thread Starter mumbomedia

    (@mumbomedia)

    Hi Stefano,

    I understand.
    But since I’m also the technical person responsible for the entire WordPress multisite, it doesn’t matter whether I overwrite your plugin code.

    From my own experience I know only too well that after the code is in production it revealed to not be a good choice. That’s a problem I’m facing everday and in the most cases it isn’t code that I have written.
    Really frustating is it when the code isn’t well documented and / or formated.
    I think every developer can sing a song about it.

    However actually I’m in a bind.
    Personally, I would like to wait for the update.
    On the other hand, my boss wants the page to be completely finished as soon as possible so that he can show it to the customer and we can go live (which then means that we can invoice our customer).

    When do you think, the plugin update will be available?

    • This reply was modified 5 years, 1 month ago by mumbomedia.
    Plugin Author Stefano Lissa

    (@satollo)

    Hi, we have a long plan of things to do, I cannot promise a date right now.

    If you use a versioning system for your production site, you can update locally and using diff to keep your changes.

    Stefano.

    Thread Starter mumbomedia

    (@mumbomedia)

    That’s a great idea.
    I have installed a svn locally on my computer for another project.
    I will make a new repository for this, so I am able to diff you changes in the plugins code.

    Because I have subscribe your newsletter I will be informed when a new release is available.

    So keep the good work.

    Alexander

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Filter the composer templates’ is closed to new replies.