• I have built a comment form that contains your standard Name / Email / Website fields. In each <input> I have the name of the field, which disappears onfocus, reappears onblur. It will allow me to hide my labels with css for a cleaner look.

    My problem is, since the term “Website” is in the website field, when a comment is posted, wordpress is counting that a valid URL and displaying it as the author link… as you’d expect.

    So my question: Is it possible to write something to put in functions.php to make wordpress detect if the field says ‘Website’ to not post a URL, or act as it would if the field were blank?

    I dug around in the core files and found this chunk of code (below). It’s from wp-includes/comment-template.php, the function get_comment_author_url_link seems to do the sniffing as to whether what the user submitted is a real URL or not and reformats it.

    I don’t know how ‘hooks’ work, so I may be off base here, but is it possible to write something (a hook maybe? 🙂 ) in your functions.php to essentially rewrite get_comment_author_url_link? To get it to include the field ‘Website’ in it’s detection?

    /**
     * Retrieves the HTML link of the url of the author of the current comment.
     *
     * $linktext parameter is only used if the URL does not exist for the comment
     * author. If the URL does exist then the URL will be used and the $linktext
     * will be ignored.
     *
     * Encapsulate the HTML link between the $before and $after. So it will appear
     * in the order of $before, link, and finally $after.
     *
     * @since 1.5.0
     * @uses apply_filters() Calls the 'get_comment_author_url_link' on the complete HTML before returning.
     *
     * @param string $linktext The text to display instead of the comment author's email address
     * @param string $before The text or HTML to display before the email link.
     * @param string $after The text or HTML to display after the email link.
     * @return string The HTML link between the $before and $after parameters
     */
    function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
    	$url = get_comment_author_url();
    	$display = ($linktext != '') ? $linktext : $url;
    	$display = str_replace( 'http://www.', '', $display );
    	$display = str_replace( 'http://', '', $display );
    	if ( '/' == substr($display, -1) )
    		$display = substr($display, 0, -1);
    	$return = "$before<a href='$url' rel='external'>$display</a>$after";
    	return apply_filters('get_comment_author_url_link', $return);
    }
    
    /**
     * Displays the HTML link of the url of the author of the current comment.
     *
     * @since 0.71
     * @see get_comment_author_url_link() Echoes result
     *
     * @param string $linktext The text to display instead of the comment author's email address
     * @param string $before The text or HTML to display before the email link.
     * @param string $after The text or HTML to display after the email link.
     */
    function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
    	echo get_comment_author_url_link( $linktext, $before, $after );
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Comment form – URL detection, hook?’ is closed to new replies.