qtranslate / qtranslate-xt

qTranslate-XT (eXTended) - reviving qTranslate-X multilingual plugin for WordPress. A new community-driven plugin soon. Built-in modules for WooCommerce, ACF, slugs and others.
GNU General Public License v2.0
553 stars 104 forks source link

PHP error and irrelevant Slugs metabox in custom admin pages #1207

Closed yoancutillas closed 2 years ago

yoancutillas commented 2 years ago

Hello,

The Slugs module causes a PHP error on any admin pages using metaboxes if they are not a WP_Post: qtranslate-xt\modules\slugs\admin\slugs-admin.php line 130

The reason is that the Slugs module assumes that the passed variable $post is a WP_Post object. Of course, a page displaying metaboxes isn't necessarily a WP_Post.

A workaround would be to exit the qts_draw_meta_box() function early if the passed variable isn't a WP_Post. For example, by adding at line 124: if( ! ( is_object( $post ) && ! empty( $post->ID ) ) ) { return; }

A better solution would be to not display the "Slugs per language" metabox at all on irrelevant pages (that is, on pages that are not WP_Post).

spleen1981 commented 2 years ago

good catch, can you try this branch?

yoancutillas commented 2 years ago

Yes it is working, Thank you!