Есть плагин который разрабатывался для wp на localhost, все работае, время запускать
function new_woo_product( $array ){
//Use lib to create WOO API wrapper
require_once( 'lib/woocommerce-api.php' );
$normal_array = array();
$unserialize_array = unserialize( $array['img'] );
if( is_array($unserialize_array) ){
$plugins_url = plugins_url();
$i = 0;
foreach ( $unserialize_array as $value) {
//'images' => [['src' => 'http://localhost/wordpress/wp-content/plugins/sinco_mate/admin/partials/images/930004002734.jpg','position' => $i]],
array_push($normal_array, [
"src"=> "$plugins_url"."/sinco_mate/admin/partials/images/".$value,
'position' => $i
] );
$i++;
}
}
$data = array(
'title' => $array['title'],
'type' => 'simple',
'regular_price' => $array['regular_price'],
'sku' => $array['sku'],
'description' => $array['description'],
//'short_description' => '',
'images' => $normal_array,
//'categories' => $array['categories'],
'stock_quantity' => $array['stock_quantity'] || 0
);
$options = array(
'debug' => true,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 30,
'ssl_verify' => false,
);
try {
$site_url = site_url();
$client = new WC_API_Client( /* API */
$options
);
$track=$client->products->create( $data ) ;
} catch ( WC_API_Client_Exception $e ) {
echo $e->getMessage() . PHP_EOL . "</br>";
echo $e->getCode() . PHP_EOL . "</br>";
if ( $e instanceof WC_API_Client_HTTP_Exception ) {
print_r( $e->get_request() . "</br>" );
print_r( $e->get_response() . "</br>" );
}
}
return null;
}
На AWS сервере мне не дают скачать файлы в директории
Ошибка
ec2-13-54-177-254.ap-southeast-2.compute.amazonaws...
127.0.0.1 via TCP/IP Error: Error getting remote image ec2-13-54-177-254.ap-southeast-2.compute.amazonaws... [woocommerce_api_invalid_remote_product_image]
400
пробовал через
$plugins_url = plugins_dir();
но нужна именно ссылка
127.0.0.1 via TCP/IP Error: Error getting remote image /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/sinco_mate/admin/partials/images/930004002734.JPG. Error: A valid URL was not provided.. [woocommerce_api_invalid_remote_product_image]
400
Пробовал через .htaccess в корне wp открыть доступ к папке
...
# password protection allowing directory and file access
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user
SetEnvIf Request_URI "( /wp-content/plugins/sinco_mate/admin/partials/images/)$" allow
Order allow,deny
Allow from env=allow
Satisfy any
# END WordPress
Как такое победить?