array( 'name' => esc_html__( 'Register', 'mega' ), 'description' => esc_html__( 'Register block', 'mega' )),
'universal' => true
);
parent::__construct( __CLASS__, $args );
$this->buildRegisterForm( new Mega_Form_Manager( array( 'type' => 'mega', 'callback' => array( $this, 'setForm' ))));
}
public function settings( $form )
{
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Title', 'mega' ), 'value' => esc_html__( 'Registration', 'mega' ), 'name' => 'title' ));
$form->add_control( 'Mega_Control_Textarea', array( 'label' => esc_html__( 'Text', 'mega' ), 'pro' => 1, 'value' => esc_html__( 'If you don\'t have an account yet, you can register below.', 'mega' ), 'name' => 'text' ));
$form->add_control( 'Mega_Control_Textarea', array( 'label' => esc_html__( 'Text Alt', 'mega' ), 'value' => esc_html__( 'Registration is currently closed.', 'mega' ), 'name' => 'text_alt' ));
$form->add_control( 'Mega_Control_Email', array( 'label' => esc_html__( 'Email From Address', 'mega' ), 'pro' => 1, 'value' => get_option( 'admin_email' ), 'name' => 'email' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Email From Name', 'mega' ), 'value' => get_bloginfo( 'name' ), 'name' => 'name' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Email Subject', 'mega' ), 'pro' => 1, 'desc' => wp_kses( __( 'Use the following snippets of code to output the necessary information:
Site name - [site_name]
Site URL - [site_url]
', 'mega' ), array( 'br' => true, 'strong' => true )), 'value' => esc_html__( 'Your password for [site_name] at [site_url]', 'mega' ), 'name' => 'subject' ));
$form->add_control( 'Mega_Control_Textarea', array( 'label' => esc_html__( 'Email Message', 'mega' ), 'desc' => esc_html__( 'Use the name attributes you have given to elements in your form to output the results inside your email, names must be surrounded with [], i.e [my-email-field], in addition you have few custom names that you can use: [site_name], [site_url] and [user_pass]', 'mega' ), 'value' => str_replace( '\n', "\n", esc_html__( 'Thank you for registering with [site_name], you can find your login information below.\n\nUsername: [user_name]\nPassword: [user_pass]', 'mega' )), 'name' => 'message' ));
}
public function block()
{
if ( get_option( 'users_can_register' ))
parent::block();
else
echo wpautop( $this->mega['settings']['text_alt'] );
}
public function getForm()
{
$this->buildRegisterForm( new Mega_Form_Manager( array( 'type' => 'echo', 'callback' => array( $this ))));
}
public function buildRegisterForm( $form )
{
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Username', 'mega' ), 'show_label' => 0, 'name' => 'user_name', 'placeholder' => esc_html__( 'enter your username', 'mega' ), 'required' => 1, 'sanitize' => 'sanitize_user' ));
$form->add_control( 'Mega_Control_Email', array( 'label' => esc_html__( 'Email', 'mega' ), 'show_label' => 0, 'name' => 'user_email', 'placeholder' => esc_html__( 'enter your email', 'mega' ), 'required' => 1 ));
$form->add_control( 'Mega_Control_Submit', array( 'value' => esc_html__( 'Submit', 'mega' )));
}
public function ajax( $post )
{
if ( wp_create_user( $post['user_name'], ( $post['user_pass'] = wp_generate_password() ), $post['user_email'] ))
{
global $mega_mail;
extract( $this->mega['settings'] );
$post['site_name'] = get_bloginfo( 'name' );
$post['site_url'] = site_url();
if ( $mega_mail->do_mail(
$post['user_email'],
mega_parse_message( array( 'site_name' => get_bloginfo( 'name' ), 'site_url' => site_url() ), $subject ),
mega_parse_message( $post, $message ),
$email,
$name
))
echo '