Tag Info

Hot answers tagged

18

admin-ajax.php loads wp-load.php: /** Load WordPress Bootstrap */ require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' ); wp-load.php loads wp-config.php, and there wp-settings.php is loaded. And here we find this: // Load the functions for the active theme, for both parent and child theme if applicable. if ( ! defined( 'WP_INSTALLING' ) || ...


16

Go into wp-config.php and change define('WP_DEBUG', false); to define('WP_DEBUG', true);. Also, install Andrew Nacin's Log Deprecated Notices plugin.


12

I don't think there is a universal URL hook. There are a lot of hooks and I may have missed it, but I don't think there is one. You can look through the hooks at adambrown.info. There are a lot of URL hooks, but not a universal one. If I may suggest another solution: Log the errors to a files. /** * This will log all errors notices and warnings to a file ...


11

If you're getting errors printed, then x-debug is a brilliant PHP extension that adds modern backtraces to PHP. If you're trying to work out what's going on where there are no errors, my favourite approach is to define a function which logs its output to a file. So I do plog($variable) and that appears in the log file which I can then examine. This is ...


10

Always flush the rewrite rules when you register a new public post type or taxonomy. Otherwise the internal rewrite rules will not take that into account when an URL is mapped to a query. You can automate that process by hooking into registered_post_type and registered_taxonomy. Below is the updated code, based on feedback from comments and other people. ...


8

Even though my first approach was for the garbage bin and s_ha_dums answer is a clean, and probably the best, way of going about it, let me offer one more working scenario: The following sets a cookie that is valid for the next 24 hours (86400 seconds) when an administrator logs into the system. In wp-config.php, the constant WP_DEBUG is conditionally ...


8

Resources on how to use the WordPress unit-test: WordPress Automated Tests Trac Automated Testing in The Codex The Unit-Test README File The PHPUnit Manual Hakre/WP Unit-Tests Codex Page


6

You can paste this block of code in your currently active WordPress theme functions.php file: function wpse_footer_db_queries(){ echo '<!-- '.get_num_queries().' queries in '.timer_stop(0).' seconds. -->'.PHP_EOL; } add_action('wp_footer', 'wpse_footer_db_queries'); The above block of code, will render an HTML comment in the footer of your theme ...


5

Add … define( 'SAVEQUERIES', TRUE ); … to your wp-config.php, and inspect $wpdb->queries at shutdown. That is the latest hook and the only one after which no queries are fired. Plus, it works on wp-admin/ too. Sample code as a plugin: <?php /** * Plugin Name: T5 Inspect Queries * Description: Adds a list of all queries at the end of each file. ...


5

The items are set up in wp_nav_menu(). There is a useful filter you can use: 'wp_nav_menu_objects'. It offers the items as $sorted_menu_items and the arguments of the wp_nav_menu() call as $args. From wp-includes/nav-menu-template.php::wp_nav_menu(): $sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args ); So … hook into ...


5

You can find the version in wp-includes/version.php, the $wp_version variable. It can also be found in the readme.html file in the root of the WordPress folder.


5

There's a global variable called $wp_scripts which is an instance of the WP_Scripts class. It doesn't have a public API for looking at registered or enqueued scripts, but you can look inside the object and see what's going on. You can see all the registered scripts with: global $wp_scripts; var_dump( $wp_scripts->registered ); To see the enqueued ...


5

After tinkering with a number of IDE's, I settled into plain old Notepad++ with an ultra-customized Syntax Highlighting color scheme. I have a macro set up such that when I hit Shift-Ctrl-X , the following code gets output where my cursor is: echo "<pre>"; var_dump($); echo "</pre>"; exit(); It's simple, but I can generally hunt down 90% of ...


5

I debug the old fashioned way, error_log()ing and var_dumping. I find that is the most efficient way for me, I have a couple of wrapper functions to handle different types of data, as error_loging arrays and objects can be a pain. Also, using print_r() in can be tricky to read when it is not in a <pre>. I have tj_log() for error logging, and tj() for ...


5

There are multiple tools and possibilities, and shure it would be nice to have something quick at hand. I know plugin authors who do offer debug flags so you can analyze what's going on quite easy. As for plugins, I have not tested it but looked at some screenshots and it is at least informative: Debug Bar (Wordpress Plugin) and the BlackBox Debug Bar ...


4

Create a cron job for a function which checks the file size and runs unlink( WP_CONTENT_DIR . '/debug.log' ) if necessary.


4

You can see the detailed list of the hook using this snippet: $hook_name = 'admin_bar_menu'; global $wp_filter; var_dump( $wp_filter[$hook_name] );


4

Just a quick update that a new method is_main_query() has been introduced in WP 3.3. Example: add_action( 'pre_get_posts', 'foo_modify_query_exclude_category' ); function foo_modify_query_exclude_category( $query ) { if ( $query->is_main_query() && ! $query->get( 'cat' ) ) $query->set( 'cat', '-5' ); } Resources: WPDevel: New ...


4

I wrote a little class for make a logfile, is very useful when you are debugging ajax calls. http://github.com/hunk/Magic-Fields/blob/master/tools/debug.php You only needs do something like: Debug::log("This is a debug message"); When that line is executed a the message will be added in the log file and after that you can use the tail command ...


4

The only way to debug this is to disable one plugin at a time, each time trying to reproduce the problem before you disable another plugin. Start with the plugins that have anything to do with the administration of WP, then move down to regular theme plugins, widgets and such. Inspect the "Not Found" page that you are served better (browse with Opera and ...


4

Please try this for your redirect: add_action( 'template_redirect', function(){ // no non-authenticated users allowed if( ! is_user_logged_in() ) { wp_redirect( home_url( '/wp-login.php' ), 302 ); exit(); } }); to allow only logged in users to view your site. It's generally too late to use redirect directly in the ...


4

There's a native PHP function get_included_files() for that. Simply attach it to an action on the hook from where you want to know it. The first one is muplugins_loaded and the last accessible on is shutdown. add_action( 'muplugins_loaded', function() { $files = get_included_files(); foreach ( $files as $f ) echo $f.'<br>'; // ...


4

Yes. It is possible and you're on the right track! :) AJAX calls happen "behind the scenes" and no screen output is generated during the process no matter what you echo or print_r - that's why you don't see anything returned to you - instead that server response is captured by javascript and acted upon there. That gives you two basic options for debugging ...


4

In other words, you should not perform a wp_enqueue_style which is not hooked to wp_enqueue_script. Your wp_enqueue_style should be in a function, and you should hook that function to wp_enqueue_scripts like in the following example: function wpse88755_enqueue(){ # call wp_enqueue_style here } #hook the function to wp_enqueue_scripts add_action( ...


4

I gave up on using the plugin and use FirePHP straight as a mu-plugin: And firebug.php file consists of: <?php /* Plugin Name: FirePHP Version: 0.1 */ require_once( 'FirePHPCore/FirePHP.class.php' ); ob_start(); $firephp = FirePHP::getInstance( true ); function logit( $var, $title='From FirePHP:' ) { global $firephp; ...


4

There sure is, I talk about some of those options in this Q&A here: Is there a flowchart for wordpress loading sequence? Here is a very brief summary of what was said, Want to see what actions get fired during a request? Take a look at this plugin by Toscho Want to see what's hooked and where with what priority? Take a look at this plugin ...


3

There is also this plug-in: https://github.com/stephenh1988/sh-hook-debug Built by myself and based on my answer to this question: How can I find out what functions are assigned to actions?) It adds a search to the admin bar, and allows you to search through all hooks that were used. Clicking that hook, you are presented with a list of functions hooked ...


3

It doesn't answer your question precisely, but from personal experience I found it is better to enable debug mode by matching IP address instead of URL. That requires to modification of links and solves how to identify admin before WP loads required user functionality.


3

From your title: register_sidebar_widget() is deprecated since version 2.8! Use wp_register_sidebar_widget() instead. Somewhere in your Theme - in functions.php, or in a function included within functions.php - you're adding custom Widgets. Look for that code, and replace usage of register_sidebar_widget() with wp_register_sidebar_widget(). PROTIP: ...



Only top voted, non community-wiki answers of a minimum length are eligible