Petr Pabouček
Freelance Web Developer

Prohlédněte si seznam mnou nabízených služeb, podívejte se, co o mě říkají mí klienti, či na jakých projektech jsem se podílel. V případě zájmu o spolupráci, či jakýchkoliv jiných dotazů, mě prosím kontaktujte.

Efficient handling of AJAX requests on WordPress platform

WordPress has got built in very developer friendly way for handling AJAX requests, which is in detailed described in WordPress documentation.

All AJAX requests are basically sent to /wp-admin/admin-ajax.php along with some data:


(function($) {

    var data = {
        'action'     : 'my_action_name',
        'postId'     : 5,
        'someKey'    : 'someValue',
        'anotherKey' : 'anotherValue'
    };

    $.get( '/wp-admin/admin-ajax.php', data );

})( jQuery );

Please note the parameter action here. This is the important ingredients which creates connection between the javascript code and your WordPress php code.

The fact, that AJAX request is triggered against /wp-admin/admin-ajax.php allows us to catch this action in our back-end using wp_ajax_{action} or wp_ajax_nopriv_{action} action hooks and call php function, which is going to do something with the data sent.

Pokračovat »

Slaboproudá elektrotechnika

Nedávno jsem dělal malý úklid ve svých historických CD se zálohami a shodou okolností jsem objevil starý projekt, o kterém jsem si myslel, že je již dávno navždy ztracen. S kamarádem jsme na začátku studií na vysoké škole dali dohromady elektronickou učebnici obsahující základy elektrotechniky. V podstatě se jedná o přepis mých poznámek ze střední školy. Vše je k dispozici tak, jak jsem to našel, na adrese elektro.bouk.info.

How to allow comments on scheduled posts in WordPress

When working on one project for client of mine I’ve bumped into problem when trying to allow comments on scheduled posts. In this specific case, scheduled posts are used for displaying different type of promotions. WordPress theme then uses a template which allows for displaying scheduled posts on the front-end and once the publication date is reached, promotion is automatically taken off the site.  So far so good.

The problem arrived when I tried to allow comments on the promotions (scheduled posts). Comment form appears as expected, but when the comment is submitted, it never makes it through. I’ve tried to do bit of a research on the Internet, but unfortunately haven’t found any  satisfying solution, which wouldn’t require altering core files.

The reason, why comment never makes it through is caused by this condition in wp-comments-post.php file.

elseif ( ! $status_obj->public && ! $status_obj->private ) {
/**
* Fires when a comment is attempted on a post in draft mode.
*
* @since unknown
* @param int $comment_post_ID Post ID.
*/
do_action( 'comment_on_draft', $comment_post_ID );
exit;
}

Pokračovat »

Adding a CSS class to the all last menu items generated by wp_nav_menu

Today I’ve been working on one WordPress project where I needed to add CSS class  to the all last menu items generated by wp_nav_menu() function.  I’ve done little research on the Internet and found this article ‚Adding a CSS Class to the Last LI Generated by wp_nav_menu()‚. Works great so far, unfortunatelly it adds class just to the very last item of the list.

My task required to add CSS class to the all last menu items as follows:

<ul>
	<li>Item A
        <ul>
	         <li>Item a1</li>
	         <li>Item a2</li>
	         <li class="last">Item a3</li>
        </ul>
    </li>
	<li>Item B
        <ul>
	          <li>Item b1</li>
	          <li>Item b2</li>
	          <li class="last">Item b3</li>
        </ul>
    </li>
	<li class="last">Item C</li>
</ul>

Article mentioned above has been a great inspiration to me and after a while of playing with WordPress, I have come up with this code.

Pokračovat »