WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 2 months ago

#22805 new enhancement

Add a hook for the live theme preview event

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

Description

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

Change History (11)

comment:1 follow-up: helenyhou17 months ago

  • Component changed from General to Themes

Why do you need one?

comment:2 in reply to: ↑ 1 alexvorn217 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: nacin17 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 17 months ago by nacin (previous) (diff)

comment:4 in reply to: ↑ 3 ; follow-up: alexvorn217 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: nvartolomei16 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.

There is no need to write anything to database at the preview.

Replying to alexvorn2:

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.

Last edited 16 months ago by nvartolomei (previous) (diff)

comment:6 in reply to: ↑ 5 ; follow-up: alexvorn216 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: nvartolomei16 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 alexvorn216 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 alexvorn216 months ago

maybe I will open another one for that...

comment:10 alexvorn215 months ago

  • Keywords needs-patch added

comment:11 nacin2 months ago

  • Component changed from Themes to Appearance
Note: See TracTickets for help on using tickets.