Developer Debug Tools
The Developer Debug Tools plugin has some useful functions and hooks for developers to use to further enhance its functionality.
- ddtt_is_dev()
- ddtt_print_r() / dpr()
- ddtt_var_dump_to_string();
- ddtt_alert()
- ddtt_console()
- ddtt_write_log()
- ddtt_backtrace()
- ddtt_debug_form_post()
- ddtt_admin_error()
- ddtt_start_timer()
- ddtt_stop_timer()
- ddtt_increase_test_number()
- ddtt_is_site()
- ddtt_get_plugins_data()
- ddtt_wpconfig_snippets
- ddtt_htaccess_snippets
- ddtt_highlight_debug_log
- ddtt_debug_log_help_col
- ddtt_debug_log_max_filesize
- ddtt_resource_links
- ddtt_recommended_plugins
- ddtt_quick_link_icon
- ddtt_quick_link_post_types
- ddtt_admin_bar_dropdown_links
- ddtt_admin_bar_condensed_items
- ddtt_omit_shortcodes
- ddtt_admin_list_update_each_user
- ddtt_admin_list_update_each_post
- ddtt_on_update_user_meta
- ddtt_on_update_post_meta
- ddtt_ignore_pages_for_discord_notifications
- ddtt_bots_to_log
ddtt_is_dev( $email = false, $array = false )
TYPE ⇢ Function
Checks if the current user is a developer.
PARAMETERS:
$email
(bool)
Default:false
Settrue
to return the developer email(s)$array
(bool)
Default:false
Only works if$email
istrue
; returns the emails as an Array or String. Default istrue
for String; setfalse
for Array
Example Usage
// Only do something if the current user is a developer
if ( ddtt_is_dev() ) { ... }
// Retrieve the developer email as a string
$dev_email = ddtt_is_dev( true );
// Retrieve all developer emails in an array
$dev_emails = ddtt_is_dev( true, true );
ddtt_print_r( $var, $user_id = null, $left_margin = null, $write_bool = true ) / dpr()
TYPE ⇢ Function
ALTERNATIVE SHORT FUNCTION: dpr() => ddtt_print_r()
An extended version of print_r()
. Wraps it in <pre> tags </pre> automatically. You can use the short dpr()
or long ddtt_print_r()
version of the function (in some cases dpr
might be used by another plugin or theme, so a long version is available).
PARAMETERS:
$var
(mixed - required)
What you want to print$user_id
(int | array | null)
Default:null
Display only to the specified user(s). Default is all developers.$left_margin
(int | string | true | null)
Default:null
Add space to the left margin of what you are printing in case it becomes hidden behind the admin menu or other elements. Settrue
to add 250px, which is the width of the admin menu sidebar plus some padding.$write_bool
(bool)
Default:true
Displays "TRUE" and "FALSE" instead of 1 and nothing.
Example Usage
// Print a variable that only developers can see
dpr( $var ); /* or */ ddtt_print_r( $var );
// Display an array in pretty print
dpr( $array );
// Make it visible to other users (for instance if you switch to another user to test an issue they are having)
// Whereas 3 and 7 are user ids
dpr( $var, 3 ); /* or */ dpr( $var, [ 3, 7 ] );
// Add left margin to move the printed information out from behind the admin menu sidebar
global $menu;
dpr( $menu, null, true );
ddtt_var_dump_to_string( $var );
TYPE ⇢ Function
Convert var_dump()
to a string. Useful when logging it to the error log.
PARAMETERS:
$var
(mixed - required)
What you want to dump.
Example Usage
// Log the var_dump() to the error log
error_log( ddtt_var_dump_to_string( $var ) );
ddtt_alert( $msg, $user_id = null )
TYPE ⇢ Function
Add JavaScript alert in PHP.
PARAMETERS:
$msg
(string - required)
The message that you want to display in an alert.$user_id
(int | null)
Default:null
Display only to the specified user. Default is all developers.
Example Usage
// Display a javascript alert with PHP
ddtt_alert( $var );
// Make it visible to other users (for instance if you switch to another user to test an issue they are having)
// Whereas 3 is the user id
ddtt_alert( $var, 3 );
ddtt_console( $msg )
TYPE ⇢ Function
Add JavaScript console.log
in PHP. This will be visible to everyone that opens their dev console, so it really should just be used for temporary testing.
PARAMETERS:
$msg
(string - required)
The message that you want to display in the console.
Example Usage
// Display something in the developer console
ddtt_console( $var );
ddtt_write_log( $log, $prefix = true, $backtrace = false, $full_stacktrace = false )
TYPE ⇢ Function
An extended version of error_log()
that writes to the debug log. Automatically wraps arrays and objects in print_r()
to be logged. Will only log if WP_DEBUG
is set to true
.
PARAMETERS:
$log
(mixed - required)
What you want to log to the debug log.$prefix
(string | bool)
Default:true
Iftrue
, adds "DDTT_LOG: " to beginning of line. You can use your ownString
as a prefix orfalse
to remove.$backtrace
(bool)
Include file and line number the function is called on.$full_stacktrace
(bool)
Include the full stack trace of where the function is called.
Example Usage
// Testing which condition is running
ddtt_write_log( 'Test Before' ); /* Prints: DDTT_LOG: Test Before */
if ( $item == 'example 1' ) {
// Do something
ddtt_write_log( 'Passed condition 1' ); /* Prints: DDTT_LOG: Passed condition 1 */
} elseif ( $item == 'example 2' ) {
// Do something
ddtt_write_log( 'Passed condition 2' ); /* Prints: DDTT_LOG: Passed condition 2 */
} else {
// Do something
ddtt_write_log( 'Else condition' ); /* Prints: DDTT_LOG: Else condition */
}
// Logging an array or object
ddtt_write_log( $array );
// Remove or change the prefix
ddtt_write_log( $array, false ); /* or */ ddtt_write_log( $array, 'ME: ' );
ddtt_backtrace( $ignore_class = null, $skip_frames = 0, $pretty = true )
TYPE ⇢ Function
Log a comma-separated string or array of functions that have been called to get to the current point in code. Basically logs wp_debug_backtrace_summary()
to debug.log
using ddtt_write_log()
.
PARAMETERS:
$ignore_class
(string)
Default:null
A class to ignore all function calls within – useful when you want to just give info about the callee.$skip_frames
(int)
Default:0
A number of stack frames to skip – useful for unwinding back to the source of the issue.$pretty
(bool)
Default:true
Whether you want a comma separated string instead of the raw array returned.
Example Usage
// Log a simple backtrace for debugging
ddtt_backtrace();
// Skip the first 2 stack frames in the trace
ddtt_backtrace( null, 2 );
// Ignore a specific class in the backtrace summary
ddtt_backtrace( 'My_Plugin_Class' );
// Return the backtrace in raw format instead of a pretty string
ddtt_backtrace( null, 0, false );
// Combine options: ignore a class, skip 1 frame, and get raw output
ddtt_backtrace( 'WP_Hook', 1, false );
ddtt_debug_form_post( $email, $test_number = 1, $subject = "Test Form $_POST " )
TYPE ⇢ Function
Send a sanitized summary of all $_POST
data to a specified email address for debugging purposes. Useful for inspecting form submissions during development or troubleshooting without exposing data on-screen.
PARAMETERS:
$email
(string - required)
The email you want to send debug email to.$test_number
(int)
Default:1
Adds a test number to the subject so you know which test you are attempting.$subject
(string)
Default:"Test Form $_POST"
Change the subject.
Example Usage
// Send the contents of $_POST to your email
ddtt_debug_form_post( 'dev@example.com' );
// Specify a test number to differentiate multiple test submissions
ddtt_debug_form_post( 'dev@example.com', 2 );
// Customize the subject line of the debug email
ddtt_debug_form_post( 'dev@example.com', 1, 'Debugging Contact Form Submission #' );
ddtt_admin_error( $msg, $include_pre = true, $br = true, $hide_error = false )
TYPE ⇢ Function
Display an admin-only error message on the front or back end, intended for development and debugging. Only users with the Administrator role will see the message, and you can optionally suppress it or customize its formatting.
PARAMETERS:
$msg
(string - required)
The message you want to display as the admin error.$include_pre
(bool)
Default:true
Whether to prepend"ADMIN ERROR: "
to the message.$br
(bool)
Default:true
Whether to add a<br>
before the error message to create spacing.$hide_error
(bool)
Default:false
If set totrue
, the error will be suppressed regardless of the user’s role.
Example Usage
// Show a simple admin-only error
echo ddtt_admin_error( 'Something went wrong.' );
// Suppress the "ADMIN ERROR: " prefix
echo ddtt_admin_error( 'Missing form field.', false );
// Remove line break spacing above the error
echo ddtt_admin_error( 'Post ID not found.', true, false );
// Hide the error completely (can be toggled via flag)
$testing = false;
echo ddtt_admin_error( 'This should not appear.', true, true, $testing );
ddtt_start_timer( $timeout_seconds = 300 )
TYPE ⇢ Function
Starts a processing timer using microseconds and (optionally) increases the cURL timeout limit. Used with ddtt_stop_timer()
(see next function below) to measure how long a process takes to run.
PARAMETERS:
$timeout_seconds
(int)
Default:300
The number of seconds to temporarily extend the cURL timeout while timing. Set tonull
or0
to skip timeout changes.
ddtt_stop_timer( $start, $timeout = true, $milliseconds = false )
TYPE ⇢ Function
Stops a previously started timer (from ddtt_start_timer()
above), calculates the total elapsed time, optionally restores the cURL timeout setting, and returns the result in seconds or milliseconds.
PARAMETERS:
$start
(float - required)
The start time returned byddtt_start_timer()
.$timeout
(bool)
Default:true
Whether to restore the original cURL timeout setting after the timer stops.$milliseconds
(bool)
Default:false
Iftrue
, returns the result in milliseconds instead of seconds.
Example Usage
// Start the timer
$start = ddtt_start_timer();
// Run some code you want to measure
do_some_custom_processing();
// Stop the timer and get elapsed time in seconds
$total_time = ddtt_stop_timer( $start );
// Display result
echo 'This process took '.$total_time.' seconds.';
/* or */
// Start the timer
$start = ddtt_start_timer();
// Process several items
$number_of_items = 0;
foreach ( $some_array as $item ) {
run_something_heavy();
$number_of_items++;
}
// Stop the timer and get elapsed time in seconds
$total_time = ddtt_stop_timer( $start );
// Get the length of time it took per item
$sec_per_item = round( ( $total_time / $number_of_items ), 2 );
// Display result
echo 'This process took a total of ' . $total_time . ' seconds; ' . $sec_per_item . ' per item.';
ddtt_increase_test_number( $reset = false )
TYPE ⇢ Function
Increments a persistent test counter stored in Settings. Useful for tracking page refreshes, form submissions, or repeated test actions across sessions. Can also be reset to zero.
PARAMETERS:
$reset
(bool)
Default:false
Iftrue
, resets the counter to zero instead of incrementing it.
Example Usage
// Increase the debug test number (e.g. on each page load or form submission)
ddtt_increase_test_number();
// Reset the debug test number (e.g. when starting a new test session)
ddtt_increase_test_number( true );
// Retrieve and display the current test number
$current = get_option( 'ddtt_test_number', 0 );
echo 'Current test run: '.$current;
ddtt_is_site( $site_to_check )
TYPE ⇢ Function
Check if the current site matches (or partially matches) a given domain string. Useful for targeting site-specific logic in multisite setups or shared codebases. Accepts partial matches (e.g. "example"
matches example.com
).
PARAMETERS:
$site_to_check
(string - required)
The string to compare against the current site’s domain. Partial matches are allowed.
Example Usage
// Run specific logic only on example.com
if ( ddtt_is_site( 'example.com' ) ) {
// Do something only for example.com
}
// Use with negation to exclude logic on a specific site (devsite.com or thedevsite.org, etc)
if ( !ddtt_is_site( 'devsite' ) ) {
// Skip something on the dev site
}
ddtt_get_plugins_data()
TYPE ⇢ Function
Fetches data for all of your plugins and caches them to a transient named ddtt_plugins_data
for 1 day. You can schedule this to run at night using WP Crontrol.
Example Usage
// Hook into plugin activation to fetch plugin data
function ddtt_on_plugin_activated( $plugin ) {
// Fetch and cache the plugin data when a plugin is activated
$plugins_data = ddtt_get_plugins_data();
// You can also log or send notifications based on the data, if needed
error_log( 'Plugins data fetched after activation of: ' . $plugin );
}
add_action( 'activated_plugin', 'ddtt_on_plugin_activated' );
ddtt_wpconfig_snippets
TYPE ⇢ Filter
Add, remove or modify a snippet from the WP-CONFIG tab. Find more snippets here.
Example Usage
/**
* Add, remove or modify a snippet from the DDT WP-CONFIG tab.
* Find more snippets here: https://developer.wordpress.org/apis/wp-config-php/
*
* @param array $snippets
* @return array
*/
function ddtt_wpconfig_snippets_filter( $snippets ) {
// Add a new snippet
$snippets[ 'post_revisions' ] = [
'label' => 'Change Number of Post Revisions',
'lines' => [
[
'prefix' => 'define',
'variable' => 'WP_POST_REVISIONS',
'value' => 3
]
],
'desc' => 'Changes the number of post revisions to 3.'
];
// Remove a snippet
unset( $snippets[ 'fs_method' ] );
// Change memory limit snippet to 512M
$snippets[ 'upload_size' ][ 'lines' ] = [
[
'prefix' => '@ini_set',
'variable' => 'upload_max_size',
'value' => '512M'
],
[
'prefix' => '@ini_set',
'variable' => 'post_max_size',
'value' => '512M'
]
];
// Return the new snippet array
return $snippets;
} // End ddtt_wpconfig_snippets_filter()
add_filter( 'ddtt_wpconfig_snippets', 'ddtt_wpconfig_snippets_filter' );
ddtt_htaccess_snippets
TYPE ⇢ Filter
Add, remove or modify a snippet from the HTACCESS tab. Find more snippets here.
Example Usage
/**
* Add, remove or modify a snippet from the DDT HTACCESS tab.
*
* @param array $snippets
* @return array
*/
function ddtt_htaccess_snippets_filter( $snippets ) {
// Add a new snippet
$snippets[ 'force_trailing_slash' ] = [
'label' => 'Force Trailing Slash',
'lines' => [
'RewriteCond %{REQUEST_URI} /+[^\.]+$',
'RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]',
],
'desc' => 'Forces a trailing slash at the end of the domain.'
];
// Remove a snippet
unset( $snippets[ 'allow_backups' ] );
// Return the new snippet array
return $snippets;
} // End ddtt_htaccess_snippets_filter()
add_filter( 'ddtt_htaccess_snippets', 'ddtt_htaccess_snippets_filter' );
ddtt_highlight_debug_log
TYPE ⇢ Filter
Change highlight colors on the Error Logs tab.
Example Usage
/**
* Add or change highlight colors on the debug log.
*
* @param array $args
* @return array
*/
function ddtt_highlight_debug_log_filter( $args ) {
// Remove theme highlighting
unset( $args[ 'theme' ] );
// Highlight a debug line that contains a keyword
// Example: /wp-content/plugins/plugin-slug/my-plugin-file.php
// The keyword can be "plugin-slug" or "plugin-slug/my-plugin-file.php" if column is set to 'path'
// The $args key is used as the table row css class
$args[ 'my-plugin' ] = [
'name' => 'My Plugin', // Name that shows on the debug log key
'keyword' => 'plugin-slug', // Keyword to search in the error string
'bg_color' => '#FFE800', // Background color (accepts any css color)
'font_color' => '#000000', // Font color (accepts any css color)
'priority' => true, // Set true to prioritize over items that are false
'column' => 'path' // What to search (accepts 'err', 'path' and 'type')
];
// Return the new args array
return $args;
} // End ddtt_highlight_debug_log_filter()
add_filter( 'ddtt_highlight_debug_log', 'ddtt_highlight_debug_log_filter' );
ddtt_debug_log_help_col
TYPE ⇢ Filter
Add, remove or modify the Error Logs search links in the Help column.
Example Usage
/**
* Add, remove or modify the debug log search links in the Help column.
*
* @param array $search_links
* @return array
*/
function ddtt_debug_log_help_col_filter( $search_links ) {
// Remove Google Past Year
unset( $search_links[ 'google_past_year' ] );
// Add your own search link
// Use anything you want as the array key; it is only used for reference
// URL prefix must include the search parameter as the last parameter in the URL
// Example: https://www.google.com/search?as_qdr=y&q= where q=these+are+the+keywords
// Format must include at least one merge tag that is passed from the log line:
// {type} = "PHP Notice"
// {err} = "Trying to get property 'xxx' of non-object"
// {path} = "/wp-content/plugins/woocommerce/templates/xxx.php"
// If filter is set to 'plugin' or 'theme', it will only show if the line is a plugin or theme
// If filter is set to 'path', it will only show if a path exists
// Otherwise set filter to false to apply to all lines
$search_links[ 'ask_jeeves' ] = [
'name' => 'Ask Jeeves',
'url' => 'https://askjeeves.net/results.html?q=',
'format' => '{type}: {err}',
'filter' => false
];
// Return the new args array
return $search_links;
} // End ddtt_debug_log_help_col_filter()
add_filter( 'ddtt_debug_log_help_col', 'ddtt_debug_log_help_col_filter' );
ddtt_debug_log_max_filesize
TYPE ⇢ Filter
Change the max file size for the Error Logs viewer. Default is 2 MB. You can use whatsabyte for converting to bytes.
Example Usage
/**
* Change the max file size for the debug log viewer. Default is 2 MB.
*
* @param int $bytes
* @return int
*/
function ddtt_debug_log_max_filesize_filter( $bytes ) {
// Value is in bytes
// 1 MB = 1048576 bytes, 2 MB = 2097152 bytes
return 1048576;
} // End ddtt_debug_log_max_filesize_filter()
add_filter( 'ddtt_debug_log_max_filesize', 'ddtt_debug_log_max_filesize_filter' );
ddtt_resource_links
TYPE ⇢ Filter
Add your own link to the Resources tab and the Resources admin bar dropdown.
Example Usage
/**
* Add your own link to Resources.
*
* @param array $links
* @return array
*/
function ddtt_resource_link_filter( $links ) {
// Add a new resource
$links[] = [
'title' => 'Google',
'url' => 'https://www.google.com',
'desc' => 'This is an example description.'
];
// Return the new links array
return $links;
} // End ddtt_resource_link_filter()
add_filter( 'ddtt_resource_links', 'ddtt_resource_link_filter' );
ddtt_recommended_plugins
TYPE ⇢ Filter
Add or remove a recommended plugin on the Add Plugins > Dev Debug Tools tab. Note that you can only add plugins that are in the WordPress.org repository.
Example Usage
/**
* Add or remove a recommended plugin from the plugins page.
* Note that you can only add plugins that are in the WordPress.org repository.
*
* @param array $plugin_slugs
* @return array
*/
function ddtt_recommended_plugins_filter( $plugin_slugs ) {
// Add your own recommended plugin
// Find the slug in the WP.org url (https://wordpress.org/plugins/{slug}/)
// For example: https://wordpress.org/plugins/user-switching/
$plugin_slugs[] = 'user-switching';
// Remove a recommended plugin
if ( ( $key = array_search( 'post-type-switcher', $plugin_slugs ) ) !== false ) {
unset( $plugin_slugs[ $key ] );
}
// Return the new links array
return $plugin_slugs;
} // End ddtt_recommended_plugins_filter()
add_filter( 'ddtt_recommended_plugins', 'ddtt_recommended_plugins_filter' );
ddtt_quick_link_icon
TYPE ⇢ Filter
Change the Quick Debug Link icon when quick links are added to posts and users in admin lists.
Example Usage
/**
* Change the Quick Debug Link icon when quick links are added to posts and users in admin lists.
*/
add_filter( 'ddtt_quick_link_icon', function() {
return '👍';
} );
ddtt_quick_link_post_types
TYPE ⇢ Filter
Add or remove post types that include quick links when enabled. Default is post
and page
.
Example Usage
/**
* Add or remove post types that include quick links when enabled
*
* @param array $post_types
* @return array
*/
function ddtt_quick_link_post_types_filter( $post_types ) {
// Add a single post type
$post_types[ 'listing' ] = 'listing';
// Add multiple post types
// Example adding Events Calendar plugin post types
$post_types = array_merge( $post_types, [
'tribe_events' => 'tribe_events',
'tribe_venue' => 'tribe_venue',
'tribe_organizer' => 'tribe_organizer',
] );
// Remove a post type
unset( $post_types[ 'post' ] );
// Return the post types array
return $post_types;
} // End ddtt_quick_link_post_types_filter()
add_filter( 'ddtt_quick_link_post_types', 'ddtt_quick_link_post_types_filter' );
ddtt_admin_bar_dropdown_links
TYPE ⇢ Filter
Add a link to the admin bar site name dropdown on the front-end.
Example Usage
/**
* Add a link to the admin bar site name dropdown on the front-end.
*
* @param array $links
* @return array
*/
function ddtt_admin_bar_dropdown_links_filter( $links ) {
// Add your own links
$links[] = [ 'Media', esc_url( '/'.DDTT_ADMIN_URL.'/upload.php' ) ];
// Return the new links array
return $links;
} // End ddtt_admin_bar_dropdown_links_filter()
add_filter( 'ddtt_admin_bar_dropdown_links', 'ddtt_admin_bar_dropdown_links_filter' );
ddtt_admin_bar_condensed_items
TYPE ⇢ Filter
Modify the admin bar icons that get condensed when the option is set.
Example Usage
/**
* Modify the admin bar icons that get condensed when the option is set.
*
* @param array $condensed_items The menu item id
* @return array
*/
function ddtt_admin_bar_condensed_items_filter( $condensed_items ) {
// Lookup menu item ids with global $wp_admin_bar; or with console log <li id="wp-admin-bar-{id}">
// Stop condensing the site name
unset( $condensed_items[ 'site-name' ] );
// Condense a menu item that has an icon by simply removing the name
$condensed_items[ 'customize' ] = '';
// Condense a menu item that doesn't have an icon by replacing it with a shorter title
$condensed_items[ 'menu-item1-id' ] = 'WP';
// Condense a menu item that has an icon by giving it a shorter title (add left margin for space between icon and text)
$condensed_items[ 'edit' ] = '<span style="margin-left: 6px;">Edit</span>';
// Or change the title to a dashicon when there is no icon
// Lookup dashicons here: https://developer.wordpress.org/resource/dashicons/
$condensed_items[ 'menu-item2-id' ] = '<span class="ab-icon dashicons dashicons-carrot" style="margin-top: 2px;"></span>';
// Always return the condensed items array
return $condensed_items;
} // End ddtt_admin_bar_condensed_items_filter()
add_filter( 'ddtt_admin_bar_condensed_items', 'ddtt_admin_bar_condensed_items_filter' );
ddtt_omit_shortcodes
TYPE ⇢ Filter
Omit shortcodes from the admin bar shortcode finder.
Example Usage
/**
* Omit shortcodes from the admin bar shortcode finder.
*
* @param array $omits
* @return array
*/
function ddtt_omit_shortcodes_filter( $omits ) {
// Omit shortcodes starting with these keywords:
// Ex: [shortcode_name param=""]
$omits[] = 'shortcode_name';
// Return the new omits array
return $omits;
} // End ddtt_omit_shortcodes_filter()
add_filter( 'ddtt_omit_shortcodes', 'ddtt_omit_shortcodes_filter' );
ddtt_admin_list_update_each_user
TYPE ⇢ Action
Do something for each user when you load the user admin list. Must have Quick Debug Links enabled in Settings.
Why? Because sometimes we have to update meta keys for all users (sometimes in the thousands), and running a function using pagination on a smaller amount of users at a time is better for testing, processing, preventing time-outs, etc. It's also easier to do this than to code a pagination script that you're only going to use once.
Example Usage
/**
* Do something for each user when you load the user admin list.
* Must have Quick Debug Links enabled in Settings.
*
* @param int $user_id
* @return void
*/
function ddtt_update_each_user( $user_id ) {
// Only update users with subscriber role
if ( ddtt_has_role( 'subscriber', $user_id ) ) {
// Console log what I'm doing to each user
$user = get_userdata( $user_id );
ddtt_console( $user->display_name.' is a subscriber.' );
// Add/update meta key/value
update_user_meta( $user_id, 'example_meta_key', 'This is just an example' );
}
} // End ddtt_update_each_user()
add_action( 'ddtt_admin_list_update_each_user', 'ddtt_update_each_user' );
ddtt_admin_list_update_each_post
TYPE ⇢ Action
Do something for each post or page when you load the post or page admin lists. Must have Quick Debug Links enabled in Settings.
Why? Because sometimes we have to update meta keys for all posts (sometimes in the thousands), and running a function using pagination on a smaller amount of posts at a time is better for testing, processing, preventing time-outs, etc. It's also easier to do this than to code a pagination script that you're only going to use once.
Example Usage
/**
* Do something for each post or page when you load the post or page admin lists.
* Must have Quick Debug Links enabled in Settings.
*
* @param int $post_id
* @return void
*/
function ddtt_update_each_post( $post_id ) {
// Only update posts
if ( get_post_status( $post_id ) == 'publish' ) {
// Console log what I'm doing to each post
$title = get_the_title( $post_id );
ddtt_console( $title.' is published.' );
// Add/update meta key/value
update_post_meta( $post_id, 'example_meta_key', 'This is just an example' );
}
} // End ddtt_update_each_post()
add_action( 'ddtt_admin_list_update_each_post', 'ddtt_update_each_post' );
ddtt_on_update_user_meta
TYPE ⇢ Action
Do something when you update user meta from the User Meta tab.
Example Usage
/**
* Do something when you update user meta from the DDT plugin.
*
* @param array $results
* @return void
*/
function ddtt_console_log_when_updating_user( $results ) {
// Console log results so we know what we are working with
ddtt_console( $results );
// Get the user
$user = get_userdata( $results[ 'user' ] );
// Add a message depending on how we are updating
if ( $results[ 'update' ] == 'add' ) {
$msg = 'Awesome! We added '.$results[ 'mk' ].' with '.$results[ 'val' ].' for ';
} elseif ( $results[ 'update' ] == 'upd' ) {
$msg = 'Woohoo! We updated '.$results[ 'mk' ].' with '.$results[ 'val' ].' for ';
} elseif ( $results[ 'update' ] == 'del' ) {
$msg = 'Great! We deleted the meta key '.$results[ 'mk' ].' for ';
} elseif ( $results[ 'update' ] == 'dels' ) {
$msg = 'You got it, dude! I deleted all meta keys starting with '.$results[ 'mk' ].' for ';
}
// Console a message
ddtt_console( $msg.$user->display_name );
} // End ddtt_console_log_when_updating_user()
add_action( 'ddtt_on_update_user_meta', 'ddtt_console_log_when_updating_user' );
ddtt_on_update_post_meta
TYPE ⇢ Action
Do something when you update post meta on the Post Meta tab.
Example Usage
/**
* Do something when you update post meta from the DDT plugin.
*
* @param array $results
* @return void
*/
function ddtt_console_log_when_updating_post( $results ) {
// Console log results so we know what we are working with
ddtt_console( $results );
// Get the post
$post = get_post( $results[ 'post_id' ] );
// Add a message depending on how we are updating
if ( $results[ 'update' ] == 'add' ) {
$msg = 'Awesome! We added '.$results[ 'mk' ].' with '.$results[ 'val' ].' for ';
} elseif ( $results[ 'update' ] == 'upd' ) {
$msg = 'Woohoo! We updated '.$results[ 'mk' ].' with '.$results[ 'val' ].' for ';
} elseif ( $results[ 'update' ] == 'del' ) {
$msg = 'Great! We deleted the meta key '.$results[ 'mk' ].' for ';
} elseif ( $results[ 'update' ] == 'dels' ) {
$msg = 'You got it, dude! I deleted all meta keys starting with '.$results[ 'mk' ].' for ';
}
// Console a message
ddtt_console( $msg.$post->post_title );
} // End ddtt_console_log_when_updating_post()
add_action( 'ddtt_on_update_post_meta', 'ddtt_console_log_when_updating_post' );
ddtt_ignore_pages_for_discord_notifications
TYPE ⇢ Filter
Add, remove or modify pages that should be ignored when using Discord Notifications found in Settings under Show Online Users.
Example Usage
/**
* Add, remove or modify pages that should be ignored when using Discord Notifications found in settings under Show Online Users.
*
* @param array $pages
* @return array
*/
function ddtt_ignore_pages_for_discord_notifications_filter( $pages ) {
// If `prefix` is true, it ignores all urls that start with the url you provide
// If `prefix` is false, the url must match exactly
// In this example we will ignore the media library page and all of it's queries (ie. upload.php?item=#, etc.)
$pages[] = [
'url' => ddtt_admin_url( 'upload.php' ),
'prefix' => true
];
// Return the new args array
return $pages;
} // End ddtt_ignore_pages_for_discord_notifications_filter()
add_filter( 'ddtt_ignore_pages_for_discord_notifications', 'ddtt_ignore_pages_for_discord_notifications_filter' );
ddtt_bots_to_log
TYPE ⇢ Filter
Add, remove or modify user agents that are flagged as bots to be included in the Bots Crawling Posts and Pages option of the Activity Log tab.
Current bots: AIOHTTP
, Apache HTTP Client
, Apache Nutch
, Audisto Crawler
, AwarioSmartBot
, Axios
, Baidu Spider
, Bing Bot
, BrightEdge Crawler
, BuiltWith
, Buzz Stream
, Bytespider (ByteDance)
, CCBot (Common Crawl)
, Chrome Lighthouse
, Cortex Xpanse Bot (Palo Alto Networks)
, Criteo Crawler
, Curl
, DataForSeoBot
, DuckDuckBot
, Dynatrace
, FAST Enterprise Crawler
, FAST-WebCrawler
, Facebook External Hit
, Feedbin
, Feedly
, GPTBot (ChatGPT)
, GeedoBot
, Go HTTP client
, Google APIs
, Google Ads Bot Mobile"
, Google Ads Bot
, Google Bot
, Google Feedfetcher
, Google Image Bot
, Google Inspection Tool
, Google Media Partners
, Google Mobile Bot
, Google News Bot
, Google Other
, Google Read Aloud
, Google Safety
, Google Site Verifier
, Google Store Bot
, Google Video Bot
, HTTrack Website Copier
, Headless Chrome
, HttpUnit
, HubSpot
, Iframely
, Internet Archive
, Linespider
, Linguee Bot
, LinkedIn Bot
, MSN Bot
, Majestic (MJ12Bot)
, MetaInspector
, Node Fetch
, PHPCrawl
, Page2RSS
, Perplexity AI
, PetalBot
, Proximic
, Python HTTPX
, Python OpenGraph
, Python Requests
, Python Urllib
, Turnitin
, Uptimebot
, Virustotal
, WebPageTest
, Wget
, YaCy
, Yahoo! Slurp
, Yandex
, ZGrab
, libwww-perl
Example Usage
/**
* Add a bot crawler to activity log "Bots Crawling Posts and Pages"
*
* @param array $bots
* @return array
*/
function ddtt_bots_to_log_filter( $bots ) {
// Key is the keyword to search for in the user agent. For example, if the user agent is
// Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; custombot/2.0; +http://www.example.com/custombot.htm) Chrome/xxx.xx.xxx.xxx Safari/537.36
// Then the key would be "custombot"
$bots[ 'custombot' ] = [
'name' => 'Custom Bot',
'url' => 'http://www.example.com/custombot.htm'
];
return $bots;
} // End ddtt_bots_to_log_filter()
add_filter( 'ddtt_bots_to_log', 'ddtt_bots_to_log_filter' );