warning template-functions.php

hello
I have made modifications in the file template-functions.php, since in the admin there is a text asking to execute the installation (setup)....
Why am i seeing this and what should i do? this is kind of scary as i do not want to re-install anything...
thanks
Pat

Comments

  • fretzl Administrator, Developer
    You're getting that message because a core file has been changed.
    It is strongly recommended not to modify any file in the `zp-core` folder!

    If you want to change a function, copy and rename the function and put it into a file called `functions.php` in your theme folder.
    Then you can call your new function anywhere you like in your theme.

    EDIT
    In case you didn't know, Zenphoto will detect if there is a `functions.php` file present in your theme folder.
    There is no need to "include" it in your theme pages.
  • acrylian Administrator, Developer
    Or create a plugin.
  • ok, so i should put the original file back where it belongs and copy the modified functions in functions.php of my theme but should i delete them from the original or leave them without touching anything?
  • acrylian Administrator, Developer
    Yes. I think I advised that already on some of your other topics. If you modify core files you have to do it on every Zenphoto update and you may break or change functionality so that we may have problems supporting here since we think of the way it was originally.

    It is also recommend in the theming tutorial. You also should make a copy of the theme under a new name for the same reason. Of course you can never be kept from some maintenaince if things change over time.
  • fretzl Administrator, Developer
    but should i delete them from the original or leave them without touching anything
    Simply copy and rename the functions you are going to change.
    Leave the original file (i.e. template-function.php) unchanged.
  • sorry i don't get what you say. Copy and RENAME the functions I have changed in MY file functions.php?

    you mean, i should copy the modified function under another name? but this imply to modify every single file where the function is called !
    I have no idea how many instances i should modify or where they are called !
  • fretzl Administrator, Developer
    Sorry if I wasn't clear.

    1) Copy the function you want to modify
    (in your case one of the functions in `template-function.php`)

    2) Paste the function in a file called `functions.php` (located in your theme folder)

    3) Rename the pasted function.(in `functions.php`)
    Otherwise you will get conflicts with the original function
    in `template-function.php`.

    4) Do whatever you like with it.
  • acrylian Administrator, Developer
    I think you really need to learn some coding basics before you start doing these things. You cannot have two functions with the same name so you have to rename your duplicate.

    You NEVER should modify core functions. That are all functions that belong to Zenphoto and are in the file in /zp-core. You can do that on your own risk of course. First, if you do that and you get problems you are on your own as we alway will refer to the original behaviour. Second, you will have to do this on every Zenphoto update. Similar of course for plugins.

    So instead you copy the function in question, rename it (so printRandomImage() would be something like printMyRandomImages()), place it in your theme functions.php (or your own custom plugin) and modify it to your liking. Then you use that function on your theme instead the original. And yes of course you need to replace all usages if you want to use your own function. In any case you have to maintain your changes since things can change on updates, too.

    Edit: Fretz was quicker and shorter ;-)
  • I am not familiar with your script doesn't mean i am unable to do basic coding.... I work with Prestashop after over 9 years with OScommerce, in Prestashop there is a similar system to overwrite functions/classes etc. BUT there is no need to rename anything.

    That's why i was suprised.
  • acrylian Administrator, Developer
    I am sorry, I naturally don't know your background. The functions we recently talked about on your other topics are from template-functions.php and not part of a class as you can see on the file itself, so if renaming here is necessary if you copy one to customize.

    You can of course also create your own classes as wrappers or maybe use namespaces in your theme functions.php then you don't need to rename the functions itself. But still you need to separate them from the originals.
Sign In or Register to comment.