WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Function.php in child theme twentyten (8 posts)

  1. jimii
    Member
    Posted 2 years ago #

    I’m trying to append the code below into a child twentyten theme. It works fine / does its job when in the parent on its own. However when I try to make it work solely in the child theme I cannot get it to provide the proper result - ie the code doesn't do its job of hiding the media library tab. I believe I’m missing something in the proper setup of a function.php in a child theme... If anyone is able to provide any guidance on this I would be grateful. (i can find step by step on css but not on function.php for child)

    function remove_medialibrary_tab($tabs) {
     unset($tabs['library']);
     return $tabs;
     }
     if(!current_user_can(‘update_core’))
    add_filter(‘media_upload_tabs’,'remove_medialibrary_tab’);

    In trying ot solve this myself I’ve reviewed the basic wordpress docs on function.php in a child theme – I understand this does not simply work like style.css in a child theme and further that while its noted as being "plugable" to the parent - Im not skilled enough in php code at present to know how to execute as a plugable command.)

    Any help on this or guidance to an online resource that i can read or adapt would be appreciated. thank you.

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    You have some single curly quotes (‘’)in your code try it with:

    function remove_medialibrary_tab($tabs) {
     unset($tabs['library']);
     return $tabs;
     }
     if(!current_user_can('update_core'))
    add_filter('media_upload_tabs','remove_medialibrary_tab');

    This code will remove the library link when adding new media in the edit/publish post screen.

    Does your parent theme have the exact same function (remove_medialibrary_tab) name?

  3. jimii
    Member
    Posted 2 years ago #

    hello keesiemeiger, thank you very much for your quick reply and help.

    I've switched the code to the 'quote' style you ref above - but as before - i am only able to get it to work when placing the code into the parent theme's function php, but not in the child.

    Correctly as you say - the code is inteded to hide the media library - its going on a multi user site - so uploaders of property pics - only see and have access to their own pics.

    If i understand your question correctly - the parent theme itself doesnt have a function name for this to my knowledge ....?

    The primary removal of the media gallery from the WP admin menu is being done by a Menu Admin plugin. It doesnt however take out / unseat the media library tab in the edit/publish post screen as you reference above - and so thus the addon code to remove that accesss/view space. Is it possible - because the plugin is functioning within the parent theme - the addon code wont work in the child theme? (doesnt seem to make sense to me either)

    Two other bit of information i can throw out; the site is in redevelopment so its on a temp url - but i dont think that would matter.

    Secondly - as it realtes to the child php file - there is littel to no information on the need for preamble information in the file - like setting up a child css. So I've tried it with just the code and also with the full function.php data from the parent. But regardless should it also have the bit of code like the css file @import.... if this makes any sense??

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    http://vudu.me/child - I'm not sure if anything in my article might help you, it's very basic

    funtions.php loads from the parent and child. So, you basically have a functions.php file like this to start in your child

    <?php
    
    // Custom code goes here

    And that's it to start. You wouldn't copy things from parent to child directly for many things - there are exceptions of course

    You just put your own custom code in to your child functions file

    Since you aren't actually trying to override anything out of the parent functions file, I won't elaborate on how to do that here

    I will try to research your issue a bit more.... I just wanted to throw out that bit of info, hoping to clarify how that file works

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    I might be doing the same thing here - but your conditional looks out of whack to me - but I'm far from a pro!

    function remove_medialibrary_tab($tabs) {
        	if ( !current_user_can( 'update_core' ) ) {
        		unset($tabs['library']);
        		return $tabs;
        	}
        }
        add_filter('media_upload_tabs','remove_medialibrary_tab');

    Or the conditional on the actual filter as you have it - what throws me is the lack of curly braces on your original conditional

    function remove_medialibrary_tab($tabs) {
    	unset($tabs['library']);
     	return $tabs;
    	}
    if( !current_user_can('update_core')) {
    	add_filter('media_upload_tabs','remove_medialibrary_tab');
    }

    I honestly am unsure how necessary that might be - I only code based on patterns I'm used to

  6. jimii
    Member
    Posted 2 years ago #

    Thank you both for your efforts and ideas.

    I tried all the suggestions above - in combinations with opening php tage - opening and closing tags - without success.

    Im still sourcing and reading other resources to try and figure this out. If there is anything else i can provide here that might shed some light please let me know. thank you again

  7. jimii
    Member
    Posted 2 years ago #

    Just to let you know that I was unable to get the function.php code edit working in the child theme but have resolved it by inserting the code into a newly create plugin.

    I had never done this before - it sounded like it might be too complex for me to figure out. Long story short - with a basic plugin format I found on a site called brave new code i was able to create a plugin for my site that resolved this issue.

    In hindsight and with review of other tutorials it makes sense, given that functions.php 'acts like a plugin' and - both the original plugin auther and the php code author made reference to plugin options.

    I still don't know specifially why the child theme didnt work but can only guess that in some fashion as a filter / hook it required access to more than just the information in the function.php file of the parent theme. I dont know if this makes sense all - but its all i can surmise logically. Anyway - just a note to advise resolved. thank you.

  8. jimii
    Member
    Posted 2 years ago #

    Just to share that while i resolved this a month ago by creating a plugin - Just today I figured out the actual cause of the code edit being non-responsive in the child theme but working in the parent.

    Had a similar problem today with a function php edit i was trying to make. It would work in parent but not in child. Something finally dawned on me to check the file name extension for functions.php. It was then i noted the child theme file was set-up with function versus functions .. (singular versus plural) a simple spelling issue.

    For anyone else with a similar issue - check the case and spelling - it will save a fair bit of time. :\

Topic Closed

This topic has been closed to new replies.

About this Topic