Changeset 1808280
- Timestamp:
- 01/24/2018 02:07:41 AM (7 years ago)
- Location:
- post-series-manager/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
post-series-manager/trunk/README.txt
r1559800 r1808280 3 3 Tags: post 4 4 Requires at least: 3.8 5 Tested up to: 4. 76 Stable tag: trunk5 Tested up to: 4. 6 Stable tag: 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 55 55 56 56 // Filters the "Continue reading this series:" text 57 post-series-manager-next-text 57 post-series-manager-next-text 58 58 59 59 // Filters the "Other posts in this series:" text … … 77 77 == Changelog == 78 78 79 80 81 82 79 83 = 1.2.0 = 80 84 * Added "start" attribute to ol to follow the count of all posts in the series -
post-series-manager/trunk/post-series-manager.php
r1630623 r1808280 1 1 <?php 2 3 2 /** 4 * 5 * @link http://cheffism.com 6 * @since 1.0.0 7 * @package Post_Series_Manager 8 * 9 * @wordpress-plugin 10 * Plugin Name: Post Series Manager 11 * Plugin URI: http://cheffism.com/post-series-manager/ 12 * Description: This plugin will help you manage and display post series more easily. You'll be able to create/assign series and display other posts in the series. 13 * Version: 1.2.0 14 * Author: Jeffrey de Wit, Adam Soucie 15 * Author URI: http://cheffism.com/ 16 * License: GPL-2.0+ 17 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 18 * Text Domain: post-series-manager 19 * Domain Path: /languages 20 * 21 * 22 * 23 * This program is free software; you can redistribute it and/or modify 24 * it under the terms of the GNU General Public License, version 2, as 25 * published by the Free Software Foundation. 26 * 27 * This program is distributed in the hope that it will be useful, 28 * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 * GNU General Public License for more details. 31 * 32 * You should have received a copy of the GNU General Public License 33 * along with this program; if not, write to the Free Software 34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 35 */ 3 * 4 * The main plugin file, this is where all the magic happens. 5 * 6 * @link http://cheffism.com 7 * @since 1.0.0 8 * @package Post_Series_Manager 9 * 10 * @wordpress-plugin 11 * Plugin Name: Post Series Manager 12 * Plugin URI: http://cheffism.com/post-series-manager/ 13 * Description: This plugin will help you manage and display post series more easily. You'll be able to create/assign series and display other posts in the series. 14 * Version: 1.2.1 15 * Author: Jeffrey de Wit, Adam Soucie 16 * Author URI: http://cheffism.com/ 17 * License: GPL-2.0+ 18 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 19 * Text Domain: post-series-manager 20 * Domain Path: /languages 21 * 22 * 23 * 24 * This program is free software; you can redistribute it and/or modify 25 * it under the terms of the GNU General Public License, version 2, as 26 * published by the Free Software Foundation. 27 * 28 * This program is distributed in the hope that it will be useful, 29 * but WITHOUT ANY WARRANTY; without even the implied warranty of 30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 31 * GNU General Public License for more details. 32 * 33 * You should have received a copy of the GNU General Public License 34 * along with this program; if not, write to the Free Software 35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 36 */ 36 37 37 38 // If this file is called directly, abort. … … 40 41 } 41 42 43 44 45 46 47 48 49 50 51 52 42 53 class Post_Series_Manager { 43 54 55 56 57 58 59 60 61 44 62 protected $plugin_name; 63 64 65 66 67 68 69 70 45 71 protected $plugin_version; 46 72 73 74 75 76 77 78 79 80 81 47 82 function __construct() { 48 83 $this->plugin_name = 'post-series-manager'; 49 $this->plugin_version = '1.1.0'; 50 51 register_activation_hook( __FILE__, array( &$this, 'post_series_manager_activate' ) ); 52 register_deactivation_hook( __FILE__, array( &$this, 'post_series_manager_deactivate' ) ); 53 54 add_action( 'init', array( &$this, 'post_series_taxonomy' ) ); 55 add_action( 'plugins_loaded', array( &$this, 'post_series_i18n' ) ); 56 add_action( 'init', array( &$this, 'post_series_shortcodes' ) ); 57 add_filter( 'the_content', array( &$this, 'post_series_before' ) ); 58 add_filter( 'the_content', array( &$this, 'post_series_after' ) ); 59 add_action( 'pre_get_posts', array( &$this, 'post_series_sort_order' ) ); 60 } 61 62 // register taxonomy and force rewrite flush when plugin is activated 63 function post_series_manager_activate() { 84 $this->plugin_version = '1.2.1'; 85 86 register_activation_hook( __FILE__, array( $this, 'post_series_manager_activate' ) ); 87 register_deactivation_hook( __FILE__, array( $this, 'post_series_manager_deactivate' ) ); 88 89 add_action( 'init', array( $this, 'post_series_taxonomy' ) ); 90 add_action( 'plugins_loaded', array( $this, 'post_series_i18n' ) ); 91 add_action( 'init', array( $this, 'post_series_shortcodes' ) ); 92 add_filter( 'the_content', array( $this, 'post_series_before' ) ); 93 add_filter( 'the_content', array( $this, 'post_series_after' ) ); 94 add_action( 'pre_get_posts', array( $this, 'post_series_sort_order' ) ); 95 } 96 97 /** 98 * Register taxonomy and force rewrite flush when plugin is activated. 99 * 100 * @since 1.0.0 101 * @access public 102 */ 103 public function post_series_manager_activate() { 64 104 $this->post_series_taxonomy(); 65 105 flush_rewrite_rules(); 66 106 } 67 107 68 // force rewrite flush when plugin is deactivated 69 function post_series_manager_deactivate() { 108 /** 109 * Force rewrite flush when plugin is deactivated. 110 * 111 * @since 1.0.0 112 * @access public 113 */ 114 public function post_series_manager_deactivate() { 70 115 flush_rewrite_rules(); 71 116 } 72 117 73 118 /** 119 * Registers the post series taxonomy. 120 * 121 * @since 1.0.0 122 * @access public 123 */ 74 124 public function post_series_taxonomy() { 75 125 register_taxonomy( … … 77 127 'post', 78 128 array( 79 'label' => esc_html__( 'Post Series', 'post-series-manager' ), 80 'rewrite' => array( 81 'slug' => 'post-series', 129 'label' => __( 'Post Series', 'post-series-manager' ), 130 'rewrite' => array( 'slug' => 'post-series' ), 131 'labels' => array( 132 'name' => __( 'Post Series', 'post-series-manager' ), 133 'singular_name' => __( 'Post Series', 'post-series-manager' ), 134 'all_items' => __( 'All Post Series', 'post-series-manager' ), 135 'edit_item' => __( 'Edit Post Series', 'post-series-manager' ), 136 'view_item' => __( 'View Post Series', 'post-series-manager' ), 137 'update_item' => __( 'Update Post Series', 'post-series-manager' ), 138 'add_new_item' => __( 'Add New Post Series', 'post-series-manager' ), 139 'new_item_name' => __( 'New Post Series Name', 'post-series-manager' ), 140 'search_items' => __( 'Search Post Series', 'post-series-manager' ), 141 'popular_items' => __( 'Popular Post Series', 'post-series-manager' ), 142 'separate_items_with_commas' => __( 'Separate post series with commas', 'post-series-manager' ), 143 'add_or_remove_items' => __( 'Add or remove post series', 'post-series-manager' ), 144 'choose_from_most_used' => __( 'Choose from most used post series', 'post-series-manager' ), 145 'not_found' => __( 'No post series found', 'post-series-manager' ), 82 146 ), 83 'labels' => array( 84 'name' => esc_html__( 'Post Series', 'post-series-manager' ), 85 'singular_name' => esc_html__( 'Post Series', 'post-series-manager' ), 86 'all_items' => esc_html__( 'All Post Series', 'post-series-manager' ), 87 'edit_item' => esc_html__( 'Edit Post Series', 'post-series-manager' ), 88 'view_item' => esc_html__( 'View Post Series', 'post-series-manager' ), 89 'update_item' => esc_html__( 'Update Post Series', 'post-series-manager' ), 90 'add_new_item' => esc_html__( 'Add New Post Series', 'post-series-manager' ), 91 'new_item_name' => esc_html__( 'New Post Series Name', 'post-series-manager' ), 92 'search_items' => esc_html__( 'Search Post Series', 'post-series-manager' ), 93 'popular_items' => esc_html__( 'Popular Post Series', 'post-series-manager' ), 94 'separate_items_with_commas' => esc_html__( 'Separate post series with commas', 'post-series-manager' ), 95 'add_or_remove_items' => esc_html__( 'Add or remove post series', 'post-series-manager' ), 96 'choose_from_most_used' => esc_html__( 'Choose from most used post series', 'post-series-manager' ), 97 'not_found' => esc_html__( 'No post series found', 'post-series-manager' ), 98 ), 147 'show_in_rest' => true, 99 148 ) 100 149 ); 101 150 } 102 151 152 153 154 155 156 157 103 158 public function post_series_i18n() { 104 159 load_plugin_textdomain( 105 'post-series-manager',160 , 106 161 false, 107 162 dirname( plugin_basename( __FILE__ ) ) . '/languages/' … … 109 164 } 110 165 166 167 168 169 170 171 111 172 public function post_series_shortcodes() { 112 173 add_shortcode( 'post_series_block', array( &$this, 'post_series_block_function' ) ); … … 114 175 } 115 176 116 // post_series_manager shortcode output 177 /** 178 * The post_series_block shortcode output. 179 * 180 * @since 1.0.0 181 * @access public 182 */ 117 183 public function post_series_block_function() { 118 184 global $post; 119 185 120 $shortcode_ HTML = NULL;186 $shortcode_; 121 187 $all_series = get_the_terms( $post->ID, 'post-series' ); 122 188 123 189 if ( $all_series ) { 124 foreach ( $all_series as $series ) {190 foreach( $all_series as $series ) { 125 191 $series_block = '<div class="post-series-manager-block"><p>%s %s</p>%s</div>'; 126 192 $series_link = sprintf( '<a href="%s">%s</a>', get_term_link( $series ), $series->name ); 127 193 128 $series_text = apply_filters( 'post-series-manager-series-text', esc_html__( 'This post is part of the series', 'post-series-manager' ) ); 129 130 if ( is_single() ) 131 { 132 $series_list_HTML = $this->get_series_list_HTML( $series ); 133 $shortcode_HTML .= sprintf( $series_block, $series_text, $series_link, $series_list_HTML ); 194 $series_text = apply_filters( 'post-series-manager-series-text', __( 'This post is part of the series', 'post-series-manager' ) ); 195 196 if ( is_single() ) { 197 $series_list_html = $this->get_series_list_html( $series ); 198 $shortcode_html .= sprintf( $series_block, $series_text, $series_link, $series_list_html ); 199 } else { 200 $shortcode_html .= sprintf( $series_block, $series_text, $series_link ); 134 201 } 135 else 136 { 137 $shortcode_HTML .= sprintf( $series_block, $series_text, $series_link ); 138 } 139 } 140 } 141 return $shortcode_HTML; 142 } 143 144 /** 145 * Generates the markup for the Post Series list. 146 * 147 * @since 1.0.0 148 * 149 * @param object $series The post series to work through 150 * @return string $series_list_HTML Completed HTML string of all the series lists 151 */ 152 public function get_series_list_HTML( $series ) 153 { 154 $current_post_ID = get_the_ID(); 155 156 $current_indicator = apply_filters( 'post-series-manager-current-text', esc_html__( '(Current)', 'post-series-manager') ); 202 } 203 } 204 return $shortcode_html; 205 } 206 207 /** 208 * Generates the markup for the Post Series list. 209 * 210 * @since 1.0.0 211 * 212 * @param object $series The post series to work through. 213 * @return string $series_list_HTML Completed HTML string of all the series lists 214 */ 215 public function get_series_list_html( $series ) { 216 $current_post_id = get_the_ID(); 217 218 $current_indicator = apply_filters( 'post-series-manager-current-text', __( '(Current)', 'post-series-manager' ) ); 157 219 158 220 $args = array( 159 221 'tax_query' => array( 160 222 array( 161 223 'taxonomy' => 'post-series', 162 224 'field' => 'slug', … … 168 230 ); 169 231 170 $series_posts = get_posts( $args ); 171 172 if ( count( $series_posts ) > 1 ) 173 { 174 $current_post = get_post( $current_post_ID ); 175 $current_index = array_search( $current_post, $series_posts ); 232 $series_posts = new WP_Query( $args ); 233 234 if ( $series_posts->post_count > 1 ) { 235 $current_post = get_post( $current_post_id ); 236 $current_index = array_search( $current_post, $series_posts->posts, true ); 176 237 177 238 $start_index = $current_index - 2; 178 239 $end_index = $current_index + 2; 179 240 180 if( $start_index < 0 ) 181 { 241 if ( $start_index < 0 ) { 182 242 $start_index = 0; 183 243 } 184 244 185 if( $end_index > ( count( $series_posts ) - 1) ) 186 { 187 $end_index = count( $series_posts ) - 1; 188 } 189 190 $list_introduction = apply_filters( 'post-series-list-intro-text', sprintf( '<p>%s</p>', esc_html__( 'Other posts in this series:', 'post-series-manager' ) ) ); 245 if ( $end_index > ( $series_posts->post_count - 1) ) { 246 $end_index = $series_posts->post_count - 1; 247 } 248 249 $list_introduction = apply_filters( 'post-series-list-intro-text', sprintf( '<p>%s</p>', __( 'Other posts in this series:', 'post-series-manager' ) ) ); 191 250 192 251 $list_opening = apply_filters( 'post-series-list-opening-tags', sprintf( '<ol class="post-series-manager-post-list" start="%s">', $start_index + 1 ) ); 193 252 194 $series_list_HTML = $list_introduction . $list_opening; 195 196 for ( $i = $start_index; $i <= $end_index; $i++ ) 197 { 198 $post_title = get_the_title( $series_posts[$i]->ID ); 199 $post_permalink = get_permalink( $series_posts[$i]->ID ); 253 $series_list_html = $list_introduction . $list_opening; 254 255 for ( $i = $start_index; $i <= $end_index; $i++ ) { 256 $post_title = get_the_title( $series_posts->posts[ $i ]->ID ); 257 $post_permalink = get_permalink( $series_posts->posts[ $i ]->ID ); 200 258 201 259 $list_item = "<li class='post-series-manager-post'>%s</li>"; 202 260 203 if ( $series_posts [$i]->ID === $current_post_ID) {261 if ( $series_posts ) { 204 262 $title_markup = $post_title . ' ' . $current_indicator; 205 263 } else { 206 $title_markup = "<a href='$post_permalink'>" . $post_title . "</a>";264 $title_markup = "<a href='$post_permalink'>" . $post_title . ; 207 265 } 208 266 209 $series_list_ HTML.= sprintf( $list_item, $title_markup );267 $series_list_ .= sprintf( $list_item, $title_markup ); 210 268 } 211 269 212 270 $list_ending = apply_filters( 'post-series-list-ending-tags', '</ol>' ); 213 271 214 $series_list_HTML .= $list_ending; 215 216 return $series_list_HTML; 217 } 218 } 219 272 $series_list_html .= $list_ending; 273 274 return $series_list_html; 275 } 276 } 277 278 /** 279 * Post series navigation function. Generates "Continue reading" link. 280 * 281 * @since 1.0.0 282 * @access public 283 */ 220 284 public function post_series_nav_function() { 221 285 global $post; 222 286 223 $shortcode_ HTML = NULL;287 $shortcode_; 224 288 $all_series = get_the_terms( $post->ID, 'post-series' ); 225 289 226 290 if ( $all_series ) { 227 $series_text = apply_filters( 'post-series-manager-next-text', esc_html__( 'Continue reading this series:', 'post-series-manager' ) );291 $series_text = apply_filters( 'post-series-manager-next-text', __( 'Continue reading this series:', 'post-series-manager' ) ); 228 292 229 293 $series_nav = '<div class="post-series-nav"><p>%s<br /> %s</p></div>'; 230 $next = get_next_post_link( '%link', '%title', true, NULL, 'post-series' );294 $next = get_next_post_link( '%link', '%title', true, , 'post-series' ); 231 295 232 296 if ( $next && is_single() ) { 233 $shortcode_HTML = sprintf( $series_nav, $series_text, $next ); 234 } 235 } 236 237 return $shortcode_HTML; 238 239 } 240 241 // Automatically add shortcodes to post content, before and after the post content 297 $shortcode_html = sprintf( $series_nav, $series_text, $next ); 298 } 299 } 300 301 return $shortcode_html; 302 303 } 304 305 /** 306 * Automatically add shortcodes to post content, before the post content. 307 * 308 * @since 1.0.0 309 * @access public 310 * @param string $content The post content. 311 */ 242 312 public function post_series_before( $content ) { 243 if ( is_single() ) {244 $series_box = do_shortcode( "[post_series_block]");313 if( is_single() ) { 314 $series_box = do_shortcode( ); 245 315 $content = $series_box . $content; 246 316 } … … 249 319 } 250 320 321 322 323 324 325 326 327 251 328 public function post_series_after( $content ) { 252 if ( is_single() ) {253 $series_nav = do_shortcode( "[post_series_nav]");329 if( is_single() ) { 330 $series_nav = do_shortcode( ); 254 331 $content = $content . $series_nav; 255 332 } … … 258 335 } 259 336 260 // Reverse sort order, since part 1 is generally older than part X 337 /** 338 * Reverse sort order, since part 1 is generally older than part X. 339 * 340 * @since 1.0.0 341 * @access public 342 * @param object $query WP_Query object. 343 */ 261 344 public function post_series_sort_order( $query ) { 262 if ( ( $query->is_main_query() ) && ( is_tax( 'post-series' ) ) ) {345 if( ( $query->is_main_query() ) && ( is_tax( 'post-series' ) ) ) { 263 346 $query->set( 'order', 'ASC' ); 264 347 }
Note: See TracChangeset
for help on using the changeset viewer.