How to post to WordPress without third party software
Posting without xml-rpc, email etc
I became obsess yesterday on how to post to WordPress without using the XML thing or email.
I was thinking about it while I was driving around in Paphos Cyprus in the traffic where technologically illiterate people dominate :)
People that they think that the computer works with magic or they know YouTube and they think that they are the TOP Scientists and think that is a waste of money to hire a skilled programmer to do the job. Anyway I got angry today because a man that I made a website for him demanded me do add more things without getting paid. Sorry I don't do charity.
Now enough with my issues :)
How to break things up!
Say hello to my little friend:
The web Browser object in Visual Basic. I don't know who designed but if you come to Cyprus I will buy you a beer!
Do the detective
We have to use WordPress HTML code to find our way....
A bit of Warning
The solution that I present here should not be used in a production environment. Its a slow code and will totally depend on bandwidth speeds to be faster.
This article is a proof of concept
How to post
Simple task, use the web Browser object to point to your WordPress administration login page.
Now open a Browser any will do but I prefer Chrome for this task.
You will probably see this
Now select the username and right click and select Inspect element
Now what you see must be similar to this
Our interest is the ID of the element.
Do the same for the password and the Log In button
Visual basic Code
Add a button to your form with the web browser object
WebBrowser1.Document.GetElementById("user_login").InnerText = "username"
WebBrowser1.Document.GetElementById("user_pass").InnerText = "password"
WebBrowser1.Document.GetElementById("wp-submit").InvokeMember("click")
And as you guested (probably) it will put your username and password and click the login button.
We managed to log in into the system. Lets get moving on how to post an article
first we need something to post.
So create two text boxes and name them title and body
now we need to navigate to the posting we will do this in one new button
so create a new button and double click it
and paste
WebBrowser1.Navigate("http://yourwebsite.com/wp-admin/post-new.php")
But why we don't use the same button.
It will not work for the moment as we have to wait for the page to load etc so we will use different buttons (i warned you above is a crappy code)
Do the detective and find the elements ID's that we will use for next!
or if you are lazy.......
So if you did that create another button and name it POST
and paste in the code
webBrowser1.Document.GetElementById("content-html").InvokeMember("click")
WebBrowser1.Document.GetElementById("content").InnerText = (bodyPOST.Text)
WebBrowser1.Document.GetElementById("title").InnerText = (titlePOST.Text)
WebBrowser1.Document.GetElementById("save-post").InvokeMember("click")
This is it!
You will now have a DRAFT post in your WordPress
I don't use the code to publish the post You are the detective use the method we talked about it above
If you think it was useful then share it on Facebook or anywhere that you think that someone will find it useful
use my code to build something amazing......
For any questions send me a comment (will need moderation before they show) as I answer to everyones comments (except for SPAM!)
Thank you
surprised there are no comments yet. Thanks for this!
ReplyDeleteHey that's a lot of money out there.
ReplyDeleteCan I please get the source code, so I'll play around with it to my own extents.
I'll be waiting.
Short answer No.
DeleteLong answer
Having an application read and analyse the data and transmit it to the server its a waste of time. It works but the problem can be solved by other means.
what i think now as a solution includes cron jobs. PHP and alot of time (time i dont have but i will try)
probably will not post my code just the methodology