Merge pull request #1248 from ultimatemember/fix/blocks

Account and User page blocks
This commit is contained in:
Mykyta Synelnikov
2023-07-12 14:45:36 +03:00
committed by GitHub
4 changed files with 182 additions and 146 deletions
@@ -2,10 +2,13 @@
font-style: italic;
}
.um-block-notice {
background: #fff;
font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;
font-size:13px;
padding: 20px;
border: 1px solid #000;
}
.um-notification-status {
margin-right: 18px;
+23 -12
View File
@@ -1,8 +1,9 @@
<?php
namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'um\core\Account' ) ) {
@@ -14,35 +15,39 @@ if ( ! class_exists( 'um\core\Account' ) ) {
*/
class Account {
/**
* @var boolean
*/
public $account_exist = false;
/**
* @var
*/
var $tabs;
public $tabs;
/**
* @var string
*/
var $current_tab = 'general';
public $current_tab = 'general';
/**
* @var array
*/
var $displayed_fields = array();
public $displayed_fields = array();
/**
* @var array
*/
var $tab_output = array();
public $tab_output = array();
/**
* Account constructor.
*/
function __construct() {
public function __construct() {
add_shortcode( 'ultimatemember_account', array( &$this, 'ultimatemember_account' ) );
add_action( 'template_redirect', array( &$this, 'account_page_restrict' ), 10001 );
add_action( 'template_redirect', array( &$this, 'account_submit' ), 10002 );
@@ -159,10 +164,13 @@ if ( ! class_exists( 'um\core\Account' ) ) {
* @return false|string
* @throws \Exception
*/
function ultimatemember_account( $args = array() ) {
public function ultimatemember_account( $args = array() ) {
if ( ! is_user_logged_in() ) {
return '';
}
if ( true === $this->account_exist ) {
return '';
}
um_fetch_user( get_current_user_id() );
@@ -199,7 +207,7 @@ if ( ! class_exists( 'um\core\Account' ) ) {
if ( ! empty( $args['tab'] ) ) {
if ( $args['tab'] == 'account' ) {
if ( 'account' === $args['tab'] ) {
$args['tab'] = 'general';
}
@@ -233,12 +241,13 @@ if ( ! class_exists( 'um\core\Account' ) ) {
*/
do_action( 'um_account_page_hidden_fields', $args );
$this->render_account_tab( $args['tab'], $this->tabs[ $args['tab'] ], $args ); ?>
$this->render_account_tab( $args['tab'], $this->tabs[ $args['tab'] ], $args );
?>
</form>
</div>
</div>
<?php }
<?php
}
} else {
$this->init_tabs( $args );
@@ -263,6 +272,8 @@ if ( ! class_exists( 'um\core\Account' ) ) {
$this->account_fields_hash();
$this->account_exist = true;
return $output;
}
+12 -3
View File
@@ -167,11 +167,15 @@ if ( ! class_exists( 'um\core\Blocks' ) ) {
*/
public function forms_render( $atts ) {
if ( isset( $atts['form_id'] ) && '' !== $atts['form_id'] ) {
$mode = get_post_meta( $atts['form_id'], '_um_mode', true );
if ( 'profile' === $mode && ( um_is_core_page( 'account' ) || um_is_core_page( 'user' ) ) ) {
if ( um_is_core_page( 'account' ) ) {
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
return '<div class="um-block-notice">' . esc_html__( 'This block cannot be used on this page', 'ultimate-member' ) . '</div>';
} else {
return '';
}
}
}
$shortcode = '[ultimatemember is_block="1"';
if ( isset( $atts['form_id'] ) && '' !== $atts['form_id'] ) {
@@ -206,9 +210,14 @@ if ( ! class_exists( 'um\core\Blocks' ) ) {
* @uses apply_shortcodes()
*/
public function account_render( $atts ) {
if ( um_is_core_page( 'account' ) || um_is_core_page( 'user' ) ) {
if ( um_is_core_page( 'user' ) ) {
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
return '<div class="um-block-notice">' . esc_html__( 'This block cannot be used on this page', 'ultimate-member' ) . '</div>';
} else {
return '';
}
}
$shortcode = '[ultimatemember_account is_block="1"';
if ( isset( $atts['tab'] ) && 'all' !== $atts['tab'] ) {
+13
View File
@@ -13,6 +13,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
*/
class Shortcodes {
/**
* @var array
*/
public $forms_exist = array();
/**
* @var string
*/
@@ -597,6 +602,14 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
* @return string
*/
public function ultimatemember( $args = array() ) {
if ( isset( $args['form_id'] ) ) {
$id = $args['form_id'];
if ( isset( $this->forms_exist[ $id ] ) && true === $this->forms_exist[ $id ] ) {
return '';
}
$this->forms_exist[ $id ] = true;
}
return $this->load( $args );
}