diff --git a/includes/admin/assets/js/um-admin-blocks-shortcode.js b/includes/admin/assets/js/um-admin-blocks-shortcode.js index c17164a6..bf6981c2 100644 --- a/includes/admin/assets/js/um-admin-blocks-shortcode.js +++ b/includes/admin/assets/js/um-admin-blocks-shortcode.js @@ -1,43 +1,29 @@ -(function (blocks, editor, components, i18n, element) { - var um_el = wp.element.createElement, - UmRegisterBlockType = wp.blocks.registerBlockType, - UmRichText = wp.editor.RichText, - UmTextControl = wp.components.TextControl, - UmSelectControl = wp.components.SelectControl, - UmToggleControl = wp.components.ToggleControl, - UmPanelBody = wp.components.PanelBody, - UmRangeControl = wp.components.RangeControl, - UmSpinner = wp.components.Spinner, - UmData = wp.data, - UmWithSelect = wp.data.withSelect, - UmApiFetch = wp.apiFetch; +//-------------------------------------\\ +//--------- Um Forms shortcode --------\\ +//-------------------------------------\\ - //-------------------------------------\\ - //--------- Um Forms shortcode --------\\ - //-------------------------------------\\ - - UmRegisterBlockType('um-block/um-forms', { - title: i18n.__( 'UM Form' , 'ultimate-member' ), - description: i18n.__( 'Choose display form', 'ultimate-member' ), - icon: 'forms', - category: 'um-blocks', - attributes: { - content: { - source: 'html', - selector: 'p' - }, - form_id: { - type: 'select' - } +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: UmWithSelect(function (select) { - return { - posts: select('core').getEntityRecords( 'postType', 'um_form', { - per_page: -1 - }) - }; - })(function ( props ) { + 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, @@ -74,99 +60,100 @@ if ( ! posts ) { - return um_el( + return wp.element.createElement( 'p', { className: className }, - um_el( - UmSpinner, + wp.element.createElement( + wp.components.Spinner, null ), - i18n.__( 'Loading Forms', 'ultimate-member' ) + wp.i18n.__( 'Loading Forms', 'ultimate-member' ) ); } if ( 0 === posts.length ) { - return um_el( + return wp.element.createElement( 'p', null, - i18n.__( 'No Posts', 'ultimate-member' ) + wp.i18n.__( 'No Posts', 'ultimate-member' ) ); } if ( form_id === undefined ) { props.setAttributes({ form_id: posts[0]['id'] }); - var shortcode = umShortcode(posts[0]['id']); + var shortcode = umShortcode( posts[0]['id'] ); props.setAttributes( { content: shortcode } ); } var get_post = get_option( posts ); - return um_el( + return wp.element.createElement( 'div', { className: className }, - um_el( - UmSelectControl, + wp.element.createElement( + wp.components.SelectControl, { - label: i18n.__( 'Select Forms', 'ultimate-member' ), - className: "um_select_users", + 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); + var shortcode = umShortcode( value ); props.setAttributes( { content: shortcode } ); } } ) ); } // end withSelect - ), // end edit + ), // end edit - save: function save( props ) { + save: function save( props ) { - return um_el( - UmRichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } - - }); - - //-------------------------------------\\ - //-- Um Member Directories shortcode --\\ - //-------------------------------------\\ - - UmRegisterBlockType( 'um-block/um-member-directories', { - title: i18n.__( 'UM Member Directories', 'ultimate-member'), - description: i18n.__( 'Choose display form', 'ultimate-member' ), - icon: 'groups', - category: 'um-blocks', - attributes: { - content: { - source: 'html', - selector: 'p' - }, - member_id: { - type: 'select' + return wp.element.createElement( + wp.editor.RichText.Content, + { + tagName: 'p', + className: props.className, + value: props.attributes.content } - }, + ); + } - edit: UmWithSelect( function( select ) { - return { - posts: select('core').getEntityRecords( 'postType', 'um_directory', { - per_page: -1 - }) - }; - })(function ( props ) { +}); + + +//-------------------------------------\\ +//-- 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, @@ -201,24 +188,24 @@ } if ( ! posts ) { - return um_el( + return wp.element.createElement( 'p', { className: className }, - um_el( - UmSpinner, + wp.element.createElement( + wp.components.Spinner, null ), - i18n.__( 'Loading Forms', 'ultimate-member' ) + wp.i18n.__( 'Loading Forms', 'ultimate-member' ) ); } if ( 0 === posts.length ) { - return um_el( + return wp.element.createElement( 'p', null, - i18n.__( 'No Posts', 'ultimate-member' ) + wp.i18n.__( 'No Posts', 'ultimate-member' ) ); } @@ -230,16 +217,16 @@ var get_post = get_option( posts ); - return um_el( + return wp.element.createElement( 'div', { className: className }, - um_el( - UmSelectControl, + wp.element.createElement( + wp.components.SelectControl, { - label: i18n.__( 'Select Directories', 'ultimate-member' ), - className: "um_select_member", + label: wp.i18n.__( 'Select Directories', 'ultimate-member' ), + className: 'um_select_directory', type: 'number', value: member_id, options: get_post, @@ -252,359 +239,167 @@ ) ); } // end withSelect - ), // end edit + ), // end edit - save: function save( props ) { - - return um_el( - UmRichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } - - }); - - //-------------------------------------\\ - //--------- Um password reset ---------\\ - //-------------------------------------\\ - UmRegisterBlockType('um-block/um-password-reset', { - title: i18n.__( 'UM Password Reset', 'ultimate-member' ), - description: i18n.__( 'Password Reset', '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 [ - um_el( - "div", - { - className: "um-password-reset-wrapper" - }, - i18n.__( 'Password Reset', 'ultimate-member' ) - ) - ] - }, - - save: function( props ) { - - return um_el( - UmRichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } - }); - - //-------------------------------------\\ - //------------ Um Account -------------\\ - //-------------------------------------\\ - UmRegisterBlockType('um-block/um-account', { - title: i18n.__( 'UM Account', 'ultimate-member' ), - description: i18n.__( 'UM Account', '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, - options = um_account_settings; - - function get_options() { - var option = []; - - option.push( { label: i18n.__( 'All', 'ultimate-member' ), value: 'all' } ); - - for ( var key in options ) { - if ( options.hasOwnProperty( key ) && options[ key ]['enabled'] ) { - option.push( - { - label: options[ 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 [ - um_el( - "div", - { - className: "um-account-wrapper" - }, - i18n.__( 'UM Account', 'ultimate-member' ) - ), - um_el( - wp.editor.InspectorControls, - {}, - um_el( - UmPanelBody, - { - title: i18n.__( 'Account Tab', 'ultimate-member' ) - }, - um_el( - UmSelectControl, - { - label: 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 um_el( - UmRichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } - }); - - //-------------------------------------\\ - //------ Social Activity function -----\\ - //-------------------------------------\\ - var um_users = getUsers(); - - function getUsers() { - - var options = [], - user_list = ''; - - UmApiFetch( { path : '/wp/v2/users/' } ).then( - function ( answer ) { - user_list = answer; - - user_list.map(function (user) { - options.push( - { - label: user.name, - value: user.id - } - ); - }); + save: function save( props ) { + return wp.element.createElement( + wp.editor.RichText.Content, + { + tagName: 'p', + className: props.className, + value: props.attributes.content } ); - - return options; } - //-------------------------------------\\ - //----- Social Activity Shortcode -----\\ - //-------------------------------------\\ - UmRegisterBlockType( 'um-block/um-user-profile-wall', { - title: i18n.__( 'User Profile Wall', 'ultimate-member' ), - description: i18n.__( 'Used on the user profile page', 'ultimate-member' ), - icon: 'businessman', - category: 'um-blocks', - attributes: { // Necessary for saving block content. - content: { - source: 'html', - selector: 'p' - }, - user_id: { - type: 'select' - }, - hashtag: { - type: 'string' - }, - wall_post: { - type: 'number' - }, - user_wall: { - type: 'boolean' +}); + +//-------------------------------------\\ +//--------- 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 user_id = props.attributes.user_id, - hashtag = props.attributes.hashtag, - wall_post = props.attributes.wall_post, - user_wall = props.attributes.user_wall, - attributes = props.attributes, - content = props.attributes.content; + edit: function( props ) { + var content = props.attributes.content, + tab = props.attributes.tab; - function onChangeContent( newContent ) { - props.setAttributes( { content: newContent } ); - } + function get_options() { + var option = []; - function umShortcode() { - - var shortcode = ''; - - if ( attributes.user_id !== undefined ) { - - shortcode = '[ultimatemember_wall user_id="' + attributes.user_id + '"'; - - if( attributes.hashtag !== undefined ) { - shortcode = shortcode + ' hashtag="' + attributes.hashtag + '"'; - } - - if( attributes.wall_post !== undefined ) { - shortcode = shortcode + ' wall_post="' + attributes.wall_post + '"'; - } - - if( attributes.user_wall !== undefined ) { - shortcode = shortcode + ' user_wall="' + attributes.user_wall + '"'; - } - - shortcode = shortcode + ']'; - - props.setAttributes( { content: shortcode } ); + 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 [ - um_el( - "div", - { - className: "um-social-activity-wrapper" - }, - um_el( - UmSelectControl, - { - label: i18n.__( 'Select User', 'ultimate-member' ), - className: "um_select_users", - type: 'number', - value: props.attributes.user_id, - options: um_users, - onChange: function onChange( value ) { - props.setAttributes({ user_id: value }); - attributes['user_id'] = value; - umShortcode(); - } - } - ), - um_el( - UmTextControl, - { - className: "um_hashtag", - label: i18n.__( 'Hashtag', 'ultimate-member' ), - value: props.attributes.hashtag, - onChange: function onChange( value ) { - props.setAttributes({ hashtag: value }); - attributes['hashtag'] = value; - umShortcode(); - } - } - ) + return option; + } - ), - um_el( - wp.editor.InspectorControls, - {}, - um_el( - UmPanelBody, + 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.editor.InspectorControls, + {}, + wp.element.createElement( + wp.components.PanelBody, + { + title: wp.i18n.__( 'Account Tab', 'ultimate-member' ) + }, + wp.element.createElement( + wp.components.SelectControl, { - title: i18n.__( 'Shortcode Attribute', 'ultimate-member' ) - }, - um_el( - UmRangeControl, - { - label: i18n.__( 'Show the form on the wall?', 'ultimate-member' ), - value: props.attributes.wall_post, - min: 2, - max: 20, - onChange: function onChange( value ) { - props.setAttributes({ wall_post: value }); - attributes['wall_post'] = value; - umShortcode(); - } + 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 ); } - ), - um_el( - UmToggleControl, - { - label: i18n.__( 'Show the form on the wall?', 'ultimate-member' ), - checked: props.attributes.user_wall, - onChange: function onChange( value ) { - props.setAttributes({ user_wall: value }); - attributes['user_wall'] = value; - umShortcode(); - } - } - ) + } ) ) - ] - }, + ) + ] + }, - save: function( props ) { + save: function( props ) { - return um_el( - UmRichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } - }); - -})( - window.wp.blocks, - window.wp.editor, - window.wp.components, - window.wp.i18n, - window.wp.element -); \ No newline at end of file + 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/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index 3215b6b1..ce070118 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -453,6 +453,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_localize_script( 'um_block_js', 'um_restrict_roles', $restrict_options ); wp_enqueue_script( 'um_block_js' ); + + do_action( 'um_load_gutenberg_js' ); } diff --git a/includes/admin/core/class-admin-menu.php b/includes/admin/core/class-admin-menu.php index 3dc61e81..302a9adb 100644 --- a/includes/admin/core/class-admin-menu.php +++ b/includes/admin/core/class-admin-menu.php @@ -218,8 +218,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Menu' ) ) { /** custom metaboxes for dashboard defined here **/ add_meta_box( 'um-metaboxes-contentbox-1', __( 'Users Overview', 'ultimate-member' ), array( &$this, 'users_overview' ), $this->pagehook, 'core', 'core' ); - add_meta_box( 'um-metaboxes-mainbox-1', __( 'Latest from our blog', 'ultimate-member' ), array( &$this, 'um_news' ), $this->pagehook, 'normal', 'core' ); - add_meta_box( 'um-metaboxes-sidebox-1', __( 'Purge Temp Files', 'ultimate-member' ), array( &$this, 'purge_temp' ), $this->pagehook, 'side', 'core' ); add_meta_box( 'um-metaboxes-sidebox-2', __( 'User Cache', 'ultimate-member' ), array( &$this, 'user_cache' ), $this->pagehook, 'side', 'core' ); @@ -232,14 +230,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Menu' ) ) { } - /** - * - */ - function um_news() { - include_once UM()->admin()->templates_path . 'dashboard/feed.php'; - } - - /** * */ diff --git a/includes/admin/templates/dashboard/feed.php b/includes/admin/templates/dashboard/feed.php deleted file mode 100644 index fb326385..00000000 --- a/includes/admin/templates/dashboard/feed.php +++ /dev/null @@ -1,23 +0,0 @@ - - - -
- - \ No newline at end of file