Skip to content

Instantly share code, notes, and snippets.

@jswelker
Created September 26, 2014 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jswelker/7c672c56be62b9d5fe58 to your computer and use it in GitHub Desktop.
Save jswelker/7c672c56be62b9d5fe58 to your computer and use it in GitHub Desktop.
<?php
class MySortingPluginClass{
//The $page_data variable is passed in through the hook system and contains page content data
public function sort_boxes( $page_data ){
usort( $page_data["boxes"], "sort_boxes_by_title");
return $page_data;
}
//This method is called by usort() above and sorts boxes by comparing the title string of two boxes
private function sort_boxes_by_title( $box_a, $box_b ){
strnatcmp( $box_a["title"], $box_b["title"] );
}
}
//Register the plugin with the on_page_load hook. "MySortingPluginClass" tells the hook system which class to initialize,
//"sort_boxes" is the method to call, and "on_page_load" is the name of the hook, which controls what data
//to pass into the function and what to expect back (in this case, an associative array of page data).
register_plugin( "MySortingPluginClass", "sort_boxes", "on_page_load" );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment