• Resolved theotherdavid

    (@theotherdavid)


    Hi there, I was wondering if it’s possible to have a certain role ticked by default so that every time you create a post it’s automatically ticked for content restrictions?

    Our client has a feed that pulls in posts so all the post will be automated.

    Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @theotherdavid,

    Thanks for reaching out Members Support Team!

    Please copy/paste below PHP snippet to theme functions.php file and let me know if it helps.

    add_action('save_post', 'update_members_access_role_after_publish');

    function update_members_access_role_after_publish($post_ID) {
    update_post_meta($post_ID, '_members_access_role', 'administrator'); //change administrator to default role you want to use
    }

    Regards,

    Thread Starter theotherdavid

    (@theotherdavid)

    Hi @omarelhawary that’s perfect and working as expected. Thank you so much.

    Thread Starter theotherdavid

    (@theotherdavid)

    @omarelhawary actually, is there a way so that it only applies to posts and not pages?

    Thank you!

    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @theotherdavid,

    Please replace the code with that one below:

    add_action('save_post', 'update_members_access_role_after_publish');

    function update_members_access_role_after_publish($post_ID) {
    // Check if the post type is 'post'
    if (get_post_type($post_ID) === 'post') {
    update_post_meta($post_ID, '_members_access_role', 'administrator'); // change 'administrator' to the default role you want to use
    }
    }

    Regards,

    Thread Starter theotherdavid

    (@theotherdavid)

    @omarelhawary perfect, thank you so much!

    Thread Starter theotherdavid

    (@theotherdavid)

    Sorry I made a mistake and need it to be two roles by default. I’ve tried a bunch of code and ChatGPT couldn’t even help. Is there a way to do this? Thank you so much!

    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @theotherdavid,

    Here’s the updated version of the code:

    add_action('save_post', 'update_members_access_role_after_publish');

    function update_members_access_role_after_publish($post_ID) {
    // Check if the post type is 'post'
    if (get_post_type($post_ID) === 'post') {
    add_post_meta($post_ID, '_members_access_role', 'administrator');
    add_post_meta($post_ID, '_members_access_role', 'author');
    add_post_meta($post_ID, '_members_access_role', 'editor');
    }
    }
    Thread Starter theotherdavid

    (@theotherdavid)

    @omarelhawary you legend! Thank you again?–?appreciate it.

    Plugin Support Omar ElHawary

    (@omarelhawary)

    @theotherdavid You’re welcome! Have a great day!

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.