Merge branch 'development/2.6.1' into feature/um-blocks

This commit is contained in:
Nikita Sinelnikov
2023-05-23 11:14:37 +03:00
committed by GitHub
77 changed files with 2712 additions and 1488 deletions
+10 -8
View File
@@ -1,9 +1,9 @@
<?php
namespace um\admin\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) {
@@ -14,17 +14,20 @@ if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) {
*/
class Admin_Builder {
/**
* @var int
*/
public $form_id;
/**
* @var
* @var array
*/
var $form_id;
public $global_fields = array();
/**
* Admin_Builder constructor.
*/
function __construct() {
public function __construct() {
add_action( 'um_admin_field_modal_header', array( &$this, 'add_message_handlers' ) );
add_action( 'um_admin_field_modal_footer', array( &$this, 'add_conditional_support' ), 10, 4 );
add_filter( 'um_admin_builder_skip_field_validation', array( &$this, 'skip_field_validation' ), 10, 3 );
@@ -33,7 +36,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) {
add_filter( 'um_admin_field_update_error_handling', array( &$this, 'um_admin_field_update_error_handling' ), 1, 2 );
}
/**
* Apply a filter to handle errors for field updating in backend
*
+11 -5
View File
@@ -104,7 +104,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Columns' ) ) {
return $actions;
}
/**
* Duplicate a form
*
@@ -112,13 +111,20 @@ if ( ! class_exists( 'um\admin\core\Admin_Columns' ) ) {
*
* @return string
*/
function duplicate_uri( $id ) {
$url = add_query_arg('um_adm_action', 'duplicate_form', admin_url('edit.php?post_type=um_form') );
$url = add_query_arg('post_id', $id, $url);
private function duplicate_uri( $id ) {
$url = add_query_arg(
array(
'post_type' => 'um_form',
'um_adm_action' => 'duplicate_form',
'post_id' => $id,
'nonce' => wp_create_nonce( "um-duplicate_form{$id}" ),
),
admin_url( 'edit.php' )
);
return $url;
}
/**
* Custom columns for Form
*
+10 -1
View File
@@ -123,10 +123,19 @@ if ( ! class_exists( 'um\admin\core\Admin_Forms' ) ) {
'href' => array(),
'title' => array(),
'target' => array(),
'class' => array(),
),
'i' => array(
'class' => array(),
),
'span' => array(
'class' => array(),
),
'br' => array(),
'em' => array(),
'strong' => array(),
'strong' => array(
'style' => array()
),
);
$data['value'] = wp_kses( $data['value'], $arr_kses );
}
+27 -7
View File
@@ -34,18 +34,38 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
private $custom_nonce_added = false;
var $init_icon = false;
public $init_icon = false;
/**
* @var bool
*/
public $in_edit = false;
/**
* @var null
*/
public $edit_mode_value = null;
/**
* @var array
*/
public $edit_array = array();
/**
* @var array
*/
public $postmeta = array();
/**
* @var bool
*/
public $is_loaded = false;
/**
* Admin_Metabox constructor.
*/
function __construct() {
$this->in_edit = false;
$this->edit_mode_value = null;
$this->edit_array = [];
add_action( 'admin_head', array( &$this, 'admin_head' ), 9);
public function __construct() {
add_action( 'admin_head', array( &$this, 'admin_head' ), 9 );
add_action( 'admin_footer', array( &$this, 'load_modal_content' ), 9 );
add_action( 'load-post.php', array( &$this, 'add_metabox' ), 9 );
@@ -52,6 +52,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
$this->extensions_page();
$this->template_version();
// removed for now to avoid the bad reviews
//$this->reviews_notice();
@@ -714,6 +716,37 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
}
/**
* Check Templates Versions notice
*/
public function template_version() {
if ( true === (bool) get_option( 'um_override_templates_outdated' ) ) {
$link = admin_url( 'admin.php?page=um_options&tab=override_templates' );
ob_start();
?>
<p>
<?php
// translators: %s override templates page link.
echo wp_kses( sprintf( __( 'Your templates are out of date. Please visit <a href="%s">override templates status page</a> and update templates.', 'ultimate-member' ), $link ), UM()->get_allowed_html( 'admin_notice' ) );
?>
</p>
<?php
$message = ob_get_clean();
UM()->admin()->notices()->add_notice(
'um_override_templates_notice',
array(
'class' => 'error',
'message' => $message,
'dismissible' => false,
),
10
);
}
}
function dismiss_notice() {
UM()->admin()->check_ajax_nonce();
+199 -5
View File
@@ -64,10 +64,12 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
add_filter( 'um_settings_section_install_info__content', array( $this, 'settings_install_info_tab' ), 10, 2 );
//custom content for override templates tab
add_action( 'plugins_loaded', array( $this, 'um_check_template_version' ), 10 );
add_filter( 'um_settings_section_override_templates__content', array( $this, 'settings_override_templates_tab' ), 10, 2 );
add_filter( 'um_settings_structure', array( $this, 'sorting_licenses_options' ), 9999, 1 );
//save handlers
add_action( 'admin_init', array( $this, 'save_settings_handler' ), 10 );
@@ -75,10 +77,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
add_action( 'um_settings_before_save', array( $this, 'check_permalinks_changes' ) );
add_action( 'um_settings_save', array( $this, 'on_settings_save' ) );
add_filter( 'um_change_settings_before_save', array( $this, 'save_email_templates' ) );
//save licenses options
add_action( 'um_settings_before_save', array( $this, 'before_licenses_save' ) );
add_action( 'um_settings_save', array( $this, 'licenses_save' ) );
@@ -440,7 +440,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
$duplicates = array();
$taxonomies_options = array();
$exclude_taxonomies = UM()->excluded_taxonomies();
$all_taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );
$all_taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true ), 'objects' );
foreach ( $all_taxonomies as $key => $taxonomy ) {
if ( in_array( $key, $exclude_taxonomies, true ) ) {
continue;
@@ -1839,6 +1839,14 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
),
),
),
'override_templates' => array(
'title' => __( 'Override templates', 'ultimate-member' ),
'fields' => array(
array(
'type' => 'override_templates',
),
),
),
)
);
@@ -1966,7 +1974,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
*/
do_action( "um_settings_page_before_" . $current_tab . "_" . $current_subtab . "_content" );
if ( in_array( $current_tab, apply_filters('um_settings_custom_tabs', array( 'licenses', 'install_info' ) ) ) || in_array( $current_subtab, apply_filters( 'um_settings_custom_subtabs', array(), $current_tab ) ) ) {
if ( in_array( $current_tab, apply_filters('um_settings_custom_tabs', array( 'licenses', 'install_info', 'override_templates' ) ) ) || in_array( $current_subtab, apply_filters( 'um_settings_custom_subtabs', array(), $current_tab ) ) ) {
/**
* UM hook
@@ -3007,6 +3015,192 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
return $section;
}
/**
* Periodically checking the versions of templates.
*
* @since 2.6.1
*
* @return void
*/
public function um_check_template_version() {
$um_check_version = get_transient( 'um_check_template_versions' );
if ( false === $um_check_version ) {
$this->get_override_templates();
}
}
/**
* HTML for Settings > Override Templates tab.
* @return void
*/
public function settings_override_templates_tab() {
$um_check_version = get_transient( 'um_check_template_versions' );
?>
<p class="description" style="margin: 20px 0 0 0;">
<a href="<?php echo esc_url( add_query_arg( 'um_adm_action', 'check_templates_version' ) ); ?>" class="button" style="margin-right: 10px;">
<?php esc_html_e( 'Re-check templates', 'ultimate-member' ); ?>
</a>
<?php
if ( false !== $um_check_version ) {
// translators: %s: Last checking templates time.
echo esc_html( sprintf( __( 'Last update: %s. You could re-check changes manually.', 'ultimate-member' ), wp_date( get_option( 'date_format', 'Y-m-d' ) . ' ' . get_option( 'time_format', 'H:i:s' ), $um_check_version ) ) );
} else {
esc_html_e( 'Templates haven\'t check yet. You could check changes manually.', 'ultimate-member' );
}
?>
</p>
<p class="description" style="margin: 20px 0 0 0;">
<?php
/** @noinspection HtmlUnknownTarget */
// translators: %s: Link to the docs article.
echo wp_kses( sprintf( __( 'You may get more details about overriding templates <a href="%s" target="_blank">here</a>.', 'ultimate-member' ), 'https://docs.ultimatemember.com/article/1516-templates-map' ), UM()->get_allowed_html( 'admin_notice' ) );
?>
</p>
<?php
include_once um_path . 'includes/admin/core/list-tables/version-template-list-table.php';
}
/**
* @param $get_list boolean
*
* @return array|void
*/
public function get_override_templates( $get_list = false ) {
$outdated_files = array();
$scan_files['um'] = $this->scan_template_files( um_path . '/templates/' );
$scan_files = apply_filters( 'um_override_templates_scan_files', $scan_files );
$out_date = false;
set_transient( 'um_check_template_versions', time(), 12 * HOUR_IN_SECONDS );
foreach ( $scan_files as $key => $files ) {
foreach ( $files as $file ) {
if ( ! str_contains( $file, 'email/' ) ) {
$located = array();
$located = apply_filters( "um_override_templates_get_template_path__{$key}", $located, $file );
if ( ! empty( $located ) ) {
$theme_file = $located['theme'];
} elseif ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' . $file ) ) {
$theme_file = get_stylesheet_directory() . '/ultimate-member/templates/' . $file;
} else {
$theme_file = false;
}
if ( ! empty( $theme_file ) ) {
$core_file = $file;
if ( ! empty( $located ) ) {
$core_path = $located['core'];
$core_file_path = stristr( $core_path, 'wp-content' );
} else {
$core_path = um_path . '/templates/' . $core_file;
$core_file_path = stristr( um_path . 'templates/' . $core_file, 'wp-content' );
}
$core_version = $this->get_file_version( $core_path );
$theme_version = $this->get_file_version( $theme_file );
$status = esc_html__( 'Theme version up to date', 'ultimate-member' );
$status_code = 1;
if ( version_compare( $theme_version, $core_version, '<' ) ) {
$status = esc_html__( 'Theme version is out of date', 'ultimate-member' );
$status_code = 0;
}
if ( '' === $theme_version ) {
$status = esc_html__( 'Theme version is empty', 'ultimate-member' );
$status_code = 0;
}
if ( 0 === $status_code ) {
$out_date = true;
update_option( 'um_override_templates_outdated', true );
}
$outdated_files[] = array(
'core_version' => $core_version,
'theme_version' => $theme_version,
'core_file' => $core_file_path,
'theme_file' => stristr( $theme_file, 'wp-content' ),
'status' => $status,
'status_code' => $status_code,
);
}
}
}
}
if ( false === $out_date ) {
delete_option( 'um_override_templates_outdated' );
}
update_option( 'um_template_statuses', $outdated_files );
if ( true === $get_list ) {
return $outdated_files;
}
}
/**
* Scan the template files.
*
* @param string $template_path Path to the template directory.
* @return array
*/
public static function scan_template_files( $template_path ) {
$files = @scandir( $template_path ); // @codingStandardsIgnoreLine.
$result = array();
if ( ! empty( $files ) ) {
foreach ( $files as $value ) {
if ( ! in_array( $value, array( '.', '..' ), true ) ) {
if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
$sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
foreach ( $sub_files as $sub_file ) {
$result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
}
} else {
$result[] = $value;
}
}
}
}
return $result;
}
/**
* @param $file string
*
* @return string
*/
public static function get_file_version( $file ) {
// Avoid notices if file does not exist.
if ( ! file_exists( $file ) ) {
return '';
}
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' ); // @codingStandardsIgnoreLine.
// Pull only the first 8kiB of the file in.
$file_data = fread( $fp, 8192 ); // @codingStandardsIgnoreLine.
// PHP will close file handle, but we are good citizens.
fclose( $fp ); // @codingStandardsIgnoreLine.
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );
$version = '';
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) {
$version = _cleanup_header_comment( $match[1] );
}
return $version;
}
/**
* @param $html
+6 -5
View File
@@ -14,14 +14,15 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) {
*/
class Admin_Users {
/**
* @var string
*/
public $custom_role = 'um_role';
/**
* Admin_Users constructor.
*/
function __construct() {
$this->custom_role = 'um_role';
public function __construct() {
add_action( 'restrict_manage_users', array( &$this, 'restrict_manage_users' ) );
add_filter( 'user_row_actions', array( &$this, 'user_row_actions' ), 10, 2 );
@@ -273,7 +274,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) {
$submitted = get_user_meta( $user_id, 'submitted', true );
if ( ! empty( $submitted ) ) {
$actions['view_info'] = '<a href="javascript:void(0);" data-modal="UM_preview_registration" data-modal-size="smaller"
$actions['view_info'] = '<a href="javascript:void(0);" data-modal="UM_preview_registration" data-modal-size="smaller"
data-dynamic-content="um_admin_review_registration" data-arg1="' . esc_attr( $user_id ) . '" data-arg2="edit_registration">' . __( 'Info', 'ultimate-member' ) . '</a>';
}
@@ -0,0 +1,215 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class UM_Versions_List_Table
*/
class UM_Versions_List_Table extends WP_List_Table {
/**
* @var string
*/
public $no_items_message = '';
/**
* @var array
*/
public $columns = array();
/**
* UM_Versions_List_Table constructor.
*
* @param array $args
*/
public function __construct( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'singular' => __( '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() {
$screen = $this->screen;
$columns = $this->get_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, array(), $sortable );
$templates = get_option( 'um_template_statuses', array() );
$templates = is_array( $templates ) ? $templates : array();
@uasort(
$templates,
function ( $a, $b ) {
if ( strtolower( $a['status_code'] ) === strtolower( $b['status_code'] ) ) {
return 0;
}
return ( strtolower( $a['status_code'] ) < strtolower( $b['status_code'] ) ) ? -1 : 1;
}
);
$per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
$paged = $this->get_pagenum();
$this->items = array_slice( $templates, ( $paged - 1 ) * $per_page, $per_page );
$this->set_pagination_args(
array(
'total_items' => count( $templates ),
'per_page' => $per_page,
)
);
}
/**
* @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_columns( $args = array() ) {
$this->columns = $args;
return $this;
}
/**
* @return array
*/
public function get_columns() {
return $this->columns;
}
/**
* @param $item
*
* @return string
*/
public function column_template( $item ) {
$output = esc_html__( 'Core path - ', 'ultimate-member' );
$output .= $item['core_file'] . '<br>';
$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 ) {
return $item['theme_version'] ? $item['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';
return $item['status'] . ' <span class="dashicons um-notification-status ' . esc_attr( $icon ) . '"></span>';
}
}
$list_table = new UM_Versions_List_Table(
array(
'singular' => __( 'Template', 'ultimate-member' ),
'plural' => __( 'Templates', 'ultimate-member' ),
'ajax' => false,
)
);
/**
* 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
* <?php
* add_filter( 'um_versions_templates_columns', 'um_versions_templates_columns', 10, 1 );
* function um_versions_templates_columns( $columns ) {
* // your code here
* $columns['my-custom-column'] = 'My Custom Column';
* return $columns;
* }
* ?>
*/
$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' ),
)
);
$list_table->set_columns( $columns );
$list_table->prepare_items();
?>
<form action="" method="get" name="um-settings-template-versions" id="um-settings-template-versions">
<input type="hidden" name="page" value="um_options" />
<input type="hidden" name="tab" value="override_templates" />
<?php $list_table->display(); ?>
</form>