How to call a plugin outside of Wordpress? - javascript

So, I need to call a plugin from outside my woocommerce websites. I have my own database that connects to Woocommerce throught REST API when it comes to products, orders and etc. My problem is, now I need to call a plugin on admin.php?page=pluginName&action=action&orderid=123456.The server that communicates with woocommerce is using classic ASP. I already tried to simply do a POST but of course wordpress asks me for login. I even tried to post it to a custom php page inside woocommerce and then post it to the plugin page but no success. Is there any way to call the plugin URL without having to login every time? It can be a php code inside my woocommerce FTP that recieves a POST with the order ID (the only query string that changes on each recordet) and then makes an AJAX POST to the plugin or something
Tried to create a custom PHP code to retrieve the POST and then do a wp_remote_post to the admin.php URL but nothing works. I just need to run the url, the plugin does the rest then

WordPress plugins rely on a lot of WordPress core code to function. Getting them to stand alone will be a LOT of work and your result will be brittle if you can get it to work at all. (Brittle === anything might break it, including a core or plugin update.)
WordPress's REST API is the best way to access WordPress, including plugin functionality, from some other network server. WooCommerce also supports REST, documented here. It offers an API key subsystem allowing secure authentication.
It's a programming task, but not unreasonably hard, to write a small plugin that adds a REST endpoint or two for a special purpose. But it's possible the one of the existing WooCommerce REST endpoints will serve your purpose. (You didn't tell us what it is, so it's hard to give more detailed advice.)

Related

Code needed for form to talk to phpmyadmin backend

I am creating a search form in wordpress using html and javascript. The form has dropdown menus which will have preselected items. These items come from the phpmyadmin(wordpress backend database). I'm having trouble writing the php code so the form talks to phpmyadmin backend. Does anyone have code for this?
John is right on that. PHP MyAdmin is a web based utility for accessing MySQL similar to WordPress which is a CMS. You will need to make queries to the backend database either directly(Not Advised) or to a web server. Wordpress has support for plugin databases built right in. Just gotta do a couple things.
Per The WordPress Site
Write a PHP function that creates the table.
Ensure that WordPress calls the function when the plugin is activated.
Create an upgrade function, if a new version of your plugin needs to have a different table structure.
WordPress - Creating Tables with Plugins
If you insist on writing it yourself you will need to setup a web server like Apache or nginx to listen to request and execute your PHP scripts.
PHP 5 Form Handling
PHP Connect to MySQL
and if you want to go dynamic
Ajax and JS, but you may want to use PostMan for testing.

Using a server to send/receive information between a mobile phone and web page

I am trying to set up a simple set up as follows:
Have a mobile app with a page consisting of 4 lines (4 html paragraph lines (I am using phonegap)).
I want to use a web page from which I will input the data for those 4 lines. This information is sent to a server and that server transfers this information to that app on that mobile phone. Now, those 4 lines on the mobile phone is filled with the new information.
Similarly user inputs information on another page consisting of 10 lines of li (list). This information is again sent to the server and to the web page where the information is displayed.
I can almost feel the "internet police guys" getting all hyped and ready to vote this question down. But please understand that I have been on this site and various forums desperate to find a tutorial to guide me to do this and not able to find.
I am trying to use ajax to perform this setup. Confused how I would be using the php file. Information such as password n username is going to go in that php file to connect to the server. But php is a server side script thus needs to sit at the public_html folder. How do I use the php file from my desktop? Write a separate javascript to access it?
It is the concept that is confusing me. I am familiar with html,js,php.
I would appreciate any guidance or maybe a link to a tutorial which would help me to do the concept I mentioned. Thanks for listening.
You will need to create an API using PHP. This API is uploaded to your server and is considered "RESTful". Google a tutorial for what fits your needs. You can set all sorts of rules in this API such as requiring any requests to have an ID or access token.
Since you are using PhoneGap, your HTML and JS files rest on the device, so you will need to allow permissions to your API from anywhere. For this you will have to speak to your host provider about unless you know how to configure it yourself (some providers restrict what you want to do by default as an extra security precaution against XSS attacks).
Next, you can either use jQuery, or you can write some AJAX calls by writing the JavaScript yourself.
The most efficient way for this to work is to send JSON objects to and from the API. You will include a "command" in the JSON when you are sending from your app. On the PHP side, you will retrieve this command and use the rest of the data included in your JSON object to process the request. Your API will need to encode a JSON object for return (such as a user's profile information).
Here is a basic PHP API tutorial to get you going that explains some of the features of a RESTful API: PHP API
Here is a simple AJAX function (you will probably want to make this much more modular): AJAX
As broad as your question is, it seems like the best/easiest thing for you to do will be for you to first create a PHP webpage that will access a SQL database to perform the record updating. Actually, this should serve all of your needs for your mobile users assuming you don't need push notifications for live data updates.
I am assuming, since you are using phone gap, that you are more comfortable with web languages. After you get the webpage fully operational, then you should start building your app based on that exact same SQL database. With mobile app development there are a lot more "what if's" (what if the phone rings, what if the app is running in the background, what if there is no cellular service, etc...)
It is always easier to start with what you know and build on that, rather than starting with a new development platform and troubleshooting as problems arise.

Can I use PHP SDK and JAVASCRIPT SDK at the same time?

I have a php program/app which asks for input, generate an image and post th image link to user's timeline (processor.php). I used PHP SDK in posting to timeline since I am more familiar with PHP. Now, in my gallery.php, i want to show like buttons for each generated image. I am aware that i have no option but use JS SDK in making button. but is it fine if i use two different SDK's in a single app?
processor.php - PHP SDK
gallerry.php - JS SDK
thanks for your answer! I would love to try your suggetions too
There shouldn't be any problem using PHP and JS in the same application, quite a common use case. You would normally use PHP to create the Web Application structure, handle backend logic, and then use JS to handle UI events.
There's nothing special about combining the two, just create the Web page with JS as normal for the view, and use PHP to build it.
Hope this helps.
Yes, there is no problem, the two APIs are designed to work together. The PHP API is usually used to created the backend logic (for example OAuth implementation, posting and getting data, etc) and the JS API to handle user iniated events.
Also see this: https://stackoverflow.com/a/6728092/1107118 on how to handle login state. Normally the JS API is used for logging in too, and then with the PHP API you take the access token and do the backend actions.

Get parameter from another page using javascript?

I have a wordpress site, and i'm not a php developer and not very eager to start either so I'm avoiding it like the plague, but I do have a requirement that requires a little bit of extra coding. I need to:
go to a different website,
download that page,
check for a certain phrase,
if phrase exists, extract a link from that page
and if link is returned I need to show that link on my wordpress site.
Currently, I have an asp.net page that does this and i'm hosting that page in an iframe on my wordpress site. but i'd like to do it without an iframe.
Question is, is there anyway for javascript to go to a different page (my asp.net page) and get a parameter (link) from it. If link is provided i will show certain content on wordpress site.
Or can javascript download a text file from the server? problem with that is i need a trigger to update the text file.
Any advice is appreciated.
Thanks.
What you should understand is that by "avoiding [PHP] like the plague" you're inadvertently avoiding the proper way of doing things. Javascript is a client-side language, and PHP is a server-side language. By asserting that you only want the load on the client's end (the kind of logic involved in what you want to do isn't exactly lightweight), you can potentially end up with a VERY slow webpage.
Not to mention, this type of situation is analogous to using a hammer to do a backhoe's job.
Either way, to answer your question, yes. You can use the jQuery Load method in tandem with Javascript's Match method.
What you should TRY to do, however, is make a CURL request using PHP, and then cache the page on your server. By doing this, you will limit the number of calls to a given page, and optimize load times.
Please consider the second option, even as an attempt in good practice. Good luck.
Use ajax and connect to a different page (on your server) which is written in server-sided language (like asp.net, as you said), that connects to the remote website.
More about Ajax

call live webservice from simple html page...?

I read lots of post here, but don't get specific answer.
I have live server on which I have my web services work properly.
now, I want to create one simple html page through which I call that web service.
with javascript this is possible but what is exact.
I repeat again only html and javascript through which I want to call that web service.
you can use jquery to load the data from webservice, but you might need to include jquery js file and your browser(IE) might prompt for security violation and you might need to click yes.

Categories

Resources