• Resolved Reventlov

    (@reventlov)


    Dear Frontend Admin Support Team,

    I’ve been using Frontend Admin to allow users on my website to publish posts directly from the frontend. This functionality has been working seamlessly until recent updates. Specifically, after updating from version 3.18.4 to 3.18.6, I encountered an issue with custom slug generation, which was part of my site’s functionality.

    Issue Description:
    In version 3.18.4, the custom code I implemented to generate unique slugs for each post based on the user’s username and an identifier from the post worked perfectly. However, after updating to version 3.18.6, this functionality broke, resulting in posts being published with a generic ‘no-name’ slug.

    Here is a simplified version of the code snippet used for custom slug generation:

    // This action hooks into the post saving process to customize the post's slug
    add_action('frontend_admin/save_post', 'customize_post_slug_frontend_admin', 10, 2);
    
    function customize_post_slug_frontend_admin($form, $post_id) {
        // Check if the post type is the one we're targeting
        if (get_post_type($post_id) != 'custom_post_type') return;
    
        $current_user = wp_get_current_user();
        // Generate a slug using the user's username
        $user_slug = sanitize_title($current_user->user_nicename); 
    
        // Example identifier from the form data (simplified for this example)
        $unique_id = 'unique_identifier'; 
    
        // Combine elements to form a new slug
        $new_slug = sanitize_title('example-' . $user_slug . '-' . $unique_id);
    
        // Update the post with the new title and slug
        wp_update_post(array('ID' => $post_id, 'post_name' => $new_slug));
    }
    

    This code is crucial for maintaining a unique naming convention for posts published via the frontend form by our users. The sudden malfunction after the update has significantly impacted our site’s functionality.

    Could you please provide any insights into changes made in version 3.18.6 that might affect my code? Additionally, any guidance on how to adapt my code to restore its functionality with the latest version of Frontend Admin would be greatly appreciated.

    Thank you for your time and assistance. Looking forward to your prompt response.

    Best regards,

    • This topic was modified 9 months, 2 weeks ago by Reventlov.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shabti Kaplan

    (@shabti)

    Hello Sylvain

    Sorry to hear about this issue. It seems that on this line, you are using data from the $form record in order to populate the unique identifier:

    // Example identifier from the form data (simplified for this example)
        $unique_id = 'unique_identifier';
    

    Is that correct?

    If so, I apologize. We have changed this so that only new or updated data is stored in the record. This is in order to improve database performance since data that doesn’t need to be saved is already saved in the database elsewhere.

    If you need to retrieve the post title for example, you can simply use get_post_field with post_id and ‘title’ as the parameters. If you need a post meta field, you can use get_post_meta.

    If you get stuck, please let me know

    Thread Starter Reventlov

    (@reventlov)

    Hello Shabti,

    Thank you for your quick support on the slug customization issue. Your advice helped me resolve the problem after updating to Frontend Admin 3.18.6.

    I noticed the changelog didn’t detail the change that affected form data handling. For future updates, could such changes be highlighted in the changelog? It would greatly assist in ensuring compatibility with custom developments.

    Appreciate your help and looking forward to future enhancements.

    Best regards,

    • This reply was modified 9 months, 2 weeks ago by Reventlov.
    Plugin Author Shabti Kaplan

    (@shabti)

    I am so happy that I helped you fix your code snippet. I will make sure to be very specific with all the changes next time. Cudos to you for being so specific with the issue, that helped me indicate where the problem was coming from.

    All the best, Shabti

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Issue with Custom Slug Generation After Updating to Version 3.18.6’ is closed to new replies.