hooks - Trying to run a compile command while saving post

admin2025-06-05  2

I have a front end built with Gatsby, connecting to WordPress via the REST API.

Each time I update a post, I need run a command to compile. Below is my attempt at automating this using the save_post filter function:

<?php

function li_rebuild_gatsby( $id, $post, $update ) {
    $command_one = "cd /home/web/public/website425";
    $command_two = "gatsby build";
    @exec( $command_one . "&& " . $command_two );
}
add_filter( 'save_post' , 'li_rebuild_gatsby' , 10, 3 );

It seems I need to change into a sudo'er and supply a password.

What is the right way to run this command?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749065097a316053.html

最新回复(0)