Wordpress XMLRPC advice needed - wordpress

I have been tasked with creating an API for retrieving and adding content to Wordpress from a flash application and legacy CMS (non-PHP). My plan is to utilise the existing default xmlrpc endpoint and add any additional functionality by creating a plugin which hooks into xmlrpc_methods.
A previous attempt had been made by another developer based on the following code:
http://blog.5ubliminal.com/posts/remote-control-wordpress-blog-xmlrpc-api/
This code looks unwieldy and poorly documented to me and my preference would be to use this approach:
http://kovshenin.com/archives/custom-xml-rpc-methods-in-wordpress/
I would be grateful if anyone with experience in this area could confirm that:
I will be able to distinguish between separate blogs in an MU installation when both retrieving and posting data via XMLRPC
I will be able to retrieve and post to custom fields
writing a plugin is the way to go.
We do not have the option of using Wordpress 3 as it is still in Beta and we are under time pressure.
I would greatly appreciate appreciate any input / advice.
Many thanks,

I've worked with WordPress' XMLRPC system before (using a WP-Hive installation with multiple separate blogs similar to a WPMU set-up). The new approach you're using is definitely simpler and easier to implement (I tried the 5ubliminal one as well the first time).
Whether or not you can distinguish between separate blogs in a MU installation depends entirely on how you build your handler function. You can build it to distinguish the separate blogs, to only function on specific blogs, or to treat the entire system as a single WordPress site. It's all up to you.
By "handler function" I mean a custom function you define to handle XMLRPC requests that call a specific, custom method (not necessarily the default WordPress methods). For example, I use XMLRPC in all my plug-ins to report back installation progress and errors -
each plug-in makes an XMLRPC call to a custom handler (method) on my server.
Yes, you can retrieve and post to custom fields.
Absolutely writing a plug-in is the way to go. The only other options are to change core files (BAD idea) or to build it into your theme, in which case it could ONLY be used on MU sites using that theme. Build it as a site-wide MU plug-in that can be controlled on a site-by-site basis by the global admin.

Wordpress XMLRPC offers various functionalities which can be harvested easily. I have used IXR_Library to parse the XML requests/responses. Currently with very small piece of code i can easily posts, fetch, edit and delete Posts in Wordpress based blogs either self hosted or on wordpress.com sites.
http://www.hurricanesoftwares.com/wordpress-xmlrpc-posting-content-from-outside-wordpress-admin-panel/ (reference)
When you have multiple blogs hosted via MU you will need site ID of all those blogs which will become the first parameter for $params (in our case 0 should be replaced with site_id).
In the reference i gave above you will see the option to fetch and post to all created custom fields (unfortunately, you can't create custom fields on the fly from my script)
You are welcome to write a WP plugin to do all of this, be my guest and let me know if you need my help. I have used the same technique to post to blogger, tumblr, Wordpress and Posterous using their API's. I hope this helps.

Related

Separate plugins or one giant plugin on WP

I’m building a WP plugin to enhance a website, and come to an interrogation with the workflow.
Basically, I have to create a custom post type, assorted with several custom taxonomies, which will be used/displayed on the frontend and backend, and create a backend section in order to interact with our CRM, and Supabase via their respective APIs (service centralisation).
All of the second part is only intended to be used/displayed on the admin section, to logged users.
However, when creating/saving a custom post type, or when viewing it from the frontend, I have to make a GET request to the CRM to fetch some data and store it in JSON somewhere (24h cache).
That I can do.
At the moment, I worked on the CPT part, and made a class to interact with the CRM, with credentials stored in wp_options. I now have to work on the backend part.
My question is: what are the best practices here? Keep it in a single plugin or divide into several plugins?
And if I divide, how should I turn it? 2 plugins, one for the CPT and one for the backend? Or go even deeper, and get the CRM and Supabase their own simple plugin, and call their methods to make my requests?
I am short of ideas here, so if you encountered this situation, could you enlighten me?

using woocommerce api locally

I'm creating a wordpress plugin that communicates with woocommerce installed on the same wordpress site. I noticed that the rest api requires ssl to use, but it seems like ssl locally is not possible and oauth is a pain in the ass.
Is there a way to develop for woocommerce locally without having ssl that doesn't use oauth?
I would recommend beginning by throwing out the idea of calling back to a local site over any HTTP/S protocol. That is almost never the right decision.
Instead, woocommerce has extended the WordPress hook/filter system into themselves: https://docs.woocommerce.com/document/introduction-to-hooks-actions-and-filters/. This allows you to inject/extend yourself throughout woocommerce without making a cludgy callback system. I don't know what you want/need to do, but I can guarantee the hooks should probably get you all the functionality you will need.
If you truly do need to make API calls back. You basically won't be able to develop locally (without a lot of effort setting up a local server environment). Instead set up a development environment on a separate server.
I assumed this is a mostly php plugin running on the server. If instead this will be serving a lot of javascript to the frontend, then you will have to use the REST API, and you will have to get some development server up with ssl.
Update: based on comment below expounding on purpose. I assume you figured out to add the 'sales goal' information as post meta to the woocommerce product. Here's a quick introduction to post meta if you need it: https://dsgnwrks.pro/how-to/what-is-post-meta-an-intro-to-wordpress-custom-fields/. This would be the best practice for adding information to the products.
For the proportion of sales to the goal. You will first need a function to get the total sales to date on this product. Here is a gist that hooks into woocommerce_single_product_summary and gets the post_meta total_sales on the current product. You should be able to use a similar scheme to get both total_sales and your sales_goal post meta and then just display the ratio in whatever way you choose.
Note: You may need to attach to a different hook. Or you may even need to get the current product a different way (maybe specified by the widget?) to get ahold of the post_meta.

Translating Wordpress based on user language cookie

Currently have a wordpress installation. I've created .mo files with translations but dont want to use wp-config.php to change the language. I want the language to change for the front end (for things such as "posted by:" etc) based on cookie we are creating when the user switches their language. I can't seem to find any way to do this. Is there a hook somewhere in wordpress where we can show the translations based on user cookie?
Wordpress has already this functionality built in using the gettext utility., with a lot of plugins to facilitate the process for you .
One of the best is with no doubt the qTranslate plugin, which offers a lot of hooks and custom functions and operates in much the same way like you described. And it is free.

Virtual pages for my plugin

I am currently in the process of making a WordPress Plugin which is going to parse some external data (products) from various web services and present them as normal pages in WordPress.
I would like to avoid actually creating the pages programatically and instead just generate them on the fly to avoid any synchronization issues if a product is deleted and so forth.
My plugin is going to have a base url in which it will hook on to, for example /products/,
and then I would generate each product page by calling /products/some-product-name/.
I also anticipate the need for uri's like /products/category/some-category-name/ which I will use to list all items in that category.
Since I am new to WordPress plugin development, I am looking for some tips and advice to get me started on the right foot. Any help is highly appreciated ;)
I suppose it really depends on where/how you're getting your info from these web services, but I can imagine that the easiest way would be to setup a page as a controller and have it parse out some RSS or XML to build these "virtual pages" by request, so that you're not storing anything in the DB and if the info requested doesn't exist than yes 404 it.
I solved this by adding a filter to rewrite_rules_array and an action catching template_redirect.

How can I sign in a Wordpress (mu) user from outside of Wordpress?

I'm working for a company that is using Wordpress MU to supplement other functions on a member site. We have a user signup process that creates the appropriate Wordpress MU users and blogs on signup, but I'm having real trouble figuring out how to log someone in to a WP blog from outside of Wordpress itself. The documentation these methods seem to be non-existent or just too obtuse for me.
In the abstract I know how to do it: Take user info, set the same cookie that Wordpress would set itself. Done. It is, however, not this simple.
Has anyone done this successfully before?
I've been able to log people into Wordpress, however I'm was running inside Wordpress. (I was inside a theme)
Basically, the tough part is getting all the hashes correct, because Wordpress uses a set of defined security hashes in the config file to create the cookie. Ideally you should be able to copy and paste the functions that Wordpress uses.
Yes Wordpress documentation for security sucks, but that is what you get in a Open Source application, not stellar documentation.
What you are looking for is the wp_set_auth_cookie function in the /wp-includes/pluggable.php file. You should look into what the do_action()s actually do, but you should be able to simply replace all the constants with the correct values, and you'll have a function that can port anywhere on the domain.
Hey, it's not so tough task, once you are using correct instruments ;)
Try XML-RPC

Resources