Skip to content

Instantly share code, notes, and snippets.

@cgrymala
cgrymala / gist:5901462
Created July 1, 2013 14:46
JetPack developer constant - avoid connecting to WP.com
define( 'JETPACK_DEV_DEBUG', true );
@cgrymala
cgrymala / gist:5950109
Created July 8, 2013 16:01
Old method of getting lat & long from Google Maps marker
// Get the latitude and longitude of the search result
lat = Math.round( lat * 100000 ) / 100000;
long = Math.round( long * 100000 ) / 100000;
for ( var i = 0; i < limit; i++ ) {
// Retrieve the latitude and longitude of the marker
var markLat = Math.round( markers[i].position.Ra * 100000 ) / 100000;
var markLong = Math.round( markers[i].position.Sa * 100000 ) / 100000;
// Compare the search result to the current marker
@cgrymala
cgrymala / gist:5950168
Created July 8, 2013 16:09
New method of retrieving latitude and longitude from a Google Maps marker
// Retrieve the latitude and longitude of the search result
lat = Math.round( lat * 100000 ) / 100000;
long = Math.round( long * 100000 ) / 100000;
for ( var i = 0; i < limit; i++ ) {
// Retrieve a new LatLng object for the marker
var markLatLng = markers[i].getPosition();
// Retrieve the latitude and longitude of the marker, separately
var markLat = Math.round( markLatLng.lat() * 100000 ) / 100000;
var markLong = Math.round( markLatLng.lng() * 100000 ) / 100000;
@cgrymala
cgrymala / remove-jetpack-sharing-filter.php
Created November 14, 2013 17:21
Brief example showing how to remove a filter (in this case, the "Sharing" buttons that JetPack outputs at the end of content) within WordPress.
<?php
function output_featured_image() {
echo '<figure class="featured-image">';
the_post_thumbnail( 'archive-feature', array( 'class' => 'alignnone' ) );
// First, check to see if the Sharing buttons are supposed to display on content or excerpt
// Remove those sharing buttons if they are
$sharecontent = false;
$shareexcerpt = false;
if ( has_filter( 'the_content', 'sharing_display' ) ) {
@cgrymala
cgrymala / class-sample-plugin.php
Created June 24, 2014 15:19
Registering a New Options Page in WordPress
<?php
if ( ! class_exists( 'Sample_Plugin' ) ) {
class Sample_Plugin {
var $text_domain = 'sample_plugin';
var $options_page_slug = 'sample-options-page'; /* Because you will use this in a lot of places, we'll define it here */
function __construct() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
function admin_menu() {
@cgrymala
cgrymala / class-sample-plugin.php
Last active August 29, 2015 14:02
Registering a New Setting in WordPress
<?php
if ( ! class_exists( 'Sample_Plugin' ) ) {
class Sample_Plugin {
var $text_domain = 'sample_plugin';
var $options_page_slug = 'sample-options-page'; /* Because you will use this in a lot of places, we'll define it here */
function __construct() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) );
}
@cgrymala
cgrymala / two-backgrounds.css
Created August 26, 2014 00:46
Apply two BGs to Executive Pro Genesis Theme
body {
background: url(my-main-image.png);
}
.site-container {
width: 100%;
max-width: 100%;
background: url(my-secondary-image.png);
}
.site-header,
.site-inner,
@cgrymala
cgrymala / element-test.js
Created October 4, 2014 14:26
Check if an element exists in JavaScript
/**
* Check to see if an element exists in the page
* Avoids potential XSS attack outlined in https://eamann.com/tech/jquery-xss/
* @see https://eamann.com/tech/jquery-xss/
*/
function doesElementExist( el ) {
try {
var tmpLen = document.querySelectorAll( el ).length;
if ( 0 < tmpLen ) {
return true;
@cgrymala
cgrymala / keybase.md
Created February 5, 2015 17:42
Keybase Identity Proof

Keybase proof

I hereby claim:

  • I am cgrymala on github.
  • I am cgrymala (https://keybase.io/cgrymala) on keybase.
  • I have a public key whose fingerprint is CD74 D412 8F46 B475 3502 596F 907D 518E 88AF 87A1

To claim this, I am signing this object:

@cgrymala
cgrymala / no-subscriber-admin.php
Created February 12, 2015 20:28
Keep Subscribers Out of the WP Admin Area
<?php
add_action( 'admin_init', 'hide_backend_from_user' );
/**
* Hide the backend from specific user levels
* @uses VFH_User_Controls::$options['login_redirect_to'] to determine where the user should be redirected
* @uses VFH_User_Controls::$user_levels to see if the user needs to be redirected
*/
function hide_backend_from_user( $level='edit_posts' ) {
/**
* Attempt not to short-circuit AJAX requests