PHPUnit Testing

How to find the reason for a risky test in PHPUnit ?

Recently I started phpUnit testing, and I found some of the test are flagging as risky. Most of the time I able figure bout reason but some time it very time consuming and also there isn’t any messages from PHPUnit.

PHPUnit 4.4.5 by Sebastian Bergmann.

Configuration read from phpunit.xml.dist

R.................R.R..R

Time: 14,17 seconds, Memory: 52,50Mb

OK, but incomplete, skipped, or risky tests!
Tests: 24, Assertions: 52, Risky: 4.

Finally I found a soultion and it is very simple( How I can forgot about -v flag !! )

 phpunit -v|--verbose              Output more verbose information.

Stay tuned, more testing related post probably writing 🙂

WordPress 4.3 Changes in Template Hierarchy

In WordPress  4.3 there is a new template file added in theme template hierarchy called singular.php . This will allow theme authors to use a common template for any singular post type.

It follows the rules of is_singular() and comes after single-{post-type}.php, single-post.php, single.php, andpage.php.

Template hierarchy for singular post types
Template hierarchy for singular post types

To learn more about WordPress theme template heirarchy : https://developer.wordpress.org/themes/basics/template-hierarchy/

The Importance of Escaping All The Things

WordPress.com VIP

Nick Daugherty is WordPress.com VIP Lead Engineer. Here he shares some important information about escaping in code and how that can increase security in WordPress sites anywhere in the world. 

If there’s one issue we flag more often than all others in code reviews…it’s escaping.

For starters, we should all agree that escaping (fundamentally, sanitizing input and escaping output) is a critical aspect of web application security. What may be less universally agreed upon is where to escape. On that point, we require “late escaping“- escaping as close as possible to the point of output – and further, we now require it everywherealways.

You may now be thinking:

“Do I really need to “late escape” everything? Always? Even core WordPress functions?”

We hear you. And, here’s why this is important to us:

In addition to some automated scanning, we manually review every line of code our VIP customers commit to the VIP platform. And…

View original post 601 more words

User Avatar in buddyPress notification loop

To display user avatar in buddypress notification-loop (You can find it in members / single / notifications / notifications-loop.php )

Below snippet will return user id of that activity ( BuddyPress stored it as  secondary_item )

$bp      = buddypress();
$user_id = $bp->notifications->query_loop->notification->secondary_item_id;

To echo avatar from user id :

echo bp_activity_avatar( array( 'user_id' => $user_id ) );

Loading IE Conditional Stylesheets in WordPress

Most web developers are familiar with the IE conditional comments that allow you to load a stylesheet only in Internet Explorer.

<!-- [if lt IE 9]>
   <link href="ie.css" rel="stylesheet" type="text/css">
<![endif]-->

Many new WordPress developers tend to just hardcode these conditional comments directly into their theme’s header.php file. The correct way to load stylesheets in WordPress is using the wp_enqueue_style() function.

add_action( 'wp_enqueue_scripts', 'enqueue_my_styles' );

function enqueue_my_styles() {
   global $wp_styles;
   enqeue_style( 'my-theme-ie', get_stylesheet_directory_uri() . 'ie.css' );
   //add_data function to add IE Condition
   $wp_styles->add_data( 'my-theme-ie', 'conditional', 'IE 9' );
}

 

Automatic update of Child Theme to Parent Theme

After automatic update of child theme to parent theme, During update we just update code of theme, but what about WordPress, WordPress still assuming current theme as child theme.

When you activate child theme, there are mainly two site options template and stylesheet who store parent theme and child theme slug. After updating you have to update that site option also (There are others relative options also).

Add following code into your theme function.php

if ( is_child_theme() && 'current-theme-slug' != get_template() ) {
    switch_theme( get_stylesheet() );
}

Enable Category/Tag support for WordPress Media files

To enable category/tag support on WordPress Media, You have to register taxonomy for Media(attachment) by adding following code in theme function.php or in plugin file

register_taxonomy( 'media-category', 'attachment', $args );

Note : This will work with WordPress 3.5 or higher.