mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- added common enqueue class
- copied blocks.js to the new path for admin JS
This commit is contained in:
@@ -0,0 +1,197 @@
|
||||
'use strict';
|
||||
|
||||
var um_components = wp.components,
|
||||
umSelectControl = um_components.SelectControl,
|
||||
umTextareaControl = um_components.TextareaControl;
|
||||
|
||||
|
||||
function um_admin_blocks_custom_fields( um_condition_fields, props ) {
|
||||
return wp.hooks.applyFilters( 'um_admin_blocks_custom_fields', [], um_condition_fields, props );
|
||||
}
|
||||
|
||||
var um_block_restriction = wp.compose.createHigherOrderComponent(
|
||||
function( BlockEdit ) {
|
||||
var um_condition_fields = {
|
||||
um_who_access: 'um_block_settings_hide',
|
||||
um_roles_access: 'um_block_settings_hide',
|
||||
um_message_type: 'um_block_settings_hide',
|
||||
um_message_content: 'um_block_settings_hide'
|
||||
};
|
||||
|
||||
um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_default', um_condition_fields );
|
||||
|
||||
return function( props ) {
|
||||
let initialIsRestrict = props.attributes.um_is_restrict !== undefined ? props.attributes.um_is_restrict : false;
|
||||
|
||||
if ( props.attributes.um_is_restrict !== true ) {
|
||||
um_condition_fields['um_who_access'] = 'um_block_settings_hide';
|
||||
um_condition_fields['um_roles_access'] = 'um_block_settings_hide';
|
||||
um_condition_fields['um_message_type'] = 'um_block_settings_hide';
|
||||
um_condition_fields['um_message_content'] = 'um_block_settings_hide';
|
||||
} else {
|
||||
um_condition_fields['um_who_access'] = '';
|
||||
|
||||
if ( parseInt( props.attributes.um_who_access ) === 0 || typeof props.attributes.um_who_access === 'undefined' ) {
|
||||
um_condition_fields['um_roles_access'] = 'um_block_settings_hide';
|
||||
um_condition_fields['um_message_type'] = 'um_block_settings_hide';
|
||||
um_condition_fields['um_message_content'] = 'um_block_settings_hide';
|
||||
} else if ( parseInt( props.attributes.um_who_access ) === 1 ) {
|
||||
um_condition_fields['um_roles_access'] = '';
|
||||
um_condition_fields['um_message_type'] = '';
|
||||
|
||||
if ( parseInt( props.attributes.um_message_type ) === 2 ) {
|
||||
um_condition_fields['um_message_content'] = '';
|
||||
} else {
|
||||
um_condition_fields['um_message_content'] = 'um_block_settings_hide';
|
||||
}
|
||||
} else {
|
||||
um_condition_fields['um_message_type'] = '';
|
||||
|
||||
if ( parseInt( props.attributes.um_message_type ) === 2 ) {
|
||||
um_condition_fields['um_message_content'] = '';
|
||||
} else {
|
||||
um_condition_fields['um_message_content'] = 'um_block_settings_hide';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields', um_condition_fields, props );
|
||||
|
||||
return wp.element.createElement(
|
||||
wp.element.Fragment,
|
||||
{},
|
||||
wp.element.createElement( BlockEdit, props ),
|
||||
wp.element.createElement(
|
||||
wp.blockEditor.InspectorControls,
|
||||
{},
|
||||
wp.element.createElement(
|
||||
wp.components.PanelBody,
|
||||
{
|
||||
title: wp.i18n.__( 'Ultimate Member: Content Restriction', 'ultimate-member' ),
|
||||
className: 'um_block_settings'
|
||||
},
|
||||
wp.element.createElement(
|
||||
wp.components.ToggleControl,
|
||||
{
|
||||
label: wp.i18n.__( 'Restrict access?', 'ultimate-member' ),
|
||||
checked: initialIsRestrict,
|
||||
onChange: function onChange( value ) {
|
||||
props.setAttributes( { um_is_restrict: value } );
|
||||
if ( value === false ) {
|
||||
um_condition_fields['um_who_access'] = 'um_block_settings_hide';
|
||||
um_condition_fields['um_roles_access'] = 'um_block_settings_hide';
|
||||
um_condition_fields['um_message_type'] = 'um_block_settings_hide';
|
||||
um_condition_fields['um_message_content'] = 'um_block_settings_hide';
|
||||
} else {
|
||||
um_condition_fields['um_who_access'] = '';
|
||||
}
|
||||
|
||||
um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_on_change', um_condition_fields, 'um_is_restrict', value );
|
||||
}
|
||||
}
|
||||
),
|
||||
wp.element.createElement(
|
||||
umSelectControl,
|
||||
{
|
||||
type: 'number',
|
||||
className: um_condition_fields['um_who_access'],
|
||||
label: wp.i18n.__( 'Who can access this block?', 'ultimate-member' ),
|
||||
value: props.attributes.um_who_access,
|
||||
options: [
|
||||
{
|
||||
label: wp.i18n.__( 'Everyone', 'ultimate-member' ),
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
label: wp.i18n.__( 'Logged in users', 'ultimate-member' ),
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
label: wp.i18n.__( 'Logged out users', 'ultimate-member' ),
|
||||
value: 2
|
||||
}
|
||||
],
|
||||
onChange: function onChange( value ) {
|
||||
props.setAttributes( { um_who_access: value } );
|
||||
if ( parseInt( value ) === 0 ) {
|
||||
um_condition_fields['um_message_type'] = 'um_block_settings_hide';
|
||||
um_condition_fields['um_message_content'] = 'um_block_settings_hide';
|
||||
um_condition_fields['um_roles_access'] = 'um_block_settings_hide';
|
||||
} else if ( parseInt( value ) === 1 ) {
|
||||
um_condition_fields['um_message_type'] = '';
|
||||
um_condition_fields['um_roles_access'] = '';
|
||||
} else {
|
||||
um_condition_fields['um_message_type'] = '';
|
||||
um_condition_fields['um_roles_access'] = 'um_block_settings_hide';
|
||||
}
|
||||
|
||||
um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_on_change', um_condition_fields, 'um_who_access', value );
|
||||
}
|
||||
}
|
||||
),
|
||||
wp.element.createElement(
|
||||
umSelectControl,
|
||||
{
|
||||
multiple: true,
|
||||
className: um_condition_fields['um_roles_access'],
|
||||
label: wp.i18n.__( 'What roles can access this block?', 'ultimate-member' ),
|
||||
value: props.attributes.um_roles_access,
|
||||
options: um_restrict_roles,
|
||||
onChange: function onChange( value ) {
|
||||
props.setAttributes( { um_roles_access: value } );
|
||||
}
|
||||
}
|
||||
),
|
||||
wp.element.createElement(
|
||||
umSelectControl,
|
||||
{
|
||||
type: 'number',
|
||||
className: um_condition_fields['um_message_type'],
|
||||
label: wp.i18n.__( 'Restriction action', 'ultimate-member' ),
|
||||
value: props.attributes.um_message_type,
|
||||
options: [
|
||||
{
|
||||
label: wp.i18n.__( 'Hide block', 'ultimate-member' ),
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
label: wp.i18n.__( 'Show global default message', 'ultimate-member' ),
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
label: wp.i18n.__( 'Show custom message', 'ultimate-member' ),
|
||||
value: 2
|
||||
}
|
||||
],
|
||||
onChange: function onChange( value ) {
|
||||
props.setAttributes( { um_message_type: value } );
|
||||
if ( parseInt( value ) === 2 ) {
|
||||
um_condition_fields['um_message_content'] = '';
|
||||
} else {
|
||||
um_condition_fields['um_message_content'] = 'um_block_settings_hide';
|
||||
}
|
||||
}
|
||||
}
|
||||
),
|
||||
wp.element.createElement(
|
||||
umTextareaControl,
|
||||
{
|
||||
type: 'number',
|
||||
className: um_condition_fields['um_message_content'],
|
||||
label: wp.i18n.__( 'Custom restricted access message', 'ultimate-member' ),
|
||||
value: props.attributes.um_message_content,
|
||||
onChange: function onChange( value ) {
|
||||
props.setAttributes( { um_message_content: value } );
|
||||
}
|
||||
}
|
||||
),
|
||||
um_admin_blocks_custom_fields( um_condition_fields, props )
|
||||
)
|
||||
)
|
||||
);
|
||||
};
|
||||
},
|
||||
'um_block_restriction'
|
||||
);
|
||||
|
||||
wp.hooks.addFilter( 'editor.BlockEdit', 'um-block/um_block_restriction', um_block_restriction );
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php namespace um\common;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Enqueue
|
||||
*
|
||||
* @package um\common
|
||||
*/
|
||||
class Enqueue {
|
||||
|
||||
/**
|
||||
* @var string scripts' Standard or Minified versions
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public $suffix;
|
||||
|
||||
/**
|
||||
* @var array URLs for easy using
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public $urls;
|
||||
|
||||
/**
|
||||
* Enqueue constructor.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'um_core_loaded', array( $this, 'init_variables' ) );
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( &$this, 'common_libs' ), 9 );
|
||||
add_action( 'wp_enqueue_scripts', array( &$this, 'common_libs' ), 9 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init variables for enqueue scripts.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function init_variables() {
|
||||
$this->suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
|
||||
$this->urls['js'] = UM_URL . 'assets/js/';
|
||||
$this->urls['css'] = UM_URL . 'assets/css/';
|
||||
$this->urls['libs'] = UM_URL . 'assets/libs/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register common JS/CSS libraries
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function common_libs() {
|
||||
wp_register_style( 'um-jquery-ui', $this->urls['libs'] . 'jquery-ui/jquery-ui' . $this->suffix . '.css', array(), '1.12.1' );
|
||||
|
||||
wp_register_script( 'um-tipsy', $this->urls['libs'] . 'tipsy/um-tipsy' . $this->suffix . '.js', array( 'jquery' ), '1.0.0a', true );
|
||||
wp_register_style( 'um-tipsy', $this->urls['libs'] . 'tipsy/um-tipsy' . $this->suffix . '.css', array(), '1.0.0a' );
|
||||
|
||||
wp_register_script( 'um-helptip', $this->urls['libs'] . 'helptip/helptip' . $this->suffix . '.js', array( 'jquery', 'jquery-ui-tooltip' ), '1.0.0', true );
|
||||
wp_register_style( 'um-helptip', $this->urls['libs'] . 'helptip/helptip' . $this->suffix . '.css', array( 'dashicons', 'um-jquery-ui' ), '1.0.0' );
|
||||
|
||||
// old fonticons
|
||||
$um_is_legacy = get_option( 'um_is_legacy' );
|
||||
if ( $um_is_legacy ) {
|
||||
wp_register_style( 'um-fonticons-ii', $this->urls['libs'] . 'fonticons/um-fonticons-ii' . $this->suffix . '.css', array(), UM_VERSION );
|
||||
wp_register_style( 'um-fonticons-fa', $this->urls['libs'] . 'fonticons/um-fonticons-fa' . $this->suffix . '.css', array(), UM_VERSION );
|
||||
}
|
||||
|
||||
// Select2
|
||||
$dequeue_select2 = apply_filters( 'um_dequeue_select2_scripts', false );
|
||||
if ( class_exists( 'WooCommerce' ) || $dequeue_select2 ) {
|
||||
wp_dequeue_style( 'select2' );
|
||||
wp_deregister_style( 'select2' );
|
||||
|
||||
wp_dequeue_script( 'select2' );
|
||||
wp_deregister_script( 'select2' );
|
||||
}
|
||||
wp_register_script( 'select2', $this->urls['libs'] . 'select2/select2.full' . $this->suffix . '.js', array( 'jquery' ), '4.0.13', true );
|
||||
wp_register_style( 'select2', $this->urls['libs'] . 'select2/select2' . $this->suffix . '.css', array(), '4.0.13' );
|
||||
|
||||
// Raty JS for rating field-type
|
||||
wp_register_script( 'um-raty', $this->urls['libs'] . 'raty/um-raty' . $this->suffix . '.js', array( 'jquery', 'wp-i18n' ), '2.6.0', true );
|
||||
wp_register_style( 'um-raty', $this->urls['libs'] . 'raty/um-raty' . $this->suffix . '.css', array(), '2.6.0' );
|
||||
|
||||
// Modal
|
||||
wp_register_script( 'um-modal', $this->urls['libs'] . 'modal/um-modal' . $this->suffix . '.js', array( 'jquery', 'wp-i18n', 'wp-hooks' ), UM_VERSION, true );
|
||||
wp_register_style( 'um-modal', $this->urls['libs'] . 'modal/um-modal' . $this->suffix . '.css', array(), UM_VERSION );
|
||||
|
||||
// Common JS scripts for wp-admin and frontend both
|
||||
wp_register_script( 'um-common', $this->urls['js'] . 'common' . $this->suffix . '.js', array( 'jquery' ), UM_VERSION, true );
|
||||
$um_common_variables = apply_filters(
|
||||
'um_common_js_variables',
|
||||
array(
|
||||
'locale' => get_locale(),
|
||||
)
|
||||
);
|
||||
wp_localize_script( 'um-common', 'um_common_variables', $um_common_variables );
|
||||
wp_enqueue_script( 'um-common' );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user