Skip to content

Instantly share code, notes, and snippets.

@davidsword
davidsword / google-map-geocode-form.html
Last active February 27, 2018 19:10
A simple script to get the geo coordinates of a location via Google Map API
<input type="text" name="location_meta[address]" placeholder="Street Address" value="">
<input type="text" name="location_meta[city]" placeholder="City" value="">,
<input type="text" name="location_meta[prov]" placeholder="State/Prov" value="">,
<select name="location_meta[country]">
<option value='CA'>🇨🇦</option>
<option value='US'>🇺🇸</option>
</select><br>
<input type="text" name="location_meta[postal]" placeholder="Postal/Zip" value="">
<button data-get-geo-cords>Click here to get Lat/Lng from address above</button>
@davidsword
davidsword / distance calculator for google maps.php
Created February 15, 2018 22:33
get the distance between two user supplied geo locations with google maps api. includes location suggestions in input dropdown.
<?php
<h3>KM Calculator</h3><?php
$key = '************-******************************';
$thispage = '?'; // ex https://localhost/index.php
if (isset($_GET['from'])) {
$from = urlencode($_GET['from']);
$to = urlencode($_GET['to']);
@davidsword
davidsword / remote-ftp-status.less
Last active March 18, 2019 16:14
Atom - better visual que to show if Atoms's RemoteFTP plugin is connected
.status-bar-left .ftp-statusbar-view {
.icon {
color: white !important;
position: relative;
z-index: 2;
&:after {
content: "";
display: block;
position: absolute;
width: 30px;
@davidsword
davidsword / WP-disable-widgets.php
Last active March 18, 2019 16:17
WordPress - Disable default widgets
<?php
/**
* Disable default Widgets
*
* @see https://digwp.com/2014/02/disable-default-dashboard-widgets/
*/
add_action('wp_dashboard_setup', function () {
global $wp_meta_boxes;
@davidsword
davidsword / WP-async-enqued.php
Last active March 18, 2019 16:19
WordPress - Make `wp_enqueue`'d scripts async.
<?php
/**
* Set all enqueued scripts except jQuery to include the `async` attribute.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#Attributes
*/
add_filter('script_loader_tag', function ($tag, $handle) {
if ( 'jquery' !== $handle )
return $tag;
@davidsword
davidsword / WP-gf-place-resources-in-footer.php
Created February 8, 2018 21:15
Put gravity form scripts and styles in footer
<?php
add_action('admin_menu', function () {
$parent_slug = 'edit.php?post_type=page'; // "Pages"
$page_title = 'My Plugin Submenu Page';
$menu_title = 'My Plugin Submenu Page';
$capability = 'edit_pages';
$menu_slug = 'myplugin-submenu-page';
$page = 'myplugin_submenu_page';
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $page);
@davidsword
davidsword / WP-redirect-a-shortcodes-url-attr.php
Created February 8, 2018 20:56
redirect the page based on the shortcode attribute
<?php
add_shortcode( 'pdf_redirect', function ( $atts ) {
$a = shortcode_atts( array(
'url' => '',
), $atts );
// instructions in case of misuse
if (empty($a['url']))
return "<pre>Please assign a destination for the PDF redirect, [pdf_redirect url='https://yourpdfurl...']</pre>";
@davidsword
davidsword / WP-media-and-library-items.php
Created February 8, 2018 20:54
two functions to: extract a posts media items, and extract all library items. can use to compare
<?php
function myplugin_find_media($content) {
$mediaRegex = "/(src|href)=\"(.+?).(jpg|png|pdf|gif)\"/i"; // your support filetypes
$mediaFind = preg_match_all($mediaRegex, $content, $media);
if (isset($media[2]) && count($media[2]) > 0)
return $media[2];
@davidsword
davidsword / WP-custom-notice-after-new-post.php
Last active May 18, 2018 17:36
show a custom message/notice after a NEW WordPress post has been published.
<?php
add_action('admin_notices', function(){
$screen = get_current_screen();
$editPostScreen = ($screen->parent_base == 'edit' && $screen->post_type == 'post') ? true : false;
$justPublished = (isset($_GET['message']) && $_GET['message'] == '6') ? true : false;
if ($editPostScreen && $justPublished) {
$class = 'notice notice-info';