Example #1
0
 /**
  * The static method that will actually call WP Router to generate the routes.
  *
  * This is the method that will be called by the 'wp_router_generate_routes' action.
  *
  * @param  WP_router $router A WP Router instance.
  * @param  tad_FunctionsAdapterInterface $f An optionally injected functions adapter.
  *
  * @return void
  */
 public static function generateRoutes(WP_Router $router, tad_FunctionsAdapterInterface $f = null)
 {
     if (is_null($f)) {
         $f = new tad_FunctionsAdapter();
     }
     // action hook for plugins and themes to act on the route
     $f->do_action('route_before_adding_routes', self::$routes);
     foreach (self::$routes as $routeId => $args) {
         $router->add_route($routeId, $args);
         /**
          * Allow for extending classes to act on the route and circumvent PHP 5.2 lack
          * of late static binding.
          * Extending classes should:
          *  - register as classes extending the WPRouting_Route one using the tad_Static::setClassExtending method
          *  - implement the `actOnRoute` method
          */
         $class = tad_Static::getClassExtending(__CLASS__);
         if ($class and $class != __CLASS__) {
             if (method_exists($class, 'actOnRoute')) {
                 call_user_func(array($class, 'actOnRoute'), $routeId, $args);
             }
         }
     }
     // action hook for plugins and themes to act on the route
     $f->do_action('route_after_adding_routes', self::$routes);
 }
 protected function maybeInitStaticHelper()
 {
     if (is_null(tad_Static::getClassExtending(self::PARENT_CLASS))) {
         tad_Static::setClassExtending(self::PARENT_CLASS, __CLASS__);
     }
 }