Skip to content

Commit

Permalink
Merge pull request #3169 from pods-framework/feature/3163-support-ter…
Browse files Browse the repository at this point in the history
…m-meta

Add support for term meta in WP 4.4
  • Loading branch information
sc0ttkclark committed Nov 23, 2015
2 parents 7fcf3e6 + f3bd4c9 commit a4c7e77
Show file tree
Hide file tree
Showing 10 changed files with 375 additions and 141 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Expand Up @@ -7,8 +7,9 @@ php:
- 5.6

env:
- WP_VERSION=nightly WP_MULTISITE=0
- WP_VERSION=nightly WP_MULTISITE=1
- WP_VERSION=bleeding WP_MULTISITE=0
- WP_VERSION=bleeding WP_MULTISITE=1
- WP_VERSION=bleeding-maintenance WP_MULTISITE=0
- WP_VERSION=4.3 WP_MULTISITE=0
- WP_VERSION=3.8 WP_MULTISITE=0
- WP_VERSION=3.8 WP_MULTISITE=1
Expand Down
61 changes: 31 additions & 30 deletions classes/Pods.php
Expand Up @@ -1033,31 +1033,26 @@ public function field ( $name, $single = null, $raw = false ) {
if ( !$no_conflict )
pods_no_conflict_on( $this->pod_data[ 'type' ] );

if ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) ) {
if ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media', 'taxonomy', 'user', 'comment' ) ) ) {
$id = $this->id();

// Support for WPML 'duplicated' translation handling
if ( is_object( $sitepress ) && $sitepress->is_translated_post_type( $this->pod_data[ 'name' ] ) ) {
$master_post_id = (int) get_post_meta( $id, '_icl_lang_duplicate_of', true );
$metadata_type = $this->pod_data['type'];

if ( 0 < $master_post_id )
$id = $master_post_id;
}

$value = get_post_meta( $id, $params->name, $params->single );
if ( in_array( $this->pod_data[ 'type' ], array( 'post_type', 'media' ) ) ) {
$metadata_type = 'post';

$single_multi = 'single';
// Support for WPML 'duplicated' translation handling
if ( is_object( $sitepress ) && $sitepress->is_translated_post_type( $this->pod_data[ 'name' ] ) ) {
$master_post_id = (int) get_metadata( $metadata_type, $id, '_icl_lang_duplicate_of', true );

if ( isset( $this->fields[ $params->name ] ) ) {
$single_multi = pods_v( $this->fields[ $params->name ][ 'type' ] . '_format_type', $this->fields[ $params->name ][ 'options' ], 'single' );
if ( 0 < $master_post_id )
$id = $master_post_id;
}
} elseif ( 'taxonomy' == $this->pod_data[ 'type' ] ) {
$metadata_type = 'term';
}

if ( $simple && !is_array( $value ) && 'single' != $single_multi ) {
$value = get_post_meta( $id, $params->name );
}
}
elseif ( in_array( $this->pod_data[ 'type' ], array( 'user', 'comment' ) ) ) {
$value = get_metadata( $this->pod_data[ 'type' ], $this->id(), $params->name, $params->single );
$value = get_metadata( $metadata_type, $id, $params->name, $params->single );

$single_multi = 'single';

Expand All @@ -1066,7 +1061,7 @@ public function field ( $name, $single = null, $raw = false ) {
}

if ( $simple && !is_array( $value ) && 'single' != $single_multi ) {
$value = get_metadata( $this->pod_data[ 'type' ], $this->id(), $params->name );
$value = get_metadata( $metadata_type, $id, $params->name );
}
}
elseif ( 'settings' == $this->pod_data[ 'type' ] )
Expand Down Expand Up @@ -1403,7 +1398,7 @@ public function field ( $name, $single = null, $raw = false ) {

$no_conflict = true;

if ( in_array( $object_type, array( 'post', 'user', 'comment', 'settings' ) ) ) {
if ( in_array( $object_type, array( 'post', 'taxonomy', 'user', 'comment', 'settings' ) ) ) {
$no_conflict = pods_no_conflict_check( $object_type );

if ( !$no_conflict )
Expand Down Expand Up @@ -1490,25 +1485,31 @@ public function field ( $name, $single = null, $raw = false ) {
else
$value[] = $item->{$field};
}
elseif ( 'post' == $object_type ) {
// Support for WPML 'duplicated' translation handling
if ( is_object( $sitepress ) && $sitepress->is_translated_post_type( $object ) ) {
$master_post_id = (int) get_post_meta( $item_id, '_icl_lang_duplicate_of', true );
elseif ( in_array( $object_type, array( 'post', 'taxonomy', 'user', 'comment' ) ) ) {
$metadata_object_id = $item_id;

if ( 0 < $master_post_id )
$item_id = $master_post_id;
$metadata_type = $object_type;

if ( 'post' == $object_type ) {
// Support for WPML 'duplicated' translation handling
if ( is_object( $sitepress ) && $sitepress->is_translated_post_type( $object ) ) {
$master_post_id = (int) get_metadata( $metadata_type, $metadata_object_id, '_icl_lang_duplicate_of', true );

if ( 0 < $master_post_id )
$metadata_object_id = $master_post_id;
}
} elseif ( 'taxonomy' == $object_type ) {
$metadata_type = 'term';
}

$value[] = get_post_meta( $item_id, $field, true );
$value[] = get_metadata( $metadata_type, $metadata_object_id, $field, true );
}
elseif ( in_array( $object_type, array( 'post', 'user', 'comment' ) ) )
$value[] = get_metadata( $object_type, $item_id, $field, true );
elseif ( 'settings' == $object_type )
$value[] = get_option( $object . '_' . $field );
}
}

if ( in_array( $object_type, array( 'post', 'user', 'comment', 'settings' ) ) && !$no_conflict )
if ( in_array( $object_type, array( 'post', 'taxonomy', 'user', 'comment', 'settings' ) ) && !$no_conflict )
pods_no_conflict_off( $object_type );

// Handle Simple Relationships
Expand Down

0 comments on commit a4c7e77

Please sign in to comment.