THE PENDING DRAFT

An Introduction to wp.media by Eric Andrew Lewis

January 14, 2015

Eric Andrew Lewis, one of the core developers behind the “new” (v3.5+) WP Media Workflow gave a talk at the WordCamp Philly about wp.media. While the video has terrible Audio quality which makes it a bit hard to understand, he gives some solid insights into how things work behind the scenes and how we can (at least somewhat) customize a Media Frame or create custom ones.

During the talk he shares a graphical representation of all the Backbone Views and Models that wp.media utilizes, which can be found here:

If you want to understand how wp.media works, you should check out Eric’s Plugin WordPress Media Javascript Guide and he also started the WordPress Media Core Developer Documentation, which i really hope he finds some time to carry on.

Zero

January 13, 2015

It’s always a good thing to have a basic starting point at hand when starting with a new project so you don’t have to write the same things over and over again. While there’s plenty of frameworks, starter themes and templates etc. i thought it would be a good idea to have my own little thingy with exactly the things i need, the way i like to write and structure things. So here it is, maybe it’s of any use for you, too.

A starting point to “jumpstart” a project which contains some of the things i wrote over and over again for each project.

Doesn’t contain any styling, html structure or other project-related stuff. Its basically just my preferred document-structure and a pre-configured Gruntfile.js and package.json.

Nothing fancy, but still very useful for new projects.

Check it out on GitHub and feel free to fork, use or do whatever you like to do with it.

Take it apart – A simple regular learning habit

January 12, 2015

If you use code on a daily basis, i’m pretty sure you also have a big pile of functions, classes and snippets that you used over and over again but never fully grasped how exactly they work in detail. That little snippet you found in a tutorial some years ago or that small bit of code you borrowed from a plugin and included in your themes ever since. Because they just worked, without the need to understand every single line of every bit of code you use.

Take it apart

The last weeks i started to make it a regular habit to take one piece of code and take it apart until i fully understand it. Whether that is a function in WP Core (or any other software you’re using) or just a small code-snippet i used over and over again. I take that code, read through it line by line, and if there is just one single comma i don’t understand i stop and google it, look it up on stackoverflow etc. until i find out exactly why it is there and what it does.

The trick here is to only take small regular steps, one at a time. You would be a fool to think you could master Regular Expressions in just some minutes, but taking apart that one function that uses some Regular Expressions isn’t that hard, gets you started and gets you the satisfaction of having learned something new.

You’ll be amazed how much you will learn without really investing a lot of time.

Redacted Font

January 10, 2015

Redacted Font

When building rough Mockups and Wireframes we normally fill text areas with random Lorem Ipsum Text. While this might work perfectly for us, it can confuse clients. First of all, not everyone gets why there’s strange random latin text all over the place, and second if you use just “any” real font it can lead to discussions about font choices too early in the process when you not even started designing those details.

The Redacted Font was created to solve that problem by obscuring text into unreadable blocks. The project is directly inspired by the BLOKK Font which was around for quite some time. David Walsh wrote more about the Redacted Font including some examples on how to use it etc. so i wont go into the details here.

Redacted Font

Sass Guidelines by Hugo Giraudel

January 9, 2015

Coding Styleguides can help a lot when working with multiple developers on a project, but even if you are a sole dev it can be very useful to write down and keep yourself to some conventions. Hugo Giraudel has put together this very thorough guide specifically targeted on Sass/SCSS Code. Definitely something to bookmark.

A styleguide is not just a pleasing document to read, picturing an ideal state for your code. It is a key document in a project’s life, describing how and why code should be written. It may look like overkill for small projects, but it helps a lot in keeping the codebase clean, scalable and easily maintainable.

Sass Guidelines

Adding things to titles inside the post content

January 8, 2015

For a specific styling i needed to be able to add elements, specifically a <span> element inside the H2 tags automatically.

Outside of the content is easy

To achieve this for titles outside of the_content is pretty easily done with the $before and $after Parameters on the_title() like so, or we could just wrap the_title inside the desired tags.

<?php the_title( '<h2 class="entry-title"><span>', '</span></h2>' ); ?>

Filtering the_content

To achieve the same result for all H2 tags inside the content we need to filter the_content with a regular expression.

function pdr_add_class_to_h2( $content ){
    return preg_replace( '/<h2(.*?)>(.*?)<\/h2>/', '<h2\1 class="entry-title"><span>\2</span></h2>', $content );
}
add_filter( 'the_content', 'pdr_add_class_to_h2' );

To extend this with other tags to replace, we can also pass arrays to preg_replace. Each element in $pattern will be replace by its counterpart in $replacement.

function pdr_add_class_to_titles( $content ){

    $pattern = array(
        '/<h2(.*?)>(.*?)<\/h2>/',
        '/<h3(.*?)>(.*?)<\/h3>/',
        '/<h4(.*?)>(.*?)<\/h4>/',
        '/<h5(.*?)>(.*?)<\/h5>/',
        '/<h6(.*?)>(.*?)<\/h6>/'
    );

    $replacement = array(
        '<h2\1 class="entry-title"><span>\2</span></h2>',
        '<h3\1 class="entry-title"><span>\2</span></h3>',
        '<h4\1 class="entry-title"><span>\2</span></h4>',
        '<h5\1 class="entry-title"><span>\2</span></h5>',
        '<h6\1 class="entry-title"><span>\2</span></h6>',
    );

return preg_replace( $pattern, $replacement, $content );
}
add_filter( 'the_content', 'pdr_add_class_to_titles' );

I found this solution in this support thread and adapted it a bit to fit my needs and replace all titles but it could basically be used to replace all kinds of stuff inside the content.

The Elements of Typographic Style Applied to the Web

January 6, 2015

ElementsOfTypographicStyles_WebTypography

The Elements of Typographic Style by Robert Bringhurst is one of those books that sits on my “to-read” list for far too long. Many people have praised this book as the “bible of typography” and i heard the phrase “if there’s one book about typography you read, make it this” more than few times.

Richard Rutter took the time to take it to the next level and apply the Elements of Typographic Style to the Web. I only skimmed through some of the chapters and have already learned a thing or two. Definitely something to bookmark.

The Elements of Typographic Style Applied to the Web

The Correspondents – Fear & Delight

January 5, 2015

Just stumbled upon this music video from the Correspondents. Never heard of them before, but like them. Go watch it and have a good start into the new year!