Mini Shell
<?php
//version 1.0.7
header("Content-Type: application/json");
// requirements: install plugin : https://wordpress.org/plugins/featured-image-by-url/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('memory_limit', '-1');
error_reporting(E_ALL);
if(file_exists("wp-load.php"))require( 'wp-load.php' );
else require( '../wp-load.php' );
// $_DOMAIN_CLOUD = 'https://'.$_SERVER['HTTP_HOST'].'/';
// $_DOMAIN_CLOUD = 'https://i2.wp.com/';
$link = (isset($_GET['url'])) ? $_GET['url'] : 0;
// $extra_tags = (isset($_GET['extra_tags'])) ? explode(',', $_GET['extra_tags']) : array();
$querystr = "
SELECT DISTINCT meta_value
FROM $wpdb->postmeta
WHERE meta_key = 'source' AND meta_value = '".$link."'
ORDER BY meta_value ASC LIMIT 1
";
$post_source = $wpdb->get_results( $querystr, OBJECT );
if (!empty($post_source[0]->meta_value)){
$response = array();
$response[0] = array(
'link'=> $link,
'error'=> True,
'message'=> "Da import roi"
);
echo json_encode($response);
exit('exit source');
}
$context = stream_context_create(
array(
"http" => array(
"header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36\r\nContent-Type: application/json",
)
)
);
$data = file_get_contents($link, false, $context);
// echo $data;
$json_shopify = addslashes($data);
$json = json_decode( htmlspecialchars_decode($data), true );
$post = array(
'post_content' => $json['description'],
'post_name' => empty($json['handle'])?$json['handle']:sanitize_title($json['title']),
'post_title' => $json['title'],
'post_status' => 'publish',
'post_type' => 'product',
);
$wp_error = True;
$product_id = wp_insert_post( $post, $wp_error );
if (empty($product_id)) {
// echo "<pre>";
// var_dump($wp_error);
// echo "</pre>";
exit('failed: cannot import wp_insert_post');
}
//SET THE WOO PRODUCT TYPE
wp_set_object_terms($product_id, 'mmolazi_gearment', 'product_type'); // mmolazi for shopify json
update_post_meta($product_id, '_price', $json['price']);
update_post_meta($product_id, '_regular_price', $json['price']);
update_post_meta($product_id, 'source', $link);
update_post_meta($product_id, 'external_id', $json['external_id']);
$product_link = "https://".$_SERVER['HTTP_HOST'] . "?p={$product_id}";
// echo "success";
$response = array();
$response[0] = array(
'product_id' => $product_id,
'product_link'=> $product_link,
'error'=> False,
'message'=> $message
);
echo json_encode($response);