<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>digitalnature &#187; Useless Stuff</title>
	<atom:link href="https://digitalnature.eu/blog/category/useless-stuff/feed/" rel="self" type="application/rss+xml" />
	<link>https://digitalnature.eu</link>
	<description>Rise Above the Ordinary</description>
	<lastBuildDate>Fri, 11 Sep 2015 15:02:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>Featured images (thumbnails) in menus</title>
		<link>https://digitalnature.eu/blog/2011/10/27/featured-images-thumbnails-in-menus/</link>
		<comments>https://digitalnature.eu/blog/2011/10/27/featured-images-thumbnails-in-menus/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 12:27:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Useless Stuff]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[menus]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://digitalnature.eu/?p=2215</guid>
		<description><![CDATA[The following code will let you use featured images as thumbnails in your custom menus. Paste this in your child theme functions.php file, or theme settings &#62; Advanced &#62; User-defined code:

atom()-&#62;setContextArgs('primary_menu', array('walker' =&#62; new ThumbMenuWalker()));

class ThumbMenuWalker  [...]]]></description>
			<content:encoded><![CDATA[<p>The following code will let you use featured images as thumbnails in your custom menus. Paste this in your child theme functions.php file, or theme settings &gt; Advanced &gt; User-defined code:</p>
<pre class="php">
atom()-&gt;setContextArgs('primary_menu', array('walker' =&gt; new ThumbMenuWalker()));

class ThumbMenuWalker extends AtomWalkerNavMenu{

  // register the thumbnail size, 64 pixel square, cropped
  function __construct(){
    add_image_size('nav-thumb', 64, 64, true);
  }

  // override start_el
  function start_el(&amp;$output, $item, $depth, $args) {

    $classes = empty($item-&gt;classes) ? array() : (array)$item-&gt;classes;

    $classes = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
    $classes = $classes ? ' class=&quot;'.esc_attr($classes).'&quot;' : '';

    $output .= &quot;\n&lt;li{$classes}&gt;&quot;;

    $attributes  = !empty($item-&gt;attr_title) ? ' title=&quot;'.esc_attr($item-&gt;attr_title).'&quot;' : '';
    $attributes .= !empty($item-&gt;target) ? ' target=&quot;'.esc_attr($item-&gt;target).'&quot;' : '';
    $attributes .= !empty($item-&gt;xfn) ? ' rel=&quot;'.esc_attr($item-&gt;xfn).'&quot;' : '';
    $attributes .= !empty($item-&gt;url) ? ' href=&quot;'.esc_attr($item-&gt;url).'&quot;' : '';

    $excerpt = $thumb = '';

    // 2nd level+
    if($depth &gt; 0){
      $post = new AtomObjectPost($item-&gt;object_id);

      // thumbnail image
      if(post_type_supports($item-&gt;object, 'thumbnail'))
        $thumb = $post-&gt;getThumbnail('nav-thumb');

    if($thumb)
      $attributes .= ' class=&quot;clear-block&quot;';

      // short description from the content, 100 is the max. character count
      $excerpt = $post-&gt;getContent(100, array(
        'cutoff'       =&gt; 'sentence',  // cut off just after the sentence ends
        'allowed_tags' =&gt; array(),     // no html
        'more'         =&gt; false,       // no 'more' text / link
      ));

      if($excerpt)
        $excerpt = &quot;&lt;small&gt;{$excerpt}&lt;/small&gt;&quot;;
      
      atom()-&gt;resetCurrentPost();
    }

    $content = $args-&gt;link_before.$thumb.'&lt;span class=&quot;tt&quot;&gt;'.apply_filters('the_title', $item-&gt;title, $item-&gt;ID).$excerpt.'&lt;/span&gt;'.$args-&gt;link_after;
    $output .= apply_filters('walker_nav_menu_start_el', &quot;{$args-&gt;before}&lt;a{$attributes}&gt;{$content}&lt;/a&gt;{$args-&gt;after}&quot;, $item, $depth, $args);
  }

}</pre>
<p>The CSS:</p>
<pre class="css">.nav img, .nav .no-img{
  float:left;
  margin-right: 5px;
} 

.nav .tt{
  overflow:hidden;
  display:block;
  font-weight:bold;  
}  

.nav small{
  font-size:11px;  
  display:block;
  margin-top: 5px;
}</pre>
<p>The result should be something like this:<br />
<img class="alignnone size-full wp-image-2216" title="Menu thumbanils" src="http://digitalnature.eu/wp-content/uploads/2011/10/thumb-menu.png" alt="Menu thumbanils" width="560" height="307" /></p>
]]></content:encoded>
			<wfw:commentRss>https://digitalnature.eu/blog/2011/10/27/featured-images-thumbnails-in-menus/feed/</wfw:commentRss>
		<slash:comments>98</slash:comments>
		</item>
		<item>
		<title>Custom avatar images in WordPress</title>
		<link>https://digitalnature.eu/blog/2011/09/18/custom-avatar-images-in-wordpress/</link>
		<comments>https://digitalnature.eu/blog/2011/09/18/custom-avatar-images-in-wordpress/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 23:28:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Useless Stuff]]></category>
		<category><![CDATA[avatars]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://digitalnature.eu/?p=1870</guid>
		<description><![CDATA[This is a short walktrough on how to let your website users upload their own avatars, without using a plugin.
First, define the maximum image sizes (note that we will only downsize, smaller images will get browser-resized):

define('MAX_AVATAR_WIDTH', 96);
define('MAX_AVATAR_HEIGHT', 96);

This  [...]]]></description>
			<content:encoded><![CDATA[<p>This is a short walktrough on how to let your website users upload their own avatars, without using a plugin.</p>
<p>First, define the maximum image sizes (note that we will only downsize, smaller images will get browser-resized):</p>
<pre class="php">
define('MAX_AVATAR_WIDTH', 96);
define('MAX_AVATAR_HEIGHT', 96);
</pre>
<p>This goes in the child theme&#8217;s functions-user.php file.</p>
<p>Next, create the form which lets users upload the image. I chose the author.php template here, but you can easily add it inside the dashboard trough some hooks.</p>
<pre class="php">
&lt;?php if(is_user_logged_in() &amp;&amp; get_current_user_id() === (int)get_query_var('author')): ?&gt;
&lt;form method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot; action=&quot;&quot;&gt;
  &lt;input type=&quot;file&quot; name=&quot;user_avatar&quot; /&gt;
  &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;wp_handle_upload&quot; /&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Upload new Avatar&quot; /&gt;
&lt;/form&gt;
&lt;?php endif; ?&gt;
</pre>
<p>The actual upload processing. You can have this in the same author template before get_header(), or inside the child theme&#8217;s functions:</p>
<pre class="php">
if(is_user_logged_in() &amp;&amp; isset($_FILES['user_avatar'])){

  // we need this for the wp_handle_upload function
  require_once ABSPATH.'wp-admin/includes/file.php';

  // ID of the current user
  $current_user_id = get_current_user_id();

  // just be aware that GIFs are annoying as fuck
  $allowed_image_types = array(
    'jpg|jpeg|jpe' =&gt; 'image/jpeg',
    'png'          =&gt; 'image/png',
    'gif'          =&gt; 'image/gif',
  );

  // let wp do the upload checks, file moving etc.
  $status = wp_handle_upload($_FILES['user_avatar'], array('mimes' =&gt; $allowed_image_types));

  // no errors? Get the uploaded file path and resize it
  if(empty($status['error'])){

    // resize it
    $resized = image_resize($status['file'], MAX_AVATAR_WIDTH, MAX_AVATAR_HEIGHT, $crop = true);

    // resize failed, display the reason
    if(is_wp_error($resized))
      wp_die($resized-&gt;get_error_message());

    // determine the resized file URL
    $uploads = wp_upload_dir();
    $resized_url = $uploads['url'].'/'.basename($resized);

    // insert the file URL into the current user meta
    update_user_meta($current_user_id, 'custom_avatar', $resized_url);

  // error, show it
  }else{
    wp_die(sprintf(__('Upload Error: %s'), $status['error']));

  }

}
</pre>
<p>Finally, hook into the avatar display function and get the avatar user meta field:</p>
<pre class="php">
add_filter('get_avatar', 'custom_avatars', 10, 3);

function custom_avatars($avatar, $id_or_email, $size){
  if(is_user_logged_in()){
    $current_user = wp_get_current_user();
    $image_url = get_user_meta($current_user-&gt;ID, 'custom_avatar', true);
    if($user_avatar !== false)
      return '&lt;img src=&quot;'.$image_url.'&quot; class=&quot;avatar photo&quot; width=&quot;'.$size.'&quot; height=&quot;'.$size.'&quot; alt=&quot;'.$current_user-&gt;display_name .'&quot; /&gt;';
  }

  return $avatar;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>https://digitalnature.eu/blog/2011/09/18/custom-avatar-images-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>83</slash:comments>
		</item>
	</channel>
</rss>
