Vypnutí komentářů u WP media příloh

/—code php
function filter_media_comment_status( $open, $post_id ) {
$post = get_post( $post_id );
if( $post->post_type == ‚attachment‘ ) {
return false;
}
return $open;
}
add_filter( ‚comments_open‘, ‚filter_media_comment_status‘, 10 , 2 );
\—

„Zdroj »“:http://www.wpbeginner.com/wp-tutorials/how-to-disable-comments-on-wordpress-media-attachments/

Užitečné hooks & filters

**Modify post title when some string exists in the post content**
Add lock icon if there is a member shortcode present in the post content.
Without *$post->ID == $id* not only post title is changed but also menu items and next/previous links.

/—code php
function modify_title($title, $id) {
global $post;
$content = $post->post_content;
if(strpos($content, ‚[member]‘) AND $post->ID == $id) {
$theme_dir = get_bloginfo(‚stylesheet_directory‘);
$lock = ‚ ‚;
$new_title = $title.$lock;
return $new_title;
} else {
return $title;
}
}
add_filter(‚the_title‘, ‚modify_title‘, 10, 2);
\—

**Add extra contact methods to user profiles**

By default, WordPress allow users to enter an AIM name on their profile, but no Facebook and no Twitter names!
In order to add more contact methods to user profile, simply paste this hook in your functions.php file. In this example it will add Facebook and Twitter, but it can be used for any website or service you need.

/—code php
function my_user_contactmethods($user_contactmethods){
$user_contactmethods[‚twitter‘] = ‚Twitter Username‘;
$user_contactmethods[‚facebook‘] = ‚Facebook Username‘;

return $user_contactmethods;
}

add_filter(‚user_contactmethods‘, ‚my_user_contactmethods‘);
\—

**Automatically enable threaded comments**

By default, WordPress do not enable threaded comments. If you want/need to change this, here is a handy code snippet to paste in your functions.php file:

/—code php
function enable_threaded_comments(){
if (!is_admin()) {
if (is_singular() AND comments_open() AND (get_option(‚thread_comments‘) == 1))
wp_enqueue_script(‚comment-reply‘);
}
}

add_action(‚get_header‘, ‚enable_threaded_comments‘);
\—

**Automatically replace words in your posts**

/—code php
function replace_text_wps($text){
$replace = array(
// ‚WORD TO REPLACE‘ => ‚REPLACE WORD WITH THIS‘
‚wordpress‘ => ‚wordpress‚,
‚excerpt‘ => ‚excerpt‚,
‚function‘ => ‚function
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}

add_filter(‚the_content‘, ‚replace_text_wps‘);
add_filter(‚the_excerpt‘, ‚replace_text_wps‘);
\—

**Quick maintenance mode**

/—code php
function cwc_maintenance_mode() {
if ( !current_user_can( ‚edit_themes‘ ) || !is_user_logged_in() ) {
wp_die(‚Maintenance, please come back soon.‘);
}
}
add_action(‚get_header‘, ‚cwc_maintenance_mode‘);
\—

„Zdroj »“:http://www.catswhocode.com/blog/super-useful-wordpress-action-hooks-and-filters

**Přidání boxu pro excerpt (stručný výpis) i do stránek**

/—code php
function enable_page_excerpt() {
add_post_type_support( ‚page‘, ‚excerpt‘ );
}
add_action(‚init‘, ‚enable_page_excerpt‘);
\—

**Deaktivace HTML v komentářích**

/—code php
add_filter(‚pre_comment_content‘, ‚wp_specialchars‘);
\—

„10 Useful WordPress Hook Hacks »“:“http://www.smashingmagazine.com/2009/08/10-useful-wordpress-hook-hacks/

Nastavení jiného jazyka pro web (frontend) a jiného pro administraci

**User Language Switch**
„https://wordpress.org/plugins/user-language-switch/“:https://wordpress.org/plugins/user-language-switch/

Allows backend users to set the language displayed in the back-end and front-end of your site. It also allows to translate pages and posts. Define one language for admin and the other for theme. **Don’t** define WPLANG in your wp-config.php file.

A nebo:

/—code php
// setup one language for admin and the other for theme
// must be called before load_theme_textdomain()
function set_my_locale($locale) {

$locale = ( is_admin() ) ? „cz_CS“ : „en_US“;
setlocale(LC_ALL, $local );
return $locale;

}
add_filter( ‚locale‘, ‚set_my_locale‘ );
\—

Úprava RSS kanálu pomocí hooku

„Action hooks and filter hooks »“:http://codex.wordpress.org/Plugin_API

„Vysvětlení a příklady »“:http://wpcandy.com/teaches/how-to-use-wordpress-hooks/

„All plugin hooks in WordPress 3.5 »“:http://adambrown.info/p/wp_hooks/version/3.5

/—code php
###################################################################################
# tento hook prida do RSS thumbnail, odstrani iframe a urizne obsah za tagem „more“
###################################################################################

function improveRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = “ . get_the_post_thumbnail( $post->ID, ‚rss-thumbnail‘, array( ‚style‘ => ‚margin:0; border: 10px solid #202020‘ ) ) . “ . $content;
}

$content = preg_replace( ‚//is‘, “, $content );

$teaser = preg_split( ‚/<\/span>/‘, $content );
$readmore = ‚Více na webu »‚;
$content = $teaser[0].$readmore;
return $content;
}

add_filter(‚the_excerpt_rss‘, ‚improveRSS‘);
add_filter(‚the_content_feed‘, ‚improveRSS‘);
\—