WordPress Options Passed To JavaScript #1

In WordPress you are not always in the PHP world and so you have to pass settings and data from the database to scripts sometimes. In many Plugins you can find solutions in loading the wp-load.php and therefore access to all features of WordPress. Long ago Otto (Samuel Wood) already referred to this fact and this articles shows solutions. Questions still there and still there are Plugins that load the wp-load.php precisely because of such problems.

A similar problem arises when the source of the scripts is not just written in the footer area of WordPress, but outsourced to a file and via wp_enqueue_script() included. Only then WordPress can manage, compromises and optimizes these scripts for delivery. Therefore I would like to show two examples, how to pass data from PHP to JS.
Continue reading …

First or Last Page in Page-Structures of WordPress

Now and then little snippets are pretty useful. For a fix in a Premium-Theme, I needed a kind of evaluation, where I am in the site structure and with little effort I was able to expand the classes and react with CSS.

The following code shows the basic for it and get_pages() is the key from the core of WordPress to get to these results. This function provides the necessary result of using the parameter and the output via the parameter sort_order provides the sequence and identification of the first page, which is then either the first or last page in this structure.
Continue reading …

Load Minimum of WordPress

A small contribution for all those using WordPress as a backend, framework or something similar. The applications, especially in the B2B sector, becoming more and more, as do the questions.

So far, I've always liked to recommended BackPress. But even a well-maintained standard is feasible, with all its advantages in the context of the philosophy of updates. WordPress reduces initializing to a minimum, if the constant SHORTINIT is set.
Continue reading …

Don’t use strlen()

Each time I see someone use strlen() I cringe. It will break.

Despite its name, strlen() doesn’t count characters. It counts bytes. In UTF-8 a character may be up to four bytes long.

So what happens if we use strlen() and its companion substr() to shorten the title of post?

<?php # -*- coding: utf-8 -*-
declare( encoding = 'UTF-8' );
header('Content-Type: text/plain;charset=utf-8');

$string = 'Doppelgänger';
print 'strlen():    ' . strlen( $string ) . "\n";
print 'mb_strlen(): ' . mb_strlen( $string, 'utf8' ) . "\n\n";

print 'substr():    ' . substr( $string, 0, 8 ) . "\n";
print 'mb_substr(): ' . mb_substr( $string, 0, 8, 'utf8' );

Output:

I have to use an image here. If I had used the plain text output our newsfeed would break. And that’s what happens each time you use strlen() and substr() on strings encoded in UTF-8: You end up with partial characters and invalid UTF-8.

Alternatives for mb_strlen()

You can use different methods to get the real string length.

$length = preg_match_all( '(.)su', $string, $matches );

See also Hakre: PHP UTF-8 string Length.

Or just use …

$length = strlen( utf8_decode( $string ) );

There is also a nice php-utf8 library on GitHub from Frank Smit.

We’ve Lost A Very Good Friend, WordPress Enthusiast And An Important Part Of WPEngineer!

Sadness has descended on WPEngineer last week. Michael Preuß, one of our WPEngineer Team, died suddenly after a short illness and after a memorable life.

Frank and I are still in shock and we can't realize that Michael left us without saying goodbye. He leaves a big gap in our life. He was not only our teammate at WPEngineer, he also was a very good friend, who have shared the same love for WordPress and the community as we do.

We didn't meet us very often in person, since we live quite far away from each other. But when we did, we always had a blast and fun talking about WordPress and other stuff that was going on right now around the world. But most of the time we were talking on the phone for hours, literally.

This time our reunion was one of Frank's and my saddest moment. We had to carry Michael to his grave. It was painful, incomprehensible and unbearable at once. Unlikely for us, not one word about WordPress, this time we had to mourn the loss of our beloved friend Michael.

Feb 2009 - Matt meets WPEngineer: Frank, Michael, Matt, Alex

Feb 2009 - Matt meets WPEngineer: Frank, Michael, Matt, Alex

Just 4 years ago we got to know each other and became very good friends. Michael, Frank and I had the urge to give the WordPress community something back, a platform for writing tips, tricks and solutions for the WordPress community - WPEngineer was born! Frank and I will continue to publish future posts, despite the loss we have.

We will also help his partner and friend Heiko, to continue Michael's life's work Xtreme Theme.

He left his wonderful and caring wife Carola and his two sons Robert and Alexander behind, and I'm sure, many other WordPress Junkies, like we are, who still can't believe he is gone forever!

You will always be in our Source Code!

In deepest sympathy

Alex & Frank