Changeset 3193532
- Timestamp:
- 11/20/2024 10:57:26 PM (16 months ago)
- Location:
- a2z-alphabetical-archive-links
- Files:
-
- 38 added
- 8 deleted
- 17 edited
- 1 copied
-
assets/screenshot-1.png (modified) (1 prop) (previous)
-
assets/screenshot-2.png (modified) (1 prop) (previous)
-
assets/screenshot-3.png (modified) (1 prop) (previous)
-
assets/screenshot-4.png (added)
-
assets/screenshot-5.png (added)
-
tags/2.1.0 (copied) (copied from a2z-alphabetical-archive-links/trunk)
-
tags/2.1.0/a2z-alphabetical-archive-links.php (modified) (1 diff)
-
tags/2.1.0/build (added)
-
tags/2.1.0/build/blocks (added)
-
tags/2.1.0/build/blocks/a2z-links (added)
-
tags/2.1.0/build/blocks/a2z-links/block.json (added)
-
tags/2.1.0/build/blocks/a2z-links/index.asset.php (added)
-
tags/2.1.0/build/blocks/a2z-links/index.js (added)
-
tags/2.1.0/build/blocks/a2z-links/render.php (added)
-
tags/2.1.0/css/display.css (modified) (9 diffs)
-
tags/2.1.0/package.json (added)
-
tags/2.1.0/readme.txt (modified) (5 diffs)
-
tags/2.1.0/src/blocks (added)
-
tags/2.1.0/src/blocks/a2z-links (added)
-
tags/2.1.0/src/blocks/a2z-links/block.json (added)
-
tags/2.1.0/src/blocks/a2z-links/edit.js (added)
-
tags/2.1.0/src/blocks/a2z-links/index.js (added)
-
tags/2.1.0/src/blocks/a2z-links/render.php (added)
-
tags/2.1.0/src/blocks/index.js (added)
-
tags/2.1.0/src/classes/A2ZAAL_Post_Type_Background_Process.php (deleted)
-
tags/2.1.0/src/classes/class-a2zaal-post-type-background-process.php (added)
-
tags/2.1.0/src/helpers.php (modified) (2 diffs)
-
tags/2.1.0/src/plugin.php (modified) (2 diffs)
-
tags/2.1.0/src/rewrites.php (modified) (11 diffs)
-
tags/2.1.0/src/settings.php (modified) (7 diffs)
-
tags/2.1.0/src/vender/wp-background-processing/composer.json (deleted)
-
tags/2.1.0/src/views/settings-form.php (added)
-
tags/2.1.0/src/views/settings_form.php (deleted)
-
tags/2.1.0/src/widgets/a2zaal_widget.php (deleted)
-
tags/2.1.0/src/widgets/class-a2zaal-widget.php (added)
-
trunk/a2z-alphabetical-archive-links.php (modified) (1 diff)
-
trunk/build (added)
-
trunk/build/blocks (added)
-
trunk/build/blocks/a2z-links (added)
-
trunk/build/blocks/a2z-links/block.json (added)
-
trunk/build/blocks/a2z-links/index.asset.php (added)
-
trunk/build/blocks/a2z-links/index.js (added)
-
trunk/build/blocks/a2z-links/render.php (added)
-
trunk/css/display.css (modified) (9 diffs)
-
trunk/package.json (added)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/src/blocks (added)
-
trunk/src/blocks/a2z-links (added)
-
trunk/src/blocks/a2z-links/block.json (added)
-
trunk/src/blocks/a2z-links/edit.js (added)
-
trunk/src/blocks/a2z-links/index.js (added)
-
trunk/src/blocks/a2z-links/render.php (added)
-
trunk/src/blocks/index.js (added)
-
trunk/src/classes/A2ZAAL_Post_Type_Background_Process.php (deleted)
-
trunk/src/classes/class-a2zaal-post-type-background-process.php (added)
-
trunk/src/helpers.php (modified) (2 diffs)
-
trunk/src/plugin.php (modified) (2 diffs)
-
trunk/src/rewrites.php (modified) (11 diffs)
-
trunk/src/settings.php (modified) (7 diffs)
-
trunk/src/vender/wp-background-processing/composer.json (deleted)
-
trunk/src/views/settings-form.php (added)
-
trunk/src/views/settings_form.php (deleted)
-
trunk/src/widgets/a2zaal_widget.php (deleted)
-
trunk/src/widgets/class-a2zaal-widget.php (added)
Legend:
- Unmodified
- Added
- Removed
-
a2z-alphabetical-archive-links/assets/screenshot-1.png
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/png
-
Property
svn:mime-type
changed from
-
a2z-alphabetical-archive-links/assets/screenshot-2.png
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/png
-
Property
svn:mime-type
changed from
-
a2z-alphabetical-archive-links/assets/screenshot-3.png
-
Property
svn:mime-type
changed from
application/octet-streamtoimage/png
-
Property
svn:mime-type
changed from
-
a2z-alphabetical-archive-links/tags/2.1.0/a2z-alphabetical-archive-links.php
r2019541 r3193532 1 1 <?php 2 /* 3 Plugin Name: A2Z Alphabetical Archive Links 4 Plugin URI: https://github.com/NowellVanHoesen/a2z-alphabetical-archive-links/wiki 5 Description: 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: 2.0.2 7 Author: Nowell VanHoesen 8 Author URI: http://nvwebdev.com/ 9 Author Email: nowell@nvwebdev.com 10 License: GPL-2.0+ 11 Licanse URI: https://www.gnu.org/licenses/gpl.html 12 Text Domain: nvwd-a2zaal 13 */ 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.2' ); 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() ) ) { 2 /* 3 Plugin Name: A2Z Alphabetical Archive Links 4 Plugin URI: https://github.com/NowellVanHoesen/a2z-alphabetical-archive-links/wiki 5 Description: Get a list of characters, A to Z, from the initial character of a post or CPT title. 6 The Initials will link to an archive page of posts/CPTs that begin with that character. 7 Version: 2.1.0 8 Requires at least: 5.8 9 Requires PHP: 7.4 10 Author: Nowell VanHoesen 11 Author URI: http://nvwebdev.com/ 12 Author Email: nowell@nvwebdev.com 13 License: GPL-2.0+ 14 License URI: https://www.gnu.org/licenses/gpl.html 15 Text Domain: nvwd-a2zaal 16 */ 17 18 namespace NVWD\A2ZAAL; 19 20 if ( ! defined( 'WPINC' ) ) { 21 die; 22 } 23 24 define( 'A2ZAAL_PLUGIN', __FILE__ ); 25 define( 'A2ZAAL_BASENAME', plugin_basename( A2ZAAL_PLUGIN ) ); 26 define( 'A2ZAAL_VERSION', '2.1.0' ); 27 define( 'A2ZAAL_PLUGIN_ROOT_DIR', trailingslashit( __DIR__ ) ); 28 29 $a2zaal_url = plugin_dir_url( A2ZAAL_PLUGIN ); 30 31 if ( is_ssl() ) { 32 $a2zaal_url = str_replace( 'http://', 'https://', $a2zaal_url ); 33 } 34 35 define( 'A2ZAAL_ROOT_URL', $a2zaal_url ); 36 37 define( 'A2ZAAL_PHP_MIN_VERSION', '7.4' ); 38 define( 'A2ZAAL_WP_MIN_VERSION', '5.8' ); 39 40 register_activation_hook( A2ZAAL_PLUGIN, 'a2zaal_activation_check' ); 41 register_deactivation_hook( A2ZAAL_PLUGIN, 'a2zaal_deactivate' ); 42 register_uninstall_hook( A2ZAAL_PLUGIN, 'a2zaal_uninstall' ); 43 44 add_filter( 'a2zaal_do_version_checks', __NAMESPACE__ . '\a2zaal_check_php_version' ); 45 add_filter( 'a2zaal_do_version_checks', __NAMESPACE__ . '\a2zaal_check_wp_version' ); 46 add_action( 'admin_init', __NAMESPACE__ . '\a2zaal_verify_versions' ); 47 48 /* do version checks before including the rest of the plugin code */ 49 if ( is_wp_error( a2zaal_version_checks() ) ) { 50 return; 51 } 52 53 /* version checks complete let's get the party started */ 54 require A2ZAAL_PLUGIN_ROOT_DIR . 'src/plugin.php'; 55 56 /** 57 * Plugin activation script 58 * initiate version checks, disable plugin if any fail 59 * 60 * @author nvwd 61 * 62 * @since 2.0.0 63 */ 64 function a2zaal_activation_check() { 65 $a2zaal_activation_check = a2zaal_version_checks(); 66 67 if ( ! is_wp_error( $a2zaal_activation_check ) ) { 43 68 return; 44 69 } 45 70 46 /* version checks complete let's get the party started */ 47 include( A2ZAAL_PLUGIN_ROOT_DIR . 'src/plugin.php' ); 48 71 deactivate_plugins( A2ZAAL_BASENAME ); 72 } 73 74 /** 75 * Plugin deactivate script 76 * 77 * @author nvwd 78 * 79 * @since 2.0.0 80 */ 81 function a2zaal_deactivate() { 49 82 /** 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 83 * Remove background processing 84 * remove any options 85 * remove any activated post type data 58 86 */ 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; 87 do_action( 'a2zaal_deactivation' ); 88 a2zaal_clear_rewrite_rules(); 89 } 90 91 /** 92 * Plugin uninstall script 93 * 94 * @author nvwd 95 * 96 * @since 2.0.0 97 */ 98 function a2zaal_uninstall() { 99 100 $a2zaal_active_post_types = get_a2zaal_active_post_types(); 101 102 foreach ( $a2zaal_active_post_types as $active_cpt ) { 103 remove_disabled_cpts( $active_cpt ); 104 } 105 106 delete_option( 'a2zaal_post_types' ); 107 } 108 109 /** 110 * Delete rewrite rules option wrapper 111 * 112 * @author nvwd 113 * 114 * @since 2.0.0 115 */ 116 function a2zaal_clear_rewrite_rules() { 117 delete_option( 'rewrite_rules' ); 118 } 119 120 /** 121 * Main version check function 122 * disable plugin if version check(s) fail 123 * 124 * @author nvwd 125 * 126 * @since 2.0.0 127 */ 128 function a2zaal_verify_versions() { 129 $a2zaal_activation_check = a2zaal_version_checks(); 130 131 if ( ! is_wp_error( $a2zaal_activation_check ) || ! is_plugin_active( A2ZAAL_BASENAME ) ) { 132 return; 133 } 134 135 deactivate_plugins( A2ZAAL_BASENAME ); 136 137 // phpcs:disable SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable, WordPress.Security.NonceVerification.Recommended -- plugin activation failed, need to remove the param so nothing else is processed. 138 if ( isset( $_GET['activate'] ) ) { 139 unset( $_GET['activate'] ); 140 } 141 // phpcs:enable SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable 142 } 143 144 /** 145 * Version check controller 146 * 147 * @author nvwd 148 * 149 * @since 2.0.0 150 * 151 * @return bool|\WP_Error 152 */ 153 function a2zaal_version_checks() { 154 // phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName -- Slevomat can't make up its mind with or without the '\', so I'm opting for with. 155 $version_check_errors = new \WP_Error(); 156 157 $version_check_errors = apply_filters( 'a2zaal_do_version_checks', $version_check_errors ); 158 159 $error_codes = $version_check_errors->get_error_codes(); 160 161 if ( ! empty( $error_codes ) ) { 162 return $version_check_errors; 163 } 164 165 return true; 166 } 167 168 /** 169 * Check WP version 170 * 171 * @author nvwd 172 * 173 * @since 2.0.0 174 * 175 * @param \WP_Error $version_check_errors version check errors. 176 * 177 * @return \WP_Error 178 * 179 * phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName -- Slevomat can't make up its mind with or without the '\', so I'm opting for with. 180 */ 181 function a2zaal_check_wp_version( \WP_Error $version_check_errors ) { 182 global $wp_version; 183 184 if ( version_compare( $wp_version, A2ZAAL_WP_MIN_VERSION, '>=' ) ) { 185 return $version_check_errors; 186 } 187 188 add_action( 'admin_notices', 'a2zaal_wp_version_failure_message' ); 189 190 $version_check_errors->add( 191 'wp_version', 192 esc_html__( 193 'WordPress version check for A2Z Alphabetical Archive Links failed. 194 A2Z Alphabetical Archive Links should not be active.', 195 'nvwd-a2zaal' 196 ) 197 ); 198 199 return $version_check_errors; 200 } 201 // phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName 202 203 /** 204 * Check PHP version 205 * 206 * @author nvwd 207 * 208 * @since 2.0.0 209 * 210 * @param \WP_Error $version_check_errors version check errors. 211 * 212 * @return \WP_Error 213 * 214 * phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName -- Slevomat can't make up its mind with or without the '\', so I'm opting for with. 215 */ 216 function a2zaal_check_php_version( \WP_Error $version_check_errors ) { 217 if ( version_compare( PHP_VERSION, A2ZAAL_PHP_MIN_VERSION, '>=' ) ) { 218 return $version_check_errors; 219 } 220 221 add_action( 'admin_notices', 'a2zaal_php_version_failure_message' ); 222 223 $version_check_errors->add( 224 'php_version', 225 esc_html__( 226 'PHP version check for A2Z Alphabetical Archive Links failed. 227 A2Z Alphabetical Archive Links should not be active.', 228 'nvwd-a2zaal' 229 ) 230 ); 231 232 return $version_check_errors; 233 } 234 // phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName 235 236 /** 237 * Create admin notice of WP version check failure 238 * 239 * @author nvwd 240 * 241 * @since 2.0.0 242 */ 243 function a2zaal_wp_version_failure_message() { 244 $css_class = 'notice notice-error'; 245 $message = sprintf( 246 /* translators: 1: Minimum WordPress version */ 247 __( 248 'A2Z Alphabetical Archive Links requires WordPress %1$s to function properly. Please upgrade WordPress. 249 A2Z Alphabetical Archive Links has been auto-deactivated.', 250 'nvwd-a2zaal' 251 ), 252 A2ZAAL_WP_MIN_VERSION 253 ); 254 255 a2zaal_output_admin_notice( $css_class, $message ); 256 } 257 258 /** 259 * Create admin notice of PHP version check failure 260 * 261 * @author nvwd 262 * 263 * @since 2.0.0 264 */ 265 function a2zaal_php_version_failure_message() { 266 $css_class = 'notice notice-error'; 267 $message = sprintf( 268 /* translators: 1: Minimum php version */ 269 __( 270 'A2Z Alphabetical Archive Links requires PHP %1$s to function properly. Please upgrade PHP. 271 A2Z Alphabetical Archive Links has been auto-deactivated.', 272 'nvwd-a2zaal' 273 ), 274 A2ZAAL_PHP_MIN_VERSION 275 ); 276 277 a2zaal_output_admin_notice( $css_class, $message ); 278 } 279 280 /** 281 * Display admin notice 282 * 283 * @author nvwd 284 * 285 * @since 2.0.0 286 * 287 * @param string $css_class css class for the message output. 288 * @param string $message message to display. 289 */ 290 function a2zaal_output_admin_notice( string $css_class, string $message ) { 291 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $css_class ), esc_html( $message ) ); 292 } 293 294 if ( function_exists( 'register_block_type' ) ) { 295 add_action( 296 'init', 297 static function () { 298 register_block_type( __DIR__ . '/build/blocks/a2z-links' ); 65 299 } 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 $error_codes = $version_check_errors->get_error_codes(); 166 if ( ! empty( $error_codes ) ) { 167 return $version_check_errors; 168 } 169 170 return true; 171 } 172 173 add_filter( 'a2zaal_do_version_checks', 'a2zaal_check_wp_version' ); 174 /** 175 * Check WP version 176 * 177 * @author: nvwd 178 * 179 * @since: 2.0.0 180 * 181 * @param $version_check_errors 182 * 183 * @return WP_Error 184 */ 185 function a2zaal_check_wp_version( $version_check_errors ) { 186 global $wp_version; 187 188 if ( version_compare( $wp_version, A2ZAAL_WP_MIN_VERSIONS, '>=' ) ) { 189 return $version_check_errors; 190 } 191 192 add_action( 'admin_notices', 'a2zaal_wp_version_failure_message' ); 193 194 $version_check_errors->add( 195 'wp_version', 196 esc_html__('WordPress version check for A2Z Alphabetical Archive Links failed. A2Z Alphabetical Archive Links should not be active.', A2ZAAL_TEXT_DOMAIN ) 197 ); 198 199 return $version_check_errors; 200 } 201 202 add_filter( 'a2zaal_do_version_checks', 'a2zaal_check_php_version' ); 203 /** 204 * Check PHP version 205 * 206 * @author: nvwd 207 * 208 * @since: 2.0.0 209 * 210 * @param $version_check_errors 211 * 212 * @return WP_Error 213 */ 214 function a2zaal_check_php_version( $version_check_errors ) { 215 if ( version_compare( PHP_VERSION, A2ZAAL_PHP_MIN_VERIONS, '>=' ) ) { 216 return $version_check_errors; 217 } 218 219 add_action( 'admin_notices', 'a2zaal_php_version_failure_message' ); 220 221 $version_check_errors->add( 222 'php_version', 223 esc_html__('PHP version check for A2Z Alphabetical Archive Links failed. A2Z Alphabetical Archive Links should not be active.', A2ZAAL_TEXT_DOMAIN ) 224 ); 225 226 return $version_check_errors; 227 } 228 229 /** 230 * Create admin notice of WP version check failure 231 * 232 * @author: nvwd 233 * 234 * @since: 2.0.0 235 * 236 * @return void 237 */ 238 function a2zaal_wp_version_failure_message() { 239 $class = 'notice notice-error'; 240 $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 ); 241 242 a2zaal_output_admin_notice( $class, $message ); 243 } 244 245 /** 246 * Create admin notice of PHP version check failure 247 * 248 * @author: nvwd 249 * 250 * @since: 2.0.0 251 * 252 * @return void 253 */ 254 function a2zaal_php_version_failure_message() { 255 $class = 'notice notice-error'; 256 $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 ); 257 258 a2zaal_output_admin_notice( $class, $message ); 259 } 260 261 /** 262 * Display admin notice 263 * 264 * @author: nvwd 265 * 266 * @since: 2.0.0 267 * 268 * @param $class 269 * @param $message 270 * 271 * @return void 272 */ 273 function a2zaal_output_admin_notice( $class, $message ) { 274 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); 275 } 300 ); 301 } -
a2z-alphabetical-archive-links/tags/2.1.0/css/display.css
r2015868 r3193532 1 1 /* CSS Document */ 2 ul.wp-block-nvwda2zaal-a2z-links, 2 3 .a2zaal_widget ul { 3 4 display: grid; … … 7 8 margin: 0; 8 9 } 10 ul.wp-block-nvwda2zaal-a2z-links.counts, 9 11 .a2zaal_widget ul.counts { 10 12 grid-template-columns: repeat( auto-fill, minmax( 3rem, 1fr ) ); 11 13 } 14 .wp-block-nvwda2zaal-a2z-links li, 12 15 .a2zaal_widget li { 13 16 position: relative; 14 17 } 15 18 .wp-block-nvwda2zaal-a2z-links a, 16 19 .a2zaal_widget a { 17 20 border-bottom: 1px solid transparent; … … 20 23 text-align: center; 21 24 } 22 25 .wp-block-nvwda2zaal-a2z-links a:hover, 23 26 .a2zaal_widget a:hover { 24 27 border-bottom: 1px solid blue; … … 26 29 text-decoration: underline; 27 30 } 31 .wp-block-nvwda2zaal-a2z-links a.count > span, 28 32 .a2zaal_widget a.count > span { 29 33 font-size: 75%; … … 32 36 white-space: nowrap; 33 37 } 34 /* premium styles for sliding counts 38 /* 39 ul.wp-block-nvwda2zaal-a2z-links.counts, 35 40 .a2zaal_widget ul.counts { 36 41 grid-template-columns: repeat( auto-fit, minmax( 2.5em, 1fr ) ); 42 gap: 5px; 37 43 } 44 .wp-block-nvwda2zaal-a2z-links li.count:after, 38 45 .a2zaal_widget li.count:after { 39 46 content: ''; … … 50 57 box-shadow: inset 1px 0 #99400e; 51 58 } 52 .a2zaal_widget li a, .a2zaal_widget li a span { 59 .wp-block-nvwda2zaal-a2z-links li a, 60 .wp-block-nvwda2zaal-a2z-links li a span, 61 .a2zaal_widget li a, 62 .a2zaal_widget li a span { 53 63 display: block; 54 64 -webkit-box-sizing: border-box; … … 57 67 white-space: nowrap; 58 68 } 69 .wp-block-nvwda2zaal-a2z-links li a, 59 70 .a2zaal_widget li a { 60 71 padding: 0.25em 0.5em; … … 76 87 box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7), 0 1px 2px rgba(0, 0, 0, 0.05); 77 88 } 89 .wp-block-nvwda2zaal-a2z-links a:hover span, 78 90 .a2zaal_widget a:hover span { 79 91 padding: 0.2em 7px 0.2em 6px; … … 82 94 box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15), 1px 1px 2px rgba(0, 0, 0, 0.2); 83 95 } 96 .wp-block-nvwda2zaal-a2z-links span, 84 97 .a2zaal_widget span { 85 98 position: absolute; -
a2z-alphabetical-archive-links/tags/2.1.0/readme.txt
r2019541 r3193532 2 2 Contributors: nvwd 3 3 Donate link: http://nvwebdev.com 4 Tags: post title, custom post type title, cpt title, title, alphabetical, alphab atized5 Requires at least: 4.6.06 Tested up to: 5.0.37 Requires PHP: 5.68 Stable tag: 2. 0.24 Tags: post title, custom post type title, cpt title, title, alphabetical, alphabetized 5 Requires at least: 5.8.0 6 Tested up to: 6.7 7 Requires PHP: 7.4 8 Stable tag: 2.1.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 36 36 1. Activate the plugin through the 'Plugins' menu in WordPress 37 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 38 1. Add the 'A2Z Alphabetical Archive Links' widget to a widget area or add the A2Z Links block to a block area 39 39 40 40 == Frequently Asked Questions == … … 44 44 == Screenshots == 45 45 46 1. Widget config 47 1. Links without count 48 1. Links with count (top), hover example ( bottom ) 46 1. Legacy widget config 47 1. A2Z Links block editor with counts disabled 48 1. A2Z Links block editor with counts enabled 49 1. A2Z Links block output with counts disabled 50 1. A2Z Links block output with counts enabled 49 51 50 52 == Changelog == 53 54 = 2.1.0 = 55 56 * Added links block to replace legacy widget 57 * Updated minimum php version to 7.4 58 * Updated minimum WordPress version to 5.8 59 * Resolved RegEx issue that incorrectly grouped some titles in the group that begin with numbers. 51 60 52 61 = 2.0.2 = … … 56 65 = 2.0.1 = 57 66 58 *fixed bug with earlier versions of php and version checking67 fixed bug with earlier versions of php and version checking 59 68 60 69 = 2.0.0 = 61 70 62 Complete rewrite. In an effort to make the code scale better.71 * Complete rewrite. In an effort to make the code scale better. 63 72 * Removed slow query 64 73 * Added minimum WordPress version check … … 73 82 = 1.0.1 = 74 83 75 * Changed widget option for post type to include only public ally queriable post types ( Pages not an option anymore )84 * Changed widget option for post type to include only publicly queryable post types ( Pages not an option anymore ) 76 85 * Fixed links generated when using the post type of Post 77 86 -
a2z-alphabetical-archive-links/tags/2.1.0/src/helpers.php
r2015868 r3193532 1 1 <?php 2 /**3 * A2Z Alphabetical Archive Links Helper Functions4 *5 * @package NVWD\A2ZAAL6 * @since 2.0.07 * @author nvwd8 * @link http://nvwebdev.com/9 * @license GPL-2.0+10 */11 2 12 3 namespace NVWD\A2ZAAL; 13 4 14 /** 15 * return an array of a2zaal active post types or an empty array when none are active 16 * 17 * @author: nvwd 18 * @since: 2.0.0 5 use WP_Post; 6 7 add_filter( 'widget_block_dynamic_classname', __NAMESPACE__ . '\add_widget_classname', 10, 2 ); 8 9 /** 10 * Return an array of a2zaal active post types or an empty array when none are active 11 * 12 * @author nvwd 13 * 14 * @since 2.0.0 15 * 19 16 * @return array 20 17 */ 21 18 function get_a2zaal_active_post_types() { 22 $a2zaal_active_post_types = get_option( 'a2zaal_post_types', array());19 $a2zaal_active_post_types = \get_option( 'a2zaal_post_types', [] ); 23 20 24 21 if ( ! is_array( $a2zaal_active_post_types ) ) { 25 return array();22 return []; 26 23 } 27 24 28 25 return $a2zaal_active_post_types; 29 30 } 31 32 /** 33 * return an array of a2zaal post types that are currently processing or an empty array 34 * 35 * @author: nvwd 36 * @since: 2.0.0 26 } 27 28 /** 29 * Return an array of a2zaal post types that are currently processing or an empty array 30 * 31 * @author nvwd 32 * 33 * @since 2.0.0 34 * 37 35 * @return array 38 36 */ 39 37 function get_a2zaal_processing_post_types() { 40 $a2zaal_processing_objects = get_option( 'a2zaal_processing_objects', array());38 $a2zaal_processing_objects = \get_option( 'a2zaal_processing_objects', [] ); 41 39 42 40 if ( empty( $a2zaal_processing_objects['post_types'] ) ) { 43 return array();41 return []; 44 42 } 45 43 46 44 return $a2zaal_processing_objects['post_types']; 47 48 } 49 50 /** 51 * this is where the magic happens, return the first character of the provided title and the string used for sorting 45 } 46 47 /** 48 * This is where the magic happens, return the first character of the provided title and the string used for sorting 52 49 * if the title begins with one or more 'a', 'an', 'and', and/or 'the', ignore them and goto the next word 53 50 * if the title then begins with a number return '#', otherwise return the first alpha character, capitalized. 54 51 * return the adjusted title for proper sorting when the links are retireved 55 52 * 56 * @author: nvwd 57 * @since: 2.0.0 58 * @param string $post_title 53 * @author nvwd 54 * 55 * @since 2.0.0 56 * 57 * @param string $post_title Post title being processed for its grouping initial. 58 * 59 59 * @return bool|array 60 60 */ 61 function get_post_a2zaal_info( $post_title ) {61 function get_post_a2zaal_info( string $post_title ) { 62 62 if ( empty( $post_title ) ) { 63 63 return false; 64 64 } 65 preg_match( '/\A[(a|an|and|the) ]*\b(([a-zA-Z]{1}|[\d]{1,}).*)\z/i', $post_title, $a2zaal_char ); 66 $post_a2zaal_info = array( 'sort_title' => $a2zaal_char[1], 'initial' => strtoupper( $a2zaal_char[2] ) ); 65 66 // Regex explained: https://regex101.com/r/B8vbdX/1. 67 preg_match( '/\A(?|a |an |and |the )*(([a-zA-Z]{1}|[\d]{1,}).*)\z/i', $post_title, $a2zaal_char ); 68 $post_a2zaal_info = [ 69 'sort_title' => $a2zaal_char[1], 70 'initial' => strtoupper( $a2zaal_char[2] ), 71 ]; 67 72 68 73 if ( is_numeric( $post_a2zaal_info['initial'] ) ) { … … 74 79 75 80 /** 76 * check if the query is an a2z query needing some extra stuff 77 * 78 * @author: nvwd 79 * @since: 2.0.0 80 * @return bool 81 * Check if the query is an a2z query needing some extra stuff 82 * 83 * @author nvwd 84 * 85 * @since 2.0.0 86 * 87 * @return bool|string 81 88 */ 82 89 function is_a2zaal_query() { 83 84 90 if ( ! \is_main_query() || ! \is_post_type_archive() ) { 85 91 return false; 86 92 } 87 93 88 if ( false === \get_query_var( A2ZAAL_REWRITE_TAG, false ) ) { 89 return false; 90 } 91 92 return true; 93 94 } 95 96 /** 97 * add sortable title and post ID to the structure used to order the posts alphabetically 98 * 99 * @author: nvwd 100 * @since: 2.0.0 101 * @param WP_Post $post post being saved 102 * @return void 103 */ 104 function add_post_a2zaal_info( $post ) { 105 $a2zaal_cpt_option = \get_option( $post->post_type . A2ZAAL_POSTS_SUFFIX, array() ); 106 $post_a2zaal_info = namespace\get_post_a2zaal_info( $post->post_title ); 107 108 if ( ! is_array( $post_a2zaal_info ) || ( array_key_exists( $post_a2zaal_info['initial'], $a2zaal_cpt_option ) && array_key_exists( $post->ID, $a2zaal_cpt_option[ $post_a2zaal_info['initial'] ] ) ) ) { 94 /* phpcs:ignore SlevomatCodingStandard.ControlStructures.UselessTernaryOperator.UselessTernaryOperator -- returning the results of get_query_var is not reliable due to one of the values being 0, making it false. */ 95 return false === \get_query_var( A2ZAAL_REWRITE_TAG, false ) ? false : true; 96 } 97 98 /** 99 * Add sortable title and post ID to the structure used to order the posts alphabetically 100 * 101 * @author nvwd 102 * 103 * @since 2.0.0 104 * 105 * @param \WP_Post $post post being saved. 106 */ 107 function add_post_a2zaal_info( WP_Post $post ) { 108 $a2zaal_cpt_option = \get_option( $post->post_type . A2ZAAL_POSTS_SUFFIX, [] ); 109 $post_a2zaal_info = get_post_a2zaal_info( $post->post_title ); 110 111 if ( 112 ! is_array( $post_a2zaal_info ) 113 || ( 114 array_key_exists( $post_a2zaal_info['initial'], $a2zaal_cpt_option ) 115 && array_key_exists( $post->ID, $a2zaal_cpt_option[ $post_a2zaal_info['initial'] ] ) 116 ) 117 ) { 109 118 return; 110 119 } 111 120 112 // in the case of an update, the post may already exist in the a2z post info structure 113 // ensure that the post doesn't already exist in the structure 114 namespace\remove_prior_post_a2zaal_data( $a2zaal_cpt_option, $post->ID, $post_a2zaal_info['initial'] );121 // in the case of an update, the post may already exist in the a2z post info structure. 122 // ensure that the post doesn't already exist in the structure. 123 remove_prior_post_a2zaal_data( $a2zaal_cpt_option, $post->ID, $post_a2zaal_info['initial'] ); 115 124 116 125 $a2zaal_cpt_option[ $post_a2zaal_info['initial'] ][ $post->ID ] = $post_a2zaal_info['sort_title']; 117 126 118 127 \update_option( $post->post_type . A2ZAAL_POSTS_SUFFIX, $a2zaal_cpt_option, true ); 119 120 } 121 122 /** 123 * in the case of a post update, check to see if the post already exists within the structure 128 } 129 130 /** 131 * In the case of a post update, check to see if the post already exists within the structure 124 132 * remove it if necessary 125 133 * 126 * @author: nvwd 127 * @since: 2.0.0 128 * @param array $a2zaal_cpt_option contains the post alphabetical detail for this post type 129 * @param int $post_id current post ID to possibly remove a previous entry 130 * @param string $post_initial initial of the current post title 131 * @return void 132 */ 133 function remove_prior_post_a2zaal_data( &$a2zaal_cpt_option, $post_id, $post_initial ) { 134 foreach( $a2zaal_cpt_option AS $key => $initial_posts ) { 135 if ( $key == $post_initial ) { 134 * @author nvwd 135 * 136 * @since 2.0.0 137 * 138 * @param array $a2zaal_cpt_option contains the post alphabetical detail for this post type. 139 * @param int $post_id current post ID to possibly remove a previous entry. 140 * @param string $post_initial initial of the current post title. 141 */ 142 function remove_prior_post_a2zaal_data( array &$a2zaal_cpt_option, int $post_id, string $post_initial ) { 143 foreach ( $a2zaal_cpt_option as $key => $initial_posts ) { 144 if ( $key === $post_initial || ! array_key_exists( $post_id, $initial_posts ) ) { 136 145 continue; 137 146 } 138 if ( array_key_exists( $post_id, $initial_posts ) ) { 139 unset( $a2zaal_cpt_option[$key][$post_id] ); 147 148 unset( $a2zaal_cpt_option[ $key ][ $post_id ] ); 149 } 150 } 151 152 /** 153 * Returns the array of a2z links for the widget/block to display. 154 * 155 * @author nvwd 156 * 157 * @since 2.1.0 158 * 159 * @param string $selected_post_type selected post type for the links. 160 * @param bool $show_counts whether to display counts for the initial groups. 161 * 162 * @return array 163 */ 164 function get_a2zaal_display_links( string $selected_post_type, bool $show_counts ) { 165 $post_type_titles_struct = \get_option( $selected_post_type . A2ZAAL_POSTS_SUFFIX, [] ); 166 167 if ( empty( $post_type_titles_struct ) ) { 168 return [ '<p>' . \__( 'No links to display.', 'nvwd-a2zaal' ) . '</p>' ]; 169 } 170 171 $post_type_labels = \get_post_type_object( $selected_post_type )->labels; 172 173 ksort( $post_type_titles_struct, SORT_NATURAL ); 174 175 /* translators: %s: plural post type name */ 176 $link_prefix = sprintf( \__( '%s beginning with ', 'nvwd-a2zaal' ), $post_type_labels->name ); 177 178 foreach ( $post_type_titles_struct as $title_initial => $grouped_titles ) { 179 $group_link = '/' . $selected_post_type . '/' . A2ZAAL_REWRITE_TAG . '/' . $title_initial; 180 $group_count_display = ! empty( $show_counts ) 181 ? '<span>' . \number_format_i18n( count( $grouped_titles ) ) . '</span>' 182 : ''; 183 $link_classes = ! empty( $show_counts ) ? [ 'count' ] : []; 184 $link_classes = implode( ' ', \apply_filters( 'a2zaal_link_css_class', $link_classes, $selected_post_type ) ); 185 $link_title = trim( 186 \apply_filters( 'a2zaal_link_title', $link_prefix . $title_initial, $selected_post_type, $title_initial ) 187 ); 188 $link_text_display = $title_initial; 189 190 if ( 0 === $title_initial ) { 191 $group_link = '/' . $selected_post_type . '/' . A2ZAAL_REWRITE_TAG . '/num'; 192 $link_text_display = '#'; 140 193 } 141 } 142 } 194 195 // TODO: Make sure link is accessible. 196 $display_links[] = sprintf( 197 '<li><a href="%s" class="%s" title="%s">%s%s</a></li>', 198 $group_link, 199 $link_classes, 200 $link_title, 201 $link_text_display, 202 $group_count_display 203 ); 204 } 205 206 return $display_links; 207 } 208 209 /** 210 * Returns adjusted className list for a2z-links widget wrapper. 211 * 212 * @author nvwd 213 * 214 * @since 2.1.0 215 * 216 * @param string $classname list of classnames to be used in the block widget’s container HTML. 217 * @param string $block_name name of the block contained by the block widget. 218 * 219 * @return string 220 */ 221 function add_widget_classname( string $classname, string $block_name ) { 222 if ( 'nvwda2zaal/a2z-links' !== $block_name ) { 223 return $classname; 224 } 225 226 // phpcs:ignore SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable -- unused even though it's part of the return. 227 return $classname .= ' a2zaal_widget'; 228 } -
a2z-alphabetical-archive-links/tags/2.1.0/src/plugin.php
r2015868 r3193532 1 1 <?php 2 /**3 * A2Z Alphabetical Archive Links Handler4 *5 * @package NVWD\A2ZAAL6 * @since 2.0.07 * @author nvwd8 * @link http://nvwebdev.com/9 * @license GPL-2.0+10 */11 2 12 3 namespace NVWD\A2ZAAL; … … 17 8 define( 'A2ZAAL_VIEW_DIR', A2ZAAL_SOURCE_DIR . 'views/' ); 18 9 19 include A2ZAAL_SOURCE_DIR . 'vender/wp-background-processing/wp-background-processing.php';20 include A2ZAAL_SOURCE_DIR . 'classes/A2ZAAL_Post_Type_Background_Process.php';10 require A2ZAAL_SOURCE_DIR . 'vender/wp-background-processing/wp-background-processing.php'; 11 require A2ZAAL_SOURCE_DIR . 'classes/class-a2zaal-post-type-background-process.php'; 21 12 22 13 if ( is_admin() ) { 23 include A2ZAAL_SOURCE_DIR . 'settings.php';14 require A2ZAAL_SOURCE_DIR . 'settings.php'; 24 15 } 25 include A2ZAAL_SOURCE_DIR . 'rewrites.php'; 26 include A2ZAAL_SOURCE_DIR . 'helpers.php'; 27 include A2ZAAL_SOURCE_DIR . 'widgets/a2zaal_widget.php'; 16 17 require A2ZAAL_SOURCE_DIR . 'rewrites.php'; 18 require A2ZAAL_SOURCE_DIR . 'helpers.php'; 19 require A2ZAAL_SOURCE_DIR . 'widgets/class-a2zaal-widget.php'; 20 21 \add_action( 'widgets_init', __NAMESPACE__ . '\maybe_register_archive_link_widget' ); 22 23 /** 24 * Register the a2zaal widget only if there are active post types 25 * 26 * @author nvwd 27 * 28 * @since 2.0.0 29 */ 30 function maybe_register_archive_link_widget() { 31 $a2z_active_post_types = get_a2zaal_active_post_types(); 32 33 if ( empty( $a2z_active_post_types ) ) { 34 return; 35 } 36 37 \register_widget( __NAMESPACE__ . '\a2zaal_widget' ); 38 } 28 39 29 40 add_action( 'save_post', __NAMESPACE__ . '\maybe_add_a2zaal_post' ); 30 41 /** 31 * add the a2zaal data to the specific structure when an active post type item is saved42 * Add the a2zaal data to the specific structure when an active post type item is saved 32 43 * 33 * @author: nvwd 34 * @since: 2.0.0 35 * @param $post_id 36 * @return void 44 * @author nvwd 45 * 46 * @since 2.0.0 47 * 48 * @param int $post_id ID of the post being saved. 37 49 */ 38 function maybe_add_a2zaal_post( $post_id ) { 39 50 function maybe_add_a2zaal_post( int $post_id ) { 40 51 if ( \wp_is_post_revision( $post_id ) || \wp_is_post_autosave( $post_id ) ) { 41 52 return; 42 53 } 43 54 44 $a2zaal_post = \get_post( $post_id );45 $a2zaal_active_post_types = namespace\get_a2zaal_active_post_types();55 $a2zaal_post = \get_post( $post_id ); 56 $a2zaal_active_post_types = get_a2zaal_active_post_types(); 46 57 47 if ( ! in_array( $a2zaal_post->post_type, $a2zaal_active_post_types ) ) {58 if ( ! in_array( $a2zaal_post->post_type, $a2zaal_active_post_types, true ) ) { 48 59 return; 49 60 } 50 61 51 namespace\add_post_a2zaal_info( $a2zaal_post ); 52 62 add_post_a2zaal_info( $a2zaal_post ); 53 63 } 54 64 55 65 /** 56 * make the a2zaal list page titles more readable66 * Make the a2zaal list page titles more readable 57 67 * 58 * @author: nvwd 59 * @since: 2.0.0 60 * @param $archive_title 68 * @author nvwd 69 * 70 * @since 2.0.0 71 * 72 * @param string $archive_title archive page title. 73 * 61 74 * @return string 62 75 */ 63 function filter_archive_title( $archive_title ) {64 if ( ! namespace\is_a2zaal_query() ) {76 function filter_archive_title( string $archive_title ) { 77 if ( ! is_a2zaal_query() ) { 65 78 return $archive_title; 66 79 } 67 80 68 $post_type_labels = get_post_type_object(get_query_var( 'post_type' ) );69 $group_title_initial = get_query_var( A2ZAAL_REWRITE_TAG );81 $post_type_labels = \get_post_type_object( \get_query_var( 'post_type' ) ); 82 $group_title_initial = \get_query_var( A2ZAAL_REWRITE_TAG ); 70 83 71 if ( '0' == $group_title_initial ) {84 if ( '0' === $group_title_initial ) { 72 85 $group_title_initial = '#'; 73 86 } 74 87 75 return sprintf( __( '%1$s: %2$s' ), $post_type_labels->label, $group_title_initial ); 88 /* translators: 1: post type title 2: initial of the archive grouping */ 89 return sprintf( __( '%1$s: %2$s', 'nvwd-a2zaal' ), $post_type_labels->label, $group_title_initial ); 76 90 } 77 91 78 92 /** 79 * customize the a2zaal list page description93 * Customize the a2zaal list page description 80 94 * 81 * @author: nvwd 82 * @since: 2.0.0 83 * @param $archive_description 95 * @author nvwd 96 * 97 * @since 2.0.0 98 * 99 * @param string $archive_description archive page description. 100 * 84 101 * @return string 85 102 */ 86 function filter_archive_description( $archive_description ) {87 if ( ! namespace\is_a2zaal_query() ) {103 function filter_archive_description( string $archive_description ) { 104 if ( ! is_a2zaal_query() ) { 88 105 return $archive_description; 89 106 } 90 107 91 $post_type_labels = get_post_type_object(get_query_var( 'post_type' ) );108 $post_type_labels = \get_post_type_object( \get_query_var( 'post_type' ) ); 92 109 93 $group_title_initial = get_query_var( A2ZAAL_REWRITE_TAG );110 $group_title_initial = \get_query_var( A2ZAAL_REWRITE_TAG ); 94 111 95 if ( '0' == $group_title_initial ) {96 $group_title_initial = __( 'a number', A2ZAAL_TEXT_DOMAIN );112 if ( '0' === $group_title_initial ) { 113 $group_title_initial = 'a number'; 97 114 } 98 115 99 return sprintf( __( '%1$s beginning with %2$s.' ), $post_type_labels->label, $group_title_initial ); 116 /* translators: 1: post type title 2: initial of the archive grouping */ 117 return sprintf( __( '%1$s beginning with %2$s.', 'nvwd-a2zaal' ), $post_type_labels->label, $group_title_initial ); 100 118 } -
a2z-alphabetical-archive-links/tags/2.1.0/src/rewrites.php
r2015868 r3193532 1 1 <?php 2 /**3 * A2Z Alphabetical Archive Rewrites Handler4 *5 * @package NVWD\A2ZAAL6 * @since 2.0.07 * @author nvwd8 * @link http://nvwebdev.com/9 * @license GPL-2.0+10 */11 2 12 3 namespace NVWD\A2ZAAL; 4 5 use WP; 6 use WP_Query; 13 7 14 8 \add_filter( 'rewrite_rules_array', __NAMESPACE__ . '\maybe_modify_rewrite_rules_array' ); 15 9 16 10 /** 17 * add rewrite rules for each a2z active post type11 * Add rewrite rules for each a2z active post type 18 12 * 19 * @author: nvwd 20 * @since: 2.0.0 21 * @param array $rewrite_rules the rewrite structure passed in 22 * @return array the possibly updated rewrite structure 13 * @author nvwd 14 * 15 * @since 2.0.0 16 * 17 * @param array $rewrite_rules the rewrite structure passed in. 18 * 19 * @return array 23 20 */ 24 function maybe_modify_rewrite_rules_array( $rewrite_rules ) {25 $a2zaal_active_post_types = namespace\get_a2zaal_active_post_types();21 function maybe_modify_rewrite_rules_array( array $rewrite_rules ) { 22 $a2zaal_active_post_types = get_a2zaal_active_post_types(); 26 23 27 24 if ( empty( $a2zaal_active_post_types ) ) { … … 29 26 } 30 27 31 $new_rules = array();28 $new_rules = []; 32 29 33 foreach ( $a2zaal_active_post_types AS $active_post_type ) { 34 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=all'; 35 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/page/?([0-9]{1,})/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=all&paged=$matches[2]'; 36 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/([a-zA-Z])/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=$matches[1]'; 37 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/num/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=0'; 38 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/([a-zA-Z])/page/?([0-9]{1,})/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=$matches[1]&paged=$matches[2]'; 39 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/num/page/?([0-9]{1,})/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=0&paged=$matches[1]'; 30 // phpcs:disable SlevomatCodingStandard.Files.LineLength.LineTooLong -- line length due to alignment for each rewrite rule. 31 foreach ( $a2zaal_active_post_types as $active_post_type ) { 32 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=all'; 33 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/page/?([0-9]{1,})/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=all&paged=$matches[2]'; 34 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/([a-zA-Z])/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=$matches[1]'; 35 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/num/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=0'; 36 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/([a-zA-Z])/page/?([0-9]{1,})/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=$matches[1]&paged=$matches[2]'; 37 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/num/page/?([0-9]{1,})/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=0&paged=$matches[1]'; 40 38 } 39 40 // phpcs:enable SlevomatCodingStandard.Files.LineLength.LineTooLong 41 41 42 42 return array_merge( $new_rules, $rewrite_rules ); … … 46 46 47 47 /** 48 * add the query tag being used for holding the specific initial48 * Add the query tag being used for holding the specific initial 49 49 * 50 * @author :nvwd51 * @since: 2.0.052 * @ return void50 * @author nvwd 51 * 52 * @since 2.0.0 53 53 */ 54 54 function add_a2zaal_rewrite_tag() { … … 59 59 60 60 /** 61 * add hooks to modify the query if the a2z rewrite tag exists61 * Add hooks to modify the query if the a2z rewrite tag exists 62 62 * 63 * @author: nvwd 64 * @since: 2.0.0 65 * @param WP_Query $query main query 66 * @return void 63 * @author nvwd 64 * 65 * @since 2.0.0 66 * 67 * @param \WP $query WordPress environment instance. 67 68 */ 68 function maybe_alter_query_for_a2zaal( $query ) {69 function maybe_alter_query_for_a2zaal( WP $query ) { 69 70 if ( ! isset( $query->query_vars[ A2ZAAL_REWRITE_TAG ] ) ) { 70 71 return; … … 79 80 80 81 /** 81 * pull all posts until I can build in pagination, then make pagination optional82 * Pull all posts until I can build in pagination, then make pagination optional 82 83 * 83 * @author: nvwd 84 * @since: 2.0.0 85 * @param WP_Query $query main query 86 * @return void 84 * @author nvwd 85 * 86 * @since 2.0.0 87 * 88 * @param \WP_Query $query main query. 87 89 */ 88 function kill_pagination( $query ) {90 function kill_pagination( WP_Query $query ) { 89 91 $query->set( 'posts_per_page', -1 ); 90 92 $query->set( 'no_found_rows', true ); … … 92 94 93 95 /** 94 * add IN clause providing a list of post IDs to be retrieved by the query96 * Add IN clause providing a list of post IDs to be retrieved by the query 95 97 * 96 * @author: nvwd 97 * @since: 2.0.0 98 * @param string $posts_where query where clause 99 * @return string maybe modified where clause 98 * @author nvwd 99 * 100 * @since 2.0.0 101 * 102 * @param string $posts_where query where clause. 103 * 104 * @return string 100 105 */ 101 function filter_a2zaal_where_clause( $posts_where ) {106 function filter_a2zaal_where_clause( string $posts_where ) { 102 107 global $wpdb; 103 108 104 $post_type_a2zaal_struct = \get_option( \get_query_var( 'post_type' ) . A2ZAAL_POSTS_SUFFIX, array());109 $post_type_a2zaal_struct = \get_option( \get_query_var( 'post_type' ) . A2ZAAL_POSTS_SUFFIX, [] ); 105 110 106 111 if ( empty( $post_type_a2zaal_struct ) ) { … … 112 117 $specific_post_ids = implode( ',', array_keys( $post_type_a2zaal_struct[ $a2zaal_query_var ] ) ); 113 118 114 $posts_where .= " AND ( $wpdb->posts.ID IN (" . $specific_post_ids . ") )";119 $posts_where .= " AND ( $wpdb->posts.ID IN (" . $specific_post_ids . ') )'; 115 120 116 121 return $posts_where; … … 118 123 119 124 /** 120 * set the sort order using the naturally sorted object titles125 * Set the sort order using the naturally sorted object titles 121 126 * 122 * @author: nvwd 123 * @since: 2.0.0 124 * @param string $posts_orderby orderby clause 125 * @return string maybe new orderby clause 127 * @author nvwd 128 * 129 * @since 2.0.0 130 * 131 * @param string $posts_orderby orderby clause. 132 * 133 * @return string 126 134 */ 127 function filter_a2zaal_orderby_clause( $posts_orderby ) {135 function filter_a2zaal_orderby_clause( string $posts_orderby ) { 128 136 global $wpdb; 129 137 130 $post_type_a2zaal_struct = \get_option( \get_query_var( 'post_type' ) . A2ZAAL_POSTS_SUFFIX, array());138 $post_type_a2zaal_struct = \get_option( \get_query_var( 'post_type' ) . A2ZAAL_POSTS_SUFFIX, [] ); 131 139 132 140 if ( empty( $post_type_a2zaal_struct ) ) { … … 148 156 149 157 /** 150 * check to see if posts/objects for the specified a2z initial exists in the post type structure158 * Check to see if posts/objects for the specified a2z initial exists in the post type structure 151 159 * 152 * @author: nvwd 153 * @since: 2.0.0 154 * @param $query 155 * @return void 160 * @author nvwd 161 * 162 * @since 2.0.0 163 * 164 * @param \WP_Query $query query to check to see if it's a 404. 156 165 */ 157 function check_a2zaal_404( &$query ) { 158 159 if ( ! namespace\is_a2zaal_query() || \is_admin() ) { 166 function check_a2zaal_404( WP_Query &$query ) { 167 if ( ! is_a2zaal_query() || \is_admin() ) { 160 168 return; 161 169 } 162 170 163 $post_type_a2zaal_struct = \get_option( $query->query_vars['post_type'] . A2ZAAL_POSTS_SUFFIX, array());171 $post_type_a2zaal_struct = \get_option( $query->query_vars['post_type'] . A2ZAAL_POSTS_SUFFIX, [] ); 164 172 165 173 if ( empty( $post_type_a2zaal_struct ) ) { … … 167 175 } 168 176 169 if ( array_key_exists( $query->query_vars[ A2ZAAL_REWRITE_TAG ], $post_type_a2zaal_struct ) || 'all' == $query->query_vars[ A2ZAAL_REWRITE_TAG ] ) { 177 if ( 178 array_key_exists( $query->query_vars[ A2ZAAL_REWRITE_TAG ], $post_type_a2zaal_struct ) 179 || 'all' === $query->query_vars[ A2ZAAL_REWRITE_TAG ] 180 ) { 170 181 return; 171 182 } … … 173 184 $query->set_404(); 174 185 } 175 -
a2z-alphabetical-archive-links/tags/2.1.0/src/settings.php
r2015868 r3193532 1 1 <?php 2 /**3 * A2Z Alphabetical Archive Links Settings Page Handler4 *5 * @package NVWD\A2ZAAL6 * @since 2.0.07 * @author nvwd8 * @link http://nvwebdev.com/9 * @license GPL-2.0+10 */11 2 12 3 namespace NVWD\A2ZAAL; 13 4 5 use WP_Screen; 6 14 7 \add_filter( 'plugin_action_links_' . A2ZAAL_BASENAME, __NAMESPACE__ . '\add_settings_page_link' ); 15 8 16 function add_settings_page_link( $links ) { 17 $settings_link = '<a href="' . \admin_url( 'options-general.php?page=a2zaal-options' ) . '">' . __( 'Settings', A2ZAAL_TEXT_DOMAIN ) . '</a>'; 9 /** 10 * Adds custom settings page to the admin settings menu 11 * 12 * @author nvwd 13 * 14 * @since 2.0.0 15 * 16 * @param array $links admin menu links. 17 * 18 * @return array 19 */ 20 function add_settings_page_link( array $links ) { 21 $settings_link = sprintf( 22 '<a href="%s">%s</a>', 23 \admin_url( 'options-general.php?page=a2zaal-options' ), 24 \__( 'Settings', 'nvwd-a2zaal' ) 25 ); 18 26 array_unshift( $links, $settings_link ); 27 19 28 return $links; 20 29 } … … 23 32 24 33 /** 25 * add admin settings page for our use26 * 27 * @author :nvwd28 * @since: 2.0.029 * @ return void34 * Add admin settings page for our use 35 * 36 * @author nvwd 37 * 38 * @since 2.0.0 30 39 */ 31 40 function add_settings_menu_link() { 32 \add_options_page( 'A2Z Alphabetical Archive Links Options', 'A2Z Alphabetical Archive Links', 'manage_options', 'a2zaal-options', __NAMESPACE__ . '\create_settings_page' ); 33 //enqueue javascript and styles needed for admin options page 34 } 35 36 /** 37 * admin page creation script 38 * 39 * @author: nvwd 40 * @since: 2.0.0 41 * @return void 41 \add_options_page( 42 'A2Z Alphabetical Archive Links Options', 43 'A2Z Alphabetical Archive Links', 44 'manage_options', 45 'a2zaal-options', 46 __NAMESPACE__ . '\create_settings_page' 47 ); 48 // enqueue javascript and styles needed for admin options page. 49 } 50 51 /** 52 * Admin page creation script 53 * 54 * @author nvwd 55 * 56 * @since 2.0.0 42 57 */ 43 58 function create_settings_page() { 44 45 59 if ( ! \current_user_can( 'manage_options' ) ) { 46 60 die( 'Unauthorized User' ); 47 61 } 48 62 49 $a2zaal_active_post_types = namespace\get_a2zaal_active_post_types(); 50 51 $a2zaal_processing_post_types = namespace\get_a2zaal_processing_post_types(); 52 53 $excluded_post_types = array( 54 'attachment', 55 'revision', 56 'nav_menu_item' 57 ); 58 59 $registered_post_types = \get_post_types( array( 'publicly_queryable' => true ), 'objects' ); 60 61 $a2zaal_processing_counts = \get_option( 'a2zaal_processing_counts', array() ); 62 63 include( A2ZAAL_VIEW_DIR . 'settings_form.php' ); 63 require A2ZAAL_VIEW_DIR . 'settings-form.php'; 64 } 65 66 \add_action( 'admin_init', __NAMESPACE__ . '\register_plugin_settings' ); 67 \add_action( 'rest_admin_init', __NAMESPACE__ . '\register_plugin_settings' ); 68 69 /** 70 * Register block widget 71 * 72 * @author nvwd 73 * 74 * @since 2.1.0 75 */ 76 function register_plugin_settings() { 77 $args = [ 78 'default' => [], 79 'type' => 'array', 80 'show_in_rest' => [ 81 'schema' => [ 82 'type' => 'array', 83 'items' => [ 84 'type' => 'string', 85 ], 86 ], 87 ], 88 ]; 89 90 \register_setting( 'options', 'a2zaal_post_types', $args ); 91 } 92 93 add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\output_a2z_active_post_types' ); 94 95 /** 96 * Outputs the a2z active post types for use in the block editor 97 * 98 * @author nvwd 99 * 100 * @since 2.1.0 101 */ 102 function output_a2z_active_post_types() { 103 $a2z_active_post_types = get_a2zaal_active_post_types(); 104 105 \wp_add_inline_script( 106 'nvwda2zaal-a2z-links-editor-script', 107 'const NVWDA2ZAAL_activePostTypes = ' . \wp_json_encode( $a2z_active_post_types ) . ';', 108 'before' 109 ); 64 110 } 65 111 … … 67 113 68 114 /** 69 * handle the submission of our settings page70 * 71 * @author :nvwd72 * @since: 2.0.073 * @ param $screen_obj74 * @return void75 * /76 function maybe_process_a2zaal_settings_save( $screen_obj ) { 77 115 * Handle the submission of our settings page 116 * 117 * @author nvwd 118 * 119 * @since 2.0.0 120 * 121 * @param \WP_Screen $screen_obj current screen. 122 */ 123 function maybe_process_a2zaal_settings_save( WP_Screen $screen_obj ) { 78 124 if ( 'settings_page_a2zaal-options' !== $screen_obj->id ) { 79 125 return; 80 126 } 81 127 82 \wp_enqueue_script( 'a2zaal_settings_admin', A2ZAAL_ROOT_URL . 'js/a2zaal.js', array( 'jquery' ), false, true ); 83 84 if ( ! empty( $_POST['sbmt_a2zaal_settings'] ) ) { 85 namespace\process_options_submission( namespace\get_a2zaal_active_post_types() ); 86 } 87 } 88 89 /** 90 * control the a2zaal activation and deactivation of specified post types 91 * 92 * @author: nvwd 93 * @since: 2.0.0 94 * @param $a2zaal_original_cpts 95 * @return void 96 */ 97 function process_options_submission( $a2zaal_original_cpts ) { 98 128 \wp_enqueue_script( 'a2zaal_settings_admin', A2ZAAL_ROOT_URL . 'js/a2zaal.js', [ 'jquery' ], A2ZAAL_VERSION, true ); 129 130 // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable -- the nonce is checked in process_options_submission() if this _POST var is not empty. 131 if ( empty( $_POST['sbmt_a2zaal_settings'] ) ) { 132 return; 133 } 134 135 process_options_submission( get_a2zaal_active_post_types() ); 136 } 137 138 /** 139 * Control the a2zaal activation and deactivation of specified post types 140 * 141 * @author nvwd 142 * 143 * @since 2.0.0 144 * 145 * @param array $a2zaal_original_cpts a2zaal active post types. 146 */ 147 function process_options_submission( array $a2zaal_original_cpts ) { 99 148 \check_admin_referer( 'a2zaal-options' ); 100 149 101 $enable_cpts = array(); 102 $disable_cpts = array(); 103 104 if ( isset( $_POST['a2zaal_enabled_post_type'] ) ) { 105 $submitted_cpts = $_POST['a2zaal_enabled_post_type']; 106 $enable_cpts = array_diff( $_POST['a2zaal_enabled_post_type'], $a2zaal_original_cpts ); 107 $disable_cpts = array_diff( $a2zaal_original_cpts, $_POST['a2zaal_enabled_post_type'] ); 150 // phpcs:disable SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable -- checking if the _POST var exists before sanitizing it. 151 $submitted_cpts = isset( $_POST['a2zaal_enabled_post_type'] ) 152 ? array_map( 'sanitize_text_field', \wp_unslash( $_POST['a2zaal_enabled_post_type'] ) ) 153 : false; 154 // phpcs:enable SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable 155 156 $enable_cpts = []; 157 $disable_cpts = []; 158 159 if ( $submitted_cpts ) { 160 $enable_cpts = array_diff( $submitted_cpts, $a2zaal_original_cpts ); 161 $disable_cpts = array_diff( $a2zaal_original_cpts, $submitted_cpts ); 108 162 } else { 109 $submitted_cpts = array();110 $disable_cpts = $a2zaal_original_cpts;111 } 112 113 namespace\maybe_remove_disabled_cpt_a2zaal_posts( $disable_cpts );114 115 namespace\maybe_setup_background_post_type_process( $enable_cpts );163 $submitted_cpts = []; 164 $disable_cpts = $a2zaal_original_cpts; 165 } 166 167 maybe_remove_disabled_cpt_a2zaal_posts( $disable_cpts ); 168 169 maybe_setup_background_post_type_process( $enable_cpts ); 116 170 117 171 if ( ! empty( $disable_cpts ) || ! empty( $enable_cpts ) ) { … … 120 174 121 175 \update_option( 'a2zaal_post_types', $submitted_cpts, true ); 122 123 } 124 125 /** 126 * disable specified post types a2zaal and create the trigger to delete the associated terms127 * 128 * @author: nvwd129 * @since :2.0.0130 * @param $disable_cpts131 * @ return void132 */ 133 function maybe_remove_disabled_cpt_a2zaal_posts( $disable_cpts ) {176 } 177 178 /** 179 * Disable specified post types a2zaal and create the trigger to delete the associated terms 180 * 181 * @author nvwd 182 * 183 * @since 2.0.0 184 * 185 * @param array $disable_cpts cpts being disabled. 186 */ 187 function maybe_remove_disabled_cpt_a2zaal_posts( array $disable_cpts ) { 134 188 if ( empty( $disable_cpts ) ) { 135 189 return; 136 190 } 137 191 138 foreach ( $disable_cpts AS$disabled_post_type ) {139 namespace\remove_disabled_cpts( $disabled_post_type );140 namespace\maybe_remove_current_processing( $disabled_post_type );192 foreach ( $disable_cpts as $disabled_post_type ) { 193 remove_disabled_cpts( $disabled_post_type ); 194 maybe_remove_current_processing( $disabled_post_type ); 141 195 } 142 196 … … 145 199 146 200 /** 147 * remove a2zaal data for disabled post types 148 * 149 * @author: nvwd 150 * @since: 2.0.0 151 * @param $disabled_post_type 152 * @return void 153 */ 154 function remove_disabled_cpts( $disabled_post_type ) { 201 * Remove a2zaal data for disabled post types 202 * 203 * @author nvwd 204 * 205 * @since 2.0.0 206 * 207 * @param string $disabled_post_type post type to delete its option data. 208 */ 209 function remove_disabled_cpts( string $disabled_post_type ) { 155 210 $a2zaal_option = $disabled_post_type . A2ZAAL_POSTS_SUFFIX; 156 211 157 212 \delete_option( $a2zaal_option ); 158 159 } 160 161 function maybe_remove_current_processing( $disabled_post_type ) { 162 $a2zaal_background_processing = \get_option( 'a2zaal_background_processing', array() ); 163 164 if ( ! isset( $a2zaal_background_processing['post-type'][$disabled_post_type] ) ) { 165 return; 166 } 167 168 unset( $a2zaal_background_processing['post-type'][$disabled_post_type] ); 213 } 214 215 /** 216 * Disable background processing for disabled post type. 217 * 218 * @author nvwd 219 * 220 * @since 2.0.0 221 * 222 * @param string $disabled_post_type disabled post type to check for background processing. 223 */ 224 function maybe_remove_current_processing( string $disabled_post_type ) { 225 $a2zaal_background_processing = \get_option( 'a2zaal_background_processing', [] ); 226 227 if ( ! isset( $a2zaal_background_processing['post-type'][ $disabled_post_type ] ) ) { 228 return; 229 } 230 231 unset( $a2zaal_background_processing['post-type'][ $disabled_post_type ] ); 169 232 \update_option( 'a2zaal_background_processing', $a2zaal_background_processing, true ); 170 233 171 if ( empty( $a2zaal_background_processing['post-type'] ) ) {172 namespace\clear_scheduled_processing( 'a2zaal_process_activation_cron' );173 } 174 175 return;176 } 177 178 /** 179 * create the admin notice that the disable request is a success180 * 181 * @author :nvwd182 * @since: 2.0.0183 * @ return void234 if ( ! empty( $a2zaal_background_processing['post-type'] ) ) { 235 return; 236 } 237 238 clear_scheduled_processing( 'a2zaal_process_activation_cron' ); 239 } 240 241 /** 242 * Create the admin notice that the disable request is a success 243 * 244 * @author nvwd 245 * 246 * @since 2.0.0 184 247 */ 185 248 function disabled_a2zaal_cpts_admin_notice() { 186 $class = 'notice notice-success is-dismissible';187 $message = __( 'The specified Post Type(s) are now disabled for A2Z Alphabetical Archive Links.', A2ZAAL_TEXT_DOMAIN);249 $class = 'notice notice-success is-dismissible'; 250 $message = __( 'The specified Post Type(s) are now disabled for A2Z Alphabetical Archive Links.', 'nvwd-a2zaal' ); 188 251 189 252 a2zaal_output_admin_notice( $class, $message ); … … 191 254 192 255 /** 193 * register a2zaal activated post types and create structure to hold the initials and sort titles for256 * Register a2zaal activated post types and create structure to hold the initials and sort titles for 194 257 * existing post type items 195 258 * 196 * @author: nvwd 197 * @since: 2.0.0 198 * @param $enable_cpts 199 * @return void 200 */ 201 function maybe_setup_background_post_type_process( $enable_post_type ) { 259 * @author nvwd 260 * 261 * @since 2.0.0 262 * 263 * @param array $enable_post_type cpts to enable. 264 */ 265 function maybe_setup_background_post_type_process( array $enable_post_type ) { 202 266 if ( empty( $enable_post_type ) ) { 203 267 return; … … 210 274 211 275 /** 212 * create admin notice that the activate request is a success213 * 214 * @author :nvwd215 * @since: 2.0.0216 * @ return void276 * Create admin notice that the activate request is a success 277 * 278 * @author nvwd 279 * 280 * @since 2.0.0 217 281 */ 218 282 function enabled_a2zaal_cpts_admin_notice() { 219 $class = 'notice notice-success is-dismissible'; 220 $message = __( 'The specified Post Type(s) are being processed in the background for A2Z Alphabetical Archive Links. Leaving this page does not stop the process.', A2ZAAL_TEXT_DOMAIN ); 283 $class = 'notice notice-success is-dismissible'; 284 $message = __( 285 'The specified Post Type(s) are being processed in the background for A2Z Alphabetical Archive Links. 286 Leaving this page does not stop the process.', 287 'nvwd-a2zaal' 288 ); 221 289 222 290 a2zaal_output_admin_notice( $class, $message ); -
a2z-alphabetical-archive-links/trunk/a2z-alphabetical-archive-links.php
r2019541 r3193532 1 1 <?php 2 /* 3 Plugin Name: A2Z Alphabetical Archive Links 4 Plugin URI: https://github.com/NowellVanHoesen/a2z-alphabetical-archive-links/wiki 5 Description: 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: 2.0.2 7 Author: Nowell VanHoesen 8 Author URI: http://nvwebdev.com/ 9 Author Email: nowell@nvwebdev.com 10 License: GPL-2.0+ 11 Licanse URI: https://www.gnu.org/licenses/gpl.html 12 Text Domain: nvwd-a2zaal 13 */ 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.2' ); 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() ) ) { 2 /* 3 Plugin Name: A2Z Alphabetical Archive Links 4 Plugin URI: https://github.com/NowellVanHoesen/a2z-alphabetical-archive-links/wiki 5 Description: Get a list of characters, A to Z, from the initial character of a post or CPT title. 6 The Initials will link to an archive page of posts/CPTs that begin with that character. 7 Version: 2.1.0 8 Requires at least: 5.8 9 Requires PHP: 7.4 10 Author: Nowell VanHoesen 11 Author URI: http://nvwebdev.com/ 12 Author Email: nowell@nvwebdev.com 13 License: GPL-2.0+ 14 License URI: https://www.gnu.org/licenses/gpl.html 15 Text Domain: nvwd-a2zaal 16 */ 17 18 namespace NVWD\A2ZAAL; 19 20 if ( ! defined( 'WPINC' ) ) { 21 die; 22 } 23 24 define( 'A2ZAAL_PLUGIN', __FILE__ ); 25 define( 'A2ZAAL_BASENAME', plugin_basename( A2ZAAL_PLUGIN ) ); 26 define( 'A2ZAAL_VERSION', '2.1.0' ); 27 define( 'A2ZAAL_PLUGIN_ROOT_DIR', trailingslashit( __DIR__ ) ); 28 29 $a2zaal_url = plugin_dir_url( A2ZAAL_PLUGIN ); 30 31 if ( is_ssl() ) { 32 $a2zaal_url = str_replace( 'http://', 'https://', $a2zaal_url ); 33 } 34 35 define( 'A2ZAAL_ROOT_URL', $a2zaal_url ); 36 37 define( 'A2ZAAL_PHP_MIN_VERSION', '7.4' ); 38 define( 'A2ZAAL_WP_MIN_VERSION', '5.8' ); 39 40 register_activation_hook( A2ZAAL_PLUGIN, 'a2zaal_activation_check' ); 41 register_deactivation_hook( A2ZAAL_PLUGIN, 'a2zaal_deactivate' ); 42 register_uninstall_hook( A2ZAAL_PLUGIN, 'a2zaal_uninstall' ); 43 44 add_filter( 'a2zaal_do_version_checks', __NAMESPACE__ . '\a2zaal_check_php_version' ); 45 add_filter( 'a2zaal_do_version_checks', __NAMESPACE__ . '\a2zaal_check_wp_version' ); 46 add_action( 'admin_init', __NAMESPACE__ . '\a2zaal_verify_versions' ); 47 48 /* do version checks before including the rest of the plugin code */ 49 if ( is_wp_error( a2zaal_version_checks() ) ) { 50 return; 51 } 52 53 /* version checks complete let's get the party started */ 54 require A2ZAAL_PLUGIN_ROOT_DIR . 'src/plugin.php'; 55 56 /** 57 * Plugin activation script 58 * initiate version checks, disable plugin if any fail 59 * 60 * @author nvwd 61 * 62 * @since 2.0.0 63 */ 64 function a2zaal_activation_check() { 65 $a2zaal_activation_check = a2zaal_version_checks(); 66 67 if ( ! is_wp_error( $a2zaal_activation_check ) ) { 43 68 return; 44 69 } 45 70 46 /* version checks complete let's get the party started */ 47 include( A2ZAAL_PLUGIN_ROOT_DIR . 'src/plugin.php' ); 48 71 deactivate_plugins( A2ZAAL_BASENAME ); 72 } 73 74 /** 75 * Plugin deactivate script 76 * 77 * @author nvwd 78 * 79 * @since 2.0.0 80 */ 81 function a2zaal_deactivate() { 49 82 /** 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 83 * Remove background processing 84 * remove any options 85 * remove any activated post type data 58 86 */ 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; 87 do_action( 'a2zaal_deactivation' ); 88 a2zaal_clear_rewrite_rules(); 89 } 90 91 /** 92 * Plugin uninstall script 93 * 94 * @author nvwd 95 * 96 * @since 2.0.0 97 */ 98 function a2zaal_uninstall() { 99 100 $a2zaal_active_post_types = get_a2zaal_active_post_types(); 101 102 foreach ( $a2zaal_active_post_types as $active_cpt ) { 103 remove_disabled_cpts( $active_cpt ); 104 } 105 106 delete_option( 'a2zaal_post_types' ); 107 } 108 109 /** 110 * Delete rewrite rules option wrapper 111 * 112 * @author nvwd 113 * 114 * @since 2.0.0 115 */ 116 function a2zaal_clear_rewrite_rules() { 117 delete_option( 'rewrite_rules' ); 118 } 119 120 /** 121 * Main version check function 122 * disable plugin if version check(s) fail 123 * 124 * @author nvwd 125 * 126 * @since 2.0.0 127 */ 128 function a2zaal_verify_versions() { 129 $a2zaal_activation_check = a2zaal_version_checks(); 130 131 if ( ! is_wp_error( $a2zaal_activation_check ) || ! is_plugin_active( A2ZAAL_BASENAME ) ) { 132 return; 133 } 134 135 deactivate_plugins( A2ZAAL_BASENAME ); 136 137 // phpcs:disable SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable, WordPress.Security.NonceVerification.Recommended -- plugin activation failed, need to remove the param so nothing else is processed. 138 if ( isset( $_GET['activate'] ) ) { 139 unset( $_GET['activate'] ); 140 } 141 // phpcs:enable SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable 142 } 143 144 /** 145 * Version check controller 146 * 147 * @author nvwd 148 * 149 * @since 2.0.0 150 * 151 * @return bool|\WP_Error 152 */ 153 function a2zaal_version_checks() { 154 // phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName -- Slevomat can't make up its mind with or without the '\', so I'm opting for with. 155 $version_check_errors = new \WP_Error(); 156 157 $version_check_errors = apply_filters( 'a2zaal_do_version_checks', $version_check_errors ); 158 159 $error_codes = $version_check_errors->get_error_codes(); 160 161 if ( ! empty( $error_codes ) ) { 162 return $version_check_errors; 163 } 164 165 return true; 166 } 167 168 /** 169 * Check WP version 170 * 171 * @author nvwd 172 * 173 * @since 2.0.0 174 * 175 * @param \WP_Error $version_check_errors version check errors. 176 * 177 * @return \WP_Error 178 * 179 * phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName -- Slevomat can't make up its mind with or without the '\', so I'm opting for with. 180 */ 181 function a2zaal_check_wp_version( \WP_Error $version_check_errors ) { 182 global $wp_version; 183 184 if ( version_compare( $wp_version, A2ZAAL_WP_MIN_VERSION, '>=' ) ) { 185 return $version_check_errors; 186 } 187 188 add_action( 'admin_notices', 'a2zaal_wp_version_failure_message' ); 189 190 $version_check_errors->add( 191 'wp_version', 192 esc_html__( 193 'WordPress version check for A2Z Alphabetical Archive Links failed. 194 A2Z Alphabetical Archive Links should not be active.', 195 'nvwd-a2zaal' 196 ) 197 ); 198 199 return $version_check_errors; 200 } 201 // phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName 202 203 /** 204 * Check PHP version 205 * 206 * @author nvwd 207 * 208 * @since 2.0.0 209 * 210 * @param \WP_Error $version_check_errors version check errors. 211 * 212 * @return \WP_Error 213 * 214 * phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName -- Slevomat can't make up its mind with or without the '\', so I'm opting for with. 215 */ 216 function a2zaal_check_php_version( \WP_Error $version_check_errors ) { 217 if ( version_compare( PHP_VERSION, A2ZAAL_PHP_MIN_VERSION, '>=' ) ) { 218 return $version_check_errors; 219 } 220 221 add_action( 'admin_notices', 'a2zaal_php_version_failure_message' ); 222 223 $version_check_errors->add( 224 'php_version', 225 esc_html__( 226 'PHP version check for A2Z Alphabetical Archive Links failed. 227 A2Z Alphabetical Archive Links should not be active.', 228 'nvwd-a2zaal' 229 ) 230 ); 231 232 return $version_check_errors; 233 } 234 // phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName 235 236 /** 237 * Create admin notice of WP version check failure 238 * 239 * @author nvwd 240 * 241 * @since 2.0.0 242 */ 243 function a2zaal_wp_version_failure_message() { 244 $css_class = 'notice notice-error'; 245 $message = sprintf( 246 /* translators: 1: Minimum WordPress version */ 247 __( 248 'A2Z Alphabetical Archive Links requires WordPress %1$s to function properly. Please upgrade WordPress. 249 A2Z Alphabetical Archive Links has been auto-deactivated.', 250 'nvwd-a2zaal' 251 ), 252 A2ZAAL_WP_MIN_VERSION 253 ); 254 255 a2zaal_output_admin_notice( $css_class, $message ); 256 } 257 258 /** 259 * Create admin notice of PHP version check failure 260 * 261 * @author nvwd 262 * 263 * @since 2.0.0 264 */ 265 function a2zaal_php_version_failure_message() { 266 $css_class = 'notice notice-error'; 267 $message = sprintf( 268 /* translators: 1: Minimum php version */ 269 __( 270 'A2Z Alphabetical Archive Links requires PHP %1$s to function properly. Please upgrade PHP. 271 A2Z Alphabetical Archive Links has been auto-deactivated.', 272 'nvwd-a2zaal' 273 ), 274 A2ZAAL_PHP_MIN_VERSION 275 ); 276 277 a2zaal_output_admin_notice( $css_class, $message ); 278 } 279 280 /** 281 * Display admin notice 282 * 283 * @author nvwd 284 * 285 * @since 2.0.0 286 * 287 * @param string $css_class css class for the message output. 288 * @param string $message message to display. 289 */ 290 function a2zaal_output_admin_notice( string $css_class, string $message ) { 291 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $css_class ), esc_html( $message ) ); 292 } 293 294 if ( function_exists( 'register_block_type' ) ) { 295 add_action( 296 'init', 297 static function () { 298 register_block_type( __DIR__ . '/build/blocks/a2z-links' ); 65 299 } 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 $error_codes = $version_check_errors->get_error_codes(); 166 if ( ! empty( $error_codes ) ) { 167 return $version_check_errors; 168 } 169 170 return true; 171 } 172 173 add_filter( 'a2zaal_do_version_checks', 'a2zaal_check_wp_version' ); 174 /** 175 * Check WP version 176 * 177 * @author: nvwd 178 * 179 * @since: 2.0.0 180 * 181 * @param $version_check_errors 182 * 183 * @return WP_Error 184 */ 185 function a2zaal_check_wp_version( $version_check_errors ) { 186 global $wp_version; 187 188 if ( version_compare( $wp_version, A2ZAAL_WP_MIN_VERSIONS, '>=' ) ) { 189 return $version_check_errors; 190 } 191 192 add_action( 'admin_notices', 'a2zaal_wp_version_failure_message' ); 193 194 $version_check_errors->add( 195 'wp_version', 196 esc_html__('WordPress version check for A2Z Alphabetical Archive Links failed. A2Z Alphabetical Archive Links should not be active.', A2ZAAL_TEXT_DOMAIN ) 197 ); 198 199 return $version_check_errors; 200 } 201 202 add_filter( 'a2zaal_do_version_checks', 'a2zaal_check_php_version' ); 203 /** 204 * Check PHP version 205 * 206 * @author: nvwd 207 * 208 * @since: 2.0.0 209 * 210 * @param $version_check_errors 211 * 212 * @return WP_Error 213 */ 214 function a2zaal_check_php_version( $version_check_errors ) { 215 if ( version_compare( PHP_VERSION, A2ZAAL_PHP_MIN_VERIONS, '>=' ) ) { 216 return $version_check_errors; 217 } 218 219 add_action( 'admin_notices', 'a2zaal_php_version_failure_message' ); 220 221 $version_check_errors->add( 222 'php_version', 223 esc_html__('PHP version check for A2Z Alphabetical Archive Links failed. A2Z Alphabetical Archive Links should not be active.', A2ZAAL_TEXT_DOMAIN ) 224 ); 225 226 return $version_check_errors; 227 } 228 229 /** 230 * Create admin notice of WP version check failure 231 * 232 * @author: nvwd 233 * 234 * @since: 2.0.0 235 * 236 * @return void 237 */ 238 function a2zaal_wp_version_failure_message() { 239 $class = 'notice notice-error'; 240 $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 ); 241 242 a2zaal_output_admin_notice( $class, $message ); 243 } 244 245 /** 246 * Create admin notice of PHP version check failure 247 * 248 * @author: nvwd 249 * 250 * @since: 2.0.0 251 * 252 * @return void 253 */ 254 function a2zaal_php_version_failure_message() { 255 $class = 'notice notice-error'; 256 $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 ); 257 258 a2zaal_output_admin_notice( $class, $message ); 259 } 260 261 /** 262 * Display admin notice 263 * 264 * @author: nvwd 265 * 266 * @since: 2.0.0 267 * 268 * @param $class 269 * @param $message 270 * 271 * @return void 272 */ 273 function a2zaal_output_admin_notice( $class, $message ) { 274 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); 275 } 300 ); 301 } -
a2z-alphabetical-archive-links/trunk/css/display.css
r2015868 r3193532 1 1 /* CSS Document */ 2 ul.wp-block-nvwda2zaal-a2z-links, 2 3 .a2zaal_widget ul { 3 4 display: grid; … … 7 8 margin: 0; 8 9 } 10 ul.wp-block-nvwda2zaal-a2z-links.counts, 9 11 .a2zaal_widget ul.counts { 10 12 grid-template-columns: repeat( auto-fill, minmax( 3rem, 1fr ) ); 11 13 } 14 .wp-block-nvwda2zaal-a2z-links li, 12 15 .a2zaal_widget li { 13 16 position: relative; 14 17 } 15 18 .wp-block-nvwda2zaal-a2z-links a, 16 19 .a2zaal_widget a { 17 20 border-bottom: 1px solid transparent; … … 20 23 text-align: center; 21 24 } 22 25 .wp-block-nvwda2zaal-a2z-links a:hover, 23 26 .a2zaal_widget a:hover { 24 27 border-bottom: 1px solid blue; … … 26 29 text-decoration: underline; 27 30 } 31 .wp-block-nvwda2zaal-a2z-links a.count > span, 28 32 .a2zaal_widget a.count > span { 29 33 font-size: 75%; … … 32 36 white-space: nowrap; 33 37 } 34 /* premium styles for sliding counts 38 /* 39 ul.wp-block-nvwda2zaal-a2z-links.counts, 35 40 .a2zaal_widget ul.counts { 36 41 grid-template-columns: repeat( auto-fit, minmax( 2.5em, 1fr ) ); 42 gap: 5px; 37 43 } 44 .wp-block-nvwda2zaal-a2z-links li.count:after, 38 45 .a2zaal_widget li.count:after { 39 46 content: ''; … … 50 57 box-shadow: inset 1px 0 #99400e; 51 58 } 52 .a2zaal_widget li a, .a2zaal_widget li a span { 59 .wp-block-nvwda2zaal-a2z-links li a, 60 .wp-block-nvwda2zaal-a2z-links li a span, 61 .a2zaal_widget li a, 62 .a2zaal_widget li a span { 53 63 display: block; 54 64 -webkit-box-sizing: border-box; … … 57 67 white-space: nowrap; 58 68 } 69 .wp-block-nvwda2zaal-a2z-links li a, 59 70 .a2zaal_widget li a { 60 71 padding: 0.25em 0.5em; … … 76 87 box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7), 0 1px 2px rgba(0, 0, 0, 0.05); 77 88 } 89 .wp-block-nvwda2zaal-a2z-links a:hover span, 78 90 .a2zaal_widget a:hover span { 79 91 padding: 0.2em 7px 0.2em 6px; … … 82 94 box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15), 1px 1px 2px rgba(0, 0, 0, 0.2); 83 95 } 96 .wp-block-nvwda2zaal-a2z-links span, 84 97 .a2zaal_widget span { 85 98 position: absolute; -
a2z-alphabetical-archive-links/trunk/readme.txt
r2019541 r3193532 2 2 Contributors: nvwd 3 3 Donate link: http://nvwebdev.com 4 Tags: post title, custom post type title, cpt title, title, alphabetical, alphab atized5 Requires at least: 4.6.06 Tested up to: 5.0.37 Requires PHP: 5.68 Stable tag: 2. 0.24 Tags: post title, custom post type title, cpt title, title, alphabetical, alphabetized 5 Requires at least: 5.8.0 6 Tested up to: 6.7 7 Requires PHP: 7.4 8 Stable tag: 2.1.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 36 36 1. Activate the plugin through the 'Plugins' menu in WordPress 37 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 38 1. Add the 'A2Z Alphabetical Archive Links' widget to a widget area or add the A2Z Links block to a block area 39 39 40 40 == Frequently Asked Questions == … … 44 44 == Screenshots == 45 45 46 1. Widget config 47 1. Links without count 48 1. Links with count (top), hover example ( bottom ) 46 1. Legacy widget config 47 1. A2Z Links block editor with counts disabled 48 1. A2Z Links block editor with counts enabled 49 1. A2Z Links block output with counts disabled 50 1. A2Z Links block output with counts enabled 49 51 50 52 == Changelog == 53 54 = 2.1.0 = 55 56 * Added links block to replace legacy widget 57 * Updated minimum php version to 7.4 58 * Updated minimum WordPress version to 5.8 59 * Resolved RegEx issue that incorrectly grouped some titles in the group that begin with numbers. 51 60 52 61 = 2.0.2 = … … 56 65 = 2.0.1 = 57 66 58 *fixed bug with earlier versions of php and version checking67 fixed bug with earlier versions of php and version checking 59 68 60 69 = 2.0.0 = 61 70 62 Complete rewrite. In an effort to make the code scale better.71 * Complete rewrite. In an effort to make the code scale better. 63 72 * Removed slow query 64 73 * Added minimum WordPress version check … … 73 82 = 1.0.1 = 74 83 75 * Changed widget option for post type to include only public ally queriable post types ( Pages not an option anymore )84 * Changed widget option for post type to include only publicly queryable post types ( Pages not an option anymore ) 76 85 * Fixed links generated when using the post type of Post 77 86 -
a2z-alphabetical-archive-links/trunk/src/helpers.php
r2015868 r3193532 1 1 <?php 2 /**3 * A2Z Alphabetical Archive Links Helper Functions4 *5 * @package NVWD\A2ZAAL6 * @since 2.0.07 * @author nvwd8 * @link http://nvwebdev.com/9 * @license GPL-2.0+10 */11 2 12 3 namespace NVWD\A2ZAAL; 13 4 14 /** 15 * return an array of a2zaal active post types or an empty array when none are active 16 * 17 * @author: nvwd 18 * @since: 2.0.0 5 use WP_Post; 6 7 add_filter( 'widget_block_dynamic_classname', __NAMESPACE__ . '\add_widget_classname', 10, 2 ); 8 9 /** 10 * Return an array of a2zaal active post types or an empty array when none are active 11 * 12 * @author nvwd 13 * 14 * @since 2.0.0 15 * 19 16 * @return array 20 17 */ 21 18 function get_a2zaal_active_post_types() { 22 $a2zaal_active_post_types = get_option( 'a2zaal_post_types', array());19 $a2zaal_active_post_types = \get_option( 'a2zaal_post_types', [] ); 23 20 24 21 if ( ! is_array( $a2zaal_active_post_types ) ) { 25 return array();22 return []; 26 23 } 27 24 28 25 return $a2zaal_active_post_types; 29 30 } 31 32 /** 33 * return an array of a2zaal post types that are currently processing or an empty array 34 * 35 * @author: nvwd 36 * @since: 2.0.0 26 } 27 28 /** 29 * Return an array of a2zaal post types that are currently processing or an empty array 30 * 31 * @author nvwd 32 * 33 * @since 2.0.0 34 * 37 35 * @return array 38 36 */ 39 37 function get_a2zaal_processing_post_types() { 40 $a2zaal_processing_objects = get_option( 'a2zaal_processing_objects', array());38 $a2zaal_processing_objects = \get_option( 'a2zaal_processing_objects', [] ); 41 39 42 40 if ( empty( $a2zaal_processing_objects['post_types'] ) ) { 43 return array();41 return []; 44 42 } 45 43 46 44 return $a2zaal_processing_objects['post_types']; 47 48 } 49 50 /** 51 * this is where the magic happens, return the first character of the provided title and the string used for sorting 45 } 46 47 /** 48 * This is where the magic happens, return the first character of the provided title and the string used for sorting 52 49 * if the title begins with one or more 'a', 'an', 'and', and/or 'the', ignore them and goto the next word 53 50 * if the title then begins with a number return '#', otherwise return the first alpha character, capitalized. 54 51 * return the adjusted title for proper sorting when the links are retireved 55 52 * 56 * @author: nvwd 57 * @since: 2.0.0 58 * @param string $post_title 53 * @author nvwd 54 * 55 * @since 2.0.0 56 * 57 * @param string $post_title Post title being processed for its grouping initial. 58 * 59 59 * @return bool|array 60 60 */ 61 function get_post_a2zaal_info( $post_title ) {61 function get_post_a2zaal_info( string $post_title ) { 62 62 if ( empty( $post_title ) ) { 63 63 return false; 64 64 } 65 preg_match( '/\A[(a|an|and|the) ]*\b(([a-zA-Z]{1}|[\d]{1,}).*)\z/i', $post_title, $a2zaal_char ); 66 $post_a2zaal_info = array( 'sort_title' => $a2zaal_char[1], 'initial' => strtoupper( $a2zaal_char[2] ) ); 65 66 // Regex explained: https://regex101.com/r/B8vbdX/1. 67 preg_match( '/\A(?|a |an |and |the )*(([a-zA-Z]{1}|[\d]{1,}).*)\z/i', $post_title, $a2zaal_char ); 68 $post_a2zaal_info = [ 69 'sort_title' => $a2zaal_char[1], 70 'initial' => strtoupper( $a2zaal_char[2] ), 71 ]; 67 72 68 73 if ( is_numeric( $post_a2zaal_info['initial'] ) ) { … … 74 79 75 80 /** 76 * check if the query is an a2z query needing some extra stuff 77 * 78 * @author: nvwd 79 * @since: 2.0.0 80 * @return bool 81 * Check if the query is an a2z query needing some extra stuff 82 * 83 * @author nvwd 84 * 85 * @since 2.0.0 86 * 87 * @return bool|string 81 88 */ 82 89 function is_a2zaal_query() { 83 84 90 if ( ! \is_main_query() || ! \is_post_type_archive() ) { 85 91 return false; 86 92 } 87 93 88 if ( false === \get_query_var( A2ZAAL_REWRITE_TAG, false ) ) { 89 return false; 90 } 91 92 return true; 93 94 } 95 96 /** 97 * add sortable title and post ID to the structure used to order the posts alphabetically 98 * 99 * @author: nvwd 100 * @since: 2.0.0 101 * @param WP_Post $post post being saved 102 * @return void 103 */ 104 function add_post_a2zaal_info( $post ) { 105 $a2zaal_cpt_option = \get_option( $post->post_type . A2ZAAL_POSTS_SUFFIX, array() ); 106 $post_a2zaal_info = namespace\get_post_a2zaal_info( $post->post_title ); 107 108 if ( ! is_array( $post_a2zaal_info ) || ( array_key_exists( $post_a2zaal_info['initial'], $a2zaal_cpt_option ) && array_key_exists( $post->ID, $a2zaal_cpt_option[ $post_a2zaal_info['initial'] ] ) ) ) { 94 /* phpcs:ignore SlevomatCodingStandard.ControlStructures.UselessTernaryOperator.UselessTernaryOperator -- returning the results of get_query_var is not reliable due to one of the values being 0, making it false. */ 95 return false === \get_query_var( A2ZAAL_REWRITE_TAG, false ) ? false : true; 96 } 97 98 /** 99 * Add sortable title and post ID to the structure used to order the posts alphabetically 100 * 101 * @author nvwd 102 * 103 * @since 2.0.0 104 * 105 * @param \WP_Post $post post being saved. 106 */ 107 function add_post_a2zaal_info( WP_Post $post ) { 108 $a2zaal_cpt_option = \get_option( $post->post_type . A2ZAAL_POSTS_SUFFIX, [] ); 109 $post_a2zaal_info = get_post_a2zaal_info( $post->post_title ); 110 111 if ( 112 ! is_array( $post_a2zaal_info ) 113 || ( 114 array_key_exists( $post_a2zaal_info['initial'], $a2zaal_cpt_option ) 115 && array_key_exists( $post->ID, $a2zaal_cpt_option[ $post_a2zaal_info['initial'] ] ) 116 ) 117 ) { 109 118 return; 110 119 } 111 120 112 // in the case of an update, the post may already exist in the a2z post info structure 113 // ensure that the post doesn't already exist in the structure 114 namespace\remove_prior_post_a2zaal_data( $a2zaal_cpt_option, $post->ID, $post_a2zaal_info['initial'] );121 // in the case of an update, the post may already exist in the a2z post info structure. 122 // ensure that the post doesn't already exist in the structure. 123 remove_prior_post_a2zaal_data( $a2zaal_cpt_option, $post->ID, $post_a2zaal_info['initial'] ); 115 124 116 125 $a2zaal_cpt_option[ $post_a2zaal_info['initial'] ][ $post->ID ] = $post_a2zaal_info['sort_title']; 117 126 118 127 \update_option( $post->post_type . A2ZAAL_POSTS_SUFFIX, $a2zaal_cpt_option, true ); 119 120 } 121 122 /** 123 * in the case of a post update, check to see if the post already exists within the structure 128 } 129 130 /** 131 * In the case of a post update, check to see if the post already exists within the structure 124 132 * remove it if necessary 125 133 * 126 * @author: nvwd 127 * @since: 2.0.0 128 * @param array $a2zaal_cpt_option contains the post alphabetical detail for this post type 129 * @param int $post_id current post ID to possibly remove a previous entry 130 * @param string $post_initial initial of the current post title 131 * @return void 132 */ 133 function remove_prior_post_a2zaal_data( &$a2zaal_cpt_option, $post_id, $post_initial ) { 134 foreach( $a2zaal_cpt_option AS $key => $initial_posts ) { 135 if ( $key == $post_initial ) { 134 * @author nvwd 135 * 136 * @since 2.0.0 137 * 138 * @param array $a2zaal_cpt_option contains the post alphabetical detail for this post type. 139 * @param int $post_id current post ID to possibly remove a previous entry. 140 * @param string $post_initial initial of the current post title. 141 */ 142 function remove_prior_post_a2zaal_data( array &$a2zaal_cpt_option, int $post_id, string $post_initial ) { 143 foreach ( $a2zaal_cpt_option as $key => $initial_posts ) { 144 if ( $key === $post_initial || ! array_key_exists( $post_id, $initial_posts ) ) { 136 145 continue; 137 146 } 138 if ( array_key_exists( $post_id, $initial_posts ) ) { 139 unset( $a2zaal_cpt_option[$key][$post_id] ); 147 148 unset( $a2zaal_cpt_option[ $key ][ $post_id ] ); 149 } 150 } 151 152 /** 153 * Returns the array of a2z links for the widget/block to display. 154 * 155 * @author nvwd 156 * 157 * @since 2.1.0 158 * 159 * @param string $selected_post_type selected post type for the links. 160 * @param bool $show_counts whether to display counts for the initial groups. 161 * 162 * @return array 163 */ 164 function get_a2zaal_display_links( string $selected_post_type, bool $show_counts ) { 165 $post_type_titles_struct = \get_option( $selected_post_type . A2ZAAL_POSTS_SUFFIX, [] ); 166 167 if ( empty( $post_type_titles_struct ) ) { 168 return [ '<p>' . \__( 'No links to display.', 'nvwd-a2zaal' ) . '</p>' ]; 169 } 170 171 $post_type_labels = \get_post_type_object( $selected_post_type )->labels; 172 173 ksort( $post_type_titles_struct, SORT_NATURAL ); 174 175 /* translators: %s: plural post type name */ 176 $link_prefix = sprintf( \__( '%s beginning with ', 'nvwd-a2zaal' ), $post_type_labels->name ); 177 178 foreach ( $post_type_titles_struct as $title_initial => $grouped_titles ) { 179 $group_link = '/' . $selected_post_type . '/' . A2ZAAL_REWRITE_TAG . '/' . $title_initial; 180 $group_count_display = ! empty( $show_counts ) 181 ? '<span>' . \number_format_i18n( count( $grouped_titles ) ) . '</span>' 182 : ''; 183 $link_classes = ! empty( $show_counts ) ? [ 'count' ] : []; 184 $link_classes = implode( ' ', \apply_filters( 'a2zaal_link_css_class', $link_classes, $selected_post_type ) ); 185 $link_title = trim( 186 \apply_filters( 'a2zaal_link_title', $link_prefix . $title_initial, $selected_post_type, $title_initial ) 187 ); 188 $link_text_display = $title_initial; 189 190 if ( 0 === $title_initial ) { 191 $group_link = '/' . $selected_post_type . '/' . A2ZAAL_REWRITE_TAG . '/num'; 192 $link_text_display = '#'; 140 193 } 141 } 142 } 194 195 // TODO: Make sure link is accessible. 196 $display_links[] = sprintf( 197 '<li><a href="%s" class="%s" title="%s">%s%s</a></li>', 198 $group_link, 199 $link_classes, 200 $link_title, 201 $link_text_display, 202 $group_count_display 203 ); 204 } 205 206 return $display_links; 207 } 208 209 /** 210 * Returns adjusted className list for a2z-links widget wrapper. 211 * 212 * @author nvwd 213 * 214 * @since 2.1.0 215 * 216 * @param string $classname list of classnames to be used in the block widget’s container HTML. 217 * @param string $block_name name of the block contained by the block widget. 218 * 219 * @return string 220 */ 221 function add_widget_classname( string $classname, string $block_name ) { 222 if ( 'nvwda2zaal/a2z-links' !== $block_name ) { 223 return $classname; 224 } 225 226 // phpcs:ignore SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable -- unused even though it's part of the return. 227 return $classname .= ' a2zaal_widget'; 228 } -
a2z-alphabetical-archive-links/trunk/src/plugin.php
r2015868 r3193532 1 1 <?php 2 /**3 * A2Z Alphabetical Archive Links Handler4 *5 * @package NVWD\A2ZAAL6 * @since 2.0.07 * @author nvwd8 * @link http://nvwebdev.com/9 * @license GPL-2.0+10 */11 2 12 3 namespace NVWD\A2ZAAL; … … 17 8 define( 'A2ZAAL_VIEW_DIR', A2ZAAL_SOURCE_DIR . 'views/' ); 18 9 19 include A2ZAAL_SOURCE_DIR . 'vender/wp-background-processing/wp-background-processing.php';20 include A2ZAAL_SOURCE_DIR . 'classes/A2ZAAL_Post_Type_Background_Process.php';10 require A2ZAAL_SOURCE_DIR . 'vender/wp-background-processing/wp-background-processing.php'; 11 require A2ZAAL_SOURCE_DIR . 'classes/class-a2zaal-post-type-background-process.php'; 21 12 22 13 if ( is_admin() ) { 23 include A2ZAAL_SOURCE_DIR . 'settings.php';14 require A2ZAAL_SOURCE_DIR . 'settings.php'; 24 15 } 25 include A2ZAAL_SOURCE_DIR . 'rewrites.php'; 26 include A2ZAAL_SOURCE_DIR . 'helpers.php'; 27 include A2ZAAL_SOURCE_DIR . 'widgets/a2zaal_widget.php'; 16 17 require A2ZAAL_SOURCE_DIR . 'rewrites.php'; 18 require A2ZAAL_SOURCE_DIR . 'helpers.php'; 19 require A2ZAAL_SOURCE_DIR . 'widgets/class-a2zaal-widget.php'; 20 21 \add_action( 'widgets_init', __NAMESPACE__ . '\maybe_register_archive_link_widget' ); 22 23 /** 24 * Register the a2zaal widget only if there are active post types 25 * 26 * @author nvwd 27 * 28 * @since 2.0.0 29 */ 30 function maybe_register_archive_link_widget() { 31 $a2z_active_post_types = get_a2zaal_active_post_types(); 32 33 if ( empty( $a2z_active_post_types ) ) { 34 return; 35 } 36 37 \register_widget( __NAMESPACE__ . '\a2zaal_widget' ); 38 } 28 39 29 40 add_action( 'save_post', __NAMESPACE__ . '\maybe_add_a2zaal_post' ); 30 41 /** 31 * add the a2zaal data to the specific structure when an active post type item is saved42 * Add the a2zaal data to the specific structure when an active post type item is saved 32 43 * 33 * @author: nvwd 34 * @since: 2.0.0 35 * @param $post_id 36 * @return void 44 * @author nvwd 45 * 46 * @since 2.0.0 47 * 48 * @param int $post_id ID of the post being saved. 37 49 */ 38 function maybe_add_a2zaal_post( $post_id ) { 39 50 function maybe_add_a2zaal_post( int $post_id ) { 40 51 if ( \wp_is_post_revision( $post_id ) || \wp_is_post_autosave( $post_id ) ) { 41 52 return; 42 53 } 43 54 44 $a2zaal_post = \get_post( $post_id );45 $a2zaal_active_post_types = namespace\get_a2zaal_active_post_types();55 $a2zaal_post = \get_post( $post_id ); 56 $a2zaal_active_post_types = get_a2zaal_active_post_types(); 46 57 47 if ( ! in_array( $a2zaal_post->post_type, $a2zaal_active_post_types ) ) {58 if ( ! in_array( $a2zaal_post->post_type, $a2zaal_active_post_types, true ) ) { 48 59 return; 49 60 } 50 61 51 namespace\add_post_a2zaal_info( $a2zaal_post ); 52 62 add_post_a2zaal_info( $a2zaal_post ); 53 63 } 54 64 55 65 /** 56 * make the a2zaal list page titles more readable66 * Make the a2zaal list page titles more readable 57 67 * 58 * @author: nvwd 59 * @since: 2.0.0 60 * @param $archive_title 68 * @author nvwd 69 * 70 * @since 2.0.0 71 * 72 * @param string $archive_title archive page title. 73 * 61 74 * @return string 62 75 */ 63 function filter_archive_title( $archive_title ) {64 if ( ! namespace\is_a2zaal_query() ) {76 function filter_archive_title( string $archive_title ) { 77 if ( ! is_a2zaal_query() ) { 65 78 return $archive_title; 66 79 } 67 80 68 $post_type_labels = get_post_type_object(get_query_var( 'post_type' ) );69 $group_title_initial = get_query_var( A2ZAAL_REWRITE_TAG );81 $post_type_labels = \get_post_type_object( \get_query_var( 'post_type' ) ); 82 $group_title_initial = \get_query_var( A2ZAAL_REWRITE_TAG ); 70 83 71 if ( '0' == $group_title_initial ) {84 if ( '0' === $group_title_initial ) { 72 85 $group_title_initial = '#'; 73 86 } 74 87 75 return sprintf( __( '%1$s: %2$s' ), $post_type_labels->label, $group_title_initial ); 88 /* translators: 1: post type title 2: initial of the archive grouping */ 89 return sprintf( __( '%1$s: %2$s', 'nvwd-a2zaal' ), $post_type_labels->label, $group_title_initial ); 76 90 } 77 91 78 92 /** 79 * customize the a2zaal list page description93 * Customize the a2zaal list page description 80 94 * 81 * @author: nvwd 82 * @since: 2.0.0 83 * @param $archive_description 95 * @author nvwd 96 * 97 * @since 2.0.0 98 * 99 * @param string $archive_description archive page description. 100 * 84 101 * @return string 85 102 */ 86 function filter_archive_description( $archive_description ) {87 if ( ! namespace\is_a2zaal_query() ) {103 function filter_archive_description( string $archive_description ) { 104 if ( ! is_a2zaal_query() ) { 88 105 return $archive_description; 89 106 } 90 107 91 $post_type_labels = get_post_type_object(get_query_var( 'post_type' ) );108 $post_type_labels = \get_post_type_object( \get_query_var( 'post_type' ) ); 92 109 93 $group_title_initial = get_query_var( A2ZAAL_REWRITE_TAG );110 $group_title_initial = \get_query_var( A2ZAAL_REWRITE_TAG ); 94 111 95 if ( '0' == $group_title_initial ) {96 $group_title_initial = __( 'a number', A2ZAAL_TEXT_DOMAIN );112 if ( '0' === $group_title_initial ) { 113 $group_title_initial = 'a number'; 97 114 } 98 115 99 return sprintf( __( '%1$s beginning with %2$s.' ), $post_type_labels->label, $group_title_initial ); 116 /* translators: 1: post type title 2: initial of the archive grouping */ 117 return sprintf( __( '%1$s beginning with %2$s.', 'nvwd-a2zaal' ), $post_type_labels->label, $group_title_initial ); 100 118 } -
a2z-alphabetical-archive-links/trunk/src/rewrites.php
r2015868 r3193532 1 1 <?php 2 /**3 * A2Z Alphabetical Archive Rewrites Handler4 *5 * @package NVWD\A2ZAAL6 * @since 2.0.07 * @author nvwd8 * @link http://nvwebdev.com/9 * @license GPL-2.0+10 */11 2 12 3 namespace NVWD\A2ZAAL; 4 5 use WP; 6 use WP_Query; 13 7 14 8 \add_filter( 'rewrite_rules_array', __NAMESPACE__ . '\maybe_modify_rewrite_rules_array' ); 15 9 16 10 /** 17 * add rewrite rules for each a2z active post type11 * Add rewrite rules for each a2z active post type 18 12 * 19 * @author: nvwd 20 * @since: 2.0.0 21 * @param array $rewrite_rules the rewrite structure passed in 22 * @return array the possibly updated rewrite structure 13 * @author nvwd 14 * 15 * @since 2.0.0 16 * 17 * @param array $rewrite_rules the rewrite structure passed in. 18 * 19 * @return array 23 20 */ 24 function maybe_modify_rewrite_rules_array( $rewrite_rules ) {25 $a2zaal_active_post_types = namespace\get_a2zaal_active_post_types();21 function maybe_modify_rewrite_rules_array( array $rewrite_rules ) { 22 $a2zaal_active_post_types = get_a2zaal_active_post_types(); 26 23 27 24 if ( empty( $a2zaal_active_post_types ) ) { … … 29 26 } 30 27 31 $new_rules = array();28 $new_rules = []; 32 29 33 foreach ( $a2zaal_active_post_types AS $active_post_type ) { 34 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=all'; 35 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/page/?([0-9]{1,})/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=all&paged=$matches[2]'; 36 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/([a-zA-Z])/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=$matches[1]'; 37 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/num/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=0'; 38 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/([a-zA-Z])/page/?([0-9]{1,})/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=$matches[1]&paged=$matches[2]'; 39 $new_rules[$active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/num/page/?([0-9]{1,})/?$'] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=0&paged=$matches[1]'; 30 // phpcs:disable SlevomatCodingStandard.Files.LineLength.LineTooLong -- line length due to alignment for each rewrite rule. 31 foreach ( $a2zaal_active_post_types as $active_post_type ) { 32 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=all'; 33 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/page/?([0-9]{1,})/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=all&paged=$matches[2]'; 34 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/([a-zA-Z])/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=$matches[1]'; 35 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/num/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=0'; 36 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/([a-zA-Z])/page/?([0-9]{1,})/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=$matches[1]&paged=$matches[2]'; 37 $new_rules[ $active_post_type . '/' . A2ZAAL_REWRITE_TAG . '/num/page/?([0-9]{1,})/?$' ] = 'index.php?post_type=' . $active_post_type . '&' . A2ZAAL_REWRITE_TAG . '=0&paged=$matches[1]'; 40 38 } 39 40 // phpcs:enable SlevomatCodingStandard.Files.LineLength.LineTooLong 41 41 42 42 return array_merge( $new_rules, $rewrite_rules ); … … 46 46 47 47 /** 48 * add the query tag being used for holding the specific initial48 * Add the query tag being used for holding the specific initial 49 49 * 50 * @author :nvwd51 * @since: 2.0.052 * @ return void50 * @author nvwd 51 * 52 * @since 2.0.0 53 53 */ 54 54 function add_a2zaal_rewrite_tag() { … … 59 59 60 60 /** 61 * add hooks to modify the query if the a2z rewrite tag exists61 * Add hooks to modify the query if the a2z rewrite tag exists 62 62 * 63 * @author: nvwd 64 * @since: 2.0.0 65 * @param WP_Query $query main query 66 * @return void 63 * @author nvwd 64 * 65 * @since 2.0.0 66 * 67 * @param \WP $query WordPress environment instance. 67 68 */ 68 function maybe_alter_query_for_a2zaal( $query ) {69 function maybe_alter_query_for_a2zaal( WP $query ) { 69 70 if ( ! isset( $query->query_vars[ A2ZAAL_REWRITE_TAG ] ) ) { 70 71 return; … … 79 80 80 81 /** 81 * pull all posts until I can build in pagination, then make pagination optional82 * Pull all posts until I can build in pagination, then make pagination optional 82 83 * 83 * @author: nvwd 84 * @since: 2.0.0 85 * @param WP_Query $query main query 86 * @return void 84 * @author nvwd 85 * 86 * @since 2.0.0 87 * 88 * @param \WP_Query $query main query. 87 89 */ 88 function kill_pagination( $query ) {90 function kill_pagination( WP_Query $query ) { 89 91 $query->set( 'posts_per_page', -1 ); 90 92 $query->set( 'no_found_rows', true ); … … 92 94 93 95 /** 94 * add IN clause providing a list of post IDs to be retrieved by the query96 * Add IN clause providing a list of post IDs to be retrieved by the query 95 97 * 96 * @author: nvwd 97 * @since: 2.0.0 98 * @param string $posts_where query where clause 99 * @return string maybe modified where clause 98 * @author nvwd 99 * 100 * @since 2.0.0 101 * 102 * @param string $posts_where query where clause. 103 * 104 * @return string 100 105 */ 101 function filter_a2zaal_where_clause( $posts_where ) {106 function filter_a2zaal_where_clause( string $posts_where ) { 102 107 global $wpdb; 103 108 104 $post_type_a2zaal_struct = \get_option( \get_query_var( 'post_type' ) . A2ZAAL_POSTS_SUFFIX, array());109 $post_type_a2zaal_struct = \get_option( \get_query_var( 'post_type' ) . A2ZAAL_POSTS_SUFFIX, [] ); 105 110 106 111 if ( empty( $post_type_a2zaal_struct ) ) { … … 112 117 $specific_post_ids = implode( ',', array_keys( $post_type_a2zaal_struct[ $a2zaal_query_var ] ) ); 113 118 114 $posts_where .= " AND ( $wpdb->posts.ID IN (" . $specific_post_ids . ") )";119 $posts_where .= " AND ( $wpdb->posts.ID IN (" . $specific_post_ids . ') )'; 115 120 116 121 return $posts_where; … … 118 123 119 124 /** 120 * set the sort order using the naturally sorted object titles125 * Set the sort order using the naturally sorted object titles 121 126 * 122 * @author: nvwd 123 * @since: 2.0.0 124 * @param string $posts_orderby orderby clause 125 * @return string maybe new orderby clause 127 * @author nvwd 128 * 129 * @since 2.0.0 130 * 131 * @param string $posts_orderby orderby clause. 132 * 133 * @return string 126 134 */ 127 function filter_a2zaal_orderby_clause( $posts_orderby ) {135 function filter_a2zaal_orderby_clause( string $posts_orderby ) { 128 136 global $wpdb; 129 137 130 $post_type_a2zaal_struct = \get_option( \get_query_var( 'post_type' ) . A2ZAAL_POSTS_SUFFIX, array());138 $post_type_a2zaal_struct = \get_option( \get_query_var( 'post_type' ) . A2ZAAL_POSTS_SUFFIX, [] ); 131 139 132 140 if ( empty( $post_type_a2zaal_struct ) ) { … … 148 156 149 157 /** 150 * check to see if posts/objects for the specified a2z initial exists in the post type structure158 * Check to see if posts/objects for the specified a2z initial exists in the post type structure 151 159 * 152 * @author: nvwd 153 * @since: 2.0.0 154 * @param $query 155 * @return void 160 * @author nvwd 161 * 162 * @since 2.0.0 163 * 164 * @param \WP_Query $query query to check to see if it's a 404. 156 165 */ 157 function check_a2zaal_404( &$query ) { 158 159 if ( ! namespace\is_a2zaal_query() || \is_admin() ) { 166 function check_a2zaal_404( WP_Query &$query ) { 167 if ( ! is_a2zaal_query() || \is_admin() ) { 160 168 return; 161 169 } 162 170 163 $post_type_a2zaal_struct = \get_option( $query->query_vars['post_type'] . A2ZAAL_POSTS_SUFFIX, array());171 $post_type_a2zaal_struct = \get_option( $query->query_vars['post_type'] . A2ZAAL_POSTS_SUFFIX, [] ); 164 172 165 173 if ( empty( $post_type_a2zaal_struct ) ) { … … 167 175 } 168 176 169 if ( array_key_exists( $query->query_vars[ A2ZAAL_REWRITE_TAG ], $post_type_a2zaal_struct ) || 'all' == $query->query_vars[ A2ZAAL_REWRITE_TAG ] ) { 177 if ( 178 array_key_exists( $query->query_vars[ A2ZAAL_REWRITE_TAG ], $post_type_a2zaal_struct ) 179 || 'all' === $query->query_vars[ A2ZAAL_REWRITE_TAG ] 180 ) { 170 181 return; 171 182 } … … 173 184 $query->set_404(); 174 185 } 175 -
a2z-alphabetical-archive-links/trunk/src/settings.php
r2015868 r3193532 1 1 <?php 2 /**3 * A2Z Alphabetical Archive Links Settings Page Handler4 *5 * @package NVWD\A2ZAAL6 * @since 2.0.07 * @author nvwd8 * @link http://nvwebdev.com/9 * @license GPL-2.0+10 */11 2 12 3 namespace NVWD\A2ZAAL; 13 4 5 use WP_Screen; 6 14 7 \add_filter( 'plugin_action_links_' . A2ZAAL_BASENAME, __NAMESPACE__ . '\add_settings_page_link' ); 15 8 16 function add_settings_page_link( $links ) { 17 $settings_link = '<a href="' . \admin_url( 'options-general.php?page=a2zaal-options' ) . '">' . __( 'Settings', A2ZAAL_TEXT_DOMAIN ) . '</a>'; 9 /** 10 * Adds custom settings page to the admin settings menu 11 * 12 * @author nvwd 13 * 14 * @since 2.0.0 15 * 16 * @param array $links admin menu links. 17 * 18 * @return array 19 */ 20 function add_settings_page_link( array $links ) { 21 $settings_link = sprintf( 22 '<a href="%s">%s</a>', 23 \admin_url( 'options-general.php?page=a2zaal-options' ), 24 \__( 'Settings', 'nvwd-a2zaal' ) 25 ); 18 26 array_unshift( $links, $settings_link ); 27 19 28 return $links; 20 29 } … … 23 32 24 33 /** 25 * add admin settings page for our use26 * 27 * @author :nvwd28 * @since: 2.0.029 * @ return void34 * Add admin settings page for our use 35 * 36 * @author nvwd 37 * 38 * @since 2.0.0 30 39 */ 31 40 function add_settings_menu_link() { 32 \add_options_page( 'A2Z Alphabetical Archive Links Options', 'A2Z Alphabetical Archive Links', 'manage_options', 'a2zaal-options', __NAMESPACE__ . '\create_settings_page' ); 33 //enqueue javascript and styles needed for admin options page 34 } 35 36 /** 37 * admin page creation script 38 * 39 * @author: nvwd 40 * @since: 2.0.0 41 * @return void 41 \add_options_page( 42 'A2Z Alphabetical Archive Links Options', 43 'A2Z Alphabetical Archive Links', 44 'manage_options', 45 'a2zaal-options', 46 __NAMESPACE__ . '\create_settings_page' 47 ); 48 // enqueue javascript and styles needed for admin options page. 49 } 50 51 /** 52 * Admin page creation script 53 * 54 * @author nvwd 55 * 56 * @since 2.0.0 42 57 */ 43 58 function create_settings_page() { 44 45 59 if ( ! \current_user_can( 'manage_options' ) ) { 46 60 die( 'Unauthorized User' ); 47 61 } 48 62 49 $a2zaal_active_post_types = namespace\get_a2zaal_active_post_types(); 50 51 $a2zaal_processing_post_types = namespace\get_a2zaal_processing_post_types(); 52 53 $excluded_post_types = array( 54 'attachment', 55 'revision', 56 'nav_menu_item' 57 ); 58 59 $registered_post_types = \get_post_types( array( 'publicly_queryable' => true ), 'objects' ); 60 61 $a2zaal_processing_counts = \get_option( 'a2zaal_processing_counts', array() ); 62 63 include( A2ZAAL_VIEW_DIR . 'settings_form.php' ); 63 require A2ZAAL_VIEW_DIR . 'settings-form.php'; 64 } 65 66 \add_action( 'admin_init', __NAMESPACE__ . '\register_plugin_settings' ); 67 \add_action( 'rest_admin_init', __NAMESPACE__ . '\register_plugin_settings' ); 68 69 /** 70 * Register block widget 71 * 72 * @author nvwd 73 * 74 * @since 2.1.0 75 */ 76 function register_plugin_settings() { 77 $args = [ 78 'default' => [], 79 'type' => 'array', 80 'show_in_rest' => [ 81 'schema' => [ 82 'type' => 'array', 83 'items' => [ 84 'type' => 'string', 85 ], 86 ], 87 ], 88 ]; 89 90 \register_setting( 'options', 'a2zaal_post_types', $args ); 91 } 92 93 add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\output_a2z_active_post_types' ); 94 95 /** 96 * Outputs the a2z active post types for use in the block editor 97 * 98 * @author nvwd 99 * 100 * @since 2.1.0 101 */ 102 function output_a2z_active_post_types() { 103 $a2z_active_post_types = get_a2zaal_active_post_types(); 104 105 \wp_add_inline_script( 106 'nvwda2zaal-a2z-links-editor-script', 107 'const NVWDA2ZAAL_activePostTypes = ' . \wp_json_encode( $a2z_active_post_types ) . ';', 108 'before' 109 ); 64 110 } 65 111 … … 67 113 68 114 /** 69 * handle the submission of our settings page70 * 71 * @author :nvwd72 * @since: 2.0.073 * @ param $screen_obj74 * @return void75 * /76 function maybe_process_a2zaal_settings_save( $screen_obj ) { 77 115 * Handle the submission of our settings page 116 * 117 * @author nvwd 118 * 119 * @since 2.0.0 120 * 121 * @param \WP_Screen $screen_obj current screen. 122 */ 123 function maybe_process_a2zaal_settings_save( WP_Screen $screen_obj ) { 78 124 if ( 'settings_page_a2zaal-options' !== $screen_obj->id ) { 79 125 return; 80 126 } 81 127 82 \wp_enqueue_script( 'a2zaal_settings_admin', A2ZAAL_ROOT_URL . 'js/a2zaal.js', array( 'jquery' ), false, true ); 83 84 if ( ! empty( $_POST['sbmt_a2zaal_settings'] ) ) { 85 namespace\process_options_submission( namespace\get_a2zaal_active_post_types() ); 86 } 87 } 88 89 /** 90 * control the a2zaal activation and deactivation of specified post types 91 * 92 * @author: nvwd 93 * @since: 2.0.0 94 * @param $a2zaal_original_cpts 95 * @return void 96 */ 97 function process_options_submission( $a2zaal_original_cpts ) { 98 128 \wp_enqueue_script( 'a2zaal_settings_admin', A2ZAAL_ROOT_URL . 'js/a2zaal.js', [ 'jquery' ], A2ZAAL_VERSION, true ); 129 130 // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable -- the nonce is checked in process_options_submission() if this _POST var is not empty. 131 if ( empty( $_POST['sbmt_a2zaal_settings'] ) ) { 132 return; 133 } 134 135 process_options_submission( get_a2zaal_active_post_types() ); 136 } 137 138 /** 139 * Control the a2zaal activation and deactivation of specified post types 140 * 141 * @author nvwd 142 * 143 * @since 2.0.0 144 * 145 * @param array $a2zaal_original_cpts a2zaal active post types. 146 */ 147 function process_options_submission( array $a2zaal_original_cpts ) { 99 148 \check_admin_referer( 'a2zaal-options' ); 100 149 101 $enable_cpts = array(); 102 $disable_cpts = array(); 103 104 if ( isset( $_POST['a2zaal_enabled_post_type'] ) ) { 105 $submitted_cpts = $_POST['a2zaal_enabled_post_type']; 106 $enable_cpts = array_diff( $_POST['a2zaal_enabled_post_type'], $a2zaal_original_cpts ); 107 $disable_cpts = array_diff( $a2zaal_original_cpts, $_POST['a2zaal_enabled_post_type'] ); 150 // phpcs:disable SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable -- checking if the _POST var exists before sanitizing it. 151 $submitted_cpts = isset( $_POST['a2zaal_enabled_post_type'] ) 152 ? array_map( 'sanitize_text_field', \wp_unslash( $_POST['a2zaal_enabled_post_type'] ) ) 153 : false; 154 // phpcs:enable SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable.DisallowedSuperGlobalVariable 155 156 $enable_cpts = []; 157 $disable_cpts = []; 158 159 if ( $submitted_cpts ) { 160 $enable_cpts = array_diff( $submitted_cpts, $a2zaal_original_cpts ); 161 $disable_cpts = array_diff( $a2zaal_original_cpts, $submitted_cpts ); 108 162 } else { 109 $submitted_cpts = array();110 $disable_cpts = $a2zaal_original_cpts;111 } 112 113 namespace\maybe_remove_disabled_cpt_a2zaal_posts( $disable_cpts );114 115 namespace\maybe_setup_background_post_type_process( $enable_cpts );163 $submitted_cpts = []; 164 $disable_cpts = $a2zaal_original_cpts; 165 } 166 167 maybe_remove_disabled_cpt_a2zaal_posts( $disable_cpts ); 168 169 maybe_setup_background_post_type_process( $enable_cpts ); 116 170 117 171 if ( ! empty( $disable_cpts ) || ! empty( $enable_cpts ) ) { … … 120 174 121 175 \update_option( 'a2zaal_post_types', $submitted_cpts, true ); 122 123 } 124 125 /** 126 * disable specified post types a2zaal and create the trigger to delete the associated terms127 * 128 * @author: nvwd129 * @since :2.0.0130 * @param $disable_cpts131 * @ return void132 */ 133 function maybe_remove_disabled_cpt_a2zaal_posts( $disable_cpts ) {176 } 177 178 /** 179 * Disable specified post types a2zaal and create the trigger to delete the associated terms 180 * 181 * @author nvwd 182 * 183 * @since 2.0.0 184 * 185 * @param array $disable_cpts cpts being disabled. 186 */ 187 function maybe_remove_disabled_cpt_a2zaal_posts( array $disable_cpts ) { 134 188 if ( empty( $disable_cpts ) ) { 135 189 return; 136 190 } 137 191 138 foreach ( $disable_cpts AS$disabled_post_type ) {139 namespace\remove_disabled_cpts( $disabled_post_type );140 namespace\maybe_remove_current_processing( $disabled_post_type );192 foreach ( $disable_cpts as $disabled_post_type ) { 193 remove_disabled_cpts( $disabled_post_type ); 194 maybe_remove_current_processing( $disabled_post_type ); 141 195 } 142 196 … … 145 199 146 200 /** 147 * remove a2zaal data for disabled post types 148 * 149 * @author: nvwd 150 * @since: 2.0.0 151 * @param $disabled_post_type 152 * @return void 153 */ 154 function remove_disabled_cpts( $disabled_post_type ) { 201 * Remove a2zaal data for disabled post types 202 * 203 * @author nvwd 204 * 205 * @since 2.0.0 206 * 207 * @param string $disabled_post_type post type to delete its option data. 208 */ 209 function remove_disabled_cpts( string $disabled_post_type ) { 155 210 $a2zaal_option = $disabled_post_type . A2ZAAL_POSTS_SUFFIX; 156 211 157 212 \delete_option( $a2zaal_option ); 158 159 } 160 161 function maybe_remove_current_processing( $disabled_post_type ) { 162 $a2zaal_background_processing = \get_option( 'a2zaal_background_processing', array() ); 163 164 if ( ! isset( $a2zaal_background_processing['post-type'][$disabled_post_type] ) ) { 165 return; 166 } 167 168 unset( $a2zaal_background_processing['post-type'][$disabled_post_type] ); 213 } 214 215 /** 216 * Disable background processing for disabled post type. 217 * 218 * @author nvwd 219 * 220 * @since 2.0.0 221 * 222 * @param string $disabled_post_type disabled post type to check for background processing. 223 */ 224 function maybe_remove_current_processing( string $disabled_post_type ) { 225 $a2zaal_background_processing = \get_option( 'a2zaal_background_processing', [] ); 226 227 if ( ! isset( $a2zaal_background_processing['post-type'][ $disabled_post_type ] ) ) { 228 return; 229 } 230 231 unset( $a2zaal_background_processing['post-type'][ $disabled_post_type ] ); 169 232 \update_option( 'a2zaal_background_processing', $a2zaal_background_processing, true ); 170 233 171 if ( empty( $a2zaal_background_processing['post-type'] ) ) {172 namespace\clear_scheduled_processing( 'a2zaal_process_activation_cron' );173 } 174 175 return;176 } 177 178 /** 179 * create the admin notice that the disable request is a success180 * 181 * @author :nvwd182 * @since: 2.0.0183 * @ return void234 if ( ! empty( $a2zaal_background_processing['post-type'] ) ) { 235 return; 236 } 237 238 clear_scheduled_processing( 'a2zaal_process_activation_cron' ); 239 } 240 241 /** 242 * Create the admin notice that the disable request is a success 243 * 244 * @author nvwd 245 * 246 * @since 2.0.0 184 247 */ 185 248 function disabled_a2zaal_cpts_admin_notice() { 186 $class = 'notice notice-success is-dismissible';187 $message = __( 'The specified Post Type(s) are now disabled for A2Z Alphabetical Archive Links.', A2ZAAL_TEXT_DOMAIN);249 $class = 'notice notice-success is-dismissible'; 250 $message = __( 'The specified Post Type(s) are now disabled for A2Z Alphabetical Archive Links.', 'nvwd-a2zaal' ); 188 251 189 252 a2zaal_output_admin_notice( $class, $message ); … … 191 254 192 255 /** 193 * register a2zaal activated post types and create structure to hold the initials and sort titles for256 * Register a2zaal activated post types and create structure to hold the initials and sort titles for 194 257 * existing post type items 195 258 * 196 * @author: nvwd 197 * @since: 2.0.0 198 * @param $enable_cpts 199 * @return void 200 */ 201 function maybe_setup_background_post_type_process( $enable_post_type ) { 259 * @author nvwd 260 * 261 * @since 2.0.0 262 * 263 * @param array $enable_post_type cpts to enable. 264 */ 265 function maybe_setup_background_post_type_process( array $enable_post_type ) { 202 266 if ( empty( $enable_post_type ) ) { 203 267 return; … … 210 274 211 275 /** 212 * create admin notice that the activate request is a success213 * 214 * @author :nvwd215 * @since: 2.0.0216 * @ return void276 * Create admin notice that the activate request is a success 277 * 278 * @author nvwd 279 * 280 * @since 2.0.0 217 281 */ 218 282 function enabled_a2zaal_cpts_admin_notice() { 219 $class = 'notice notice-success is-dismissible'; 220 $message = __( 'The specified Post Type(s) are being processed in the background for A2Z Alphabetical Archive Links. Leaving this page does not stop the process.', A2ZAAL_TEXT_DOMAIN ); 283 $class = 'notice notice-success is-dismissible'; 284 $message = __( 285 'The specified Post Type(s) are being processed in the background for A2Z Alphabetical Archive Links. 286 Leaving this page does not stop the process.', 287 'nvwd-a2zaal' 288 ); 221 289 222 290 a2zaal_output_admin_notice( $class, $message );
Note: See TracChangeset
for help on using the changeset viewer.