10up / ads-txt

Ads.txt Manager for WordPress: Manage your ads.txt and app-ads.txt files in the WordPress dashboard
https://wordpress.org/plugins/ads-txt/
GNU General Public License v2.0
57 stars 25 forks source link

Fatal error ads-txt on multisite without adminsitrator role #139

Closed renzit closed 1 year ago

renzit commented 1 year ago

Describe the bug

I found a bug while managing a WordPress multisite. I'm using version 1.4.0 and also tested 1.4.2

The functions: function add_adstxt_capabilities() function remove_adstxt_capabilities() {

PHP Fatal error: Uncaught Error: Call to a member function has_cap() on null in /var/www/html/wp-content/plugins/ads-txt/ads-txt.php:93

The issue is that I don't have an administrator role on those sites, only super-admin. I think it will be nice to check if the role exists before operating with it, or even check which roles exist.

Steps to Reproduce

1 Create a wordpress multisite. 2 Create users on site 1 3 Make those users super admin. 4 Create a site as a standalone domain. 5 Trying to access admin on the new created site throw a fatal error due that it doesn't have an administrator.

Screenshots, screen recording, code snippet

No response

Environment information

Wordpress 5.9 ads-txt: Version 1.4.0 and 1.4.2

WordPress information

No response

Code of Conduct