Skip to content
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

Pods 2.8 i18n integration classes #6155

Merged
merged 47 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
9eeabe5
Add WPML and Polylang classes
JoryHogeveen Sep 30, 2021
6f200ab
add hook and unhook methods
JoryHogeveen Sep 30, 2021
fba6516
Move PodsMeta PLL code to integration class
JoryHogeveen Sep 30, 2021
5261434
Move PLL template post types to integration class
JoryHogeveen Sep 30, 2021
cf8ea6e
Move get_table_info code to integration classes
JoryHogeveen Sep 30, 2021
512fb26
Update WPML.php
JoryHogeveen Sep 30, 2021
342d1f1
Move pods_data_traverse_recurse_ignore_aliases to integration classes
JoryHogeveen Sep 30, 2021
787d398
Move support for WPML 'duplicated' translation handling to integratio…
JoryHogeveen Sep 30, 2021
73e6234
Add helper methods to sync with WPML class
JoryHogeveen Sep 30, 2021
4d418a9
Codestyle
JoryHogeveen Sep 30, 2021
c5d0328
Remove redundant code
JoryHogeveen Sep 30, 2021
3baf56a
Fix hooks
JoryHogeveen Sep 30, 2021
2d8966d
is_active methods
JoryHogeveen Sep 30, 2021
536dc16
Polylang get language data method
JoryHogeveen Sep 30, 2021
7a5761e
get current language methods
JoryHogeveen Sep 30, 2021
deb332a
Refactor class for integration classes
JoryHogeveen Sep 30, 2021
7ed8d07
Enable i18n integration classes
JoryHogeveen Sep 30, 2021
d2b2f66
Create Integration.php
JoryHogeveen Oct 1, 2021
afcefd2
Implement abstract Integration class
JoryHogeveen Oct 1, 2021
e488f60
Enhance getting language data
JoryHogeveen Oct 1, 2021
2767870
Add getter methods for languages and locales
JoryHogeveen Oct 1, 2021
ec1236c
Fix i18n integration classes call
JoryHogeveen Oct 1, 2021
f6d3fbe
Move plugin integration from i18n component to integration classes
JoryHogeveen Oct 1, 2021
e0a1541
Improve get table info
JoryHogeveen Oct 1, 2021
68afd8f
Update comments and phpdocs
JoryHogeveen Oct 1, 2021
9d9129f
Return doc
JoryHogeveen Oct 1, 2021
4036b3a
Var name enhancements
JoryHogeveen Oct 1, 2021
c70ec2b
Add comments and users to language contexts
JoryHogeveen Oct 1, 2021
b311097
Update phpdocs
JoryHogeveen Oct 1, 2021
58fa78c
Request params are leading
JoryHogeveen Oct 1, 2021
5482dbe
Remove unused var
JoryHogeveen Oct 4, 2021
d716fff
Merge branch 'release/2.8' into feature/2.8/i18n-integration
JoryHogeveen Oct 5, 2021
fdf7fc0
Add alternative object types
JoryHogeveen Oct 5, 2021
9144aed
Merge branch 'release/2.8' into feature/2.8/i18n-integration
JoryHogeveen Oct 5, 2021
1e5b55d
filter documentation
JoryHogeveen Oct 5, 2021
2daec3a
Enhance param name
JoryHogeveen Oct 5, 2021
f0d1507
Remove return
sc0ttkclark Oct 5, 2021
81f2419
Add doc for pods_data_traverse_recurse_ignore_aliases filter
JoryHogeveen Oct 5, 2021
44b1040
Inheritdoc
JoryHogeveen Oct 5, 2021
08360cf
Use ::get_languages()
JoryHogeveen Oct 5, 2021
852ec97
Refactor loading integrations
JoryHogeveen Oct 5, 2021
5f1b49a
`pods_integrations_on_plugins_loaded` filter
JoryHogeveen Oct 5, 2021
d01ac19
More descriptive phpdoc summary
sc0ttkclark Oct 5, 2021
ad81401
More descriptive phpdoc summary
sc0ttkclark Oct 5, 2021
e2be977
Merge branch 'release/2.8' into feature/2.8/i18n-integration
sc0ttkclark Oct 6, 2021
f93fade
Merge branch 'release/2.8' into feature/2.8/i18n-integration
JoryHogeveen Oct 11, 2021
73aa7cf
Merge branch 'release/2.8' into feature/2.8/i18n-integration
JoryHogeveen Oct 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions classes/Pods.php
Original file line number Diff line number Diff line change
Expand Up @@ -904,25 +904,27 @@ public function field( $name, $single = null, $raw = false ) {
}

if ( $use_meta_fallback ) {
$id = $this->id();

$metadata_type = $pod_type;

if ( in_array( $metadata_type, array( 'post_type', 'media' ), true ) ) {
$metadata_type = 'post';

// Support for WPML 'duplicated' translation handling.
if ( did_action( 'wpml_loaded' ) && apply_filters( 'wpml_is_translated_post_type', false, $this->pod_data['name'] ) ) {
$master_post_id = (int) apply_filters( 'wpml_master_post_from_duplicate', $id );

if ( $master_post_id ) {
$id = $master_post_id;
}
}
} elseif ( 'taxonomy' === $metadata_type ) {
$metadata_type = 'term';
}

/**
* Modify the object ID for getting metadata.
* Added for i18n integration classes.
*
* @since 2.8.0
*
* @param int $id The object ID.
* @param string $metadata_type The object metadata type.
* @param array $params Field params
* @param \Pods $pod Pods object.
*/
$id = apply_filters( 'pods_pods_field_get_metadata_object_id', $this->id(), $metadata_type, $params, $this );
JoryHogeveen marked this conversation as resolved.
Show resolved Hide resolved

$value = get_metadata( $metadata_type, $id, $params->name, $params->single );

$single_multi = 'single';
Expand Down Expand Up @@ -1475,19 +1477,13 @@ public function field( $name, $single = null, $raw = false ) {

$metadata_type = $object_type;

if ( 'post' === $object_type ) {
// Support for WPML 'duplicated' translation handling.
if ( did_action( 'wpml_loaded' ) && apply_filters( 'wpml_is_translated_post_type', false, $object ) ) {
$master_post_id = (int) apply_filters( 'wpml_master_post_from_duplicate', $metadata_object_id );

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

/** This filter is documented earlier in this method */
$metadata_object_id = apply_filters( 'pods_pods_field_get_metadata_object_id', $metadata_object_id, $metadata_type, $params, $this );
sc0ttkclark marked this conversation as resolved.
Show resolved Hide resolved

$meta_value = get_metadata( $metadata_type, $metadata_object_id, $field, true );

$value[] = pods_traverse( $traverse_fields, $meta_value );
Expand Down
89 changes: 1 addition & 88 deletions classes/PodsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -9485,35 +9485,7 @@ public function get_table_info( $object_type, $object, $name = null, $pod = null

$transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );

$current_language = false;
$current_language_t_id = 0;
$current_language_tt_id = 0;

// Get current language data
$lang_data = pods_i18n()->get_current_language_data();

if ( $lang_data ) {
if ( ! empty( $lang_data['language'] ) ) {
$current_language = $lang_data['language'];
}

if ( ! empty( $lang_data['t_id'] ) ) {
$current_language_t_id = $lang_data['t_id'];
}

if ( ! empty( $lang_data['tt_id'] ) ) {
$current_language_tt_id = $lang_data['tt_id'];
}

if ( ! empty( $lang_data['tl_t_id'] ) ) {
$current_language_tl_t_id = $lang_data['tl_t_id'];
}

if ( ! empty( $lang_data['tl_tt_id'] ) ) {
$current_language_tl_tt_id = $lang_data['tl_tt_id'];
}
}

$current_language = pods_i18n()->get_current_language();
if ( ! empty( $current_language ) ) {
$transient = 'pods_' . $wpdb->prefix . '_get_table_info_' . $current_language . '_' . md5( $object_type . '_object_' . $object . '_name_' . $name . '_pod_' . $pod_name . '_field_' . $field_name );
}
Expand Down Expand Up @@ -9647,35 +9619,6 @@ public function get_table_info( $object_type, $object, $name = null, $pod = null

$info['orderby'] = "`t`.`menu_order`, `t`.`{$info['field_index']}`, `t`.`post_date`";

/*
* @todo wpml-comp Check if WPML filters can be applied afterwards
*/
// WPML support
if ( did_action( 'wpml_loaded' ) && ! empty( $current_language ) && apply_filters( 'wpml_is_translated_post_type', false, $post_type ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
$info['join']['wpml_translations'] = "
LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
ON `wpml_translations`.`element_id` = `t`.`ID`
AND `wpml_translations`.`element_type` = 'post_" . pods_sanitize( $post_type ) . "'
AND `wpml_translations`.`language_code` = '" . pods_sanitize( $current_language ) . "'
";

$info['join']['wpml_languages'] = "
LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
";

$info['where']['wpml_languages'] = "`wpml_languages`.`code` IS NOT NULL";
} elseif ( ( function_exists( 'PLL' ) || is_object( $polylang ) ) && ! empty( $current_language ) && function_exists( 'pll_is_translated_post_type' ) && pll_is_translated_post_type( $post_type ) ) {
// Polylang support
$info['join']['polylang_languages'] = "
LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`
ON `polylang_languages`.`object_id` = `t`.`ID`
AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tt_id}
";

$info['where']['polylang_languages'] = "`polylang_languages`.`object_id` IS NOT NULL";
}

$info['object_fields'] = $this->get_wp_object_fields( $object_type, $info['pod'] );
} elseif (
0 === strpos( $object_type, 'taxonomy' ) || in_array( $object_type, [
Expand Down Expand Up @@ -9742,36 +9685,6 @@ public function get_table_info( $object_type, $object, $name = null, $pod = null
'tt.taxonomy' => "`tt`.`{$info['field_type']}` = '" . pods_sanitize( $taxonomy ) . "'",
];

/*
* @todo wpml-comp WPML API call for is_translated_taxononomy
* @todo wpml-comp Check if WPML filters can be applied afterwards
*/
// WPML Support
if ( is_object( $sitepress ) && ! empty( $current_language ) && $sitepress->is_translated_taxonomy( $taxonomy ) && apply_filters( 'wpml_setting', true, 'auto_adjust_ids' ) ) {
$info['join']['wpml_translations'] = "
LEFT JOIN `{$wpdb->prefix}icl_translations` AS `wpml_translations`
ON `wpml_translations`.`element_id` = `tt`.`term_taxonomy_id`
AND `wpml_translations`.`element_type` = 'tax_" . pods_sanitize( $taxonomy ) . "'
AND `wpml_translations`.`language_code` = '" . pods_sanitize( $current_language ) . "'
";

$info['join']['wpml_languages'] = "
LEFT JOIN `{$wpdb->prefix}icl_languages` AS `wpml_languages`
ON `wpml_languages`.`code` = `wpml_translations`.`language_code` AND `wpml_languages`.`active` = 1
";

$info['where']['wpml_languages'] = "`wpml_languages`.`code` IS NOT NULL";
} elseif ( ( function_exists( 'PLL' ) || is_object( $polylang ) ) && ! empty( $current_language ) && ! empty( $current_language_tl_tt_id ) && function_exists( 'pll_is_translated_taxonomy' ) && pll_is_translated_taxonomy( $taxonomy ) ) {
// Polylang support
$info['join']['polylang_languages'] = "
LEFT JOIN `{$wpdb->term_relationships}` AS `polylang_languages`
ON `polylang_languages`.`object_id` = `t`.`term_id`
AND `polylang_languages`.`term_taxonomy_id` = {$current_language_tl_tt_id}
";

$info['where']['polylang_languages'] = "`polylang_languages`.`object_id` IS NOT NULL";
}

$info['object_fields'] = $this->get_wp_object_fields( $object_type, $info['pod'] );
} elseif ( 'user' === $object_type || 'user' === pods_v( 'type', $info['pod'] ) ) {
// User.
Expand Down
17 changes: 11 additions & 6 deletions classes/PodsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3183,12 +3183,17 @@ public function traverse_recurse( $traverse_recurse ) {

$field = $traverse_recurse['fields'][ $traverse_recurse['depth'] ];

$ignore_aliases = array(
'wpml_languages',
'polylang_languages',
);

$ignore_aliases = apply_filters( 'pods_data_traverse_recurse_ignore_aliases', $ignore_aliases, $field, $traverse_recurse, $this );
/**
* Prevent aliases from being used in traversals.
*
* @since 2.3.0
*
* @param array $ignore_aliases Aliases to be ignored.
* @param array $field Field data.
* @param array $traverse_recurse Traverse params.
* @param \PodsData $pods_data PodsData instance.
*/
$ignore_aliases = apply_filters( 'pods_data_traverse_recurse_ignore_aliases', [], $field, $traverse_recurse, $this );
JoryHogeveen marked this conversation as resolved.
Show resolved Hide resolved

if ( in_array( $field, $ignore_aliases, true ) ) {
return $joins;
Expand Down
Loading