- reset password block

This commit is contained in:
ashubawork
2023-03-29 14:38:11 +03:00
parent 61d99135f4
commit a08ed9b6c1
8 changed files with 200 additions and 188 deletions
@@ -128,176 +128,6 @@ wp.blocks.registerBlockType( 'um-block/um-forms', {
});
//-------------------------------------\\
//-- 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 -------------\\
//-------------------------------------\\
@@ -402,4 +232,4 @@ wp.blocks.registerBlockType( 'um-block/um-account', {
}
);
}
});
});
+15
View File
@@ -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"
}
+105
View File
@@ -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-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 (
<p>
<Spinner />
{wp.i18n.__('Loading...', 'ultimate-member')}
</p>
);
}
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 (
<div {...blockProps}>
<ServerSideRender block="um-block/um-forms" attributes={props.attributes} />
<InspectorControls>
<PanelBody title={wp.i18n.__('Select Forms', 'ultimate-member')}>
<SelectControl
label={wp.i18n.__('Select Forms', 'ultimate-member')}
className="um_select_forms"
value={form_id}
options={get_post}
style={{ height: '35px', lineHeight: '20px', padding: '0 7px' }}
onChange={(value) => {
props.setAttributes({ form_id: value });
umShortcode(value);
}}
/>
</PanelBody>
</InspectorControls>
</div>
);
},
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});
// });
@@ -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"
}
@@ -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 (
<div {...blockProps}>
<ServerSideRender block="um-block/um-password-reset" />
</div>
);
},
save: function save(props) {
return null;
}
});
+31
View File
@@ -45,6 +45,17 @@ if ( ! class_exists( 'um\core\Blocks' ) ) {
),
),
),
'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' ),
),
);
foreach ( $blocks as $k => $block_data ) {
@@ -65,5 +76,25 @@ if ( ! class_exists( 'um\core\Blocks' ) ) {
return apply_shortcodes( $shortcode );
}
public function um_forms_render( $atts ) {
$shortcode = '[ultimatemember';
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 );
}
}
}
+16 -16
View File
@@ -430,11 +430,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
$args = ! empty( $args ) ? $args : array();
$default_login = $wpdb->get_var(
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'login' AND
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'login' AND
pm2.meta_value = '1'"
);
@@ -463,11 +463,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
$args = ! empty( $args ) ? $args : array();
$default_register = $wpdb->get_var(
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'register' AND
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'register' AND
pm2.meta_value = '1'"
);
@@ -496,11 +496,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
$args = ! empty( $args ) ? $args : array();
$default_profile = $wpdb->get_var(
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'profile' AND
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'profile' AND
pm2.meta_value = '1'"
);
@@ -530,11 +530,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
$args = ! empty( $args ) ? $args : array();
$default_directory = $wpdb->get_var(
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
"SELECT pm.post_id
FROM {$wpdb->postmeta} pm
LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' )
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'directory' AND
WHERE pm.meta_key = '_um_mode' AND
pm.meta_value = 'directory' AND
pm2.meta_value = '1'"
);
+3 -1
View File
@@ -20,7 +20,9 @@
"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-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"
},
"engines": {
"node": ">= 0.10.0"