コード例 #1
0
 protected function get_template_part($args, $instance)
 {
     $sidebar_slug = $args['id'];
     do_action('get_template_part_' . $this->slug, $this->slug, $sidebar_slug);
     $template_names = array($this->slug . '-' . $sidebar_slug . '.php', $this->slug . '.php');
     $template_paths = Utility::get_template_paths();
     $located = false;
     foreach ($template_names as $template_name) {
         foreach ($template_paths as $template_path) {
             if (file_exists($template_path . $template_name)) {
                 $located = $template_path . $template_name;
                 break;
             }
         }
         if ($located) {
             break;
         }
     }
     if ($located) {
         $this->load_template_file($located, $instance);
     } elseif ($this->args['template_file'] && file_exists($this->args['template_file'])) {
         $this->load_template_file($this->args['template_file'], $instance);
     } elseif ($this->args['template_callback'] && is_callable($this->args['template_callback'])) {
         $this->load_template_callback($this->args['template_callback'], $instance);
     } else {
         App::doing_it_wrong(__METHOD__, sprintf(__('The widget %s is missing a valid template file or callback. You must provide either a template file or a callback function for it.', 'widgets-definitely'), $this->slug), '0.5.0');
     }
 }