paulmassen / grav-plugin-seo

Manage your site’s meta tags for display in search engine results or social media networks. Create and manage json-ld microdata. Includes an easy-to-use live preview feature.
MIT License
84 stars 21 forks source link

Call to a member function media() on null #79

Open tranduyhung opened 5 years ago

tranduyhung commented 5 years ago

In seoGetimage function in seo.php, line 78 creates the error Call to a member function media() on null if the page of image is not found:

$imgarray = $this->grav['page']->find($fixedurl)->media()->images();

To fix this, we need to check if the page exists or not first, something like this:

$page = $this->grav['page']->find($fixedurl);

if (!$page)
    return [
        'url'       => '',
        'width'     => '',
        'height'    => '',
    ];

$imgarray = $page->media()->images();

Because I am not familiar with this plugin so I don't know if returning empty URL, width and height would effect somewhere else or not, so I don't submit a pull request for this, at least with this simple fix the error is gone and the site's running again.

danjames68 commented 4 years ago

I also get this error when using the microdata section - if I turn the microdata off the page renders properly, if I turn any of them on the page throws an empty $imgarray error. I've just discovered this, will investigate over the next days.