Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @hthsrtdtuk

    Thanks for letting us know. For now, you can try the following code snippets to enabled the Patreon as a predefined field:

    
    // Register Patreon as a predefined field
    add_filter("um_predefined_fields_hook","um_122021_add_patreon_field");
    function um_122021_add_patreon_field( $fields ){
        $fields['patreon'] = array(
            'title' => __('Patreon','ultimate-member'),
            'metakey' => 'patreon',
            'type' => 'text',
            'label' => __('Patreon ID','ultimate-member'),
            'required' => 0,
            'public' => 1,
            'editable' => 1,
            'url_target' => '_blank',
            'url_rel' => 'nofollow',
            'validate' => 'patreon_url',
        );
    
        return $fields;
    }
    
    // Register Patreon URL validation
    add_filter("um_admin_field_validation_hook","um_122021_patreon_validate");
    function um_122021_patreon_validate( $array ){
    
        $array['patreon_url'] = __('Patreon URL','ultimate-member');
    
        return $array;
    }
    
    // Validate URL
    add_action( 'um_submit_form_errors_hook_', 'um_submit_form_validate_patreon_url', 100 );
    function um_submit_form_validate_patreon_url( $args ){
        $form_id = $args['form_id'];
        $mode = $args['mode'];
        $fields = unserialize( $args['custom_fields'] );
        
        foreach ( $fields as $key => $array ) {
            if( isset( $args[ $key ] ) && isset( $array['validate'] ) && $array['validate'] == "patreon_url" ){
                if ( ! UM()->validation()->is_url( $args[ $key ], 'patreon.com' ) ) {
                    UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
                }
            }
        }
    }
    

    You can add the code to your theme/child-theme’s functions.php file or use the Code Snippets plugin to run the code. Once the codes are added, you can now add the Patreon field to the UM Form.

    Regards,

    Thread Starter AlexMS

    (@hthsrtdtuk)

    Patreon ID not working, only link on profile

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @hthsrtdtuk

    Please try this updated code snippet, this accepts the Patreon ID but it doesn’t check the existence of the Patreon ID or Profile URL only the pattern.

    add_filter("um_predefined_fields_hook","um_122021_add_patreon_field");
    function um_122021_add_patreon_field( $fields ){
        $fields['patreon'] = array(
            'title' => __('Patreon','ultimate-member'),
            'metakey' => 'patreon',
            'type' => 'text',
            'label' => __('Patreon ID','ultimate-member'),
            'required' => 0,
            'public' => 1,
            'editable' => 1,
            'url_target' => '_blank',
            'url_rel' => 'nofollow',
            'validate' => 'patreon_url',
        );
    
        return $fields;
    }
    
    add_filter("um_admin_field_validation_hook","um_122021_patreon_validate");
    function um_122021_patreon_validate( $array ){
    
        $array['patreon_url'] = __('Patreon URL','ultimate-member');
    
        return $array;
    }
    add_action( 'um_submit_form_errors_hook_', 'um_submit_form_validate_patreon_url', 100 );
    function um_submit_form_validate_patreon_url( $args ){
        $form_id = $args['form_id'];
        $mode = $args['mode'];
        $fields = unserialize( $args['custom_fields'] );
        
        foreach ( $fields as $key => $array ) {
            if( isset( $args[ $key ] ) && isset( $array['validate'] ) && $array['validate'] == "patreon_url" ){
    
                if ( strstr( $args[ $key ], 'http' )
    			     || strstr( $args[ $key ], '://' )
    			     || strstr( $args[ $key ], 'www.' )
    			     || strstr( $args[ $key ], '.com' ) ){
                    if ( ! UM()->validation()->is_url( $args[ $key ], 'patreon.com' ) ) {
                        UM()->form()->add_error( $key, sprintf( __( 'Please enter a valid %s username or profile URL', 'ultimate-member' ), $array['label'] ) );
                    }
                }
            }
        }
    }
    
    function um_122221_patreon_url( $value, $data, $type = '' ) {
    	if ( ! $value ) {
    		return '';
    	}
    
        if ( ( isset( $data['validate'] ) && $data['validate'] !== '' && strstr( $data['validate'], 'url' ) ) || ( isset( $data['type'] ) && $data['type'] == 'url' ) ) {
            $alt = ( isset( $data['url_text'] ) && !empty( $data['url_text'] ) ) ? $data['url_text'] : $value;
            $url_rel = ( isset( $data['url_rel'] ) && $data['url_rel'] == 'nofollow' ) ? 'rel="nofollow"' : '';
            if ( ! strstr( $value, 'http' )
                    && !strstr( $value, '://' )
                    && !strstr( $value, 'www.' )
                    && !strstr( $value, '.com' )
            ) {
                if ( $data['validate'] == 'patreon_url' ) 	$value = 'https://patreon.com/' . $value;
            }
    
            if ( strpos( $value, 'https://' ) !== 0 ) {
                $value = 'https://' . $value;
            }
            $data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank';
        }
    
    	return $value;
    
    }
    add_filter( 'um_profile_field_filter_hook__', 'um_122221_patreon_url', 1, 3 );
    

    Regards,

    Thread Starter AlexMS

    (@hthsrtdtuk)

    still not working, the profile link looks like this https://www.patreon.com/user?u=00000000, the last digits its ID, but it is enough for me that a user points to a link to his profile

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @hthsrtdtuk

    Please update this function:

    function um_122221_patreon_url( $value, $data, $type = '' ) {
    	if ( ! $value ) {
    		return '';
    	}
    
        if ( ( isset( $data['validate'] ) && $data['validate'] !== '' && strstr( $data['validate'], 'url' ) ) || ( isset( $data['type'] ) && $data['type'] == 'url' ) ) {
            $alt = ( isset( $data['url_text'] ) && !empty( $data['url_text'] ) ) ? $data['url_text'] : $value;
            $url_rel = ( isset( $data['url_rel'] ) && $data['url_rel'] == 'nofollow' ) ? 'rel="nofollow"' : '';
            if ( ! strstr( $value, 'http' )
                    && !strstr( $value, '://' )
                    && !strstr( $value, 'www.' )
                    && !strstr( $value, '.com' )
            ) {
                if ( $data['validate'] == 'patreon_url' ) 	$value = 'https://patreon.com/user?u=' . $value;
            }
    
            if ( strpos( $value, 'https://' ) !== 0 ) {
                $value = 'https://' . $value;
            }
            $data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank';
        }
    
    	return $value;
    
    }
    add_filter( 'um_profile_field_filter_hook__', 'um_122221_patreon_url', 1, 3 );

    Regards,

    Thread Starter AlexMS

    (@hthsrtdtuk)

    Thanks for help!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Thanks for letting us know.

    Regards,

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Patreon’ is closed to new replies.