Getting a list of WordPress hook actions

January 18th, 2012 by Alex No comments »

Sometimes content is outputted somewhere where I don’t need (when I run do_action), and I can’t really see what action does that. So to get the list of WordPress actions attached to a hook, use this kind of code:

global $wp_filter;
var_dump($wp_filter['comment_form']);

You will get then something like this:

array(1) {
  [10]=>
  array(2) {
    ["wp_comment_form_unfiltered_html_nonce"]=>
    array(2) {
      ["function"]=>
      string(37) "wp_comment_form_unfiltered_html_nonce"
      ["accepted_args"]=>
      int(1)
    }
    ["akismet_add_comment_nonce"]=>
    array(2) {
      ["function"]=>
      string(25) "akismet_add_comment_nonce"
      ["accepted_args"]=>
      int(1)
    }
  }
}

Pretty cool, now we know what produces all that output.

How to disable Flash, JavaScript and Cookies in Google Chrome

January 17th, 2012 by Alex No comments »

For those who just need the shortcuts, here’s the link to JavaScript and Cookies options:

chrome://settings/content

For Flash, Silverlight, Quicktime and other similar addons, the link is:

chrome://plugins

Issue with Flash uploader and Suhosin PHP patch

January 11th, 2012 by Alex No comments »

This is a very simply situation: we use multiple files Flash uploader to display progress, and for other extended functionality when uploading files. But this issue was killing me. After installing Suhosin patch, the session was breaking after any file upload.

This was made because Suhosin checks the User-Agent also, and Flash has a different user agent from the browser. Even providing a session id to Flash won’t solve the issue because Suhosin checks the user agents when session_id/session_start is called.

To solve this issue, simply disable user agent encrypting, but leave the IP address encrypting in php.ini:

suhosin.session.encrypt = On
suhosin.session.cryptraddr = On
suhosin.session.cryptua = Off

Coloring regions in Google Maps JavaScript API v3

December 22nd, 2011 by Alex No comments »

Want to color a map region in Google Maps V3? Easy as pie: load map, centrify on a particular point, define polygon points and options, attach polygon to map with polygon.setMap:

Loading …


<div id="color-maps" style="height: 400px">
  <div style='padding-top: 180px; text-align: center'>Loading ...</div>
</div>
 
<script type='text/javascript' src='http://maps.googleapis.com/maps/api/js?sensor=false'></script>
<script type='text/javascript'>
function colormaps() {
  // 1. setup map
  var myLatlng = new google.maps.LatLng(25, -70);
  var myOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("color-maps"), myOptions);
  // 2. define points and polygon
  var triangleCoords = [
    new google.maps.LatLng(25.774252, -80.190262),
    new google.maps.LatLng(18.466465, -66.118292),
    new google.maps.LatLng(32.321384, -64.75737),
    new google.maps.LatLng(25.774252, -80.190262)
  ];
  var bermudaTriangle = new google.maps.Polygon({
    paths: triangleCoords,
    strokeColor: "#E01B2F",
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: "#E01B2F",
    fillOpacity: 0.35
  });
  // 3. attach polygon to map
  bermudaTriangle.setMap(map);
}
google.maps.event.addDomListener(window, 'load', colormaps);
</script>

MySQL regexp word boundary explained

December 22nd, 2011 by Alex No comments »

The word boundary regexp is something you may need when a list of data is saved in a single column. Example:

id   numbers
1    2,34,647
2    78,102,342
3    34,78,103

Now our task would be to select IDs where numbers contain “2″ and “34″. One would say that we can do

SELECT * FROM mytable WHERE numbers LIKE "2" OR numbers LIKE "34"

But that won’t work correctly, because 2 will match 2, 102 and 342, which is something we don’t need. In this case MySQL word boundary regex comes handy:

SELECT * FROM mytable WHERE numbers REGEXP "[[:<:]]2[[:>:]]" OR numbers REGEXP "[[:<:]]34[[:>:]]"

Take a look at [[:<:]] and [[:>:]]. This is all we need here. The word boundary regex makes sure the match we are looking for is a standalone word, matching without commas and spaces, and making sure the “2″ word doesn’t have additional letters/numbers on left/right side. This is pretty awesome and saves our day!