Plugin Directory

Changeset 2233358


Ignore:
Timestamp:
01/26/2020 03:15:53 AM (6 years ago)
Author:
byronj
Message:

Fixed an issue that prevented custom post type options from displaying.
Grouped category and taxonomy options within their post type.
Set the content to display on all posts if a category or taxonomy is not selected.
Added an enable button to category and taxonomy filtering options.

Location:
easy-content-adder/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • easy-content-adder/trunk/admin/class-easy-content-adder-admin-display.php

    r2233331 r2233358  
    2525    // Properties
    2626    private $beca_options;
    27     private $post_types;
    2827    private $categories;
    2928    private $category_names;
     
    3736    public function __construct() {
    3837        $this->beca_options = get_option('beca_settings');
    39         $this->post_types = get_post_types(array('public' => true));
     38       
    4039        $this->categories = get_terms(array(
    4140            'hide_empty' => false,
    4241        ));
     42       
    4343        $this->category_names = $this->get_term_names($this->categories);
    4444
    4545    }
    4646
     47    /**
     48     * Get all post types on the site
     49     *
     50     * @since    1.1.1
     51     */
     52
     53    public function get_site_post_types() {
     54        $site_post_types = get_post_types(array('public' => true));
     55        return $site_post_types;
     56    }
     57
     58
     59    /**
     60     * Get all taxonomy terms for a post type
     61     *
     62     * @since    1.1.2
     63     */
     64
     65    public function get_post_terms($this_post_type) {
     66        if($this_post_type){
     67            $full_term_list = array();
     68            $this_post_taxonomies = get_object_taxonomies($this_post_type);
     69
     70            foreach($this_post_taxonomies as $taxonomy){
     71               
     72                if($taxonomy != 'post_tag'){
     73                    $tax_terms = get_terms(array(
     74                        'taxonomy' => $taxonomy,
     75                        'hide_empty' => false,
     76                    ));
     77
     78                    foreach($tax_terms as $term){
     79                        array_push( $full_term_list, $term->name );
     80                    }
     81                }
     82               
     83            };
     84
     85            return $full_term_list;
     86        }
     87    }
     88   
     89
     90
    4791
    4892    /**
     
    5195     * @since    1.1.0
    5296     */
    53     public function render_enable_option(){
     97    public function render_enable_option($option_name = 'enable', $show_header, $label_name){
    5498        ob_start();
    5599
    56         ?>
    57             <h3><?php _e('Enable', 'beca_domain' ); ?></h3>
     100         
     101            if( $show_header){
     102                echo '<h3>' . ucfirst($option_name) . '</h3>';
     103            }
     104        ?>
    58105            <p>
    59106                <?php
    60107                    // If "Turn content on" is not selected, set input value to
    61                     if ( ! isset( $this->beca_options['enable'] ) )
    62                         $this->beca_options['enable'] = 0;
     108                    if ( ! isset( $this->beca_options[$option_name] ) )
     109                        $this->beca_options[$option_name] = 0;
    63110                    ?>
    64                 <input id="beca_settings[enable]" name="beca_settings[enable]" type="checkbox" value="1" <?php checked($this->beca_options['enable'], '1', true ); ?> />
    65                 <label class="description" for="beca_settings[enable]">
    66                     <?php _e('Turn the content on.', 'beca_domain'); ?>
     111                <input id="beca_settings[<?php echo $option_name ?>]" name="beca_settings[<?php echo $option_name ?>]" type="checkbox" value="1" <?php checked($this->beca_options[$option_name], '1', true ); ?> />
     112                <label class="description" for="beca_settings[<? echo $option_name ?>]">
     113                    <?php _e($label_name, 'beca_domain'); ?>
    67114                </label>
    68115
     
    96143    public function render_checkbox_options($item_array, $section_title, $is_post_types){
    97144        ob_start();
    98         ?>
    99                 <h4><?php _e($section_title, 'beca_domain' ); ?></h4>
     145        ?> 
     146                <?php if(!empty($section_title)){
     147                    echo '<h4>' .$section_title . '</h4>';
     148                } ?>
    100149                <?php
    101150           
     
    200249    public function build_form(){
    201250        ob_start();
     251        $site_post_types = $this->get_site_post_types();
    202252    ?>
    203253            <div class="wrap"> 
     
    212262                        ?>
    213263                       
    214                         <?php $this->render_enable_option(); ?>
     264                        <?php $this->render_enable_option('enable', true, 'Turn the content on.'); ?>
    215265
    216266                        <hr class="beca_divider" />
    217267
    218268                        <h3><?php  _e('Post Types') ?></h3>
    219                         <?php $this->render_checkbox_options($this->post_types, 'Select which type of posts to display the content on.', true); ?>
     269                        <?php $this->render_checkbox_options($site_post_types, 'Select which type of posts to display the content on.', true); ?>
    220270
    221271                        <hr class="beca_divider" />
    222272
    223                         <h3><?php  _e('Categories and Taxonomies') ?></h3>
    224                         <?php $this->render_checkbox_options($this->category_names, 'Select which categories and/or taxonomies to display the content on. These options will apply if Posts or a custom post type is selected above.', false); ?>
     273                        <h3><?php  _e('Categories and Taxonomies Names') ?></h3>
     274                        <h4><?php _e('The content will display on all posts tagged with the selected categories and taxonomies. <br/> If the Enable option is not checked, the content will display on all of the posts for that post type.'); ?></h4>
     275                        <div class="post-type-groups">
     276                            <?php
     277                            // Build the category and taxonomies list
     278                            foreach($site_post_types as $current_post_type){
     279                                $current_post_terms = $this->get_post_terms($current_post_type);
     280                                $post_type_name = get_post_type_object($current_post_type);
     281                                $plural_name = $post_type_name->labels->name;   
     282                                $post_type_lower = strtolower($current_post_type);
     283
     284                           
     285                                if(!empty($current_post_terms)){
     286                                    echo '<div class="post-type-group">';
     287                                    echo '<h4 class="post-type-name">' . ucwords($plural_name) . '</h4>';
     288
     289                                        $this->render_enable_option('enable-'. $post_type_lower, false, 'Enable'  );
     290                                        echo '<hr>';
     291                                        $this->render_checkbox_options($current_post_terms, '', false);
     292                                   
     293                                    echo '</div>';
     294                                }
     295
     296                            }; ?>
     297                        </div>
    225298
    226299                        <hr class="beca_divider" />
  • easy-content-adder/trunk/admin/css/easy-content-adder-admin.css

    r2233331 r2233358  
    44 */
    55
    6  hr.beca_divider {
     6
     7hr.beca_divider {
    78    margin: 3em 0 2em 0;
    89}
     
    2122
    2223h4 {
     24    font-weight: 400;
    2325    margin-top: 5px;
    2426}
     27
     28h4.post-type-name {
     29    margin-bottom: 5px;
     30}
     31
     32.post-type-groups {
     33    display: -webkit-box;
     34    display: -ms-flexbox;
     35    display: flex;
     36    -ms-flex-wrap: wrap;
     37        flex-wrap: wrap;
     38    -webkit-box-pack: start;
     39        -ms-flex-pack: start;
     40            justify-content: flex-start;
     41}
     42
     43.post-type-group {
     44    -ms-flex-preferred-size: 25%;
     45        flex-basis: 25%;
     46    margin-bottom: 30px;
     47}
     48
     49.post-type-group hr {
     50    margin-left: 0;
     51    max-width: 70%;
     52    text-align: left;
     53}
  • easy-content-adder/trunk/easy-content-adder.php

    r2233331 r2233358  
    1616 * Plugin Name:       Easy Content Adder
    1717 * Description:       Easily add content to all of your Pages, Posts, and Custom Post Types.
    18  * Version:           1.1.1
     18 * Version:           1.1.2
    1919 * Author:            Byron Johnson
    2020 * Author URI:        https://byronj.me
     
    3232/**
    3333 * Currently plugin version.
    34  * Start at version 1.1.0 and use SemVer - https://semver.org
     34 * Start at version 1.0.0 and use SemVer - https://semver.org
    3535 * Rename this for your plugin and update it as you release new versions.
    3636 */
    37 define( 'EASY_CONTENT_ADDER_VERSION', '1.1.1' );
     37define( 'EASY_CONTENT_ADDER_VERSION', '1.1.2' );
    3838
    3939
  • easy-content-adder/trunk/public/class-easy-content-adder-public-display.php

    r2233331 r2233358  
    2121 * @author     Byron Johnson <me@byronj.me>
    2222 */
    23 class Easy_Content_Adder_Public_Display
    24 {
     23class Easy_Content_Adder_Public_Display {
    2524
    2625    // Properties
     
    3736
    3837    // Constructor
    39     public function __construct()
    40     {
     38    public function __construct() {
    4139        $this->beca_options = get_option('beca_settings');
    4240
     
    4543        }
    4644       
    47 
    4845        if(isset($this->beca_options['bottom'])){
    4946            $this->bottom = $this->beca_options['bottom'];
     
    5451        }
    5552       
    56        
    57         $this->post_types = get_post_types(array('public' => true));
    58         $this->selected_post_types = $this->get_selected_options($this->post_types);
    5953        $this->categories = get_terms();
    6054        $this->category_names = $this->get_term_names($this->categories);
     
    6761     * @since    1.1.0
    6862     */
    69     public function set_properties()
    70     {
     63    public function set_properties() {
    7164        if (!isset($this->enable)) {
    7265            $this->enable = 0;
     
    7972            $this->bottom = 0;
    8073        }
     74    }
     75
     76    /**
     77     * Get all post types on the site
     78     *
     79     * @since    1.1.2
     80     */
     81
     82    public function get_site_post_types() {
     83        $site_post_types = get_post_types(array('public' => true));
     84        return $site_post_types;
    8185    }
    8286
     
    8690     * @since    1.1.1
    8791     */
    88     public function get_term_names($terms){
     92    public function get_term_names($terms) {
    8993        $new_terms = array();
     94       
    9095        foreach($terms as $term){
    9196            array_push( $new_terms, $term->name );
     
    100105     * @since    1.1.0
    101106     */
    102     public function modify_content($content)
    103     {
     107    public function modify_content($content) {
     108
     109        // Store the original content
     110        $base_content = $content;
     111        $post_type_categories_enabled = 0;
     112
     113        // Post type of current post
     114        $this_posts_post_type = get_post_type();
     115
     116        // Check if the Post Types categories/taxonomies option is enabled
     117        if(isset($this->beca_options['enable-' . $this_posts_post_type])){
     118            $post_type_categories_enabled = $this->beca_options['enable-' . $this_posts_post_type];
     119        }
     120
     121        $this_post_type_taxonomies = get_object_taxonomies($this_posts_post_type);
     122
     123        $site_post_types = $this->get_site_post_types();
     124        $this->selected_post_types = $this->get_selected_options($site_post_types);
    104125
    105126        // display content if a post type is chosen and if the enable option is selected
    106127        if (in_array(get_post_type(), $this->selected_post_types) && $this->enable == 1) {
    107128
    108             // Store the original content
    109             $base_content = $content;
    110129
    111130            // display content at top or bottom of content....or both top and bottom
     
    122141        }
    123142
    124         // Begin check if post is single and has matching terms
    125         if(is_single()){
     143        // Begin check if post is a single post type, has registered taxonomies, and has the category option enabled
     144        if(is_single() && !empty($this_post_type_taxonomies) && $post_type_categories_enabled){
     145           
    126146            $this_post_categories = get_the_category();
    127147            $site_taxonomies = get_taxonomies();
    128148            $this_post_terms = array();
     149            $category_matches = array();
     150            $term_matches = array();
    129151           
    130152       
     
    151173
    152174            // If there are matching categories or terms, show the updated content. otherwise, show the original content
    153             if($category_matches || $term_matches){
     175            if( $category_matches || $term_matches){
    154176                return $content;
    155177            } else {
     
    185207    }
    186208
     209
    187210    /**
    188211     * Builds final layout
     
    190213     * @since    1.1.0
    191214     */
    192     public function build_results($content)
    193     {
     215    public function build_results($content) {
    194216
    195217        $this->set_properties();
     
    207229     * @since    1.1.0
    208230     */
    209     public function render_results()
    210     {
     231    public function render_results() {
    211232        add_filter('the_content', [$this, 'build_results']);
    212233    }
  • easy-content-adder/trunk/readme.txt

    r2233331 r2233358  
    3131== Changelog ==
    3232
     33= 1.1.2 - 2020-01-25 =
     34* Fixed an issue that prevented custom post type options from displaying.
     35* Grouped category and taxonomy options within their post type.
     36* Set the content to display on all posts if a category or taxonomy is not selected.
     37* Added an enable button to category and taxonomy filtering options.
     38
    3339= 1.1.1 - 2020-01-25 =
    3440* Added an option to display the content on selected categories and taxonomies.
Note: See TracChangeset for help on using the changeset viewer.