Skip to content

Instantly share code, notes, and snippets.

@habibmac
habibmac / gist:2883102
Created June 6, 2012 16:33
WP: Wordpress profiling tools
if ( !defined('SAVEQUERIES') && isset($_GET['debug']) && $_GET['debug'] == 'sql' )
define('SAVEQUERIES', true);
if ( !function_exists('dump') ) :
/**
* dump()
*
* @param mixed $in
* @return mixed $in
**/
@habibmac
habibmac / gist:2883092
Created June 6, 2012 16:30
WP: Remove default Wordpress meta boxes
// REMOVE META BOXES FROM DEFAULT POSTS SCREEN
function remove_default_post_screen_metaboxes() {
remove_meta_box( 'postcustom','post','normal' ); // Custom Fields Metabox
remove_meta_box( 'postexcerpt','post','normal' ); // Excerpt Metabox
remove_meta_box( 'commentstatusdiv','post','normal' ); // Comments Metabox
remove_meta_box( 'trackbacksdiv','post','normal' ); // Talkback Metabox
remove_meta_box( 'slugdiv','post','normal' ); // Slug Metabox
remove_meta_box( 'authordiv','post','normal' ); // Author Metabox
}
add_action('admin_menu','remove_default_post_screen_metaboxes');
@habibmac
habibmac / gist:2883042
Created June 6, 2012 16:24
WP: Set a maximum number of post revisions to avoid DB bloat.
// Set the post revisions unless the constant was set in wp-config.php
if (!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS', 5);
@habibmac
habibmac / gist:2883040
Created June 6, 2012 16:23
WP: Delay the public posting to RSS Feed
// delay feed update
function publish_later_on_feed($where) {
global $wpdb;
if (is_feed()) {
// timestamp in WP-format
$now = gmdate('Y-m-d H:i:s');
// value for wait; + device
$wait = '10'; // integer
@habibmac
habibmac / gist:2883036
Created June 6, 2012 16:22
WP: Add Spam & Delete Links to Comments on Front End
// spam & delete links for all versions of wordpress
function delete_comment_link($id) {
if (current_user_can('edit_post')) {
echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&c='.$id.'">del</a> ';
echo '| <a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&dt=spam&c='.$id.'">spam</a>';
}
}
@habibmac
habibmac / gist:2883028
Created June 6, 2012 16:21
WP: Remove the WordPress Version Info for Security
// remove version info from head and feeds
function complete_version_removal() {
return '';
}
add_filter('the_generator', 'complete_version_removal');
@habibmac
habibmac / gist:2883013
Created June 6, 2012 16:19
WP: Loading jQuery from the Google CDN
// even more smart jquery inclusion :)
add_action( 'init', 'jquery_register' );
// register from google and for footer
function jquery_register() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', ( 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' ), false, null, true );
@habibmac
habibmac / untitled.php
Created June 6, 2012 15:47
WP: Include custom post types in the search results
// MAKE CUSTOM POST TYPES SEARCHABLE
function searchAll( $query ) {
if ( $query->is_search ) { $query->set( 'post_type', array( 'site', 'plugin', 'theme', 'person' ) ); }
return $query;
}
add_filter( 'the_search_query', 'searchAll' );
// ADD CUSTOM POST TYPES TO THE DEFAULT RSS FEED
// Add your custom post types to your sites main RSS feed by default.
function custom_feed_request( $vars ) {
@habibmac
habibmac / gist:2882639
Created June 6, 2012 15:28
WP: Modify the login logo & image URL link
// This code will allow you to easily modify the WordPress Login page Logo as well as the href link and title text of this logo.
add_filter( 'login_headerurl', 'namespace_login_headerurl' );
/**
* Replaces the login header logo URL
*
* @param $url
*/
function namespace_login_headerurl( $url ) {
$url = home_url( '/' );
@habibmac
habibmac / gist:2882625
Created June 6, 2012 15:26
WP: Enable hidden admin feature displaying ALL site settings
// CUSTOM ADMIN MENU LINK FOR ALL SETTINGS
// This little piece of code does something pretty cool. It will add an additional option to your settings menu with a link to "all settings" which will show you a complete list of all the settings you have within your database related to your wordpress site. The code below will only made this link visible to an admin user and hide it for all other users.
function all_settings_link() {
add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
}
add_action('admin_menu', 'all_settings_link');