How to debug new shortcode? And how to get string from shortcode into code?

I am trying to write a simple plugin that fetches some data from an API endpoint. I am planning to read the api key from a shortcode, but didn't get that far yet. I wrote the following piece of code. The noob question I have is how do I even trigger the code so that I could debug it to see what happens ? If that's a simple question, the follow up would be how to read the api key …
Category: Web

Is curl required?

My admin panel is very slow I've tried to debug the issue. I nailed it to the function wp_remote_post and an internal error message thrown by curl on this line return new WP_Error( 'http_request_failed', curl_error( $handle ) ); I wonder what would have happened if I uninstalled curl. Can WordPress use other mechanisms to make http requests or is curl required?
Category: Web

Wordpress wp_remote_post vs wp_remote_request

I'm somehow new to Wordpress and its API and while writing an simple Rest Service to an remote Server i have been asked to use the native wp_remote_X functions. Right now i have some trouble to distinguish between them both: wp_remote_post() wp_remote_request(). Does it make any difference which one to use or is the wp_remote_request an alias to missing wp_remote_delete() and wp_remote_update() ?
Category: Web

WP_REMOTE_POST Requests are being blocked by API provider

I'm trying to make some API POST requests via WordPress' own method i.e. wp_remote_post() Here is the sample code I'm using: $args = array ( 'sslverify' => false, 'headers' => [ 'Authorization: Bearer {API_KEY}', 'Content-Type: application/json' ], 'body' => array ( 'region' => 'USA', 'plan' => 1, 'label' => 'API Test', 'app_id' => 2 ) ); $response = wp_remote_post( "https://api.example.com/plans/create", $args ); $response = wp_remote_retrieve_body($response); error_log($response); But it returns me a 403 Forbidden error, Here are the details: <HTML> <head><title>403 …
Category: Web

What would be the best way to implement Magic Link logins in WordPress?

On the internet I saw several plugins/services offering a kind of a 'magic login' link functionality. This allows users to sign in without a password but with a magic link. That made me wondering: If I want to implement this myself, how would I do this? I do not necessarily need to send emails, but just the process of getting a link/specific endpoint that signs a user in. Edit: after a little bit more digging I found the wp_signon() function, …
Category: Web

wp_remote_post sends empty body

I made an api with nodejs and i'm trying to make some calls to it throught wordpress, all the requests works correctly but when i add a request body it is sent empty, i tried to search what was the problem but i found nothing that worked. I mean if i send this request $body = [ 'name' => 'Pixelbart', 'email' => '[email protected]', "password" => "Pass#your!word" ]; $body = json_encode( $body, TRUE ); echo $body; // here the body is …
Category: Web

Can I call a functions.php file from a different URL?

I have several(5+) sites that are very similar in functionality. With that I have the same amount of functions.php files and child themes. What I'd like to do is have one common functions file and then a custom functions.php file for each individual site for more site-specific functionality. What is the best way to do this?
Category: Web

Using webhook sending message to telegram from wordpress?

I want send a message to telegram whenever a form submitted. i am using gravity form plugin form. and it has the hook add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 ); which will be call after form submitted. and i create a telegram bot and submit my url as webhook url base on instruction. here is my code: $url = $path."/sendmessage?chat_id=".$userID."&text=".'messaginggggg'; $request = file_get_contents($url); the problem is when i use the url in my browser it perfectly send notification to my bot …
Category: Web

is_admin() returns false in save_post hook with Gutenberg editor

I have a plugin that implements a REST API that needs to be notified when an admin adds one of my supported shortcodes to a page or post. I hook save_post with my function like this. add_action( 'save_post', 'detect_shortcodes'); However, when I update from the editor, it does an ajax call that instantiates my plugin. The first thing it does is determine whether to load public or admin hooks like this. if(is_admin()) { $this->define_admin_hooks(); } else { $this->define_public_hooks(); } Of …
Category: Web

Custom routes for custom post type?

I have a custom post type called 'event'. An event has multiple subpages like registration, speakers, contact us, etc. Currently the content is saved as one or more custom fields. I would like to have an url structure like events/{event_slug}/registration events/{event_slug}/speakers events/{event_slug}/contactus With each URL displaying the information from each custom field, respectively. Is there a way, we can achieve this in WordPress?
Category: Web

how to avoid timeouts with remote API requests?

I'm developing a plugin, WP SoundSystem, that makes Wordpress rest requests to my remote API api.spiff-radio.org. That API is scraping content on the web. Which means that it might be slow to get the data. (EDIT:that data is just plain text tracklists) So WP SoundSystem plugin requests data on api.spiff-radio.org... ...api.spiff-radio.org scrapes the web... ...api.spiff-radio.org returns a response... ...WP SoundSystem plugin gets the response WHICH might be quite slow. I already set a 20 seconds timeout (default is 5) when …
Category: Web

wp_remote_request to url with port 8001 not woorking

I try to send a request with the function wp_remote_request and it is not accepted (Note the port at URL) When I download the port it is accepted Where's the problem? tish is the code: $args = array( 'body' => array( 'key' => 'value' ) ); wp_remote_request('http://exemple.com:8001/page', $args);
Category: Web

get token using the 'WordPress REST API with JWT Authentication' plugin

I'm trying to build a Wordpress plugin that is an API which can be queried from remote websites. I want to secure it with JWT web tokens, so I did install the JWT Authentication for WP REST API plugin. I read this article to configure it, and have a working setup (checked in Postman). So I have my API website with JWT working. Now, I want to request that API from the client website. I need a token from the …
Category: Web

wp_remote_request header error even though working properly with cURL

I'm trying to make calls to a JSON API inside my wordpress theme. I tried with the cURL option, making a custom function and things works as it should but I wanted to use the built-in wordpress functions and with the same parameters I keep getting an error "Invalid request header" here are my parameters: $payload = array ( 'httpversion' => '1.0', 'headers' => array ( 'Content-type' => 'application/json', 'Accept' => 'application/json; charset=utf-8', 'Authorization' => 'Basic ' . base64_encode( $login …
Category: Web

view counter update in WordPress REST api HTTP get

I use WordPress rest API for app communication with my site in need update post view counter when HTTP get API. I search a lot but nothing found about it, in a tutorial "Find popular posts with the WordPress REST API" view counter update when call HTTP get API URL but it's in custom endpoint but I need this update function in rest API default endpoint the code for popular post custom endpoint : add_action( 'rest_api_init', function () { register_rest_route( …
Category: Web

Proxy not working with Requests::request_multiple()?

I try to send async multiple requests with proxy option by built-in WP Class Requests, but it's not working. $options = array( 'proxy' => $proxy ); Single Request, it's working, so the proxy itself is working properly. $s = Requests::request($link1, array(), array(), 'GET', $options); The result of var_dump($s): object(Requests_Response)[1637] public 'body' => string '<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're …
Category: Web

How to run a function on plugin's options page?

I am writing a plugin that syncs data from a third party service to custom post types in wordpress via HTTP/SOAP. There will be the option to run it on an interval (using wP_cron functions) but I also want to include a 'Sync' button to be able to manually pull in or update data without having to wait for the next time the cron runs. I have an options page for the plugin page setup using Wordpress's Settings API, which …
Category: Web

How can I interact with a third party service that sends POST requests to me in response to the order information that I send them?

I'm developing a payment gateway for Wordpress. I should send the data to a third party and get the confirmation code (and other info) from them. The problem is that they don't return this confirmation code as a direct response to my POST request. Instead, they process it, and send a POST request to a URL that I can specify. Because of this, I can't use the wp_remote_post. How can I implement this, and if possible, ensure that the user …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.