Posted By

Zayac on 12/05/12


Tagged

ajax wordpress only wpdb


Versions (?)

wordpress include wpdb only (wpdb for ajax)


 / Published in: PHP
 

So, you define a couple of fake funcs and require WP database config, after this you can require wp-db.php, create new wpdb and use it independency of WP for your ajax actions.

  1. <?php
  2.  
  3. define('WP_DEBUG', false);
  4.  
  5. //fake funcs
  6. function is_multisite() {return true;}
  7. function apply_filters($tag, $value) { return $value; }
  8. function wp_load_translations_early() {}
  9. function __($text) { return $text; }
  10. function wp_debug_backtrace_summary( $ignore_class, $skip_frames, $pretty) { return array(); }
  11. //
  12.  
  13. $doc_root = $_SERVER['DOCUMENT_ROOT'];
  14. require $doc_root . '/db-config.php';
  15. require $doc_root . '/wp-includes/wp-db.php';
  16.  
  17. //Oh, Yeah!
  18. $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
  19.  
  20. ?>

Report this snippet  

You need to login to post a comment.