mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
Merge pull request #1248 from ultimatemember/fix/blocks
Account and User page blocks
This commit is contained in:
@@ -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,21 +164,24 @@ 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() );
|
||||
|
||||
ob_start();
|
||||
|
||||
$defaults = array(
|
||||
'template' => 'account',
|
||||
'mode' => 'account',
|
||||
'form_id' => 'um_account_id',
|
||||
'template' => 'account',
|
||||
'mode' => 'account',
|
||||
'form_id' => 'um_account_id',
|
||||
);
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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' ) ) ) {
|
||||
return '';
|
||||
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' ) ) {
|
||||
return '';
|
||||
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,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 );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user