do_the_methods() static public method

The "the_" method can call virtual methods and/or delegate to a view or a model. The view and model can both be the same object if needed.
static public do_the_methods ( string | object $view, string | object $model, string $method_name, array $args ) : mixed
$view string | object
$model string | object
$method_name string
$args array
return mixed
Beispiel #1
0
 /**
  * Magic method for calling inaccessible methods
  * Examples:
  *  $this->date             Return original ISO 8601 date format from model
  *  $this->get_date()       Return custom formatted date
  *  $this->get_date_html()  Return custom formatted date HTML
  *  $this->the_date()       Output custom formatted date
  *  $this->the_date_html()  Output custom formatted date HTML
  *
  * @param string $method_name
  * @param array  $args
  *
  * @return mixed|null
  */
 function __call($method_name, $args = array())
 {
     $value = null;
     if (false !== strpos($method_name, 'the_')) {
         $value = WPLib::do_the_methods($this, $this->model(), $method_name, $args);
     } else {
         $value = call_user_func_array(array($this->model(), $method_name), $args);
     }
     return $value;
 }
Beispiel #2
0
 /**
  * Generate debugging error message for attempts to call a non-existent method.
  *
  * @param string $method_name
  * @param array  $args
  *
  * @return mixed
  */
 function __call($method_name, $args)
 {
     $value = null;
     if (preg_match('#^the_#', $method_name) && is_callable(array($this, $method_name))) {
         $value = WPLib::do_the_methods($this, $this, $method_name, $args);
     } else {
         /*
          * Oops. No method was found.  Output an error message.
          */
         $message = sprintf(__('ERROR: There is no method %s() in class %s. ', 'wplib'), $method_name, get_class($this));
         WPLib::trigger_error($message, E_USER_ERROR);
     }
     return $value;
 }