functions.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. // For adding hooks before loading WP
  3. function tests_add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
  4. global $wp_filter, $merged_filters;
  5. $idx = _test_filter_build_unique_id($tag, $function_to_add, $priority);
  6. $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
  7. unset( $merged_filters[ $tag ] );
  8. return true;
  9. }
  10. function _test_filter_build_unique_id($tag, $function, $priority) {
  11. global $wp_filter;
  12. static $filter_id_count = 0;
  13. if ( is_string($function) )
  14. return $function;
  15. if ( is_object($function) ) {
  16. // Closures are currently implemented as objects
  17. $function = array( $function, '' );
  18. } else {
  19. $function = (array) $function;
  20. }
  21. if (is_object($function[0]) ) {
  22. return spl_object_hash($function[0]) . $function[1];
  23. } else if ( is_string($function[0]) ) {
  24. // Static Calling
  25. return $function[0].$function[1];
  26. }
  27. }
  28. function _delete_all_posts() {
  29. global $wpdb;
  30. $all_posts = $wpdb->get_col("SELECT ID from {$wpdb->posts}");
  31. if ($all_posts) {
  32. foreach ($all_posts as $id)
  33. wp_delete_post( $id, true );
  34. }
  35. }