Load_TextDomain(); // Setup the Widget data $this->WP_Widget ( False, $this->t('Random images'), Array('description' => $this->t('Shows random images on your sidebar.'))); $this->base_url = get_option('siteurl').'/'.Str_Replace("\\", '/', SubStr(RealPath(DirName(__FILE__)), Strlen(ABSPATH))); // Register as Widget Add_Action ('widgets_init', Array($this, 'Register')); } Function Register(){ Register_Widget(get_class($this)); Add_Action('wp_head', Array($this, 'Include_CSS')); } Function Load_TextDomain(){ $this->text_domain = get_class($this); load_textdomain ($this->text_domain, DirName(__FILE__).'/language/'.get_locale().'.mo'); } Function t ($text, $context = ''){ // Translates the string $text with context $context If ($context == '') return __($text, $this->text_domain); Else return _x($text, $context, $this->text_domain); } Function Include_CSS(){ Echo ''; } Function widget ($args, $settings){ If ($settings['title'] == '') $settings['title'] = $this->t('Random images'); If ($settings['limit'] == '') $settings['limit'] = 4; Else $settings['limit'] = IntVal($settings['limit']); // Get gallery posts If (method_exists('wp_plugin_post_special_properties', 'get_gallery_posts')) $arr_gallery = wp_plugin_post_special_properties::get_gallery_posts(-1); // Get all gallery posts Else return False; // Get random images $arr_item = Array(); ForEach ($arr_gallery AS $gallery){ $arr_gallery_element = theme_functions::get_post_preview_image($gallery->ID, Ceil($settings['limit'] / Count($arr_gallery))); ForEach ($arr_gallery_element AS $gallery_element){ $arr_item[] = Array ($gallery, $gallery_element); } } // Randomize items Shuffle ($arr_item); // Crop to the limit List($arr_item) = Array_Chunk ($arr_item, $settings['limit']); // print html to sidebar Echo $args['before_widget']; Echo $args['before_title'].$settings['title'].$args['after_title']; Echo '
'; ForEach ($arr_item AS $item){ $gallery =& $item[0]; $image =& $item[1]; Echo ''; } Echo '
'; Echo $args['after_widget']; } Function form ($settings){ // Show Form Echo $this->t('Title:').'
'; Echo $this->t('Number of images:').'
'; } Function update ($new_settings, $old_settings){ return $new_settings; } } /* End of Class */ New widget_random_images(); } /* End of If-Class-Exists-Condition */ /* End of File */