Changeset 2468467
- Timestamp:
- 02/04/2021 04:08:04 AM (5 years ago)
- Location:
- custom-comment-links/trunk
- Files:
-
- 1 added
- 5 edited
-
class-admin.php (modified) (1 diff)
-
class-helpers.php (modified) (3 diffs)
-
class-settings.php (modified) (6 diffs)
-
custom-comment-links.php (modified) (2 diffs)
-
index.php (added)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
custom-comment-links/trunk/class-admin.php
r2101952 r2468467 85 85 86 86 add_settings_field( 87 ' form_url',88 __( ' Comment form', 'custom-comment-links' ),89 'EcoTechie\Custom_Comment_Links\Settings:: form_url_render',87 'bypass_users', 88 __( 'Bypass settings', 'custom-comment-links' ), 89 'EcoTechie\Custom_Comment_Links\Settings::bypass_users_render', 90 90 'pluginPage', 91 91 'pluginPage_section' -
custom-comment-links/trunk/class-helpers.php
r2101952 r2468467 48 48 $options = get_option( 'settings' ); 49 49 50 if ( isset( $options['form_url'] ) ) {51 add_filter( 'comment_form_default_fields', array( $this, 'comment_form_default_fields_remove_url' ) );52 }53 54 50 if ( isset( $options['comment_author_url'] ) ) { 55 add_filter( 'get_comment_author_url', array( $this, 'remove_comment_author_url' ), 10, 3 );51 add_filter( 'get_comment_author_url', array( $this, 'remove_comment_author_url' ), 20, 3 ); 56 52 } 57 53 58 54 if ( isset( $options['comment_links'] ) && '1' == $options['comment_links'] ) { 59 add_filter( 'comment_text', array( $this, 'comment_text_links_move' ) );55 add_filter( 'comment_text', array( $this, 'comment_text_links_move' ), 20, 3 ); 60 56 } 61 57 62 58 if ( isset( $options['comment_links'] ) && '2' == $options['comment_links'] ) { 63 add_filter( 'comment_text', array( $this, 'comment_text_links_unset' ) );59 add_filter( 'comment_text', array( $this, 'comment_text_links_unset' ), 20, 3 ); 64 60 } 65 61 } 66 62 67 63 /** 68 * Unsets comment form URL field. 69 * 70 * @since 0.1.0 71 * 72 * @param array $fields The default comment fields. 73 * 74 * @return array $fields Unset URL key. 75 */ 76 function comment_form_default_fields_remove_url( $fields ) { 77 unset( $fields['url'] ); 78 return $fields; 64 * Verify user has, at least, edit posts priviledges. 65 * 66 * @since 0.2 67 * 68 * @param int The comment ID. 69 * 70 * @return bool 71 */ 72 function is_user_priviledged( $id ) { 73 if ( user_can( get_user_by( 'login', get_comment_author( $id ) ), 'edit_posts' ) ) { 74 return true; 75 } else { 76 return false; 77 } 78 } 79 80 /** 81 * Verify priviledged users should be bypassed. 82 * 83 * @since 0.2 84 * 85 * @return bool 86 */ 87 function bypass_priviledged_users() { 88 $options = get_option( 'settings' ); 89 if ( isset( $options['bypass_users'] ) ) { 90 return true; 91 } else { 92 return false; 93 } 79 94 } 80 95 … … 87 102 * @param int $comment_ID The comment ID. 88 103 * @param WP_Comment $comment The comment object. 104 * 105 * @return string The comment author's URL. 89 106 */ 90 function remove_comment_author_url( $url, $id, $comment ) { 91 unset( $url ); 107 function remove_comment_author_url( $url, $comment_ID, $comment ) { 108 if ( ( ! self::bypass_priviledged_users() ) || ( self::bypass_priviledged_users() && ! self::is_user_priviledged( $comment->ID ) ) ) { 109 $url = ''; 110 } 111 return $url; 92 112 } 93 113 … … 97 117 * @since 0.1.0 98 118 * 99 * @param string $comment_text Text of the current comment. 119 * @param string $comment_text Text of the current comment. 120 * @param WP_Comment/null $comment The comment object. Null if not found. 121 * @param array $args An array of arguments. 100 122 * 101 * @return string $url Removes link's href and move next to it in parenthesis.123 * @return string Text of the current comment. 102 124 */ 103 function comment_text_links_move( $comment_text ) { 104 $comment_text = preg_replace( '/<a href=[\",\'](.*?)[\",\']>(.*?)<\/a>/', "\\2(\\1)", $comment_text ); 105 return $comment_text; 125 function comment_text_links_move( $comment_text, $comment, $args ) { 126 if ( ( ! self::bypass_priviledged_users() ) || ( self::bypass_priviledged_users() && ! self::is_user_priviledged( $comment->ID ) ) ) { 127 $comment_text = preg_replace( '/<a[^>]+href=\"(.*?)\"[^>]*>(.*?)<\/a>/', "\\2 (\\1)", $comment_text ); 128 } 129 return $comment_text; 106 130 } 107 131 108 132 /** 109 * Filters comment to be displayed by removing links' href .133 * Filters comment to be displayed by removing links' href. 110 134 * 111 135 * @since 0.1.1 112 136 * 113 * @param string $comment_text Text of the current comment. 137 * @param string $comment_text Text of the current comment. 138 * @param WP_Comment/null $comment The comment object. Null if not found. 139 * @param array $args An array of arguments. 114 140 * 115 * @return string $url Removes link's href.141 * @return string Text of the current comment. 116 142 */ 117 function comment_text_links_unset( $comment_text ) { 118 $comment_text = preg_replace( '/<a href=[\",\'](.*?)[\",\']>(.*?)<\/a>/', "\\2", $comment_text ); 119 return $comment_text; 143 function comment_text_links_unset( $comment_text, $comment, $args ) { 144 if ( ( ! self::bypass_priviledged_users() ) || ( self::bypass_priviledged_users() && ! self::is_user_priviledged( $comment->ID ) ) ) { 145 $comment_text = preg_replace( '/<a[^>]+href=\"(.*?)\"[^>]*>(.*?)<\/a>/', "\\2", $comment_text ); 146 } 147 return $comment_text; 120 148 } 121 149 } 122 150 123 /**151 /** 124 152 * Init the plugin. 125 153 */ -
custom-comment-links/trunk/class-settings.php
r2139697 r2468467 40 40 41 41 /** 42 * Add comment formsetting checkbox.42 * Add edit permission setting checkbox. 43 43 * 44 * @since 0.1. 144 * @since 0.1.3 45 45 */ 46 function form_url_render() {46 static function bypass_users_render() { 47 47 $options = get_option( 'settings' ); 48 48 49 49 ?> 50 <input type='checkbox' id='form_url' name='settings[form_url]' <?php checked( isset( $options['form_url'] ) ); ?> value='1'> 51 <label for='form_url'>Hide Website input field in comment form</label> 52 <p class='description'>If checked, comment author won't be able to add their Website in comment forms.</p> 53 <p class='description'>Website won't be saved in the database.</p> 50 <input type='checkbox' id='bypass_users' name='settings[bypass_users]' <?php checked( isset( $options['bypass_users'] ) ); ?> value='1'> 51 <label for='bypass_users'>Bypass for priviledged users</label> 52 <p class='description'>If checked, users who can edit posts won't be affected by settings below.</p> 54 53 <?php 55 54 } … … 60 59 * @since 0.1.1 61 60 */ 62 function comment_author_url_render() {61 static function comment_author_url_render() { 63 62 $options = get_option( 'settings' ); 64 63 … … 67 66 <label for='comment_author_url'>Hide comment author's Website on comments</label> 68 67 <p class='description'>If checked, comment author's name won't have a link to their Website.</p> 69 <p class='description'>If it was already saved in the database.</p>70 68 <?php 71 69 } … … 77 75 * @since 0.1.1 78 76 */ 79 function comment_links_render() {77 static function comment_links_render() { 80 78 $options = get_option( 'settings' ); 81 79 if ( ! is_array( $options ) ) { … … 91 89 <input type='radio' id='comment_links_move' name='settings[comment_links]' <?php checked( $options['comment_links'], 1 ); ?> value='1'> 92 90 <label for='comment_links_move'>Move</label> 93 <p class='description'><a href="https://www.ecotechie.io">EcoTechie</a>, would be changed to EcoTechie (https://www.ecotechie.io)</p>91 <p class='description'><a href="https://www.ecotechie.io">EcoTechie</a>, would be changed to EcoTechie (https://www.ecotechie.io)</p> 94 92 <br> 95 93 <input type='radio' id='comment_links_unset' name='settings[comment_links]' <?php checked( $options['comment_links'], 2 ); ?> value='2'> … … 105 103 * @since 0.1.1 106 104 */ 107 public function options_page() {105 public static function options_page() { 108 106 109 107 ?> -
custom-comment-links/trunk/custom-comment-links.php
r2167966 r2468467 8 8 * Text Domain: custom-comment-links 9 9 * Domain Path: /languages 10 * Version: 0. 1.310 * Version: 0.2 11 11 * 12 12 * @package Custom_Comment_Links … … 36 36 * @var string 37 37 */ 38 const VERSION = '0. 1.1';38 const VERSION = '0.2'; 39 39 40 40 /** -
custom-comment-links/trunk/readme.txt
r2167971 r2468467 1 1 === Custom Comment Links === 2 2 Contributors: seedsca 3 Tags: custom comment links, custom, comment, links, comment link, comment SEO, hide comment links, remove link 3 Tags: custom comment links, custom, comment, links, comment link, comment SEO, hide comment links, remove link, comments, author 4 4 Requires at least: 4.5 5 Tested up to: 5. 2.36 Stable tag: 0. 1.35 Tested up to: 5.6 6 Stable tag: 0.2 7 7 Requires PHP: 5.6 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Simple plugin to customize how comment form's links behave on your site. Control Website input field, comment's author URL, and remove links from comments (with option to add the un-clickable URL next to the text).11 Customize comment links on your site. Control comment author's URL, remove links from comments. Disable these options for privileged users. 12 12 13 13 == Description == 14 14 15 Customize how your site's comments links are shown for website, author and content. 15 Ever wish you could remove links inside comments, or their author's website? 16 17 With this simple plugin you can customize how your site's comment links are shown for author and content. 16 18 Enable this plugin and select if: 17 * The Website input field on the Comment form is hidden. 18 * The comment author's name link to their website is loaded. 19 20 * Users with post editing capabilities are affected by the settings. 21 * The comment author's website link is loaded. 19 22 * Any links in the comments are unset or moved next to the link text inside parenthesis. 20 23 … … 24 27 25 28 == Changelog == 29 30 = 0.2 = 31 * Remove setting to disable the comment author website input field on comment forms. 32 * Add option to bypass priviledged users, those who can edit posts, from the plugin settings. 26 33 27 34 = 0.1.3 =
Note: See TracChangeset
for help on using the changeset viewer.