April 16, 2014

WordPress: Anonymous PHP functions

Recently I wrote about my problem with WordPress editor and now I realize that I wanted to write also about something different - using anonymous functions in WordPress development - it's amazing how using of them can simplify your code (if you forget older PHP versions).

Compare these examples:

<?php
// Sets WordPress admin bar hidden.
// Old:
add_filter('show_admin_bar', '__return_false');
// New:
add_filter('show_admin_bar', function() { return false; });

// Activate widgets
// Old:
add_action('widgets_init',
     create_function('', 'return register_widget("Your_Widget_Class");')
);
// New:
add_action('widgets_init', function() {
    register_widget('Your_Widget_Class');
});

And of course that this can be used everywhere you're using function such add_action, add_filter etc.







April 15, 2014

WordPress: Custom font family in TinyMCE editor

I tried to add custom font family to the WordPress editor but it turns to the little battle - firstly I just do what is described in the WordPress Codex:

your-theme/functions.php:
<?php
function your_theme_editor_styles() {
    add_editor_style('assets/css/editor-style.css');
}
add_action('init', 'your_theme_editor_styles');
?>

your-theme/assets/css/editor-style.css:
@font-face {
    font-family: CharisSILBold;
    src: url(../fonts/CharisSIL-Bold.woff);
}

body#tinymce.wp-editor { 
    font-family: CharisSILBold; 
    font-size: 14pt;
}

But it doesn't work (of course). Then I look into the default theme and found the solution (code in functions.php is the same as before so here only editor-style.css):

your-theme/assets/css/editor-style.css:
@font-face {
    font-family: CharisSILBold;
    src: url(../fonts/CharisSIL-Bold.woff);
}

html .mceContentBody { 
    font-family: CharisSILBold;
    font-size: 14pt;
}

It sucks that small things take so much time (but of course it's my fault).

Tested on WP 3.8.*.



April 11, 2014

Firefox OS 2.0 Screenshots

Today I found screenshots of design proposals for Firefox OS 2.0. I must say that I like it a lot - especially the calendar screen:

I think the time to throw all iPhones etc. will be here soon :) . You can see more screenshots here (original post by Sören Hentzschel).