Debug a reset cronu ve WordPressu

Po aktualizaci pluginu Post Indexer mě zřejmě přestal fungovat cron –  indexace byla naplánovaná ale nespustila se. Tak jsem na fóru wpmudev jsem dostal pár rad jak debugovat cron a jak cron resetovat. Zde je stručný návod jak na to.

Debugování cronu

debug-cronK tomu jsou zapotřebí nahrát dva pluginy v tomto pořadí:

  1. Debug bar
  2. Debug bar cron

Zde zjistíte jaké procesy jsou v cronu naplánované a hlavně jaká uplynula doba od poslední úlohy cronu. Pokud to porovnáte s informací jak často se má task cronu spouštět, hned vidíte jestli je něco špatně.

Reset cronu

Reset cronu je třeba udělat v MyPHPAdmin – najděte tabulku wp_option a v ní pak řádek cron a ten smažte – pouze ten jeden řádek cron. Pak znovu jděte do administrace WordPressu a tabulka se sama obnoví. Otestováno na WPMU a funguje. Pokud jste si při instalaci WordPressu změnili prefix databáze z wp_ za blb_ tak tabulka se bude jmenovat blb_option.

Problém byl možná jinde

Nicméně u mě byl problém možná v pluginu W3 Total Cache nebo  Better WP Security. Cron se správně rozjel až resetu a po následné aktualizaci těchto dvou pluginů.

Pluginy Post Indexer a Recent post můžete vidět v akci na této stránce vyhledame.cz/posledni-tematicke-clanky/, kde jsem potřeboval aby články z 27 subdomén na wpmu se zobrazovali na jedné stránce.

The post Debug a reset cronu ve WordPressu appeared first on wpmax.cz.

Hromadné přidání uživatelů

Add Multiple Users
http://wordpress.org/extend/plugins/add-multiple-users/

Provides the ability for administrators to bulk register users using a range of tools.
Functions include the ability to manually input new user information, convert CSV data to user information, and create users from a list of email addresses. Each new user registration can include almost all available standard user meta fields plus any additional meta fields you require.

Rich text editor (Tiny MCE) pro popisky tagů. rubrik a dalších taxonomií

The Rich Text Tags – A TinyMCE Editor for Tags, Categories, and Taxonomies
http://wordpress.org/extend/plugins/rich-text-tags/

The Rich Text Tags Plugin allows you to edit tag descriptions, category descriptions, and taxonomy descriptions using WordPress‘ built in rich-text editor. Switch between WYSIWYG and HTML editing modes with the click of a link. Use the WordPress uploader to insert images from your computer or site’s Media Library.

Use the WordPress functions tag_description() and category_description() in your theme to show the descriptions. To learn how to show taxonomy descriptions, read more on the plugin page.
Features

– Edit term descriptions with WordPress’s built-in WYSIWYG editor
– Works with custom taxonomies (and custom post types, introduced in WP 3.0)
– Now supports user biography fields!

Vytváření kvízů a testů

Watu
http://wordpress.org/extend/plugins/watu/

Create exams and quizzes and display the result immediately after the user takes the exam. You can assign grades and point levels for every grade. Then assign points to every answer to a question and Watu will figure out the grade based on the total number of points collected.

SlickQuiz
http://wordpress.org/plugins/slickquiz/

Plugin for displaying and managing pretty, dynamic quizzes. It uses the SlickQuiz jQuery plugin.

Struktura databáze WordPressu

Pokud chcete pochopit, jak vlastně samotný WordPress funguje, určitě vám pomůže základní znalost struktury jeho databáze. Ta se zkládá z celkem 11 tabulek, které ještě mohou rozšiřovat pluginy. Každá má svůj prefix, nejčastěji wp_, který se nastavuje běhěm instalace WordPressu a vytváření databáze. comments, commentmeta První dvě tabulky obsahují informace o komentářích na webu. V […]

Ultimate guide on redirect to custom page after login / register fails

It’s quite easy to setup a frontend registration or login form. You can find a really extensive ammount of tutorials on this topic. And usually everything works great – your users do not see typical WordPress login/register page and are redirected to frontend of your website. Till either registration or login fails. Than most of solutions fails too – users are not redirected and see typical WordPress login/register screen. What now? It’s quite hard to find a solution on the internet – that’s why I’ve prepared this ultimate howto.

Actually, to redirect after login fails is well documented – there is a special hook for that in WordPress. You can find a great tutorials on this.

So in breaf: here’s my code based on this solution: How to Redirect WordPress Failed Logins (modified as original code stackups login=fail attrs):

// hook failed login
add_action('wp_login_failed', 'my_frontend_login_fail'); 
 
function my_frontend_login_fail($username){
    // Get the reffering page, where did the post submission come from?
    $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']);
 
    // if there's a valid referrer, and it's not the default log-in screen
    if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
        // let's append some information (login=failed) to the URL for the theme to use
        wp_redirect($referrer . '?login=failed'); 
    exit;
    }
}

Ok, this was easy, wasn’t it? But wait! What has happen when a user submit your custom login form (frontend login form) empty? He/She will land on wp-login.php again instead on your custom login form. To fix this behaviour, add this code also:

add_action( 'login_head', 'my_frontend_login_no_pass_no_username' );

function my_frontend_login_no_pass_no_username(){
    $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']);
    if ( (!isset($_REQUEST['user_login']) || ( isset( $_REQUEST['user_login'] ) && trim( $_REQUEST['user_login'] ) == '' ) ) || (!isset($_REQUEST['user_pass']) || ( isset( $_REQUEST['user_pass'] ) && trim( $_REQUEST['user_pass'] ) == '' ) ) ){
        wp_redirect( add_query_arg('login', 'failed', $referrer) ); 
        exit; 
    }   
}

And now, what if we would like to redirect our user (not registered yet) to a custom page after unsuccessful registration attempt?

Have to say, that I’v originally published this solution, with extensive comment, on WordPress Answers – vote up, if you find this solution helpful, thx.

Again in breaf, here’s the code:

add_action('register_post', 'binda_register_fail_redirect', 99, 3);

function binda_register_fail_redirect( $sanitized_user_login, $user_email, $errors ){
    //this line is copied from register_new_user function of wp-login.php
    $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
    //this if check is copied from register_new_user function of wp-login.php
    if ( $errors->get_error_code() ){
        //setup your custom URL for redirection
        $redirect_url = get_bloginfo('url') . '/registrace';
        //add error codes to custom redirection URL one by one
        foreach ( $errors->errors as $e => $m ){
            $redirect_url = add_query_arg( $e, '1', $redirect_url );    
        }
        //add finally, redirect to your custom page with all errors in attributes
        wp_redirect( $redirect_url );
        exit;   
    }
}

Ultimate guide on redirect to custom page after login / register fails

It’s quite easy to setup a frontend registration or login form. You can find a really extensive ammount of tutorials on this topic. And usually everything works great – your users do not see typical WordPress login/register page and are redirected to frontend of your website. Till either registration or login fails. Than most of solutions fails too – users are not redirected and see typical WordPress login/register screen. What now? It’s quite hard to find a solution on the internet – that’s why I’ve prepared this ultimate howto.

Actually, to redirect after login fails is well documented – there is a special hook for that in WordPress. You can find a great tutorials on this.

So in breaf: here’s my code based on this solution: How to Redirect WordPress Failed Logins (modified as original code stackups login=fail attrs):

// hook failed login
add_action('wp_login_failed', 'my_frontend_login_fail'); 
 
function my_frontend_login_fail($username){
    // Get the reffering page, where did the post submission come from?
    $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']);
 
    // if there's a valid referrer, and it's not the default log-in screen
    if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
        // let's append some information (login=failed) to the URL for the theme to use
        wp_redirect($referrer . '?login=failed'); 
    exit;
    }
}

Ok, this was easy, wasn’t it? But wait! What has happen when a user submit your custom login form (frontend login form) empty? He/She will land on wp-login.php again instead on your custom login form. To fix this behaviour, add this code also:

add_action( 'login_head', 'my_frontend_login_no_pass_no_username' );

function my_frontend_login_no_pass_no_username(){
    $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']);
    if ( (!isset($_REQUEST['user_login']) || ( isset( $_REQUEST['user_login'] ) && trim( $_REQUEST['user_login'] ) == '' ) ) || (!isset($_REQUEST['user_pass']) || ( isset( $_REQUEST['user_pass'] ) && trim( $_REQUEST['user_pass'] ) == '' ) ) ){
        wp_redirect( add_query_arg('login', 'failed', $referrer) ); 
        exit; 
    }   
}

And now, what if we would like to redirect our user (not registered yet) to a custom page after unsuccessful registration attempt?

Have to say, that I’v originally published this solution, with extensive comment, on WordPress Answers – vote up, if you find this solution helpful, thx.

Again in breaf, here’s the code:

add_action('register_post', 'binda_register_fail_redirect', 99, 3);

function binda_register_fail_redirect( $sanitized_user_login, $user_email, $errors ){
    //this line is copied from register_new_user function of wp-login.php
    $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
    //this if check is copied from register_new_user function of wp-login.php
    if ( $errors->get_error_code() ){
        //setup your custom URL for redirection
        $redirect_url = get_bloginfo('url') . '/registrace';
        //add error codes to custom redirection URL one by one
        foreach ( $errors->errors as $e => $m ){
            $redirect_url = add_query_arg( $e, '1', $redirect_url );    
        }
        //add finally, redirect to your custom page with all errors in attributes
        wp_redirect( $redirect_url );
        exit;   
    }
}

Čeština pro WordPress 3.5.1

Před několika dny vyšla první opravná a bezpečnostní verze WordPress 3.5.1. Čeština vychází teprve dnes (chřipka) a obsahuje pouze několik drobných změn. Doporučujeme neotálet s automatickou aktualizací, pro nové instalace si pak můžete stáhnout kompletní balíček. A pro zajímavost, zatím byla česká verze WordPressu 3.5 použita na téměř 14 tisíc webech. Aktuální česká verze by se […]

No hierarchy of pages when adding pages to nav menus with too many pages

WordPress had problems with hierarchy on Menu page in history. There was no hierarchy at all for pages on View All tab. Now, it is fixed. At first glance. When you have more than 50 pages, you’ll run into problem.

Your pages will be divided to two or more pages. The first page is OK, second and next not. On second and next page, there are pages without hierarchy. This makes it almost imposible to setup a nav menu.

I have a quick fix for this issue. It will remove the mentioned pagination and will display reall „All“ pages on single tab. Copy and paste the following WordPress snippet to your functions.php.

function binda_modify_nav_menu_items_page( $posts, $args, $post_type ){
	global $_nav_menu_placeholder, $nav_menu_selected_id;

	$post_type_name = $post_type['args']->name;

	$args = array(
		'offset' => $offset,
		'order' => 'ASC',
		'orderby' => 'title',
		'posts_per_page' => -1,
		'post_type' => $post_type_name,
		'suppress_filters' => true,
		'update_post_term_cache' => false,
		'update_post_meta_cache' => false
	);

	if ( isset( $post_type['args']->_default_query ) )
		$args = array_merge($args, (array) $post_type['args']->_default_query );

	$get_posts = new WP_Query;
	$posts = $get_posts->query( $args );

	if ( !$posts )
		$error = '
  • '. $post_type['args']->labels->not_found .'
  • '; // if we're dealing with pages, let's put a checkbox for the front page at the top of the list if ( 'page' == $post_type_name ) { $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0; if ( ! empty( $front_page ) ) { $front_page_obj = get_post( $front_page ); $front_page_obj->front_or_home = true; array_unshift( $posts, $front_page_obj ); } else { $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; array_unshift( $posts, (object) array( 'front_or_home' => true, 'ID' => 0, 'object_id' => $_nav_menu_placeholder, 'post_content' => '', 'post_excerpt' => '', 'post_parent' => '', 'post_title' => _x('Home', 'nav menu home label'), 'post_type' => 'nav_menu_item', 'type' => 'custom', 'url' => home_url('/'), ) ); } } return $posts; } add_action ( 'nav_menu_items_page', 'binda_modify_nav_menu_items_page', 1, 3 ); add_action( 'admin_print_styles-' . 'nav-menus.php', 'binda_nav_menu_custom_css' ); function binda_nav_menu_custom_css() { echo '#posttype-page .add-menu-item-pagelinks{display:none;}'; }

    No hierarchy of pages when adding pages to nav menus with too many pages

    WordPress had problems with hierarchy on Menu page in history. There was no hierarchy at all for pages on View All tab. Now, it is fixed. At first glance. When you have more than 50 pages, you’ll run into problem.

    Your pages will be divided to two or more pages. The first page is OK, second and next not. On second and next page, there are pages without hierarchy. This makes it almost imposible to setup a nav menu.

    I have a quick fix for this issue. It will remove the mentioned pagination and will display reall „All“ pages on single tab. Copy and paste the following WordPress snippet to your functions.php.

    function binda_modify_nav_menu_items_page( $posts, $args, $post_type ){
    	global $_nav_menu_placeholder, $nav_menu_selected_id;
    
    	$post_type_name = $post_type['args']->name;
    
    	$args = array(
    		'offset' => $offset,
    		'order' => 'ASC',
    		'orderby' => 'title',
    		'posts_per_page' => -1,
    		'post_type' => $post_type_name,
    		'suppress_filters' => true,
    		'update_post_term_cache' => false,
    		'update_post_meta_cache' => false
    	);
    
    	if ( isset( $post_type['args']->_default_query ) )
    		$args = array_merge($args, (array) $post_type['args']->_default_query );
    
    	$get_posts = new WP_Query;
    	$posts = $get_posts->query( $args );
    
    	if ( !$posts )
    		$error = '
  • '. $post_type['args']->labels->not_found .'
  • '; // if we're dealing with pages, let's put a checkbox for the front page at the top of the list if ( 'page' == $post_type_name ) { $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0; if ( ! empty( $front_page ) ) { $front_page_obj = get_post( $front_page ); $front_page_obj->front_or_home = true; array_unshift( $posts, $front_page_obj ); } else { $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; array_unshift( $posts, (object) array( 'front_or_home' => true, 'ID' => 0, 'object_id' => $_nav_menu_placeholder, 'post_content' => '', 'post_excerpt' => '', 'post_parent' => '', 'post_title' => _x('Home', 'nav menu home label'), 'post_type' => 'nav_menu_item', 'type' => 'custom', 'url' => home_url('/'), ) ); } } return $posts; } add_action ( 'nav_menu_items_page', 'binda_modify_nav_menu_items_page', 1, 3 ); add_action( 'admin_print_styles-' . 'nav-menus.php', 'binda_nav_menu_custom_css' ); function binda_nav_menu_custom_css() { echo '#posttype-page .add-menu-item-pagelinks{display:none;}'; }