WebDevStudios / WebDevStudios/custom-post-type-ui
Convert WPML integration to WPML String Package
Open
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 641
- Forks
- 139
- PR merge metrics
- No merged PRs in 30d
Description
https://wpml.org/documentation/support/string-package-translation/
if ( ! function_exists( 'cptui_pkg_build_package' ) ) {
function cptui_pkg_build_package( $slug ) {
return array(
'kind' => 'CPT UI Post Type',
'kind_slug' => 'cptui-post-type',
'name' => $slug,
'title' => 'Post Type: ' . $slug,
'edit_link' => admin_url( 'admin.php?page=cptui_manage_post_types&action=edit' ),
);
}
add_filter( 'wpml_active_string_package_kinds', function ( $kinds ) {
$kinds['cptui-post-type'] = 'CPT UI Post Type';
return $kinds;
} );
// Register the package + its label strings (here scoped to 'book').
add_action( 'wp_loaded', function () {
if ( ! defined( 'WPML_ST_VERSION' ) ) { return; }
$all = get_option( 'cptui_post_types', array() );
if ( empty( $all['book'] ) ) { return; }
$pt = $all['book'];
$package = cptui_pkg_build_package( 'book' );
do_action( 'wpml_start_string_package_registration', $package );
if ( ! empty( $pt['label'] ) ) {
do_action( 'wpml_register_string', $pt['label'], 'name', $package, 'Name (plural)', 'LINE' );
}
if ( ! empty( $pt['singular_label'] ) ) {
do_action( 'wpml_register_string', $pt['singular_label'], 'singular_name', $package, 'Singular name', 'LINE' );
}
if ( ! empty( $pt['labels'] ) && is_array( $pt['labels'] ) ) {
foreach ( $pt['labels'] as $key => $val ) {
if ( '' === $val ) { continue; }
do_action( 'wpml_register_string', $val, $key, $package, $key, 'LINE' );
}
}
do_action( 'wpml_delete_unused_package_strings', $package );
} );
// Apply the package translations when CPT UI registers the post type.
add_filter( 'cptui_pre_register_post_type', function ( $args, $slug, $post_type ) {
if ( 'book' !== $slug || ! defined( 'WPML_ST_VERSION' ) ) { return $args; }
$package = cptui_pkg_build_package( 'book' );
if ( ! empty( $args['labels'] ) && is_array( $args['labels'] ) ) {
foreach ( $args['labels'] as $key => $val ) {
$args['labels'][ $key ] = apply_filters( 'wpml_translate_string', $val, $key, $package );
}
}
if ( ! empty( $args['label'] ) ) {
$args['label'] = apply_filters( 'wpml_translate_string', $args['label'], 'name', $package );
}
return $args;
}, 20, 3 );
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the WPML String Package documentation linked in the issue, then trace the existing CPT UI WPML integration around cptui_pre_register_post_type and the wp_loaded registration flow. Generalize the demonstrated package registration and translation handling beyond the example book post type, and verify that custom post type labels are registered, translated, and unused package strings are removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100