This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Takes an array of data and creates a csv file that will automatically download | |
*/ | |
function downloadable_csv( $data, $filename = 'data_csv' ){ | |
/* | |
Sample Data Format: | |
array( | |
'headings' => array(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Takes an array containing address elements and outputs a formatted address. | |
*/ | |
function get_formatted_address( $address, $args = array() ) { | |
$before = isset( $args['before'] ) ? $args['before']: ''; | |
$after = isset( $args['after'] ) ? $args['after']: ''; | |
$format = ( isset( $args['format'] ) && 'block' == $args['format'] ) ? 'block': 'inline'; | |
$formatted_address = ''; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Force SSL on pages in WordPress | |
*/ | |
function force_ssl(){ | |
if( !is_ssl() ){ | |
$url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
wp_redirect( $url, 301); | |
exit(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WordPress function for redirecting users on login based on user role | |
*/ | |
function my_login_redirect( $url, $request, $user ){ | |
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) { | |
if( $user->has_cap( 'administrator' ) ) { | |
$url = admin_url(); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* Take a multi-dimensional array in $_POST format and convert into an unordered list. | |
* | |
* @param $data | |
* @param array $args | |
* @return string | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WordPress shortcode allows you to create content that is visible only in your RSS feeds. | |
* | |
* Example: [feedonly]Dear RSS readers...[/feedonly] | |
*/ | |
function feedonly_shortcode( $atts, $content = null) { | |
if (!is_feed()) return ""; | |
return $content; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WordPress shortcode loads a PDF file on your site in an iframe using Google Docs. | |
* | |
* Example: [embed_pdf width="600px" height="500px"]http://infolab.stanford.edu/pub/papers/google.pdf[/embedpdf] | |
*/ | |
function embed_pdf($attr, $url) { | |
return '<iframe src="http://docs.google.com/viewer?url=' . $url . '&embedded=true" style="width:' .$attr['width']. '; height:' .$attr['height']. ';" frameborder="0">Your browser should support iFrame to view this PDF document</iframe>'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WordPress shortcode only displays content to registered users. Could be improved by | |
* passing role as an attribute to only allow certain types of users. | |
* | |
* Example: [member]This text will be only displayed to registered users.[/member] | |
*/ | |
function members_only_shortcode( $atts, $content = null ) { | |
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) |