Exemplo n.º 1
0
 protected function add($handle, $path, $dependencies, $version, $footer, $area, $type)
 {
     switch ($area) {
         case self::ADMIN:
             $hook = 'admin_enqueue_scripts';
             break;
         case self::LOGIN:
             $hook = 'login_enqueue_scripts';
             break;
         default:
             $hook = 'wp_enqueue_scripts';
     }
     $method = 'enqueue' . ucfirst($type);
     if (!method_exists($this, $method)) {
         throw new \Exception('Invalid asset type given');
     }
     $this->actions->listen($hook, function () use($handle, $path, $dependencies, $version, $footer, $area, $type) {
         switch ($type) {
             case self::TYPE_SCRIPT:
                 wp_enqueue_script($handle, $path, $dependencies, $version, $footer, $area);
                 break;
             case self::TYPE_STYLE:
                 wp_enqueue_style($handle, $path, $dependencies, $version, $footer, $area);
                 break;
         }
     });
 }
Exemplo n.º 2
0
 public function register($model)
 {
     if (is_string($model)) {
         if (!class_exists($model)) {
             throw new \InvalidArgumentException('Attempted to register a post type whose model does not exist.');
         }
         $model = new $model();
     }
     $this->actions->listen('init', function () use($model) {
         $this->makeCustomPostType($model);
     });
 }
Exemplo n.º 3
0
 public function register(MetaBox $metaBox)
 {
     $container = $this->container;
     $this->actions->listen('add_meta_boxes', function () use($metaBox, $container) {
         add_meta_box($metaBox->getId(), $metaBox->getTitle(), function () use($container, $metaBox) {
             $post = Post::resolveWordPressPostToModel(get_post());
             echo $container->call($metaBox->getOutputHandler(), ['post' => $post] + func_get_args());
         }, $metaBox->getPostType(), $metaBox->getContext(), $metaBox->getPriority());
     });
     if (is_callable($metaBox->getInputHandler())) {
         $this->actions->listen('save_post', function ($postId, $post, $isUpdate) use($metaBox, $container) {
             if ($post->post_type !== $metaBox->getPostType() || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
                 return;
             }
             $post = Post::resolveWordPressPostToModel($post);
             $container->call($metaBox->getInputHandler(), compact('metaBox', 'postId', 'post', 'isUpdate'));
         }, $metaBox->getPriority(), 3);
     }
     return $metaBox;
 }