public function admin_init() { //set the settings $page = $this->page; //add_section //you can pass section_id, section_title, section_description, the section id must be unique for this page, section descriptiopn is optional $page->add_section('basic_section', __('Settings', 'buddyblog'), __('Settings for BuddyBlog.', 'buddyblog')); $post_types = get_post_types(array('public' => true)); //public post types $post_type_options = array(); foreach ($post_types as $post_type) { $post_type_object = get_post_type_object($post_type); $post_type_options[$post_type] = $post_type_object->labels->name; } $post_statuses = array('publish' => __('Published', 'buddyblog'), 'draft' => __('Draft', 'buddyblog')); $comment_statuses = array('open' => __('Open', 'buddyblog'), 'close' => __('Closed', 'buddyblog')); $default_post_type = buddyblog_get_posttype() ? buddyblog_get_posttype() : 'post'; $taxonomies = get_object_taxonomies($default_post_type); if (isset($taxonomies['post_format'])) { unset($taxonomies['post_format']); } $tax = array(); foreach ($taxonomies as $taxonomy) { $tax_object = get_taxonomy($taxonomy); $tax[$taxonomy] = $tax_object->labels->name; } //add fields $page->get_section('basic_section')->add_fields(array(array('name' => 'post_type', 'label' => __('Blog Post Type', 'buddyblog'), 'desc' => __('Set the post type for user blog.', 'buddyblog'), 'type' => 'select', 'default' => $default_post_type, 'options' => $post_type_options), array('name' => 'post_status', 'label' => __('Default post status', 'buddyblog'), 'desc' => __('What should be the post status when user submits the form?', 'buddyblog'), 'type' => 'select', 'default' => 'publish', 'options' => $post_statuses), array('name' => 'comment_status', 'label' => __('Comment status?', 'buddyblog'), 'desc' => __('Do you want to allow commenting on user posts?', 'buddyblog'), 'type' => 'select', 'default' => 'open', 'options' => $comment_statuses), array('name' => 'show_comment_option', 'label' => __('Allow post author to enable/disable comment?', 'buddyblog'), 'desc' => __('If you enable, A user will be able to change the comment status for his/her post.', 'buddyblog'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'enable_taxonomy', 'label' => __('Enable Taxonomy?', 'buddyblog'), 'desc' => __('If you enable, users will be able to select terms from the selected taxonomies.', 'buddyblog'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'allowed_taxonomies', 'label' => __('Select allowed taxonomies', 'buddyblog'), 'desc' => __('Please check the taxonomies you want users to be able to attach to their post.', 'buddyblog'), 'type' => 'multicheck', 'default' => 'category', 'options' => $tax), array('name' => 'show_posts_on_profile', 'label' => __('Show single posts on user profile?', 'buddyblog'), 'desc' => __('If you enable it, the permalink to single post will be something like http://yoursite.com/members/username/buddyblog/postname.', 'buddyblog'), 'type' => 'radio', 'default' => 0, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'limit_no_of_posts', 'label' => __('Limit number of posts a user can create?', 'buddyblog'), 'desc' => __('If you enable it, You can control the allowed number of posts from the next option.', 'buddyblog'), 'type' => 'radio', 'default' => 0, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'max_allowed_posts', 'label' => __('How many posts a user can create?', 'buddyblog'), 'desc' => __('Only applies if you have enabled the limit on posts from above option.', 'buddyblog'), 'type' => 'text', 'default' => 10), array('name' => 'publish_cap', 'label' => __('Which capability is required for pusblishing?', 'buddyblog'), 'desc' => __('Please check for https://codex.wordpress.org/Roles_and_Capabilities allowed capabilities.', 'buddyblog'), 'type' => 'text', 'default' => 'read'), array('name' => 'allow_unpublishing', 'label' => __('Allow users to unpublish their own post?', 'buddyblog'), 'desc' => '', 'type' => 'radio', 'default' => 0, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'post_cap', 'label' => __('Which capability is required for creating post?', 'buddyblog'), 'desc' => __('Please check for https://codex.wordpress.org/Roles_and_Capabilities allowed capabilities.', 'buddyblog'), 'type' => 'text', 'default' => 'read'), array('name' => 'allow_edit', 'label' => __('Allow user to edit their post?', 'buddyblog'), 'desc' => __('if you disable it, user will not be able to edit their own post.', 'buddyblog'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))), array('name' => 'dashboard_edit_cap', 'label' => __('Which capability can edit post in backend(WordPress Dashboard)?', 'buddyblog'), 'desc' => __('User with these capabilities will nto be redirected to front end editor for editing post., user will not be able to edit their own post.', 'buddyblog'), 'type' => 'text', 'default' => 'publish_posts'), array('name' => 'allow_delete', 'label' => __('Allow user to delete their post?', 'buddyblog'), 'desc' => __('if you disable it, user will not be able to delete their own post.', 'buddyblog'), 'type' => 'radio', 'default' => 1, 'options' => array(1 => __('Yes', 'buddyblog'), 0 => __('No', 'buddyblog'))))); $page->init(); }
/** * Get the url of the Post for editing * @param type $post_id * @return type */ function buddyblog_get_edit_url($post_id = false) { $bp = buddypress(); $user_id = get_current_user_id(); if (!$user_id) { return; } if (empty($post_id)) { $post_id = get_the_ID(); } //cheeck if current user can edit the post $post = get_post($post_id); //if the author of the post is same as the loggedin user or the logged in user is admin if ($post->post_type != buddyblog_get_posttype()) { return false; } if ($post->post_author != $user_id && !is_super_admin()) { return; } $action_name = 'edit'; if (current_user_can(buddyblog_get_option('dashboard_edit_cap'))) { return get_edit_post_link($post); } //if we are here, we can allow user to edit the post return bp_core_get_user_domain($post->post_author) . $bp->buddyblog->slug . "/{$action_name}/" . $post->ID . '/'; }
/** * Get the id of the post via * @param type $slug * @return int ID of Post */ function buddyblog_get_post_id_from_slug($slug) { if (!$slug) { return 0; } $post = get_page_by_path($slug, false, buddyblog_get_posttype()); if ($post) { return $post->ID; } return 0; }
<?php if (buddyblog_user_has_posted()) { if (bp_is_my_profile() || is_super_admin()) { $status = 'any'; } else { $status = 'publish'; } $query_args = array('author' => bp_displayed_user_id(), 'post_type' => buddyblog_get_posttype(), 'post_status' => $status, 'p' => intval(buddyblog_get_post_id(bp_action_variable(0)))); query_posts($query_args); global $post; // global $withcomments; // $withcomments = true; while (have_posts()) { the_post(); ?> <?php //used to unhook BuddyPress Theme compatibility comment closing function do_action('buddyblog_before_blog_post'); ?> <div class="user-post"> <h2><?php the_title(); ?> </h2> <div class="post-entry"> <p class="alignright"><?php printf(__('Postend on %1$s', 'buddyblog'), get_the_time('m/j/Y'));
/** * This file is used for listing the posts on profile */ ?> <?php if (buddyblog_user_has_posted()) { //let us build the post query if (bp_is_my_profile() || is_super_admin()) { $status = 'any'; } else { $status = 'publish'; } $paged = bp_action_variable(1); $paged = $paged ? $paged : 1; $query_args = array('author' => bp_displayed_user_id(), 'post_type' => buddyblog_get_posttype(), 'post_status' => $status, 'paged' => intval($paged)); query_posts($query_args); ?> <?php if (have_posts()) { ?> <?php while (have_posts()) { the_post(); global $post; ?> <div id="post-<?php the_ID();
function buddyblog_modify_page_title($full_title, $title, $sep, $seplocation) { if (!bp_is_buddyblog_component()) { return $full_title; } $post_type_obj = get_post_type_object(buddyblog_get_posttype()); $full_title = bp_get_displayed_user_fullname() . ' ' . $sep . ' ' . $post_type_obj->labels->name . ' ' . $sep . ' '; if (buddyblog_is_single_post()) { $post_id = buddyblog_get_post_id(bp_action_variable(0)); $post = get_post($post_id); $full_title .= $post->post_title . ' ' . $sep . ' '; } elseif (buddyblog_is_edit_post()) { $full_title .= $post_type_obj->labels->edit_item . ' ' . $sep . ' '; } elseif (buddyblog_is_new_post()) { $full_title .= $post_type_obj->labels->new_item . ' ' . $sep . ' '; } return $full_title; // bp_get_displayed_user_fullname(), ucwords( $component_name ), $sep //if we are here, we are on }
/** * register post form for Posting/editing * @return type */ public function register_form() { //make sure the Front end simple post plugin is active if (!function_exists('bp_new_simple_blog_post_form')) { return; } $post_status = buddyblog_get_option('post_status'); $user_id = get_current_user_id(); if (!buddyblog_user_can_post($user_id)) { $post_status = 'draft'; } $settings = array('post_type' => buddyblog_get_posttype(), 'post_status' => $post_status, 'comment_status' => buddyblog_get_option('comment_status'), 'show_comment_option' => buddyblog_get_option('show_comment_option'), 'custom_field_title' => '', 'custom_fields' => array('_is_buddyblog_post' => array('type' => 'hidden', 'label' => '', 'default' => 1)), 'upload_count' => 0, 'has_post_thumbnail' => 1, 'current_user_can_post' => current_user_can(buddyblog_get_option('post_cap'))); if (buddyblog_get_option('enable_taxonomy')) { $taxonomies = array(); $tax = buddyblog_get_option('allowed_taxonomies'); if (!empty($tax)) { foreach ((array) $tax as $tax_name) { $view = 'checkbox'; //is_taxonomy_hierarchical($tax_name); $taxonomies[$tax_name] = array('taxonomy' => $tax_name, 'view_type' => 'checkbox'); } } if (!empty($taxonomies)) { $settings['tax'] = $taxonomies; } } //use it to add extra fields or filter the post type etc $settings = apply_filters('buddyblog_post_form_settings', $settings); bp_new_simple_blog_post_form('buddyblog-user-posts', $settings); // the blog form }