WordPress funkcie

// dispay all hidden WP options

add_action('admin_menu', 'all_settings_menu');
function all_settings_menu() {
add_submenu_page('options-general.php', 'All Settings', 'All Settings', 'administrator', 'options.php');
}

 

// disable admin bar < WP 3.3

add_filter( 'show_admin_bar', '__return_false' );
remove_action( 'personal_options', '_admin_bar_preferences' );

 

// disable WP admin bar for all users but admins

if (!current_user_can('administrator')):
show_admin_bar(false);
endif;

 

// disable admin bar WP 3.3

function wps_admin_bar() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo');
$wp_admin_bar->remove_menu('about');
$wp_admin_bar->remove_menu('wporg');
$wp_admin_bar->remove_menu('documentation');
$wp_admin_bar->remove_menu('support-forums');
$wp_admin_bar->remove_menu('feedback');
$wp_admin_bar->remove_menu('view-site');
}
add_action( 'wp_before_admin_bar_render', 'wps_admin_bar' );

 

// hide WP version in header

remove_action('wp_head', 'wp_generator');

 

// 60 * 10, auto-saves every 10 minutes

define('AUTOSAVE_INTERVAL', 600);

 

// disable autosave

function no_autosave() {
wp_deregister_script('autosave');
}
add_action( 'wp_print_scripts', 'no_autosave' );

 

// disable revisions – wp-config.php

define('WP_POST_REVISIONS', false);

 

// maximum 5 revisions per post – wp-config.php

define('WP_POST_REVISIONS', 5)

 

// disable visual editor

add_filter('user_can_richedit' , create_function('' , 'return false;') , 50);

 

// email notify members on new posts

function email_members($post_ID) {
global $wpdb;
$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
$users = implode(",", $usersarray);
mail($users, "New WordPress recipe online!", 'A new recipe have been published on http://www.wprecipes.com');
return $post_ID;
}
add_action('publish_post', 'email_members');

 

// empty trash every 5 days – wp-config.php

define('EMPTY_TRASH_DAYS', 5 );

 

// change email header

function res_fromemail($email) {
$wpfrom = get_option('admin_email');
return $wpfrom;
}
function res_fromname($email){
$wpfrom = get_option('blogname');
return $wpfrom;
}
add_filter('wp_mail_from', 'res_fromemail');
add_filter('wp_mail_from_name', 'res_fromname');

 

// change role capalities – important: the capabilities are written to the database, so if you want to give back a capability to a user role, you have to use the add_cap function to reverse the removal (and, vice versa, use remove_cap if you want to remove a capability you added in this fashion).

$edit_contributor = get_role('contributor'); // Get the user role
$edit_contributor->add_cap('upload_files'); // Contributor can now upload media
$edit_contributor->remove_cap('delete_posts'); // Contributor can no longer delete posts

 

// loading jQuery from Google

if (is_admin()) {
}
else {
wp_deregister_script('jquery');
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"), false, '1.3.2', true);
wp_enqueue_script('jquery');
}

 

// time user message

if ((date('m') == 12) && (date('d') == 25)) { ?>
<h2>Merry Christmas!</h2>

 

// user contact form info profil

function new_contactmethods( $contactmethods ) {
$contactmethods['twitter'] = 'Twitter'; // Add Twitter
$contactmethods['facebook'] = 'Facebook'; // Add Facebook
unset($contactmethods['yim']); // Remove Yahoo IM
unset($contactmethods['aim']); // Remove AIM
unset($contactmethods['jabber']); // Remove Jabber
return $contactmethods;
}
add_filter('user_contactmethods','new_contactmethods',10,1);

 

// redirect after login

add_action('login_form', 'redirect_after_login');
function redirect_after_login() {
global $redirect_to;
if (!isset($_GET['redirect_to'])) {
$redirect_to = get_option('siteurl');
}
}

 

// remove default WordPress widgets

function unregister_default_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Text');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Recent_Posts');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_RSS');
unregister_widget('WP_Widget_Tag_Cloud');
unregister_widget('WP_Nav_Menu_Widget');
unregister_widget('Twenty_Eleven_Ephemera_Widget');
}
add_action('widgets_init', 'unregister_default_widgets', 11);

 

// disable theme and plugin editors from WP admin panel – wp-config.php

define( 'DISALLOW_FILE_EDIT', true );

 

// add theme editor in WP admin bar

function admin_bar_theme_editor_option() {
global $wp_admin_bar;
if ( !is_super_admin() || !is_admin_bar_showing() )
return;
$wp_admin_bar->add_menu(
array( 'id' => 'edit-theme',
'title' => __('Edit Theme'),
'href' => admin_url( 'theme-editor.php')
)
);
}
add_action( 'admin_bar_menu', 'admin_bar_theme_editor_option', 100 );

 

// add log in/out links to a specific WP menu

add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
}
return $items;
}

 

// automatically set the featured image

function autoset_featured() {
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
}
}
} //end function
add_action('the_post', 'autoset_featured');
add_action('save_post', 'autoset_featured');
add_action('draft_to_publish', 'autoset_featured');
add_action('new_to_publish', 'autoset_featured');
add_action('pending_to_publish', 'autoset_featured');
add_action('future_to_publish', 'autoset_featured');

 

// home url

get_home_url();

 

// url template directory

echo get_template_directory_uri();

 

// site url

echo site_url();