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 WordPress to return a 404 status | |
*/ | |
global $wp_query; | |
$wp_query->set_404(); | |
status_header( 404 ); | |
nocache_headers(); |
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 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 | |
/** | |
* WordPress - Store timestamp of a user's last login as user meta | |
*/ | |
function user_last_login( $user_login, $user ){ | |
update_user_meta( $user->ID, '_last_login', time() ); | |
} | |
add_action( 'wp_login', 'user_last_login', 10, 2 ); |
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 | |
/** | |
* 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 | |
/** | |
* 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 | |
/** | |
* Show WordPress custom post types on the main blog and archive pages | |
* | |
* @param WP_Query $query | |
**/ | |
function show_custom_post_types( $query ) { | |
// Show all custom post types on main blog and archive pages |
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
/** | |
* jQuery plugin that limits the number of characters that can be used in a text field. | |
*/ | |
(function( $ ){ | |
$.fn.limitInput = function( limit ) { | |
return this.each( function() { | |
$(this).keypress( function() { | |
if( $(this).val().length > limit ) { | |
$(this).val( $(this).val().substring(0, limit) ); | |
} |
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 | |
/** | |
* Test if a WordPress plugin is active | |
*/ | |
if ( is_plugin_active('plugin-directory/plugin-file.php') ) { | |
// the plugin is active | |
} |