Changeset 1303333
- Timestamp:
- 12/08/2015 10:35:01 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
comment-author-url-stripper/trunk/comment-author-url-stripper.php
r1303319 r1303333 10 10 */ 11 11 12 add_action( 'admin_menu', 'mdv_caus_add_pages');13 add_filter( 'pre_comment_author_url', 'mdv_caus');14 register_activation_hook( __FILE__, 'set_mdv_caus_options');12 add_action(); 13 add_filter(); 14 register_activation_hook(); 15 15 16 16 function mdv_caus_add_pages() { 17 add_options_page( 'Comment Author URL Stripper Options', 'CAU Stripper', 8, __FILE__, 'mdv_caus_options_page');17 add_options_page(); 18 18 } 19 19 20 20 function set_mdv_caus_options() { 21 add_option( 'mdv_caus_keys', '');21 add_option(); 22 22 } 23 23 … … 25 25 $updated = false; 26 26 27 if ($_REQUEST['mdv_caus_keys']) {28 update_option( 'mdv_caus_keys', $_REQUEST['mdv_caus_keys']);27 if) { 28 update_option(); 29 29 $updated = true; 30 30 } 31 31 32 if($updated) { ?> 32 if ( $updated ) { 33 ?> 33 34 <div id="message" class="updated fade"> 34 35 <p>Options saved.</p> 35 </div><?php 36 } else { ?> 36 </div> 37 <?php 38 } else { 39 ?> 37 40 <div id="message" class="failed fade"> 38 41 <p>Failed to update options.</p> 39 </div><?php 42 </div> 43 <?php 40 44 } 41 45 } … … 46 50 <h2>Comment Author URL Stripper Options</h2> 47 51 <?php 48 if($_REQUEST['submit']) update_mdv_caus_options(); 49 $mdv_caus_keys = get_option('mdv_caus_keys'); 52 if ( $_REQUEST['submit'] ) { 53 update_mdv_caus_options(); 54 } 55 $mdv_caus_keys = get_option( 'mdv_caus_keys' ); 50 56 ?> 51 57 <form method="post" action="options.php"> 52 <?php wp_nonce_field('update-options') ?> 53 54 <fieldset class="options"> 55 <p><?php _e('When a comment author URL contains any of these words, the URL will be removed. One word per line.') ?></p> 56 <p> 57 <textarea name="mdv_caus_keys" cols="60" rows="4" id="moderation_keys" style="width: 98%; font-size: 12px;" class="code"><?php echo $mdv_caus_keys; ?></textarea> 58 </p> 59 </fieldset> 58 <?php wp_nonce_field( 'update-options' ); ?> 60 59 61 <p class="submit"> 62 <input type="hidden" name="action" value="update" /> 63 <input type="hidden" name="page_options" value="mdv_caus_keys" /> 64 <input type="submit" name="Submit" value="<?php _e('Update Options »') ?>" /> 65 </p> 60 <fieldset class="options"> 61 <p><?php _e( 'When a comment author URL contains any of these words, the URL will be removed. One word per line.' ); ?></p> 62 <p> 63 <textarea name="mdv_caus_keys" cols="60" rows="4" id="moderation_keys" style="width: 98%; font-size: 12px;" class="code"><?php echo esc_html( $mdv_caus_keys ); ?></textarea> 64 </p> 65 </fieldset> 66 67 <p class="submit"> 68 <input type="hidden" name="action" value="update" /> 69 <input type="hidden" name="page_options" value="mdv_caus_keys" /> 70 <input type="submit" name="Submit" value="<?php _e( 'Update Options »' ); ?>" /> 71 </p> 66 72 </form> 67 73 </div> … … 69 75 } 70 76 71 function mdv_caus($url) { 72 if ( !mdv_caus_ok($url) ) $url = ''; 77 function mdv_caus( $url ) { 78 if ( ! mdv_caus_ok( $url ) ) { 79 $url = ''; 80 } 73 81 74 82 return $url; 75 83 } 76 84 77 function mdv_caus_ok( $url) {78 $mdv_caus_keys = trim( get_option('mdv_caus_keys'));79 if ( ! empty($mdv_caus_keys) ) {80 $words = explode( "\n", $mdv_caus_keys );85 function mdv_caus_ok() { 86 $mdv_caus_keys = trim(); 87 if ( !) ) { 88 $words = explode("\n", $mdv_caus_keys ); 81 89 82 foreach ( $words as $word) {83 $word = trim( $word);90 foreach () { 91 $word = trim(); 84 92 85 93 // Skip empty lines 86 if ( empty( $word) )94 if ( empty( 87 95 continue; 96 88 97 89 98 // Do some escaping magic so that '#' chars in the 90 99 // spam words don't break things: 91 $word = preg_quote( $word, '#');100 $word = preg_quote(); 92 101 93 102 $pattern = "#$word#i"; 94 if ( preg_match($pattern, $url) ) return false; 103 if ( preg_match( $pattern, $url ) ) { 104 return false; 105 } 95 106 } 96 107 } … … 98 109 return true; 99 110 } 100 ?>
Note: See TracChangeset
for help on using the changeset viewer.