Blog – Page 4

Create Block Patterns Programmatically

Recently I’ve been implementing an automatic block pattern synchronisation feature into my Simple Multisite Crossposting plugin and decided why not to talk about it in a new post.

The goal of this tutorial is to learn how to create both synced and not synced block patterns programmatically and to assign specific pattern categories to them.

How to Integrate Custom Payment Gateways with WooCommerce Checkout Block

On my blog you can find a complete tutorial about creating a WooCommerce payment gateway but in the latest versions of WooCommerce (since 8.3 I guess) you may notice that your custom payment method isn’t available in the Checkout block.

For example if you try to deactivate all the payment methods except your custom one on your store, you’ll probably get an error message like this:

Custom payment method is not displaying in the checkout block
Here I am using Storefront theme as an example, but the same error message will appear for any WordPress theme anyway.

But for sure everything is working great when you’re using a legacy [woocommerce_checkout] shortcode.

Yes, it seems like my complete payment gateway tutorial isn’t that complete anymore, but we’re about to change it today by this extra tutorial where I guide you step by step what you should do in order to add the compatibility of your custom WooCommerce payment method for the WooCommerce Cart and Checkout blocks.

That’s what we’re going to achieve by end of this tutorial:

Custom payment gateway integration with WooCommerce checkout blocks

Sure thing, I will also show you some neat extra stuff like adding a custom icon for your payment method.

How to Publish a Plugin to the WordPress Plugin Directory

Recently I published one more plugin to the wordpress.org repository and I decided it is time to share the whole process with you.

This is not going to be the guide how you need to develop your own plugin in order for it to be accepted by the moderators team, the long story short – just read the guidelines, make sure that any user input is properly validated and sanitized, any output is escaped, turn on WP_DEBUG while developing and make sure that there are no PHP notices etc.

How to Auto-Post From One WordPress Site to Another

In this tutorial I am going to show you how you can automatically post an article to another WordPress website with the help of a couple of hooks and REST API. There is also an alternative way of doing that with my Simple WP Crossposting plugin, we’re also going to cover in just a little bit.

By the way, in the similar tutorials about this topic it is usually recommended to use a RSS feed and a plugin which allows to import the content from a feed. Well, this may work when your post consists only from a title and some content but it won’t work of course for complex posts with custom fields, featured images etc.

Prevent Posts in the Trash from Being Updated via REST API

This is a very specific post so it may not be useful for many of you guys, but on the other hand I didn’t even find I hint about anything like this across the internet, so, for those of you who need it, this tutorial is a gem. I hope πŸ™‚

Let’s say that you have my Simple WP Crossposting plugin installed on your main site (Site 1) or it could be any custom functionality or a plugin that uses a post update REST API endpoint {WP url}/wp-json/wp/v2/posts/{post ID}. So basically we’re syncing changes between the same posts on “Site 1” and “Site 2”.

And our goal is to prevent syncing changes we made on “Site 1” when a post copy on “Site 2” has been moved to the trash. Please note that here I mean not only restoring a post from the trash (changing the post status) but any changes.

Create Users Programmatically

You can create a WordPress user programmatically using either wp_create_user() or wp_insert_user() functions, so in this tutorial I am going to show you the difference between them and we’re also going to take a look at several examples.

There is also a way how you can do that with SQL-requests but it is not exactly creating users programmatically, so we’re not going to uncover it in this tutorial, but you can read more here.

How to Create a Language Redirect in Multisite

Recently I got a request from my client and what she was needed is to automatically redirect users to a language-specific store within the WordPress multisite network depending on a customer IP address.

For example:

  • no.example.com – redirect customers here if they have a norwegian IP address,
  • dk.example.com – redirect customers here if they have a danish IP address,
  • example.com – let customers to stay on this website if there is no specific language website version for them (based on their IP again).

What is the easiest way to accomplish it?