WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 5 months ago

#22805 new enhancement

Add a hook for the live theme preview event

Reported by: alexvorn2 Owned by:
Priority: normal Milestone: Awaiting Review
Component: Themes Version: 3.4.2
Severity: normal Keywords: needs-patch
Cc:

Description

We have a hook for theme activation and deactivation, but for the theme live preview - not...

Change History (10)

comment:1 follow-up: helenyhou6 months ago

  • Component changed from General to Themes

Why do you need one?

comment:2 in reply to: ↑ 1 alexvorn26 months ago

Replying to helenyhou:

Why do you need one?

To save for example theme settings before the live preview, so theme will show exactly as after the activation.

comment:3 follow-up: nacin6 months ago

To save for example theme settings before the live preview, so theme will show exactly as after the activation.

A live preview shouldn't save *anything* to the database. Can you be more specific?

Last edited 6 months ago by nacin (previous) (diff)

comment:4 in reply to: ↑ 3 ; follow-up: alexvorn26 months ago

Replying to nacin:

To save for example theme settings before the live preview, so theme will show exactly as after the activation.

A live preview shouldn't save *anything* to the database. Can you be more specific?

admin panel settings of the theme:

  1. style css file
  2. logo image
  3. show excerpt in the home page - yes/no

etc..
so I use after_switch_theme action to save all this stuff, but on live preview event settings are not saved because this action is not called.

I think that after such hook will be available a lot of developers will start to develop themes in more professional way, because now I think some of them just use update_option function to insert a data for knowing if settings were saved or not.

comment:5 in reply to: ↑ 4 ; follow-up: nvartolomei6 months ago

You just have to look if option exists, if not, just use default option without having to write database and then to read it again to use option.

Replying to alexvorn2:

Replying to nacin:

To save for example theme settings before the live preview, so theme will show exactly as after the activation.

A live preview shouldn't save *anything* to the database. Can you be more specific?

admin panel settings of the theme:

  1. style css file
  2. logo image
  3. show excerpt in the home page - yes/no

etc..
so I use after_switch_theme action to save all this stuff, but on live preview event settings are not saved because this action is not called.

I think that after such hook will be available a lot of developers will start to develop themes in more professional way, because now I think some of them just use update_option function to insert a data for knowing if settings were saved or not.

Version 0, edited 6 months ago by nvartolomei (next)

comment:6 in reply to: ↑ 5 ; follow-up: alexvorn26 months ago

Replying to nvartolomei:

So if we have activation and deactivation then we should have a life preview hook too.
Theme settings will be saved on theme activation or on theme live preview...
To check every time when the site loads if the settings were saved or not does not look very nice.

For me for example this is one thing that I think just is missed in the current WordPress build.

It would be great too to have a is_live_preview() function to know if the current state of theme is just a preview for reducing the files and load time but this is already for another ticket.

comment:7 in reply to: ↑ 6 ; follow-up: nvartolomei6 months ago

Replying to alexvorn2:

Useless, reread my answer, by the way look at this get_option.

How do you want to minimize load time for preview if user still wants to see the theme in action?

comment:8 in reply to: ↑ 7 alexvorn26 months ago

Replying to nvartolomei:

Replying to alexvorn2:
How do you want to minimize load time for preview if user still wants to see the theme in action?

Sorry, this question is not related to this ticket.

comment:9 alexvorn26 months ago

maybe I will open another one for that...

comment:10 alexvorn25 months ago

  • Keywords needs-patch added
Note: See TracTickets for help on using tickets.