Skip to content

Instantly share code, notes, and snippets.

View wildiney's full-sized avatar

Wildiney Di Masi wildiney

View GitHub Profile
@wildiney
wildiney / wp_add_admin_bar_trash_menu.php
Created June 22, 2011 16:59
WordPress - Snippet to add a trash button on admin bar on Wordpress
<?php
/* Insert into functions.php on WordPress */
add_action('admin_bar_menu', 'fb_add_admin_bar_trash_menu', 35);
function fb_add_admin_bar_trash_menu(){
global $wp_admin_bar;
if(!is_super_admin() || !is_admin_bar_showing()){
return;
}
@wildiney
wildiney / .htaccess
Created June 28, 2011 14:31
.htaccess - Redirecting to a custom page errors
ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html
@wildiney
wildiney / gist:1051250
Created June 28, 2011 14:32
.htaccess - Registering Errors on PHP
# display no errors to user
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
# log to file
php_flag log_errors on
php_value error_log /location/to/php_error.log
@wildiney
wildiney / functions.php
Created June 28, 2011 14:35
WordPress - Count comments by author
<?php
function commentCount() {
global $wpdb;
$count = $wpdb->get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . get_comment_author_email() . '"');
return $count . ' comments';
}
/* USAGE */
/*
<?php echo commentCount(); ?>
*/
@wildiney
wildiney / functions.php
Created June 28, 2011 14:46
WordPress - Put your site in Maintenace mode
<?php
function maintenance_mode() {
if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
wp_die('Maintenance, please come back soon.');
}
}
add_action('get_header', 'maintenance_mode');
?>
@wildiney
wildiney / functions.php
Created June 28, 2011 14:52
WordPress - Enable buttons cut, copy and paste on Tiny MCE Buttons
<?php
function enable_more_buttons($buttons) {
$buttons[] = 'copy,cut,paste';
return $buttons;
}
add_filter("mce_buttons_2", "enable_more_buttons");
?>
@wildiney
wildiney / functions.php
Created June 28, 2011 14:53
WordPress - Add custom button on admin bar
<?php
function mytheme_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'parent' => 'new-content', // use 'false' for a root menu, or pass the ID of the parent menu
'id' => 'new_media', // link ID, defaults to a sanitized title value
'title' => __('Media'), // link title
'href' => admin_url( 'media-new.php'), // name of file
'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' );
));
@wildiney
wildiney / functions.php
Created June 28, 2011 15:59
WordPress - Add trash button to admin bar
<?php
function fb_add_admin_bar_trash_menu() {
global $wp_admin_bar;
if ( !is_super_admin() || !is_admin_bar_showing() )
return;
$current_object = get_queried_object();
if ( empty($current_object) )
return;
if ( !empty( $current_object->post_type ) &&
( $post_type_object = get_post_type_object( $current_object->post_type ) ) &&
@wildiney
wildiney / yourfile.php
Created June 28, 2011 16:02
WordPress - Add custom edit post link
<?php if(current_user_can('administrator')){ ?>
<a href="<?php bloginfo('url');?>/wp-admin/edit.php?p=< ?php the_ID(); ?>">Edit Post</a>
<?php } ?>
}
@wildiney
wildiney / buttons.css
Created June 28, 2011 16:13
CSS3 Buttons
.button, .button span {
display: inline-block;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.button {
white-space: nowrap;
line-height:1em;
position:relative;