$widget_args ); $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); extract( $widget_args, EXTR_SKIP ); $options = get_option('multi_widget_polls'); if ( !isset($options[$number]) ) return false; $title = apply_filters('widget_title', $options[$number]['title']); $currentpoll = $options[$number]['currentpoll']; $multiplepolls = $options[$number]['multiplepolls']; $archive_show = $options[$number]['archive_show']; // No poll ? if(intval(get_option('poll_currentpoll')) == -1) { return false; } // Random Poll if( intval($currentpoll) == -2 ) { $poll_id = intval($wpdb->get_var("SELECT pollq_id FROM $wpdb->pollsq WHERE pollq_active = 1 ORDER BY RAND() LIMIT 1")); // Current Poll ID Is Not Specified } elseif( intval($currentpoll) == 0 ) { // Get Lastest Poll ID $poll_id = intval(get_option('poll_latestpoll')); } else { // Get Current Poll ID $poll_id = $currentpoll; } if (function_exists('vote_poll') && !in_pollarchive()) { echo $before_widget; echo $before_title . $title . $after_title; if( intval($currentpoll) == -3 ) { $multiplepolls = explode(',', $multiplepolls); foreach( (array) $multiplepolls as $multiplepoll ) { get_poll($multiplepoll); } } else { get_poll( $poll_id ); } // Fake option if archive me be show if ( $archive_show == '1' ) { add_filter( 'pre_option_poll_archive_show', 'allow_poll_archive_show' ); } display_polls_archive_link(); remove_filter( 'pre_option_poll_archive_show', 'allow_poll_archive_show' ); echo $after_widget; } return true; } function allow_poll_archive_show( $flag = '' ) { return true; } ### Function: Multi WP-Polls Widget Options function multi_widget_polls_options( $widget_args ) { global $wpdb; global $wp_registered_widgets; static $updated = false; if ( is_numeric($widget_args) ) $widget_args = array( 'number' => $widget_args ); $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); extract( $widget_args, EXTR_SKIP ); $options = get_option('multi_widget_polls'); if ( !is_array($options) ) $options = array(); if ( !$updated && !empty($_POST['sidebar']) ) { $sidebar = (string) $_POST['sidebar']; $sidebars_widgets = wp_get_sidebars_widgets(); if ( isset($sidebars_widgets[$sidebar]) ) $this_sidebar =& $sidebars_widgets[$sidebar]; else $this_sidebar = array(); foreach ( (array) $this_sidebar as $_widget_id ) { if ( 'multi_widget_polls' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) { $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number']; if ( !in_array( "poll-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed. unset($options[$widget_number]); } } foreach ( (array) $_POST['widget-poll'] as $widget_number => $widget_poll ) { if ( !isset($widget_poll['title']) && isset($options[$widget_number]) ) // user clicked cancel continue; $title = strip_tags(stripslashes($widget_poll['title'])); $currentpoll = intval($widget_poll['currentpoll']); $archive_show = intval($widget_poll['archive_show']); if( is_array($widget_poll['multiplepolls']) ) { $multiplepolls = implode( ',', $widget_poll['multiplepolls'] ); } else { $multiplepolls = $widget_poll['multiplepolls']; } $options[$widget_number] = compact( 'title', 'currentpoll', 'archive_show', 'multiplepolls' ); } update_option('multi_widget_polls', $options); $updated = true; } if ( -1 == $number ) { $title = __('Polls', 'wp-polls'); $currentpoll = ''; $archive_show = ''; $multiplepolls = ''; $number = '%i%'; } else { $title = attribute_escape($options[$number]['title']); $currentpoll = intval($options[$number]['currentpoll']); $archive_show = intval($options[$number]['archive_show']); $multiplepolls = $options[$number]['multiplepolls']; } // CSS if( $currentpoll == -3 ) { $display = 'display: block;'; $disabled = ''; } else { $display = 'display: none;'; $disabled = 'disabled="disabled"'; } ?>
'widget_poll', 'description' => __('Display a poll (multi-widget).')); $control_ops = array('width' => 400, 'height' => 300, 'id_base' => 'poll'); $name = __('Poll'); $id = false; foreach ( (array) array_keys($options) as $o ) { // Old widgets can have null values for some reason if ( !isset($options[$o]['title']) ) continue; $id = "poll-$o"; // Never never never translate an id wp_register_sidebar_widget($id, $name, 'multi_widget_polls', $widget_ops, array( 'number' => $o )); wp_register_widget_control($id, $name, 'multi_widget_polls_options', $control_ops, array( 'number' => $o )); } // If there are none, we register the widget's existance with a generic template if ( !$id ) { wp_register_sidebar_widget( 'poll-1', $name, 'multi_widget_polls', $widget_ops, array( 'number' => -1 ) ); wp_register_widget_control( 'poll-1', $name, 'multi_widget_polls_options', $control_ops, array( 'number' => -1 ) ); } } multi_widget_poll_register(); } ### Function: Load The Multi WP-Polls Widget add_action('plugins_loaded', 'multi_widget_polls_init'); ?>