-
Notifications
You must be signed in to change notification settings - Fork 801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Widget visibility: Add support for old-style single widgets #21
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Props @westonruter For more details, view the original ticket: http://plugins.trac.wordpress.org/ticket/1979
@cfinke -- thoughts? |
@jeherve do you have access to WPML or know of another plugin/widget that caused that notice to test against? |
I reproduced the issue by creating an old single widget, like so: add_action("widgets_init", array('Widget_name', 'register'));
register_activation_hook( __FILE__, array('Widget_name', 'activate'));
register_deactivation_hook( __FILE__, array('Widget_name', 'deactivate'));
class Widget_name {
function activate(){
$data = array( 'option1' => 'Default value' ,'option2' => 55);
if ( ! get_option('widget_name')){
add_option('widget_name' , $data);
} else {
update_option('widget_name' , $data);
}
}
function deactivate(){
delete_option('widget_name');
}
function control(){
$data = get_option('widget_name');
?>
<p><label>Option 1<input name="widget_name_option1"
type="text" value="<?php echo $data['option1']; ?>" /></label></p>
<p><label>Option 2<input name="widget_name_option2"
type="text" value="<?php echo $data['option2']; ?>" /></label></p>
<?php
if (isset($_POST['widget_name_option1'])){
$data['option1'] = attribute_escape($_POST['widget_name_option1']);
$data['option2'] = attribute_escape($_POST['widget_name_option2']);
update_option('widget_name', $data);
}
}
function widget($args){
echo $args['before_widget'];
echo $args['before_title'] . 'Your widget title' . $args['after_title'];
echo 'I am your widget';
echo $args['after_widget'];
}
function register(){
wp_register_sidebar_widget( 'my_widget_id', 'Widget name', array('Widget_name', 'widget'));
wp_register_widget_control( 'my_widget_id', 'Widget name', array('Widget_name', 'control'));
}
} |
ghost
assigned lezama
Jan 15, 2014
lezama
added a commit
that referenced
this pull request
Jan 15, 2014
Widget visibility: Add support for old-style single widgets
FYI, This breaks widgets that have no settings. Working off the example widget above:
The widget doesn't render when added to a sidebar. |
I'll revert. |
Simple fix:
|
kraftbj
pushed a commit
that referenced
this pull request
Jan 12, 2021
Avoid errors when the plugin is installed manually.
jeherve
added a commit
that referenced
this pull request
Jun 18, 2021
Merged
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Props @westonruter
Fixes the following notice:
Undefined offset: 1 at /jetpack/modules/widget-visibility/widget-conditions.php line 251
This is the line that is erroring
list( $basename, $suffix ) = explode( "-", $widget_id, 2 );
The problem is that it assumes the a -number on the end of the widget name
This is not safe as you can widget names like:
icl_lang_sel_widget
recent-comments-2
For more details, view the original ticket:
http://plugins.trac.wordpress.org/ticket/1979