IF condition based on wp_remote_get output

Following would be the revised example code which you may want to try. function display_api_response() { $api_url = “https://randletter2020.herokuapp.com”; $response = wp_remote_get($api_url); if ( 200 === wp_remote_retrieve_response_code($response) ) { $body = wp_remote_retrieve_body($response); if ( ‘a’ === $body ) { echo ‘A wins’; }else { // Do something else. } } } add_action( ‘init’, ‘display_api_response’ ); … Read more

Passing the name of selected color from the custom component to `render_callback`

If you just want to get the selected color name, then you can use the getColorObjectByColorValue() function in the @wordpress/block-editor package, which is wp.blockEditor.getColorObjectByColorValue in the browser. The function accepts two parameters: a color list (each is an object with color and name as the properties), and the color (a HEX code, e.g. #17a2b8) that … Read more

Update variable value via add_filter

Filters only allow you to directly modify the first value passed to them. In your case, that’s null. If you shifted view_slug up a place, it would be available to filters using your events_view_html tag. add_filter( ‘events_view_html’, ‘my_callback’, 10, 3); // passing 3 args to the callback, assuming you need them for something. function my_callback( … Read more

WordPress shortcode returns the data before

Change form.php <form action=”<?= $_SERVER[“REQUEST_URI”]; ?>” method=”post”> <input type=”hidden” name=”form_submit_nonce” value=”<?php echo wp_create_nonce(‘form-submit-nonce’); ?>”/> <label for=”id”>ID</label> <input id=”id” name=”id” type=”text” value=”” required /> <input type=”submit” name=”submitid” value=”Submit”> </form> Change plugin file function form_shortcode(){ if ( isset( $_POST[“submitid”] ) && isset($_POST[‘form_submit_nonce’]) && wp_verify_nonce($_POST[‘form_submit_nonce’], ‘form-submit-nonce’) ) { echo “<p>OK</p>”; } else { include “form.php”; } } add_shortcode( … Read more