Skip to content

Buddypress support #2

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
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

clariner
Copy link

This is the first draft of adding buddypress group support to p2p.

There is an issue which needs to be reviewed.,

  1. All connections are automatically added to the dropdown on page load.

Additional features that need to be added

  1. Allow group parent to be defined so only sub_groups are listed (would require BP Hierarchy to be installed)
  2. Filter groups by if user is a member
  3. Filter groups by if user is an admin
  4. Filter groups by status

All these option should be defined in connection registration

}
}

class P2P_BP_Group_Query {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should move this class to a separate file (call it bp-group-query.php, so that it gets loaded on-demand automatically).

moved P2P_BP_Group_Query to separate file bp-group-query.php
fixed query object type check  in side-bpgroup.php
@clariner
Copy link
Author

I have updated the pull request following your comments.

@scribu
Copy link
Owner

scribu commented Sep 10, 2014

Did you actually test the changes you made?

Ref: scribu/wp-posts-to-posts#454

@clariner
Copy link
Author

Yes, but still I'm still getting the issue of all connections are automatically added to the dropdown on page load.

@scribu
Copy link
Owner

scribu commented Sep 10, 2014

Ok, I'll give it a try myself soon. In the mean time, you might find this class chart helpful:

https://github.com/scribu/wp-posts-to-posts/wiki/Class-diagrams

@scribu
Copy link
Owner

scribu commented Sep 11, 2014

How exactly are you registering the connection type that you're testing with?

I tried this:

p2p_register_connection_type( array(
    'name' => 'posts_to_groups',
    'from' => 'post',
    'to' => 'bpgroup'
) );

It just assumes that 'bpgroup' is a custom post type. The solution is to apply this patch:

diff --git connection-type-factory.php connection-type-factory.php
index bc9a784..5f6f50e 100644
--- connection-type-factory.php
+++ connection-type-factory.php
@@ -54,7 +54,7 @@ class P2P_Connection_Type_Factory {
    private static function create_side( &$args, $direction ) {
        $object = _p2p_pluck( $args, $direction );

-       if ( in_array( $object, array( 'user', 'attachment' ) ) )
+       if ( in_array( $object, array( 'user', 'attachment', 'bpgroup' ) ) )
            $object_type = $object;
        else
            $object_type = 'post';

You'll then get:

Fatal error: Class 'P2P_BP_Group_Query' not found in /Users/User/wp/wp-content/plugins/p2p/vendor/scribu/lib-posts-to-posts/side-bpgroup.php on line 60

That is because you named the file incorrectly - bg-group-query.php, instead of bp-group-query.php.

@clariner
Copy link
Author

I have updated the files after your comments.

I have investigated the issue further and its down to how the sql is generated in prepare_query() in side-bpgroup.php. Its not generating the correct sql to either include or exclude results.

I can adjust the sql so records an not connected on page load but in doing so it stops the search box from working.

@scribu
Copy link
Owner

scribu commented Sep 20, 2014

Ok, no more fatal errors. The search box doesn't work for me because the ajax response is malformed due to a notice:

Notice: Undefined index: connected_type in /Users/User/wp/wp-content/plugins/p2p/vendor/scribu/lib-posts-to-posts/bp-group-query.php on line 113

In order to see this notice, you have to enable WP_DEBUG in wp-config.php.

If you're not familiar with JavaScript development, you should read http://codex.wordpress.org/Using_Your_Browser_to_Diagnose_JavaScript_Errors

@clariner
Copy link
Author

I have resolved the outstanding issue and have been able to and and remove connection successfully.

The following features still need to be included

  1. Filter groups by if user is a member
  2. Filter groups by if user is an admin

I will add these one its confirmed that the base functionality is working outside of my development install.

@scribu
Copy link
Owner

scribu commented Oct 13, 2014

The AJAX still doesn't work for me, due to the same error as before:

PHP Notice:  Undefined index: connected_type in /Users/User/wp/wp-content/plugins/p2p/vendor/scribu/lib-posts-to-posts/bp-group-query.php on line 113

Are you sure you have define( 'WP_DEBUG', true ); in your wp-config.php file?

PS: Sorry for the delay.

@scribu
Copy link
Owner

scribu commented Oct 13, 2014

Oh, there is no connection_type because the admin box calls get_connectable(), which ends up calling BP_Group_Query to get a list of BP groups that don't have any connections.

You need to make BP_Group_Query account for such cases when there simply is no connection type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants