theme's functions.php exectuded during setup

vincent3569 Member, Translator

hi,

it seems that my theme's functions.php file is executed during setup process.

and in fact, I can see 'Theme setup:' during setup process and I was thinking only themeoptions.php was running during this process .

can you explain what is running during setup process, especcilally about themes (selected or notin admin) ?

is it depending of OFFSET_PATH value used in my functions.php file?

which value of OFFSET_PATH should I use in functions.php to use it only when my theme is used in front end ?

Comments

  • vincent3569 Member, Translator
    edited November 2017

    to give an example:

    I have this lines in my functions.php :

    if (!OFFSET_PATH) {
        // override some options to avoid conflits
        setOption('comment_form_toggle', false, true);
        setOption('comment_form_pagination', false, true);
    
        // disable some unsupported plugins to avoid loading of unnecessary scripts
        enableExtension('colorbox_js', 0, true);
        enableExtension('slideshow', 0, true);
    }
    

    colorbox and slideshow plugin are disabled during setup process.
    I only want to disabled it when my theme is used in front end.

  • acrylian Administrator, Developer
    edited November 2017

    Simple answer: Themes and their functions are technically also kind of plugins. They are run/loaded on Setup (2nd page) to see if they are valid.

    OFFSET_PATH is not a true/false constant and not meant for exact backend or frontend checks (the planned major release will have something for this). It rather contains a value of the location of a file:
    1 = within /zp-core/ (this is what backend pages set)
    3 = within /plugins/
    4 = within /themes/
    (don't remember offhand if there is 2 and what it means)

    A theme's functions.php is otherwise loaded on frontend for the current theme only outside setup which is quite a special context.

    IMHO a theme should or could enable plugins it needs but it should not disable them itself. You might have a customized theme version that wants them. That should be left to the user.

  • vincent3569 Member, Translator

    thanks for the answer.
    So is there a way to not execute functions.php during setup process but only on Front End ?

  • acrylian Administrator, Developer

    No, but I don't really understand what the issue is with this. It's just on setup. All that happens is that the options are already set. Once you enable a different theme it can override these again. Actual plugins are loaded after the theme functions.php.

  • vincent3569 Member, Translator

    I wish to disable some unsupported plugins (in my theme) to avoid loading of unnecessary scripts (CSS and JS).

    but I understand that is the responsability of admin to right configure its own website...

  • acrylian Administrator, Developer
    edited November 2017

    I do understand what you want to do. But your theme can do it like you do. It is really not a problem if things are loaded while setup runs. This is outside of the actual frontend anyway.

    the responsability of admin to right configure its own website...

    Exactly ;-) He even might have modified your theme so he wants these plugins.

  • The proper way to disable things you don't want loaded in a theme is to do so "temporarily." That is reset the persistent parameter. You can do this in your functions.php script and the plugin will not load.

    Permanently disabling things in a Theme would be considered not playing nicely, in my opinion. You really should let the site admin decide if he wants a feature or not. But if your theme must disable something because of its design, do it so the change is not persistent.

  • vincent3569 Member, Translator
    edited December 2017

    I have tests with temporarily disable plugins in functions.php.

    And as far I can test, I can't use enableExtension('colorbox_js', 0, true/false); in functions.php because:
    - if I set true, functions.php is running during setup process and the matter is the same
    - if I set false, zp_apply_filter('theme_head'); doesn't care of this temporary value and apply css and js even if plugin is temporarily disabled.

    So I have non choice: I will do some cleanup in my themeoptions.php.

  • acrylian Administrator, Developer

    I really have to agree that it is the job of the site admin to only enable what he needs to. You really can't do everything for him…

  • vincent3569 Member, Translator

    OK you are right, I will suppress this code

    but, according to me, zenphoto should separate 2 things :

    • configuration of the theme (in themeoptions.php)
    • Front End usability of the theme (in functions.php)

    in other words, functions.php should only called "by the front-end", and not by "the back-end".

    I would be more clear and simple like that.

  • acrylian Administrator, Developer
    edited December 2017

    Sorry, you are really seeing an issue where there is none. Again, setup loads the functions.php of any theme to validate as it does with eveyr plugin. Setup is not the backend. A theme's functions.php is not direclty used on the backend but since it is kind of a plugin it may very well containt filter calls or functions that are used within the theme options.

    Sorry, i will be closing this topic.

Sign In or Register to comment.