Ejemplo n.º 1
0
 function form($instance)
 {
     // default values
     $instance = wp_parse_args((array) $instance, array_merge(array('title' => ''), PLL_Switcher::get_switcher_options('widget', 'default')));
     // title
     $title = sprintf('<p><label for="%1$s">%2$s</label><input class="widefat" id="%1$s" name="%3$s" type="text" value="%4$s" /></p>', $this->get_field_id('title'), __('Title:', 'polylang'), $this->get_field_name('title'), esc_attr($instance['title']));
     $fields = '';
     foreach (PLL_Switcher::get_switcher_options('widget') as $key => $str) {
         $fields .= sprintf('<div class = "%5$s" %6$s><input type="checkbox" class="checkbox" id="%1$s" name="%2$s" %3$s/> <label for="%1$s">%4$s</label></div>', $this->get_field_id($key), $this->get_field_name($key), $instance[$key] ? 'checked="checked"' : '', esc_html($str), 'dropdown' == $key ? '' : 'no-dropdown-' . $this->id, 'dropdown' == $key || empty($instance['dropdown']) ? '' : 'style="display:none;"');
     }
     echo $title . '<p>' . $fields . '</p>';
     // FIXME echoing script in form is not very clean
     // but it does not work if enqueued properly :
     // clicking save on a widget makes this code unreachable for the just saved widget (?!)
     $this->admin_print_script();
 }
Ejemplo n.º 2
0
 public function admin_enqueue_scripts()
 {
     $screen = get_current_screen();
     if ('nav-menus' != $screen->base) {
         return;
     }
     $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     wp_enqueue_script('pll_nav_menu', POLYLANG_URL . '/js/nav-menu' . $suffix . '.js', array('jquery'), POLYLANG_VERSION);
     // the strings for the options
     foreach (array_reverse(PLL_Switcher::get_switcher_options('menu', 'string')) as $str) {
         $data['strings'][] = $str;
     }
     $data['strings'][] = __('Language switcher', 'polylang');
     // the title
     // get all language switcher menu items
     $items = get_posts(array('numberposts' => -1, 'nopaging' => true, 'post_type' => 'nav_menu_item', 'fields' => 'ids', 'meta_key' => '_pll_menu_item'));
     // the options values for the language switcher
     $data['val'] = array();
     foreach ($items as $item) {
         $data['val'][$item] = get_post_meta($item, '_pll_menu_item', true);
     }
     // send all these data to javascript
     wp_localize_script('pll_nav_menu', 'pll_data', $data);
 }