• Hey WP friends, I need some help to figure out how to do accomplish this:

    1) I have a CRUD PHP app running inside a wordpress system, but quite independently, with its own tables and functions… It talks to wordpress and uses its front-end to show its tables. As it’s an admin platform, the whole website is private and protected by login/pass. Let’s call it ADMIN.

    2) The end-users interact to another wordpress website (another server, another db, another install). Let’s call it FRONT.

    3) Based on that interactions in FRONT, I need to send some data from FRONT to ADMIN and update my CRUD tables… the easiest way to get that data into my CRUD tables is passing variables to some URL, where I have my code to get it and query the CRUD db. A simple URL with parameters solve my problem, like myadmin.com/?param1=test&param2=test2

    4) The question is how to do it? Using WP API? POST method?(edited)

    Using WP API, I should do something like that, right?

    $remote_url = 'https://myadmin.com/';
    
    function post_remote( $remote_url ) {
    
           $headers    = array (
                 'Authorization' => 'Basic ' . base64_encode( 'my_login' . ':' . 'my_pass' ),
           );
    
           $body = array (
    			'param1' => 'test',
    			'param1' => 'test2',
    		);
    
           $response = wp_remote_post( $remote_url, array (
                        'method'      => 'POST',
                        'timeout'     => 45,
                        'redirection' => 5,
                        'httpversion' => '1.0',
                        'blocking'    => true,
    					'headers'     => $headers,
    					'body'        => $body,
    					'cookies'     => array ()
    					) );
    
    		if ( is_wp_error( $response ) ) {
                 $error_message = $response->get_error_message();
    			 echo sprintf( '<p class=”error”>Something went wrong: %1s</p>', $error_message );
    
    		} else {
    			echo 'Response:<pre>';
    			print_r ($response);
    			echo '</pre>';
    		}
    }
    
    post_remote( $remote_url );

    – I need to authenticate in ADMIN. Here I’m using Basic method for tests, but I know I should use OAuth (another step!).
    – I should call the URL with my parameters to send the data.

    Am I in the right way? Is there a way to know what is the final URL (with all stuff) this coding is generating? I suppose it’s a json style one, but I need to figure out how to retrieve that data in my ADMIN app…

    Any help?? Thanks!!

  • The topic ‘Sending data to another site using WP API’ is closed to new replies.