• Resolved mrengy

    (@mrengy)


    I’m trying to debug a function that is run on the WordPress attachment_fields_to_edit filter. When I run something like

    do_action( 'qm/debug', $form_fields);

    or even

    do_action( 'qm/debug', 'test');

    … from within the function run on that filter

    and view a page like https://localhost:10003/wp-admin/upload.php?item=126

    nothing shows up in the “logs” tab under Query Monitor.

    Full code of the relevant part of functions.php

    function my_attachment_fields_to_edit( $form_fields ) {
    	    // debug not working here
    	    do_action( 'qm/debug', 'test');
    
                // apply to these taxonomies
    	    $taxonomies_arr = ['submitter_name', 'submitter_email', 'creator_name'];
    		foreach ( $taxonomies_arr as $taxonomy ) {
    
    	    // Do nothing if the Submitter Email field is not in the fields list.
    	    if ( ! isset( $form_fields[ $taxonomy ] ) ) {
    	       continue;
    	    } else {
    		    // Get the term by its slug.
    		    $field = (array) $form_fields[ $taxonomy ];
    		    $term  = empty( $field['taxonomy'] ) ? null :
    		        get_term_by( 'slug', $field['value'], $taxonomy );
    
    		    // Use the term name.
    		    if ( $term instanceof WP_Term ) {
    		        $form_fields[ $taxonomy ]['value'] = $term->name;
    		    }
    			}
    
    	    }
                // debug not working here
    	    do_action( 'qm/debug', $form_fields);
    
        return $form_fields;
    }
    
    add_filter( 'attachment_fields_to_edit', 'my_attachment_fields_to_edit' );

    Debugging in other places works as expected. How can I get these debug messages to show?

    PHP 7.4.1
    WordPress 5.9.3
    Query Monitor 3.9.0

    • This topic was modified 2 years, 10 months ago by mrengy. Reason: cleaned up code, added basic example
    • This topic was modified 2 years, 10 months ago by mrengy. Reason: added versions

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    This is because the media library items are loaded via Ajax so they’re not part of the main request, hence the logging won’t show up in QM.

    I’ve got a solution for this in the pipeline but there’s no ETA yet.

    Thread Starter mrengy

    (@mrengy)

    Thanks. I am really looking forward to the solution for this ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘debug not working inside a WordPress filter’ is closed to new replies.