/** * Runs pre-header functions on admin-side only - ran on ALL admin pages * * Checks if plugin has been updated. * * @since 0.1 * */ function admin_init() { global $wp_rewrite, $wp_roles, $wp_crm, $wpdb, $current_user; //** Check if current page is profile page, and load global variable */ WP_CRM_F::maybe_load_profile(); do_action('wp_crm_metaboxes'); //** Add overview table rows. Static because admin_menu is not loaded on ajax calls. */ add_filter("manage_toplevel_page_wp_crm_columns", array('WP_CRM_Core', "overview_columns")); add_action('admin_print_scripts-' . $wp_crm['system']['pages']['settings'], create_function('', "wp_enqueue_script('jquery-ui-tabs');wp_enqueue_script('jquery-cookie');")); add_action('load-crm_page_wp_crm_add_new', array('WP_CRM_Core', 'wp_crm_save_user_data')); // Add metaboxes if (is_array($wp_crm['system']['pages'])) { $sidebar_boxes = array('special_actions'); foreach ($wp_crm['system']['pages'] as $screen) { if (!class_exists($screen)) { continue; } $location_prefixes = array('side_', 'normal_', 'advanced_'); foreach (get_class_methods($screen) as $box) { // Set context and priority if specified for box $context = 'normal'; if (strpos($box, "side_") === 0 || in_array($box, $sidebar_boxes)) { $context = 'side'; } if (strpos($box, "advanced_") === 0) { $context = 'advanced'; } // Get name from slug $label = CRM_UD_F::slug_to_label(str_replace($location_prefixes, '', $box)); add_meta_box($box, $label, array($screen, $box), $screen, $context, 'default'); } } } //** Handle actions */ if (isset($_REQUEST['wp_crm_action'])) { $_wpnonce = $_REQUEST['_wpnonce']; switch ($_REQUEST['wp_crm_action']) { case 'delete_user': $user_id = $_REQUEST['user_id']; if (wp_verify_nonce($_wpnonce, 'wp-crm-delete-user-' . $user_id)) { //** Get IDs of users posts */ $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d", $user_id)); //** Delete user and reassign all their posts to the current user */ if (wp_delete_user($user_id, $current_user->data->ID)) { //** Trash all posts */ if (is_array($post_ids)) { foreach ($post_ids as $trash_post) { wp_trash_post($trash_post); } } wp_redirect(admin_url('admin.php?page=wp_crm&message=user_deleted')); } } break; } } if ($wp_crm['configuration']['replace_default_user_page'] == 'true') { add_filter('admin_user_info_links', array('WP_CRM_Core', 'admin_user_info_links'), 10, 2); } add_filter('admin_title', array('WP_CRM_F', 'admin_title')); }