Changeset 1917788
- Timestamp:
- 07/31/2018 06:20:10 PM (7 years ago)
- Location:
- blog-post-filter
- Files:
-
- 2 added
- 5 edited
-
assets/screenshot-2.png (added)
-
assets/screenshot-3.png (added)
-
trunk/adminPage.php (modified) (3 diffs)
-
trunk/blog-post-filter.php (modified) (2 diffs)
-
trunk/languages/blog-post-filter-fa_IR.mo (modified) (previous)
-
trunk/languages/blog-post-filter-fa_IR.po (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
blog-post-filter/trunk/adminPage.php
r1263008 r1917788 3 3 function BlogPostFilterAdminPage(){ 4 4 add_action('admin_init', array(&$this, 'registerOptionSetting')); 5 6 add_posts_page ( 7 __('post filtering', 'blog-post-filter'), //string $page_title, 8 __('post filtering', 'blog-post-filter'), //string $menu_title, 9 'manage_options', //string $capability, 10 'blog-post-filter-setting', //string $menu_slug, 11 array(&$this, 'setting') //callback $function = '' 5 6 add_posts_page ( 7 __('post filtering', 'blog-post-filter'), //string $page_title, 8 __('post filtering', 'blog-post-filter'), //string $menu_title, 9 'manage_options', //string $capability, 10 'blog-post-filter-setting', //string $menu_slug, 11 array(&$this, 'setting') //callback $function = '' 12 12 ); 13 13 } 14 14 15 15 private $optionValues; 16 16 17 function showCategories($parentid = ''){ 17 18 $categories = get_categories(array('parent' => $parentid, 'hide_empty' => 0)); 18 19 if(count($categories)<1) return; 19 20 20 21 echo '<ol>'; 21 22 foreach($categories as $category){ 22 23 echo '<li>'; 23 echo '<input type="checkbox" name="blogPostFilterCategories['.$category->cat_ID.']" value="1" '.($this->optionValues[$category->cat_ID]=='0'? '': 'checked').' >';24 echo $category->name;25 echo '('.$category->category_count.')' ;24 echo '<input type="checkbox" name="blogPostFilterCategories['.$category->cat_ID.']" id="blogPostFilterCategories_'.$category->cat_ID.'" value="1" '.($this->optionValues[$category->cat_ID]=='0'? '': 'checked').' >'; 25 echo '<label for="blogPostFilterCategories_'.$category->cat_ID.'">' . $category->name; 26 echo '('.$category->category_count.')' . '</label>'; 26 27 $this->showCategories($category->cat_ID); 27 28 echo '</li>'; … … 29 30 echo '</ol>'; 30 31 } 31 32 33 function showFilterStickyPost() { 34 $filterSticky = get_option('blogPostFilterStickyPosts'); 35 $checkedYes = ($filterSticky == 1)? 'checked': ''; 36 $checkedNo = ($filterSticky == 0)? 'checked': ''; 37 echo '<p>'; 38 echo '<span>'.__('Would you like to filter sticky posts', 'blog-post-filter').'?</span>'; 39 echo ' '; 40 echo '<input type="radio" name="blogPostFilterStickyPosts" value="1" id="bpfsp_yes" ' .$checkedYes. ' />'; 41 echo '<label for="bpfsp_yes">' .__('Yes'). '</label>'; 42 echo ' '; 43 echo '<input type="radio" name="blogPostFilterStickyPosts" value="0" id="bpfsp_no" ' .$checkedNo. ' />'; 44 echo '<label for="bpfsp_no">' .__('No').' ('. __('Default').') '. '</label>'; 45 echo '</p>'; 46 } 47 32 48 function setting(){ 33 49 echo '<div class="wrap">'; 34 echo '<h2>'.__('Please select the categories that you would like show their posts on the front page', 'blog-post-filter').'.</h2>'; 50 echo '<h1>'.__('Post Filtering', 'blog-post-filter').'</h1>'; 51 echo '<form method="post" action="options.php">'; 52 settings_fields('blog-post-filter-option-group'); 53 //do_settings_section('blog-post-filter-option-group'); 54 55 echo '<h2>'.__('Sticky Post Filtering', 'blog-post-filter').'</h2>'; 56 echo '<p>'.__('By default, sticky posts will not be filtered. Select "Yes" below, to filter them', 'blog-post-filter').'.</p>'; 57 $this->showFilterStickyPost(); 58 59 echo '<h2>'.__('Select Categories', 'blog-post-filter').'</h2>'; 60 echo '<p>'.__('Please select the categories that you would like show their posts on the front page', 'blog-post-filter').'.</p>'; 35 61 echo '<p>'.__('Only posts that are at least in one of selected categories will be shown on the front page', 'blog-post-filter').'.</p>'; 36 echo '<form method="post" action="options.php">'; 37 settings_fields('blog-post-filter-option-group'); 38 //do_settings_section('blog-post-filter-option-group'); 39 62 40 63 $this->optionValues = get_option('blogPostFilterCategories'); 41 64 42 65 $this->showCategories(0); 43 66 44 67 submit_button(); 45 68 echo '</form>'; 46 69 echo '</div>'; 47 70 } 48 71 49 72 function registerOptionSetting(){ 50 73 register_setting( 51 'blog-post-filter-option-group', 74 'blog-post-filter-option-group', 52 75 'blogPostFilterCategories', 53 array(&$this, 'validateOption') 76 array( 77 'sanitize_callback'=>array(&$this, 'validateOption') ) 78 ); 79 register_setting( 80 'blog-post-filter-option-group', 81 'blogPostFilterStickyPosts', 82 array('default'=> '0') 54 83 ); 55 84 } 56 85 57 86 function validateOption($values){ 58 87 $input = array(); … … 62 91 return $input; 63 92 } 64 93 65 94 } -
blog-post-filter/trunk/blog-post-filter.php
r1263008 r1917788 4 4 * Plugin URI: http://www.sloth.ir/ 5 5 * Description: Blog Post Filter filters frontpage posts by their categories. 6 * Version: 1. 0.06 * Version: 1.1.0 7 7 * Author: ammar.shahraki 8 8 * Author URI: http://www.sloth.ir/ammar-shahraki … … 15 15 public function __construct(){ 16 16 add_action('plugins_loaded', array(&$this, 'loadTextDomain') ); 17 add_action('admin_menu', array(&$this, 'settingPage'));17 add_action('admin_menu', array(&$this, 'settingPage')); 18 18 add_action('pre_get_posts', array(&$this, 'filterCategories')); 19 19 } 20 20 21 function getDirectPosts($categoryList){ 22 $directPostIds = array(); 23 foreach ($categoryList as $category) { 24 $children = get_term_children($category, 'category'); 25 $chilePostIDs = array(); 26 if(count($children)>0) 27 $chilePostIDs = get_posts(array( 28 'fields' => 'ids', // Only get post IDs 29 'category' => implode(',', $children), 30 'posts_per_page' => -1, 31 'numberposts' => -1 32 )); 33 $allPostIDs = get_posts(array( 34 'fields' => 'ids', // Only get post IDs 35 'category' => $category, 36 'posts_per_page' => -1, 37 'numberposts' => -1 38 )); 39 40 $directPostIds=array_merge($directPostIds, array_diff($allPostIDs, $chilePostIDs)); 41 } 42 return $directPostIds; 43 } 44 21 45 function filterCategories($query) { 22 46 if ($query->is_main_query() && is_home()) { 23 47 48 $filterSticky = get_option('blogPostFilterStickyPosts'); 49 $allowed = get_option('blogPostFilterCategories'); 50 24 51 $categoryList = array(); 25 $allowed = get_option('blogPostFilterCategories'); 52 $hiddenCategories = array(); 53 26 54 foreach($allowed as $id=>$status) 27 if($status==1){ 28 $categoryList[] = $id; 29 } 30 $query->set('cat', implode(',', $categoryList)); 55 if($status == 1) 56 $visibleCategories[] = $id; 57 else 58 $hiddenCategories[] = $id; 59 60 if ($filterSticky == 0) { 61 $query->set('category__in', $visibleCategories); 62 // //$query->set('cat', implode(',', $visibleCategories)); 63 // //$query->set('ignore_sticky_posts', 'true'); 64 } else if(count($hiddenCategories)>0) { 65 // $visiblePostIDs = get_posts(array( 66 // 'fields' => 'ids', // Only get post IDs 67 // 'category' => implode(',', $visibleCategories), 68 // 'posts_per_page' => -1, 69 // 'numberposts' => -1, 70 // 'include_children' => false 71 // )); 72 // 73 // $hiddenPostIDs = get_posts(array( 74 // 'fields' => 'ids', // Only get post IDs 75 // 'category' => implode(',', $hiddenCategories), 76 // 'posts_per_page' => -1, 77 // 'numberposts' => -1 78 // )); 79 // 80 // $postIDs = array_diff($hiddenPostIDs,$visiblePostIDs); 81 82 $postIDs = $this->getDirectPosts($hiddenCategories); 83 84 $query->set('post__not_in', $postIDs); 85 } 31 86 } 32 87 } 33 88 34 89 function settingPage(){ 35 90 //load_textdomain('blog-post-filter', plugin_dir_path( __FILE__ ) . '/languages/fa_IR.mo'); 36 91 new BlogPostFilterAdminPage(); 37 92 } 38 93 39 94 function loadTextDomain(){ 40 95 //load_plugin_textdomain('blog-post-filter', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 41 load_plugin_textdomain('blog-post-filter', false, basename( dirname( __FILE__ ) ) . '/languages' ); 96 load_plugin_textdomain('blog-post-filter', false, basename( dirname( __FILE__ ) ) . '/languages' ); 42 97 } 43 98 } -
blog-post-filter/trunk/languages/blog-post-filter-fa_IR.po
r1263008 r1917788 4 4 # Ammar Shahraki Ebrahimi <[email protected]>, 2015. 5 5 # 6 #, fuzzy7 6 msgid "" 8 7 msgstr "" 9 8 "Project-Id-Version: blog-post-filter\n" 10 9 "POT-Creation-Date: 2015-08-10 15:20+0430\n" 11 "PO-Revision-Date: 201 5-08-10 15:27+0430\n"10 "PO-Revision-Date: 2018-07-31 17:22+0000\n" 12 11 "Last-Translator: Ammar Shahraki Ebrahimi\n" 13 12 "Language-Team: \n" … … 15 14 "Content-Type: text/plain; charset=UTF-8\n" 16 15 "Content-Transfer-Encoding: 8bit\n" 17 "X-Generator: Poedit 1.8. 4\n"16 "X-Generator: Poedit 1.8.7.1\n" 18 17 "X-Poedit-Basepath: .\n" 19 18 "Plural-Forms: nplurals=1; plural=0;\n" 20 19 "Language: fa_IR\n" 21 20 22 ## ............................................................................ 21 # # ............................................................................ 22 # @ blog-post-filter 23 msgid "Blog Post Filter" 24 msgstr "غربالگری نوشتههای بلاگ" 23 25 24 # @ blog-post-filter25 msgid "Blog Post Filter "26 msgstr " غربالگری نوشته های بلاگ"26 # @ blog-post-filter 27 msgid "Blog Post Filter filters frontpage posts by their categories." 28 msgstr "نوشتههای صفحه نخست را بر اساس دسته آنها غربال میکند." 27 29 28 #@ blog-post-filter 29 msgid "Blog Post Filter filters frontpage posts by their categories." 30 msgstr "نوشته های صفحه نخست را بر اساس دسته آنها غربال می کند." 31 32 #@ blog-post-filter 30 # @ blog-post-filter 33 31 msgid "ammar.shahraki" 34 32 msgstr "عمار شهرکی ابراهیمی" … … 36 34 #: adminPage.php:8 37 35 msgid "post filtering" 38 msgstr "غربالگری نوشته ها"36 msgstr "غربالگری نوشتهها" 39 37 40 #: adminPage.php: 35 38 #: adminPage.php:50 39 msgid "Post Filtering" 40 msgstr "غربالگری نوشتهها" 41 42 #: adminPage.php:55 43 msgid "Sticky Post Filtering" 44 msgstr "غربالگری نوشتههای چسبنده" 45 46 #: adminPage.php:56 47 msgid "By default, sticky posts will not be filtered. Select \"Yes\" below, to filter them" 48 msgstr "به طور پیشفرض، نوشتههای چسبنده غربال نمیشوند. برای غربالگری آنها گزینه «بلی» را انتخاب کنید" 49 50 #: adminPage.php:0 51 msgid "Select Categories" 52 msgstr "دستهها را انتخاب کنید" 53 54 #: adminPage.php:38 55 msgid "Would you like to filter sticky posts" 56 msgstr "آیا میخواهید نوشتههای چسبنده را غربال کنید" 57 58 #: adminPage.php:60 41 59 msgid "Please select the categories that you would like show their posts on the front page" 42 msgstr "دسته هایی که میخواهید نوشته های آنها در صفحه نخست نمایش داده شود را انتخاب کنید"60 msgstr "دستههایی که میخواهید نوشته های آنها در صفحه نخست نمایش داده شود را انتخاب کنید" 43 61 44 #: adminPage.php: 3662 #: adminPage.php:61 45 63 msgid "Only posts that are at least in one of selected categories will be shown on the front page" 46 msgstr "فقط نوشته هایی که دستکم در یکی از دستههای انتخاب شده باشند در صفحه نخست نمایش داده خواهند شد"64 msgstr "فقط نوشتههایی که دستکم در یکی از دستههای انتخاب شده باشند در صفحه نخست نمایش داده خواهند شد" -
blog-post-filter/trunk/readme.txt
r1815917 r1917788 4 4 Tags: filter, categories, category, frontpage, post 5 5 Requires at least: 4.2.4 6 Tested up to: 4.9.2 7 Stable tag: trunk 6 Tested up to: 4.9.7 7 Requires PHP: 5.2.4 8 Stable tag: 1.0.1 8 9 License: GPLv2 or later 9 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 40 41 == Screenshots == 41 42 42 1. Preview of the Blog Post Filter's admin page. 43 1. Preview of the Blog Post Filter's admin page (v1.0.1). 44 2. Preview of the Blog Post Filter's admin page (v1.1.0). 45 3. Persian translation of the plugin (v1.1.0). 43 46 44 47 == Changelog == 48 49 = 1.1.0 = 50 * Added an option to filter sticky posts. 51 52 = 1.0.1 = 53 * Minor bug fix. 45 54 46 55 = 1.0.0 =
Note: See TracChangeset
for help on using the changeset viewer.