Author Approval

Written by Jake Evans


Enter the E-mail address you'd like page rejections to be forwarded to:

You didn't enter an E-mail address! Enter an E-mail address and try again!


You didn't enter a valid e-mail address... try again!



Click below to view the pages that have been approved by the Authors:



get_results("SELECT * FROM $wpdb->author_approval_jre_approved_pages_log WHERE temp_storage_for_user_id is null "); if (!empty($approved_pages)) { // Create the list of approved pages foreach($approved_pages as $pages_approved){ echo $pages_approved->username; echo ' approved '; ?>page_title; ?>approved_urls; echo ') '; echo 'on '; echo $pages_approved->date; ?>

(Warning, this will reset ALL currently approved pages, there is no backup!)

No one has approved any pages yet!

query($wpdb->prepare("DELETE FROM $wpdb->author_approval_jre_approved_pages_log WHERE is_page = %s",'1')); echo 'All approved pages have been reset!'; } ?>


Select a user from the drop-down menu below to assign pages to:

prefix . 'author_approval_jre_approved_pages_log'; $wpdb->insert( $table_name, array( 'temp_storage_for_user_id' => $user_id_for_authorship ) ); } /* When the drop-down menu is set AND the "Add Checked Pages" button has NOT been clicked * create checkboxes next to a list of all pages the selected user is NOT an author of */ if ((isset($_POST['my_dropdown'])) && (!isset($_POST['add_checked_pages']))) { if( strrchr(htmlspecialchars($_POST['my_dropdown']), '&')){ return; } if(preg_match('/[A-Z]+[a-z]/', $_POST['my_dropdown'])){ return; } $user = get_userdata( $_POST['my_dropdown'] ); $checkfield = array(); $pages = get_pages(); ?>
display_name ?> can be set as the Author of these pages below:
post_author) != ($_POST['my_dropdown'])){ ?> ID, (array) $checkfield) ) { ?> checked />
prefix . 'author_approval_jre_approved_pages_log'; $wpdb->insert( $table_name, array( 'temp_storage_for_user_id' => $user_id_for_authorship ) ); ?>
prefix . 'author_approval_jre_approved_pages_log'; $lastid = $wpdb->insert_id; $wpdb->delete( $table_name, array( 'ID' => $lastid ) ); $lastid_for_reading = (($wpdb->insert_id)-1); $thepost = $wpdb->get_row("SELECT * FROM $wpdb->author_approval_jre_approved_pages_log WHERE ID = $lastid_for_reading"); $selected_users_id = $thepost->temp_storage_for_user_id; if(isset($_POST['checkfield'])){ foreach($_POST['checkfield'] as $pages_checked){ $my_post = array( 'ID' => $pages_checked, 'post_author' => $selected_users_id ); wp_update_post($my_post); } $pages = get_pages('authors='.$selected_users_id); $user = get_userdata( $selected_users_id ); ?>

display_name ?> is now the Author of all the pages below:

post_title; ?>

You didn't check any pages! Select an Author and try again!

author_approval_jre_approved_pages_log = "{$wpdb->prefix}author_approval_jre_approved_pages_log"; } // Code for creating the database table for page approvals. This is created once upon plugin activation. function author_approval_jre_create_tables() { require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); global $wpdb; global $charset_collate; // Call this manually as we may have missed the init hook author_approval_jre_register_approved_pages_table(); // Creating the table $sql_create_table = "CREATE TABLE {$wpdb->author_approval_jre_approved_pages_log} ( username varchar(255), ID bigint(255) auto_increment, page_title varchar(255) NOT NULL default 'updated', approved_urls varchar(255) NOT NULL default 'updated', date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, temp_storage_for_user_id bigint(255), is_page int(1), PRIMARY KEY (ID), KEY approved_urls (approved_urls) ) $charset_collate; "; dbDelta( $sql_create_table ); } // Code for deleting author_approval_jre_approved_pages_log table upon deactivation of plugin function author_approval_jre_delete_tables() { global $wpdb; $table = $wpdb->prefix."author_approval_jre_approved_pages_log"; $wpdb->query("DROP TABLE IF EXISTS $table"); } function author_approval_jre_approval_rejection_creation_and_execution(){ $plugin_url = plugins_url( '/', __FILE__ ); // Getting user's role global $current_user; get_currentuserinfo(); $user_roles = $current_user->roles; $user_role = array_shift($user_roles); // If user's role is "Author", write logic to create APPROVAL and REJECTION admin bar links if($user_role == 'author'){ $role = get_role( 'author' ); $role->add_cap( 'edit_pages' ); // If user is currently editing a page, create and display APPROVAL and REJECTION admin bar links $current_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; if(strstr($current_url, 'post.php')){ $pos = strpos($current_url, '&a'); $pos = substr($current_url, 0, $pos); //query the database for this URL global $wpdb; $table = $wpdb->prefix."author_approval_jre_approved_pages_log"; $url_column = $wpdb->get_results( "SELECT approved_urls FROM $table"); // Checking to see if URL is already in database. If so, page has been approved already. Quit function, never create approve/reject links in admin bar. foreach($url_column as $stored_url){ $stored_url = serialize($stored_url); if(strstr($stored_url, $pos)){ echo 'this page has already been approved'; return; } } // This adds the Approval link in the admin bar add_action( 'admin_bar_menu', 'author_approval_jre_toolbar_link_to_approve', 999 ); function author_approval_jre_toolbar_link_to_approve( $wp_admin_bar ) { $args = array( 'id' => 'approve_this_page', 'title' => 'Approve This Page', 'href' => '#' ); $wp_admin_bar->add_node( $args ); } // This adds the Rejection link in the admin bar add_action( 'admin_bar_menu', 'author_approval_jre_toolbar_link_to_reject', 999 ); function author_approval_jre_toolbar_link_to_reject( $wp_admin_bar ) { $args = array( 'id' => 'reject_this_page', 'title' => 'Reject This Page', 'href' => '#', 'meta' => array( 'class' => 'author_approval_jre_toolbar_link_to_reject' ) ); $wp_admin_bar->add_node( $args ); } } } } // The JavaScript to be added to the footer for the approval link function author_approval_jre_page_approval_javascript() { ?> prefix . 'author_approval_jre_approved_pages_log'; global $current_user; get_currentuserinfo(); // Getting page ID from URL, then using that to get page title $urltemp = strstr($url, '='); $urltemp = substr($urltemp, 1); $urltemp = (int)$urltemp; $title_of_page_to_be_duplicated = get_the_title( $urltemp ); // Inserting the approval info into the database $wpdb->insert( $table_name, array( 'approved_urls' => $url, 'page_title' => $title_of_page_to_be_duplicated, 'username' => $current_user -> display_name, 'is_page' => '1' ) ); echo 'Thanks for approving your page! The time, date, page url, and your username have been recorded. You will no longer see the approval or rejection links in your admin bar.'; wp_die(); // this is required to terminate immediately and return a proper response } // The JavaScript to be added to the footer for the rejection link function author_approval_jre_page_rejection_javascript() { ?>