Plugin Directory

Changeset 1670246


Ignore:
Timestamp:
06/03/2017 04:20:14 PM (9 years ago)
Author:
kantoniak
Message:

Release version 0.0.2

Location:
project-description
Files:
4 edited
6 copied

Legend:

Unmodified
Added
Removed
  • project-description/tags/0.0.2/kantoniak-project-description.php

    r1642981 r1670246  
    44Plugin URI: https://github.com/kantoniak/kantoniak-project-description/
    55Description: This plugin adds project description at the top of the article.
    6 Version: 0.0.1
     6Version: 0.0.2
    77Author: Krzysztof Antoniak
    88Author URI: http://antoniak.in/
     
    1818  const OPTION_SHOWFROMCAT = 'kantoniak_pd_showfromcat';
    1919  const OPTION_CHANGEDESC = 'kantoniak_pd_changedesc';
     20  const OPTION_SHOWINSUBCAT = 'kantoniak_pd_showinsubcat';
    2021  const OPTION_BOXTITLE = 'kantoniak_pd_boxtitle';
    2122  const OPTION_BOXCONTENTS = 'kantoniak_pd_boxcontents';
     
    2324  const OPTION_CATEGORY_NONE = -1;
    2425  const OPTION_CHANGEDESC_DEFAULT = false;
     26  const OPTION_SHOWINSUBCAT_DEFAULT = false;
    2527  const OPTION_BOXTITLE_DEFAULT = 'About the project';
    2628  const OPTION_BOXCONTENTS_DEFAULT = '';
     
    5153        update_option(ProjectDescription::OPTION_SHOWFROMCAT, (boolean) $_POST['show_from_cat']);
    5254        update_option(ProjectDescription::OPTION_CHANGEDESC, (boolean) $_POST['change_cat_desc']);
     55        update_option(ProjectDescription::OPTION_SHOWINSUBCAT, (boolean) $_POST['change_cat_desc'] ? (boolean) $_POST['show_in_subcat'] : false);
    5356        update_option(ProjectDescription::OPTION_BOXTITLE, $_POST['boxtitle']);
    5457        update_option(ProjectDescription::OPTION_BOXCONTENTS, $_POST['boxcontents']);
     
    6770    $showFromCat = (boolean) get_option(ProjectDescription::OPTION_SHOWFROMCAT, true);
    6871    $changeCatDesc = (boolean) get_option(ProjectDescription::OPTION_CHANGEDESC, ProjectDescription::OPTION_CHANGEDESC_DEFAULT);
     72    $showInSubcat = (boolean) get_option(ProjectDescription::OPTION_SHOWINSUBCAT, ProjectDescription::OPTION_SHOWINSUBCAT_DEFAULT);
    6973    $boxTitle = get_option(ProjectDescription::OPTION_BOXTITLE, ProjectDescription::OPTION_BOXTITLE_DEFAULT);
    7074    $boxContents = get_option(ProjectDescription::OPTION_BOXCONTENTS, ProjectDescription::OPTION_BOXCONTENTS_DEFAULT);
     
    8286
    8387  public function onCategoryDescription($content) {
    84     if (!is_category(get_option(ProjectDescription::OPTION_CATEGORY, ProjectDescription::OPTION_CATEGORY_NONE)) || !(boolean) get_option(ProjectDescription::OPTION_CHANGEDESC, ProjectDescription::OPTION_CHANGEDESC_DEFAULT)) {
     88    if (!(boolean) get_option(ProjectDescription::OPTION_CHANGEDESC, ProjectDescription::OPTION_CHANGEDESC_DEFAULT)) {
    8589      return $content;
    8690    }
    8791
    88     return $this->renderBox();
     92    $category = get_option(ProjectDescription::OPTION_CATEGORY, ProjectDescription::OPTION_CATEGORY_NONE);
     93    if (is_category($category)) {
     94      return $this->renderBox();
     95    }
     96
     97    $changeSubCats = (boolean) get_option(ProjectDescription::OPTION_SHOWINSUBCAT, ProjectDescription::OPTION_SHOWINSUBCAT_DEFAULT);
     98    if ($changeSubCats && $this->is_subcategory($category)) {
     99      return $this->renderBox();
     100    }
     101
     102    return $content;
    89103  }
    90104
    91105  protected function renderBox() {
     106    $category = get_option(ProjectDescription::OPTION_CATEGORY, ProjectDescription::OPTION_CATEGORY_NONE);
     107 
    92108    // List posts from the category
    93109    $others = get_posts(array(
    94         'category' => get_option(ProjectDescription::OPTION_CATEGORY, ProjectDescription::OPTION_CATEGORY_NONE),
     110        'category' => $category,
    95111        'numberposts' => -1
    96112    ));
     
    108124    $postList = $postList;
    109125    $showFromCat = (boolean) get_option(ProjectDescription::OPTION_SHOWFROMCAT, true);
     126    if ($showFromCat) {
     127      $catName = get_cat_name($category);
     128    }
    110129
    111130    ob_start();
     
    113132    return ob_get_clean();
    114133  }
     134
     135  protected function is_subcategory($cat) {
     136    $subcategories = get_categories(array('child_of' => $cat));
     137    foreach($subcategories as $category) {
     138      if (is_category($category->term_id)) {
     139        return true;
     140      }
     141    }
     142    return false;
     143  }
    115144}
    116145
  • project-description/tags/0.0.2/readme.txt

    r1642981 r1670246  
    88Author:            Krzysztof Antoniak
    99Requires at least: 4.7.0
    10 Tested up to:      4.7.3
    11 Stable tag:        0.0.1
    12 Version:           0.0.1
     10Tested up to:      4.8.0
     11Stable tag:        0.0.2
     12Version:           0.0.2
    1313License:           GNU General Public License, version 3.0 (GPL-3.0)
    1414License URI:       https://www.gnu.org/licenses/gpl-3.0.en.html
     
    2121* Set custom title and contents (full editor)
    2222* Show in articles from single category
    23 * Show in category archives (disabled by default)
     23* Show in category archives (disabled by default), optionally in subcategories
    2424* Toggle "Jump to content" link
    2525* Toggle article list visibility
     
    3838Initial revision
    3939
     40= 0.0.2 =
     41Added option to show box in archive pages of subcategories.
     42
    4043== Screenshots ==
    41441. Box preview
  • project-description/tags/0.0.2/template-box.php

    r1642981 r1670246  
    1111<?php if ($showFromCat) { ?>
    1212  <div class="other-posts">
    13     <p>See all the posts from this category:</p>
     13    <p>See all the posts from category “<?php echo $catName; ?>”:</p>
    1414    <ul class="other-posts-list">
    1515<?php
  • project-description/tags/0.0.2/template-settings.php

    r1642981 r1670246  
    4343            <label for="change_cat_desc">Change category description in archives to description box</label>
    4444            <p class="description">Filter will return HTML code. Not every template shows category description.</p>
     45
     46            <div class="show_in_subcat_group" style="margin-top: 15px">
     47              <input name="show_in_subcat" type="checkbox" <?php echo ($showInSubcat ? ' checked' : ''); ?>>
     48              <label for="show_in_subcat">Show also in subcategories</label>
     49              <p class="description">Will run filter also for archive pages of subcategories.</p>
     50            </div>
    4551          </td>
    4652      </tr>
  • project-description/trunk/kantoniak-project-description.php

    r1642981 r1670246  
    44Plugin URI: https://github.com/kantoniak/kantoniak-project-description/
    55Description: This plugin adds project description at the top of the article.
    6 Version: 0.0.1
     6Version: 0.0.2
    77Author: Krzysztof Antoniak
    88Author URI: http://antoniak.in/
     
    1818  const OPTION_SHOWFROMCAT = 'kantoniak_pd_showfromcat';
    1919  const OPTION_CHANGEDESC = 'kantoniak_pd_changedesc';
     20  const OPTION_SHOWINSUBCAT = 'kantoniak_pd_showinsubcat';
    2021  const OPTION_BOXTITLE = 'kantoniak_pd_boxtitle';
    2122  const OPTION_BOXCONTENTS = 'kantoniak_pd_boxcontents';
     
    2324  const OPTION_CATEGORY_NONE = -1;
    2425  const OPTION_CHANGEDESC_DEFAULT = false;
     26  const OPTION_SHOWINSUBCAT_DEFAULT = false;
    2527  const OPTION_BOXTITLE_DEFAULT = 'About the project';
    2628  const OPTION_BOXCONTENTS_DEFAULT = '';
     
    5153        update_option(ProjectDescription::OPTION_SHOWFROMCAT, (boolean) $_POST['show_from_cat']);
    5254        update_option(ProjectDescription::OPTION_CHANGEDESC, (boolean) $_POST['change_cat_desc']);
     55        update_option(ProjectDescription::OPTION_SHOWINSUBCAT, (boolean) $_POST['change_cat_desc'] ? (boolean) $_POST['show_in_subcat'] : false);
    5356        update_option(ProjectDescription::OPTION_BOXTITLE, $_POST['boxtitle']);
    5457        update_option(ProjectDescription::OPTION_BOXCONTENTS, $_POST['boxcontents']);
     
    6770    $showFromCat = (boolean) get_option(ProjectDescription::OPTION_SHOWFROMCAT, true);
    6871    $changeCatDesc = (boolean) get_option(ProjectDescription::OPTION_CHANGEDESC, ProjectDescription::OPTION_CHANGEDESC_DEFAULT);
     72    $showInSubcat = (boolean) get_option(ProjectDescription::OPTION_SHOWINSUBCAT, ProjectDescription::OPTION_SHOWINSUBCAT_DEFAULT);
    6973    $boxTitle = get_option(ProjectDescription::OPTION_BOXTITLE, ProjectDescription::OPTION_BOXTITLE_DEFAULT);
    7074    $boxContents = get_option(ProjectDescription::OPTION_BOXCONTENTS, ProjectDescription::OPTION_BOXCONTENTS_DEFAULT);
     
    8286
    8387  public function onCategoryDescription($content) {
    84     if (!is_category(get_option(ProjectDescription::OPTION_CATEGORY, ProjectDescription::OPTION_CATEGORY_NONE)) || !(boolean) get_option(ProjectDescription::OPTION_CHANGEDESC, ProjectDescription::OPTION_CHANGEDESC_DEFAULT)) {
     88    if (!(boolean) get_option(ProjectDescription::OPTION_CHANGEDESC, ProjectDescription::OPTION_CHANGEDESC_DEFAULT)) {
    8589      return $content;
    8690    }
    8791
    88     return $this->renderBox();
     92    $category = get_option(ProjectDescription::OPTION_CATEGORY, ProjectDescription::OPTION_CATEGORY_NONE);
     93    if (is_category($category)) {
     94      return $this->renderBox();
     95    }
     96
     97    $changeSubCats = (boolean) get_option(ProjectDescription::OPTION_SHOWINSUBCAT, ProjectDescription::OPTION_SHOWINSUBCAT_DEFAULT);
     98    if ($changeSubCats && $this->is_subcategory($category)) {
     99      return $this->renderBox();
     100    }
     101
     102    return $content;
    89103  }
    90104
    91105  protected function renderBox() {
     106    $category = get_option(ProjectDescription::OPTION_CATEGORY, ProjectDescription::OPTION_CATEGORY_NONE);
     107 
    92108    // List posts from the category
    93109    $others = get_posts(array(
    94         'category' => get_option(ProjectDescription::OPTION_CATEGORY, ProjectDescription::OPTION_CATEGORY_NONE),
     110        'category' => $category,
    95111        'numberposts' => -1
    96112    ));
     
    108124    $postList = $postList;
    109125    $showFromCat = (boolean) get_option(ProjectDescription::OPTION_SHOWFROMCAT, true);
     126    if ($showFromCat) {
     127      $catName = get_cat_name($category);
     128    }
    110129
    111130    ob_start();
     
    113132    return ob_get_clean();
    114133  }
     134
     135  protected function is_subcategory($cat) {
     136    $subcategories = get_categories(array('child_of' => $cat));
     137    foreach($subcategories as $category) {
     138      if (is_category($category->term_id)) {
     139        return true;
     140      }
     141    }
     142    return false;
     143  }
    115144}
    116145
  • project-description/trunk/readme.txt

    r1642981 r1670246  
    88Author:            Krzysztof Antoniak
    99Requires at least: 4.7.0
    10 Tested up to:      4.7.3
    11 Stable tag:        0.0.1
    12 Version:           0.0.1
     10Tested up to:      4.8.0
     11Stable tag:        0.0.2
     12Version:           0.0.2
    1313License:           GNU General Public License, version 3.0 (GPL-3.0)
    1414License URI:       https://www.gnu.org/licenses/gpl-3.0.en.html
     
    2121* Set custom title and contents (full editor)
    2222* Show in articles from single category
    23 * Show in category archives (disabled by default)
     23* Show in category archives (disabled by default), optionally in subcategories
    2424* Toggle "Jump to content" link
    2525* Toggle article list visibility
     
    3838Initial revision
    3939
     40= 0.0.2 =
     41Added option to show box in archive pages of subcategories.
     42
    4043== Screenshots ==
    41441. Box preview
  • project-description/trunk/template-box.php

    r1642981 r1670246  
    1111<?php if ($showFromCat) { ?>
    1212  <div class="other-posts">
    13     <p>See all the posts from this category:</p>
     13    <p>See all the posts from category “<?php echo $catName; ?>”:</p>
    1414    <ul class="other-posts-list">
    1515<?php
  • project-description/trunk/template-settings.php

    r1642981 r1670246  
    4343            <label for="change_cat_desc">Change category description in archives to description box</label>
    4444            <p class="description">Filter will return HTML code. Not every template shows category description.</p>
     45
     46            <div class="show_in_subcat_group" style="margin-top: 15px">
     47              <input name="show_in_subcat" type="checkbox" <?php echo ($showInSubcat ? ' checked' : ''); ?>>
     48              <label for="show_in_subcat">Show also in subcategories</label>
     49              <p class="description">Will run filter also for archive pages of subcategories.</p>
     50            </div>
    4551          </td>
    4652      </tr>
Note: See TracChangeset for help on using the changeset viewer.