'Posts', // Do not translate ( used for css class ) 'ajax' => false, ) ); $this->model = $model; $this->language_list = $this->model->get_languages_list(array( 'hide_default' => true)); } /** * Displays the item information in a column ( default case ) * * @since 1.0 * * @param object $item * @param string $column_name * @return string */ public function column_default( $item, $column_name ) { $language_list_locale = $this->model->get_available_locales(); switch ( $column_name ) { case 'post_type': return esc_html( $item->$column_name ); default: //language column fr_FR, en_US, ... if (in_array($column_name,$language_list_locale)){ return $this->display_translation_post_action($item,$column_name); } else { return print_r( $item, true ); //Show the whole array for troubleshooting purposes } } } /** * Displays the item information in the column 'name' * * @since 1.0 * * @param object $item * @return string */ public function column_name( $item ) { return esc_html( $item->post_title ); } /** * Displays the item information in the column 'name' * * @since 1.0 * * @param object $item * @return string */ public function column_locale( $item ) { $post_locale = get_post_meta($item->ID,'_locale' , true); if (empty($post_locale) || 'all' == $post_locale) { //$post_locale = esc_html__( 'All languages', 'falang' ); //$post_locale = ''; $post_locale = __( '*', 'falang' ); } return esc_html__($post_locale); } /** * Displays the id information in the column 'id' * * @since 1.0.6 * * @param object $item * @return string */ public function column_id( $item ) { return esc_html($item->ID); } /** * Gets the list of columns * * @since 0.1 * @update 1.3.51 change _x by __ to allow translation * * @return array the list of column titles */ public function get_columns() { $columns = array( 'name' => __( 'Name', 'falang' ), 'post_type' => __( 'Type', 'falang' ) ); $columns['locale'] = sprintf( '%2$s', esc_attr__( 'Locale','falang' ), __( 'Locale', 'falang' ) ); //add language column //language list is only non default language foreach ($this->language_list as $language){ $columns[$language->locale] = $language->get_flag(); } //add ID column to the end $columns['id'] = __( 'ID', 'falang' ); return $columns; } /** * Gets the name of the default primary column. * * @since 2.1 * * @return string Name of the default primary column, in this case, 'name'. */ protected function get_default_primary_column_name() { return 'name'; } /** ************************************************************************ * * @from 1.0 * @update 1.3.32 get the item in the prepare_items * filter the post by filter * get_posts displayed only * @update 1.3.47 fix sqlInjection on post search * @update 1.3.48 fix injecton with esc_sql * * * * @param array $data * * @uses $this->_column_headers * @uses $this->items * @uses $this->get_columns() * @uses $this->get_sortable_columns() * @uses $this->get_pagenum() * @uses $this->set_pagination_args() **************************************************************************/ public function prepare_items() { // Filter for search post $s = !empty( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : ''; $per_page = $this->get_items_per_page('falang_post_per_page',20); $paged = isset($_REQUEST['paged']) ? $_REQUEST['paged'] - 1 : 0; $postOffset = $paged * $per_page; $post_type = $this->model->get_transtable_post_types(true); $post_status = array('publish', 'pending', 'draft', 'future', 'private','inherit'); if (!empty( $s )) { add_filter( 'posts_where', array($this,'filter_title_post_where') ); } $args = array( 'post_type' => $this->model->get_transtable_post_types(true), 'post_status' => $post_status, 'orderby' => 'post_title', 'offset' => $postOffset, 'suppress_filters' => false, 'order' => 'ASC', 'posts_per_page' => $per_page ); if ((isset($_REQUEST['pt-filter']) && $_REQUEST['pt-filter'])) { $args['post_type'] = $_REQUEST['pt-filter']; $post_type = array($_REQUEST['pt-filter']);//use for the count } $translable_post_list = get_posts($args); if (!empty( $s )) { remove_filter( 'posts_where', array($this,'filter_title_post_where') ); } //count number of item global $wpdb; $query_count = "SELECT count(1) FROM {$wpdb->posts} wp_posts WHERE 1=1 "; $query_count .= " AND wp_posts.post_type IN ('" . implode( "', '", array_map( 'esc_sql', $post_type ) ) . "')"; $query_count .= " AND wp_posts.post_status IN ('" . implode( "', '", array_map( 'esc_sql', $post_status ) ) . "')"; if (!empty( $s )) { $like_search = '%' . $wpdb->esc_like( $s ) . '%'; $query_count .= $wpdb->prepare( " AND ({$wpdb->posts}.post_title LIKE %s)", $like_search ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared } $total_items = $wpdb->get_var($query_count); $this->items = $translable_post_list; $this->set_pagination_args( array( 'total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil( $total_items / $per_page ), ) ); $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() ); } // status filter links // http://wordpress.stackexchange.com/questions/56883/how-do-i-create-links-at-the-top-of-wp-list-table function get_views() { $views = array(); //TODO check remove query args $base_url = esc_url_raw( remove_query_arg( array( 'post_type' ) ) ); // handle search query if ( isset($_REQUEST['s']) && $_REQUEST['s'] ) { $base_url = add_query_arg( 's', $_REQUEST['s'], $base_url ); } // handle post_type filter if ( isset($_REQUEST['pt-filter']) && $_REQUEST['pt-filter'] ) { $base_url = add_query_arg( 'post_type', $_REQUEST['pt-filter'], $base_url ); } return $views; } /** * Add extra markup in the toolbars before or after the list * @param string $which, helps you decide if you add the markup after (bottom) or before (top) the list */ function extra_tablenav( $which ) { if ( 'top' != $which ) return; $post_type = $this->model->get_transtable_post_types(true); ?>