Rychlá nebo hromadná editace uživatelských polí

**Saving custom fields in quick or bulk edit mode in WordPress**
„http://wpdreamer.com/2012/03/manage-wordpress-posts-using-bulk-edit-and-quick-edit/“:http://wpdreamer.com/2012/03/manage-wordpress-posts-using-bulk-edit-and-quick-edit/

One of the most cool features when managing WordPress posts, is the ability to batch edit multiple posts at once or quickly edit one post to perform a simple task such as adding a tag. Learn how to extend WordPress’ Quick Edit and Bulk Edit to retrieve and save the value of your custom fields.

**Plugin Custom Bulk/Quick Edit**
„http://wordpress.org/plugins/custom-bulkquick-edit/“:http://wordpress.org/plugins/custom-bulkquick-edit/
„https://github.com/michael-cannon/custom-bulkquick-edit“:https://github.com/michael-cannon/custom-bulkquick-edit
„How do I add custom fields to my bulk/quick edit page »“:https://aihrus.zendesk.com/entries/24800411-How-do-I-add-custom-fields-to-my-bulk-quick-edit-page-
„How do you configure options »“:https://aihrus.zendesk.com/entries/24911342

Pozor, do functions.php *může* být nutné přidat:

/—code php
add_filter( ‚manage_post_posts_columns‘, ‚my_manage_post_posts_columns‘ );
function my_manage_post_posts_columns( $columns ) {
$columns[‚custom_field_name‘] = esc_html__( ‚Nazev sloupce v administraci‘ ); // pozor, název sloupce musí být bez diakritiky
return $columns;
}
\—

a teprve **po přidání** tohoto kódu je třeba zpřístupnit pole v nastavení pluginu.

Nástroj pro přesun WordPressu jinam

When you’re migrating WordPress (or any other platform using serialized PHP strings in the database) between domains, you must use a safe search and replace method that preserves the integrity of the serialized string lengths. A simple of a dump file for http://localhost to, for example, http://thenewdomain.com is problematic because the length of the string changes but the indexes for the serialized strings does not. Consequently settings are lost and widgets disappear. Not good.

This script can now also handle multiply nested serializations, which can happen in transient values in WP at times, and it can also handle multi-byte Unicode changes safely. This is important now that internationalised domain names are allowed.

It’s worth mentioning that the code will work for any platform that stores PHP serialized arrays in a MySQL database. You can easily use this script on Drupal, Joomla and many other systems where you need to change items across a database without messing up your stored arrays.

„Search & Replace DB »“:http://interconnectit.com/products/search-and-replace-for-wordpress-databases/

*Související*

**How to Move WordPress to a New Server (without losing anything)**
„http://www.sitepoint.com/move-wordpress-new-server-without-losing-anything/“:http://www.sitepoint.com/move-wordpress-new-server-without-losing-anything/

Vyloučení rubriky ze zobrazení přes the_category()

Může se hodit, když nechceme zobrazovat např. nadřazenou rubriku, ale jen podrubriky. Umístíme do functions.php.
/—code php
function the_category_filter($thelist,$separator=‘ ‚) {
// seznam ID rubrik, které se nemají zobrazit
$exclude = array(4, 5);
// create an empty array
$exclude2 = array();

// loop through the excluded IDs and get their actual names
foreach($exclude as $c) {
// store the names in the second array
$exclude2[] = get_cat_name($c);
}

// get the list of categories for the current post
$cats = explode($separator,$thelist);
// create another empty array
$newlist = array();

foreach($cats as $cat) {
// remove the tags from each category
$catname = trim(strip_tags($cat));

// check against the excluded categories
if(!in_array($catname,$exclude2))

// if not in that list, add to the new array
$newlist[] = $cat;
}
// return the new, shortened list
return implode($separator,$newlist);
}

add_filter(‚the_category‘,’the_category_filter‘, 10, 2);
\—

Dohledávání v anglických slovnících a thesaurech

Např. pro „TheFreeDictionary“:http://thefreedictionary.com/ do functions.php přidáme shortcode:

/—code php
function tfd_lookup($atts)
{
$keyword = $atts[‚0‘];
$output = ‚‚ . $keyword . ‚‚;
return $output;
}

add_shortcode(‚tfdl‘, ‚tfd_lookup‘);
\—

a v textu příspěvku pak výraz, které chceme dohledat, označíme příslušným shortcodem:

[tfdl hledaný_výraz]

„Další příklady »“:http://wpcodesnippets.info/blog/five-easy-dictionary-lookup-shortcodes.html

*Můžeme použít i pluginy:*

**Click2Refer Virtual Dictionary**
„http://wordpress.org/plugins/click2refer-virtual-dictionary/“:http://wordpress.org/plugins/click2refer-virtual-dictionary/

Click2Refer plugin lets the blog readers to lookup the Wordnet dictionary just by a double click on the word they want to refer.
This will take in a floating window into your blog upon the first double click.

[* http://s.wordpress.org/extend/plugins/click2refer-virtual-dictionary/screenshot-2.jpg?r=717851 *]

**Double Click Dictionary Look-up**
„http://wordpress.org/plugins/double-click-dictionary-look-up/“:http://wordpress.org/plugins/double-click-dictionary-look-up/

Double click on the screen to highlight a word. This creates a qTip next to the word where when clicked, a pop-up will appear with the Miriam-Webster.com’s definition on the word.

„Top 10 WordPress Dictionary Plugins »“:www.wordpressintegration.com/blog/top-10-wordpress-dictionary-plugins-you-can-use/

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‘ );
\—

Jak vytvořit a přidat vlastní shortcodes

**Zakódování e-mailové adresy**

/—code php
function cwc_mail_shortcode( $atts , $content=null ) {
for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';'; return '‚.$encodedmail.‘‚;
}
add_shortcode(‚mailto‘, ‚cwc_mail_shortcode‘);
\—

Použití shortcode:

[mailto]email@yourdomain.com[/mailto]

**Obsah pouze pro přihlášené uživatele**

/—code php
function cwc_member_check_shortcode( $atts, $content = null ) {
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
return $content;
return “;
}

add_shortcode( ‚member‘, ‚cwc_member_check_shortcode‘ );
\—

Použití shortcode:

[member]This text will be only displayed to registered users.[/member]

**Zobrazení PDF v iframe**

/—code php
function cwc_viewpdf($attr, $url) {
return ‚‚;
}
add_shortcode(‚embedpdf‘, ‚cwc_viewpdf‘);
\—

**Použití shortcode**

/—code php
[embedpdf width=“600px“ height=“500px“]http://infolab.stanford.edu/pub/papers/google.pdf[/embedpdf]
\—

**Volání shortcode v šabloně (mimo editor)**

/—code php
echo do_shortcode(‚[jmeno_shortcode]‘);
\—

viz „dokumentace“:http://codex.wordpress.org/Function_Reference/do_shortcode.

**Znepřístupnění shortcodes**

There might be some cases that you need the shortcodes of the text to be omitted. When that time comes, strip_shortcodes() is your friend.

Let’s say that you need to strip shortcodes in the homepage but let them run in other content pages:

/—code php

\—

„Jak vytvořit vlastní shortcode (musilda.cz) »“:http://musilda.cz/jak-vytvorit-vlastni-shortcode/
„10 super useful WordPress shortcodes »“:http://www.catswhocode.com/blog/10-super-useful-wordpress-shortcodes
„Mastering WordPress shortcodes »“:http://coding.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/
„8 fun & useful shortcode functions for WordPress »“:http://blue-anvil.com/archives/8-fun-useful-shortcode-functions-for-wordpress/

Používání uživatelských polí v šablonách

„Using Custom Fields In Your WordPress Template »“:http://return-true.com/2010/06/using-custom-fields-in-your-wordpress-template/

/—code php
// key = název (klíč) uživatelského pole
// $post->ID lze použít pouze v loopu
if($data = get_post_meta($post->ID, ‚key‘, true)) {
echo $data;
}

// v případě pole
if($data = get_post_meta($post->ID, ‚key‘)) {
echo $data[0];
echo $data[1];
}
\—

„Detailed example“:http://codex.wordpress.org/Function_Reference/post_meta_Function_Examples for the usage of the add_post_meta, delete_post_meta, update_post_meta, and get_post_meta functions.

Ú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‘);
\—

Generátor .po souborů, konvertor .mo souborů

„This generator“:http://www.icanlocalize.com/tools/php_scanner will scan PHP file(s) and create .po files, that are used for localization. It will extract all strings wrapped in __(„txt“, „domain“) and _e(„txt“, „domain“) calls.

Strings can be enclosed in either double quotes („) or single quotes(‚) and with any character encoding.

You can upload a single PHP file or a ZIP file containing multiple files. The scanner will extract strings from all PHP files inside the archive, ignoring other files (like images and stylesheets).

„Nástroj pro Konverzi z .mo do .po »“:http://tools.konstruktors.com/