Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

largo_get_active_homepage_layout does not check whether the layout exists #1823

Open
benlk opened this issue Oct 18, 2019 · 0 comments
Open
Labels

Comments

@benlk
Copy link
Collaborator

benlk commented Oct 18, 2019

Largo stores the homepage layout chosen as a string that is the name of the homepage layout class, which implements Homepage. This string is stored in the options framework, and is fetched by a dedicated function:

https://github.com/INN/largo/blob/512da701664b329f2f92244bbe54880a6e146431/homepages/homepage.php#L83-L88

This layout string is passed to the function that attempts to render the layout:

https://github.com/INN/largo/blob/f50df16e9e06fb9402802e2f1ce76ce058d26d76/home.php#L26-L35

largo_render_homepage_layout has no check to see whether the class exists:

https://github.com/INN/largo/blob/c41d8519370b48a6e53ce36b3b516d3e54e39d66/homepages/homepage.php#L75-L81

If that string doesn't correspond to a class in the current scope, the homepage of a site will fail to render.

Fatal error: Uncaught Error: Class 'CityLimits' not found in /Users/blk/sites/citylimits/wp-content/themes/Largo/homepages/homepage.php:79

Stack trace:
#0 /Users/user/sites/example/wp-content/themes/Largo/home.php(35): largo_render_homepage_layout('ExampleHomepage')
#1 /Users/user/sites/example/wp-includes/template-loader.php(78): include('/Users/blk/site...')
#2 /Users/user/sites/example/wp-blog-header.php(19): require_once('/Users/blk/site...')
#3 /Users/user/sites/example/index.php(17): require('/Users/blk/site...')
#4 /Users/user/.composer/vendor/laravel/valet/server.php(158): require('/Users/blk/site...')
#5 {main} thrown in /Users/user/sites/example/wp-content/themes/Largo/homepages/homepage.php on line 79

We can fix this by:

  • making sure that all "what is the homepage class" questions use the largo_get_active_homepage_layout function
  • have largo_get_active_homepage_layout test whether that string is a class that exists
  • have largo_get_active_homepage_layout return an error or debug log output when the class does not exist

Marking this as priority: low because this has only really been problem when switching back and forth between feature branches of child themes that add or remove homepage layouts, and it only breaks the homepage. Sites experiencing this problem can still get into their theme options and change the layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant