WordPress.org

Ready to get started?Download WordPress

Forums

Front-end Editor
[resolved] Edit Select Widgets (4 posts)

  1. Scotm
    Member
    Posted 3 years ago #

    This is quite possibly the best WordPress plugin I've ever come across (with kudos to Widget Logic):)

    I've seen examples where you can limit editing to select categories, etc. but is it possible to limit it to select widgets as well? Perhaps by widget title somehow?

    Great work!

  2. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    You can restrict widgets by widget type, widget number, sidebar id or any combination thereof:

    function restrict_widget_editing( $allow, $params ) {
    	extract( $params ); // populates $widget_id and $sidebar_id
    
    	$widget_type = explode( '-', $widget_id );
    	$widget_nr = array_pop( $widget_type );
    	$widget_type = implode( '-', $widget_type );
    
    	if ( 'categories' == $widget_type )
    		return false;
    
    	return $allow;
    }
    add_filter( 'front_end_editor_allow_widget', 'restrict_widget_editing', 10, 2 );
  3. Scotm
    Member
    Posted 3 years ago #

    scribu

    Awesome...but if I understand you widgets can't be excluded by the title you give them? I'm looking for the ability to exclude editing on some instances of Text widgets versus all Text widgets (type), though failing that I guess I could limit it to the sidebar ID where they appear.

    If I was using the above code, how would I exclude "footer-1" as an example of a widget area to exclude or "Text" as an example of excluding Text widgets or "Primary Sidebar" as an example of a sidebar to exclude.

    This is a great feature btw...

    Thx

  4. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    If I was using the above code, how would I exclude "footer-1" as an example of a widget area to exclude or "Text" as an example of excluding Text widgets or "Primary Sidebar" as an example of a sidebar to exclude.

    I don't understand what you mean by "widget area".

    I already explained the information you can use. Beyond that, it's just basic PHP knowledge. One final example:

    To disable editing of all text widgets in the 'primary' sidebar, in the first example, you would replace this:

    if ( 'categories' == $widget_type )
    	return false;

    with this:

    if ( 'text' == $widget_type && 'primary' == $sidebar_id )
    	return false;

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic