• Resolved gopanthers

    (@gopanthers)


    I’m reading a bunch of tutorials about how to add custom profile fields to users’ info. This is just one of several similar approaches. Each tutorial varies slightly but they all say to add code to the functions.php file in my theme.

    When my theme needs updating, will the update automatically write over the custom code I put in that file?

    Side question: Most of these tutorials never tell me to add fields to any database. Does the functions.php just add fields for me if they don’t already exist?

Viewing 10 replies - 1 through 10 (of 10 total)
  • If you update the theme periodically then yes the changes would get overwritten..

    An easy solution would be to keep your own generic plugin, and add functions directly into that file instead (it’ll work just aswell there as in the theme’s functions.php)..

    This is all the code required to create a plugin file..

    <?php
    /*
    Plugin Name: A Name For Your Plugin
    */

    NOTE: There are of course various other pieces of information you can include in the top of the plugin file, but really for personal plugins(with your own code), only the name is required(to make it work – and be able to identify it’s yours).

    As many or as few functions as you like can sit below that code.. so just go ahead and add the above, plus any functions from the tutorials into the file and save it with a php extension. Upload the file to your plugins folder, and activate it like you would any plugin..

    Once it’s active, modify/update the file as often as you like…

    The code will operate perfectly fine this way, and you’ll not lose changes to the code, since it will exist independantly from the theme..

    Thread Starter gopanthers

    (@gopanthers)

    Thanks for the help. Related to this, tutorials often seem to add additional fields to the existing usermeta table (or something like that). Since database data is always personal to each individual blog, I would assume that changes to my database (core tables within my database) should be safe from having additional fields “hacked off” when I update WordPress, right?

    tutorials often seem to add additional fields to the existing usermeta table

    Adding or removing columns in any of the database tables would have a negative impact on upgrading, since the upgrade is expecting a particular structure for these tables.

    There are enough apis in place for users/coders to add there own customizations without any need to modify the database structure. If users must add new database fields, they should be done in an independant table, so the WordPress table structures remain intact.

    Although i do wonder if you’re really referring to modifying database table structures, because i’ve honestly not seen that many tutorials that suggest doing so..

    Thread Starter gopanthers

    (@gopanthers)

    Hmm. Perhaps I’m not understanding them then. The tutorial most linked to seems to be this one.

    https://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields

    I didn’t see it mention where the data was being stored so I just assumed it was adding it to an existing core WordPress table for user info. Is that not what it’s doing?

    And here’s another one. This is a plugin but unless I’m just not understanding it, I thought it was saying that it adds the data to the exisitng WordPress core user table.

    https://vadimk.com/2009/11/29/extra-user-details/

    ————————

    Perhaps this part below the line belongs in a new forum thread since I’m now getting more off from the original topic, but I’ve been pleased from testing a plugin called “Cimy User Extra Fields”. It adds new custom fields for users to fill out but I checked the database and I know it keeps this data in it’s own new tables. Works fine, but I’m worried about long term record keeping outside of mySQL. If all user data was in one big table I could export that table as a CVS and have a spreadsheet backup for people who need it offline. But I just don’t have the skills to recover data stored in two different tables and somehow export the data into one spreadsheet.

    That’s why I’d prefer all the user data in one table, but it sounds like you’re saying that’s highly not recommended from a WordPress standpoint.

    I remember reading Justin’s article before, it uses user meta, which is stored in one of the native WordPress tables wp_user_meta.. there’s no database structure modification throughout the code shown, only input into the database and getting data out, so a perfectly valid and good approach..

    Same with the second article, using user meta, relying on the existing WordPress tables and structure..

    Nothing bad about either approach.. no db changes.. data goes in, data comes out… ??

    Thread Starter gopanthers

    (@gopanthers)

    Thanks for all your help. ??

    @mark / t31os

    Your suggestion for site-wide configuration of single functions.php plugin worked for me . I have a multi-site installation and if I need to configure a css file .I has to modify it per each theme .Could you tell me if I create a single css file and make it activated for site wide and also ability to switch to theme’s css file if necessary ?

    Thanks !

    @@Mark / t31os

    I want to use this customized plugin with new functions for multisite installation .I want some functions activated only for a particular sub-sites and not for some sub-blogs . So I will create 3 to 5 plugins with different functions differentiating with the need of usage . Does it slows down the speed of my main site installation or sub-sites?

    Thanks

    @venug, hi..

    You may wish to try your question on the multisite forum, i’m not an extensive multisite user myself, so unfortunately not equipped to answer your question.

    @mark / t31os
    Thank you Mark ! I will try it there

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘editing the functions.php’ is closed to new replies.