WordPress.org

Ready to get started?Download WordPress

Forums

Add Meta Tags
[resolved] Function get_video_url() is referencing non-existent array offset. (4 posts)

  1. Dan Rossiter
    Member
    Posted 1 year ago #

    When I run with debugging, I'm getting two Notices from amt_get_video_url():

    Notice: Undefined offset: 1 in /path/to/wp-content/plugins/add-meta-tags/add-meta-tags.php on line 842
    
    Notice: Undefined offset: 1 in /path/to/wp-content/plugins/add-meta-tags/add-meta-tags.php on line 850

    If you just check whether any matches exist before making assignments with $matches[1], this should be resolved. Here's one option for a fix:

    function amt_get_video_url() {
        global $post;
    
        // Youtube
        $pattern = '#youtube.com/watch\?v=([-|~_0-9A-Za-z]+)#';
        if( preg_match($pattern, $post->post_content, $matches) ){
            return 'http://youtube.com/v/' . $matches[1];
        }
    
        // Vimeo
        $pattern = '#vimeo.com/([-|~_0-9A-Za-z]+)#';
        if( preg_match($pattern, $post->post_content, $matches) ){
            return 'http://vimeo.com/couchmode/' . $matches[1];
        }
    
        return '';
    }

    All the best!
    -Dan

    http://wordpress.org/extend/plugins/add-meta-tags/

  2. George Notaras
    Member
    Plugin Author

    Posted 1 year ago #

    @Dan: Thank you for your feedback. Will be fixed in 2.1.0.

  3. George Notaras
    Member
    Plugin Author

    Posted 1 year ago #

    Fixed in 2.1.0 using provided code. Thanks again.

  4. Dan Rossiter
    Member
    Posted 1 year ago #

    Thanks, George! Great plugin, btw! Definitely a SEO must-have!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic