From 00dd3d6b9fbce758ffb6d21edd1b3079fd2d074d Mon Sep 17 00:00:00 2001 From: ashubawork Date: Fri, 7 Apr 2023 12:45:34 +0300 Subject: [PATCH] - list of templates --- .../admin/assets/css/um-admin-settings.css | 16 +- includes/admin/core/class-admin-settings.php | 29 +- .../version-template-list-table.php | 322 ++++++++++++++++++ 3 files changed, 351 insertions(+), 16 deletions(-) create mode 100644 includes/admin/core/list-tables/version-template-list-table.php diff --git a/includes/admin/assets/css/um-admin-settings.css b/includes/admin/assets/css/um-admin-settings.css index 0f8d78df..1e159673 100644 --- a/includes/admin/assets/css/um-admin-settings.css +++ b/includes/admin/assets/css/um-admin-settings.css @@ -46,6 +46,20 @@ text-align: center; } +.column-core_version { + width: 100px; + text-align: center; +} + +.column-theme_version { + width: 100px; + text-align: center; +} + +.column-status { + width: 260px; +} + th.column-email.column-primary { padding-left: 48px; } @@ -243,4 +257,4 @@ th.column-email.column-primary { .um_setting_ajax_button_response.complete { color:darkgreen; font-style: italic; -} \ No newline at end of file +} diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index c448377c..441bdbcd 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -3020,14 +3020,23 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { public function settings_override_templates_tab( $html, $section_fields ) { + ?> +

+ + + +

+ scan_template_files( um_path . '/templates/' ); foreach ( $scan_files as $key => $file ) { if ( ! str_contains( $file, 'email/' ) ) { - $located = apply_filters( 'um_located_template', $file, get_stylesheet_directory() . '/ultimate-member/' ); - if ( file_exists( $located ) ) { - $theme_file = $located; - } elseif ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' . $file ) ) { + if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' . $file ) ) { $theme_file = get_stylesheet_directory() . '/ultimate-member/templates/' . $file; } else { $theme_file = false; @@ -3060,17 +3069,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { } } - ob_start(); - ?> -

- - - -

- __( 'item', 'ultimate-member' ), + 'plural' => __( 'items', 'ultimate-member' ), + 'ajax' => false, + ) + ); + + $this->no_items_message = $args['plural'] . ' ' . __( 'not found.', 'ultimate-member' ); + + parent::__construct( $args ); + } + + + /** + * @param callable $name + * @param array $arguments + * + * @return mixed + */ + public function __call( $name, $arguments ) { + return call_user_func_array( array( $this, $name ), $arguments ); + } + + + /** + * + */ + public function prepare_items() { + $columns = $this->get_columns(); + $hidden = array(); + $sortable = $this->get_sortable_columns(); + $this->_column_headers = array( $columns, $hidden, $sortable ); + } + + + /** + * @param object $item + * @param string $column_name + * + * @return string + */ + public function column_default( $item, $column_name ) { + if ( isset( $item[ $column_name ] ) ) { + return $item[ $column_name ]; + } else { + return ''; + } + } + + + /** + * + */ + public function no_items() { + echo $this->no_items_message; + } + + + /** + * @param array $args + * + * @return $this + */ + public function set_sortable_columns( $args = array() ) { + $return_args = array(); + foreach ( $args as $k=>$val ) { + if ( is_numeric( $k ) ) { + $return_args[ $val ] = array( $val, $val == $this->default_sorting_field ); + } elseif( is_string( $k ) ) { + $return_args[ $k ] = array( $val, $k == $this->default_sorting_field ); + } else { + continue; + } + } + $this->sortable_columns = $return_args; + return $this; + } + + + /** + * @return array + */ + public function get_sortable_columns() { + return $this->sortable_columns; + } + + + /** + * @param array $args + * + * @return $this + */ + public function set_columns( $args = array() ) { + if ( count( $this->bulk_actions ) ) { + $args = array_merge( array( 'cb' => '' ), $args ); + } + $this->columns = $args; + + return $this; + } + + + /** + * @return array + */ + public function get_columns() { + return $this->columns; + } + + + /** + * @param array $args + * + * @return $this + */ + public function set_actions( $args = array() ) { + $this->actions = $args; + return $this; + } + + + /** + * @return array + */ + public function get_actions() { + return $this->actions; + } + + + /** + * @param array $args + * + * @return $this + */ + public function set_bulk_actions( $args = array() ) { + $this->bulk_actions = $args; + return $this; + } + + + /** + * @return array + */ + public function get_bulk_actions() { + return $this->bulk_actions; + } + + + /** + * @param $item + * + * @return string + */ + public function column_template( $item ) { + $output = esc_html__( 'Core path - ', 'ultimate-member' ); + $output .= $item['core_file'] . '
'; + $output .= esc_html__( 'Theme path - ', 'ultimate-member' ); + $output .= $item['theme_file']; + + return $output; + } + + + /** + * @param $item + * + * @return string + */ + public function column_core_version( $item ) { + return $item['core_version']; + } + + + /** + * @param $item + * + * @return string + */ + public function column_theme_version( $item ) { + $theme_version = $item['theme_version'] ? $item['theme_version'] : '-'; + + return $theme_version; + } + + + /** + * @param $item + * + * @return string + */ + public function column_status( $item ) { + $icon = 1 === $item['status_code'] ? 'um-notification-is-active dashicons-yes' : 'dashicons-no-alt'; + $text = $item['status'] . ' '; + + return $text; + } + + + /** + * @param array $attr + */ + public function wpc_set_pagination_args( $attr = array() ) { + $this->set_pagination_args( $attr ); + } +} + +$ListTable = new UM_Versions_List_Table( + array( + 'singular' => __( 'Template', 'ultimate-member' ), + 'plural' => __( 'Templates', 'ultimate-member' ), + 'ajax' => false, + ) +); + +$per_page = 999; +$paged = $ListTable->get_pagenum(); + +/** + * UM hook + * + * @type filter + * @title um_versions_templates_columns + * @description Version Templates List Table columns + * @input_vars + * [{"var":"$columns","type":"array","desc":"Columns"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_versions_templates_columns', 'function_name', 10, 1 ); + * @example + * + */ +$columns = apply_filters( + 'um_versions_templates_columns', + array( + 'template' => __( 'Template', 'ultimate-member' ), + 'core_version' => __( 'Core version', 'ultimate-member' ), + 'theme_version' => __( 'Theme version', 'ultimate-member' ), + 'status' => __( 'Status', 'ultimate-member' ), + ) +); + +$ListTable->set_columns( $columns ); + +$templates = UM()->admin_settings()->get_override_templates(); + +$ListTable->prepare_items(); +$ListTable->items = array_slice( $templates, ( $paged - 1 ) * $per_page, $per_page ); +$ListTable->wpc_set_pagination_args( + array( + 'total_items' => count( $templates ), + 'per_page' => $per_page, + ) +); ?> + +
+ + + + display(); ?> +