cache = $cache; $this->textdomain = strtolower(get_class($this)); $this->add_field('title', 'Enter title', '', 'text'); parent::__construct($this->textdomain, __('GitHub Profile Widget', 'f13-github'), array( 'description' => __('Some description', 'f13-github'), 'classname' => 'f13-github')); } public function widget($args, $instance) { $cache_key = 'f13_github_profile_'.sha1(serialize($instance)); $cache = get_transient( $cache_key ); if ( $cache ) { echo ''; echo $cache; return; } $m = new \F13\Github\Models\Git_api(); $data = $m->get_user( ); $starred = $m-> get_starred_count( ); $v = new \F13\Github\Views\Profile_widget(array( 'args' => $args, 'instance' => $instance, 'data' => $data, 'starred' => $starred, )); $return = $v->widget(); set_transient($cache_key, $return, $this->cache); echo ''; echo $return; } public function form( $instance ) { $v = '

Set your GitHub API tokens in the F13 Admin menu

'; foreach($this->fields as $field_name => $field_data) { if($field_data['type'] === 'text') { $v .= '

'; $v .= ''; $v .= ''; $v .= '

'; } elseif($field_data['type'] === 'number') { $v .= '

'; $v .= ''; $v .= ''; $v .= '

'; } elseif($field_data['type'] === 'password') { $v .= '

'; $v .= ''; $v .= ''; $v .= '

'; } elseif($field_data['type'] === 'checkbox') { $v .= '

'; $v .= '
'; $v .= 'textdomain) . ': ' . $field_data['type']; } } echo $v; } public function update($new_instance, $old_instance) { return $new_instance; } private function add_field($field_name, $field_description = '', $field_default_value = '', $field_type = 'text') { if(!is_array($this->fields)) $this->fields = array(); $this->fields[$field_name] = array('name' => $field_name, 'description' => $field_description, 'default_value' => $field_default_value, 'type' => $field_type); } }