Why when I instantiate wp_error in a validation method my user registration method stops working?

It seems you need to use $errors = new \WP_Error(); in your code, since WP_Error isn’t part of your namespace. I ran a quick test on my machine, using wp-cli commands: Using new WP_Error(): % wp eval ‘namespace PJ\NS\Test; $x = new WP_Error(); var_dump( $x );’ Fatal error: Uncaught Error: Class ‘PJ\NS\Test\WP_Error’ not found in … Read more

Is $hook a global variable in WordPress

Ok – so, firstly you should know that it is a variable and not a function – in php this is indicated by the dollar symbol before the name: $variable as opposed to function() Second, you should note that $hook is passed as a parameter to the function block – like so: function_name( $hook ){ … Read more

Question about the template-loader.php file

The conditional first checks against what gets returned from the template_include hook. In most cases, a template will be found, and there will be no issue. We’ll only move onto the 2nd conditional if template_include cannot find or cannot load the template. We then look at the WP_Theme object, which does some base-line checks to … Read more

Adding graphics to 404.php page

How are you changing the text and links? If you’re editing a 404.php file, then you simply need to add html to output whatever images you want, i.e.: <img src=”https://www.google.com/images/logos/ps_logo2.png” /> Will output this: For more on HTML, check out w3schools.com’s excellent material: http://www.w3schools.com/html/

if statement on database query

On your if(), it should be like this: if (!($wpdb->get_row(“SELECT voter_ip FROM ” . $wpdb->prefix . “voter_ips WHERE post_id = $post_id AND voter_ip = ‘$voter_ip'”) Notice the quotation mark added on $voter_ip.

WP database error for comments_popup_link()

Your template code includes $wpdb->print_error(). This function prints the last database error between [ and ] brackets, and the executed SQL code. But if there is no error, you just see the empty brackets and the SQL. $wpdb->show_errors() is used to enable displaying of database errors. If you want to see all database errors, you … Read more

Auto-add paragraphs to custom field?

Why don’t you use apply_filters( ‘the_content’, $var ); when outputting your custom field? You don’t really want to save the extra paragraphs, otherwise you’ll end up seeing them when editing the custom field. This is not what happens with WordPress. If you’re not happy with what the_content does (it does a lot of things including … Read more

Can’t use get_results() in ajax query

This will not work because you call example.com/markers.php directly, and that file does not load anything from WordPress, like the $wpdb object. You can include wp-load.php, but this might break if you move the WordPress installation to somewhere else. To be more in line with how Ajax calls in WordPress should be made, you should … Read more