Enable WordPress Debug only for Admin

Do this: if(!function_exists(‘display_php_error_for_admin’)) { function display_php_error_for_admin() { $user_id = get_current_user_id(); $user_meta = get_userdata($user_id); $roles = $user_meta->roles; if(is_array($roles)){ if (in_array(“administrator”, $roles)) { error_reporting(0); @ini_set(‘display_errors’, 0); } }elseif ($roles == “administrator”){ error_reporting(0); @ini_set(‘display_errors’, 0); } } } add_action(‘init’,’display_php_error_for_admin’);

debugging wordpress

if you set WP_DEBUG to true in wp-config.php it should output all your errors. Alternatively, you can use something like Debug Bar or BlackBox to display the errors. How much you need should determine your solution.

The plugin generated xx characters of unexpected output. How to solve?

The issue appears to be in the formatting of your mp_calcs_display() function. I modified the function to use the heredoc syntax for your html output, and was then able to activate the plugin successfully. function mp_calcs_display() { $output = <<<HTML <form name=”calsinput” action=”” method=”post” id=”calsinput” ><h1> Process </h1> <p> operation type always robot </p> <br> … Read more

Using debug log in production, is that a security concern?

I would consider it a security concern if everyone is able to view the debug.log file from the browser. It could reveal e.g. paths, plugins and their problems. There are though ways to restrict access to it via Nginx or Apache. Another problem I’ve seen with logging to debug.log on production sites is that it’s … Read more

xdebug connects but won’t break in WordPress with vvv

In my case it turned out to be a path mapping issue. Adding… “pathMappings” : { “/srv/www” : “C:\\Users\\tmorgan\\websites\\local\\www” } …fixed it for me. In other words, explicitly specifying how the server path related to my local file path was necessary. I did not think this was the case because xdebug was connecting to my … Read more

How to dump/log default values that are passed to hooks/filter functions?

If you want to keep your log on the server, try using php’s error_log() which is more flexible than just writing to files on disk. Something along the lines of: add_filter(‘manage_edit-member_columns’, ‘set_custom_edit_member_columns’); function set_custom_edit_member_columns($columns) { error_log(print_r($columns,true),3,__DIR__.”/log.txt”); $columns[‘photo’] = “Photo”; return $columns; } OTOH, if you find the browser console more convenient, you should include a … Read more

if(!is_user_logged_in()) returns true when 404

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 header.php file, so it’s better to use … Read more

Send specific users an email when posts are published

Do you know if your wp_mail() function is working at all? Do you know whether or not your function isn’t failing higher in the chain? I’d re-write the function like this, which makes it a little easier to read and also slightly more efficient as we are only running functions that we absolutely need to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)