WordPress plugin accessing WordPress URL remotely to send data across - wordpress

I am in the process of writing a small WordPress data sync plugin that is intended to sync some records between two sites. When a new data item is entered on one site, a JSON-encoded version of that data item is posted to a URL on the other site which then digests it and saves it to a local database.
I'm finding it really hard to work out what URL I should be posting the JSON data to so that it gets into the plugin on the other end. Or whether I should be reusing admin_ajax, even though this is server-to-server not browser-to-server.
Happy to assume that both sites are running WordPress 3.3/3.4.
I've spent quite some considerable time googling without results, which may simply be that I'm looking for the wrong terminology.
For instance, I might get the sending copy of the plugin to post to a URL such as http://www.example.com/wp-content/plugins/datasyncer/incoming.php - but a shorter URL or a smarter way to do it would be great. While I could make this URL work pretty easily by including ../../../wp-load.php I'm reluctant to do that as that will break on some sites, and is considered Bad Practice in a plugin.
I'm using wp_remote_post() to do the post to URL part, the problem is which URL to post to, not how to post.
I'll edit this and correct terminology if anyone has any ideas that help! Thanks in advance!

You can post anywhere you want (in front side, and not on admin side, of course). You can even post to the home page. Just make sure that you don't post any data which conflicts with wordpress core. For example: name, post, p are all reserved.
Add a prefix to all your post variables "myplugin_name" is ok, "name" is not.
Then in your plugin code add a condition to check if something was posted:
if(isset($_POST["myplugin_remote_data"])) {
// check if data was indeed sent by your server. use some api key etc
// save the data
// echo some response telling if data was posted or not. anything you want.
die(); // no need to show the page
}

Related

How to create a job post by email parsing in WordPress?

I want to develop a job board website. I want specific feature in that is job posts will be created automatically by email parsing.
I tried Zapier, but it creates only blog posts.
And tried postie plugin to, but Gmail didn't allow it.
Willing to use job monster / work scout/ superio any one of these themes. If you have any suggestions, please let me know about it.
Is there any way to parse the email data and create a new job post. Please help me to resolve this issue.
No paid task. Need help to learn the things
There is a lot to unpack here.
The main problem you are going to encounter is that the emails you are parsing may not all be formatted the same. To pull the info out of an email you will need to be able to generate some rules to extract it.
If however, the emails are formatted the same then you can use the "split" function in Zapier to pull out the various bits of data from the email. Once you have these you can create a new post with your Zap.
I would recommend looking for a Wordpress plugin that allows you to create lists with custom post types. WP-Bakery does this from memory. You can set up a custom feed based on that post type.
Hopefully this helps narrow down the process for you. Good Luck.

I need help understanding how to refresh cache for a place id

I have installed a Everest GPlaces Business Reviews and have found the place id that is required to be added. But it comes back Saying:
The provided Place ID is no longer valid. Please refresh cached Place IDs as per https://developers.google.com/maps/documentation/places/web-service/place-id#save-id
I have read this but I have no idea where to add a field they talk about and am totally stuck. All the reviews plugins have this place id and I don't know what to do from here.
Hoping for some help with what to do. In basic language.
Thanks in advance
I'm no expert; I ran into this problem myself and to my knowledge it seems like reviews can't be pulled easily with most plugins, if the GMB is set up as anything other than a location with a physical address.
Instead of the Places API you'd want to use the My Business API... although if you are using a plugin (and don't want to add a physical location to your GMB) you're stuck.

Woocommerce API whitout curl.. Is it possible?

I'm creating a plugin for Wordpress/Woocommerce and I was wondering if there is a simple way to call the Woocommerce API without going through the hassle of the whole REST API thing (curl, authentication, keys, secrets, etc). Since the code runs on the same server as Woocommerce it seems like a much easier and cleaner solution to just call some woocommerce function immediately.
So I'm looking for something like $myProducts = WC->getProducts();
Instead of having to make a Curl request to /wp-json/wc/v2/products
Is there a nice way to do this? Or is the next best option just to start querying the database (since this code is already somewhere in Woocommerce it seems a bit redundant to program it again)?
PS besides getting all the products I have a lot of other calls too so I'm looking for a general approach (the getProducts is just an example).
Hooray! I finally found a way to do this, thanks to this blog: https://blog.wallacetheme.com/wordpress-theme-rest-api
$request = new WP_REST_Request('GET', '/wc/v2/products');
$result = rest_get_server()->dispatch($request);
return $result->data;
This just bypasses the whole curl request.
Optionally you can use set_query_params and set_body_params for sending optional GET and POST data.

Create own customed URL shortener

I am currently trying to code out a simple asp.net URL shortener which allows me to customise the shortened url. I am also not allowed to use open source, which means I cannot use any of the url shortening services. I am required to develop on on my own.
But this is the first time I am doing this so i have no idea on how to start(excluding the UI).
I understand that there are already such questions being asked. But I've read through the posts and I couldn't understand what is it about. I've also tried to google for the solution but it doesn't seem to be working.
I would really appreciate any help given to me.
P.S I am fairly new in programming and not strong in any of the programming languages.
You would need:
A system to store pairs of shortened URLs and their full version.
A page which takes the shortened URL parameter (eg. short.aspx?q=SHORTENED), looks it up in your data store, and redirects to the full URL.
Some interface to edit your data store, add new URLs, etcetera.
That should be it really. If this is too difficult, it might be smarter to start on a basic programming course first.

Should an edit of a comment be sent through POST or PUT?

I have the following URI: Posts/{postId}/Comments/{commentId}
I would like to enable users to edit a comment through my API, should the edit be done with POST or PUT?
One one hand, POST updates the contents of a resource so that makes sense but on the other hand PUT replaces it with a new one. So if I understand correctly with POST I need to send only what needs to be updates and with PUT I send the whole resource.
Usually in edit forms, the whole resource is loaded anyway so what's the point of using POST?
If I take one approach or the other, what are the differences?
From what I have read (in RESTful Web Services, published by O'Reilly), it seems clear that you should use PUT to update an existing comment.
PUT is meant to be used for updating as well as creating a resource.
POST can also be used for creating a resource. The difference here is that when POSTing, you don't need to know the exact URI of the resource to be created. (The service will report the new resource's URI in its response.)
POST is appropriate for partial updates, or when appending information to a resource; PUT is appropriate for a full update (replacement) of a resource.
When updating, you can send partial updates, but you should make sure that these are idempotent; ie. if you send the same update more than once, the update will always have the same effect. Don't send an update such as "Increase n by 1"; instead, send an update such as "Set n to 5."
Thus, my suggestion for your case are as follows:
Use POST to /Posts/{postId}/Comments to create a new comment, since the client doesn't know the {commentId} in advance.
Use PUT /Posts/{postId}/Comments/{commentId} to completely update a comment (or perhaps POST when appending text to it).
see here:
PUT vs POST in REST

Resources