• Resolved Bryan Willis

    (@codecandid)


    I changed the function to show the broken shortcodes to the admin/developer. Around line 70 I changed the function to the following and it appears to be working fine although I don’t know if it’s the proper place for it.

    public static function register_filters() {
    		$filters = (array) apply_filters( 'hide_broken_shortcodes_filters', array( 'the_content', 'widget_text',  ) );
    
    		foreach ( $filters as $filter )
    			if( !current_user_can('administrator') ) {
    			add_filter( $filter, array( __CLASS__, 'do_shortcode' ), 1001 );
    	}
    }

    Also is there a bettwer way to do this like a remove_filter or remove_action I could use instead so I don’t have to change the plugin itself? I saw on your faq’s how to remove individual shortcodes, but my goal is to hide the shortcodes for select people. I have a hell of a time trying to understand classes. The codex says you have to do something like this when the plugin is in a class:

    global $my_class;
    remove_filter( 'the_content', array($my_class, 'class_filter_function') );

    I can’t figure out what to change $myclass and class_filter_function to and maybe I have to add a priority since this gets called late.

    https://www.ads-software.com/plugins/hide-broken-shortcodes/

Viewing 1 replies (of 1 total)
  • Plugin Author Scott Reilly

    (@coffee2code)

    WordPress & Plugin Developer

    @codecandid:

    Here’s one way to do it (placing the following in your theme’s functions.php or a mu-plugin:

    function show_broken_shortcodes_to_admins( $default, $shortcode, $content ) {
            // For administrators, show the unhandled shortcode
            if ( current_user_can( 'administrator' ) )
                    return $content[0];
            // Otherwise, let the plugin do its thing
            return $default;
    }
    add_filter( 'hide_broken_shortcode', 'show_broken_shortcodes_to_admins', 10, 3 );

    Let me know if you have any questions about it.

Viewing 1 replies (of 1 total)
  • The topic ‘Per user filters’ is closed to new replies.