Changeset 2015868
- Timestamp:
- 01/20/2019 04:34:38 PM (6 years ago)
- Location:
- a2z-alphabetical-archive-links/trunk
- Files:
-
- 22 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
a2z-alphabetical-archive-links/trunk/a2z-alphabetical-archive-links.php
r727659 r2015868 3 3 Plugin Name: A2Z Alphabetical Archive Links 4 4 Plugin URI: https://github.com/NowellVanHoesen/a2z-alphabetical-archive-links/wiki 5 Description: This WordPress plugin will get a list of characters, A to Z, from the initial character of a post or CPT title. The Initials will link to an archive page of posts/CPTs that begin with that character.6 Version: 1.0.25 Description: et a list of characters, A to Z, from the initial character of a post or CPT title. The Initials will link to an archive page of posts/CPTs that begin with that character. 6 Version: 7 7 Author: Nowell VanHoesen 8 8 Author URI: http://nvwebdev.com/ 9 9 Author Email: nowell@nvwebdev.com 10 License: 11 12 Copyright 2013 Nowell VanHoesen (nowell@nvwebdev.com) 13 14 This program is free software; you can redistribute it and/or modify 15 it under the terms of the GNU General Public License, version 2, as 16 published by the Free Software Foundation. 17 18 This program is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program; if not, write to the Free Software 25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 10 License: GPL-2.0+ 11 Licanse URI: https://www.gnu.org/licenses/gpl.html 12 Text Domain: nvwd-a2zaal 27 13 */ 28 29 /* add actions and filters */ 30 add_filter( 'query_vars', 'a2zaal_query_vars' ); 31 add_action( 'pre_get_posts', 'a2z_check_qv' ); 32 add_action( 'wp_print_styles', 'register_a2zaal_styles' ); 33 add_action( 'widgets_init', 'a2zaal_register_widgets' ); 34 35 function register_a2zaal_styles() { 36 wp_register_style( 'myWidgetStylesheet', plugins_url( 'css/display.css', __FILE__ ) ); 37 wp_enqueue_style( 'myWidgetStylesheet' ); 38 } 39 40 function a2zaal_query_vars( $query_vars ) { 41 array_push( $query_vars, 'a2zaal' ); 42 return $query_vars; 43 } 44 45 function a2z_check_qv( $query ) { 46 global $wp_query; 47 if( $query->is_main_query() && isset( $wp_query->query_vars['a2zaal'] ) ) { 48 // if we are on the main query and the query var 'a2zaal' exists, modify the where/orderby statements 49 add_filter( 'posts_where', 'a2zaal_modify_query_where' ); 50 add_filter( 'posts_orderby', 'a2zaal_modify_query_orderby' ); 51 } 52 } 53 54 function a2zaal_modify_query_where( $where ) { 55 global $wp_query, $wpdb; 56 $where .= " AND substring( TRIM( LEADING 'A ' FROM TRIM( LEADING 'AN ' FROM TRIM( LEADING 'THE ' FROM UPPER( $wpdb->posts.post_title ) ) ) ), 1, 1) = '" . $wp_query->query_vars['a2zaal'] . "'"; 57 return $where; 58 } 59 60 function a2zaal_modify_query_orderby( $orderby ) { 61 global $wp_query, $wpdb; 62 $orderby = "( TRIM( LEADING 'A ' FROM TRIM( LEADING 'AN ' FROM TRIM( LEADING 'THE ' FROM UPPER( $wpdb->posts.post_title ) ) ) ) )"; 63 return $orderby; 64 } 65 66 function a2zaal_register_widgets() { 67 register_widget( 'a2zaal_widget' ); 68 } 69 70 class a2zaal_widget extends WP_Widget { 71 72 function a2zaal_widget() { 73 $opts = array( 74 'classname' => 'a2zaal_widget', 75 'description' => 'Display a list of post/cpt title initials that link to a list of posts beginning with that initial.', 76 ); 77 $this->WP_Widget( 'a2zaal_widget', 'A2Z Alphabetical Archive Links', $opts ); 78 } 79 80 function form( $instance ) { 81 $available_posts_types = get_post_types( array( 'publicly_queryable' => true ) ); 82 $exclude_pts = array( 'attachment' ); 83 $defaults = array( 84 'post_type' => 'post', 85 'title' => '', 86 'show_counts' => 0, 87 ); 88 $instance = wp_parse_args( (array) $instance, $defaults ); 89 $post_type = $instance['post_type']; 90 $title = $instance['title']; 91 $show_counts = $instance['show_counts']; 92 echo '<p>Title: <input class="widefat" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . esc_attr( $title ) . '" /></p>'; 93 echo '<p>Post Type: <select name="' . $this->get_field_name( 'post_type' ) . '">'; 94 foreach ( $available_posts_types AS $post_type_name ) { 95 if ( array_search( $post_type_name, $exclude_pts ) === false ) { 96 echo '<option value="' . esc_attr( $post_type_name ) . '" ' . selected( $post_type, $post_type_name, false ) . '>' . esc_attr( $post_type_name ) . '</option>'; 97 } 98 } 99 echo '</select></p>'; 100 echo '<p>Show Counts: <input name="' . $this->get_field_name( 'show_counts' ) . '" type="checkbox" ' . checked( $show_counts, 'on', false ) . ' /></p>'; 101 } 102 103 function update( $new_instance, $old_instance ) { 104 $instance = $old_instance; 105 $instance['title'] = strip_tags( $new_instance['title'] ); 106 $instance['post_type'] = strip_tags( $new_instance['post_type'] ); 107 $instance['show_counts'] = strip_tags( $new_instance['show_counts'] ); 108 return $instance; 109 } 110 111 function widget( $args, $instance ) { 112 extract( $args ); 113 // run query to pull the initials for the specified post_type 114 global $wpdb; 115 $count_col = ''; 116 if ( (bool) $instance['show_counts'] ) { 117 $count_col = ", count( substring( TRIM( LEADING 'A ' FROM TRIM( LEADING 'AN ' FROM TRIM( LEADING 'THE ' FROM UPPER( $wpdb->posts.post_title ) ) ) ), 1, 1) ) as counts"; 118 } 119 $querystr = " 120 SELECT DISTINCT substring( TRIM( LEADING 'A ' FROM TRIM( LEADING 'AN ' FROM TRIM( LEADING 'THE ' FROM UPPER( $wpdb->posts.post_title ) ) ) ), 1, 1) as initial" . $count_col . " 121 FROM $wpdb->posts 122 WHERE $wpdb->posts.post_status = 'publish' 123 AND $wpdb->posts.post_type = '" . $instance['post_type'] . "' 124 GROUP BY initial 125 ORDER BY TRIM( LEADING 'A ' FROM TRIM( LEADING 'AN ' FROM TRIM( LEADING 'THE ' FROM UPPER( $wpdb->posts.post_title ) ) ) ); 126 "; 127 $pt_initials = $wpdb->get_results( $querystr, ARRAY_A ); 128 $initial_arr = array(); 129 $base_url = get_post_type_archive_link( $instance['post_type'] ); 130 if ( ! $base_url ) { 131 if (get_option('show_on_front')=='page') { 132 $base_url = esc_url( get_permalink( get_option('page_for_posts') ) ); 133 } else { 134 $base_url = esc_url( home_url( '/' ) ); 135 } 136 137 } 138 foreach( $pt_initials AS $pt_rec ) { 139 $link = add_query_arg( 'a2zaal', $pt_rec['initial'], $base_url ); 140 if ( (bool) $instance['show_counts'] ) { 141 $item = '<li class="count"><a href="' . $link . '">' . $pt_rec['initial'] . '<span>' . $pt_rec['counts'] . '</span>' . '</a></li>'; 142 } else { 143 $item = '<li><a href="' . $link . '">' . $pt_rec['initial'] . '</a></li>'; 144 } 145 $initial_arr[] = $item; 146 } 147 $initial_list = '<ul>' . implode( '', $initial_arr ) . '</ul>'; 148 149 // check widget title - get post_type name if it is empty 150 if ( strlen( $instance['title'] ) == 0 ) { 151 $pt_obj = get_post_type_object( $instance['post_type'] ); 152 $instance['title'] = $pt_obj->labels->name; 153 } 154 $title = apply_filters( 'widget_title', $instance['title'] ); 155 156 echo $before_widget; 157 echo $before_title . $title . $after_title; 158 echo $initial_list; 159 echo $after_widget; 160 161 } 162 163 } 14 15 if ( ! defined( 'WPINC' ) ) { 16 die; 17 } 18 19 define( 'A2ZAAL_PLUGIN', __FILE__ ); 20 define( 'A2ZAAL_BASENAME', plugin_basename( A2ZAAL_PLUGIN ) ); 21 define( 'A2ZAAL_VERSION', '2.0.0' ); 22 define( 'A2ZAAL_PLUGIN_ROOT_DIR', trailingslashit( __DIR__ ) ); 23 24 $a2zaal_url = plugin_dir_url( A2ZAAL_PLUGIN ); 25 if ( is_ssl() ) { 26 $a2zaal_url = str_replace( 'http://', 'https://', $a2zaal_url ); 27 } 28 29 define( 'A2ZAAL_ROOT_URL', $a2zaal_url ); 30 define( 'A2ZAAL_TEXT_DOMAIN', 'nvwd-a2zaal' ); 31 32 define( 'A2ZAAL_PHP_MIN_VERIONS', '5.6' ); 33 define( 'A2ZAAL_WP_MIN_VERSIONS', '4.6.0' ); 34 35 register_activation_hook( A2ZAAL_PLUGIN, 'a2zaal_activation_check' ); 36 register_deactivation_hook( A2ZAAL_PLUGIN, 'a2zaal_deactivate' ); 37 register_uninstall_hook( A2ZAAL_PLUGIN, 'a2zaal_uninstall' ); 38 39 add_action( 'admin_init', 'a2zaal_verify_versions' ); 40 41 /* do version checks before including the rest of the plugin code */ 42 if ( is_wp_error( a2zaal_version_checks() ) ) { 43 return; 44 } 45 46 /* version checks complete let's get the party started */ 47 include( A2ZAAL_PLUGIN_ROOT_DIR . 'src/plugin.php' ); 48 49 /** 50 * plugin activation script 51 * initiate version checks, disable plugin if any fail 52 * 53 * @author: nvwd 54 * 55 * @since: 2.0.0 56 * 57 * @return void 58 */ 59 function a2zaal_activation_check() { 60 $a2zaal_activation_check = a2zaal_version_checks(); 61 62 if ( is_wp_error( $a2zaal_activation_check ) ) { 63 deactivate_plugins( A2ZAAL_BASENAME ); 64 return; 65 } 66 67 return; 68 } 69 70 /** 71 * plugin deactivate script 72 * 73 * @author: nvwd 74 * 75 * @since: 2.0.0 76 * 77 * @return void 78 */ 79 function a2zaal_deactivate() { 80 /** 81 * remove background processing 82 * remove any options 83 * remove any activated post type data 84 */ 85 do_action( 'a2zaal_deactivation' ); 86 a2zaal_clear_rewrite_rules(); 87 } 88 89 /** 90 * plugin uninstall script 91 * 92 * @author: nvwd 93 * 94 * @since: 2.0.0 95 * 96 * @return void 97 */ 98 function a2zaal_uninstall() { 99 100 $a2zaal_active_post_types = NVWD\A2ZAAL\get_a2zaal_active_post_types(); 101 102 foreach ( $a2zaal_active_post_types AS $active_cpt ) { 103 NVWD\A2ZAAL\remove_disabled_taxonomy_terms( $active_cpt ); 104 } 105 106 delete_option( 'a2zaal_post_types' ); 107 108 } 109 110 /** 111 * delete rewrite rules option wrapper 112 * 113 * @author: nvwd 114 * 115 * @since: 2.0.0 116 * 117 * @return void 118 */ 119 function a2zaal_clear_rewrite_rules() { 120 delete_option( 'rewrite_rules' ); 121 } 122 123 /** 124 * main version check function 125 * disable plugin if version check(s) fail 126 * 127 * @author: nvwd 128 * 129 * @since: 2.0.0 130 * 131 * @return void 132 */ 133 function a2zaal_verify_versions() { 134 $a2zaal_activation_check = a2zaal_version_checks(); 135 136 if ( ! is_wp_error( $a2zaal_activation_check ) ) { 137 return; 138 } 139 140 if ( ! is_plugin_active( A2ZAAL_BASENAME ) ) { 141 return; 142 } 143 144 deactivate_plugins( A2ZAAL_BASENAME ); 145 146 if ( isset( $_GET['activate'] ) ) { 147 unset( $_GET['activate'] ); 148 } 149 } 150 151 /** 152 * version check controller 153 * 154 * @author: nvwd 155 * 156 * @since: 2.0.0 157 * 158 * @return bool|WP_Error 159 */ 160 function a2zaal_version_checks() { 161 $version_check_errors = new WP_Error(); 162 163 $version_check_errors = apply_filters( 'a2zaal_do_version_checks', $version_check_errors ); 164 165 if ( ! empty( $version_check_errors->get_error_codes() ) ) { 166 return $version_check_errors; 167 } 168 169 return true; 170 } 171 172 add_filter( 'a2zaal_do_version_checks', 'a2zaal_check_wp_version' ); 173 /** 174 * Check WP version 175 * 176 * @author: nvwd 177 * 178 * @since: 2.0.0 179 * 180 * @param $version_check_errors 181 * 182 * @return WP_Error 183 */ 184 function a2zaal_check_wp_version( $version_check_errors ) { 185 global $wp_version; 186 187 if ( version_compare( $wp_version, A2ZAAL_WP_MIN_VERSIONS, '>=' ) ) { 188 return $version_check_errors; 189 } 190 191 add_action( 'admin_notices', 'a2zaal_wp_version_failure_message' ); 192 193 $version_check_errors->add( 194 'wp_version', 195 esc_html__('WordPress version check for A2Z Alphabetical Archive Links failed. A2Z Alphabetical Archive Links should not be active.', A2ZAAL_TEXT_DOMAIN ) 196 ); 197 198 return $version_check_errors; 199 } 200 201 add_filter( 'a2zaal_do_version_checks', 'a2zaal_check_php_version' ); 202 /** 203 * Check PHP version 204 * 205 * @author: nvwd 206 * 207 * @since: 2.0.0 208 * 209 * @param $version_check_errors 210 * 211 * @return WP_Error 212 */ 213 function a2zaal_check_php_version( $version_check_errors ) { 214 if ( version_compare( PHP_VERSION, A2ZAAL_PHP_MIN_VERIONS, '>=' ) ) { 215 return $version_check_errors; 216 } 217 218 add_action( 'admin_notices', 'a2zaal_php_version_failure_message' ); 219 220 $version_check_errors->add( 221 'php_version', 222 esc_html__('PHP version check for A2Z Alphabetical Archive Links failed. A2Z Alphabetical Archive Links should not be active.', A2ZAAL_TEXT_DOMAIN ) 223 ); 224 225 return $version_check_errors; 226 } 227 228 /** 229 * Create admin notice of WP version check failure 230 * 231 * @author: nvwd 232 * 233 * @since: 2.0.0 234 * 235 * @return void 236 */ 237 function a2zaal_wp_version_failure_message() { 238 $class = 'notice notice-error'; 239 $message = __( 'A2Z Alphabetical Archive Links requires WordPress ' . A2ZAAL_WP_MIN_VERSIONS . ' to function properly. Please upgrade WordPress. A2Z Alphabetical Archive Links has been auto-deactivated.', A2ZAAL_TEXT_DOMAIN ); 240 241 a2zaal_output_admin_notice( $class, $message ); 242 } 243 244 /** 245 * Create admin notice of PHP version check failure 246 * 247 * @author: nvwd 248 * 249 * @since: 2.0.0 250 * 251 * @return void 252 */ 253 function a2zaal_php_version_failure_message() { 254 $class = 'notice notice-error'; 255 $message = __( 'A2Z Alphabetical Archive Links requires PHP ' . A2ZAAL_PHP_MIN_VERIONS . ' to function properly. Please upgrade PHP. A2Z Alphabetical Archive Links has been auto-deactivated.', A2ZAAL_TEXT_DOMAIN ); 256 257 a2zaal_output_admin_notice( $class, $message ); 258 } 259 260 /** 261 * Display admin notice 262 * 263 * @author: nvwd 264 * 265 * @since: 2.0.0 266 * 267 * @param $class 268 * @param $message 269 * 270 * @return void 271 */ 272 function a2zaal_output_admin_notice( $class, $message ) { 273 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); 274 } -
a2z-alphabetical-archive-links/trunk/css/display.css
r720133 r2015868 1 1 /* CSS Document */ 2 .a2zaal_widget ul:before, 3 .a2zaal_widget ul:after { 4 content: ""; 5 display: table; 2 .a2zaal_widget ul { 3 display: grid; 4 grid-template-columns: repeat( auto-fill, minmax( 2.625rem, 1fr ) ); 5 justify-items: center; 6 list-style: none; 7 margin: 0; 6 8 } 7 .a2zaal_widget ul:after { 8 clear: both; 9 } 10 .a2zaal_widget ul { 11 *zoom: 1; 9 .a2zaal_widget ul.counts { 10 grid-template-columns: repeat( auto-fill, minmax( 3rem, 1fr ) ); 12 11 } 13 12 .a2zaal_widget li { 14 13 position: relative; 15 float: left; 16 margin: 0 0 0 1em; 14 } 15 16 .a2zaal_widget a { 17 border-bottom: 1px solid transparent; 18 display: block; 19 padding: 0.625rem 0.5rem; 20 text-align: center; 21 } 22 23 .a2zaal_widget a:hover { 24 border-bottom: 1px solid blue; 25 color: blue; 26 text-decoration: underline; 27 } 28 .a2zaal_widget a.count > span { 29 font-size: 75%; 30 padding-left: 0.4em; 31 vertical-align: super; 32 white-space: nowrap; 33 } 34 /* premium styles for sliding counts 35 .a2zaal_widget ul.counts { 36 grid-template-columns: repeat( auto-fit, minmax( 2.5em, 1fr ) ); 17 37 } 18 38 .a2zaal_widget li.count:after { … … 35 55 -moz-box-sizing: border-box; 36 56 box-sizing: border-box; 57 37 58 } 38 59 .a2zaal_widget li a { … … 90 111 transition-property: padding, max-width; 91 112 } 113 -
a2z-alphabetical-archive-links/trunk/readme.txt
r727659 r2015868 3 3 Donate link: http://nvwebdev.com 4 4 Tags: post title, custom post type title, cpt title, title, alphabetical, alphabatized 5 Requires at least: 3.3 6 Tested up to: 3.5.1 7 Stable tag: 1.0.2 5 Requires at least: 4.6.0 6 Tested up to: 5.0.3 7 Requires PHP: 5.6 8 Stable tag: 2.0.0 8 9 License: GPLv2 or later 9 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 11 11 Create and di aplay a list of first characters for post/cpt titles which link to an archive of the posts/cpts that begin with that character.12 Create and diplay a list of first characters for post/cpt titles which link to an archive of the posts/cpts that begin with that character. 12 13 13 14 == Description == … … 19 20 * A 20 21 * An 22 21 23 * The 22 24 … … 25 27 * 'A Cup of Joe' will be listed under 'C' 26 28 * 'The Pony' will be listed under 'P' 29 30 27 31 28 32 … … 31 35 1. Upload the entire 'a2z-alphabetical-archive-links' folder to the '/wp-content/plugins/' directory 32 36 1. Activate the plugin through the 'Plugins' menu in WordPress 33 1. Add the 'A2Z Alphabetical Archive Links' widget to a sidebar 37 1. Go to the settings page to activate which post type(s) to have 38 1. Add the 'A2Z Alphabetical Archive Links' widget to a widget area 34 39 35 40 == Frequently Asked Questions == … … 44 49 45 50 == Changelog == 51 52 53 54 55 56 57 58 59 46 60 47 61 = 1.0.2 = … … 59 73 == Upgrade Notice == 60 74 75 76 77 78 61 79 = 1.0.2 = 62 80
Note: See TracChangeset
for help on using the changeset viewer.