'',
'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 .= '
assign an existing category as the container for all projects.', 'prologue-projects' ); ?>
Note:
Deleting a project does not delete the posts in that project.', 'prologue-projects' ); ?>
id, $checked, $input_name ); ?> |