diff --git a/bp-docs.php b/bp-docs.php index f4c08202..3d84b43e 100644 --- a/bp-docs.php +++ b/bp-docs.php @@ -108,6 +108,8 @@ function includes() { require( BP_DOCS_INCLUDES_PATH . 'theme-bridge.php' ); + require( BP_DOCS_INCLUDES_PATH . 'edit-lock.php' ); + // formatting.php contains filters and functions used to modify appearance only require( BP_DOCS_INCLUDES_PATH . 'formatting.php' ); @@ -173,8 +175,9 @@ function load_constants() { } // You should never really need to override this bad boy - if ( !defined( 'BP_DOCS_INSTALL_PATH' ) ) - define( 'BP_DOCS_INSTALL_PATH', WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . BP_DOCS_PLUGIN_SLUG . DIRECTORY_SEPARATOR ); + if ( !defined( 'BP_DOCS_INSTALL_PATH' ) ) { + define( 'BP_DOCS_INSTALL_PATH', plugin_dir_path( __FILE__ ) ); + } // Ditto if ( !defined( 'BP_DOCS_INCLUDES_PATH' ) ) @@ -541,32 +544,12 @@ function protect_doc_access() { } if ( ! bp_docs_current_user_can( $action ) ) { - $redirect_to = wp_get_referer(); - - if ( ! $redirect_to || trailingslashit( $redirect_to ) == trailingslashit( wp_guess_url() ) ) { - $redirect_to = bp_get_root_domain(); - } - - switch ( $action ) { - case 'read' : - $message = __( 'You are not allowed to read that Doc.', 'bp-docs' ); - break; + $redirect_to = wp_login_url( bp_docs_get_doc_link() ); - case 'create' : - $message = __( 'You are not allowed to create Docs.', 'bp-docs' ); - break; - - case 'edit' : - $message = __( 'You are not allowed to edit that Doc.', 'bp-docs' ); - break; - - case 'view_history' : - $message = __( 'You are not allowed to view that Doc\'s history.', 'bp-docs' ); - break; - } - - bp_core_add_message( $message, 'error' ); - bp_core_redirect( $redirect_to ); + bp_core_no_access( array( + 'mode' => 2, + 'redirect' => $redirect_to, + ) ); } } diff --git a/includes/addon-taxonomy.php b/includes/addon-taxonomy.php index 2a6929f7..fa64dda6 100644 --- a/includes/addon-taxonomy.php +++ b/includes/addon-taxonomy.php @@ -110,7 +110,7 @@ function register_taxonomy() { function register_with_post_type() { $this->taxonomies = array( /* 'category', */ $this->docs_tag_tax_name ); - foreach( $this->taxonomies as $tax ) { + foreach ( $this->taxonomies as $tax ) { register_taxonomy_for_object_type( $tax, bp_docs_get_post_type_name() ); } } @@ -125,7 +125,7 @@ function register_with_post_type() { * @return int $post_id Returns the doc's post_id on success */ function save_post( $query ) { - foreach( $this->taxonomies as $tax_name ) { + foreach ( $this->taxonomies as $tax_name ) { if ( $tax_name == 'category' ) $tax_name = 'post_category'; @@ -151,10 +151,6 @@ function save_post( $query ) { } wp_set_post_terms( $query->doc_id, $terms, $tax_name ); - - // Store these terms in the item term cache, to be used for tag clouds etc - $this->cache_terms_for_item( $terms, $query->doc_id ); - } do_action( 'bp_docs_taxonomy_saved', $query ); @@ -180,11 +176,11 @@ function delete_post( $new_status, $old_status, $post ) { $doc_id = $post->ID; // Terms for the item (group, user, etc) - $item_terms = $this->get_item_terms(); + $item_terms = $this->get_item_terms(); // Terms for the doc - $doc_terms = wp_get_post_terms( $doc_id, $this->docs_tag_tax_name ); + $doc_terms = wp_get_post_terms( $doc_id, $this->docs_tag_tax_name ); - foreach( $doc_terms as $doc_term ) { + foreach ( $doc_terms as $doc_term ) { $term_name = $doc_term->name; // If the term is currently used (should always be true - this is a @@ -201,8 +197,6 @@ function delete_post( $new_status, $old_status, $post ) { } } } - - $this->save_item_terms( $item_terms ); } /** @@ -212,72 +206,21 @@ function delete_post( $new_status, $old_status, $post ) { * @since 1.0-beta */ function show_terms() { - foreach( $this->taxonomies as $tax_name ) { + foreach ( $this->taxonomies as $tax_name ) { $html = ''; - $tagtext = array(); - $tags = wp_get_post_terms( get_the_ID(), $tax_name ); + $tagtext = array(); + $tags = wp_get_post_terms( get_the_ID(), $tax_name ); - foreach( $tags as $tag ) { - $tagtext[] = bp_docs_get_tag_link( array( 'tag' => $tag->name ) ); - } + foreach ( $tags as $tag ) { + $tagtext[] = bp_docs_get_tag_link( array( 'tag' => $tag->name ) ); + } if ( ! empty( $tagtext ) ) { $html = '

' . sprintf( __( 'Tags: %s', 'bp-docs' ), implode( ', ', $tagtext ) ) . '

'; } - echo apply_filters( 'bp_docs_taxonomy_show_terms', $html, $tagtext ); - } - } - - /** - * Store taxonomy terms and their use count for a given item - * - * @package BuddyPress Docs - * @since 1.0-beta - * - * @param array $terms The terms submitted in the most recent save - * @param int $doc_id The unique id of the doc - */ - function cache_terms_for_item( $terms = array(), $doc_id ) { - $existing_terms = $this->get_item_terms(); - - // First, make sure that each submitted term is recorded - foreach ( $terms as $term ) { - if ( empty( $existing_terms[$term] ) || ! is_array( $existing_terms[$term] ) ) - $existing_terms[$term] = array(); - - if ( ! in_array( $doc_id, $existing_terms[$term] ) ) - $existing_terms[$term][] = $doc_id; + echo apply_filters( 'bp_docs_taxonomy_show_terms', $html, $tagtext ); } - - // Then, loop through to see if any existing terms have been deleted - foreach ( $existing_terms as $existing_term => $docs ) { - // If the existing term is not in the list of submitted terms... - if ( ! in_array( $existing_term, $terms ) ) { - // ... check to see whether the current doc is listed under that - // term. If so, that indicates that the term has been removed from - // the doc - $key = array_search( $doc_id, $docs ); - if ( $key !== false ) { - unset( $docs[$key] ); - } - } - - // Reset the array keys for the term's docs - $docs = array_values( $docs ); - - if ( empty( $docs ) ) { - // If there are no more docs associated with the term, we can remove - // it from the array - unset( $existing_terms[$existing_term] ); - } else { - // Othewise, store the docs back in the existing terms array - $existing_terms[$existing_term] = $docs; - } - } - - // Save the terms back to the item - $this->save_item_terms( $existing_terms ); } /** @@ -322,23 +265,24 @@ function save_item_terms( $terms ) { function modify_tax_query( $tax_query ) { // Check for the existence tag filters in the request URL - if ( !empty( $_REQUEST['bpd_tag'] ) ) { + if ( ! empty( $_REQUEST['bpd_tag'] ) ) { // The bpd_tag argument may be comma-separated $tags = explode( ',', urldecode( $_REQUEST['bpd_tag'] ) ); // Clean up the tag input - foreach( $tags as $key => $value ) { + foreach ( $tags as $key => $value ) { $tags[$key] = esc_attr( $value ); } $tax_query[] = array( 'taxonomy' => $this->docs_tag_tax_name, 'terms' => $tags, - 'field' => 'slug' + 'field' => 'slug', ); - if ( !empty( $_REQUEST['bool'] ) && $_REQUEST['bool'] == 'and' ) + if ( !empty( $_REQUEST['bool'] ) && $_REQUEST['bool'] == 'and' ) { $tax_query['operator'] = 'AND'; + } } return apply_filters( 'bp_docs_modify_tax_query_for_tax', $tax_query ); @@ -367,11 +311,11 @@ function tags_th() { */ function tags_td() { - $tags = get_the_terms( get_the_ID(), $this->docs_tag_tax_name ); - $tagtext = array(); + $tags = get_the_terms( get_the_ID(), $this->docs_tag_tax_name ); + $tagtext = array(); - foreach( (array)$tags as $tag ) { - if ( !empty( $tag->name ) ) { + foreach ( (array) $tags as $tag ) { + if ( ! empty( $tag->name ) ) { $tagtext[] = bp_docs_get_tag_link( array( 'tag' => $tag->name ) ); } } @@ -399,10 +343,10 @@ function tags_td() { function info_header_message( $message, $filters ) { $this->current_filters = $filters; - if ( !empty( $filters['tags'] ) ) { + if ( ! empty( $filters['tags'] ) ) { $tagtext = array(); - foreach( $filters['tags'] as $tag ) { + foreach ( $filters['tags'] as $tag ) { $tagtext[] = bp_docs_get_tag_link( array( 'tag' => $tag ) ); } @@ -436,25 +380,11 @@ function filter_markup() {