Skip to content

Conversation

@vuckro
Copy link
Contributor

@vuckro vuckro commented Aug 9, 2025

  • Add null checks in UI element output methods
  • Prevent errors when site/membership objects are null
  • Ensures compatibility with Slim SEO plugin that calls output() directly
  • Defensive programming approach for robustness

@vuckro vuckro closed this Aug 9, 2025
@vuckro vuckro reopened this Aug 9, 2025
@vuckro vuckro force-pushed the fix/plugins/slim-seo branch from 79dfc67 to 8e25460 Compare August 9, 2025 18:23
@superdav42
Copy link
Collaborator

What is it about Slim SEO that makes that properties null? Ideally any compatibility code would only be loaded if the Slim SEO plugin was loaded. In this case it does seem to make sense to just have defensive programming. However would it be possible to create get_site() and get_membership() methods to lazy load then objects if they are not already set? Such a pattern should allow output to always behave the same way.

@vuckro
Copy link
Contributor Author

vuckro commented Aug 10, 2025

When Multisite Ultimate shortcodes are used on non-Multisite Ultimate pages, this error appear in Query Monitor when Slim SEO is enabled:

Uncaught Error: Call to a member function get_active_site_url() on null
in inc/ui/class-current-site-element.php:360

10 08 2025

Maybe not the cleanest fix, but it works on my setup.
Let me know if you see any improvements.

@vuckro
Copy link
Contributor Author

vuckro commented Aug 10, 2025

I'm trying to update with the recommendations quickly.

@vuckro
Copy link
Contributor Author

vuckro commented Aug 11, 2025

I just updated the code following your recommendations.

Let me know if everything is correct or if you see any other improvements.

@superdav42
Copy link
Collaborator

Now that I see the problem I think you just need to call this function [wu_element_setup_preview](https://github.com/superdav42/wp-multisite-waas/blob/main/inc/functions/element.php#L18)() in the appropriate action. It seems to be an issue when bricks and slim seo is active. Probably you just need to to setup the preview in an action fired by the bricks plugin when it loads the editor.

See https://github.com/superdav42/wp-multisite-waas/blob/main/inc/compat/class-elementor-compat.php for how a class is setup to fix a similar problem in elementor. Particularly this line:

		add_action('elementor/widget/shortcode/skins_init', [$this, 'maybe_setup_preview']);

If the preview is setup correctly none of the other code changes in the other files will be necessary and they will show appropriate preview data. You should make a single class like Bricks_Compat which will keep all the code in once place.

@vuckro vuckro force-pushed the fix/plugins/slim-seo branch 4 times, most recently from 02dedce to a44b8ac Compare August 12, 2025 14:34
Add null checks in UI element output() methods to prevent errors when
Slim SEO processes shortcodes before WP Ultimo is fully initialized.

This fixes the 'Call to a member function get_active_site_url() on null'
error by returning empty string instead of attempting to access null objects.

Changes:
- Add defensive checks in 5 UI elements output() methods
- Return empty string when site/membership objects are null
- Prevents fatal errors during Slim SEO's shortcode processing

Files modified:
- inc/ui/class-account-summary-element.php
- inc/ui/class-billing-info-element.php
- inc/ui/class-current-site-element.php
- inc/ui/class-invoices-element.php
- inc/ui/class-limits-element.php
@vuckro vuckro force-pushed the fix/plugins/slim-seo branch from a44b8ac to de3dca1 Compare August 12, 2025 14:38
@vuckro
Copy link
Contributor Author

vuckro commented Aug 12, 2025

Thanks for the feedback and explanations.

I don't think Bricks is the problem (same error with only Slim SEO active + Multisite Ultimate).

Also, the approach with a compatibility class causes problems in my tests.
I'm going to revert to the original defensive changes, which were safer.

Hoping to hear back on this slim seo issue.

Copy link
Collaborator

@superdav42 superdav42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is simple enough to mitigate the bug that's in seo slim. I'm adding these _doing_it_wrong so it's obvious to a developer that something isn't working right, otherwise it may take some extensive troubleshooting to figure why the output is blank

@superdav42 superdav42 merged commit aaf4475 into Multisite-Ultimate:main Aug 13, 2025
18 checks passed
@vuckro
Copy link
Contributor Author

vuckro commented Aug 21, 2025

@superdav42 It seems that the merge did not completely resolve the issue with my first code proposal:

22 08 2025

Can you take a look? I can create a temporary site if necessary.

Also following this issue #232, but no response for now

vuckro added a commit to vuckro/multisite-ultimate that referenced this pull request Aug 21, 2025
vuckro added a commit to vuckro/multisite-ultimate that referenced this pull request Aug 22, 2025
…lements

This addresses David's feedback in PR Multisite-Ultimate#159 to include the version parameter
in all _doing_it_wrong() calls for better debugging when Slim SEO processes
shortcodes before WP Ultimo is fully initialized.
superdav42 pushed a commit that referenced this pull request Aug 26, 2025
…lements (#179)

This addresses David's feedback in PR #159 to include the version parameter
in all _doing_it_wrong() calls for better debugging when Slim SEO processes
shortcodes before WP Ultimo is fully initialized.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants