Skip to content

Instantly share code, notes, and snippets.

Miroslav Mitev m1r0

Block or report user

Report or block m1r0

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@m1r0
m1r0 / wp_insert_attachment_from_url.php
Last active Oct 29, 2019
WP: Insert attachment from URL
View wp_insert_attachment_from_url.php
<?php
/**
* Insert an attachment from an URL address.
*
* @param String $url
* @param Int $parent_post_id
* @return Int Attachment ID
*/
function crb_insert_attachment_from_url($url, $parent_post_id = null) {
@m1r0
m1r0 / gist:6048c9c8f55d86eb0d0e
Created May 2, 2014
PHP: Lat/Lng Distance Calculator
View gist:6048c9c8f55d86eb0d0e
function crb_calculate_location_distance($latitude1, $longitude1, $latitude2, $longitude2) {
$theta = $longitude1 - $longitude2;
$miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
$miles = acos($miles);
$miles = rad2deg($miles);
$miles = $miles * 60 * 1.1515;
// $feet = $miles * 5280;
// $yards = $feet / 3;
// $kilometers = $miles * 1.609344;
// $meters = $kilometers * 1000;
@m1r0
m1r0 / gist:8417210
Last active Dec 9, 2017
PHP-WP: Geocode address to lat and lng
View gist:8417210
function crb_get_lat_lng_by_address($address) {
$url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=' . urlencode($address) . '&sensor=false';
$transient_key = substr(md5($address), 0, 20);
$coords_cache = get_transient( $transient_key );
if ( $coords_cache !== false ) {
return $coords_cache;
}
You can’t perform that action at this time.