--- name: wp-debugging description: WordPress debugging, dependency checking, and local development patterns. Use when debugging WordPress issues, checking plugin dependencies, setting up local environments, resolving conflicts, or troubleshooting errors in themes and plugins. --- # WordPress Debugging & Dependency Management Comprehensive debugging techniques, dependency checking, local development patterns, and conflict resolution for WordPress themes and plugins. ## When to Use **Use when:** - Debugging PHP errors, warnings, notices - Checking if required plugins are active - Setting up local development environments - Resolving plugin/theme conflicts - Troubleshooting performance issues - Setting up wp-config.php debug options - Using Query Monitor, Debug Bar, or other tools --- ## Debug Mode Configuration ### wp-config.php Debug Settings ```php $trace ) { $log_entry .= sprintf( " #%d %s:%d %s()\n", $i, $trace['file'] ?? 'unknown', $trace['line'] ?? 0, $trace['function'] ?? 'unknown' ); } } error_log( $log_entry ); } // Usage examples plugin_name_log( 'Plugin initialized' ); plugin_name_log( 'User action', 'info', array( 'user_id' => 123 ) ); plugin_name_log( $user_data, 'debug' ); // Arrays/objects plugin_name_log( 'Something went wrong', 'error' ); // Includes backtrace ``` ### Conditional Logging ```php 123 ) ); ``` --- ## Dependency Checking ### Check Required Plugins ```php 'Display Name' * * @var array */ private static $required_plugins = array( 'woocommerce/woocommerce.php' => 'WooCommerce', 'advanced-custom-fields/acf.php' => 'Advanced Custom Fields', 'buddypress/bp-loader.php' => 'BuddyPress', ); /** * Optional plugins (enhanced features). * * @var array */ private static $optional_plugins = array( 'query-monitor/query-monitor.php' => 'Query Monitor', ); /** * Minimum PHP version. * * @var string */ private static $min_php_version = '8.0'; /** * Minimum WordPress version. * * @var string */ private static $min_wp_version = '6.0'; /** * Check all dependencies. * * @return bool True if all dependencies met. */ public static function check() { $errors = array(); // Check PHP version if ( version_compare( PHP_VERSION, self::$min_php_version, '<' ) ) { $errors[] = sprintf( /* translators: 1: Required PHP version, 2: Current PHP version */ __( 'PHP %1$s or higher is required. You are running PHP %2$s.', 'plugin-name' ), self::$min_php_version, PHP_VERSION ); } // Check WordPress version if ( version_compare( get_bloginfo( 'version' ), self::$min_wp_version, '<' ) ) { $errors[] = sprintf( /* translators: 1: Required WP version, 2: Current WP version */ __( 'WordPress %1$s or higher is required. You are running WordPress %2$s.', 'plugin-name' ), self::$min_wp_version, get_bloginfo( 'version' ) ); } // Check required plugins $missing_plugins = self::get_missing_plugins(); if ( ! empty( $missing_plugins ) ) { $errors[] = sprintf( /* translators: %s: List of missing plugins */ __( 'The following required plugins are missing or inactive: %s', 'plugin-name' ), implode( ', ', $missing_plugins ) ); } if ( ! empty( $errors ) ) { add_action( 'admin_notices', function() use ( $errors ) { self::display_admin_notice( $errors ); }); return false; } return true; } /** * Get list of missing required plugins. * * @return array Missing plugin names. */ public static function get_missing_plugins() { if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $missing = array(); foreach ( self::$required_plugins as $plugin_path => $plugin_name ) { if ( ! is_plugin_active( $plugin_path ) ) { $missing[] = $plugin_name; } } return $missing; } /** * Check if a specific plugin is active. * * @param string $plugin_path Plugin path (e.g., 'woocommerce/woocommerce.php'). * @return bool */ public static function is_plugin_active( $plugin_path ) { if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } return is_plugin_active( $plugin_path ); } /** * Check if WooCommerce is active. * * @return bool */ public static function is_woocommerce_active() { return self::is_plugin_active( 'woocommerce/woocommerce.php' ); } /** * Check if BuddyPress is active. * * @return bool */ public static function is_buddypress_active() { return self::is_plugin_active( 'buddypress/bp-loader.php' ) || function_exists( 'buddypress' ); } /** * Check if ACF is active. * * @return bool */ public static function is_acf_active() { return self::is_plugin_active( 'advanced-custom-fields/acf.php' ) || self::is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) || class_exists( 'ACF' ); } /** * Check if Elementor is active. * * @return bool */ public static function is_elementor_active() { return defined( 'ELEMENTOR_VERSION' ); } /** * Display admin notice for missing dependencies. * * @param array $errors Error messages. */ private static function display_admin_notice( $errors ) { ?>
| Queries: | |
| Load Time: | ms |
';
var_dump( $var );
echo '';
}
}
}
if ( ! function_exists( 'console_log' ) ) {
/**
* Log to browser console.
*
* @param mixed $data Data to log.
* @param string $label Optional label.
*/
function console_log( $data, $label = '' ) {
if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
return;
}
$js_data = wp_json_encode( $data );
$label = esc_js( $label );
add_action( 'wp_footer', function() use ( $js_data, $label ) {
echo "";
});
add_action( 'admin_footer', function() use ( $js_data, $label ) {
echo "";
});
}
}
// Usage
dump( $user_data );
dd( $query_results ); // Stops execution
console_log( $ajax_response, 'API Response' );
```
---
## Conflict Detection
### Plugin Conflict Checker
```php
array(
'name' => 'Conflicting Plugin',
'reason' => 'Uses same shortcode [example]',
'resolve' => 'Deactivate one of the plugins or use the filter to change shortcode.',
),
'another-conflict/plugin.php' => array(
'name' => 'Another Plugin',
'reason' => 'Overrides same hooks with different priority',
'resolve' => 'Adjust hook priority using filters.',
),
);
/**
* Check for known conflicts.
*
* @return array Active conflicts.
*/
public static function check_conflicts() {
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$conflicts = array();
foreach ( self::$known_conflicts as $plugin_path => $info ) {
if ( is_plugin_active( $plugin_path ) ) {
$conflicts[ $plugin_path ] = $info;
}
}
return $conflicts;
}
/**
* Display conflict warnings in admin.
*/
public static function display_conflict_notices() {
$conflicts = self::check_conflicts();
if ( empty( $conflicts ) ) {
return;
}
add_action( 'admin_notices', function() use ( $conflicts ) {
?>
$info ) : ?>
: