Creating Endpoint For Directorist Plugin

So I am trying to find out how the structure of directorist function looks like. And this is what I got.

 Array
        (
            [name] => All American Lock and Key
            [details] => It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout
            [tagline] => Donec pede justo fringilla vel
            [price] => 2525
            [price_range] => high
            [atbdp_post_views_count] => 25
            [excerpt] => 
            [location] => london
            [tag] => food
            [category] => Cafe
            [hide_contact_info] => 0
            [address] => My geo location
            [manual_lat] => 40.7143528
            [manual_lng] => -74.0059731
            [hide_map] => 
            [zip] => 369659
            [phone] => 59589585298
            [phone2] => 548548596xxxx
            [fax] => 562552
            [email] => example@gmail.com
            [website] => https://example.com
            [listing_prv_img] => https://demo.directorist.com/plugin/directorist-sample-data/6_.jpg
            [videourl] => https://www.youtube.com/watch?v=DGQwd1_dpuc&t=4s
            [fm_plans] => 
            [claimed_by_admin] => 
        )

This can easily be translate to:

$data = array(
'name'=>'Name',
'details'=>'hello',
'tagline'=>'Hello world',
'price'=>'20',
'price_range'=>'high/low',
'atbdp_post_views_count'=>'0',
'address'=>'where you stay',
'manual_lat'=>'2.23',
'manual_lng'=>'239',
'hide_map'=>'',
'excerpt'=>'',
'location'=>'',
'tag'=>'',
'category'=>'cafe',
'hide_contact_info'=>0,
'hide_map'=>'',
'zip'=>'123455',
'phone'=>'123',
'phone2'=>'123',
'fax'=>'123',
'email'=>'you@email.com',
'website'=>'https://hello.com',
'listing_prv_img'=>'image.png',
'videourl'=>'youtube.com',
'fm_plans'=>'',
'claimed_by_admin'=>''
);

So with the above, I created an endpoint for directorist plugin.

To post remotely, lets say from here, I can use this function: kh_post_directorist ($data)


function kh_post_directorist($data){
	$the_post='';
	foreach ($data as $item=>$value){
    $the_post .= $item.'='.urlencode(apply_filters('kh_directorist_before_input',$value)).'&';
	}
	$the_post  = rtrim($the_post ,'&');

	$args_post = array(
       'method' => 'POST',
        'timeout' => 45,
        'redirection' => 5,
        'httpversion' => '1.1',
        'blocking' => true,
    	'body'        => $the_post,
    	'sslverify' => false,
    	'headers'     => array(
    		'Content-type' => 'application/x-www-form-urlencoded'
    	  ),
      'cookies' => array() 
	);

	$response = wp_remote_post( 'https://yourdomain.com/json/', $args_post );
	$res = $response['body'];

	return $res;
}

add_filter('kh_directorist_before_input','kh_post_directory_filter');
function kh_post_directory_filter($text){
	return $text;
}

I will need to have the data. The simplest demo is to put the data in an array

$fieldsthing = array(
  'name' => 'The Hero',
  'details' => 'Hero is a hero who eats chicken',
  'tagline' => 'The hero champion',
  'price' => '30',
  'pricerange' => 'low',
  'address' => 'Wherever you go',
  'lat' => '23',
  'lng' => '55',
  'summary' => 'He is a chicken',
  'location' => 'Singapore',
  'tag' => 'power ranger,hero',
  'category' => 'Superman',
  'zip' => '123233',
  'phone' => '928384848',
  'fax' => '38474374',
  'email' => 'ahahah@aewf.com',
  'website' => 'https://yest.com',
  'image_url' => 'https://e64rk75q2rv.exactdn.com/wp-content/uploads/2022/12/XJT2LJ4XJZWR62B7N2QT.jpg',
  'youtube_url' => 'https://www.youtube.com/watch?v=kwtHOkf7Jdg',
  'token' => 'ojoewfef4ow3jfweoi4'
);

kh_post_directorist($fieldsthing);

Similar Posts