Plugin Directory

Changeset 2071541


Ignore:
Timestamp:
04/19/2019 08:21:28 PM (7 years ago)
Author:
yzhs
Message:

Tested up to: 5.1.1

Location:
specify-home-hidden-categories/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • specify-home-hidden-categories/trunk/index.php

    r1903973 r2071541  
    33Plugin Name: Specify Home Hidden Categories
    44Description: Specify the Homepage&RSS hidden under all the article
    5 Plugin URI: http://www.9sep.org/specify-home-hidden-categories
    6 Version: 0.2.1
     5Plugin URI: https://www.9sep.org/specify-home-hidden-categories
     6Version: 0.2.2
    77Author: Zhys
    8 Author URI: http://www.9sep.org/author/zhys
     8Author URI: https://www.9sep.org/author/zhys
    99License: GPLv2 or later
    1010
     
    2121along with this program; if not, write to the Free Software
    2222Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    23 */
    24 defined( 'ABSPATH' ) OR exit;
    25 add_action( 'admin_init', 'specify_homepage_cats_init' );
     23 */
     24defined('ABSPATH') OR exit;
     25add_action('admin_init', 'specify_homepage_cats_init');
    2626add_filter('pre_get_posts', 'specifycats');
    2727
    28 function specify_homepage_cats_init(){
    29     if(get_bloginfo('language')=='zh-CN'||get_bloginfo('language')=='zh-TW'){
    30         $specify_tips='指定首页隐藏分类';
    31     }else{
    32         $specify_tips='Specify Categories';
    33     }
     28function specify_homepage_cats_init() {
     29    if (get_bloginfo('language') == 'zh-CN' || get_bloginfo('language') == 'zh-TW') {
     30        $specify_tips = '指定首页隐藏分类';
     31    } else {
     32        $specify_tips = 'Specify Categories';
     33    }
    3434    add_settings_field(
    3535        'specify_cats',
     
    3939        'default'
    4040    );
    41     register_setting( 'reading', 'specify_cats' );
     41    register_setting('reading', 'specify_cats');
    4242}
    4343
    44 function specify_homepage_cats_callback_function(){
    45     $options    = get_option('specify_cats');
    46     $pag        = 'specify_cats';
    47     $_cats      = get_terms( 'category' );
    48     $html      = '';
     44function specify_homepage_cats_callback_function() {
     45    $options = get_option('specify_cats');
     46    $pag = 'specify_cats';
     47    $_cats = get_terms('category');
     48    $html = '';
    4949
    50     foreach ($_cats as $term){
    51         if($options != ''){
    52             $checked = in_array($term->term_id, $options) ? 'checked="checked"' : '';
    53         }
     50    foreach ($_cats as $term) {
     51        if ($options != '') {
     52            $checked = in_array($term->term_id, $options) ? 'checked="checked"' : '';
     53        }
    5454
    55         $html .= '<p class="sep9_l">';
    56         $html .= sprintf( '<input type="checkbox" id="%1$s[%2$s]" name="%1$s[]" value="%2$s" %3$s />', $pag, $term->term_id, $checked );
    57         $html .= sprintf( '<label for="%1$s[%3$s]"> %2$s</label><br>', $pag, $term->name, $term->term_id );
    58         $html .= '</p>';
    59     }
     55        $html .= '<p class="sep9_l">';
     56        $html .= sprintf('<input type="checkbox" id="%1$s[%2$s]" name="%1$s[]" value="%2$s" %3$s />', $pag, $term->term_id, $checked);
     57        $html .= sprintf('<label for="%1$s[%3$s]"> %2$s</label><br>', $pag, $term->name, $term->term_id);
     58        $html .= '</p>';
     59    }
    6060
    61     $html .= '<p class="sep"></p>';
     61    $html .= '<p class="sep"></p>';
    6262
    63     echo $html;
     63    echo $html;
    6464}
    6565
    66 function getchild($id){
    67     $result = explode('/',get_category_children($id));
     66function getchild($id) {
     67    $result = explode('/', get_category_children($id));
    6868    $childs = array();
    69     foreach($result as $i){
    70         if(!empty($i))$childs[] = get_category($i);
     69    foreach ($result as $i) {
     70        if (!empty($i)) {
     71            $childs[] = get_category($i);
     72        }
     73
    7174    }
    7275    return $childs;
    7376}
    7477
    75 function array_get_by_key(array $array, $string){
    76     if (!trim($string)) return false;
    77     preg_match_all("/\"$string\";\w{1}:(?:\d+:|)(.*?);/", serialize($array), $res);
    78     return $res[1];
     78function array_get_by_key(array $array, $string) {
     79    if (!trim($string)) {
     80        return false;
     81    }
     82
     83    preg_match_all("/\"$string\";\w{1}:(?:\d+:|)(.*?);/", serialize($array), $res);
     84    return $res[1];
    7985}
    8086
    81 function hidecats($catID){
    82     $cata=array();
    83     foreach($catID as $i){
    84         if(!empty($i))$cata[] = get_category($i);
    85         if(get_category_children($i)!=""){
    86             $cata[]=getchild($i);
    87         }else{
    88             $cata[]=$i;
     87function hidecats($catID) {
     88    $cata = array();
     89    foreach ($catID as $i) {
     90        if (!empty($i)) {
     91            $cata[] = get_category($i);
     92        }
     93
     94        if (get_category_children($i) != "") {
     95            $cata[] = getchild($i);
     96        } else {
     97            $cata[] = $i;
    8998        }
    9099    }
    91     return array_unique(array_get_by_key($cata,'term_id'));
     100    return array_unique(array_get_by_key($cata, 'term_id'));
    92101}
    93102
    94 function specifycats($query){
    95     if ( $query->is_home || $query->is_feed ) {
     103function specifycats($query) {
     104    if ($query->is_home || $query->is_feed) {
    96105        $query->set('category__not_in', hidecats(get_option('specify_cats')));
    97106    }
    98107    return $query;
    99108}
    100 
    101 
  • specify-home-hidden-categories/trunk/readme.txt

    r1903973 r2071541  
    22Contributors: yzhs
    33Tags:  SHHC,Specify,exclude,hide,related,HiddenCategories,Specify Home Hidden,categories,Cat,options,Homepage,Home,feed,rss,get_posts,have_posts,the_post,Hidden,page,post,Posts,All,首页隐藏特定分类,首页排除指定文章不显示,隐藏分类,隐藏文章,隐藏指定分类目录文章
    4 Donate link: http://www.9sep.org/specify-home-hidden-categories
    5 Stable tag: 0.2.1
     4Donate link: https://www.9sep.org/specify-home-hidden-categories
     5Stable tag: 0.2.2
    66Requires at least: 3.5
    7 Tested up to: 4.9.6
     7Tested up to: 5.1.1
    88License: GPLv2 or later
    99
     
    3838English: author/[zhys](http://www.9sep.org/author/zhys) English is so bad, you can help me with a simple question-and-answer feature, please?
    3939
    40 中文:[Specify Home Hidden Categories常见问题回答](http://www.9sep.org/specify-home-hidden-categories#comments)
     40中文:[Specify Home Hidden Categories常见问题回答](https://www.9sep.org/specify-home-hidden-categories#comments)
    4141
    4242== Changelog ==
     
    5353*   中文:测试兼容性至WP 4.9.6,添加中文提示
    5454
     55= 0.2.2 =
     56* English: WordPress Tested up to: 5.1.1
     57* 中文:测试兼容性至WP 5.1.1
     58
    5559== Reviews ==
    5660*   中文:
     
    6367
    6468== Upgrade Notice ==
     692019-04-20 00 Tested up to: 5.1.1
     702018-07-04 20 Tested up to: 4.9.6
     712015-07-27 14 Tested up to: 4.2.3
    65722015-01-16 16   Tested up to: 4.1
    66 2015-07-27 14   Tested up to: 4.2.3
    67 2018-07-04 20   Tested up to: 4.9.6
    6873
Note: See TracChangeset for help on using the changeset viewer.