• Resolved peter0001

    (@peter0001)


    I’m looking into using WordPress as a headless CMS for use in conjunction with a GatsbyJS static frontend. My frontend code is built by GitLab CI/CD.

    Currently my frontend code pulls site content straight from the WP API on page load. This isn’t really a static solution. It would be better to trigger a CI/CD pipeline that builds a completely static frontend through their API whenever someone saves a custom post.

    .

    It would be great if we could have an input field in custom post settings that takes the name/names of functions that will be ran on publish.

    add_action('publish_customposttype', 'func_name');

    By leaving implementation of the actual function up to the developer, this feature could be used to trigger all kinds of things: CI/CD Pipelines on a variety of platforms, Slack notifications, other WP core functions, etc.

    .

    I was inspired by this WP plugin: https://github.com/kmturley/wordpress-gitlab-trigger-pipeline/blob/master/gitlab-trigger-pipeline.php

    • This topic was modified 6 years, 5 months ago by peter0001.
    • This topic was modified 6 years, 5 months ago by peter0001.
    • This topic was modified 6 years, 5 months ago by peter0001.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If I’m understanding you correct, you’re looking for something like below?

    Imagine we have a post type of “movie” and “tv_show”. We provide a text input in the CPTUI settings that the user can provide and save function names of “my_movie” and “my_tv_show”. They then define both somewhere, and make sure they’re callable.

    Really basic examples:

    function my_movie() {
        echo 'My movie is awesome!';
    }
    
    function my_movie() {
        echo 'My tv show is awesome!';
    }
    

    Along with that, elsewhere in our own code, we are wiring up those saved values by and for the user, with something like this?

    Note: fake function call to get the saved function name

    $cpt_func_to_run = cptui_get_saved_callable( $post_type );
    $tax_func_to_run = cptui_get_saved_callable( $taxonomy );
    
    add_action( "publish_{$post_type}", $cpt_func_to_run, 10, 2 );
    

    If that’s what you’re thinking, or at least pretty close, I’m not sure it’s something I want our plugin to take on the responsibility for. Particularly, anyone with enough domain knowledge to set up that much already with the callback, could just as easily set up the add_action themselves. It would also be a good thing to keep those two parts together, in my mind, instead of just leaving a function defined that would maybe be assumed to be used in the theme somewhere else, but instead is nested in a setting with CPTUI that people won’t think of to check.

    I’m not against the idea of providing some documentation to help someone do similar things, but it just wouldn’t be directly integrated with our saved settings.

    Thread Starter peter0001

    (@peter0001)

    Yeah that’s exactly what I was thinking of.

    I could setup custom post types manually as well but I’m using this awesome plugin to make my life a bit easier. Having to code these triggers manually anyway negates that added value somewhat.

    It might make more sense for me to write a separate plugin for this, as I fully understand why you wouldn’t want to add this feature to the plugin (and I’m probably an edge case).

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    It’s not all proverbial doom. I would check out the following hook and an example that I have that utilizes it.

    Utility hook:
    https://github.com/WebDevStudios/custom-post-type-ui/blob/master/inc/post-types.php#L1355-L1363

    Example plugin:
    https://github.com/tw2113/custom-post-type-ui-capabilities

    We added the hook as part of our development for CPTUI-Extended, and allows for outputting your own fields. My example plugin should also show how to hook in to saving the submission along with integrating the custom settings somehow. The integration part will not be quite the way you’re needing, since my example passes custom data to register_post_type() args, and you just need to run callbacks.

    Let me know if you have any questions, regardless.

    Thread Starter peter0001

    (@peter0001)

    Thanks, much appreciated. I’ll look into this.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Custom publish_customposttype action’ is closed to new replies.