Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress var_dump in functions.php

Tags:

php

wordpress

I need to do a var_dump in a custom function filter in WP but, where is the results shown? The code is working because I can see the search result structure difference from when the code is present and not

    add_filter('relevanssi_hits_filter', 'products_first');
function products_first($hits) {
    $types = array();

    $types['section1'] = array();
    $types['section2'] = array();
    $types['section3'] = array();
    $types['section4'] = array();

    // Split the post types in array $types
    if (!empty($hits)) {
        foreach ($hits[0] as $hit) {
            array_push($types_1[$hit->post_type], $hit);
        }
    }

    // Merge back to $hits in the desired order
    var_dump($types);
    $hits[0] = array_merge($types['section1'], $types['section2'], $types['section3'], $types['section4']);
    return $hits;
}
like image 514
acctman Avatar asked Mar 06 '15 17:03

acctman


People also ask

How do I debug a PHP function in WordPress?

To start debugging, go to the wp-config. php file in the root of the WordPress file system and turn on the debug variable, i.e., set debug to true: define( 'WP_DEBUG', true ); Defining this constant as true will cause all PHP errors, notices, and warnings to be displayed on the screen.

What is Var_dump function in PHP?

The function var_dump() displays structured information (type and value) about one or more expressions/variables. Arrays and objects are explored recursively with values indented to show structure. All public, private and protected properties of objects will be returned in the output.

What is the difference between Print_r and Var_dump in PHP?

var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.

Which is true about Var_dump () function?

4. Which is true about var_dump() function? Explanation: var_dump() cuts off loop after getting the same element three times is true about var_dump() function.

What is the use of Var_dump () function in PHP?

PHP var_dump () Function 1 Definition and Usage. The var_dump () function dumps information about one or more variables. The information holds type and value of the variable (s). 2 Syntax 3 Parameter Values 4 Technical Details

What does var_dump_pre() do?

This one automatically adds the PRE tags around the var_dump output so you get nice formatted arrays. This one returns the value of var_dump instead of outputting it. Fairly simple functions, but they're infinitely helpful (I use var_dump_pre () almost exclusively now). I post a new var_dump function with colors and collapse features.

What does $B mean in var_dump ()?

$b = "Hello world!"; The var_dump () function dumps information about one or more variables. The information holds type and value of the variable (s).

How to debug UN-minified JavaScript and CSS core files in WordPress?

Learn how to use the un-minified JavaScript and CSS core files for debugging purposes, To start debugging, go to the wp-config.php file in the root of the WordPress file system and turn on the debug variable, i.e., set debug to true: Defining this constant as true will cause all PHP errors, notices, and warnings to be displayed on the screen.


2 Answers

Try killing the flow right after the var_dump, that ussually helps me debug easier:

var_dump($types);
die("products_first_ends");

That way if something after your var_dump is rendering on top of the var dump it wont get covered by it.

like image 54
taxicala Avatar answered Oct 13 '22 00:10

taxicala


shutdown hook can be used, add this code to functions.php:

function custom_dump($anything){
  add_action('shutdown', function () use ($anything) {
    echo "<div style='position: absolute; z-index: 100; left: 30px; bottom: 30px; right: 30px; background-color: white;'>";
    var_dump($anything);
    echo "</div>";
  });
}
like image 33
Narek Malkhasyan Avatar answered Oct 13 '22 00:10

Narek Malkhasyan