The debug method

One downside to the highly structured and dynamic nature of the MasterPress API is that trying to inspect objects with PHP functions like var_dump and print_r can lead to some rather unhelpful nested object structures, that don’t offer the information you’re probably looking for. For example, if you were to try to debug the contents of a field set named “details” in the current post using the following code:

Example 1: The hard way to deug

… you’ll get hundreds of lines of output detailing the structure of that object, when all you probably wanted to know is “what content is in this field set”.

A much better way to do this is to use the debug method, which is available in every object in the API (and will also add a “<pre>” block for you by default):

Example 2: The easy way to debug

This debug method is specifically tailored to output more useful information – for example, here’s the output for the “Details” field set for the WOOF_Image::resize method in this documentation:

{class} => 27
{description} => <p>A highly useful method to resize an image, and cache the result in the image cache. Has the ability to crop, stretch, or fill the image to fit a certain width and height, or specify just a single dimension to resize the other dimension proportionally.</p>
{since} => 1.0
{example} => <?php

$logo = $wf->theme_image("logo.jpg");

// resize to fit a width of 200 pixels (height scaled proportionally)
echo $logo->resize("w=200");

// resize to fit a bounding box of 200 x 200 pixels (cropped centrally by default)
echo $logo->resize("w=200&h=200");

// resize to fit a bounding box of 200 x 200 pixels (cropped from the top left)
echo $logo->resize("ca=tl&w=200&h=200");

{visibility} => Public
{static} =>
{related_methods} => 2479
{credit} =>

As you can see, you now get a formatted breakdown of the content of the field set.

Silent Failure and debug

The debug method is also useful to debug chained property calls that are invalid in some way. Consider the following code:

Example 3: Chained property failure

The silent failure mechanism in the MasterPress API would mean that this code would output nothing when, for example, the “about” page didn’t exist in this site. To ascertain the point of failure in a property chain, we can simply add a debug call at the end, which will give us insight into the problem:

Example 4: Chained property debugging

If our about page doesn’t exist (keep in mind we may not realise this while developing), we’d get the following error:

Cannot find page with id or slug 'about'

This helps us get to the source of the problem immediately. For more information on silent failure in the MasterPress, please refer to Silent Failure with the WOOF class.

Latest From the Blog

MasterPress 1.1.4 now available

MasterPress 1.1.4 is now available. This release contains an important compatibility fix for WordPress 4.5 to allow correct detection of the taxonomy term editing screen. Without this fix, any custom fields you have attached to custom taxonomies will not be shown at all in the editing form. Note also that MasterPress will still detect the edit screen correctly in… 

Plugin Requirements

MasterPress requires a minimum of WordPress version 3.4, MySQL 5, and PHP version 5.2.4.

We also recommend that PHP is configured to use a memory limit of 64MB per request (128MB may be required for sites with higher complexity).

This plug-in is not compatible with the hosted service.