function get_author_avatar() { global $default; $avatar = ''; if (class_exists('author_image')) { $avatar = author_image::get(); } if ($avatar == '') { if (in_the_loop()) { $author_id = get_the_author_ID(); } elseif (is_singular()) { global $wp_the_query; $author_id = $wp_the_query->posts[0]->post_author; } elseif (is_author()) { global $wp_the_query; $author_id = $wp_the_query->get_queried_object_id(); } $author = get_userdata($author_id); if (!empty($author)) { $avatar = get_avatar($author->user_email, 64, $default, $author->display_name); } else { $avatar = '<img src="' . esc_url($default) . '" alt="' . $author->display_name . '" />'; } } return $avatar; }
/** * edit_image() * * @return void **/ function edit_image() { if (!is_dir(WP_CONTENT_DIR . '/authors') && !wp_mkdir_p(WP_CONTENT_DIR . '/authors')) { echo '<div class="error">' . '<p>' . sprintf(__('Author Images requires that your %s folder be writable by the server', 'sem-author-image'), 'wp-content') . '</p>' . '</div>' . "\n"; return; } elseif (!is_writable(WP_CONTENT_DIR . '/authors')) { echo '<div class="error">' . '<p>' . sprintf(__('Author Images requires that your %s folder be writable by the server', 'sem-author-image'), 'wp-content/authors') . '</p>' . '</div>' . "\n"; return; } echo '<h3>' . __('Author Image', 'sem-author-image') . '</h3>'; global $profileuser; $author_id = $profileuser->ID; $author_image = author_image::get_meta($author_id); $author_image_url = content_url() . '/authors/' . str_replace(' ', rawurlencode(' '), $author_image); echo '<table class="form-table">'; if ($author_image) { echo '<tr valign="top">' . '<td colspan="2">' . '<img src="' . esc_url($author_image_url) . '" alt="" />' . '<br />' . "\n"; if (is_writable(WP_CONTENT_DIR . '/authors/' . $author_image)) { echo '<label for="delete_author_image">' . '<input type="checkbox"' . ' id="delete_author_image" name="delete_author_image"' . ' />' . ' ' . __('Delete author image', 'sem-author-image') . '</label>'; } else { echo __('This author image is not writable by the server.', 'sem-author-image'); } echo '</td></tr>' . "\n"; } if (!$author_image || is_writable(WP_CONTENT_DIR . '/authors/' . $author_image)) { echo '<tr valign-"top">' . '<th scope="row">' . __('New Image', 'sem-author-image') . '</th>' . '<td>'; echo '<input type="file"' . ' id="author_image" name="author_image"' . ' />' . ' '; if (defined('GLOB_BRACE')) { echo __('(jpg, jpeg or png)', 'sem-author-image') . "\n"; } else { echo __('(jpg)', 'sem-author-image') . "\n"; } echo '</td>' . '</tr>' . "\n"; } echo '<tr>' . '<th><label for="sem_aboutme_page">About Me Page</label></th>' . '<td>' . '<input type="text" name="sem_aboutme_page" id="sem_aboutme_page" value="' . esc_attr(get_the_author_meta('sem_aboutme_page', $author_id)) . '" class="regular-text" /><br />' . '<span class="description">Please enter an alternate About Me page for the image' . "'s url.</span>" . '</td>' . '</tr>'; echo '</table>' . "\n"; }
/** * form() * * @param array $instance * @return void **/ function form($instance) { $instance = wp_parse_args($instance, author_image::defaults()); extract($instance, EXTR_SKIP); echo '<p>' . '<label>' . __('Title:', 'sem-author-image') . '<input type="text" id="' . $this->get_field_name('title') . '" class="widefat"' . ' name="' . $this->get_field_name('title') . '"' . ' value="' . esc_attr($title) . '"' . ' />' . '</label>' . '</p>' . "\n"; echo '<p>' . '<label>' . __('Width: ', 'sem-author-image') . '<input type="text" size="4" name="' . $this->get_field_name('width') . '"' . ' value="' . intval($width) . '"' . ' />' . '</label>' . "\n"; echo '<label>' . __('Height: ', 'sem-author-image') . '<input type="text" size="4" name="' . $this->get_field_name('height') . '"' . ' value="' . intval($height) . '"' . ' />' . '</label>' . '</p>' . "\n" . '<p><i>' . __('Leave width and height at 0 to use dimensions from the uploaded image itself.', 'sem-author-image') . '</i></p>' . "\n"; echo '<p>' . '<label>' . '<input type="checkbox"' . ' name="' . $this->get_field_name('bio') . '" ' . checked($bio, true, false) . ' />' . ' ' . __('Display the author\'s bio', 'sem-author-image') . '</label>' . '</p>' . "\n"; echo '<p>' . '<label>' . '<input type="checkbox"' . ' name="' . $this->get_field_name('link') . '" ' . checked($link, true, false) . ' />' . ' ' . __('Link to the author\'s posts', 'sem-author-image') . '</label>' . '</p>' . "\n"; echo '<p>' . '<label>' . '<input type="checkbox"' . ' name="' . $this->get_field_name('always') . '" ' . checked($always, true, false) . ' />' . ' ' . __('This site has a single author', 'sem-author-image') . '</label>' . '</p>' . "\n" . '<p><i>' . __('Normally, this widget will only output something when in the loop or on singular posts or pages. Check the above checkbox if a single author has an image.', 'sem-author-image') . '</i></p>' . "\n"; }