Load_TextDomain(); // Add MetaBox and Set Action to save it Add_Action( 'admin_menu', Array($this, 'Add_Meta_Box') ); Add_Action( 'save_post', Array($this, 'Save_Meta_Box_Inputs') ); // Add post classes Add_Action( 'post_class', Array($this, 'post_class') ); // Include Widgets Require_Once DirName(__FILE__).'/widget_featured_posts.php'; Require_Once DirName(__FILE__).'/widget_gallery_posts.php'; Require_Once DirName(__FILE__).'/widget_random_images.php'; } 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 Add_Meta_Box(){ Add_Meta_Box( 'post_special_properties', $this->t('Special properties of this post'), Array($this, 'print_meta_box'), 'post', 'advanced', 'high' ); } Function Print_Meta_Box(){ ?>

t('Featured post') ?>

is_featured()) ? 'checked="checked"' : '' ?> /> t('This post is a featured one.') ?>

t('Gallery') ?>

is_gallery()) ? 'checked="checked"' : '' ?> /> t('Mark this post as gallery.') ?>

meta_key(); // Delete all old meta field $arr_custom_field = get_post_custom_keys($post_id); If (Is_Array($arr_custom_field)){ ForEach ($arr_custom_field AS $key) If (SubStr($key, 0, StrLen($meta_key)) == $meta_key) delete_post_meta($post_id, $key); } // if there are no values of our form we dont care If (!IsSet ($_REQUEST[$meta_key])) return False; // Save as meta data in the post ForEach ($_REQUEST[$meta_key] AS $key => $property) update_post_meta ($post_id, $meta_key.'_'.$key, $property); } Function post_class ($arr_class){ // Read Post id $post_id = get_the_id(); // check the class Array If (!Is_Array($arr_class)) $arr_class = Array(); // Check if the post has any properties If ($this->is_featured()) $arr_class[] = 'featured-post'; If ($this->is_gallery()) $arr_class[] = 'gallery-post'; // return the classes return $arr_class; } Function CheckForMeta ($meta_key, $post_id = Null){ If ($post_id == Null){ Global $post; $post_id = $post->ID; } Else $post_id = IntVal ($post_id); If (get_post_meta($post_id, self::meta_key().'_'.$meta_key, True)) return True; Else return False; } Function is_featured ($post_id = Null){ If (self::CheckForMeta('is_featured', $post_id)) return True; Else return False; } Function is_gallery ($post_id = Null){ If (self::CheckForMeta('is_gallery', $post_id)) return True; Else return False; } Function get_featured_posts ($limit = -1){ $arr_post =& get_posts (Array( 'meta_key' => self::meta_key().'_'.'is_featured', 'numberposts' => $limit )); If (!Empty($arr_post)) return $arr_post; Else return False; } Function get_gallery_posts ($limit = -1){ $arr_post =& get_posts (Array( 'meta_key' => self::meta_key().'_'.'is_gallery', 'numberposts' => $limit )); If (!Empty($arr_post)) return $arr_post; Else return False; } } /* End of Class */ New wp_plugin_post_special_properties(); } /* End of If-Class-Exists-Condition */ /* End of File */