Neural Network that finds what season the given day belongs to

Neural Network - find what season it is

Today i am creating new category branch in my blog, where i will post simple and useful AI snippets that is very easy to implement. My main focus would be E-Commerce and mining useful data from WordPress user sessions.

As a start, i will post very simple starter example.

I will use JavaScript based AI engines in general – simply because those are very easy to implement, work in browser, don’t require any software installation. So you will be able create neural network online without installing any tool.

So, let’s get started.

Continue reading “Neural Network that finds what season the given day belongs to”

Remove pagination trails from WooCommerce Breadcrumb

Today i am sharing small snippet that removes Pagination Trail from WooCommerce breadcrumbs.

Some shop owners may dislike this built-in feature and would like remove WooCommerce pagination links from WooCommerce navigation breadcrumb.

First let’s see how is before-after state of this change.

Before:

After:

Now let’s write a snippet for that:

Continue reading “Remove pagination trails from WooCommerce Breadcrumb”

Slow WP-Admin? Boost WP_Admin performance by disabling update checker.

In modern WordPress era things about theme and plugin repositories are far from ideal.

We don’t have centralized “app store” in WordPress world (similar to Apple Store and Google Play Store of mobile platforms) – that’s why we can list at least 3 different branches as defragmented segments:

  1. WordPress.org – where only free plugins are allowed.
  2. ThemeForest+Codecanyon – which doesn’t have own repository, but by using some 3rd party tools it is possible to have repository like channel.
  3. Premium self-hosted plugin/theme markets – Each of them has their own repositories.

Alongside with defragmantation this issue has another negative side – WP-Admin checks updates at background, with some transient-expire logic. When you have just one repository(official one – wordpress.org) – that’s not a problem. But when you are using different 3rd party plugins, it causes nightmare.

Few months ago one of my clients asked me to check why his wp-admin works so slowly.

First as a quick check i made quick monitoring with Query Monitor plugin – and discovered that connecting to external hosts takes 4-10 seconds (!) each time – Some of repositories had a problem with response time – and that was affecting whole wp-admin performance.

So i decided to disable Update Checking in wp-admin, excluding Plugins.php page itself.

I wrote such small snippet and put it to functions.php of the theme:

if(is_admin() and strpos($_SERVER["REQUEST_URI"],'plugins.php')===false){
    remove_all_filters('pre_set_site_transient_update_plugins');
    remove_all_filters('site_transient_update_plugins');
    remove_all_actions('pre_set_site_transient_update_plugins');
    remove_all_actions('site_transient_update_plugins');
}

And that did the JOB. Update checking occurs when the client enters to plugins.php to see of there is an update. And that’s exactly what we needed.

Add custom recipient to WordPress comment notification

WordPress sends email notification to Comment Post Author by default. And if it is a reply, it also send a notification to the comment author.

So, what if we need to send email to a different person, using some different logic?

In that case we can use WP’s corresponding filter, called comment_notification_recipients.

This filter sits in wp-includes/pluggable.php.

So, we just add this small snippet to functions.php file of our active theme:

add_filter( 'comment_notification_recipients',function( $emails, $comment_ID){
    $emails[]='[email protected]';
    return $emails;
},10,2);

What if this email should be fetched by using some logic, f.e. there is special meta field in each post, where we need to fetch it from. Here is how it should look like:

add_filter( 'comment_notification_recipients',function( $emails, $comment_ID){
    $comment_obj=get_comment($comment_ID);
    if(!empty($comment_obj->comment_post_ID)){
        $email_owner=get_post_meta($comment_obj->comment_post_ID,
                      'email_meta_field',true); 
        if(is_email($email_owner))$emails[]=$email_owner;
    }
    return $emails;
},10,2);

That’s all. If any question on this subject, you can leave a reply. Don’t forget to subscribe my newsletter feed club to get more and more useful small snippets for WP websites.