Skip to content

Instantly share code, notes, and snippets.

@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: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: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: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: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:2883110
Created June 6, 2012 16:34
WP: Customize the order of the admin menu
// CUSTOMIZE ADMIN MENU ORDER
function custom_menu_order($menu_ord) {
if (!$menu_ord) return true;
return array(
'index.php', // this represents the dashboard link
'edit.php?post_type=events', // this is a custom post type menu
'edit.php?post_type=news',
'edit.php?post_type=articles',
'edit.php?post_type=faqs',
'edit.php?post_type=mentors',
@habibmac
habibmac / gist:2883112
Created June 6, 2012 16:35
WP: Custom user profile fields
// CUSTOM USER PROFILE FIELDS
function my_custom_userfields( $contactmethods ) {
// ADD CONTACT CUSTOM FIELDS
$contactmethods['contact_phone_office'] = 'Office Phone';
$contactmethods['contact_phone_mobile'] = 'Mobile Phone';
$contactmethods['contact_office_fax'] = 'Office Fax';
// ADD ADDRESS CUSTOM FIELDS
$contactmethods['address_line_1'] = 'Address Line 1';
@habibmac
habibmac / gist:2883120
Created June 6, 2012 16:36
WP: Change the length of excerpt
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');
@habibmac
habibmac / gist:2883123
Created June 6, 2012 16:37
WP: Remove pings to your own blog
//remove pings to self
function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );
@habibmac
habibmac / gist:2883133
Created June 6, 2012 16:38
WP: Customize the Dashboard
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
// Remove these dashboard widgets...
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);