Changeset 2233358
- Timestamp:
- 01/26/2020 03:15:53 AM (6 years ago)
- Location:
- easy-content-adder/trunk
- Files:
-
- 5 edited
-
admin/class-easy-content-adder-admin-display.php (modified) (6 diffs)
-
admin/css/easy-content-adder-admin.css (modified) (2 diffs)
-
easy-content-adder.php (modified) (2 diffs)
-
public/class-easy-content-adder-public-display.php (modified) (13 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
easy-content-adder/trunk/admin/class-easy-content-adder-admin-display.php
r2233331 r2233358 25 25 // Properties 26 26 private $beca_options; 27 private $post_types;28 27 private $categories; 29 28 private $category_names; … … 37 36 public function __construct() { 38 37 $this->beca_options = get_option('beca_settings'); 39 $this->post_types = get_post_types(array('public' => true));38 40 39 $this->categories = get_terms(array( 41 40 'hide_empty' => false, 42 41 )); 42 43 43 $this->category_names = $this->get_term_names($this->categories); 44 44 45 45 } 46 46 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 47 91 48 92 /** … … 51 95 * @since 1.1.0 52 96 */ 53 public function render_enable_option( ){97 public function render_enable_option($option_name = 'enable', $show_header, $label_name){ 54 98 ob_start(); 55 99 56 ?> 57 <h3><?php _e('Enable', 'beca_domain' ); ?></h3> 100 101 if( $show_header){ 102 echo '<h3>' . ucfirst($option_name) . '</h3>'; 103 } 104 ?> 58 105 <p> 59 106 <?php 60 107 // 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; 63 110 ?> 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'); ?> 67 114 </label> 68 115 … … 96 143 public function render_checkbox_options($item_array, $section_title, $is_post_types){ 97 144 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 } ?> 100 149 <?php 101 150 … … 200 249 public function build_form(){ 201 250 ob_start(); 251 $site_post_types = $this->get_site_post_types(); 202 252 ?> 203 253 <div class="wrap"> … … 212 262 ?> 213 263 214 <?php $this->render_enable_option( ); ?>264 <?php $this->render_enable_option('enable', true, 'Turn the content on.'); ?> 215 265 216 266 <hr class="beca_divider" /> 217 267 218 268 <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); ?> 220 270 221 271 <hr class="beca_divider" /> 222 272 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> 225 298 226 299 <hr class="beca_divider" /> -
easy-content-adder/trunk/admin/css/easy-content-adder-admin.css
r2233331 r2233358 4 4 */ 5 5 6 hr.beca_divider { 6 7 hr.beca_divider { 7 8 margin: 3em 0 2em 0; 8 9 } … … 21 22 22 23 h4 { 24 font-weight: 400; 23 25 margin-top: 5px; 24 26 } 27 28 h4.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 16 16 * Plugin Name: Easy Content Adder 17 17 * Description: Easily add content to all of your Pages, Posts, and Custom Post Types. 18 * Version: 1.1. 118 * Version: 1.1.2 19 19 * Author: Byron Johnson 20 20 * Author URI: https://byronj.me … … 32 32 /** 33 33 * Currently plugin version. 34 * Start at version 1. 1.0 and use SemVer - https://semver.org34 * Start at version 1.0.0 and use SemVer - https://semver.org 35 35 * Rename this for your plugin and update it as you release new versions. 36 36 */ 37 define( 'EASY_CONTENT_ADDER_VERSION', '1.1. 1' );37 define( 'EASY_CONTENT_ADDER_VERSION', '1.1.2' ); 38 38 39 39 -
easy-content-adder/trunk/public/class-easy-content-adder-public-display.php
r2233331 r2233358 21 21 * @author Byron Johnson <me@byronj.me> 22 22 */ 23 class Easy_Content_Adder_Public_Display 24 { 23 class Easy_Content_Adder_Public_Display { 25 24 26 25 // Properties … … 37 36 38 37 // Constructor 39 public function __construct() 40 { 38 public function __construct() { 41 39 $this->beca_options = get_option('beca_settings'); 42 40 … … 45 43 } 46 44 47 48 45 if(isset($this->beca_options['bottom'])){ 49 46 $this->bottom = $this->beca_options['bottom']; … … 54 51 } 55 52 56 57 $this->post_types = get_post_types(array('public' => true));58 $this->selected_post_types = $this->get_selected_options($this->post_types);59 53 $this->categories = get_terms(); 60 54 $this->category_names = $this->get_term_names($this->categories); … … 67 61 * @since 1.1.0 68 62 */ 69 public function set_properties() 70 { 63 public function set_properties() { 71 64 if (!isset($this->enable)) { 72 65 $this->enable = 0; … … 79 72 $this->bottom = 0; 80 73 } 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; 81 85 } 82 86 … … 86 90 * @since 1.1.1 87 91 */ 88 public function get_term_names($terms) {92 public function get_term_names($terms) { 89 93 $new_terms = array(); 94 90 95 foreach($terms as $term){ 91 96 array_push( $new_terms, $term->name ); … … 100 105 * @since 1.1.0 101 106 */ 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); 104 125 105 126 // display content if a post type is chosen and if the enable option is selected 106 127 if (in_array(get_post_type(), $this->selected_post_types) && $this->enable == 1) { 107 128 108 // Store the original content109 $base_content = $content;110 129 111 130 // display content at top or bottom of content....or both top and bottom … … 122 141 } 123 142 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 126 146 $this_post_categories = get_the_category(); 127 147 $site_taxonomies = get_taxonomies(); 128 148 $this_post_terms = array(); 149 $category_matches = array(); 150 $term_matches = array(); 129 151 130 152 … … 151 173 152 174 // 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){ 154 176 return $content; 155 177 } else { … … 185 207 } 186 208 209 187 210 /** 188 211 * Builds final layout … … 190 213 * @since 1.1.0 191 214 */ 192 public function build_results($content) 193 { 215 public function build_results($content) { 194 216 195 217 $this->set_properties(); … … 207 229 * @since 1.1.0 208 230 */ 209 public function render_results() 210 { 231 public function render_results() { 211 232 add_filter('the_content', [$this, 'build_results']); 212 233 } -
easy-content-adder/trunk/readme.txt
r2233331 r2233358 31 31 == Changelog == 32 32 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 33 39 = 1.1.1 - 2020-01-25 = 34 40 * Added an option to display the content on selected categories and taxonomies.
Note: See TracChangeset
for help on using the changeset viewer.