[Plugin: Polylang] pll_register_string problem
-
Hey,
I’m using polylang 0.9.3 and I’ve made a simple plugin for a widget to make a list my posts of different post types (I use Types plugin too). You can set a title and a description text for the widget, but of course only widget’s title is visible at “Strings translation” tab of Polylang settings.
So I’m trying to use pll_register_string function. I use it at the “update” function what is called when you save the widget’s settings. The problem is that the string doesn’t come visible to the “Strings translation” list and I don’t know why.
Here is my plugin code (sorry, there is a lot of code you don’t need to see):
<?php /* Plugin Name: Post list Plugin URI: Description: Widget to list posts with specified post type Author: nnn Version: 1000 Author URI: */ class post_list extends WP_Widget { function post_list() { $widget_ops = array('classname' => 'post_list', 'description' => 'Post types: press-releases, media-tours, media-event' ); $this->WP_Widget('post_list', 'Post list', $widget_ops); } function form($instance) { $instance = wp_parse_args( (array) $instance, array( 'title' => '','max_posts'=>2,'post_type'=>'post', "text"=>'' ) ); $title = $instance['title']; $max_posts = $instance['max_posts']; $post_type = $instance['post_type']; $text = $instance['text']; ?> <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label> <p><label for="<?php echo $this->get_field_id('text'); ?>">Text: <input class="widefat" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" type="text" value="<?php echo attribute_escape($text); ?>" /></label> <p><label for="<?php echo $this->get_field_id('max_posts'); ?>">Max. posts: <input class="widefat" id="<?php echo $this->get_field_id('max_posts'); ?>" name="<?php echo $this->get_field_name('max_posts'); ?>" type="text" value="<?php echo attribute_escape($max_posts); ?>" /></label></p> <p><label for="<?php echo $this->get_field_id('post_type'); ?>">Post type: <input class="widefat" id="<?php echo $this->get_field_id('post_type'); ?>" name="<?php echo $this->get_field_name('post_type'); ?>" type="text" value="<?php echo attribute_escape($post_type); ?>" /></label></p> <?php } function makeEventDate($start,$end){ $start = strtotime($start,true); $end = strtotime($end,true); $startMonthYear = strtotime(date("Y-m",$start) . "-01",true); $endMonthYear = strtotime(date("Y-m",$end) . "-01",true); $startYear=date("Y",$start); $endYear=date("Y",$end); if($startYear<$endYear){ $startDate = date_i18n("F d, Y",$start); }else{ $startDate = date_i18n("F d",$start); } if($endMonthYear>$startMonthYear){ $endDate = date_i18n("F d",$end); }else{ $endDate = date("d",$end); } return $startDate . " - " . $endDate . ", " . $endYear; } function dateFormat($postID, $type){ $date=""; if($type == "media-tours"){ $date = $this->makeEventDate(get_post_meta($postID, 'start_date', true),get_post_meta($postID, 'end_date', true)); }else{ $date = get_post_meta($postID, 'date', true); $date = strtotime($date,true); $date = date_i18n("F d, Y",$date); } return $date; } function urlGet($postID, $type){ $URL=""; if($type=="media-follow-up"){ $URL=get_post_meta($postID, 'url', true); }else{ $URL=get_permalink($postID); } return $URL; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = $new_instance['title']; $instance['max_posts'] = $new_instance['max_posts']; $instance['post_type'] = $new_instance['post_type']; $instance['text'] = $new_instance['text']; pll_register_string("Post list text",$instance['text'] ); return $instance; } function widget($args, $instance) { extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); $max_posts = $instance['max_posts']; $post_type = $instance['post_type']; $text = $instance['text']; echo '<div class="post_list ' . $post_type . '">' . '<div class="' . $post_type . '_icon icon"></div>' . '<div class="description">' . $before_title . $title . $after_title . '<i>' . pll__($text) . '</i></div><div class="posts">'; $args = array( 'post_type' => $post_type, 'numberposts'=>$max_posts ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ $post = get_post( $recent["ID"] ); echo '<span class="date">' . $this->dateFormat($recent["ID"],$post_type) . "</span><br>" . '<a href="' . $this->urlGet($recent["ID"],$post_type) . '">' . $recent["post_title"].'</a><br>'; } echo "</div></div>"; echo $after_widget; } } add_action( 'widgets_init', create_function('', 'return register_widget("post_list");') );?>
I understand the string should come visible to “Strings translation” tab when I save plugins settings.
- The topic ‘[Plugin: Polylang] pll_register_string problem’ is closed to new replies.