diff --git a/.gitignore b/.gitignore index 706e5908..a7597b20 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,6 @@ local.properties [Dd]ebug/ [Rr]elease/ x64/ -build/ [Bb]in/ [Oo]bj/ @@ -195,7 +194,6 @@ $RECYCLE.BIN/ *.egg *.egg-info dist/ -build/ eggs/ parts/ var/ diff --git a/assets/js/um-blocks.js b/assets/js/um-blocks.js new file mode 100644 index 00000000..2b258d3b --- /dev/null +++ b/assets/js/um-blocks.js @@ -0,0 +1,79 @@ +jQuery(window).on( 'load', function($) { + var observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + jQuery(mutation.addedNodes).find('.um.um-directory').each(function() { + jQuery('.um-directory input, .um-directory select, .um-directory button').attr('disabled', 'disabled'); + jQuery('.um-directory a').attr('href', ''); + + if ( typeof( jQuery.fn.select2 ) === 'function' ) { + jQuery(".um-s1").each( function( e ) { + var obj = jQuery(this); + obj.select2({ + allowClear: true, + dropdownParent: obj.parent() + }).on( 'change', unselectEmptyOption ); + } ); + + jQuery(".um-s2").each( function( e ) { + var obj = jQuery(this); + + // fix https://github.com/ultimatemember/ultimatemember/issues/941 + // using .um-custom-shortcode-tab class as temporarily solution + var atts = {}; + if ( obj.parents('.um-custom-shortcode-tab').length ) { + atts = { + allowClear: false + }; + } else { + atts = { + allowClear: false, + minimumResultsForSearch: 10, + dropdownParent: obj.parent() + }; + } + obj.select2( atts ).on( 'change', unselectEmptyOption ); + } ); + + jQuery(".um-s3").each( function( e ) { + var obj = jQuery(this); + + obj.select2({ + allowClear: false, + minimumResultsForSearch: -1, + dropdownParent: obj.parent() + }).on( 'change', unselectEmptyOption ); + } ); + } + }); + jQuery(mutation.addedNodes).find('.um.um-profile').each(function() { + jQuery('.um-profile input, .um-profile select, .um-profile button').attr('disabled', 'disabled'); + jQuery('.um-profile a').attr('href', ''); + }); + jQuery(mutation.addedNodes).find('.um.um-account').each(function() { + jQuery('.um-account input, .um-account select, .um-account button').attr('disabled', 'disabled'); + jQuery('.um-account a').attr('href', ''); + }); + jQuery(mutation.addedNodes).find('.um.um-password').each(function() { + jQuery('.um-password input, .um-password select, .um-password button').attr('disabled', 'disabled'); + jQuery('.um-password a').attr('href', ''); + }); + }); + }); + + observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); + +}); + +function unselectEmptyOption( e ) { + var $element = jQuery( e.currentTarget ); + var $selected = $element.find(':selected'); + + if ( $selected.length > 1 ) { + $selected.each( function ( i, option ) { + if ( option.value === '' ) { + option.selected = false; + $element.trigger( 'change' ); + } + }); + } +}`` diff --git a/includes/admin/assets/js/um-admin-blocks-shortcode.js b/includes/admin/assets/js/um-admin-blocks-shortcode.js deleted file mode 100644 index 88038cf3..00000000 --- a/includes/admin/assets/js/um-admin-blocks-shortcode.js +++ /dev/null @@ -1,405 +0,0 @@ -//-------------------------------------\\ -//--------- Um Forms shortcode --------\\ -//-------------------------------------\\ - -wp.blocks.registerBlockType( 'um-block/um-forms', { - title: wp.i18n.__( 'Form', 'ultimate-member' ), - description: wp.i18n.__( 'Choose display form', 'ultimate-member' ), - icon: 'forms', - category: 'um-blocks', - attributes: { - content: { - source: 'html', - selector: 'p' - }, - form_id: { - type: 'select' - } - }, - - edit: wp.data.withSelect( function( select ) { - return { - posts: select( 'core' ).getEntityRecords( 'postType', 'um_form', { - per_page: -1 - }) - }; - } )( function( props ) { - var posts = props.posts, - className = props.className, - attributes = props.attributes, - setAttributes = props.setAttributes, - form_id = props.attributes.form_id, - content = props.attributes.content; - - function get_option( posts ) { - - var option = []; - - posts.map( function( post ) { - option.push( - { - label: post.title.rendered, - value: post.id - } - ); - }); - - return option; - } - - function umShortcode( value ) { - - var shortcode = ''; - - if ( value !== undefined ) { - shortcode = '[ultimatemember form_id="' + value + '"]'; - } - - return shortcode; - } - - - if ( ! posts ) { - return wp.element.createElement( - 'p', - { - className: className - }, - wp.element.createElement( - wp.components.Spinner, - null - ), - wp.i18n.__( 'Loading Forms', 'ultimate-member' ) - ); - } - - if ( 0 === posts.length ) { - return wp.element.createElement( - 'p', - null, - wp.i18n.__( 'No Posts', 'ultimate-member' ) - ); - } - - if ( form_id === undefined ) { - props.setAttributes({ form_id: posts[0]['id'] }); - var shortcode = umShortcode( posts[0]['id'] ); - props.setAttributes( { content: shortcode } ); - } - - var get_post = get_option( posts ); - - return wp.element.createElement( - 'div', - { - className: className - }, - wp.element.createElement( - wp.components.SelectControl, - { - label: wp.i18n.__( 'Select Forms', 'ultimate-member' ), - className: 'um_select_forms', - type: 'number', - value: form_id, - options: get_post, - onChange: function onChange( value ) { - props.setAttributes({ form_id: value }); - var shortcode = umShortcode( value ); - props.setAttributes( { content: shortcode } ); - } - } - ) - ); - } // end withSelect - ), // end edit - - save: function save( props ) { - - return wp.element.createElement( - wp.editor.RichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } - -}); - - -//-------------------------------------\\ -//-- Um Member Directories shortcode --\\ -//-------------------------------------\\ - -wp.blocks.registerBlockType( 'um-block/um-member-directories', { - title: wp.i18n.__( 'Member Directory', 'ultimate-member' ), - description: wp.i18n.__( 'Choose display directory', 'ultimate-member' ), - icon: 'groups', - category: 'um-blocks', - attributes: { - content: { - source: 'html', - selector: 'p' - }, - member_id: { - type: 'select' - } - }, - - edit: wp.data.withSelect( function( select ) { - return { - posts: select( 'core' ).getEntityRecords( 'postType', 'um_directory', { - per_page: -1 - }) - }; - } )( function( props ) { - var posts = props.posts, - className = props.className, - attributes = props.attributes, - setAttributes = props.setAttributes, - member_id = props.attributes.member_id, - content = props.attributes.content; - - function get_option( posts ) { - var option = []; - - posts.map( function( post ) { - option.push( - { - label: post.title.rendered, - value: post.id - } - ); - }); - - return option; - } - - function umShortcode( value ) { - - var shortcode = ''; - - if ( value !== undefined ) { - shortcode = '[ultimatemember form_id="' + value + '"]'; - } - - return shortcode; - } - - if ( ! posts ) { - return wp.element.createElement( - 'p', - { - className: className - }, - wp.element.createElement( - wp.components.Spinner, - null - ), - wp.i18n.__( 'Loading Forms', 'ultimate-member' ) - ); - } - - if ( 0 === posts.length ) { - return wp.element.createElement( - 'p', - null, - wp.i18n.__( 'No Posts', 'ultimate-member' ) - ); - } - - if ( member_id === undefined ) { - props.setAttributes({ member_id: posts[0]['id'] }); - var shortcode = umShortcode(posts[0]['id']); - props.setAttributes( { content: shortcode } ); - } - - var get_post = get_option( posts ); - - return wp.element.createElement( - 'div', - { - className: className - }, - wp.element.createElement( - wp.components.SelectControl, - { - label: wp.i18n.__( 'Select Directories', 'ultimate-member' ), - className: 'um_select_directory', - type: 'number', - value: member_id, - options: get_post, - onChange: function onChange( value ) { - props.setAttributes({ member_id: value }); - var shortcode = umShortcode(value); - props.setAttributes( { content: shortcode } ); - } - } - ) - ); - } // end withSelect - ), // end edit - - save: function save( props ) { - - return wp.element.createElement( - wp.editor.RichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } - -}); - -//-------------------------------------\\ -//--------- Um password reset ---------\\ -//-------------------------------------\\ -wp.blocks.registerBlockType( 'um-block/um-password-reset', { - title: wp.i18n.__( 'Password Reset', 'ultimate-member' ), - description: wp.i18n.__( 'Displaying the password reset form', 'ultimate-member' ), - icon: 'unlock', - category: 'um-blocks', - attributes: { - content: { - source: 'html', - selector: 'p' - } - }, - - edit: function( props ) { - var content = props.attributes.content; - props.setAttributes({ content: '[ultimatemember_password]' }); - - return [ - wp.element.createElement( - "div", - { - className: "um-password-reset-wrapper" - }, - wp.i18n.__( 'Password Reset', 'ultimate-member' ) - ) - ] - }, - - save: function( props ) { - - return wp.element.createElement( - wp.editor.RichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } -}); - -//-------------------------------------\\ -//------------ Um Account -------------\\ -//-------------------------------------\\ -wp.blocks.registerBlockType( 'um-block/um-account', { - title: wp.i18n.__( 'Account', 'ultimate-member' ), - description: wp.i18n.__( 'Displaying the account page of the current user', 'ultimate-member' ), - icon: 'id', - category: 'um-blocks', - attributes: { - content: { - source: 'html', - selector: 'p' - }, - tab: { - type: 'select' - } - }, - - edit: function( props ) { - var content = props.attributes.content, - tab = props.attributes.tab; - - function get_options() { - var option = []; - - option.push( { label: wp.i18n.__( 'All', 'ultimate-member' ), value: 'all' } ); - - for ( var key in um_account_settings ) { - if ( um_account_settings.hasOwnProperty( key ) && um_account_settings[ key ]['enabled'] ) { - option.push( - { - label: um_account_settings[ key ]['label'], - value: key - } - ) - } - } - - return option; - } - - function umShortcode( value ) { - - var shortcode = '[ultimatemember_account'; - - if ( value !== 'all' ) { - shortcode = shortcode + ' tab="' + value + '"'; - } - - shortcode = shortcode + ']'; - - props.setAttributes({ content: shortcode }); - } - - if ( content === undefined ) { - props.setAttributes({ content: '[ultimatemember_account]' }); - } - - return [ - wp.element.createElement( - "div", - { - className: 'um-account-wrapper' - }, - wp.i18n.__( 'Account', 'ultimate-member' ) - ), - wp.element.createElement( - wp.blockEditor.InspectorControls, - {}, - wp.element.createElement( - wp.components.PanelBody, - { - title: wp.i18n.__( 'Account Tab', 'ultimate-member' ) - }, - wp.element.createElement( - wp.components.SelectControl, - { - label: wp.i18n.__( 'Select Tab', 'ultimate-member' ), - className: "um_select_account_tab", - type: 'number', - value: props.attributes.tab, - options: get_options(), - onChange: function onChange( value ) { - props.setAttributes({ tab: value }); - umShortcode( value ); - } - } - ) - ) - ) - ] - }, - - save: function( props ) { - - return wp.element.createElement( - wp.editor.RichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } -}); \ No newline at end of file diff --git a/includes/admin/assets/js/um-admin-blocks.js b/includes/admin/assets/js/um-admin-blocks.js index f6161b61..2f3ec381 100644 --- a/includes/admin/assets/js/um-admin-blocks.js +++ b/includes/admin/assets/js/um-admin-blocks.js @@ -1,7 +1,7 @@ 'use strict'; -var um_components = wp.components, - umSelectControl = um_components.SelectControl, +var um_components = wp.components, + umSelectControl = um_components.SelectControl, umTextareaControl = um_components.TextareaControl; @@ -9,227 +9,189 @@ 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' - }; +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 ); + um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_default', um_condition_fields ); - return function( props ) { + 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'; + 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 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'] = ''; + um_condition_fields['um_who_access'] = ''; - if ( parseInt( props.attributes.um_message_type ) === 2 ) { - um_condition_fields['um_message_content'] = ''; - } else { + 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 ); + 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, + return wp.element.createElement( + wp.element.Fragment, {}, + wp.element.createElement( BlockEdit, props ), wp.element.createElement( - wp.components.PanelBody, - { - title: wp.i18n.__( 'Ultimate Member: Content Restriction', 'ultimate-member' ), - className: 'um_block_settings' - }, + wp.blockEditor.InspectorControls, + {}, wp.element.createElement( - wp.components.ToggleControl, + wp.components.PanelBody, { - label: wp.i18n.__( 'Restrict access?', 'ultimate-member' ), - checked: props.attributes.um_is_restrict, - 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'] = ''; - } + 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 ); + 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'; - } + ), + 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'; + um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_on_change', um_condition_fields, 'um_who_access', value ); } } - } - ), - 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 }); + ), + 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 } ); + } } - } - ), - um_admin_blocks_custom_fields( um_condition_fields, props ) + ), + 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' ); + ); + }; + }, + 'um_block_restriction' +); wp.hooks.addFilter( 'editor.BlockEdit', 'um-block/um_block_restriction', um_block_restriction ); - - -/** - * Save Attributes - * - * @type {{um_is_restrict: {type: string}, um_who_access: {type: string}, um_message_type: {type: string}, um_message_content: {type: string}}} - */ -var um_block_restrict_settings = { - um_is_restrict: { - type: "boolean" - }, - um_who_access: { - type: "select" - }, - um_roles_access: { - type: "select" - }, - um_message_type: { - type: "select" - }, - um_message_content: { - type: "string" - } -}; - -um_block_restrict_settings = wp.hooks.applyFilters( 'um_admin_blocks_restrict_settings', um_block_restrict_settings ); - - -/** - * - * @param settings - * @returns {*} - */ -function um_add_block_attributes( settings ) { - var _lodash = lodash, - assign = _lodash.assign; - - settings.attributes = assign( settings.attributes, um_block_restrict_settings ); - return settings; -} - -wp.hooks.addFilter( 'blocks.registerBlockType', 'um-block/um_add_block_attributes', um_add_block_attributes ); diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index 659cfaa7..b3f5669a 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -1,8 +1,9 @@ js_url = um_url . 'includes/admin/assets/js/'; + public function __construct() { + $this->js_url = um_url . 'includes/admin/assets/js/'; $this->css_url = um_url . 'includes/admin/assets/css/'; - $this->front_js_baseurl = um_url . 'assets/js/'; + $this->front_js_baseurl = um_url . 'assets/js/'; $this->front_css_baseurl = um_url . 'assets/css/'; $this->suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'UM_SCRIPT_DEBUG' ) ) ? '' : '.min'; @@ -73,7 +74,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { add_action( 'admin_head', array( &$this, 'admin_head' ), 9 ); - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); + add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); add_filter( 'enter_title_here', array( &$this, 'enter_title_here' ) ); @@ -89,20 +90,135 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { } else { add_filter( 'block_categories', array( &$this, 'blocks_category' ), 10, 2 ); } + add_action( 'enqueue_block_assets', array( &$this, 'block_editor' ), 11 ); } - function enqueue_role_wrapper() { - add_action( 'admin_enqueue_scripts', array( &$this, 'load_role_wrapper' ) ); + /** + * Enqueue Gutenberg Block Editor assets + */ + public function block_editor() { + wp_register_style( 'um_ui', um_url . 'assets/css/jquery-ui.css', array(), ultimatemember_version ); + wp_register_style( 'um_members', um_url . 'assets/css/um-members.css', array( 'um_ui' ), ultimatemember_version ); + if ( is_rtl() ) { + wp_register_style( 'um_members_rtl', um_url . 'assets/css/um-members-rtl.css', array( 'um_members' ), ultimatemember_version ); + } + wp_register_style( 'um_styles', um_url . 'assets/css/um-styles.css', array(), ultimatemember_version ); + wp_register_style( 'um_profile', um_url . 'assets/css/um-profile.css', array(), ultimatemember_version ); + wp_register_style( 'um_crop', um_url . 'assets/css/um-crop.css', array(), ultimatemember_version ); + wp_register_style( 'um_responsive', um_url . 'assets/css/um-responsive.css', array( 'um_profile', 'um_crop' ), ultimatemember_version ); + wp_register_style( 'um_account', um_url . 'assets/css/um-account.css', array(), ultimatemember_version ); + wp_register_style( 'um_default_css', um_url . 'assets/css/um-old-default.css', array(), ultimatemember_version ); + wp_register_style( 'um_fonticons_fa', um_url . 'assets/css/um-fonticons-fa.css', array(), ultimatemember_version ); + wp_register_style( 'select2', um_url . 'assets/css/select2/select2' . $this->suffix . '.css', array(), ultimatemember_version ); + wp_register_style( 'um_fonticons_ii', um_url . 'assets/css/um-fonticons-ii.css', array(), ultimatemember_version ); + + wp_register_script( 'um_admin_blocks_shortcodes', um_url . 'assets/js/um-blocks' . $this->suffix . '.js', array( 'wp-i18n', 'wp-blocks', 'wp-components' ), ultimatemember_version, true ); + wp_set_script_translations( 'jb_admin_blocks_shortcodes', 'ultimate-member' ); + + if ( ! empty( UM()->account()->get_tab_fields( 'notifications', array() ) ) ) { + $notifications_enabled = 1; + } else { + $notifications_enabled = 0; + } + + $um_account_settings = array( + 'general' => array( + 'label' => __( 'General', 'ultimate-member' ), + 'enabled' => 1, + ), + 'password' => array( + 'label' => __( 'Password', 'ultimate-member' ), + 'enabled' => UM()->options()->get( 'account_tab_password' ), + ), + 'privacy' => array( + 'label' => __( 'Privacy', 'ultimate-member' ), + 'enabled' => UM()->options()->get( 'account_tab_privacy' ), + ), + 'notifications' => array( + 'label' => __( 'Notifications', 'ultimate-member' ), + 'enabled' => $notifications_enabled, + ), + 'delete' => array( + 'label' => __( 'Delete', 'ultimate-member' ), + 'enabled' => UM()->options()->get( 'account_tab_delete' ), + ), + ); + $um_account_settings = apply_filters( 'um_extend_account_settings', $um_account_settings ); + wp_localize_script( 'um_admin_blocks_shortcodes', 'um_account_settings', $um_account_settings ); + + wp_enqueue_script( 'um_admin_blocks_shortcodes' ); + + wp_register_script( 'select2', um_url . 'assets/js/select2/select2.full' . $this->suffix . '.js', array( 'jquery', 'jquery-masonry' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime', um_url . 'assets/js/pickadate/picker.js', array( 'jquery' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_date', um_url . 'assets/js/pickadate/picker.date.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_time', um_url . 'assets/js/pickadate/picker.time.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_conditional', um_url . 'assets/js/um-conditional' . $this->suffix . '.js', array( 'jquery', 'wp-hooks' ), ultimatemember_version, true ); + wp_register_script( 'um_scripts', um_url . 'assets/js/um-scripts' . $this->suffix . '.js', array( 'jquery', 'wp-util', 'um_conditional', 'um_datetime', 'um_datetime_date', 'um_datetime_time', 'select2' ), ultimatemember_version, true ); + $max_upload_size = wp_max_upload_size(); + if ( ! $max_upload_size ) { + $max_upload_size = 0; + } + + $localize_data = apply_filters( + 'um_enqueue_localize_data', + array( + 'max_upload_size' => $max_upload_size, + 'nonce' => wp_create_nonce( 'um-frontend-nonce' ), + ) + ); + wp_localize_script( 'um_scripts', 'um_scripts', $localize_data ); + + wp_register_script( 'um_dropdown', um_url . 'assets/js/dropdown' . $this->suffix . '.js', array( 'jquery' ), ultimatemember_version, true ); + wp_register_script( 'um_members', um_url . 'assets/js/um-members' . $this->suffix . '.js', array( 'jquery', 'wp-util', 'jquery-ui-slider', 'um_dropdown', 'wp-hooks', 'jquery-masonry', 'um_scripts' ), ultimatemember_version, true ); + + wp_register_script( 'um_account', um_url . 'assets/js/um-account' . $this->suffix . '.js', array( 'jquery', 'wp-hooks' ), ultimatemember_version, true ); + wp_register_script( 'um_scrollbar', um_url . 'assets/js/simplebar' . $this->suffix . '.js', array( 'jquery' ), ultimatemember_version, true ); + wp_register_script( 'um_crop', um_url . 'assets/js/um-crop' . $this->suffix . '.js', array( 'jquery' ), ultimatemember_version, true ); + wp_register_script( 'um_functions', um_url . 'assets/js/um-functions' . $this->suffix . '.js', array( 'jquery', 'jquery-masonry', 'wp-util', 'um_scrollbar' ), ultimatemember_version, true ); + wp_register_script( 'um_responsive', um_url . 'assets/js/um-responsive' . $this->suffix . '.js', array( 'jquery', 'um_functions', 'um_crop' ), ultimatemember_version, true ); + + // render blocks + wp_enqueue_script( 'um_datetime' ); + wp_enqueue_script( 'um_datetime_date' ); + wp_enqueue_script( 'um_datetime_time' ); + wp_enqueue_script( 'um_conditional' ); + wp_enqueue_script( 'um_dropdown' ); + wp_enqueue_script( 'um_members' ); + wp_enqueue_script( 'um_account' ); + wp_enqueue_script( 'um_scrollbar' ); + wp_enqueue_script( 'um_crop' ); + wp_enqueue_script( 'um_functions' ); + wp_enqueue_script( 'um_responsive' ); + + wp_enqueue_style( 'um_fonticons_ii' ); + wp_enqueue_style( 'select2' ); + wp_enqueue_style( 'um_default_css' ); + wp_enqueue_style( 'um_fonticons_fa' ); + wp_enqueue_style( 'um_members' ); + wp_enqueue_style( 'um_styles' ); + wp_enqueue_style( 'um_profile' ); + wp_enqueue_style( 'um_crop' ); + wp_enqueue_style( 'um_responsive' ); + wp_enqueue_style( 'um_account' ); + + $custom_css = '.um{opacity: 1;}.um_request_name {display: none !important;}'; + + wp_add_inline_style( 'um_styles', $custom_css ); + } + + + public function enqueue_role_wrapper() { + add_action( 'admin_enqueue_scripts', array( &$this, 'load_role_wrapper' ) ); } /** * */ - function enqueue_cpt_scripts() { - if ( ( isset( $_GET['post_type'] ) && 'um_form' === sanitize_key( $_GET['post_type'] ) ) || - ( isset( $_GET['post'] ) && 'um_form' === get_post_type( absint( $_GET['post'] ) ) ) ) { + public function enqueue_cpt_scripts() { + // phpcs:ignore WordPress.Security.NonceVerification + if ( ( isset( $_GET['post_type'] ) && 'um_form' === sanitize_key( $_GET['post_type'] ) ) || ( isset( $_GET['post'] ) && 'um_form' === get_post_type( absint( $_GET['post'] ) ) ) ) { $this->um_cpt_form_screen = true; add_action( 'admin_footer', array( $this, 'admin_footer_scripts' ), 20 ); } @@ -112,7 +228,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * */ - function enqueue_frontend_preview_assets() { + public function enqueue_frontend_preview_assets() { //scripts for FRONTEND PREVIEW if ( class_exists( 'WooCommerce' ) ) { wp_dequeue_style( 'select2' ); @@ -122,7 +238,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_deregister_script( 'select2' ); } - wp_register_script( 'select2', $this->front_js_baseurl . 'select2/select2.full' . $this->suffix . '.js', array( 'jquery', 'jquery-masonry' ), '4.0.13', true ); wp_register_script( 'um_jquery_form', $this->front_js_baseurl . 'um-jquery-form' . $this->suffix . '.js', array( 'jquery' ), ultimatemember_version, true ); wp_register_script( 'um_fileupload', $this->front_js_baseurl . 'um-fileupload.js', array( 'jquery' ), ultimatemember_version, true ); @@ -138,9 +253,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { $locale = get_locale(); if ( $locale ) { if ( file_exists( WP_LANG_DIR . '/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js' ) ) { - wp_register_script('um_datetime_locale', content_url() . '/languages/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_locale', content_url() . '/languages/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); } elseif ( file_exists( um_path . 'assets/js/pickadate/translations/' . $locale . '.js' ) ) { - wp_register_script('um_datetime_locale', um_url . 'assets/js/pickadate/translations/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_locale', um_url . 'assets/js/pickadate/translations/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); } } @@ -148,7 +263,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_script( 'um_responsive', $this->front_js_baseurl . 'um-responsive' . $this->suffix . '.js', array( 'um_scripts' ), ultimatemember_version, true ); wp_register_script( 'um_modal', $this->front_js_baseurl . 'um-modal' . $this->suffix . '.js', array( 'um_responsive' ), ultimatemember_version, true ); - wp_register_style( 'select2', $this->front_css_baseurl . 'select2/select2' . $this->suffix . '.css', array(), '4.0.13' ); wp_register_style( 'um_datetime', $this->front_css_baseurl . 'pickadate/default.css', array(), ultimatemember_version ); wp_register_style( 'um_datetime_date', $this->front_css_baseurl . 'pickadate/default.date.css', array( 'um_datetime' ), ultimatemember_version ); @@ -174,7 +288,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load js for Add/Edit User form */ - function load_role_wrapper() { + public function load_role_wrapper() { wp_register_script( 'um_admin_role_wrapper', $this->js_url . 'um-admin-role-wrapper.js', array( 'jquery' ), ultimatemember_version, true ); $localize_roles_data = get_option( 'um_roles', array() ); wp_localize_script( 'um_admin_role_wrapper', 'um_roles', (array) $localize_roles_data ); @@ -189,11 +303,11 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { * * @return string */ - function enter_title_here( $title ) { + public function enter_title_here( $title ) { $screen = get_current_screen(); - if ( 'um_directory' == $screen->post_type ) { + if ( 'um_directory' === $screen->post_type ) { $title = __( 'e.g. Member Directory', 'ultimate-member' ); - } elseif ( 'um_form' == $screen->post_type ) { + } elseif ( 'um_form' === $screen->post_type ) { $title = __( 'e.g. New Registration Form', 'ultimate-member' ); } return $title; @@ -203,7 +317,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Runs on admin head */ - function admin_head() { + public function admin_head() { if ( UM()->admin()->is_plugin_post_type() ) { ?> - css_url . 'um-admin-form.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_admin_form' ); @@ -230,7 +345,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Forms */ - function load_forms() { + public function load_forms() { if ( class_exists( 'WooCommerce' ) ) { wp_dequeue_style( 'select2' ); wp_deregister_style( 'select2' ); @@ -248,9 +363,20 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_script( 'um_admin_forms', $this->js_url . 'um-admin-forms.js', array( 'jquery', 'wp-i18n', 'select2' ), ultimatemember_version, true ); - wp_localize_script( 'um_admin_forms', 'um_forms_data', array( - 'successfully_redirect' => add_query_arg( array( 'page' => 'um_options', 'tab' => 'misc', 'msg' => 'updated' ), admin_url( 'admin.php' ) ), - ) ); + wp_localize_script( + 'um_admin_forms', + 'um_forms_data', + array( + 'successfully_redirect' => add_query_arg( + array( + 'page' => 'um_options', + 'tab' => 'misc', + 'msg' => 'updated', + ), + admin_url( 'admin.php' ) + ), + ) + ); wp_enqueue_script( 'um_admin_forms' ); } @@ -259,7 +385,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load dashboard */ - function load_dashboard() { + public function load_dashboard() { wp_register_style( 'um_admin_dashboard', $this->css_url . 'um-admin-dashboard.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_admin_dashboard' ); } @@ -268,7 +394,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load settings */ - function load_settings() { + public function load_settings() { wp_register_style( 'um_admin_settings', $this->css_url . 'um-admin-settings.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_admin_settings' ); @@ -280,7 +406,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load modal */ - function load_modal() { + public function load_modal() { wp_register_style( 'um_admin_modal', $this->css_url . 'um-admin-modal.css', array( 'wp-color-picker' ), ultimatemember_version ); wp_enqueue_style( 'um_admin_modal' ); @@ -292,8 +418,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Field Processing */ - function load_field() { - wp_register_script( 'um_admin_field', $this->js_url . 'um-admin-field.js', array('jquery', 'wp-util', 'wp-i18n'), ultimatemember_version, true ); + public function load_field() { + wp_register_script( 'um_admin_field', $this->js_url . 'um-admin-field.js', array( 'jquery', 'wp-util', 'wp-i18n' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_field' ); } @@ -301,8 +427,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Builder */ - function load_builder() { - wp_register_script( 'um_admin_builder', $this->js_url . 'um-admin-builder.js', array('jquery', 'wp-util'), ultimatemember_version, true ); + public function load_builder() { + wp_register_script( 'um_admin_builder', $this->js_url . 'um-admin-builder.js', array( 'jquery', 'wp-util' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_builder' ); //hide footer text on add/edit UM Forms @@ -310,9 +436,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { //and WP calculate page height $hide_footer = false; global $pagenow, $post; - if ( ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) && - ( ( isset( $_GET['post_type'] ) && 'um_form' === sanitize_key( $_GET['post_type'] ) ) || - ( isset( $post->post_type ) && 'um_form' === $post->post_type ) ) ) { + // phpcs:ignore WordPress.Security.NonceVerification + if ( ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) && ( ( isset( $_GET['post_type'] ) && 'um_form' === sanitize_key( $_GET['post_type'] ) ) || ( isset( $post->post_type ) && 'um_form' === $post->post_type ) ) ) { $hide_footer = true; } @@ -321,7 +446,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { ); wp_localize_script( 'um_admin_builder', 'um_admin_builder_data', $localize_data ); - wp_register_script( 'um_admin_dragdrop', $this->js_url . 'um-admin-dragdrop.js', array('jquery', 'wp-util'), ultimatemember_version, true ); + wp_register_script( 'um_admin_dragdrop', $this->js_url . 'um-admin-dragdrop.js', array( 'jquery', 'wp-util' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_dragdrop' ); wp_register_style( 'um_admin_builder', $this->css_url . 'um-admin-builder.css', array(), ultimatemember_version ); @@ -332,7 +457,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load core WP styles/scripts */ - function load_core_wp() { + public function load_core_wp() { wp_enqueue_script( 'jquery-ui-draggable' ); wp_enqueue_script( 'jquery-ui-sortable' ); @@ -343,7 +468,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Admin Styles */ - function load_css() { + public function load_css() { wp_register_style( 'um_admin_menu', $this->css_url . 'um-admin-menu.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_admin_menu' ); @@ -358,7 +483,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load functions js */ - function load_functions() { + public function load_functions() { wp_register_script( 'um_scrollbar', um_url . 'assets/js/simplebar.js', array( 'jquery' ), ultimatemember_version, true ); wp_register_script( 'um_functions', um_url . 'assets/js/um-functions.js', array( 'jquery', 'jquery-masonry', 'wp-util', 'um_scrollbar' ), ultimatemember_version, true ); wp_enqueue_script( 'um_functions' ); @@ -368,7 +493,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Fonticons */ - function load_fonticons() { + public function load_fonticons() { wp_register_style( 'um_fonticons_ii', um_url . 'assets/css/um-fonticons-ii.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_fonticons_ii' ); @@ -380,8 +505,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load global css */ - function load_global_scripts() { - wp_register_script( 'um_admin_global', $this->js_url . 'um-admin-global.js', array('jquery'), ultimatemember_version, true ); + public function load_global_scripts() { + wp_register_script( 'um_admin_global', $this->js_url . 'um-admin-global.js', array( 'jquery' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_global' ); wp_register_style( 'um_admin_global', $this->css_url . 'um-admin-global.css', array(), ultimatemember_version ); @@ -392,7 +517,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load jQuery custom code */ - function load_custom_scripts() { + public function load_custom_scripts() { wp_register_script( 'um_datetime', $this->front_js_baseurl . 'pickadate/picker.js', array( 'jquery' ), ultimatemember_version, true ); wp_register_script( 'um_datetime_date', $this->front_js_baseurl . 'pickadate/picker.date.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); wp_register_script( 'um_datetime_time', $this->front_js_baseurl . 'pickadate/picker.time.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); @@ -401,9 +526,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { $locale = get_locale(); if ( $locale ) { if ( file_exists( WP_LANG_DIR . '/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js' ) ) { - wp_register_script('um_datetime_locale', content_url() . '/languages/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_locale', content_url() . '/languages/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); } elseif ( file_exists( um_path . 'assets/js/pickadate/translations/' . $locale . '.js' ) ) { - wp_register_script('um_datetime_locale', um_url . 'assets/js/pickadate/translations/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_locale', um_url . 'assets/js/pickadate/translations/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); } } @@ -411,9 +536,10 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_style( 'um_datetime_date', $this->front_css_baseurl . 'pickadate/default.date.css', array( 'um_datetime' ), ultimatemember_version ); wp_register_style( 'um_datetime_time', $this->front_css_baseurl . 'pickadate/default.time.css', array( 'um_datetime' ), ultimatemember_version ); - wp_enqueue_style( 'um_datetime_date', 'um_datetime_time' ); + wp_enqueue_style( 'um_datetime_date' ); + wp_enqueue_style( 'um_datetime_time' ); - wp_register_script( 'um_admin_scripts', $this->js_url . 'um-admin-scripts.js', array('jquery','wp-util', 'wp-color-picker', 'um_datetime', 'um_datetime_date', 'um_datetime_time'/*, 'um_datetime_legacy'*/ ), ultimatemember_version, true ); + wp_register_script( 'um_admin_scripts', $this->js_url . 'um-admin-scripts.js', array( 'jquery', 'wp-util', 'wp-color-picker', 'um_datetime', 'um_datetime_date', 'um_datetime_time'/*, 'um_datetime_legacy'*/ ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_scripts' ); } @@ -421,8 +547,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load jQuery custom code */ - function load_nav_manus_scripts() { - wp_register_script( 'um_admin_nav_manus', $this->js_url . 'um-admin-nav-menu.js', array('jquery','wp-util'), ultimatemember_version, true ); + public function load_nav_manus_scripts() { + wp_register_script( 'um_admin_nav_manus', $this->js_url . 'um-admin-nav-menu.js', array( 'jquery', 'wp-util' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_nav_manus' ); } @@ -430,8 +556,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load AJAX */ - function load_ajax_js() { - wp_register_script( 'um_admin_ajax', $this->js_url . 'um-admin-ajax.js', array('jquery','wp-util'), ultimatemember_version, true ); + public function load_ajax_js() { + wp_register_script( 'um_admin_ajax', $this->js_url . 'um-admin-ajax.js', array( 'jquery', 'wp-util' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_ajax' ); } @@ -439,7 +565,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Gutenberg scripts */ - function load_gutenberg_js() { + public function load_gutenberg_js() { //disable Gutenberg scripts to avoid the conflicts $disable_script = apply_filters( 'um_disable_blocks_script', false ); if ( $disable_script ) { @@ -455,12 +581,12 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_set_script_translations( 'um_block_js', 'ultimate-member' ); $restrict_options = array(); - $roles = UM()->roles()->get_roles( false ); + $roles = UM()->roles()->get_roles( false ); if ( ! empty( $roles ) ) { foreach ( $roles as $role_key => $title ) { $restrict_options[] = array( 'label' => $title, - 'value' => $role_key + 'value' => $role_key, ); } } @@ -472,71 +598,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { } - /** - * Load Gutenberg blocks js - */ - function load_gutenberg_shortcode_blocks() { - if ( ! function_exists( 'register_block_type' ) ) { - // Gutenberg is not active. - return; - } - - //disable Gutenberg scripts to avoid the conflicts - $disable_script = apply_filters( 'um_disable_blocks_script', false ); - if ( $disable_script ) { - return; - } - - $enable_blocks = UM()->options()->get( 'enable_blocks' ); - if ( empty( $enable_blocks ) ) { - return; - } - - wp_register_script( 'um-blocks-shortcode-js', $this->js_url . 'um-admin-blocks-shortcode.js', array( 'wp-i18n', 'wp-blocks', 'wp-components', /*'rich-text'*/ ), ultimatemember_version, true ); - wp_set_script_translations( 'um-blocks-shortcode-js', 'ultimate-member' ); - wp_enqueue_script( 'um-blocks-shortcode-js' ); - - $account_settings = array( - 'password' => array( - 'label' => __( 'Password', 'ultimate-member' ), - 'enabled' => UM()->options()->get( 'account_tab_password' ), - ), - 'privacy' => array( - 'label' => __( 'Privacy', 'ultimate-member' ), - 'enabled' => UM()->options()->get( 'account_tab_privacy' ), - ), - 'notifications' => array( - 'label' => __( 'Notifications', 'ultimate-member' ), - 'enabled' => UM()->options()->get( 'account_tab_notifications' ), - ), - 'delete' => array( - 'label' => __( 'Delete', 'ultimate-member' ), - 'enabled' => UM()->options()->get( 'account_tab_delete' ), - ), - ); - wp_localize_script( 'um-blocks-shortcode-js', 'um_account_settings', $account_settings ); - - /** - * create gutenberg blocks - */ - register_block_type( 'um-block/um-forms', array( - 'editor_script' => 'um-blocks-shortcode-js', - ) ); - - register_block_type( 'um-block/um-member-directories', array( - 'editor_script' => 'um-blocks-shortcode-js', - ) ); - - register_block_type( 'um-block/um-password-reset', array( - 'editor_script' => 'um-blocks-shortcode-js', - ) ); - - register_block_type( 'um-block/um-account', array( - 'editor_script' => 'um-blocks-shortcode-js', - ) ); - } - - /** * Add Gutenberg category for UM shortcodes * @@ -545,27 +606,27 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { * * @return array */ - function blocks_category( $categories, $context ) { - $enable_blocks = UM()->options()->get( 'enable_blocks' ); - if ( empty( $enable_blocks ) ) { - return $categories; - } + public function blocks_category( $categories, $context ) { + $enable_blocks = UM()->options()->get( 'enable_blocks' ); + if ( empty( $enable_blocks ) ) { + return $categories; + } - return array_merge( - $categories, - array( - array( - 'slug' => 'um-blocks', - 'title' => __( 'Ultimate Member Blocks', 'ultimate-member' ), - ), - ) - ); - } + return array_merge( + $categories, + array( + array( + 'slug' => 'um-blocks', + 'title' => __( 'Ultimate Member Blocks', 'ultimate-member' ), + ), + ) + ); + } /** * Load localize scripts */ - function load_localize_scripts() { + public function load_localize_scripts() { /** * UM hook @@ -587,10 +648,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { * } * ?> */ - $localize_data = apply_filters( 'um_admin_enqueue_localize_data', array( - 'nonce' => wp_create_nonce( "um-admin-nonce" ) - ) - ); + $localize_data = apply_filters( 'um_admin_enqueue_localize_data', array( 'nonce' => wp_create_nonce( 'um-admin-nonce' ) ) ); wp_localize_script( 'um_admin_global', 'um_admin_scripts', $localize_data ); } @@ -599,7 +657,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Enqueue scripts and styles */ - function admin_enqueue_scripts() { + public function admin_enqueue_scripts() { if ( UM()->admin()->is_um_screen() ) { /*if ( get_post_type() != 'shop_order' ) { @@ -628,7 +686,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { $this->load_fonticons(); $this->load_localize_scripts(); - //scripts for frontend preview UM()->enqueue()->load_imagecrop(); UM()->enqueue()->load_css(); @@ -646,7 +703,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_style( 'um_admin_rtl', $this->css_url . 'um-admin-rtl.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_admin_rtl' ); } - } else { $this->load_global_scripts(); @@ -659,7 +715,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { if ( version_compare( $wp_version, '5.0', '>=' ) ) { if ( isset( $current_screen ) && $current_screen->is_block_editor() ) { $this->load_gutenberg_js(); - $this->load_gutenberg_shortcode_blocks(); } } } @@ -668,7 +723,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Print editor scripts if they are not printed by default */ - function admin_footer_scripts() { + public function admin_footer_scripts() { /** * @var $class \_WP_Editors */ diff --git a/includes/blocks/um-account/block.json b/includes/blocks/um-account/block.json new file mode 100644 index 00000000..2085aec7 --- /dev/null +++ b/includes/blocks/um-account/block.json @@ -0,0 +1,15 @@ +{ + "apiVersion": 2, + "name": "um-block/um-account", + "title": "Account", + "description": "Displaying the account page of the current user", + "icon": "id", + "category": "um-blocks", + "attributes": { + "tab": { + "type": "string" + } + }, + "editorScript": "file:./build/index.js", + "textdomain": "ultimate-member" +} diff --git a/includes/blocks/um-account/build/index.asset.php b/includes/blocks/um-account/build/index.asset.php new file mode 100644 index 00000000..cf48a0d1 --- /dev/null +++ b/includes/blocks/um-account/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-server-side-render'), 'version' => '98a99fd44cd9deb95734'); diff --git a/includes/blocks/um-account/build/index.js b/includes/blocks/um-account/build/index.js new file mode 100644 index 00000000..d8d1e5fe --- /dev/null +++ b/includes/blocks/um-account/build/index.js @@ -0,0 +1 @@ +(()=>{"use strict";var t={n:e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return t.d(n,{a:n}),n},d:(e,n)=>{for(var a in n)t.o(n,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:n[a]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=window.wp.element,n=window.wp.blocks,a=window.wp.serverSideRender;var o=t.n(a);const u=window.wp.blockEditor,r=window.wp.components;(0,n.registerBlockType)("um-block/um-account",{edit:function(t){let{tab:n,setAttributes:a}=t.attributes;const c=(0,u.useBlockProps)();return(0,e.createElement)("div",c,(0,e.createElement)(o(),{block:"um-block/um-account",attributes:t.attributes}),(0,e.createElement)(u.InspectorControls,null,(0,e.createElement)(r.PanelBody,{title:wp.i18n.__("Account Tab","ultimate-member")},(0,e.createElement)(r.SelectControl,{label:wp.i18n.__("Select Tab","ultimate-member"),className:"um_select_account_tab",value:n,options:function(){var t=[];for(var e in t.push({label:wp.i18n.__("All","ultimate-member"),value:"all"}),um_account_settings)um_account_settings.hasOwnProperty(e)&&um_account_settings[e].enabled&&t.push({label:um_account_settings[e].label,value:e});return t}(),style:{height:"35px",lineHeight:"20px",padding:"0 7px"},onChange:e=>{t.setAttributes({tab:e}),function(e){var n="[ultimatemember_account";"all"!==e&&(n=n+' tab="'+e+'"'),n+="]",t.setAttributes({content:n})}(e)}}))))},save:function(t){return null}}),jQuery(window).on("load",(function(t){new MutationObserver((function(t){t.forEach((function(t){jQuery(t.addedNodes).find(".um.um-account").each((function(){var t=jQuery(this).find(".um-account-main").attr("data-current_tab");t&&(jQuery(this).find('.um-account-tab[data-tab="'+t+'"]').show(),jQuery(this).find(".um-account-tab:not(:visible)").find("input, select, textarea").not(":disabled").addClass("um_account_inactive").prop("disabled",!0).attr("disabled",!0),um_responsive(),um_modal_responsive())}))}))})).observe(document,{attributes:!1,childList:!0,characterData:!1,subtree:!0})}))})(); \ No newline at end of file diff --git a/includes/blocks/um-account/src/index.js b/includes/blocks/um-account/src/index.js new file mode 100644 index 00000000..530cd789 --- /dev/null +++ b/includes/blocks/um-account/src/index.js @@ -0,0 +1,88 @@ +import { registerBlockType } from '@wordpress/blocks'; +import ServerSideRender from '@wordpress/server-side-render'; +import {InspectorControls, useBlockProps} from '@wordpress/block-editor'; +import {PanelBody, SelectControl} from "@wordpress/components"; + +registerBlockType('um-block/um-account', { + edit: function (props) { + let { tab, setAttributes } = props.attributes; + const blockProps = useBlockProps(); + + function get_options() { + var option = []; + + option.push( { label: wp.i18n.__( 'All', 'ultimate-member' ), value: 'all' } ); + + for ( var key in um_account_settings ) { + if ( um_account_settings.hasOwnProperty( key ) && um_account_settings[ key ]['enabled'] ) { + option.push( + { + label: um_account_settings[ key ]['label'], + value: key + } + ) + } + } + + return option; + } + + function umShortcode( value ) { + + var shortcode = '[ultimatemember_account'; + + if ( value !== 'all' ) { + shortcode = shortcode + ' tab="' + value + '"'; + } + + shortcode = shortcode + ']'; + + props.setAttributes({ content: shortcode }); + } + + return ( +
+ + + + { + props.setAttributes({ tab: value }); + umShortcode(value); + }} + /> + + +
+ ); + + }, + save: function save(props) { + return null; + } +}); + +jQuery(window).on( 'load', function($) { + var observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + + jQuery(mutation.addedNodes).find('.um.um-account').each(function() { + var current_tab = jQuery(this).find('.um-account-main').attr('data-current_tab'); + + if ( current_tab ) { + jQuery(this).find('.um-account-tab[data-tab="'+current_tab+'"]').show(); + jQuery(this).find('.um-account-tab:not(:visible)').find( 'input, select, textarea' ).not( ':disabled' ).addClass('um_account_inactive').prop( 'disabled', true ).attr( 'disabled', true ); + um_responsive(); + um_modal_responsive(); + } + }); + }); + }); + + observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); +}); diff --git a/includes/blocks/um-forms/block.json b/includes/blocks/um-forms/block.json new file mode 100644 index 00000000..563f7399 --- /dev/null +++ b/includes/blocks/um-forms/block.json @@ -0,0 +1,15 @@ +{ + "apiVersion": 2, + "name": "um-block/um-forms", + "title": "Form", + "description": "Choose display form", + "icon": "forms", + "category": "um-blocks", + "attributes": { + "form_id": { + "type": "integer" + } + }, + "editorScript": "file:./build/index.js", + "textdomain": "ultimate-member" +} diff --git a/includes/blocks/um-forms/build/index.asset.php b/includes/blocks/um-forms/build/index.asset.php new file mode 100644 index 00000000..6ef4166a --- /dev/null +++ b/includes/blocks/um-forms/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-server-side-render'), 'version' => '9dc130f3a0af7db5d679'); diff --git a/includes/blocks/um-forms/build/index.js b/includes/blocks/um-forms/build/index.js new file mode 100644 index 00000000..eaaac6a4 --- /dev/null +++ b/includes/blocks/um-forms/build/index.js @@ -0,0 +1 @@ +(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,r=window.wp.data,n=window.wp.components,l=window.wp.blockEditor,o=window.wp.serverSideRender;var i=e.n(o);(0,window.wp.blocks.registerBlockType)("um-block/um-forms",{edit:function(e){let{form_id:o,setAttributes:a}=e.attributes;const s=(0,l.useBlockProps)(),m=(0,r.useSelect)((e=>e("core").getEntityRecords("postType","um_form",{per_page:-1,_fields:["id","title"]})));if(!m)return(0,t.createElement)("p",null,(0,t.createElement)(n.Spinner,null),wp.i18n.__("Loading...","ultimate-member"));if(0===m.length)return"No forms found.";let c=[{id:"",title:""}].concat(m).map((e=>({label:e.title.rendered,value:e.id})));return(0,t.createElement)("div",s,(0,t.createElement)(i(),{block:"um-block/um-forms",attributes:e.attributes}),(0,t.createElement)(l.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:wp.i18n.__("Select Forms","ultimate-member")},(0,t.createElement)(n.SelectControl,{label:wp.i18n.__("Select Forms","ultimate-member"),className:"um_select_forms",value:o,options:c,style:{height:"35px",lineHeight:"20px",padding:"0 7px"},onChange:t=>{e.setAttributes({form_id:t})}}))))},save:function(e){return null}})})(); \ No newline at end of file diff --git a/includes/blocks/um-forms/src/index.js b/includes/blocks/um-forms/src/index.js new file mode 100644 index 00000000..27cc2418 --- /dev/null +++ b/includes/blocks/um-forms/src/index.js @@ -0,0 +1,91 @@ +import { useSelect } from '@wordpress/data'; +import { PanelBody, SelectControl, Spinner } from '@wordpress/components'; +import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import ServerSideRender from '@wordpress/server-side-render'; +import { registerBlockType } from "@wordpress/blocks"; + +registerBlockType('um-block/um-forms', { + edit: function (props) { + let { form_id, setAttributes } = props.attributes; + const blockProps = useBlockProps(); + const posts = useSelect((select) => { + return select('core').getEntityRecords('postType', 'um_form', { + per_page: -1, + _fields: ['id', 'title'] + }); + }); + + if (!posts) { + return ( +

+ + {wp.i18n.__('Loading...', 'ultimate-member')} +

+ ); + } + + if (posts.length === 0) { + return 'No forms found.'; + } + + function get_option( posts ) { + var option = []; + + posts.map( function( post ) { + option.push( + { + label: post.title.rendered, + value: post.id + } + ); + }); + + return option; + } + + function umShortcode( value ) { + + var shortcode = ''; + + if (value !== undefined && value !== '') { + shortcode = '[ultimatemember form_id="' + value + '"]'; + } + + return shortcode; + } + + let posts_data = [{ id: '', title: '' }].concat(posts); + + let get_post = posts_data.map((post) => { + return { + label: post.title.rendered, + value: post.id + }; + }); + + return ( +
+ + + + { + props.setAttributes({ form_id: value }); + umShortcode(value); + }} + /> + + +
+ ); + + }, + save: function save(props) { + return null; + } +}); diff --git a/includes/blocks/um-member-directories/block.json b/includes/blocks/um-member-directories/block.json new file mode 100644 index 00000000..ddaabf37 --- /dev/null +++ b/includes/blocks/um-member-directories/block.json @@ -0,0 +1,15 @@ +{ + "apiVersion": 2, + "name": "um-block/um-member-directories", + "title": "Member Directory", + "description": "Choose display directory", + "icon": "groups", + "category": "um-blocks", + "attributes": { + "member_id": { + "type": "integer" + } + }, + "editorScript": "file:./build/index.js", + "textdomain": "ultimate-member" +} diff --git a/includes/blocks/um-member-directories/build/index.asset.php b/includes/blocks/um-member-directories/build/index.asset.php new file mode 100644 index 00000000..8e85d2c6 --- /dev/null +++ b/includes/blocks/um-member-directories/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-server-side-render'), 'version' => '57ea4f619de4d752a4bb'); diff --git a/includes/blocks/um-member-directories/build/index.js b/includes/blocks/um-member-directories/build/index.js new file mode 100644 index 00000000..05bc85e3 --- /dev/null +++ b/includes/blocks/um-member-directories/build/index.js @@ -0,0 +1 @@ +(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,r=window.wp.data,n=window.wp.components,i=window.wp.blockEditor,o=window.wp.serverSideRender;var l=e.n(o);(0,window.wp.blocks.registerBlockType)("um-block/um-member-directories",{edit:function(e){let{member_id:o,setAttributes:a}=e.attributes;const c=(0,i.useBlockProps)(),u=(0,r.useSelect)((e=>e("core").getEntityRecords("postType","um_directory",{per_page:-1,_fields:["id","title"]})));if(!u)return(0,t.createElement)("p",null,(0,t.createElement)(n.Spinner,null),wp.i18n.__("Loading...","ultimate-member"));if(0===u.length)return"No posts found.";let d=[{id:"",title:""}].concat(u).map((e=>({label:e.title.rendered,value:e.id})));return(0,t.createElement)("div",c,(0,t.createElement)(l(),{block:"um-block/um-member-directories",attributes:e.attributes}),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:wp.i18n.__("Select Directories","ultimate-member")},(0,t.createElement)(n.SelectControl,{label:wp.i18n.__("Select Directories","ultimate-member"),className:"um_select_directory",value:o,options:d,style:{height:"35px",lineHeight:"20px",padding:"0 7px"},onChange:t=>{e.setAttributes({member_id:t})}}))))},save:function(e){return null}}),jQuery(window).on("load",(function(e){new MutationObserver((function(e){e.forEach((function(e){jQuery(e.addedNodes).find(".um.um-directory").each((function(){var e=jQuery(this);um_ajax_get_members(e)}))}))})).observe(document,{attributes:!1,childList:!0,characterData:!1,subtree:!0})}))})(); \ No newline at end of file diff --git a/includes/blocks/um-member-directories/src/index.js b/includes/blocks/um-member-directories/src/index.js new file mode 100644 index 00000000..12ac4b6a --- /dev/null +++ b/includes/blocks/um-member-directories/src/index.js @@ -0,0 +1,105 @@ +import { useSelect } from '@wordpress/data'; +import { PanelBody, SelectControl, Spinner } from '@wordpress/components'; +import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import ServerSideRender from '@wordpress/server-side-render'; +import { registerBlockType } from "@wordpress/blocks"; + +registerBlockType('um-block/um-member-directories', { + edit: function (props) { + let { member_id, setAttributes } = props.attributes; + const blockProps = useBlockProps(); + const posts = useSelect((select) => { + return select('core').getEntityRecords('postType', 'um_directory', { + per_page: -1, + _fields: ['id', 'title'] + }); + }); + + if (!posts) { + return ( +

+ + {wp.i18n.__('Loading...', 'ultimate-member')} +

+ ); + } + + if (posts.length === 0) { + return 'No posts found.'; + } + + function get_option( posts ) { + var option = []; + + posts.map( function( post ) { + option.push( + { + label: post.title.rendered, + value: post.id + } + ); + }); + + return option; + } + + function umShortcode( value ) { + + var shortcode = ''; + + if (value !== undefined && value !== '') { + shortcode = '[ultimatemember form_id="' + value + '"]'; + } + + return shortcode; + } + + let posts_data = [{ id: '', title: '' }].concat(posts); + + let get_post = posts_data.map((post) => { + return { + label: post.title.rendered, + value: post.id + }; + }); + + return ( +
+ + + + { + props.setAttributes({ member_id: value }); + umShortcode(value); + }} + /> + + +
+ ); + + }, + save: function save(props) { + return null; + } +}); + +jQuery(window).on( 'load', function($) { + var observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + + jQuery(mutation.addedNodes).find('.um.um-directory').each(function() { + var directory = jQuery(this); + um_ajax_get_members( directory ); + }); + }); + }); + + observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); +}); diff --git a/includes/blocks/um-password-reset/block.json b/includes/blocks/um-password-reset/block.json new file mode 100644 index 00000000..f73a45ee --- /dev/null +++ b/includes/blocks/um-password-reset/block.json @@ -0,0 +1,10 @@ +{ + "apiVersion": 2, + "name": "um-block/um-password-reset", + "title": "Password Reset", + "description": "Displaying the password reset form", + "icon": "unlock", + "category": "um-blocks", + "editorScript": "file:./build/index.js", + "textdomain": "ultimate-member" +} diff --git a/includes/blocks/um-password-reset/build/index.asset.php b/includes/blocks/um-password-reset/build/index.asset.php new file mode 100644 index 00000000..75ba44e5 --- /dev/null +++ b/includes/blocks/um-password-reset/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-element', 'wp-server-side-render'), 'version' => '95e8fe2695e681505871'); diff --git a/includes/blocks/um-password-reset/build/index.js b/includes/blocks/um-password-reset/build/index.js new file mode 100644 index 00000000..5f96959e --- /dev/null +++ b/includes/blocks/um-password-reset/build/index.js @@ -0,0 +1 @@ +(()=>{"use strict";var e={n:r=>{var o=r&&r.__esModule?()=>r.default:()=>r;return e.d(o,{a:o}),o},d:(r,o)=>{for(var t in o)e.o(o,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:o[t]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)};const r=window.wp.element,o=window.wp.blocks,t=window.wp.serverSideRender;var n=e.n(t);const s=window.wp.blockEditor;(0,o.registerBlockType)("um-block/um-password-reset",{edit:function(e){const o=(0,s.useBlockProps)();return(0,r.createElement)("div",o,(0,r.createElement)(n(),{block:"um-block/um-password-reset"}))},save:function(e){return null}})})(); \ No newline at end of file diff --git a/includes/blocks/um-password-reset/src/index.js b/includes/blocks/um-password-reset/src/index.js new file mode 100644 index 00000000..56ab795b --- /dev/null +++ b/includes/blocks/um-password-reset/src/index.js @@ -0,0 +1,19 @@ +import { registerBlockType } from '@wordpress/blocks'; +import ServerSideRender from '@wordpress/server-side-render'; +import { useBlockProps } from '@wordpress/block-editor'; + +registerBlockType('um-block/um-password-reset', { + edit: function (props) { + const blockProps = useBlockProps(); + + return ( +
+ +
+ ); + + }, + save: function save(props) { + return null; + } +}); diff --git a/includes/class-init.php b/includes/class-init.php index 1839a9d7..9f6e01c5 100644 --- a/includes/class-init.php +++ b/includes/class-init.php @@ -606,6 +606,7 @@ if ( ! class_exists( 'UM' ) ) { $this->external_integrations(); $this->gdpr(); $this->member_directory(); + $this->blocks(); //if multisite networks active if ( is_multisite() ) { @@ -635,6 +636,20 @@ if ( ! class_exists( 'UM' ) ) { } + /** + * @since 2.6.1 + * + * @return um\core\Blocks() + */ + public function blocks() { + if ( empty( $this->classes['blocks'] ) ) { + $this->classes['blocks'] = new um\core\Blocks(); + } + + return $this->classes['blocks']; + } + + /** * Get extension API * diff --git a/includes/core/class-access.php b/includes/core/class-access.php index 9e445ac5..67372e11 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -1196,7 +1196,7 @@ if ( ! class_exists( 'um\core\Access' ) ) { if ( $block['attrs']['um_message_type'] == '1' ) { $block_content = $default_message; } elseif ( $block['attrs']['um_message_type'] == '2' ) { - $block_content = $block['attrs']['um_message_content']; + $block_content = isset( $block['attrs']['um_message_content'] ) ? sanitize_textarea_field( $block['attrs']['um_message_content'] ) : ''; } } } else { @@ -1220,7 +1220,7 @@ if ( ! class_exists( 'um\core\Access' ) ) { if ( $block['attrs']['um_message_type'] == '1' ) { $block_content = $default_message; } elseif ( $block['attrs']['um_message_type'] == '2' ) { - $block_content = $block['attrs']['um_message_content']; + $block_content = isset( $block['attrs']['um_message_content'] ) ? sanitize_textarea_field( $block['attrs']['um_message_content'] ) : ''; } } } @@ -1234,7 +1234,7 @@ if ( ! class_exists( 'um\core\Access' ) ) { if ( $block['attrs']['um_message_type'] == '1' ) { $block_content = $default_message; } elseif ( $block['attrs']['um_message_type'] == '2' ) { - $block_content = $block['attrs']['um_message_content']; + $block_content = isset( $block['attrs']['um_message_content'] ) ? sanitize_textarea_field( $block['attrs']['um_message_content'] ) : ''; } } } diff --git a/includes/core/class-account.php b/includes/core/class-account.php index 95caa02c..446a5cb2 100644 --- a/includes/core/class-account.php +++ b/includes/core/class-account.php @@ -626,6 +626,9 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { + if ( isset( $shortcode_args['is_block'] ) && 1 === (int) $shortcode_args['is_block'] ) { + $data['is_block'] = 1; + } $output .= UM()->fields()->edit_field( $key, $data ); } break; @@ -666,6 +669,9 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { + if ( isset( $shortcode_args['is_block'] ) && 1 === (int) $shortcode_args['is_block'] ) { + $data['is_block'] = 1; + } $output .= UM()->fields()->edit_field( $key, $data ); } @@ -720,6 +726,9 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { + if ( isset( $shortcode_args['is_block'] ) && 1 === (int) $shortcode_args['is_block'] ) { + $data['is_block'] = 1; + } $output .= UM()->fields()->edit_field( $key, $data ); } @@ -758,6 +767,9 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { + if ( isset( $shortcode_args['is_block'] ) && 1 === (int) $shortcode_args['is_block'] ) { + $data['is_block'] = 1; + } $output .= UM()->fields()->edit_field( $key, $data ); } diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php new file mode 100644 index 00000000..583743fb --- /dev/null +++ b/includes/core/class-blocks.php @@ -0,0 +1,162 @@ + 'boolean', + ); + } + if ( empty( $settings['attributes']['um_who_access'] ) ) { + $settings['attributes']['um_who_access'] = array( + 'type' => 'string', + ); + } + if ( empty( $settings['attributes']['um_roles_access'] ) ) { + $settings['attributes']['um_roles_access'] = array( + 'type' => 'array', + ); + } + if ( empty( $settings['attributes']['um_message_type'] ) ) { + $settings['attributes']['um_message_type'] = array( + 'type' => 'string', + ); + } + if ( empty( $settings['attributes']['um_message_content'] ) ) { + $settings['attributes']['um_message_content'] = array( + 'type' => 'string', + ); + } + + return $settings; + } + + + public function block_editor_render() { + //disable Gutenberg scripts to avoid the conflicts + $disable_script = apply_filters( 'um_disable_blocks_script', false ); + if ( $disable_script ) { + return; + } + + $enable_blocks = UM()->options()->get( 'enable_blocks' ); + if ( empty( $enable_blocks ) ) { + return; + } + + $blocks = array( + 'um-block/um-member-directories' => array( + 'render_callback' => array( $this, 'um_member_directories_render' ), + 'attributes' => array( + 'member_id' => array( + 'type' => 'string', + ), + ), + ), + 'um-block/um-forms' => array( + 'render_callback' => array( $this, 'um_forms_render' ), + 'attributes' => array( + 'form_id' => array( + 'type' => 'string', + ), + ), + ), + 'um-block/um-password-reset' => array( + 'render_callback' => array( $this, 'um_password_reset_render' ), + ), + 'um-block/um-account' => array( + 'render_callback' => array( $this, 'um_account_render' ), + 'attributes' => array( + 'tab' => array( + 'type' => 'string', + ), + ), + ), + ); + + foreach ( $blocks as $k => $block_data ) { + $block_type = str_replace( 'um-block/', '', $k ); + register_block_type_from_metadata( um_path . 'includes/blocks/' . $block_type, $block_data ); + } + } + + + public function um_member_directories_render( $atts ) { + $shortcode = '[ultimatemember'; + + if ( isset( $atts['member_id'] ) && '' !== $atts['member_id'] ) { + $shortcode .= ' form_id="' . $atts['member_id'] . '"'; + } + + $shortcode .= ']'; + + return apply_shortcodes( $shortcode ); + } + + + public function um_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 ''; + } + } + $shortcode = '[ultimatemember is_block="1"'; + + if ( isset( $atts['form_id'] ) && '' !== $atts['form_id'] ) { + $shortcode .= ' form_id="' . $atts['form_id'] . '"'; + } + + $shortcode .= ']'; + + return apply_shortcodes( $shortcode ); + } + + + public function um_password_reset_render() { + $shortcode = '[ultimatemember_password]'; + + return apply_shortcodes( $shortcode ); + } + + + public function um_account_render( $atts ) { + if ( um_is_core_page( 'account' ) || um_is_core_page( 'user' ) ) { + return ''; + } + $shortcode = '[ultimatemember_account is_block="1"'; + + if ( isset( $atts['tab'] ) && 'all' !== $atts['tab'] ) { + $shortcode .= ' tab="' . $atts['tab'] . '"'; + } + + $shortcode .= ']'; + + return apply_shortcodes( $shortcode ); + } + } +} diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 73544566..58e70013 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -2109,14 +2109,23 @@ if ( ! class_exists( 'um\core\Fields' ) ) { * @return string|null * @throws \Exception */ - function edit_field( $key, $data, $rule = false, $args = array() ) { + public function edit_field( $key, $data, $rule = false, $args = array() ) { global $_um_profile_id; - $output = ''; + if ( isset( $data['is_block'] ) && 1 === (int) $data['is_block'] ) { + $form_suffix = ''; + } else { + $form_suffix = UM()->form()->form_suffix; + } + + $output = ''; $disabled = ''; if ( empty( $_um_profile_id ) ) { $_um_profile_id = um_user( 'ID' ); } + if ( ! is_user_logged_in() ) { + $_um_profile_id = 0; + } // get whole field data if ( isset( $data ) && is_array( $data ) ) { @@ -2380,7 +2389,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $field_name = $key . UM()->form()->form_suffix; + $field_name = $key . $form_suffix; $field_value = htmlspecialchars( $this->field_value( $key, $default, $data ) ); $output .= ' @@ -2417,8 +2426,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $field_name = $key . UM()->form()->form_suffix; - + $field_name = $key . $form_suffix; $field_value = $this->field_value( $key, $default, $data ); $field_value = ! is_null( $field_value ) ? htmlspecialchars( $field_value ) : null; @@ -2456,7 +2464,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $field_name = $key . UM()->form()->form_suffix; + $field_name = $key . $form_suffix; $field_value = htmlspecialchars( $this->field_value( $key, $default, $data ) ); $output .= ' @@ -2501,7 +2509,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $number_limit .= ' max="' . esc_attr( $max ) . '" '; } - $output .= ' + $output .= ' '; @@ -2537,7 +2545,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $output .= ' + $output .= ' '; @@ -2569,7 +2577,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $output .= ' + $output .= ' '; @@ -2605,7 +2613,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $name = $key . UM()->form()->form_suffix; + $name = $key . $form_suffix; if ( $this->set_mode == 'password' && um_is_core_page( 'password-reset' ) ) { $name = $key; } @@ -2643,7 +2651,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $name = $key . UM()->form()->form_suffix; + $name = $key . $form_suffix; if ( $this->set_mode == 'password' && um_is_core_page( 'password-reset' ) ) { $name = $key; } @@ -2693,7 +2701,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $output .= ' + $output .= ' '; @@ -2736,7 +2744,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $value = date( 'Y/m/d', $unixtimestamp ); } - $output .= ' + $output .= ' '; @@ -2766,7 +2774,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $output .= ' + $output .= ' '; @@ -2907,7 +2915,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } else { $field_value = $this->field_value( $key, $default, $data ); } - $output .= ''; + $output .= ''; if ( isset( $data['label'] ) ) { $output .= $this->field_label( $label, $key, $data ); } @@ -2992,7 +3000,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { /* Single File Upload */ case 'file': $output .= '
get_atts( $key, $classes, $conditional, $data ) . ' data-mode="' . esc_attr( $this->set_mode ) . '" data-upload-label="' . ( ! empty( $data['button_text'] ) ? esc_attr( $data['button_text'] ) : esc_attr__( 'Upload', 'ultimate-member' ) ) . '">'; - $output .= ''; + $output .= ''; if ( isset( $data['label'] ) ) { $output .= $this->field_label( $label, $key, $data ); } diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index d7f02e4d..c87ac86d 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -721,6 +721,10 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { } } + if ( ! is_user_logged_in() && isset( $args['is_block'] ) && 1 === (int) $args['is_block'] && 'profile' === $mode ) { + return; + } + // for profiles only if ( $mode == 'profile' && um_profile_id() ) { diff --git a/includes/core/um-actions-account.php b/includes/core/um-actions-account.php index 84e099fd..44ef426d 100644 --- a/includes/core/um-actions-account.php +++ b/includes/core/um-actions-account.php @@ -593,20 +593,20 @@ function um_after_account_privacy( $args ) {
get_row( - "SELECT ID - FROM $wpdb->posts - WHERE post_author = $user_id AND - post_type = 'user_request' AND - post_name = 'export_personal_data' AND - post_status = 'request-completed' - ORDER BY ID DESC + "SELECT ID + FROM $wpdb->posts + WHERE post_author = $user_id AND + post_type = 'user_request' AND + post_name = 'export_personal_data' AND + post_status = 'request-completed' + ORDER BY ID DESC LIMIT 1", ARRAY_A ); if ( ! empty( $completed ) ) { - + $exports_url = wp_privacy_exports_url(); - + echo '

' . esc_html__( 'You could download your previous data:', 'ultimate-member' ) . '

'; echo '' . esc_html__( 'Download Personal Data', 'ultimate-member' ) . ''; echo '

' . esc_html__( 'You could send a new request for an export of personal your data.', 'ultimate-member' ) . '

'; @@ -614,13 +614,13 @@ function um_after_account_privacy( $args ) { } $pending = $wpdb->get_row( - "SELECT ID, post_status - FROM $wpdb->posts - WHERE post_author = $user_id AND - post_type = 'user_request' AND - post_name = 'export_personal_data' AND - post_status != 'request-completed' - ORDER BY ID DESC + "SELECT ID, post_status + FROM $wpdb->posts + WHERE post_author = $user_id AND + post_type = 'user_request' AND + post_name = 'export_personal_data' AND + post_status != 'request-completed' + ORDER BY ID DESC LIMIT 1", ARRAY_A ); @@ -670,13 +670,13 @@ function um_after_account_privacy( $args ) { get_row( - "SELECT ID - FROM $wpdb->posts - WHERE post_author = $user_id AND - post_type = 'user_request' AND - post_name = 'remove_personal_data' AND - post_status = 'request-completed' - ORDER BY ID DESC + "SELECT ID + FROM $wpdb->posts + WHERE post_author = $user_id AND + post_type = 'user_request' AND + post_name = 'remove_personal_data' AND + post_status = 'request-completed' + ORDER BY ID DESC LIMIT 1", ARRAY_A ); @@ -688,13 +688,13 @@ function um_after_account_privacy( $args ) { } $pending = $wpdb->get_row( - "SELECT ID, post_status - FROM $wpdb->posts - WHERE post_author = $user_id AND - post_type = 'user_request' AND - post_name = 'remove_personal_data' AND - post_status != 'request-completed' - ORDER BY ID DESC + "SELECT ID, post_status + FROM $wpdb->posts + WHERE post_author = $user_id AND + post_type = 'user_request' AND + post_name = 'remove_personal_data' AND + post_status != 'request-completed' + ORDER BY ID DESC LIMIT 1", ARRAY_A ); diff --git a/package.json b/package.json index faa58dc5..ce1525b8 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,13 @@ } ], "scripts": { - "postinstall": "node node_modules/bower/bin/bower install && grunt dev" + "postinstall": "node node_modules/bower/bin/bower install && grunt dev", + "build": "npm-run-all build:*", + "build:all-blocks": "npm-run-all --parallel build-block-*", + "build-block-um-member-directories": "cd includes/blocks/um-member-directories && wp-scripts build src/index.js", + "build-block-um-forms": "cd includes/blocks/um-forms && wp-scripts build src/index.js", + "build-block-um-password-reset": "cd includes/blocks/um-password-reset && wp-scripts build src/index.js", + "build-block-um-account": "cd includes/blocks/um-account && wp-scripts build src/index.js" }, "engines": { "node": ">= 0.10.0" @@ -27,10 +33,18 @@ "gulp-cli": "^2.3.0", "gulp-concat": "2.6.1", "gulp-rename": "^2.0.0", - "gulp-sass": "^4.1.0", + "gulp-sass": "^5.1.0", "gulp-uglify": "^3.0.2", - "gulp-clean-css": "^4.3.0" + "gulp-clean-css": "^4.3.0", + "npm-run-all": "^4.1.5", + "@wordpress/block-editor": "^11.5.0", + "@wordpress/blocks": "^12.5.0", + "@wordpress/components": "^23.5.0", + "@wordpress/i18n": "^4.28.0", + "@wordpress/scripts": "^25.5.1", + "@wordpress/server-side-render": "^4.5.0" }, "dependencies": { + "react": "^18.2.0" } } diff --git a/templates/members.php b/templates/members.php index 4a463c84..ae295981 100644 --- a/templates/members.php +++ b/templates/members.php @@ -222,10 +222,13 @@ if ( ( ( $search && $show_search ) || ( $filters && $show_filters && count( $sea } } } -} ?> +} + +$postid = ! empty( $post->ID ) ? $post->ID : ''; +?>