Skip Navigation

[Resolved] Limiting user edit capabilities based on status

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 9 replies, has 2 voices.

Last updated by samuelel 6 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#920822

Hi, this is the current situation:

- A registered user can create a custom post 'X' from the front-end (status = draft, after submission);
- The same user can edit the post above from the front-end (status = draft, after submission).

I would like to implement the following:

- The user can change the post status to a custom status (defined with Oasis Workflow), called 'submitted' by clicking on a new button in the edit form.
- Once the post status changes into 'submitted' the user will NOT be able to modify the post anymore
- The user will be still able to see the post in the 'submitted' status

How can I do that?

(note: my website is installed locally).

#920992

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Samuel,

Thank you for contacting our support forum.

Unfortunately no its not possible to restrict based on post status. You can only restrict based on user role or single user.

- You can create your custom post status but then it would still be accessible to the user. The custom post status will be created using some custom code
- To restrict based on the post status you will need to write some custom code to do this.

Thanks,
Shane

#921200

Thanks. Can you suggest a workaround within Toolset? By that I mean that a user writes a post, this post is sent for review to the admin, when it is under review by the administrator the user cannot modify it, but he will be able to see it.

Alternatively can you suggest what is the php code needed for this and where do I need to insert it?

#921419

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Samuel,

Do the users have access to the backend ?

If you allow them to submit the posts but not allowing them to have access to the backend then they shouldn't be able to edit it.

If they can only view the post on the frontend the it would need to be in a published state.

Thanks,
Shane

#922074

That wouldn't work. The user can create and edit the post from the front-end. When the user creates/edits the post, the status of the post is 'draft'. The ability for a user to come back and modify the post is required. Disabling access to the back-end (which I have done with a plug-in) does not make any difference.

Would you be so kind to suggest what code do I need to add and where to implement what I sad above? In the edit form I would like to add a button close to the standard submit (which is now called 'save draft') called 'change status'. By pressing save the status changes into 'submitted'. Then we need to add an 'if condition' somewhere to specify that if the current post status is 'submitted' the author cannot see it. How can I do that?

Thanks a lot!

#922712

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Samuel,

So if the user creates the post its set as Submitted correct. This is a custom status that needs to be created.

To create the custom status take a look at the link below.
https://codex.wordpress.org/Function_Reference/register_post_status

Now in toolset forms you can then set this status from a new post creation. Finally if there is an admin review then they should set the post status as draft because I believe that if someone other that the original user who published the post becomes the actual author.

Finally after it is set to draft then you should be able to use views to print it out on the user's profile and allow them to Edit it with a Form that when submitted would set the post status to Publish.

Please let me know what you think of this idea and then we can work through the setup process.

Thanks,
Shane

#922750
Figure 3.JPG
Figure 2.JPG
Figure 1.JPG

Hi Shane,

Probably I haven’t been clear. Let me recap with some illustrations. Let’s start from scratch. 🙂

See Figure 1. Author logs-in (Figure 1a) and accesses My Account (Figure 1b). Author clicks on the Submit Manuscript link and accesses Draft Manuscript (Figure 1c), where he can create a custom type post called Manuscript, from the front-end. On the bottom of Figure 1c there is a 'Submit Draft' button. This saves Manuscript as a draft (as specified in the form settings in Toolset in Figure 1d) and works fine.

See Figure 2. After clicking on Submit Manuscript, Author is redirected to My Account page (Figure 2a). Here Author can see a list of his Manuscripts and their statuses. This works fine. When author clicks on Edit, the manuscript Edit Form is loaded and the Author can modify Manuscript (Figure 2b).

Author has now two options: ‘Save Draft’ or ‘Submit Manuscript’. ‘Save Draft’ simply saves Manuscript as it is. We want that when Author clicks on the other button ‘Submit Manuscript’ and the checkbox submit_validation is selected (==1), the Manuscript changes from 'draft' to ‘submitted’ (which is a custom status as defined with the plugin ‘Oasis Workflow’, see Figure 2c).

The section in the ‘Edit Post Form cell’ that implements the buttons and the checkbox is:

[cred_generic_field field='submit_validation' type='checkbox' class='' urlparam='']
{
"required":0,
"validate_format":0,
"checked":0,
"default":"1",
"label":"submit_validation"
}
[/cred_generic_field]

 [cred_field field='form_submit' value='Submit Manuscript' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

So, I created a dummy plugin in WordPress. The php code of plugin_name.php is the following:

if (! defined('ABSPATH')){
	exit;
}
//[submit_manuscript]
function submit_manuscript_func( $atts ){
     submit_man($atts);
    }
add_shortcode( 'submit_manuscript', 'submit_manuscript_func' );
function submit_man($atts ){
      $my_post = array(
      'ID'          => get_the_ID(),
      'post_status' => 'submitted');
       wp_update_post($my_post);
 }

See Figure 3. If I include the shortcode [submit_manuscript] anywhere in the Manuscript fields (from the Admin back-end) and I load the Manuscript page, this will change the status from ‘draft’ to ‘submitted’. So, the shortcode is working fine.

However I would like to trigger the shortcode when the button 'Submit Manuscript' is pressed (with the conditions that the checkbox must be checked) . In pseudo-code it should be something like:

if ((submit manuscript button is clicked) && (submit_validation checkbox == 1) {
do shortcode [submit_manuscript];
redirect to My-account page;
}

How can I do this?

#922762

By the way, this chat does not allow re-editing… there are some inaccuracies above:

- Figure 1. The correct sentence is: On the bottom of Figure 1c there is a 'Save Draft' button.
- Figure 2. The correct sentence is: After clicking on ‘Save Draft’, Author is redirected…

#923036
Figure 4.JPG

Hi,

I found a solution myself by creating a second Layout called 'Template for Submitting Manuscript'. This template contains an Edit Post Form called 'Edit content Manuscripts (submit)' similar to the one described above (ID 234). I just needed to do two things:

- in the View that displays Manuscripts in My Accounts, I needed to add a link to ID 234

 
[toolset-edit-post-link layout_slug="template-for-submitting-manuscripts"] Submit | [/toolset-edit-post-link] 

- In my_plugin.php I needed to add the following code that changes the status to 'submitted' when the form is submitted:

 
add_action('cred_save_data', 'cred_custom_status_action',10,2);
function cred_custom_status_action($post_id, $form_data)
{
    // Change the status of the post just created by CRED
    if ($form_data['id']==234) {
         $my_post = array(
            'ID'           => $post_id,
            'post_status'   => 'submitted'
        );
 
        // Update the post in the database
        wp_update_post( $my_post );
    }
}
#923883

Hi Shane, I suggest you delete the posts before #922750 to keep this clean a tidy for the other users.