How to get the post_id after you successfully create new post using xmlrpc api wp newPost?

Note: The WP REST API might be a better alternative. Client Let’s assume we use the built-in WP_HTTP_IXR_CLIENT (see e.g. my previous answer): include_once( ABSPATH . WPINC . ‘/class-IXR.php’ ); include_once( ABSPATH . WPINC . ‘/class-wp-http-ixr-client.php’ ); $client = new WP_HTTP_IXR_CLIENT( ‘https://example.tld/xmlrpc.php’ ); $result = $client->query( ‘wp.newPost’, [ $blog_id = 0, $user = “user”, // … Read more

JSON API and notification about registration

Set your query var notify to user (if you want to send an email to the user only) or both (if you want to send it to the user and the admin). Within the plugin controller/User.php:165 calls wp_new_user_notification with $_REQUEST[‘notify’]. wp_new_user_notification is (lucky you) a pluggable function. If you have your activation logic ready to … Read more

How to convert and use JSON data from a remote WordPress server?

On server B: $result = wp_remote_post(‘http://serverA.com/?api=json’, array( ‘method’ => ‘POST’, ‘redirection’ => 1, ‘httpversion’ => ‘1.0’, ‘blocking’ => true, ‘headers’ => array(), ‘body’ => array(), ‘cookies’ => array() )); if ( is_wp_error( $result ) ) { return ‘bad connection!’; } $json = $result[‘body’]; $posts = json_decode($json); Now you have $posts as usual php array. var_dump($posts) … Read more

WP REST API and Access-Control-Allow-Origin

I found a .htaccess solution, but I will be happy if anyone know a working PHP solution. It’s my .htaccess with multiple domain access support and access for only GET request: # CORS Headers <ifModule mod_headers.c> SetEnvIf Origin “^http(s)?://(.+\.)?(localhost:8080|example\.com|example\.net)$” origin_is=$0 Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is Header always set Access-Control-Allow-Methods “GET” Header always set Access-Control-Allow-Headers … Read more

Integrating API in to WordPress

this line IS your php inlcude path: require_once(dirname(__FILE__) . ‘path_to ChargeBee.php’); you need to change it to something specific to your coding. ie: are you putting this into a theme or a plugin? ( would suggest a plugin) If that were the case you would use something like this: require_once( CHARGEBEEPLUGIN_DIR . ‘/lib/chargebee.php’ ); this … Read more

How to add an endpoint for my custom post type? /wp-json/wp/v2/posts is working but it didn’t in the custom post

The “register_rest_field” function will add and handle data update for a given endpoint, looks like it’s not what you are looking for. The register_post_type() function accepts a “show_in_rest” and “rest_base” params if you want to use a custom slug for the endpoint: https://codex.wordpress.org/Function_Reference/register_post_type By default it uses the WP_REST_Posts_Controller class to handle the methods (get, … Read more

How to fix AWS SNS API end point code that cause site not to load?

The root cause is this: function sns_endpoint_data() { // this line caused the site not to load $message = Message::fromRawPostData(); /* additional code follows… */ } add_action( ‘template_redirect’, ‘sns_endpoint_data’ ); There is no if condition checking if this is indeed the URL you desired to do this on. As a result, the Message::fromRawPostData() will load … Read more

Save external API calls in WordPress

Mark, I’ve had to do something similar for multiple jobs. This is a larger topic but I’ll try break it down in steps and hopefully gets you going in the right direction. I’ve broken the code into steps and outlined them here: if (isset($_POST[‘submit’])) { $example = $_REQUEST[‘example’]; $result = $customcontact->lookupByName( $example ); /** API … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)