Created
September 11, 2020 20:18
-
-
Save cPanelRyan/5d648399d670dc594d913a7089622578 to your computer and use it in GitHub Desktop.
Hook Action Code: PHP Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/cpanel/3rdparty/bin/php -q | |
<?php | |
// Get decoded input. | |
$input = get_passed_data(); | |
// Declare return variables and set their values. | |
list($result_result, $result_message) = do_something($input); | |
// Return the return variables. | |
echo "$result_result $result_message"; | |
// Perform the hook's action, using the decoded input. | |
function do_something($input = array()) { | |
// Insert your actions here. | |
// Set success and failure messages. | |
$result = "1"; // This Boolean value is set to fail. | |
$message = "This is an error message."; // This string is a reason for $result. | |
// Return the hook result and message. | |
return array($result, $message); | |
} | |
// Process data from STDIN. | |
function get_passed_data() { | |
// Get input from STDIN. | |
$raw_data; | |
$stdin_fh = fopen('php://stdin', 'r'); | |
if ( is_resource($stdin_fh) ) { | |
stream_set_blocking($stdin_fh, 0); | |
while ( ($line = fgets( $stdin_fh, 1024 )) !== false ) { | |
$raw_data .= trim($line); | |
} | |
fclose($stdin_fh); | |
} | |
// Process and JSON-decode the raw output. | |
if ($raw_data) { | |
$input_data = json_decode($raw_data, true); | |
} else { | |
$input_data = array('context'=>array(),'data'=>array(), 'hook'=>array()); | |
} | |
// Return the output. | |
return $input_data; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment