File size: 1.06Kb
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Rusnetim_API {
public static function get_api_url( $locale = null, $apikey = '' ) {
if ( ! $locale ) {
$locale = Rusnetim_Options::sanitize_locale( get_locale() );
}
$apikey_param = $apikey ? '&apikey=' . rawurlencode( $apikey ) : '';
return 'https://api-maps.yandex.ru/2.1/?lang=' . rawurlencode( $locale ) . $apikey_param;
}
public static function ajax_get_attachment_image() {
check_ajax_referer( 'rusnetim_ajax_nonce', 'nonce' );
if ( empty( $_POST['attachment_id'] ) ) {
wp_send_json_error();
}
$id = intval( wp_unslash( $_POST['attachment_id'] ) );
$image_url = wp_get_attachment_image_url( $id, 'thumbnail' );
if ( $image_url ) {
wp_send_json_success( array( 'url' => $image_url ) );
} else {
wp_send_json_error();
}
}
}
add_action( 'wp_ajax_rusnetim_get_attachment_image', [ 'Rusnetim_API', 'ajax_get_attachment_image' ] );