- add column "icl_translations" to UM_Emails_List_Table

This commit is contained in:
Denis Baranov
2017-12-19 11:56:42 +02:00
parent d460139473
commit b0576e0b19
@@ -37,6 +37,90 @@ $order = ( isset( $_GET['order'] ) && 'asc' == strtolower( $_GET['order'] ) ) ?
if( ! class_exists( 'WP_List_Table' ) )
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
class UM_WPML_Column_Extends{
static function add_management_column($columns){
global $sitepress;
$new_columns = $columns;
$active_languages = $sitepress->get_active_languages();
$current_language = $sitepress->get_current_language();
unset( $active_languages[ $current_language ] );
if ( count( $active_languages ) > 0 ) {
$flags_column = '';
foreach ( $active_languages as $language_data ) {
$flags_column .= '<img src="' . $sitepress->get_flag_url( $language_data['code'] ). '" width="18" height="12" alt="' . $language_data['display_name'] . '" title="' . $language_data['display_name'] . '" style="margin:2px" />';
}
$new_columns = array();
foreach ( $columns as $column_key => $column_content ) {
$new_columns[ $column_key ] = $column_content;
if ( 'email' === $column_key && ! isset( $new_columns['icl_translations'] ) ) {
$new_columns['icl_translations'] = $flags_column;
}
}
}
return $new_columns;
}
static function add_content_for_management_column( $item ) {
global $sitepress;
$html = '';
$active_languages = $sitepress->get_active_languages();
$current_language = $sitepress->get_current_language();
unset( $active_languages[ $current_language ] );
foreach ( $active_languages as $language_data ) {
$html .= self::get_status_html( $item['key'], $language_data['code'] );
}
return $html;
}
static function get_status_html( $template, $code ) {
global $sitepress;
$status = 'add';
$lang = '';
$active_languages = $sitepress->get_active_languages();
$translation = array(
'edit' => array( 'icon' => 'edit_translation.png', 'text' => sprintf(
__( 'Edit the %s translation', 'sitepress' ),
$active_languages[$code]['display_name'] ) ),
'add' => array( 'icon' => 'add_translation.png', 'text' => sprintf(
__( 'Add translation to %s', 'sitepress' ),
$active_languages[$code]['display_name']
)
)
);
$default_language_code = $sitepress->get_locale_from_language_code($sitepress->get_default_language());
$current_language_code = $sitepress->get_locale_from_language_code($code);
if ( $default_language_code != $current_language_code ) {
$lang = $current_language_code.'/';
}
$template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' ) . $lang . $template . '.php';
if ( file_exists( $template_path ) ) {
$status = 'edit';
}
$link = add_query_arg( array( 'email' => $template, 'lang' => $code ) );
return self::render_status_icon( $link, $translation[$status]['text'], $translation[$status]['icon'] );
}
static function render_status_icon( $link, $text, $img ) {
$icon_html = '<a href="' . $link . '" title="' . $text . '">';
$icon_html .= '<img style="padding:1px;margin:2px;" border="0" src="'
. ICL_PLUGIN_URL . '/res/img/'
. $img . '" alt="'
. $text . '" width="16" height="16"/>';
$icon_html .= '</a>';
return $icon_html;
}
}
class UM_Emails_List_Table extends WP_List_Table {
@@ -108,6 +192,10 @@ class UM_Emails_List_Table extends WP_List_Table {
$args = array_merge( array( 'cb' => '<input type="checkbox" />' ), $args );
}
$this->columns = $args;
if( um_is_wpml_active() ){
$this->columns = UM_WPML_Column_Extends::add_management_column($this->columns);
}
return $this;
}
@@ -152,6 +240,12 @@ class UM_Emails_List_Table extends WP_List_Table {
return '<a class="button um-email-configure" href="' . add_query_arg( array( 'email' => $item['key'] ) ) . '"><span class="dashicons dashicons-admin-generic"></span></a>';
}
function column_icl_translations( $item ){
if( um_is_wpml_active() ){
return UM_WPML_Column_Extends::add_content_for_management_column( $item );
}
}
function wpc_set_pagination_args( $attr = array() ) {
$this->set_pagination_args( $attr );