-
Notifications
You must be signed in to change notification settings - Fork 261
initial draft of adding buddypress support #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clariner
wants to merge
6
commits into
scribu:master
Choose a base branch
from
clariner:buddypress-groups
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4c5a801
initial draft of adding buddypress support
clariner 9914cb8
Merge branch 'master' of https://github.com/clariner/wp-posts-to-post…
clariner 259bfcd
removed redundant buddypress group files from /core and bin/install-w…
clariner 1e3d87e
added bpgroup query init.
clariner 5dca3a8
update urls for testing
clariner 58881ea
removed redundant function call
clariner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
class P2P_Column_Bpgroup extends P2P_Column { | ||
|
||
function __construct( $directed ) { | ||
parent::__construct( $directed ); | ||
|
||
add_action( 'pre_user_query', array( __CLASS__, 'user_query' ), 9 ); | ||
|
||
add_filter( 'manage_users_custom_column', array( $this, 'display_column' ), 10, 3 ); | ||
} | ||
|
||
protected function get_items() { | ||
global $wp_list_table; | ||
|
||
return $wp_list_table->items; | ||
} | ||
|
||
// Add the query vars to the global user query (on the user admin screen) | ||
static function user_query( $query ) { | ||
if ( isset( $query->_p2p_capture ) ) | ||
return; | ||
|
||
// Don't overwrite existing P2P query | ||
if ( isset( $query->query_vars['connected_type'] ) ) | ||
return; | ||
|
||
_p2p_append( $query->query_vars, wp_array_slice_assoc( $_GET, | ||
P2P_URL_Query::get_custom_qv() ) ); | ||
} | ||
|
||
function get_admin_link( $item ) { | ||
$args = array( | ||
'connected_type' => $this->ctype->name, | ||
'connected_direction' => $this->ctype->flip_direction()->get_direction(), | ||
'connected_items' => $item->get_id(), | ||
); | ||
|
||
return add_query_arg( $args, admin_url( 'users.php' ) ); | ||
} | ||
|
||
function display_column( $content, $column, $item_id ) { | ||
return $content . parent::render_column( $column, $item_id ); | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
class P2P_Dropdown_Bpgroup extends P2P_Dropdown_Post { | ||
|
||
function __construct( $directed, $title ) { | ||
parent::__construct( $directed, $title ); | ||
|
||
add_action( 'pre_user_query', array( __CLASS__, 'massage_query' ), 9 ); | ||
|
||
add_action( 'restrict_manage_users', array( $this, 'show_dropdown' ) ); | ||
} | ||
|
||
static function massage_query( $query ) { | ||
if ( isset( $query->_p2p_capture ) ) | ||
return; | ||
|
||
// Don't overwrite existing P2P query | ||
if ( isset( $query->query_vars['connected_type'] ) ) | ||
return; | ||
|
||
_p2p_append( $query->query_vars, self::get_qv() ); | ||
} | ||
|
||
protected function render_dropdown() { | ||
return html( 'div', array( | ||
'style' => 'float: right; margin-left: 16px' | ||
), | ||
parent::render_dropdown(), | ||
html( 'input', array( | ||
'type' => 'submit', | ||
'class' => 'button', | ||
'value' => __( 'Filter', P2P_TEXTDOMAIN ) | ||
) ) | ||
); | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
class P2P_Field_Title_Bpgroup extends P2P_Field_Title { | ||
|
||
function get_data( $item ) { | ||
$data = array( | ||
'title-attr' => $item->get_permalink() | ||
); | ||
|
||
$group = $item->get_object(); | ||
|
||
if ( $group ) { | ||
$data['status']['text'] = __(ucwords($group->status),'clariner'); | ||
} | ||
|
||
return $data; | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ $# -lt 3 ]; then | ||
echo "usage: $0 <db-name> <db-user> <db-pass> [wp-version]" | ||
exit 1 | ||
fi | ||
|
||
DB_NAME=$1 | ||
DB_USER=$2 | ||
DB_PASS=$3 | ||
WP_VERSION=${4-master} | ||
|
||
set -ex | ||
|
||
# set up a WP install | ||
WP_CORE_DIR=/tmp/wordpress/ | ||
mkdir -p $WP_CORE_DIR | ||
wget -nv -O /tmp/wordpress.tar.gz https://github.com/WordPress/WordPress/tarball/$WP_VERSION | ||
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR | ||
|
||
# set up testing suite | ||
svn co --ignore-externals --quiet http://unit-tests.svn.wordpress.org/trunk/ $WP_TESTS_DIR | ||
|
||
cd $WP_TESTS_DIR | ||
cp wp-tests-config-sample.php wp-tests-config.php | ||
sed -i "s:dirname( __FILE__ ) . '/wordpress/':'$WP_CORE_DIR':" wp-tests-config.php | ||
sed -i "s/yourdbnamehere/$DB_NAME/" wp-tests-config.php | ||
sed -i "s/yourusernamehere/$DB_USER/" wp-tests-config.php | ||
sed -i "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php | ||
|
||
# create database | ||
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
P2P_Query_Post::init(); | ||
P2P_Query_User::init(); | ||
P2P_Query_Bpgroup::init(); | ||
|
||
P2P_URL_Query::init(); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
class P2P_Item_Bpgroup extends P2P_Item { | ||
|
||
function get_title() { | ||
return get_the_title( $this->item ); | ||
} | ||
|
||
function get_permalink() { | ||
return get_permalink( $this->item ); | ||
} | ||
|
||
function get_editlink() { | ||
return get_edit_post_link( $this->item ); | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
class P2P_Query_Bpgroup { | ||
|
||
static function init() { | ||
add_action( 'pre_user_query', array( __CLASS__, 'pre_user_query' ), 20 ); | ||
} | ||
|
||
static function pre_user_query( $query ) { | ||
global $wpdb; | ||
|
||
$r = P2P_Query::create_from_qv( $query->query_vars, 'bpgroup' ); | ||
|
||
if ( is_wp_error( $r ) ) { | ||
$query->_p2p_error = $r; | ||
|
||
$query->query_where = " AND 1=0"; | ||
return; | ||
} | ||
|
||
if ( null === $r ) | ||
return; | ||
|
||
list( $p2p_q, $query->query_vars ) = $r; | ||
|
||
$map = array( | ||
'fields' => 'query_fields', | ||
'join' => 'query_from', | ||
'where' => 'query_where', | ||
'orderby' => 'query_orderby', | ||
); | ||
|
||
$clauses = array(); | ||
|
||
foreach ( $map as $clause => $key ) | ||
$clauses[$clause] = $query->$key; | ||
|
||
$clauses = $p2p_q->alter_clauses( $clauses, "$wpdb->bp_groups.ID" ); | ||
|
||
if ( 0 !== strpos( $clauses['orderby'], 'ORDER BY ' ) ) | ||
$clauses['orderby'] = 'ORDER BY ' . $clauses['orderby']; | ||
|
||
foreach ( $map as $clause => $key ) | ||
$query->$key = $clauses[ $clause ]; | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
class P2P_Side_Bpgroup extends P2P_Side { | ||
|
||
protected $item_type = 'P2P_Item_Bpgroup'; | ||
|
||
function __construct( $query_vars ) { | ||
$this->query_vars = $query_vars; | ||
} | ||
|
||
function get_object_type() { | ||
return 'bpgroup'; | ||
} | ||
|
||
function get_desc() { | ||
return __( 'Buddypress Group', P2P_TEXTDOMAIN ); | ||
} | ||
|
||
function get_title() { | ||
return $this->get_desc(); | ||
} | ||
|
||
function get_labels() { | ||
return (object) array( | ||
'singular_name' => __( 'Buddypress Group', P2P_TEXTDOMAIN ), | ||
'search_items' => __( 'Search Buddypress Groups', P2P_TEXTDOMAIN ), | ||
'not_found' => __( 'No Buddypress Groups found.', P2P_TEXTDOMAIN ), | ||
); | ||
} | ||
|
||
function can_edit_connections() { | ||
return true; //current_user_can( 'list_users' ); | ||
} | ||
|
||
function can_create_item() { | ||
return false; | ||
} | ||
|
||
function translate_qv( $qv ) { | ||
if ( isset( $qv['p2p:include'] ) ) | ||
$qv['include'] = _p2p_pluck( $qv, 'p2p:include' ); | ||
|
||
if ( isset( $qv['p2p:exclude'] ) ) | ||
$qv['exclude'] = _p2p_pluck( $qv, 'p2p:exclude' ); | ||
|
||
if ( isset( $qv['p2p:search'] ) && $qv['p2p:search'] ) | ||
$qv['search'] = '*' . _p2p_pluck( $qv, 'p2p:search' ) . '*'; | ||
|
||
if ( isset( $qv['p2p:page'] ) && $qv['p2p:page'] > 0 ) { | ||
if ( isset( $qv['p2p:per_page'] ) && $qv['p2p:per_page'] > 0 ) { | ||
$qv['number'] = $qv['p2p:per_page']; | ||
$qv['offset'] = $qv['p2p:per_page'] * ( $qv['p2p:page'] - 1 ); | ||
} | ||
} | ||
|
||
return $qv; | ||
} | ||
|
||
function do_query( $args ) { | ||
return new BP_Groups_Template($args); | ||
} | ||
|
||
function capture_query( $args ) { | ||
$args['count_total'] = false; | ||
|
||
$uq = new BP_Groups_Group; | ||
$uq->_p2p_capture = true; // needed by P2P_URL_Query | ||
|
||
$r = wp_parse_args( $args, $defaults ); | ||
|
||
$groups = BP_Groups_Group::get( array( | ||
'type' => $r['type'], | ||
'user_id' => $r['user_id'], | ||
'include' => $r['include'], | ||
'exclude' => $r['exclude'], | ||
'search_terms' => $r['search_terms'], | ||
'meta_query' => $r['meta_query'], | ||
'show_hidden' => $r['show_hidden'], | ||
'per_page' => $r['per_page'], | ||
'page' => $r['page'], | ||
'populate_extras' => $r['populate_extras'], | ||
'update_meta_cache' => $r['update_meta_cache'], | ||
'order' => $r['order'], | ||
'orderby' => $r['orderby'], | ||
) ); | ||
|
||
return $groups; | ||
} | ||
|
||
function get_list( $query ) { | ||
$list = new P2P_List( $query->get_results(), $this->item_type ); | ||
|
||
$qv = $query->query_vars; | ||
|
||
if ( isset( $qv['p2p:page'] ) ) { | ||
$list->current_page = $qv['p2p:page']; | ||
$list->total_pages = ceil( $query->get_total() / $qv['p2p:per_page'] ); | ||
} | ||
|
||
return $list; | ||
} | ||
|
||
function is_indeterminate( $side ) { | ||
return true; | ||
} | ||
|
||
function get_base_qv( $q ) { | ||
return array_merge( $this->query_vars, $q ); | ||
} | ||
|
||
protected function recognize( $arg ) { | ||
if ( is_a( $arg, 'BP_Groups_Group' ) ) | ||
return $arg; | ||
|
||
return false; | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2P already has a
bin/install-wp-tests.sh
file, so this file is a duplicate and should be removed.