soflyy / oxygen-bugs-and-features

Bug Reports & Feature Requests for Oxygen
https://oxygenbuilder.com/
315 stars 29 forks source link

BUG ct_disable_theme_load when using editorScript with Rank Math #3527

Closed javierruizjimenez closed 5 months ago

javierruizjimenez commented 5 months ago

Sandbox

Not available as qsandbox.org uses Wordpress version: 6.4.2, the bug only happens in WP 6.5.2

Bug description

Using the popular SEO tool Rank Math and Oxygen, WP.

Rank Math includes a Table Of Contents (TOC) block for he Gutennberg editor.

Rank Math has identified the problem at OXYGEN code: plugins/oxygen/component-framework/component-init.php

With the latest Wordpress update, the TOC is not available anymore.

Disabling Oxygen fixes the problem.

With Oxygen enabled I can see that 3 URLs returns a 404 not-found:

Example: https://www.domain_name.com/wp-content/themes/oxygen-is-not-a-theme/home/itwl_pro_001/public_html/wp-content/plugins/seo-by-rank-math/includes/modules/schema/blocks/toc/assets/css/toc.css?ver=6.5.2

It is a virtual URL, removing "wp-content/themes/oxygen-is-not-a-theme/home/itwl_pro_001/public_html/" and using the "/wp-content/plugins/seo-by-rank-math/..." returns the right files.

Example: https://www.domain_name.com/wp-content/plugins/seo-by-rank-math/includes/modules/schema/blocks/toc/assets/css/toc.css?ver=6.5.2

Affected files:

Rank Math has been contacted and they provided the following explanation:

Pratik Deshmukh (https://support.rankmath.com/ticket/your-site-doesnt-include-support-for-the-table-of-contents/#post-783396) Hello, We were able to reproduce this issue on our setup and identified the source of the problem as originating from the Oxygen plugin. In the plugins/oxygen/component-framework/component-init.php file, the plugin has used the template_directory filter, which returns a fake value. Here is the code:


function ct_disable_theme_load( $stylesheet_dir ) {
// disable theme entirely for now
return "fake";

if ( isset( $_GET["has_oxygen_template"] ) && $_GET["has_oxygen_template"] ) {
    return $stylesheet_dir;
}

if ( defined("HAS_OXYGEN_TEMPLATE") && HAS_OXYGEN_TEMPLATE ) {
    return "";
}
else {
    return $stylesheet_dir;
}

}


> // Need to remove for both parent and child themes
`add_filter("template_directory", "ct_disable_theme_load", 1, 1);`
> Due to this code, the path of the block script registered using the editorScript property in the block.json file is being changed to http://rankmath.local/wp-content/themes/oxygen-is-not-a-theme/Local%20Sites/rankmath/app/public/wp-content/plugins/seo-by-rank-math/includes/modules/schema/blocks/toc/assets/js/index.js?ver=1.0.217-beta, resulting in a 404 error. You will also see this error in the browser’s console on your site.
> An example of the editorScript property can be found here: https://github.com/rankmath/seo-by-rank-math/blob/master/includes/modules/schema/blocks/toc/block.json#L9-L10
> 
> I believe this issue is not specific to the Rank Math plugin and could potentially cause problems with all plugins that use block.json to register blocks.
> 
> Please forward this to the Oxygen Builder team so they can take a look at this issue. We will also try to get in touch with them.
> Hope that helps.

### Steps to reproduce the behavior:

1. Install Wordpress 6.5.2 (latests) 
2. Install Oxygen  latests 
3. Install Rank Math latests 
4. Use Gutemberg editor to edit post (hello world is fine). 
5. Open Developer Console, Network view.
6. Try to insert Rank Math Table of Contents Block under Rank Math (it is not available)
7. Developer console shows 3 URLs returning a 404 not-found
Kpudlo commented 5 months ago

Thank you for the report. Marking this as a duplicate of https://github.com/soflyy/oxygen-bugs-and-features/issues/3525