Changeset 3335487
- Timestamp:
- 07/28/2025 04:30:22 PM (8 months ago)
- Location:
- broken-link-notifier
- Files:
-
- 54 added
- 4 edited
-
tags/1.3.2 (added)
-
tags/1.3.2/broken-link-notifier.php (added)
-
tags/1.3.2/includes (added)
-
tags/1.3.2/includes/cache.php (added)
-
tags/1.3.2/includes/css (added)
-
tags/1.3.2/includes/css/results-front.css (added)
-
tags/1.3.2/includes/css/results-front.min.css (added)
-
tags/1.3.2/includes/discord.php (added)
-
tags/1.3.2/includes/example-hook.php (added)
-
tags/1.3.2/includes/export.php (added)
-
tags/1.3.2/includes/helpers.php (added)
-
tags/1.3.2/includes/img (added)
-
tags/1.3.2/includes/img/admin-help-docs.png (added)
-
tags/1.3.2/includes/img/clear-cache-everywhere.png (added)
-
tags/1.3.2/includes/img/dev-debug-tools.png (added)
-
tags/1.3.2/includes/img/devconsole.gif (added)
-
tags/1.3.2/includes/img/discord.png (added)
-
tags/1.3.2/includes/img/eri-file-library.png (added)
-
tags/1.3.2/includes/img/gf-discord.png (added)
-
tags/1.3.2/includes/img/gf-msteams.png (added)
-
tags/1.3.2/includes/img/gf-tools.png (added)
-
tags/1.3.2/includes/img/gravity-zwr.png (added)
-
tags/1.3.2/includes/img/logo-teal.png (added)
-
tags/1.3.2/includes/img/logo-transparent.png (added)
-
tags/1.3.2/includes/img/screen_options.png (added)
-
tags/1.3.2/includes/index.php (added)
-
tags/1.3.2/includes/integrations.php (added)
-
tags/1.3.2/includes/js (added)
-
tags/1.3.2/includes/js/index.php (added)
-
tags/1.3.2/includes/js/omits.js (added)
-
tags/1.3.2/includes/js/results-back.js (added)
-
tags/1.3.2/includes/js/results-front.js (added)
-
tags/1.3.2/includes/js/results-front.min.js (added)
-
tags/1.3.2/includes/js/scan-multi.js (added)
-
tags/1.3.2/includes/js/scan-single.js (added)
-
tags/1.3.2/includes/js/settings.js (added)
-
tags/1.3.2/includes/loader.php (added)
-
tags/1.3.2/includes/menu.php (added)
-
tags/1.3.2/includes/msteams.php (added)
-
tags/1.3.2/includes/omits.php (added)
-
tags/1.3.2/includes/page-export.php (added)
-
tags/1.3.2/includes/page-help.php (added)
-
tags/1.3.2/includes/page-link-search.php (added)
-
tags/1.3.2/includes/page-scan-multi.php (added)
-
tags/1.3.2/includes/page-scan-single.php (added)
-
tags/1.3.2/includes/page-settings.php (added)
-
tags/1.3.2/includes/page.php (added)
-
tags/1.3.2/includes/results.php (added)
-
tags/1.3.2/includes/scan-multi.php (added)
-
tags/1.3.2/includes/scan.php (added)
-
tags/1.3.2/includes/test_files (added)
-
tags/1.3.2/includes/test_files/Jubiläum-A-und-B.pdf (added)
-
tags/1.3.2/index.php (added)
-
tags/1.3.2/readme.txt (added)
-
trunk/broken-link-notifier.php (modified) (2 diffs)
-
trunk/includes/loader.php (modified) (3 diffs)
-
trunk/includes/menu.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
broken-link-notifier/trunk/broken-link-notifier.php
r3331551 r3335487 4 4 * Plugin URI: https://pluginrx.com/plugin/broken-link-notifier/ 5 5 * Description: Get notified when someone loads a page with a broken link 6 * Version: 1.3. 1.16 * Version: 1.3.2 7 7 * Requires at least: 5.9 8 8 * Tested up to: 6.8 … … 83 83 84 84 /** 85 * Initialize the plugin loader 86 */ 87 $blnotifier_loader_instance = new BLNOTIFIER_LOADER(); 88 89 90 /** 91 * Register activation and deactivation hooks for role/capability management. 92 * These hooks must be called in the main plugin file and target methods of your plugin instance. 93 */ 94 register_activation_hook( __FILE__, [ $blnotifier_loader_instance, 'plugin_activate' ] ); 95 register_deactivation_hook( __FILE__, [ $blnotifier_loader_instance, 'plugin_deactivate' ] ); 96 97 98 /** 85 99 * Delete the cache table on plugin deactivation or uninstall. 86 100 */ -
broken-link-notifier/trunk/includes/loader.php
r3305248 r3335487 11 11 12 12 /** 13 * Initialize the class14 */15 16 new BLNOTIFIER_LOADER();17 18 19 /**20 13 * Main plugin class. 21 14 */ 22 15 class BLNOTIFIER_LOADER { 16 17 /** 18 * Define your custom capability 19 */ 20 public $capability = 'manage_broken_links'; 21 22 23 /** 24 * Define your custom role slug 25 */ 26 public $role_slug = 'blnotifier_link_manager'; 27 23 28 24 29 /** … … 32 37 } 33 38 $this->load_dependencies(); 39 40 // Add custom capability to the admin 41 add_action( 'admin_init', [ $this, 'add_custom_capability_to_admin' ] ); 34 42 35 43 } // End __construct() … … 141 149 } // End load_dependencies() 142 150 151 152 /** 153 * Plugin activation hook callback 154 */ 155 public function plugin_activate() { 156 $admin_role = get_role( 'administrator' ); 157 if ( $admin_role ) { 158 $admin_role->add_cap( $this->capability ); 159 } 160 161 add_role( 162 $this->role_slug, 163 __( 'Broken Link Manager', 'broken-link-notifier' ), 164 [ 165 'read' => true, 166 $this->capability => true, 167 ] 168 ); 169 } // End plugin_activate() 170 171 172 /** 173 * Plugin deactivation hook callback 174 */ 175 public function plugin_deactivate() { 176 $admin_role = get_role( 'administrator' ); 177 if ( $admin_role ) { 178 $admin_role->remove_cap( $this->capability ); 179 } 180 181 remove_role( $this->role_slug ); 182 } // End plugin_deactivate() 183 184 185 /** 186 * Ensures the custom capability exists for administrators on admin_init 187 */ 188 public function add_custom_capability_to_admin() { 189 $role = get_role( 'administrator' ); 190 if ( $role && !$role->has_cap( $this->capability ) ) { 191 $role->add_cap( $this->capability ); 192 } 193 } // End add_custom_capability_to_admin() 194 143 195 } -
broken-link-notifier/trunk/includes/menu.php
r3292111 r3335487 39 39 */ 40 40 public $menu_items; 41 42 43 /** 44 * The capability required to access the menu 45 * 46 * @var string 47 */ 48 public $capability = 'manage_broken_links'; 41 49 42 50 … … 70 78 add_action( 'admin_menu', [ $this, 'admin_menu' ] ); 71 79 80 // Update role after sett 81 add_action( 'admin_init', [ $this, 'update_roles' ] ); 82 72 83 // Fix the Manage link to show active 73 84 add_filter( 'parent_file', [ $this, 'submenus' ] ); … … 88 99 */ 89 100 public function admin_menu() { 90 // Capability 91 $capability = sanitize_key( apply_filters( 'blnotifier_capability', 'manage_options' ) ); 101 // Get the current user's roles 102 $current_user = wp_get_current_user(); 103 $user_roles = (array) $current_user->roles; 104 105 $capability = 'do_not_allow'; 106 $show_menu = false; 107 108 if ( in_array( 'administrator', $user_roles ) ) { 109 $capability = 'manage_options'; 110 $show_menu = true; 111 112 } else { 113 $allowed_roles = get_option( 'blnotifier_editable_roles', [] ); 114 if ( is_array( $allowed_roles ) && !empty( $allowed_roles ) ) { 115 foreach ( $allowed_roles as $role_slug => $value ) { 116 $role_slug = sanitize_key( $role_slug ); 117 118 if ( in_array( $role_slug, $user_roles ) ) { 119 $capability = $this->capability; 120 $show_menu = true; 121 break; 122 } 123 } 124 } 125 } 126 127 if ( !$show_menu ) { 128 return; 129 } 92 130 93 131 // Count broken links … … 112 150 } 113 151 } // End admin_menu() 152 153 154 /** 155 * Update user roles 156 * 157 * @return void 158 */ 159 public function update_roles() { 160 if ( isset( $_GET[ 'settings-updated' ] ) && $_GET[ 'settings-updated' ] == 'true' ) { 161 162 $allowed_roles = get_option( 'blnotifier_editable_roles', [] ); 163 if ( is_array( $allowed_roles ) && !empty( $allowed_roles ) ) { 164 $saniotized_allowed_roles = []; 165 foreach ( $allowed_roles as $role_slug => $value ) { 166 $saniotized_allowed_roles[] = sanitize_key( $role_slug ); 167 } 168 $allowed_roles = $saniotized_allowed_roles; 169 } 170 171 $editable_roles = $this->get_editable_roles_choices(); 172 if ( !empty( $editable_roles ) && is_array( $editable_roles ) ) { 173 174 foreach ( $editable_roles as $editable_role_slug => $label ) { 175 $role = get_role( $editable_role_slug ); 176 if ( !$role ) { 177 continue; 178 } 179 180 if ( in_array( $editable_role_slug, $allowed_roles ) && ! $role->has_cap( $this->capability ) ) { 181 $role->add_cap( $this->capability ); 182 } elseif ( $role->has_cap( $this->capability ) ) { 183 $role->remove_cap( $this->capability ); 184 } 185 } 186 } 187 } 188 } // End update_roles() 114 189 115 190 … … 449 524 'min' => 0, 450 525 'comments' => 'Use 0 to disable caching. If you are experienced performance issues, you can set the value to 28800 (8 hours), 43200 (12 hours), 86400 (24 hours) or whatever you feel is best. Broken and warning links will never be cached. Deactivating or uninstalling the plugin will clear the cache completely.' 526 ] 527 ); 528 529 // User Roles for Editing Links 530 $roles_option_name = 'blnotifier_editable_roles'; 531 register_setting( $this->page_slug, $roles_option_name, [ $this, 'sanitize_checkboxes' ] ); 532 add_settings_field( 533 $roles_option_name, 534 'Allow These Additional Roles to Manage Broken Links', 535 [ $this, 'field_checkboxes' ], 536 $this->page_slug, 537 'general', 538 [ 539 'class' => $roles_option_name, 540 'name' => $roles_option_name, 541 'options' => $this->get_editable_roles_choices(), 451 542 ] 452 543 ); … … 794 885 795 886 /** 887 * Get editable roles choices 888 * 889 * @return array 890 */ 891 public function get_editable_roles_choices() { 892 global $wp_roles; 893 $results = []; 894 $roles = $wp_roles->get_names(); 895 foreach ( $roles as $role_slug => $role_name ) { 896 if ( $role_slug == 'administrator' ) { 897 continue; 898 } 899 $results[ $role_slug ] = $role_name; 900 } 901 return $results; 902 } // End get_editable_roles_choices() 903 904 905 /** 796 906 * Custom callback function to print multiple emails field 797 907 * -
broken-link-notifier/trunk/readme.txt
r3331551 r3335487 5 5 Tested up to: 6.8 6 6 Requires PHP: 7.4 7 Stable tag: 1.3. 1.17 Stable tag: 1.3.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.txt … … 128 128 129 129 == Changelog == 130 = 1.3.2 = 131 * Update: Added support for additional roles to have capability of managing broken links 132 130 133 = 1.3.1.1 = 131 134 * Fix: preg_replace() deprecation error (props @venutius)
Note: See TracChangeset
for help on using the changeset viewer.