Skip to content

Instantly share code, notes, and snippets.

@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 / jetpack-override-genesis-favicon.php
Created February 13, 2015 14:36
Allow JetPack to control your WordPress site's favicon instead of Genesis
<?php
/**
* The 'genesis_pre_load_favicon' filter runs at the beginning of the genesis_load_favicon() function.
* If the value returned by that filter ends up as anything except boolean false, Genesis bails on the
* genesis_load_favicon() process.
*/
add_filter( 'genesis_pre_load_favicon', 'check_jetpack_site_icon_status' );
function check_jetpack_site_icon_status() {
/**
* If the JetPack module is active and a JetPack Site Icon has been set,
@cgrymala
cgrymala / cwa-modify-js-args.php
Created July 13, 2015 14:07
Modify Collapsible Widget Area arguments to use "content" height style instead of "auto"
<?php
/**
* Sets the heightStyle argument for all accordion widget areas
* @see http://api.jqueryui.com/accordion/#option-heightStyle
*/
add_filter( 'collapsible-widget-javascript-arguments', 'my_theme_modify_cwa_js_args' );
function my_theme_modify_cwa_js_args( $args = array() ) {
/**
* Loop through all of the existing Collapsible Widget Areas
*/
@cgrymala
cgrymala / cwa-filter-usage-reference.php
Last active August 29, 2015 14:24
Usage Examples for Collapsible Widget Area Filters
<?php
/**
* Example usage of the collapsible-widget-ui-theme filter
* We set the priority to 10, and tell WordPress that the callback function should receive 2 arguments
* @see http://codex.wordpress.org/Function_Reference/add_filter
*/
add_filter( 'collapsible-widget-ui-theme', 'my_theme_cwa_ui_theme', 10, 2 );
function my_theme_cwa_ui_theme( $theme, $opt=null ) {
/**
* Set a custom jQueryUI theme specifically for use with our WordPress theme
@cgrymala
cgrymala / jetpack-allow-native-oembed.php
Created July 21, 2015 16:39
Removes the [youtube] and [vimeo] shortcodes from JetPack Shortcode Embeds module
<?php
/**
* Filter the list of JetPack shortcodes to remove the YouTube and
* Vimeo shortcodes from the list
* @param array $shortcodes a numerically-indexed array of the absolute
* paths to the shortcode definition files
* @return array the filtered array
*/
function jetpack_allow_native_youtube_vimeo_oembeds( $shortcodes ) {
$good_shortcodes = array();
@cgrymala
cgrymala / wpe-ssl-port-fix.php
Created September 1, 2015 14:07
Attempt to fix the way CASMaestro/phpCAS on WPEngine sends the application URL to the CAS server
<?php
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
if ( isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) && ! empty( $_SERVER['HTTP_X_FORWARDED_PORT'] ) ) {
$ports = explode(',', $_SERVER['HTTP_X_FORWARDED_PORT']);
error_log( 'The forwarded Port var is set to: ' . $ports[0] );
} else if ( isset( $_SERVER['SERVER_PORT'] ) && ! empty( $_SERVER['SERVER_PORT'] ) ) {
error_log( 'The server Port var is set to: ' . $_SERVER['SERVER_PORT'] );
$_SERVER['SERVER_PORT'] = 443;
}
}