コード例 #1
0
function pp_generate_sidebars()
{
    register_sidebar(array('name' => 'All - Top', 'id' => 'pp-sidebar-top', 'before_widget' => '<li id="%1$s" class="widget pp-sidebar-top %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    register_sidebar(array('name' => 'Home', 'id' => 'pp-home-sidebar', 'before_widget' => '<li id="%1$s" class="widget pp-home-sidebar %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    register_sidebar(array('name' => 'Single post page', 'id' => 'pp-single-sidebar', 'before_widget' => '<li id="%1$s" class="widget pp-single-sidebar %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    register_sidebar(array('name' => 'Project (default)', 'id' => 'pp-project-sidebar-default', 'before_widget' => '<li id="%1$s" class="widget pp-project-sidebar pp-project-sidebar-all %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    $options = pp_get_options();
    if ($options['project_sidebars'] && ($projects = pp_get_projects())) {
        foreach ($projects as $project) {
            register_sidebar(array('name' => 'Project - ' . $project->name, 'id' => 'pp-project-sidebar-' . $project->cat_ID, 'before_widget' => '<li id="%1$s" class="widget pp-project-sidebar pp-project-sidebar-' . $project->cat_ID . ' %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
        }
    }
    register_sidebar(array('name' => 'Author (default)', 'id' => 'pp-author-sidebar-default', 'before_widget' => '<li id="%1$s" class="widget pp-author-sidebar pp-author-sidebar-all %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    // Todo: cache the author array
    $authors = array();
    if ($options['author_sidebars'] && ($users = get_users_of_blog())) {
        foreach ($users as $user) {
            $user_object = new WP_User($user->user_id);
            if (!$user_object->has_cap('publish_posts')) {
                continue;
            }
            $authors[] = $user;
        }
    }
    foreach ($authors as $author) {
        register_sidebar(array('name' => 'Author - ' . $author->display_name, 'id' => 'pp-author-sidebar-' . $author->user_id, 'before_widget' => '<li id="%1$s" class="widget pp-author-sidebar pp-author-sidebar-' . $author->user_id . ' %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
    }
    register_sidebar(array('name' => 'All - Bottom', 'id' => 'pp-sidebar-bottom', 'before_widget' => '<li id="%1$s" class="widget pp-sidebar-bottom %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>'));
}
コード例 #2
0
function pp_admin_settings()
{
    $options = pp_get_options();
    add_filter('wp_dropdown_cats', 'pp_admin_empty_category_alert');
    ?>
<div class="wrap">
	<h2><?php 
    _e('Project Settings', 'prologue-projects');
    ?>
</h2>
	<form method="post" action="admin.php?page=prologue-projects-settings">
		<?php 
    wp_nonce_field('prologue-projects-settings');
    ?>
		<input type="hidden" name="option_page" value="prologue-projects-settings" />
		<h3><?php 
    _e('Projects', 'prologue-projects');
    ?>
</h3>
		<table class="form-table">
			<tr valign="top">
				<th scope="row"><label for="category_projects"><?php 
    _e('Projects category', 'prologue-projects');
    ?>
</label></th>
				<td>
					<?php 
    wp_dropdown_categories(array('show_option_none' => __('-- select --', 'prologue-projects'), 'hide_empty' => 0, 'name' => 'category_projects', 'orderby' => 'name', 'selected' => $options['category_projects'], 'hierarchical' => true));
    ?>
<br />
					<span class="setting-description"><?php 
    _e('Select the category which contains all your projects.', 'prologue-projects');
    ?>
</span>
				</td>
			</tr>
			<tr valign="top">
				<th scope="row"><label for="featured_project"><?php 
    _e('Featured project', 'prologue-projects');
    ?>
</label></th>
				<td>
<?php 
    if ($project_category_id = pp_get_category_id('projects')) {
        ?>
					<?php 
        wp_dropdown_categories(array('show_option_none' => __('-- select --', 'prologue-projects'), 'child_of' => $project_category_id, 'hide_empty' => 0, 'name' => 'featured_project', 'orderby' => 'name', 'selected' => $options['featured_project'], 'hierarchical' => true));
        ?>
<br />
					<span class="setting-description"><?php 
        _e('Select the project to be featured on the projects base page.', 'prologue-projects');
        ?>
</span>
<?php 
    } else {
        ?>
					<span class="setting-description"><?php 
        _e('You must select and save the "projects" category above first.', 'prologue-projects');
        ?>
</span>
<?php 
    }
    ?>
				</td>
			</tr>
			<tr valign="top">
				<th scope="row"><label for="project_sidebars"><?php 
    _e('Create project sidebars', 'prologue-projects');
    ?>
</label></th>
				<td>
<?php 
    $project_sidebars_checked = $options['project_sidebars'] ? 'checked="checked" ' : '';
    ?>
					<input id="project_sidebars" name="project_sidebars" type="checkbox" value="1" <?php 
    echo $project_sidebars_checked;
    ?>
/>
					<?php 
    _e('Create unique widget areas for each project\'s page.', 'prologue-projects');
    ?>
				</td>
			</tr>
		</table>
		<h3><?php 
    _e('Updates', 'prologue-projects');
    ?>
</h3>
		<table class="form-table">
			<tr valign="top">
				<th scope="row"><label for="category_updates"><?php 
    _e('Updates category', 'prologue-projects');
    ?>
</label></th>
				<td>
					<?php 
    wp_dropdown_categories(array('show_option_none' => __('-- select --', 'prologue-projects'), 'hide_empty' => 0, 'name' => 'category_updates', 'orderby' => 'name', 'selected' => $options['category_updates'], 'hierarchical' => true));
    ?>
<br />
					<span class="setting-description"><?php 
    _e('Select the category which will contain updates.', 'prologue-projects');
    ?>
</span>
				</td>
			</tr>
		</table>
		<h3><?php 
    _e('Tasks', 'prologue-projects');
    ?>
</h3>
		<table class="form-table">
			<tr valign="top">
				<th scope="row"><label for="category_tasks"><?php 
    _e('Tasks category', 'prologue-projects');
    ?>
</label></th>
				<td>
					<?php 
    wp_dropdown_categories(array('show_option_none' => __('-- select --', 'prologue-projects'), 'hide_empty' => 0, 'name' => 'category_tasks', 'orderby' => 'name', 'selected' => $options['category_tasks'], 'hierarchical' => true));
    ?>
<br />
					<span class="setting-description"><?php 
    _e('Select the category which will contain tasks.', 'prologue-projects');
    ?>
</span>
				</td>
			</tr>
			<tr valign="top">
				<th scope="row"><label for="default_task_level"><?php 
    _e('Default task level', 'prologue-projects');
    ?>
</label></th>
				<td>
<?php 
    if ($task_category_id = pp_get_category_id('tasks')) {
        ?>
					<?php 
        wp_dropdown_categories(array('show_option_none' => __('-- select --', 'prologue-projects'), 'child_of' => $task_category_id, 'hide_empty' => 0, 'name' => 'default_task_level', 'orderby' => 'name', 'selected' => $options['default_task_level'], 'hierarchical' => true));
        ?>
<br />
					<span class="setting-description"><?php 
        _e('Select the level which new tasks will be set to by default.', 'prologue-projects');
        ?>
</span>
<?php 
    } else {
        ?>
					<span class="setting-description"><?php 
        _e('You must select and save the "tasks" category above first.', 'prologue-projects');
        ?>
</span>
<?php 
    }
    ?>
				</td>
			</tr>
		</table>
		<h3><?php 
    _e('Questions', 'prologue-projects');
    ?>
</h3>
		<table class="form-table">
			<tr valign="top">
				<th scope="row"><label for="category_questions"><?php 
    _e('Questions category', 'prologue-projects');
    ?>
</label></th>
				<td>
					<?php 
    wp_dropdown_categories(array('show_option_none' => __('-- select --', 'prologue-projects'), 'hide_empty' => 0, 'name' => 'category_questions', 'orderby' => 'name', 'selected' => $options['category_questions'], 'hierarchical' => true));
    ?>
<br />
					<span class="setting-description"><?php 
    _e('Select the category which will contain questions.', 'prologue-projects');
    ?>
</span>
				</td>
			</tr>
			<tr valign="top">
				<th scope="row"><label for="default_question_state"><?php 
    _e('Default question state', 'prologue-projects');
    ?>
</label></th>
				<td>
<?php 
    if ($question_category_id = pp_get_category_id('questions')) {
        ?>
					<?php 
        wp_dropdown_categories(array('show_option_none' => __('-- select --', 'prologue-projects'), 'child_of' => $question_category_id, 'hide_empty' => 0, 'name' => 'default_question_state', 'orderby' => 'name', 'selected' => $options['default_question_state'], 'hierarchical' => true));
        ?>
<br />
					<span class="setting-description"><?php 
        _e('Select the state which new questions will be set to by default.', 'prologue-projects');
        ?>
</span>
<?php 
    } else {
        ?>
					<span class="setting-description"><?php 
        _e('You must select and save the "questions" category above first.', 'prologue-projects');
        ?>
</span>
<?php 
    }
    ?>
				</td>
			</tr>
		</table>
		<h3><?php 
    _e('Authors', 'prologue-projects');
    ?>
</h3>
		<table class="form-table">
			<tr valign="top">
				<th scope="row"><label for="author_sidebars"><?php 
    _e('Create author sidebars', 'prologue-projects');
    ?>
</label></th>
				<td>
<?php 
    $author_sidebars_checked = $options['author_sidebars'] ? 'checked="checked" ' : '';
    ?>
					<input id="author_sidebars" name="author_sidebars" type="checkbox" value="1" <?php 
    echo $author_sidebars_checked;
    ?>
/>
					<?php 
    _e('Create unique widget areas for each author\'s page.', 'prologue-projects');
    ?>
				</td>
			</tr>
		</table>
		<p class="submit">
			<input class="button-primary" type="submit" name="Submit" value="<?php 
    _e('Save Changes', 'prologue-projects');
    ?>
" />
			<input type="hidden" name="action" value="update" />
		</p>
	</form>
</div>
<?php 
}
コード例 #3
0
function pp_maybe_insert_post()
{
    if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'post') {
        if (!is_user_logged_in()) {
            auth_redirect();
        }
        if (!current_user_can('publish_posts')) {
            $goback = add_query_arg('result', -2, wp_get_referer());
            wp_redirect($goback);
            exit;
        }
        check_admin_referer('pp-update');
        $user_id = $current_user->user_id;
        $post_content = $_POST['posttext'];
        $tags = $_POST['tags'];
        $char_limit = 40;
        $post_title = trim(strip_tags($post_content));
        if (strlen($post_title) > $char_limit) {
            $post_title = substr($post_title, 0, $char_limit) . ' ... ';
        }
        $categories = isset($_POST['post_category']) ? $_POST['post_category'] : array();
        if (!is_array($categories)) {
            $categories = array($categories);
        }
        if (isset($_POST['task_level'])) {
            $categories[] = (int) $_POST['task_level'];
        }
        $options = pp_get_options();
        $category_updates_id = $options['category_updates'];
        $category_tasks_id = $options['category_tasks'];
        $category_questions_id = $options['category_questions'];
        $category_default_questions_status = $options['default_question_state'];
        if (isset($_GET['tasks'])) {
            $type = 'tasks';
        } elseif (isset($_GET['questions'])) {
            $type = 'questions';
        } else {
            $type = 'updates';
        }
        switch ($type) {
            case 'questions':
                if ($category_questions_id) {
                    $categories[] = $category_questions_id;
                    $categories[] = $category_default_questions_status;
                }
                break;
            case 'tasks':
                if ($category_tasks_id) {
                    $categories[] = $category_tasks_id;
                }
                break;
            case 'updates':
            default:
                if ($category_updates_id) {
                    $categories[] = $category_updates_id;
                }
                break;
        }
        $categories = array_filter($categories);
        $post_id = wp_insert_post(array('post_author' => $user_id, 'post_title' => $post_title, 'post_content' => $post_content, 'tags_input' => $tags, 'post_status' => 'publish', 'post_category' => $categories));
        if (!$post_id) {
            $goback = add_query_arg('result', -1, wp_get_referer());
        } else {
            $goback = add_query_arg('result', $post_id, wp_get_referer());
        }
        wp_redirect($goback);
        exit;
    }
}