• Hi there,

    Is it possible to add some custom post type support to the plugin? I would like to redirect users to a specific WooCommerce page, but only regular pages are supported currently.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @thomdj,

    Thanks for contacting us!

    Currently, it isn’t possible, but it does seem like an interesting feature. I’ve shared your suggestion to the development team, and they have duly noted it down. If more users express interest in this, we’ll consider including it.

    Let me know if you need any other support.

    Thanks a lot!

    Thread Starter ThomDJ

    (@thomdj)

    Changing the function of class-wp-temporary-login-without-password-common.php at line #1121 to the following achieves what I’m looking for:

    /**
     * Get all public post types that are not excluded from search
     * Group posts by post type and sort them by post type name
     * Display post type names in the language used in WordPress
     *
     * @param string $selected
     *
     * @since 1.6.9
     */
    public static function tlwp_dropdown_redirect_to( $selected = '' ) {
    
        // Get all public post types that are not excluded from search
        $post_types = get_post_types( array(
            'public'            => true,
            'exclude_from_search' => false,
        ), 'objects' );
    
        // Array to store all posts from public post types grouped by post type
        $items_by_type = array();
    
        // Loop through each public post type
        foreach ( $post_types as $post_type ) {
            // Get posts for the current post type
            $posts = get_posts( array(
                'post_type'      => $post_type->name,
                'post_status'    => 'publish',
                'posts_per_page' => -1
            ) );
    
            // Add each post to the items_by_type array under its post type
            foreach ($posts as $post) {
                $items_by_type[$post_type->name][] = array(
                    'ID'        => $post->ID,
                    'post_title'=> $post->post_title,
                    'post_type' => $post_type->name
                );
            }
        }
    
        // Start building the dropdown HTML
        $output = '';
    
        // Loop through each post type
        foreach ($items_by_type as $type => $items) {
            // Sort items alphabetically by post title within each post type
            usort($items, function($a, $b) {
                return strcmp($a['post_title'], $b['post_title']);
            });
    
            // Get translated post type name
            $post_type_label = get_post_type_object($type)->labels->name;
    
            // Start an optgroup for each post type
            $output .= "<optgroup label='" . esc_attr( $post_type_label ) . "'>";
            foreach ($items as $item) {
                // Preselect specified item
                $is_selected = ( $selected == $item['ID'] ) ? 'selected="selected"' : '';
    
                // Add an <option> element for each item
                $output .= "\n\t<option value='" . esc_attr( $item['ID'] ) . "' $is_selected>" . esc_html( $item['post_title'] ) . "</option>";
            }
            $output .= "</optgroup>";
        }
    
        // Echo the generated HTML
        echo $output;
    }
    
    • This reply was modified 7 months, 3 weeks ago by ThomDJ.
    Thread Starter ThomDJ

    (@thomdj)

    Also, the plugin auto-generates a username based on the first and last name, but doesn’t remove spaces if a person has more than one first or last name. Perhaps it would be useful to also remove spaces automatically when generating the username.

    /**
     * Create a random username for the temporary user
     *
     * @param array $data
     *
     * @return string
     */
    public static function create_username( $data ) {
        $first_name = isset( $data['user_first_name'] ) ? $data['user_first_name'] : '';
        $last_name  = isset( $data['user_last_name'] ) ? $data['user_last_name'] : '';
        $email      = isset( $data['user_email'] ) ? $data['user_email'] : '';
    
        $name = '';
    
        if ( ! empty( $first_name ) || ! empty( $last_name ) ) {
            // Remove spaces from first and last names and concatenate them
            $name = str_replace( array( '.', '+', ' ' ), '', strtolower( trim( $first_name . $last_name ) ) );
    
            // Transliterate special characters to ASCII equivalents
            $name = iconv('UTF-8', 'ASCII//TRANSLIT', $name);
    
            // Remove any non-alphanumeric characters
            $name = preg_replace('/[^a-zA-Z0-9]/', '', $name);
        } else {
            if ( ! empty( $email ) ) {
                $explode = explode( '@', $email );
                // Use portion before '@' symbol as name and remove spaces
                $name    = str_replace( array( '.', '+', ' ' ), '', $explode[0]);
            }
        }
    
        if ( username_exists( $name ) ) {
            $name = $name . substr( uniqid( '', true ), - 6 );
        }
    
        $username = sanitize_user( $name, true );
    
        /**
         * We are generating WordPress username from First Name & Last Name fields.
         * When First Name or Last Name comes with non-latin words, the generated username
         * might be non-latin, and the sanitize_user function might discard it, resulting
         * in the user not being generated.
         *
         * To avoid this, if this situation occurs, we are generating a random username
         * for this user.
         */
        if ( empty( $username ) ) {
            $username = self::random_username();
        }
    
        return sanitize_user( $username, true );
    }
    
    • This reply was modified 7 months, 3 weeks ago by ThomDJ.
    • This reply was modified 7 months, 3 weeks ago by ThomDJ.

    Hi @thomdj ,

    Thank you for providing the information above. We’ve taken note of it and are currently looking into it. We’ll keep you updated once it’s incorporated into the plugin.

    Feel free to reach out if you require any additional support or have further suggestions.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add custom post type support?’ is closed to new replies.