WordPress.org

Forums

Code Snippets
[resolved] Snippet doesn't work fully (6 posts)

  1. GermanKiwi
    Member
    Posted 1 year ago #

    Hi, I'm using this plugin along with the Genesis Framework theme, and a Genesis child theme that has its own functions.php funtionality. I prefer to use Code Snippets however.

    I've encountered something odd with one snippet of code though - see below. When I add this code to my theme's own functions.php, it works perfectly (it removes all of the mentioned profile fields from the User profile page).

    But if I remove it from my theme's functions.php and add it to Code Snippets instead, it only removes the AIM, YIM and Jabber fields, but does not remove the Google+ or Twitter fields. I have no idea why. Can anyone offer a reason?

    Here's the code:

    function hide_profile_fields( $contactmethods ) {
    	unset($contactmethods['aim']);
    	unset($contactmethods['yim']);
    	unset($contactmethods['jabber']);
    	unset($contactmethods['googleplus']);
    	unset($contactmethods['twitter']);
    	return $contactmethods;
    }
    add_filter('user_contactmethods','hide_profile_fields',10,1);

    http://wordpress.org/plugins/code-snippets/

  2. Shea Bunge
    Member
    Plugin Author

    Posted 1 year ago #

    I have fiddled around with your snippet and found that you can get it working if you increase the filter priority. Like:

    add_filter( 'user_contactmethods', 'hide_profile_fields', 999, 1 );

    I think that this has to do with how snippets are executed much earlier than functions.php files.

  3. GermanKiwi
    Member
    Posted 1 year ago #

    Thanks - that's done the trick nicely!

  4. GermanKiwi
    Member
    Posted 1 year ago #

    Actually there's one other snippet that I'm having trouble with - maybe you can help too. I think it might also be related to priority, but I'm not sure how to change that in this case, because it's using the "add_editor_style" function:

    add_editor_style( dynamik_get_stylesheet_location('url') . 'genesis-column-classes.css' );

    I have this currently in my theme's functions.php file but I'd like to move it to a snippet. As you can see, it looks like it is a theme-specific function because it references "dynamik" which is the name of my Genesis child theme.

    My guess is that this snippet runs before WordPress has been informed of the path that "dynamik_get_stylesheet_location" equates to.

    Any ideas?

  5. Shea Bunge
    Member
    Plugin Author

    Posted 1 year ago #

    Placing all of the code inside a function hooked to the init action. This action runs after all of the plugins and the theme has loaded

    add_action( 'init', function() {
        add_editor_style( dynamik_get_stylesheet_location('url') . 'genesis-column-classes.css' );
    });
  6. GermanKiwi
    Member
    Posted 1 year ago #

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.