function rul_validate_submission($typeValue, $type) { $success = true; $error_message = ''; if ($type == 'user') { if (!username_exists($typeValue)) { $success = false; $error_message = '<p><strong>****' . __('ERROR: Non-existent username submitted ', 'peters-login-redirect') . '****</strong></p>'; } } elseif ($type == 'role') { // Get a list of roles in the system so that we can verify that a valid role was submitted $rul_existing_rolenames = rul_returnrolenames(); if (!isset($rul_existing_rolenames[$typeValue])) { $success = false; $error_message = '<p><strong>****' . __('ERROR: Non-existent role submitted ', 'peters-login-redirect') . '****</strong></p>'; } } elseif ($type == 'level') { // Get a list of levels in the system so that we can verify that a valid level was submitted $rul_existing_levelnames = array_flip(rul_returnlevelnames()); if (!isset($rul_existing_levelnames[$typeValue])) { $success = false; $error_message = '<p><strong>****' . __('ERROR: Non-existent level submitted ', 'peters-login-redirect') . '****</strong></p>'; } } return array('success' => $success, 'error_message' => $error_message); }
function rul_submit_role($roles, $addresses) { global $wpdb, $rul_db_addresses; // Open the informational div $rul_process_submit = '<div id="message" class="updated fade">'; // Code for closing the informational div $rul_process_close = '</div>'; // ---------------------------------- // Process the rule changes // ---------------------------------- if ($roles && $addresses) { $rul_submit_success = true; $rul_roles_updated = array(); $rul_role_keys = array_keys($roles); $rul_role_loop = 0; // Loop through all submitted roles foreach ($roles as $role) { $i = $rul_role_keys[$rul_role_loop]; // Get a list of roles in the system so that we can verify that a valid role was submitted $rul_existing_rolenames = rul_returnrolenames(); if (isset($rul_existing_rolenames[$role])) { // Check to see whether it matches the "local URL" test $address = rul_safe_redirect($addresses[$i]); if (!$address) { $rul_submit_success = false; $rul_process_submit .= '<p><strong>****' . __('ERROR: Non-local or invalid URL submitted for role ', 'peterloginrd') . $role . '****</strong></p>'; } else { // Update the existing entry or insert a new one $rul_update_role = $wpdb->query('REPLACE INTO ' . $rul_db_addresses . ' SET rul_url = \'' . $address . '\', rul_type = \'role\', rul_value = \'' . $role . '\''); if (!$rul_update_role) { $rul_submit_success = false; $rul_process_submit .= '<p><strong>****' . __('ERROR: Unknown error updating role-specific URL for role ', 'peterloginrd') . $role . '****</strong></p>'; } } // Make a note that this role name was updated $rul_roles_updated[] = $role; } elseif ($role != -1) { $rul_submit_success = false; $rul_process_submit .= '<p><strong>****' . __('ERROR: Non-existent role submitted ', 'peterloginrd') . '****</strong></p>'; } ++$rul_role_loop; } // Built the "not in" MySQL query $rul_roles_notin = "'" . implode("','", $rul_roles_updated) . "'"; // Delete all role rules in the database that weren't updated (in other words, the user unchecked the box next to it) $wpdb->query('DELETE FROM ' . $rul_db_addresses . ' WHERE rul_type = \'role\' AND rul_value NOT IN (' . $rul_roles_notin . ')'); if ($rul_submit_success) { $rul_process_submit .= '<p>' . __('Successfully updated role-specific URLs', 'peterloginrd') . '</p>'; } } // Close the informational div $rul_process_submit .= $rul_process_close; // We've made it this far, so success! return $rul_process_submit; }