Forum Replies Created

Viewing 15 replies - 121 through 135 (of 213 total)
  • Thread Starter aryanduntley

    (@dunar21)

    Yup

    Thread Starter aryanduntley

    (@dunar21)

    <?php
    $ch = curl_init();
    // Disable SSL verification
    //application/javascript
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    // Will return the response, if false it print the response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    // Set the url
    //curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    //curl_setopt($ch, CURLOPT_USERPWD, $creds);
    curl_setopt($ch, CURLOPT_URL,$url);
    //curl_setopt($ch, CURLOPT_COOKIEJAR, ‘/tmp/cookies.txt’);
    //curl_setopt($ch, CURLOPT_COOKIEFILE, ‘/tmp/cookies.txt’);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    //$fjj = base64_encode($username.”:”.$password);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(“Content-Type:application/json”, “Accept:application/json”, ‘Authorization:Basic ‘. base64_encode($username.”:”.$password)));
    //base64_decode base64_encode(
    //curl_setopt($ch, CURLOPT_HEADER, 1);
    //curl_setopt($ch, CURLOPT_POST, true);
    //curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER[‘HTTP_USER_AGENT’]);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    /*$parameters = array(
    //’ID’ => [ <post id> ]
    ‘content_raw’ => ‘some stuff about the fake post’,
    //’post_name’ => slug,
    ‘title’ => ‘FAKER POST’,
    ‘status’ => ‘publish’,
    ‘type’ => ‘post’,//post_type
    ‘author’ => ‘6140’,
    //’ping_status’ => ,
    //’post_parent’ => ,
    //’menu_order’ => ,
    //’to_ping’ => ,
    //’pinged’ => ,
    //’post_password’ => ,
    //’guid’ => ,
    //’post_content_filtered’ => ,
    //’post_excerpt’ => ,
    //’post_date’ => ,
    //’post_date_gmt’ => ,
    //’comment_status’ => ‘open’,
    //’post_category’ => array(),
    //’tags_input’ => ‘tag,tag,tag’,
    //’tax_input’ => array(‘{taxonomy}’ => ” or array()),
    //’page_template’ => ,

    ); */
    /*$userparams = array(
    ‘test_pass’ => ‘fakerpasw’,
    ‘test_login’ => ‘FAKERUNAME’,
    //’test_nicename’ => ”,
    ‘test_email’ => ‘[email protected]’,
    //’test_display_name’ => ,
    //’test_nickname’ => ,
    ‘test_first_name’ => ‘FAKEGUEY’,
    ‘test_last_name’ => ‘FAKINGNAME’,
    ‘test_usermeta’ => array(
    ‘address’ => ‘123 fake st.’,
    ‘city’ => ‘KA’,
    ‘state’ => ‘US’,
    ‘postalcode’ => ‘92109’,
    ‘mobilenum’ => ‘123-456-7890’,
    ‘carrier’ => ‘npt’,
    ‘dob’ => ‘1/2/13’,
    ‘sex’ => ‘male’,
    ‘wanttext’ => ‘no’,
    ‘colorwant’ => ‘pink’
    )
    );*/
    //$parameters = $userparams;
    //$json = json_encode($parameters);

    //$postArgs = ‘data=’ . $json;
    //curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    // Execute
    $result=curl_exec($ch);
    $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $allinf = curl_getinfo($ch);
    curl_close($ch);
    var_dump(json_decode($result, true));//print_r($result);
    echo “some br tags”;
    echo $http_status . “some br tags”;
    print_r($allinf);

    Thread Starter aryanduntley

    (@dunar21)

    Uhm, without going into the method of trying to send the same data via an ajax call, instead, all you have to do is put that into a php file, and use ajax to call that php file. So, you have ajax.js which calls middleman.php. middleman.php has the cul code you have listed, gets the data back into a variable and spits it out into the underverse where the ajax call can retrieve it and do with the returned data as you desire.

    Thread Starter aryanduntley

    (@dunar21)

    I have received no update notification via WP and the version remains 0.8 on the wp plugins page. Should I download again and replace manually (have you made the changes without and updated version #)? I’ll download again and compare the files. (downloaded from github and see changes.) I’ve got to take care when swapping files in order to catch any conflicts with my api extensions that are already in place, and I’m currently vacationing in Thailand, so I’ll get back to you when I can.

    Thread Starter aryanduntley

    (@dunar21)

    Thanks

    Plugin Author aryanduntley

    (@dunar21)

    Plugin Author aryanduntley

    (@dunar21)

    Thanks for finding this bug. I’ll incorporate it in a release. I no longer actively maintain this plugin, but I have no problem updating when people find important things that could improve performance.

    Yeah, I don’t think you are completely familiar with the methods you are trying to use or the api you are using. There is nothing you can’t do with the api that is available in wordpress. It is not complete and has it’s limitations as is, but it can be extended to do whatever you want. I’ll sign off this thread. Good luck.

    You can try filtering the prepare posts method in the posts class:

    return apply_filters( ‘json_prepare_post’, $_post, $post, $context );

    If the post class is just too off base for what you need specifically, you can always create a new class like I mentioned here (last few posts):

    http://ww.wp.xz.cn/support/topic/registration-and-examples?replies=5

    You can also create your own server class (hook available in plugin.php) and manipulate to produce desired results (copy the default server class, rename, then hook):

    $wp_json_server_class = apply_filters(‘wp_json_server_class’, ‘WP_JSON_Server’);

    You can also directly call the response method in the server class (via a custom method in a custom/extended class):
    public function prepare_response($data) {}

    Are you using the json rest api just to have an ajax frontend with no loading? This is not being used to view and manipulate data from external calls such as a mobile device? You don’t need this plugin at all to create a javascript front end. All you need is a combination of wp-ajax and get_template_part (as one of probably hundreds of ways of doing this). The api is extreme overkill and a separation from native wordpress use for just creating a js front-end, no reloading.

    Thread Starter aryanduntley

    (@dunar21)

    FYI, the media is uploaded during a new post entry. It’s done at the bottom of insert_post in the ‘json_insert_post’ hook. That hook is declared in plugin.php and calls ‘attachThumbnail’ in the wp-json-media class. Looking at that class, it seems as though there is an expected media id as a parameter in the data object[‘featured_image’]. This doesn’t seem to make a whole lot of sense unless it is expected that media must first be uploaded via the /media endpoint, the media id retrieved, then the media id provided as a data parameter in the new or updated post. Seems kind of round-about, but I’m not sure whether they can both be done at the same time. I will investigate and post here with finding for anyone interested.

    insert_post does not have new metadata insert with either new or updated posts. I created the class in the previous post and added: apply_filters(‘json_insertadd_postmeta’, $post_ID, $data, $update); after if ( is_wp_error( $post_ID ) ). It needs to be added here because you don’t need to add meta to a post id that doesn’t exits. So, if there is no error and you have a valid post id, you can add the filter for json_insertadd_postmeta. I am only passing $data and not $post because the $data variable will contain the meta by whatever method you choose to have it sent. In your hook, you will be able access that data and the post id and with those variables, update whatever post meta is passed in whatever way you feel is necessary.

    Thread Starter aryanduntley

    (@dunar21)

    For those of you having some trouble with the metadata and such for posts and types, until the final release is ready and so you don’t have to edit source files, create a duplicate of the class-wp-json-posts.php file and call it something else. Change the class name, then include it in your extensions function like listed below. Then you have to unhook the posts class call and rehook it to your new class. Now you can edit that file and not worry about updates interfering. You can now add meta data, allow for featured image uploads with posts (looking now, but don’t think it’s there yet), etc…

    function custom_class_api($server) {
    	global $userreg_api, $wp_json_posts;
    	require_once('wp-json-extend-regstr.php');
    	require_once('wp-json-extend-customposts.php');
    	remove_filter( 'json_endpoints', array( $wp_json_posts, 'registerRoutes' ), 0 );
    	$userreg_api = new User_NRegist($server);
    	$wp_json_posts = new MyCustom_Posts($server);
    	add_filter( 'json_endpoints', array($uderreg_api, 'registerRoutes') );
    	add_filter( 'json_endpoints', array($wp_json_posts, 'registerRoutes'), 0 );
    }
    add_action( 'wp_json_server_before_serve', 'custom_class_api' );

    I don’t know where the plugin author has gone to. I’m online looking now at the GSoC Tracker and elsewhere to try and see if he’s still working on this project or whether it needs to be taken over by someone else.

    As far as your question, looking at the source, all you need to pass is the file, so posting the file to wp-json/media should get the file inserted into the uploads folder and listed in media attachments. As far as passing additional data, the code uses wp_read_image_metadata.

    So the title and description can be tied into the actual image file’s metadata, here’s his comment: // use image exif/iptc data for title and caption defaults if possible. If no title is passed that way, the title will be the name of the file.

    I have no idea how to attach this metadata to the file itself. There is some info on how to do it programatically here: http://ww.wp.xz.cn/support/topic/adding-exif-fields-to-wp_read_image_metadata , but if you are sending the file via the api, this is not what you want. If you figure out more, please post.

    Yeah, this plugin is “planning” on being added to the core. Not so sure that’s going to happen, but I feel the same way… better safe than sorry. If you want to do something custom, just extend the api with a class and do whatever you want with it. For an example of extending it, I wrote an extension to allow user registration. You can see the code here: http://ww.wp.xz.cn/support/topic/registration-and-examples?replies=3

    You don’t have to rely on any limitations or restrictions when doing it that way, just be sure that you are careful about who is logging in, gathering and using your parameters correctly, etc…

    If you don’t know, you probably don’t need it. Still, it’s a rest api. That’s about as simple as it gets. Google rest api to find out what that is and what it does. When you click the “like” button for a post anywhere and it shows up on facebook as a “like” that was a rest api (the now use the graph api, but it essentially is good enough to describe what the rest api does). The rest api allows external applications to access data and otherwise have a means of interfacing with your wordpress site.

Viewing 15 replies - 121 through 135 (of 213 total)