Submit page changes for reviewer in beaver builder – wordpress
- Digital Engineering
Submit page changes for reviewer in beaver builder – wordpress
How we can submit page changes for review and make live after reviewed it in beaver builder?
There is revisionary plugin https://wordpress.org/plugins/revisionary/. Revisionary creates a new user role named Revisor. Revisors can make changes to page content, but they do not have the ability to Publish these changes, they can only “Submit for Review” before the changes can be published by an admin.
When using the default WordPress page as a Revisor role, the “Publish Changes” button changes to “Submit for Review”. However, when using the Page Builder to edit page content, the button seems it is generated separately, and the Revisor is able to Publish the changes.
When reviser user update any page and click on publish changes then page status being changed from publish to pending review which is wrong. It should create page revision and current page should work fine. After admin can check review and make new revision as published.
I found the code save_layout function where it update the post status to pending. So i changed it based on user role and it works fine now. Admin can check revision of post.
In wp-content/themes/bb-theme/functions.php file, you have to override method. You need to add this code to make a revision and load previous version.
add_action(“fl_builder_after_save_layout”, “bb_save_post_revision”);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
function bb_save_post_revision($post_id, $publish, $data, $settings){ global $current_user , $wpdb; get_currentuserinfo(); //revert to last revision if current user is revisor if($current_user->roles[0] == ‘revisor’){ //check last revision id $revisions = wp_get_post_revisions( $post_id ); $revisions_ids = array_keys($revisions); $post = get_post($post_id); if(!$post->post_parent){ $last_id = $revisions_ids[0]; $published_last_id = $revisions_ids[1]; if($last_id && $published_last_id){ wp_update_post(array(‘ID’ => $last_id,’post_status’ => ‘pending’,’post_type’ => ‘page’)); FLBuilderModel::restore_revision($post_id , $published_last_id); } $wpdb->insert(“wp_postmeta”, array(“meta_value” => true , “post_id” => $last_id , “meta_key” => “_fl_builder_enabled”)); } } else{ $post = get_post($post_id); if($post->post_parent){ //check last revision id $revisions = wp_get_post_revisions( $post_id ); $revisions_ids = array_keys($revisions); $last_id = $revisions_ids[0]; $published_last_id = $revisions_ids[1]; $post_name = $post->post_parent.’-revision-v1′; wp_update_post(array(‘ID’ => $last_id, ‘post_parent’ => $post->post_parent , ‘post_name’ => $post_name)); wp_update_post(array(‘ID’ => $post_id, ‘post_status’ => ‘inherit’ , ‘post_name’ => $post_name , ‘post_type’ => ‘revision’)); FLBuilderModel::restore_revision($post->post_parent , $published_last_id); } } } |
When revisor submit changes then convert revision to page as pending state. After admin publish page then convert page again to revision and restore latest revision to parent page.
also bb-plugin/includes/ui-js-config.php file, You have to change text of button Publish Changes based on user role.
1 2 3 |
publish: ‘<?php if($current_user->roles[0] != ‘revisor’){ esc_attr_e(‘Publish Changes’, ‘fl-builder’); } else { esc_attr_e(‘Submit Revision’, ‘fl-builder’); } ?>’, |
Above changes you need to add separately so you can get update from future versions.
Use below code to redirect to parent page.
1 2 3 4 5 6 7 8 9 10 11 |
add_action('template_redirect','bb_page_redirect'); function bb_page_redirect(){ $page_id = (int)$_GET['page_id']; $post = get_post($page_id); if($post->post_type == 'revision' && $post->post_parent){ wp_redirect(get_permalink( $post->post_parent )); exit; } } |
Related content
Auriga: Leveling Up for Enterprise Growth!
Auriga’s journey began in 2010 crafting products for India’s