Recently, I have updated my site using an SSL and all URIs are now "https://".
My site is developed with Symfony 2 and mixing a Wordpress installation inside Symfony 2 web/wordpress directory.
All regular access is fine. Only one question:
In my Symfony 2, there is this code snippet:
private function getRecentPosts($num = 4)
{
require_once 'wordpress/wp-includes/class-IXR.php';
$user = '11111';
$pwd = '22222';
$host='https://www.rsywx.net';
$script='/wordpress/xmlrpc.php';
$port=443;
$client = new \IXR_Client($host, $script, $port);
$params = array(0, $user, $pwd, $num);
$client->query('metaWeblog.getRecentPosts', $params);
$wp = $client->getResponse();
return $wp;
}
When my site is not wrapped with https, the above code works fine. But now it is under https, the above code is not working. If I dump the $client variable after the query function call, it gives an error like:
+error: IXR_Error {#256 ▼
+code: -32300
+message: "transport error - could not open socket"
Any hints? Do I need to tweak my WP?
The problem was on the file wp-includes/class-IXR.php, it doesn't work with HTTPS, you must use also class-wp-http-ixr-client.php . And don't forget to include the configuration file wp-load.php.
The code snippet will be:
private function getRecentPosts($num = 4)
{
include 'wordpress/wp-load.php';
require_once ABSPATH . WPINC . 'wordpress/wp-includes/class-IXR.php';
require_once ABSPATH . WPINC . 'wordpress/wp-includes/class-wp-http-ixr-client.php';
$user = '11111';
$pwd = '22222';
//Deprecated
/*
$host='https://www.rsywx.net';
$script='/wordpress/xmlrpc.php';
$port=443;
$client = new \IXR_Client($host, $script, $port);
*/
$client = new WP_HTTP_IXR_CLIENT('https://www.rsywx.net/wordpress/xmlrpc.php');
$params = array(0, $user, $pwd, $num);
$client->query('metaWeblog.getRecentPosts', $params);
$wp = $client->getResponse();
return $wp;
}
I just avoided using XMLRPC at all to solve this.
In my Symfony 2 application, I just used a 2nd database to directly access the underlying wordpress database. It is a hack but it resolves my issue for the time being.
Related
I am currently working on an automated site creation function on my local installation of wordpress. In essence, a form is filled out on an already existing site and that info is pulled to create a new site automatically via an endpoint that activates some queries. So far I have been able to successfully pull the information into an array and then pass that to the wpmu_create_blog function. The issue is that the $domain isn't being called correctly(that is to say, how I intend it to be called), the '/' is lost between 'localhost' and 'wordpress'.
public function create_endpoint($request) {
$key = $request['key'];
if ($this->validate_key($key)) {
$newsite = array (
$title = $request['name'],
$path = $request['slug'],
$admin_user = $request['admin_user'],
);
$domain = 'localhost/wordpress';
$site_id = get_blog_id_from_url($domain, $path);
$user_id = get_user_by('login', $admin_user);
if ( !empty($title) and !empty($domain) and !empty($path) and empty($user_id) ) {
return wpmu_create_blog($domain, $path, $title, $user_id, $site_id);
}
else {
return "Not enough information";
}
}
else {
return $this->invalid_key_message;
}
}
Everything but the domain being called as intended is working as intended. This is also just the static prototype, my end goal is that this is entirely dynamic including the $domain variable.
I'm just totally lost on where to go from here. I've tried some appendage stuff and moving syntax around in all types of ways but keep hitting a wall. Any input or suggestions are happily accepted.
I have a solution implemented. In the array $path has been changed to $slug (use of slug is specific to my code). The $domain now only calls 'localhost' and I create $path using plain text the 'wordpress' and then add the slug via a $request.
$newsite = array (
$title = $request['name'],
$slug = $request['slug'],
$admin_user = $request['admin_user'],
);
$domain = 'localhost';
$path = 'wordpress/'.$request['slug'];
i have try to develop one api using WP.
Bellow is my testing code.
define( 'WP_USE_THEMES', false );
require_once(dirname(__FILE__).'/wp-load.php');
header('Content-Type: application/json');
wp();
$PiBy180 = 0;
$arr[0] = array("id"=>1,"name"=>"aaaa");
$arr[1] = array("id"=>2,"name"=>"bbbb");
echo json_encode($arr);die;
When i test it with postman it shows bellow output.
But if i comment require_once than i check it it works for me. But i need it becuase i have to call some wordpress function before i retun ajax json response. Please check bellow screenshot and code.
define( 'WP_USE_THEMES', false );
//require_once(dirname(__FILE__).'/wp-load.php');
header('Content-Type: application/json');
//wp();
$PiBy180 = 0;
$arr[0] = array("id"=>1,"name"=>"aaaa");
$arr[1] = array("id"=>2,"name"=>"bbbb");
echo json_encode($arr);die;
is there a way to load wp function without use require function. I have added custom file in my root folder of project.
Please suggest your solutions.
Finally i got solution.
I found that wp-load.php file include many other files and they file having having echo so just becuase of it return unwanted output. So finally i have made core php connection and access data from database and it works for me.
Here is my code.
ini_set("display_errors", 0);
$host='localhost';
$user='testuser';
$password='testpass';
$db='testdb';
$con = mysql_connect($host,$user,$password) or exit("Connection Error");
$connection = mysql_select_db($db, $con);
$query = "SELECT * FROM orders where customer_mail like '%".$_GET['jobs']."%' ORDER BY id DESC;";
$orderList = mysql_query ($query) or exit("The query could not be performed");
May be it help someone.
I set up a custom registration page to my http server (apache) which hosts a number of services, including a wiki.
The intended goal is to have the user sign-up at once to all these services including the wiki of course.
For the wiki I'm trying to rearrange the "CreateAndPromote" maintenance script and fit it into my page. By now I came up with this snippet
$path = "/wiki";
putenv("MW_INSTALL_PATH={$path}");
require_once ("/wiki/includes/WebStart.php");
chdir("wiki");
$mediaWiki = new MediaWiki();
$name = $_POST['username'];
$pass = $_POST['password'];
$user = User::newFromName( $name );
if ( !is_object( $user ) ) {
die("Invalid user!\n");
}
$exists = ( 0 !== $user->idForName() );
if ( !$exists ) {
$user->addToDatabase();
}
try {
$user->setPassword( $pass );
} catch ( PasswordError $pwe ) {
die("password error:" . $pwe->getText()."");
}
$user->addGroup("editor");
$user->saveSettings();
$ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
$ssu->doUpdate();
But i get
Error: LightnCandy class not defined
MediaWiki 1.25.2
PHP 5.6.12 (apache2handler)
The problem was simple as that:
declaring the MW_INSTALL_PATH like that apparently did not work
$path = "/wiki";
putenv("MW_INSTALL_PATH={$path}");
require_once ("/wiki/includes/WebStart.php");
so I had to change dir to the wiki BEFORE requiring the webstart.php
chdir("wiki");
require_once ("/includes/WebStart.php");
I have successfully setup the Quickbooks PHP DevKit, but I am currently trying to run the example_customer_add script with my sandbox. When I do, I get the following error:
Notice: Undefined variable: Context in /Applications/MAMP/htdocs/quickbooks-php/test_qb.php on line 54
I've tried to track down the $Context variable, but it is used all over the place, and I'm unsure of where it being set, etc...
Any help is appreciated! Thanks!
EDIT
I'm just using the script included in the docs folder of the Quickbooks PHP DevKit:
<?php
require_once dirname(__FILE__) . '/config.php';
require_once dirname(__FILE__) . '/views/header.tpl.php';
?>
<pre>
<?php
$CustomerService = new QuickBooks_IPP_Service_Customer();
$Customer = new QuickBooks_IPP_Object_Customer();
$Customer->setTitle('Ms');
$Customer->setGivenName('Shannon');
$Customer->setMiddleName('B');
$Customer->setFamilyName('Palmer');
$Customer->setDisplayName('Shannon B Palmer ' . mt_rand(0, 1000));
// Terms (e.g. Net 30, etc.)
$Customer->setSalesTermRef(4);
// Phone #
$PrimaryPhone = new QuickBooks_IPP_Object_PrimaryPhone();
$PrimaryPhone->setFreeFormNumber('860-532-0089');
$Customer->setPrimaryPhone($PrimaryPhone);
// Mobile #
$Mobile = new QuickBooks_IPP_Object_Mobile();
$Mobile->setFreeFormNumber('860-532-0089');
$Customer->setMobile($Mobile);
// Fax #
$Fax = new QuickBooks_IPP_Object_Fax();
$Fax->setFreeFormNumber('860-532-0089');
$Customer->setFax($Fax);
// Bill address
$BillAddr = new QuickBooks_IPP_Object_BillAddr();
$BillAddr->setLine1('72 E Blue Grass Road');
$BillAddr->setLine2('Suite D');
$BillAddr->setCity('Mt Pleasant');
$BillAddr->setCountrySubDivisionCode('MI');
$BillAddr->setPostalCode('48858');
$Customer->setBillAddr($BillAddr);
// Email
$PrimaryEmailAddr = new QuickBooks_IPP_Object_PrimaryEmailAddr();
$Customer->setPrimaryEmailAddr($PrimaryEmailAddr);
if ($resp = $CustomerService->add($Context, $realm, $Customer))
{
print('Our new customer ID is: [' . $resp . '] (name "' . $Customer- >getDisplayName() . '")');
}
else
{
print($CustomerService->lastError($Context));
}
?>
</pre>
<?php
require_once dirname(__FILE__) . '/views/footer.tpl.php';
The quickbooks_oauth table looks like this after attempting to connect:
'1', 'DO_NOT_CHANGE_ME', '12345', 'qyprdaX1yo1uYqu3GU8xxPvs8raoTss2ZVRBE3fHWy7qZdAB', 'IWZHlW2e956sqR9GVIxa2JOU82NdSrJixZLpb3af', 'KNwiKE2bUXtqFqJ/Vb0NhjzBGYMXwRRcT9xtFOQiV6F8aEgUoqGzA7aheRLPJ/z6EPYy1ZS4e6ZuVpteBaQtxc5H0cN5VcCmWLfj+lryaCpLgw8mGK5+E/Muv2wJ+3UwbOyqVstU+pYQw/yNgFKhfSuA3lOgjgqctuO6ZpMK1wWr42IycA05QrJuOB4+LQ==', 'rCj1V3zl4Jj5mHgTw+BPCPN7SDcJkzLQPWb1tyerEXedsQB0WsZ+caMCBafS+hfN3ECZl3mfNDSyIqKDK+t8RSEAKyFWwRSPOh3UcWDCDEhXrTSUddmKhoIq6pL6yVtNEyETyNtfMaKYN+U6uIwSEMKZB/4IUjK8c0GP5KhoKSl0dv+Bp9w=', '1391140255', 'QBO', NULL, '2015-06-04 19:57:58', '2015-06-04 19:58:36', '2015-06-04 19:58:36'
The code you posted is missing several lines at the top of the script. Look at the example on GitHub:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/example_customer_add.php#L3
There are two require_once statements that you are missing. $Context is defined in those required files.
require_once dirname(__FILE__) . '/config.php';
require_once dirname(__FILE__) . '/views/header.tpl.php';
Fix your code so that you're using the example code completely, and making sure those required files actually get included.
If you continue to have trouble, please post your updated code.
You can see where $Context gets defined here:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/config.php#L110
Note that you must be connected to QuickBooks to run the example. I'm assuming you have clicked the "Connect to QuickBooks" button and gotten connected already... right?
what i want to achieve is, user login in my wordpress website and also login on vanilla forum, i have installed jsconnect plugin in vanilla forum, and using the php's jsconnect library from following location jsConnectPHP
Here is my code:
require_once('functions.jsconnect.php');
$clientID = "1501569466";
$secret = "xxxxxxxxxxxxxxxxxxxxxx";
$userD = array();
if( isset($_POST['log']) ){
$data = array();
$data['user_login'] = $_POST['u_user'];
$data['user_password'] = $_POST['u_pass'];
$data['remember'] = TRUE;
$user = wp_signon($data, FALSE);
if(!is_wp_error($user)){
$userD['uniqueid'] = $user->ID;
$userD['name'] = $user->user_login;
$userD['email'] = $user->user_email;
$userD['photourl'] = '';
$secure = true;
WriteJsConnect($user, $_GET, $clientID, $secret, $secure);
$redirect = "http://localhost/vanilla/entry/jsconnect?client_id={$clientID}";
echo "<script>document.location.href='".$redirect."';</script>";
}
}
when the user login on wordpress i redirect it to jsconnect url in vanilla where i just found only a progress image, and can't figure out where is the problem..
jsconnect authentication url expects jsonp array like the following:
test({"email":"test#test.com",
"name":"testuser",
"photourl":"",
"uniqueid":1234,
"client_id":"12345678",
"signature":"XXXX"})
You authorization url you specify inside jsconnect should see this output to process further. In fact I am stuck at that point. I could see vanilla forum when loaded gets this input but no login happens.