Git Product home page Git Product logo

wp-jamstack-deployments's Introduction

JAMstack Deployments [BETA]

A WordPress plugin for JAMstack deployments on Netlify (and other platforms).

Description

This plugin provides a way to fire off a request to a webhook when a post, page or custom post type has been created, udpated or deleted. You're also able to fire off a request manually at the click of a button, or programmatically via a WordPress action.

WordPress Actions/Filters

The plugin attempts to trigger builds when you update your content, and has settings that you can use to define what post types & taxonomies should be monitored. However, when you need more control, there are actions & filters you can use to get the job done.

Post Types

You can choose which posts types should trigger builds from the plugin settings. However, you may require more control, or need to overwrite the settings, you can do so using the jamstack_deployments_post_types filter. By default, this filter contains an array of post types that we monitor. You can add or remove them as required.

For example, if you want to force the plugin to trigger builds for the 'post' post type regardless of the settings, you can do so with the following code:

add_filter('jamstack_deployments_post_types', function ($post_types, $post_id, $post) {
    if (!in_array($post->post_type, $post_types, true)) {
        $post_types[] = 'post';
    }
    return $post_types;
}, 10, 3);

Taxonomies

Like post types, you can choose which taxonmies should trigger builds from the plugin settings. But there may be times you need more control. For this, you can use the jamstack_deployments_taxonomies filter. By defualt, this filter contains an array of taxonomies that we monitor.

For example, if you want to force the plugin to trigger builds for the 'post_tag' taxonomy regardless of the settings, you can do so with the following code:

add_filter('jamstack_deployments_taxonomies', function ($taxonomies, $term_id, $tax_id) {
    $tax = get_taxonomy($tax_id);
    if (!in_array($tax->name, $taxonomies, true)) {
        $taxonomies[] = 'post_tag';
    }
    return $taxonomies;
}, 10, 3);

Post Statuses

You can use the jamstack_deployments_post_statuses filter to change which post statuses we monitor. The default is to monitor 'publish', 'private' and 'trash'.

Here is an example that adds 'review' to the array of post statuses that we monitor & will trigger builds for.

add_filter('jamstack_deployments_post_statuses', function ($statuses, $post_id, $post) {
    $statuses[] = 'review';
    return $statuses;
}, 10, 3);

Custom Actions

The jamstack_deployments_fire_webhook action can be used to fire the webhook and trigger a build at a custom point that you specify. For example, if you want to fire the webhook when a user registers, then you can use:

add_action('user_register', 'jamstack_deployments_fire_webhook');

Running Code Before & After Webhooks

You can run code directly before or after you fire the webhook using the following actions:

  • Before: jamstack_deployments_before_fire_webhook
  • After: jamstack_deployments_after_fire_webhook

License

GPL-3.0

wp-jamstack-deployments's People

Watchers

James Cloos avatar yinka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.