'', 'name' => __('Name', 'prologue-projects'), 'description' => __('Description', 'prologue-projects'), 'slug' => __('Slug', 'prologue-projects'), 'posts' => __('Posts', 'prologue-projects') ) ); // If we needed to load a javascript dependancy for the theme, this is how it should be done. //$template_dir = basename( dirname( __FILE__ ) ); //wp_register_script( 'admin-projects', get_theme_root_uri() . '/' . $template_dir . '/js/projects.js', array('wp-lists'), '20090210' ); } add_action( 'admin_init', 'pp_admin_init' ); // This stops the header from loading when running pp_admin_projects(), feels dirty. function pp_admin_noheader() { $_GET['noheader'] = true; } add_action( 'load-toplevel_page_prologue-projects', 'pp_admin_noheader' ); // Add admin menu and pages function pp_admin_pages_add() { add_object_page( __( 'Projects', 'prologue-projects' ), __( 'Projects', 'prologue-projects' ), 'manage_categories', 'prologue-projects', 'pp_admin_projects', '' ); add_submenu_page( 'prologue-projects', __( 'Edit', 'prologue-projects' ), __( 'Edit', 'prologue-projects' ), 'manage_categories', 'prologue-projects', 'pp_admin_projects' ); add_submenu_page( 'prologue-projects', __( 'Settings', 'prologue-projects' ), __( 'Settings', 'prologue-projects' ), 'manage_options', 'prologue-projects-settings', 'pp_admin_settings' ); } add_action( 'admin_menu', 'pp_admin_pages_add' ); function pp_insert_project( $project_data, $wp_error = false ) { $cat_ID = null; if ( !$project_category_id = pp_get_category_id( 'projects' ) ) { return false; // This shouldn't happen from the edit screen. } if ( isset( $project_data['project_parent'] ) && ( !$project_data['project_parent'] || -1 == $project_data['project_parent'] ) ) { unset( $project_data['project_parent'] ); } $project_defaults = array( 'project_ID' => 0, 'project_name' => '', 'project_description' => '', 'project_nicename' => '', 'project_parent' => $project_category_id, 'project_website' => '', // Meta 'project_blog' => '', // Meta 'project_svn' => '', // Meta 'project_trac' => '', // Meta 'project_intertrac' => '', // Meta 'project_activity' => '', // Meta 'project_overheard' => '' // Meta ); $project_data = wp_parse_args( $project_data, $project_defaults ); $category_data = array( 'cat_ID' => $project_data['project_ID'], 'cat_name' => $project_data['project_name'], 'category_description' => $project_data['project_description'], 'category_nicename' => $project_data['project_nicename'], 'category_parent' => $project_data['project_parent'] ); $category_id = wp_insert_category( $category_data, $wp_error ); if ( !$wp_error && !$category_id ) { return false; } if ( $wp_error && is_wp_error( $category_id ) ) { return $cat_ID; } $project_meta = array(); $project_meta['logo'] = $project_data['project_logo']; $project_meta['website'] = $project_data['project_website']; $project_meta['blog'] = $project_data['project_blog']; $project_meta['svn'] = $project_data['project_svn']; $project_meta['trac'] = $project_data['project_trac']; $project_meta['intertrac'] = $project_data['project_intertrac']; $project_meta['activity'] = $project_data['project_activity']; $project_meta['overheard'] = $project_data['project_overheard']; if ( $project_meta['activity'] ) { $project_meta['activity'] = str_replace( "\r", '', $project_meta['activity'] ); $project_meta['activity'] = explode( "\n", $project_meta['activity'] ); array_walk( $project_meta['activity'], function(&$a){ $a = trim($a); }); $project_meta['activity'] = array_filter( $project_meta['activity'] ); } if ( $project_meta['overheard'] ) { $project_meta['overheard'] = str_replace( "\r", '', $project_meta['overheard'] ); $project_meta['overheard'] = explode( "\n", $project_meta['overheard'] ); array_walk( $project_meta['overheard'], function(&$a){ $a = trim($a); }); $project_meta['overheard'] = array_filter( $project_meta['overheard'] ); } update_option( 'pp_project_meta_' . $category_id, $project_meta ); return true; } function pp_update_project( $project_data ) { if ( !$project_category_id = pp_get_category_id( 'projects' ) ) { return false; // This shouldn't happen from the edit screen. } if ( isset( $project_data['project_parent'] ) && ( !$project_data['project_parent'] || -1 == $project_data['project_parent'] ) ) { $project_data['project_parent'] = $project_category_id; } $category_data = array( 'cat_ID' => $project_data['project_ID'], 'cat_name' => $project_data['project_name'], 'category_description' => $project_data['project_description'], 'category_nicename' => $project_data['project_nicename'], 'category_parent' => $project_data['project_parent'] ); if ( !$category_id = wp_update_category( $category_data, false ) ) { return false; } $project_meta = array(); $project_meta['logo'] = $project_data['project_logo']; $project_meta['website'] = $project_data['project_website']; $project_meta['blog'] = $project_data['project_blog']; $project_meta['svn'] = $project_data['project_svn']; $project_meta['trac'] = $project_data['project_trac']; $project_meta['intertrac'] = $project_data['project_intertrac']; $project_meta['activity'] = $project_data['project_activity']; $project_meta['overheard'] = $project_data['project_overheard']; if ( $project_meta['activity'] ) { $project_meta['activity'] = str_replace( "\r", '', $project_meta['activity'] ); $project_meta['activity'] = explode( "\n", $project_meta['activity'] ); array_walk( $project_meta['activity'], function(&$a){ $a = trim($a); }); $project_meta['activity'] = array_filter( $project_meta['activity'] ); } if ( $project_meta['overheard'] ) { $project_meta['overheard'] = str_replace( "\r", '', $project_meta['overheard'] ); $project_meta['overheard'] = explode( "\n", $project_meta['overheard'] ); array_walk( $project_meta['overheard'], function(&$a){ $a = trim($a); }); $project_meta['overheard'] = array_filter( $project_meta['overheard'] ); } if ( $current_project_meta = get_option( 'pp_project_meta_' . $category_id ) ) { $project_meta = array_merge( $current_project_meta, $project_meta ); } update_option( 'pp_project_meta_' . $category_id, $project_meta ); return $category_id; } function pp_delete_project( $project_id ) { if ( true !== wp_delete_category( $project_id ) ) { return false; } delete_option( 'pp_project_meta_' . $project_id ); return true; } // Ugly copy of WordPress category_rows() function pp_project_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) { $count = 0; _pp_project_rows( $categories, $count, $parent, $level, $page, $per_page ); } // Ugly copy of WordPress _category_rows() function _pp_project_rows( $categories, &$count, $parent = 0, $level = 0, $page = 1, $per_page = 20 ) { if ( empty( $categories ) ) { $args = array('hide_empty' => 0); if ( !empty($_GET['s']) ) { $args['search'] = $_GET['s']; } $categories = get_categories( $args ); } if ( !$categories ) { return false; } $children = _get_term_hierarchy( 'category' ); $start = ( $page - 1 ) * $per_page; $end = $start + $per_page; $i = -1; ob_start(); foreach ( $categories as $category ) { if ( $count >= $end ) { break; } $i++; if ( $category->parent != $parent ) { continue; } // If the page starts in a subtree, print the parents. if ( $count == $start && $category->parent > 0 ) { $my_parents = array(); while ( $my_parent) { $my_parent = get_category( $my_parent ); $my_parents[] = $my_parent; if ( !$my_parent->parent ) break; $my_parent = $my_parent->parent; } $num_parents = count( $my_parents ); while( $my_parent = array_pop( $my_parents ) ) { echo "\t" . _pp_project_row( $my_parent, $level - $num_parents ); $num_parents--; } } if ( $count >= $start ) { echo "\t" . _pp_project_row( $category, $level ); } unset( $categories[$i] ); // Prune the working set $count++; if ( isset( $children[$category->term_id] ) ) { _pp_project_rows( $categories, $count, $category->term_id, $level + 1, $page, $per_page ); } } $output = ob_get_contents(); ob_end_clean(); echo $output; } // Ugly copy of WordPress _category_row() function _pp_project_row( $category, $level, $name_override = false ) { static $row_class = ''; $category = get_category( $category, OBJECT, 'display' ); $default_cat_id = (int) get_option( 'default_category' ); $pad = str_repeat( '— ', $level ); $name = ( $name_override ? $name_override : $pad . ' ' . $category->name ); $edit_link = "admin.php?page=prologue-projects&action=edit&project_ID=$category->term_id"; if ( current_user_can( 'manage_categories' ) ) { $edit = "name ) ) . "'>" . attribute_escape( $name ) . '
'; $actions = array(); $actions['edit'] = '' . __( 'Edit', 'prologue-projects' ) . ''; if ( $default_cat_id != $category->term_id ) $actions['delete'] = "term_id) . "' onclick=\"if ( confirm('" . js_escape(sprintf(__("You are about to delete this project '%s'\n 'Cancel' to stop, 'OK' to delete.", 'prologue-projects'), $category->name )) . "') ) { return true;}return false;\">" . __('Delete', 'prologue-projects') . ""; $action_count = count($actions); $i = 0; $edit .= '
'; foreach ( $actions as $action => $link ) { ++$i; ( $i == $action_count ) ? $sep = '' : $sep = ' | '; $edit .= "$link$sep"; } $edit .= '
'; } else { $edit = $name; } $row_class = 'alternate' == $row_class ? '' : 'alternate'; $qe_data = get_category_to_edit($category->term_id); $category->count = number_format_i18n( $category->count ); $posts_count = ( $category->count > 0 ) ? "$category->count" : $category->count; $output = ""; $columns = get_column_headers('projects'); $hidden = get_hidden_columns('projects'); foreach ( $columns as $column_name => $column_display_name ) { $class = "class=\"$column_name column-$column_name\""; $style = ''; if ( in_array($column_name, $hidden) ) $style = ' style="display:none;"'; $attributes = "$class$style"; switch ($column_name) { case 'cb': $output .= ""; if ( $default_cat_id != $category->term_id ) { $output .= ""; } else { $output .= " "; } $output .= ''; break; case 'name': $output .= "$edit"; $output .= ''; break; case 'description': $output .= "$category->description"; break; case 'slug': $output .= "$category->slug"; break; case 'posts': $attributes = 'class="posts column-posts num"' . $style; $output .= "$posts_count\n"; } } $output .= ''; return $output; } function pp_admin_projects() { global $user_identity; $title = __( 'Edit Projects', 'prologue-projects' ); if ( !$project_category_id = pp_get_category_id( 'projects' ) ) { ?>

assign an existing category as the container for all projects.', 'prologue-projects' ); ?>

%s category: this is the default one", 'prologue-projects' ), $cat_name ) ); } pp_delete_project( $project_ID ); wp_redirect( 'admin.php?page=prologue-projects&message=2' ); exit; break; case 'bulk-delete': check_admin_referer( 'bulk-projects' ); echo 1; if ( !current_user_can( 'manage_categories' ) ) { wp_die( __( 'You are not allowed to delete projects.', 'prologue-projects' ) ); } foreach ( (array) $_GET['delete'] as $project_ID ) { $project_name = get_catname( $project_ID ); // Don't delete the default cats. if ( $project_ID == get_option( 'default_category' ) ) { wp_die( sprintf( __( "Can’t delete the %s category: this is the default one", 'prologue-projects' ), $cat_name ) ); } pp_delete_project( $project_ID ); } $sendback = wp_get_referer(); wp_redirect( $sendback ); exit; break; case 'edit': if ( !current_user_can( 'manage_categories' ) ) { wp_die( __( 'You are not allowed to edit projects.', 'prologue-projects' ) ); } $title = __( 'Edit Project', 'prologue-projects' ); require_once( ABSPATH . '/wp-admin/admin-header.php' ); $project_ID = (int) $_GET['project_ID']; $project = pp_get_project_data( $project_ID, 'all', 'editing' ); ?>



$project_category_id, 'hide_empty' => 0, 'name' => 'project_parent', 'orderby' => 'name', 'selected' => $project['parent_id'], 'hierarchical' => true, 'show_option_none' => __( 'None', 'prologue-projects' ) ) ); ?>









' . __( 'Search results for “%s”', 'prologue-projects' ) . '', wp_specialchars( stripslashes( $_GET['s'] ) ) ); } ?>


add_query_arg( 'pagenum', '%#%' ), 'format' => '', 'prev_text' => __('«', 'prologue-projects'), 'next_text' => __('»', 'prologue-projects'), 'total' => ceil( $projectstotal / $projectsperpage ), 'current' => $pagenum )); if ( $page_links ) { ?>


Note:
Deleting a project does not delete the posts in that project.', 'prologue-projects' ); ?>

$project_category_id, 'hide_empty' => 0, 'name' => 'project_parent', 'orderby' => 'name', 'selected' => 0, 'hierarchical' => true, 'show_option_none' => __( 'None', 'prologue-projects' ) ) ); ?>

0 ) ? true : false; $author_sidebars = ( isset( $_POST['author_sidebars'] ) && $_POST['author_sidebars'] > 0 ) ? true : false; $_options = array( 'category_projects' => (int) $_POST['category_projects'], 'featured_project' => (int) $_POST['featured_project'], 'project_sidebars' => (bool) $project_sidebars, 'category_updates' => (int) $_POST['category_updates'], 'category_tasks' => (int) $_POST['category_tasks'], 'default_task_level' => (int) $_POST['default_task_level'], 'category_questions' => (int) $_POST['category_questions'], 'default_question_state' => (int) $_POST['default_question_state'], 'author_sidebars' => (bool) $author_sidebars ); update_option( 'prologue_projects', $_options ); $goback = add_query_arg( 'updated', 'true', wp_get_referer() ); wp_redirect( $goback ); return; } } function pp_admin_empty_category_alert( $dropdown ) { if ( !$dropdown ) { return __( 'No categories exist under the parent category specified above.', 'prologue-projects' ); } return $dropdown; } function pp_admin_settings() { $options = pp_get_options(); add_filter( 'wp_dropdown_cats', 'pp_admin_empty_category_alert' ); ?>

__('-- select --', 'prologue-projects'), 'hide_empty' => 0, 'name' => 'category_projects', 'orderby' => 'name', 'selected' => $options['category_projects'], 'hierarchical' => true ) ); ?>
__( '-- select --', 'prologue-projects' ), 'child_of' => $project_category_id, 'hide_empty' => 0, 'name' => 'featured_project', 'orderby' => 'name', 'selected' => $options['featured_project'], 'hierarchical' => true ) ); ?>
/>

__('-- select --', 'prologue-projects'), 'hide_empty' => 0, 'name' => 'category_updates', 'orderby' => 'name', 'selected' => $options['category_updates'], 'hierarchical' => true ) ); ?>

__('-- select --', 'prologue-projects'), 'hide_empty' => 0, 'name' => 'category_tasks', 'orderby' => 'name', 'selected' => $options['category_tasks'], 'hierarchical' => true ) ); ?>
__('-- select --', 'prologue-projects'), 'child_of' => $task_category_id, 'hide_empty' => 0, 'name' => 'default_task_level', 'orderby' => 'name', 'selected' => $options['default_task_level'], 'hierarchical' => true ) ); ?>

__('-- select --', 'prologue-projects'), 'hide_empty' => 0, 'name' => 'category_questions', 'orderby' => 'name', 'selected' => $options['category_questions'], 'hierarchical' => true ) ); ?>
__('-- select --', 'prologue-projects'), 'child_of' => $question_category_id, 'hide_empty' => 0, 'name' => 'default_question_state', 'orderby' => 'name', 'selected' => $options['default_question_state'], 'hierarchical' => true ) ); ?>

/>

$meta ); foreach ( $projects as $project_id => $project_data ) { if ( $project_data[0] ) { $checked[] = $project_id; } } $input_name = 'prologue_projects'; global $is_profile_page; if ( $is_profile_page ) { $heading = __( 'Your projects', 'prologue-projects' ); $instruction = __( 'Select the projects which the you participate in. You will be listed on each projects page.', 'prologue-projects' ); } else { $heading = __( 'The user\'s projects', 'prologue-projects' ); $instruction = __( 'Select the projects which the user participates in. They will be listed on each projects page.', 'prologue-projects' ); } ?>

id, $checked, $input_name ); ?>
$project_role ) { $project_active = isset( $project_active_ids[ $project_id ] ) ? 1 : 0; $projects[$project_id] = array( $project_active, $project_role ); } update_usermeta( $user_id, 'prologue_projects_' . $blog_id, $projects ); } add_action( 'personal_options_update', 'pp_admin_user_form_process' ); add_action( 'edit_user_profile_update', 'pp_admin_user_form_process' ); function pp_admin_head() { ?>