예제 #1
0
  public static function dispatch_ajax($action) {

    MasterPress::$ajax_action = $_REQUEST["method"];
    MasterPress::$controller_key = $_REQUEST["controller"];
    
    if ( wp_verify_nonce($_REQUEST["nonce"], "mp-ajax-nonce") ) {

      MPC::incl(MasterPress::$controller_key);

      $controller_class = MasterPress::controller_class(MasterPress::$controller_key);

      if (class_exists($controller_class)) {
        MasterPress::$controller = new $controller_class();
        
        $method = str_replace("-", "_", MasterPress::$ajax_action);
        $ajax_method = "ajax_".$method;
        
        if (method_exists(MasterPress::$controller, $ajax_method)) {
          MasterPress::$controller->$ajax_method();
        } else if (method_exists(MasterPress::$controller, $method)) {
          MasterPress::$controller->$method();
        }

      }

    }
    exit();
  }