Plugin Directory

Changeset 2468467


Ignore:
Timestamp:
02/04/2021 04:08:04 AM (5 years ago)
Author:
seedsca
Message:

Add feature to exclude priviledged user roles, and remove feature to hide author website in comment form

Location:
custom-comment-links/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • custom-comment-links/trunk/class-admin.php

    r2101952 r2468467  
    8585
    8686            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',
    9090                'pluginPage',
    9191                'pluginPage_section'
  • custom-comment-links/trunk/class-helpers.php

    r2101952 r2468467  
    4848            $options = get_option( 'settings' );
    4949
    50             if ( isset( $options['form_url'] ) ) {
    51                 add_filter( 'comment_form_default_fields', array( $this, 'comment_form_default_fields_remove_url' ) );
    52             }
    53 
    5450            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 );
    5652            }
    5753
    5854            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 );
    6056            }
    6157
    6258            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 );
    6460            }
    6561        }
    6662
    6763        /**
    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            }
    7994        }
    8095
     
    87102         * @param int        $comment_ID The comment ID.
    88103         * @param WP_Comment $comment    The comment object.
     104         *
     105         * @return string The comment author's URL.
    89106         */
    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;
    92112        }
    93113
     
    97117         * @since 0.1.0
    98118         *
    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.
    100122         *
    101          * @return string $url          Removes link's href and move next to it in parenthesis.
     123         * @return string Text of the current comment.
    102124         */
    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;
    106130        }
    107131
    108132        /**
    109          * Filters comment to be displayed by removing links' href .
     133         * Filters comment to be displayed by removing links' href.
    110134         *
    111135         * @since 0.1.1
    112136         *
    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.
    114140         *
    115          * @return string $url          Removes link's href.
     141         * @return string Text of the current comment.
    116142         */
    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;
    120148        }
    121149    }
    122150
    123         /**
     151    /**
    124152     * Init the plugin.
    125153     */
  • custom-comment-links/trunk/class-settings.php

    r2139697 r2468467  
    4040
    4141        /**
    42          * Add comment form setting checkbox.
     42         * Add edit permission setting checkbox.
    4343         *
    44          * @since 0.1.1
     44         * @since 0.1.3
    4545         */
    46         function form_url_render() {
     46        static function bypass_users_render() {
    4747            $options = get_option( 'settings' );
    4848
    4949            ?>
    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>
    5453            <?php
    5554        }
     
    6059         * @since 0.1.1
    6160         */
    62         function comment_author_url_render() {
     61        static function comment_author_url_render() {
    6362            $options = get_option( 'settings' );
    6463
     
    6766            <label for='comment_author_url'>Hide comment author's Website on comments</label>
    6867            <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>
    7068            <?php
    7169        }
     
    7775         * @since 0.1.1
    7876         */
    79         function comment_links_render() {
     77        static function comment_links_render() {
    8078            $options = get_option( 'settings' );
    8179            if ( ! is_array( $options ) ) {
     
    9189            <input type='radio' id='comment_links_move' name='settings[comment_links]' <?php checked( $options['comment_links'], 1 ); ?> value='1'>
    9290            <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>
    9492            <br>
    9593            <input type='radio' id='comment_links_unset' name='settings[comment_links]' <?php checked( $options['comment_links'], 2 ); ?> value='2'>
     
    105103         * @since 0.1.1
    106104         */
    107         public function options_page() {
     105        public static function options_page() {
    108106
    109107            ?>
  • custom-comment-links/trunk/custom-comment-links.php

    r2167966 r2468467  
    88 * Text Domain:     custom-comment-links
    99 * Domain Path:     /languages
    10  * Version:         0.1.3
     10 * Version:         0.2
    1111 *
    1212 * @package         Custom_Comment_Links
     
    3636         * @var string
    3737         */
    38         const VERSION = '0.1.1';
     38        const VERSION = '0.2';
    3939
    4040        /**
  • custom-comment-links/trunk/readme.txt

    r2167971 r2468467  
    11=== Custom Comment Links ===
    22Contributors: seedsca
    3 Tags: custom comment links, custom, comment, links, comment link, comment SEO, hide comment links, remove link
     3Tags: custom comment links, custom, comment, links, comment link, comment SEO, hide comment links, remove link, comments, author
    44Requires at least: 4.5
    5 Tested up to: 5.2.3
    6 Stable tag: 0.1.3
     5Tested up to: 5.6
     6Stable tag: 0.2
    77Requires PHP: 5.6
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010
    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).
     11Customize comment links on your site. Control comment author's URL, remove links from comments. Disable these options for privileged users.
    1212
    1313== Description ==
    1414
    15 Customize how your site's comments links are shown for website, author and content.
     15Ever wish you could remove links inside comments, or their author's website?
     16
     17With this simple plugin you can customize how your site's comment links are shown for author and content.
    1618Enable 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.
    1922* Any links in the comments are unset or moved next to the link text inside parenthesis.
    2023
     
    2427
    2528== 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.
    2633
    2734= 0.1.3 =
Note: See TracChangeset for help on using the changeset viewer.