Author: webhead

wpdb insert returning false

Problem When running wpdb->insert the result returns false.  All the values seem to check out to be fine.   Solution The problem might be due to this bug in WordPress.  Basically one of your fields is too long and WordPress

Posted in Coding Tagged with: ,

WP Cron with Basic Authentication

Problem WordPress’ cron doesn’t work when a site has basic authentication.  You basically would get a 401 error.   Solution Thanks to Nick Ohrn (in 2014) this problem is solved with a simple mu-plugin.  You just need to set the

Posted in Coding Tagged with:

Where is wp_capabilities?

Problem After creating a user with a certain role I need to do a custom sql query where it only selected users of a specific role.  This failed to find anything: select u.ID, u.display_name, u.user_login from $wpdb->users as u inner

Posted in Coding Tagged with: , ,

Chrome Zoom Shifts Layout

Problem: When zooming in or out on Chrome, the widths of elements increases very slightly and causes some elements to shift to the next line. Solution: The actual problem is Chrome adjusts the widths of elements by tenths.  So something

Posted in Coding Tagged with: ,

WordPress REST API schema property format: email

Problem:  When setting a property type to ’email’ like so: $schema = array( ‘$schema’ => ‘http://json-schema.org/schema#’, ‘title’ => ‘user’, ‘type’ => ‘object’, ‘properties’ => array( ’email’ => array( ‘description’ => __( ‘The optional email address for the something.’ ), ‘type’

Posted in Coding Tagged with: ,

WordPress Capabilities with map_meta_cap and user_has_cap

The two functions, map_meta_cap and user_has_cap allow you to change capabilities on the fly without having to add to roles in the database.  These also allow you to have a ton of flexibility. Some examples from the talk:  If you can

Posted in Coding

WordPress 4.6 crashed my site

Fatal error: Cannot redeclare the_post_thumbnail_caption() (previously declared in …. This error occurs because the_post_thumbnail_caption is a new function in WordPress 4.6.  However, people have been using this function for over 5 years now.  How?  Stackoverflow and other WordPress forums are flooded with

Posted in Coding Tagged with: ,

Escape strings for use in JavaScript

When using parameters from the URL, it should always be sanitized before using it in your javascript. Using jQuery you can easily do: var safeString = $(“<span></span>”).text(unsafeString).html(); Using plain javascript: var entityMap = { “&”: “&amp;”, “<“: “&lt;”, “>”: “&gt;”,

Posted in Coding Tagged with: , ,

Left Sidebar Under Content

Problem Having a left sidebar move under the content in a responsive design needs a bit more thinking.  You can’t just do float left width 100% or display block and let the sidebar fall to the next line. Solution When

Posted in Coding Tagged with: ,

Run WP-Cron with no visitors

Got a website with noone visits or simply a website that is private but still need WP-Cron to be run?  no problem, you have 2 easy options. 1) Setup a free account with set https://www.setcronjob.com ( i like them better because they

Posted in Coding Tagged with: