Support » Plugin: Anti-spam » Notice: Use of undefined constant comment_author_url – assumed "comment_author_u

  • Resolved sw33t

    (@sw33t)


    Just updated, now got this notice, as reported by a user… and the page isn’t loading.

    Notice: Use of undefined constant comment_author_url – assumed “comment_author_url” in “……plugins/anti-spam/anti-spam.php on line 128.

    Notice: Use of undefined constant comment_content – assumed “comment_content” in “……plugins/anti-spam/anti-spam.php on line 133.

    same for comment_content, on lines 144, 150, 155.

    Anyone else have this issue?

    https://wordpress.org/plugins/anti-spam/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author webvitalii

    (@webvitaly)

    Warning notice is not an error.
    If you have enabled warning notices on your production site – I recommend you to disabled it because alot of plugins will reproduce warning messages.

    If this warnings are bothering you alot – you can fix it and share updated plugin with everyone. And probably I will include your code in the next release.

    jumbo

    (@jumbo)

    @webvitaly I do think this is actually a meaningful notice to correct. For folks with active commenting on their website and the WordPress WP_DEBUG constant set to true and logged, these notices are going to be logged every single time a comment is submitted.

    For instance, the follow is logged within WordPress’ /wp-content/debug.log after one comment is submitted:

    [04-Dec-2014 03:43:02 UTC] PHP Notice:  Use of undefined constant comment_author_url - assumed 'comment_author_url' in /home/user/public_html/wp-content/plugins/anti-spam/anti-spam.php on line 128
    [04-Dec-2014 03:43:02 UTC] PHP Notice:  Use of undefined constant comment_content - assumed 'comment_content' in /home/user/public_html/wp-content/plugins/anti-spam/anti-spam.php on line 133
    [04-Dec-2014 03:43:02 UTC] PHP Notice:  Use of undefined constant comment_content - assumed 'comment_content' in /home/user/public_html/wp-content/plugins/anti-spam/anti-spam.php on line 139
    [04-Dec-2014 03:43:02 UTC] PHP Notice:  Use of undefined constant comment_content - assumed 'comment_content' in /home/user/public_html/wp-content/plugins/anti-spam/anti-spam.php on line 144
    [04-Dec-2014 03:43:02 UTC] PHP Notice:  Use of undefined constant comment_content - assumed 'comment_content' in /home/user/public_html/wp-content/plugins/anti-spam/anti-spam.php on line 150
    [04-Dec-2014 03:43:02 UTC] PHP Notice:  Use of undefined constant comment_content - assumed 'comment_content' in /home/user/public_html/wp-content/plugins/anti-spam/anti-spam.php on line 155

    You’re quoting your array keys for the $antispam_settings array, but not the $commentdata array. If you quote your array keys for the latter, these notices will go away. The following page discusses this in detail and how it’s considered good form to do so:
    http://stackoverflow.com/questions/2941169/what-does-the-php-error-message-notice-use-of-undefined-constant-mean

    You just need to do a search and replace and convert the following from this:

    $commentdata[comment_author_url]
    $commentdata[comment_content]

    to that:

    $commentdata['comment_author_url']
    $commentdata['comment_content']

    Then the Anti-Spam plugin won’t log these six lines to debug.log due to PHP thinking those array keys are constants, when they’re not.

    On a production site, I do typically turn on WP_DEBUG logging to file to see what’s going on, although I rarely see plugins log notices. The most common notice is ‘PHP Notice: Undefined index’ but I haven’t yet seen a ‘PHP Notice: Use of undefined constant’ which Anti-spam will now always log in its current incarnation.

    Following are the 6 lines in question and their corrections, although the search and replace above would be more efficient as there are only two keys (comment_author_url and comment_content) that are triggering the error:

    Line 128

    if ( ! empty($commentdata['comment_author_url'])) { // probably spam

    Line 133

    $links_count = substr_count($commentdata['comment_content'], 'http');

    Line 139

    if (strpos($commentdata['comment_content'], '</') !== false) { // probably spam

    Line 144

    $comment_length = strlen($commentdata['comment_content']);

    Line 150

    if (strpos($commentdata['comment_content'], 'rel="nofollow"') !== false) { // probably spam

    Line 155

    if (strpos($commentdata['comment_content'], '[/url]') !== false) { // probably spam

    Plugin Author webvitalii

    (@webvitaly)

    @jumbo: Thank you for your reply.
    Sorry, I missed those quotes.
    Fixed it and updated the plugin.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Notice: Use of undefined constant comment_author_url – assumed "comment_author_u’ is closed to new replies.