Git Product home page Git Product logo

wp-content-connect's Introduction

WP Content Connect

WordPress library that enables direct relationships for posts to posts and posts to users.

Support Level Release Version WordPress tested up to version GPLv3 License

Installation and Usage

WP Content Connect can be used as a plugin or a standalone library. The easiest way to use this is to install as a plugin and activate.

Composer install

As a library

First, require this repository using the command line:

$ composer require 10up/wp-content-connect

or directly in composer.json:

  "require": {
    "10up/wp-content-connect": "^1.5.0"
  }

This will install WP Content Connect to your vendor folder and allow you to to use it as a library by calling \TenUp\ContentConnect\Plugin::instance(); from your code.

As a plugin

Alternatively, if you prefer to have composer install it as a plugin, you may redeclare this package in your composer.json using the following example:

{
  "name": "your project name",
  "repositories": [
    {
      "type": "package",
      "package": {
        "name": "10up/wp-content-connect",
        "type": "wordpress-plugin",
        "version": "1.5.0",
        "source": {
          "url": "https://github.com/10up/wp-content-connect.git",
          "type": "git",
          "reference": "1.5.0"
        }
      }
    }
  ],
  "require": {
    "10up/wp-content-connect": "^1.5",
    "composer/installers": "^1.7"
  },
  "extra": {
    "installer-paths": {
      "plugins/wp-content-connect/": [
        "10up/wp-content-connect"
      ]
    }
  }
}

Defining Relationships

Relationships can be defined once any post types they utilize are defined by hooking into the tenup-content-connect-init action. This action is fired on the WordPress init action, at priority 100, so any post types must be registered prior to this. Currently supported relationships are post-to-post and post-to-user. Additionally, when registering a relationship, you must specify a name. Name enables multiple distinct relationships between the same object types. For instance, you could have a post-to-user relationship for post type post with a type of researchers to indicate that any user in the "researcher" relationship is a researcher for the post and have another post-to-user relationship defined for post type post with a name of backer to indicate that any user in the "backer" relationship contributes financially to the post.

define_post_to_post( $from, $to, $name, $args = array() )

This method defines a post to post relationship between two post types, $from and $to.

Parameters:

$from (String) First post type in the relationship

$to (String|Array) Second post type(s) in the relationship

$name (String) Unique name for this relationship, used to distinguish between multiple relationships between the same post types

$args (Array) Array of options for the relationship

Args:

Args expects options for the from and to sides of the relationship as top level keys. Options for each direction are as follows:

  • enable_ui (Bool) - Should the default UI be enabled for the current side of this relationship
  • sortable (Bool) - Should the relationship be sortable for the current side of this relationship
  • labels (Array) - Labels used in the UI for the relationship. Currently only expects one value, name (String)

Return Value

This method returns an instance of \TenUp\ContentConnect\Relationships\PostToPost specific to this relationship. The object can then be used to manage related items manually, if required. See the <@TODO insert link> section below.

Example:

function my_define_relationships( $registry ) {
    $args = array(
        'from' => array(
            'enable_ui' => true,
            'sortable' => true,
            'labels' => array(
                'name' => 'Related Tires',
            ),
        ),
        'to' => array(
            'enable_ui' => false,
            'sortable' => false,
            'labels' => array(
                'name' => 'Related Cars',
            ),
        ),
    );

    $relationship = $registry->define_post_to_post( 'car', 'tire', 'car-tires', $args );    
}
add_action( 'tenup-content-connect-init', 'my_define_relationships' );

define_post_to_user( $post_type, $name $args = array() )

This method defines a post to user relationship between the supplied post type and users.

Parameters:

$post_type (String) The post type to be related to users

$name (String) Unique name for this relationship, used to distinguish between multiple relationships between users and the same post type

$args (Array) Array of options for the relationship

Args:

Args expects options for the from (post type) side of the relationship as a top level key. Options are as follows:

  • enable_ui (Bool) - Should the default UI be enabled for the current side of this relationship
  • sortable (Bool) - Should the relationship be sortable for the current side of this relationship
  • labels (Array) - Labels used in the UI for the relationship. Currently only expects one value, name (String)

Return Value

This method returns an instance of \TenUp\ContentConnect\Relationships\PostToUser specific to this relationship. The object can then be used to manage related items manually, if required. See the <@TODO insert link> section below.

Example:

function my_define_relationships( $registry ) {
    $args = array(
        'from' => array(
            'enable_ui' => true,
            'sortable' => false,
            'labels' => array(
                'name' => 'Related Users',
            ),
        ),
    )
    
    $relationship = $registry->define_post_to_user( 'post', 'related', $args );   
}
add_action( 'tenup-content-connect-init', 'my_define_relationships' );

There is not currently support for rendering any default UIs on the User side of these relationships

Sortable Relationships

Relationships can optionally support sortable related items. Order can be stored independently for both sides of a relationship. For example, if you have cars and tires, you may have a car that has 5 related tires, and if you wanted to sort the tires, you do so from the car page. You could then go to one of the related tires, and order all of the cars it is related to separately.

Since you can manage this relationship from both post types in the relationship, if you added a tire from the car page, and you had relationship data previously stored on the tire, the NEW car in the relationship will still show up in query results, at the very end (after all of your other pre-ordered data).

Query Integration

Querying for relationships is enabled via a new relationship_query parameter for WP_Query. The format for relationship_query is very similar to tax_query.

A valid relationship query segment requires name and either related_to_post OR related_to_user. As many relationship segments as necessary can be combined to create a specific set of results, and can be combined using an AND or OR relation.

Top Level Args:

  • relation (String) Can be either AND (default) or OR. How all of the segments in the relationship should be combined.

Segment Args:

  • name (String) The unique name for the relationship you are querying. Should match a name from registering relationships.
  • related_to_post (Int) Find items in the relationship related to this post ID. Cannot be used in the same segment as related_to_user.
  • related_to_user (Int) Find items in the relationship related to this user ID. Cannot be used in the same segment as related_to_post.

Example:

$query = new WP_Query( array(
    'post_type' => 'post',
    'relationship_query' => array(
        'relation' => 'AND', // AND is default
        array(
            'related_to_post' => 25,
            'name' => 'related',
        ),
        array(
            'related_to_user' => 5,
            'name' => 'researcher',
        )
    ),
) );

Currently, querying for multiple post types in WP_Query may not work as expected. When using relationship queries, make sure to only have one post_type value in WP_Query.

Order By

For relationships where sorting is disabled, all of the default WP_Query orderby options are supported. In addition to default orderby options, if sorting is enabled for a relationship, an additional orderby parameter relationship is supported. When using relationship as the orderby value, the order is always ASC and you must adhere to the following WP_Query and WP_User_Query restrictions:

  • Compound relationship queries are not allowed - only one segment may be added to the query

For example, this is fine:

'relationship_query' => array(
    array(
        'related_to_post' => 25,
        'name' => 'related',
    ),
),
'orderby' => 'relationship',

while this will not work (orderby will be ignored):

'relationship_query' => array(
    array(
        'related_to_post' => 25,
        'name' => 'related',
    ),
    array(
		'related_to_post' => 15,
		'name' => 'related',
	),
),
'orderby' => 'relationship',

Manually Managing Relationships

If you choose to not use the built in UIs for relationships, you'll need to manually update relationships. DO NOT try and work directly with the database tables. Instead, work with the following API methods. The underlying implementations may need to change from time to time, but the following methods should continue to function if the underlying implementations need to change.

These methods are available on the relationship objects returned when defining the relationship. Make sure to call these methods on the specific relationship object you are defining a relationship for, as these methods are specific to the relationship context (they are aware of the name of the relationship, as well as the post types in the relationship).

If you don't already have a relationship object, you can get one from the registry using either Registry->get_post_to_post_relationship() or Registry->get_post_to_user_relationship().

Registry->get_post_to_post_relationship( $cpt1, $cpt2, $name )

Returns the relationship object between the two post types with the provided name.

Parameters:

$cpt1 (String) The first post type in the relationship

$cpt2 (String) The second post type in the relationship

$name (String) The name of the relationship, as passed to define_post_to_post_relationship

Example:

$registry = \TenUp\ContentConnect\Plugin::instance()->get_registry();

// Gets the car to tire relationship defined in the example above
$relationship = $registry->get_post_to_post_relationship( 'car', 'tire', 'car-tires' );

Registry->get_post_to_user_relationship( $post_type, $name )

Returns the relationship object between the post types and users with the provided name.

Parameters:

$post_type (String) The post type in the post to user relationship

$name (String) The name of the relationship, as passed to define_post_to_user_relationship

Example:

$registry = \TenUp\ContentConnect\Plugin::instance()->get_registry();

// Gets the post to user relationship defined in the example above
$relationship = $registry->get_post_to_user_relationship( 'post', 'related' );

PostToPost->add_relationship( $pid1, $pid2 )

This method adds a relationship between one post and another, in a post to post relationship. When calling this method, the order of IDs passed is not important.

Parameters:

$pid1 (Int) The ID of the first post in the relationship

$pid2 (Int) The ID of the second post in the relationship

Example:

// $relationship is the return value from ->define_post_to_post()
$relationship->add_relationship( 1, 2 ); // Adds a relationship between post ID 1 and post ID 2

PostToPost->delete_relationship( $pid1, $pid2 )

This methods deletes a relationship between one post and another, in a post to post relationship. When calling this method, the order of IDs passed is not important.

Parameters:

$pid1 (Int) The ID of the first post in the relationship. Does not need to be in the same order as the relationship was added.

$pid2 (Int) The ID of the second post in the relationship. Does not need to be in the same order as the relationship was added.

Example:

// $relationship is the return value from ->define_post_to_post()
// Note that the example above added these in the reverse order, but the relationship is still deleted
$relationship->delete_relationship( 2, 1 ); // Deletes the relationship between post ID 1 and post ID 2. 

PostToPost->replace_relationships( $post_id, $related_ids )

Replaces existing relationships for the post to post relationship. Any relationship that is present in the database but not in $related_ids will no longer be related.

Parameters:

$post_id (Int) The ID of the post we are replacing relationships from.

$related_ids (Array) An array of Post IDs of items related to $post_id

Example:

Post ID 5 is related to posts 2, 3, 6, 7, 8

// $relationship is the return value from ->define_post_to_post()
$relationship->replace_relationships( 5, array( 2, 3, 6, 7, 8 ) );

PostToPost->save_sort_data( $object_id, $ordered_ids )

For a relationship with sorting enabled, this saves the order of the posts for a single direction of the relationship.

Parameters:

$object_id (Int) The Post ID that we are ordering from. If we were ordering 5 tires for a single car, this would be the car ID.

$ordered_ids (Array) An array of Post IDs, in the order they should be sorted. If we were ordering 5 tires for a single car, this is the ordered tire IDs.

Example:

Car ID 5 has five related tires, that should be ordered 7, 6, 3, 8, 2

// $relationship is the return value from ->define_post_to_post()
$relationship->save_sort_data( 5, array( 7, 6, 3, 8, 2 ) );

PostToUser->add_relationship( $post_id, $user_id )

This method adds a relationship between a post and a user, in a post to user relationship.

Parameters:

$post_id (Int) The ID of the post in the relationship

$user_id (Int) The ID of the user in the relationship

Example:

// $relationship is the return value from ->define_post_to_user()
$relationship->add_relationship( 1, 5 ); // Adds a relationship between post 1 and user 5

PostToUser->delete_relationship( $post_id, $user_id )

This method deletes a relationship between a post and a user, in a post to user relationship.

Parameters:

$post_id (Int) The ID of the post in the relationship

$user_id (Int) The ID of the user in the relationship

Example:

// $relationship is the return value from ->define_post_to_user()
$relationship->delete_relationship( 1, 5 ); // Deletes the relationship between post 1 and user 5

PostToUser->replace_post_to_user_relationships( $post_id, $user_ids )

Replaces users related to a post with the provided set of user ids. Any users related to the post that are not provided in $user_ids will no longer be related.

Parameters:

$post_id (Int) The ID of the post we are replacing relationships from.

$user_ids (Array) An array of User IDs related to $post_id

Example:

Post ID 5 is related to users 3, 4, 5

// $relationship is the return value from ->define_post_to_user()
$relationship->replace_post_to_user_relationships( 5, array( 3, 4, 5 ) );

PostToUser->replace_user_to_post_relationships( $user_id, $post_ids )

Replaces posts related to a user with the provided set of post ids. Any posts related to the user that are not provided in $post_ids will no longer be related.

Parameters:

$user_id (Int) The User ID we are replacing relationships from.

$post_ids (Array) An array of Post IDs related to $user_id

Example:

User 2 is related to posts 6, 7, 8

// $relationship is the return value from ->define_post_to_user()
$relationship->replace_user_to_post_relationships( 2, array( 6, 7, 8 ) );

PostToUser->save_post_to_user_sort_data( $object_id, $ordered_user_ids )

For a relationship with sorting enabled, this saves the order of users for a particular post

Parameters:

$object_id (Int) The ID of the post to store the order of users for

$ordered_user_ids (Array) Array of User IDs, in the order they should be sorted.

Example:

Post ID has 5 users that need to be stored in the following order: 2, 4, 1, 6, 3

// $relationship is the return value from ->define_post_to_user()
$relationship->save_post_to_user_sort_data( 5, array( 2, 4, 1, 6, 3 ) );

PostToUser->save_user_to_post_sort_data( $user_id, $ordered_post_ids )

For a relationship with sorting enabled, this saves the order of posts for a particular user

Parameters:

$user_id (Int) The ID of the user to store the order of posts for

$ordered_post_ids (Array) Array of Post IDs, in the order they should be sorted

Example:

User ID 1 has 5 posts that need to be stored in the following order: 4, 2, 7, 9, 8

// $relationship is the return value from ->define_post_to_user()
$relationship->save_user_to_post_sort_data( 1, array( 4, 2, 7, 9, 8 ) );

Support Level

Stable: 10up is not planning to develop any new features for this, but will still respond to bug reports and security concerns. We welcome PRs, but any that include new features should be small and easy to integrate and should not include breaking changes. We otherwise intend to keep this tested up to the most recent version of WordPress.

Like what you see?

wp-content-connect's People

Contributors

alexisbellido avatar cmmarslender avatar dependabot[bot] avatar dinhtungdu avatar jeffpaul avatar mmcachran avatar moraleida avatar mphillips avatar pcrumm avatar petenelson avatar s3rgiosan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-content-connect's Issues

Item deletion does not remove the "added" label

Describe the bug

We found a bug while using this plugin where deleting an item from a search does not revert the "added" label correctly. You can see the bug in action in this loom video

Steps to Reproduce

  1. Go to a post
  2. Search for a related post
  3. Add 2nd post from the result. The "add" button in this search result should change to the "added" label.
  4. Remove the post you just added by clicking on the "delete" button.
  5. You will see that the "added" label does not change to the "add" button,

Screenshots, screen recording, code snippet

https://www.loom.com/share/d7de2a0e38204d4baf83f32173c3a57e

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

PHP Notice on new post

NOTICE: wp-content/plugins/wp-content-connect/includes/QueryIntegration/WPQueryIntegration.php:58 - Undefined index: orderby
include('wp-admin/edit-form-advanced.php'), do_action('add_meta_boxes'), WP_Hook->do_action, WP_Hook->apply_filters, TenUp\ContentConnect\UI\MetaBox->add_meta_boxes, apply_filters('tenup_content_connect_post_relationship_data'), WP_Hook->apply_filters, TenUp\ContentConnect\UI\PostToPost->filter_data, WP_Query->__construct, WP_Query->query, WP_Query->get_posts, apply_filters_ref_array, WP_Hook->apply_filters, TenUp\ContentConnect\QueryIntegration\WPQueryIntegration->posts_orderby

Is it possible to make it work with get_posts()

Is your enhancement related to a problem? Please describe.

First of all, thanks for sharing this.

The 'relationship_query' argument on queries currently only work for WP_Query and not for get_posts().

Is there an underlying reason for this?

While we can easily use WP_Query on our own developments, I'm now in a situation where I need to hook into other plugin queries, and manipulate them to return only related posts, and it doesn't work because at the end they+re using get_posts() an not WP_Query.

For example, I'm trying to manipulate the options on a WPForms field, by using their wpforms_dynamic_choice_post_type_args filter without success because they're using get_posts().

Designs

No response

Describe alternatives you've considered

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

"Notice: Function post_type was called incorrectly" on new WooCommerce orders edit screen

Describe the bug

If WooCommerce is active and using the new High Performance order Tables, this plugin throws several notices on the order edit screen (wp-admin/admin.php?page=wc-orders&action=edit&id=12345)

Notice: Function post_type was called incorrectly. Order properties should not be accessed directly. Backtrace: do_action('load-woocommerce_page_wc-orders'), WP_Hook->do_action, WP_Hook->apply_filters, Automattic\WooCommerce\Internal\Admin\Orders\PageController->__call, call_user_func_array, Automattic\WooCommerce\Internal\Admin\Orders\PageController->handle_load_page_action, Automattic\WooCommerce\Internal\Admin\Orders\PageController->setup_action_edit_order, Automattic\WooCommerce\Internal\Admin\Orders\PageController->prepare_order_edit_form, Automattic\WooCommerce\Internal\Admin\Orders\Edit->setup, do_action('add_meta_boxes'), WP_Hook->do_action, WP_Hook->apply_filters, TenUp\ContentConnect\UI\MetaBox->add_meta_boxes, apply_filters('tenup_content_connect_post_relationship_data'), WP_Hook->apply_filters, TenUp\ContentConnect\UI\PostToPost->filter_data, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong Please see Debugging in WordPress for more information. (This message was added in version 3.0.) in /Users/marcoalmeida/Documents/Websites/_local/wordpress-testing/app/public/wp-includes/functions.php on line 6078

Steps to Reproduce

  1. Activate this plugin
  2. Activate WooCommerce
  3. Activate HPOS on WooCommerce
  4. Got to a order edit screen and see the notices

Screenshots, screen recording, code snippet

image

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Add a button to create a new related post under the meta box

Is your enhancement related to a problem? Please describe.

It would be a UX improvement to have the option to create a new related post from within the post meta box of another post. The use case is if you need to relate a post to another post that does not yet exist. We could create a button, that when clicked, hits a custom endpoint that will create a new post (of the appropriate CPT based on the relationship settings) and automatically create the relationship. The endpoint will then return the ID of the new post, and open the editor for that new post in a new tab. It will also need to update the "Related Posts" listing in the post where it was originally created.

Designs

The design for the button would be similar to the "+ Add New Category" button for taxonomies, except it would open the cpt in a new window since a CPT would have a lot more details to fill in.

what-is-a-taxonomy-1

Describe alternatives you've considered

We could just add a filter at the bottom of the render function ( https://github.com/10up/wp-content-connect/blob/master/includes/UI/MetaBox.php#L40 ) and allow developers to add whatever they would like under the meta box, but it would be difficult to trigger a refresh of the related post list.

Code of Conduct

  • I agree to follow this project's Code of Conduct

WP 5.0+ Gutenberg integration

Is your enhancement related to a problem? Please describe.

In WordPress 5.0+, the Vue-based metabox created by the library doesn't look great:

Screen Shot 2019-10-14 at 10 44 21 AM

Even when forced into the sidebar, it sticks out visually because it doesn't use core blocks:

Screen Shot 2019-10-14 at 10 55 07 AM

Describe the solution you'd like

New JS for Gutenberg using React and core packages, creating either a metabox or a plugin sidebar.

Additional context

Using this library in a client project that needs post-to-post relationships.

How to limit number of connected posts?

Is it possible to limit the number of posts related on one side of the relationship? If the limit is set to one this would be a one-to-many relationship.

For example, if I have a content type, let's call it parent, connected to another, let's call it child and a definition like the following:

$args = array(
  'from' => array(
    'enable_ui' => true,
    'sortable' => false,
    'labels' => array(
      'name' => 'Parents',
    ),
  ),
  'to' => array(
    'enable_ui' => true,
    'sortable' => false,
    'labels' => array(
      'name' => 'Children',
    ),
  ),
);
$relationship = $registry->define_post_to_post( 'parent', 'child', 'parent-child', $args );

How do I make sure that when I edit a parent post I can add many children but if edit a child I only can add it to one parent?

WP CLI Integration

An integration for WP-CLI for the core methods (add, delete, sort) on all of the relationship types (PostToPost, PostToUser)

Allow UI rendering outside of the standard meta box

On a client project, we want to add the content connect UI to a custom WooCommerce product tab. Changing render() and other methods within the MetaBox class to be static methods would allow other code to easily render the UI in different parts of the WP admin instead of just the built-in meta boxes.

Table Indexes

Need to go through the queries that will be run on the custom tables and ensure that indexes are in place

Cursor pointer missing

The links with the names of the relationships on the edit post form are missing the cursor on hover.

This can be fixed by adding a cursor: pointer property to the .vtab-menu > a rule in wp-content-connect/assets/js/src/App.vue.

Search for define_post_to_user won't search first and last name

Search for define_post_to_user won't search for first and last name.

For example, if a user name is joesmith and the first and last name are John and Smith. I can only find him if I type the exact user name. If I search for John or Smith there won't be any results.

Also, partial words won't work for these or the user name either. See #16 for a similar issue for posts.

Additional filters on REST endpoint

We have a use case where we:

  • We're editing a child post
  • We need to add a relationship limited to only other child posts for the current post's parent post

The proposal would be:

  • Send the current post ID/user ID and the relationship name in the REST request to provider better context to the REST endpoint
  • Add filters to the search_users() and search_posts() functions that pass the query args as well as the ID and relationship name to allow the query args to be adjusted as-needed

I can work on a PR for this if it seems reasonable.

Composer doesn't pull into the correct place.

When trying to pull this into a project, the plugin is always installed in a 10up directory inside the plugins folder. Which doesn't work with the installer-path setup for other wordpress-plugins.

"installer-paths": {
      "plugins/{$name}/": ["type:wordpress-plugin" ]
}

New connections automatically including all possible posts in the meta field.

After creating this connection:

$args = array(
		'from' => array(
			'enable_ui' => true,
			'sortable' => true,
			'labels' => array(
				'name' => 'Related Hotels',
			),
		),
		'to' => array(
			'enable_ui' => true,
			'sortable' => true,
			'labels' => array(
				'name' => 'Related Stories',
			),
		),
	);
	$relationship = $registry->define_post_to_post( 'post', 'hotel', 'hotel-post', $args );

When I go to the Hotel's page, its appears that all posts has already been assigned to the hotel. wp_post_to_postis empty, and if I hit "Update", it then saves the connection.

It appears to me that in generate_join_clause(), the left join is being dropped resulting in a query for all posts. The root cause appears to be that the post_type in posts_where() is an array which breaks get_relationship_key().

Not that in my example Hotel pages display all posts, but Post pages do not display all Hotels.

Typos in PostToUser methods

There are some inconsistencies in the documentation for PostToUser methods. For instance, in PostToUser->delete_relationship, the comment in the example says:

// $relationship is the return value from ->define_post_to_post()

and it should say:

// $relationship is the return value from ->define_post_to_user()

I've seen this in at least three methods.

UI search doesn't work for content type registered with public set to false

I think I've found an issue with the query in search_posts (https://github.com/10up/wp-content-connect/blob/master/includes/API/Search.php#L104).

If I create a post to post relationship from my-post-type to a msr-guest-profile, defined as shown below (note that public is set to false), and then I go to edit a my-post-type post and try searching a post of type msr-guest-profile nothing is returned.

I already tried changing public to true and even added exclude_from_search false in the definition of msr-guest-profile but wp-content-connect's search still doesn't return any result.

If I run the same WP_Query from any other part of the website I do see posts of type msr-guest-profile returned.

Furthermore, I can still use the add_relationship method of my-post-type to msr-guest-profile relationship and it works just fine.

function register() {

	$labels = array(
		'name'               => esc_html__( 'Guest profiles', 'example' ),
		'singular_name'      => esc_html__( 'Guest Profile', 'example' ),
		'add_new'            => esc_html__( 'Add New Guest Profile', 'example' ),
		'add_new_item'       => esc_html__( 'Add New Guest Profile', 'example' ),
		'new_item'           => esc_html__( 'New Guest Profile', 'example' ),
		'edit_item'          => esc_html__( 'Edit Guest Profile', 'example' ),
		'view_item'          => esc_html__( 'View Guest Profile', 'example' ),
		'all_items'          => esc_html__( 'Guest Profile', 'example' ),
		'search_items'       => esc_html__( 'Search Guest Profiles', 'example' ),
		'not_found'          => esc_html__( 'No Guest Profiles found', 'example' ),
		'not_found_in_trash' => esc_html__( 'No Guest Profiles found in Trash', 'example' ),
	);

	$args = array(
		'public'             => false,
		'publicly_queryable' => true,
		'show_in_rest'       => true,
		'show_ui'            => true,
		'show_in_nav_menus'  => false,
		'show_in_menu'       => 'users.php',
		'query_var'          => true,
		'label'              => esc_html__( 'Guest profiles', 'example' ),
		'labels'             => $labels,
		'has_archive'        => false,
		'supports'           => array( 'thumbnail' ),
		'rewrite'            => false,
		'capability_type'    => array( 'msr-guest-profile', 'msr-guest-profiles' ),
		'map_meta_cap'       => true,
	);

	if( ! current_user_can( 'edit_pages' ) ){
		unset( $args['show_in_menu'] );
	}

	register_post_type( 'msr-guest-profile', $args );
}

Warning: Array to string conversion in .../content-connect/includes/Registry.php on line 34

This setup gives me a PHP warning, not sure what's going on there.

add_action( 'tenup-content-connect-init', 'prefix_content_connections' );

function prefix_content_connections( $registry ) {

	$args = [
		'from' => [
			'enable_ui' => true,
			'sortable'  => true,
			'labels'    => [
				'name' => 'Related Foos',
			],
		],
		'to' => [
			'enable_ui' => true,
			'sortable'  => true,
			'labels'    => [
				'name' => 'Related Bars',
			],
		],
	];

	$relationship = $registry->define_post_to_post(
		'bar',
		'foo',
		'bar-foo',
		$args
	);
}

Test against WP 5.3

Is your enhancement related to a problem? Please describe.
Now that WordPress 5.3 is released, we'll want to test WP Content Connect to see if any incompatibility issues arise.

Describe the solution you'd like

  • test WP Content Connect on WP 5.3
  • open issues for any incompatibilities noted in testing
  • resolve issues identified in testing
  • bump "tested up to" version
  • if code changes needed due to incompatibilities, ship a plugin release

Designs
n/a

Describe alternatives you've considered
none

Additional context
none

readme updates

It's not obvious the level of support provided for this repo, so let's add some clarification.

  • add support level section and badge
  • add release version badge
  • add license badge

Support for Relationship Meta

It would be awesome to have support for relationship meta.

There’s often situations where data isn’t a property of one entity or the other, but exists only in the context of their relationship with each other, and it doesn’t make sense to store said data in the meta of one or the other object, but ideally somewhere between, such as relationship meta.

For example, let’s say we were making an activity stream, and we wanted “activity items” to show as “unread” or “read” (similar to email). Since activity items and users would be a many-to-many relationship, we wouldn’t want an activity to be marked “read” when any user read it, we’d only want it to be marked “read” for you, if you read it.

Currently, the options are to store an array of user IDs in the activity item meta, and use that to determine if the current user has or has not “read” the item, or you could store an array of items in each users meta. . . Neither are good solutions. Storing user IDs on the activity is likely the better of the two, but still doesn’t scale
If you have a lot of users.

It would be awesome to have a formal way to store this contextual data, and in some cases even query by it.

I believe Posts 2 Posts has support for relationship meta. Might be worth looking at for inspiration 🤷‍♂️🤔

Anyway, I can think of heaps of examples where this would be useful.

Gotta throw out mention of GraphQL while I’m at it... 😀

In the WPGraphQL Schema, there’s a concept of “edges” which is the space between two nodes. For example, there’s an edge between a user and a post, or a Post and a Featured Image. This “edge” space is used for exposing contextual information that’s only relevant in the context of the relationship between the two connected nodes.

WPGraphQL could easily take advantage of relationship meta by exposing it on the edges.

Test against WordPress 5.9

Is your enhancement related to a problem? Please describe.
Once WordPress 5.9 is released, we'll want to test WP Content Connect to see if any incompatibility issues arise.

Describe the solution you'd like

  • test WP Content Connect on WordPress 5.9
  • open issues for any incompatibilities noted in testing
  • resolve issues identified in testing
  • bump "tested up to" version
  • if code changes needed due to incompatibilities, ship a plugin release

Designs
n/a

Describe alternatives you've considered
none

Additional context
none

UI Related Tests

Current, the UI components don't have tests. PHP tests could be added for basics like ensuring metabox is registered when there are relationships to render, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.