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

QTS: rationalize get post_types/taxonomies functions and calls #1121

Merged
merged 8 commits into from
Mar 18, 2022
18 changes: 15 additions & 3 deletions modules/slugs/includes/qtranslate-slug-settings-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function get_multi_txt_choices() {
* @return array
*/
function qts_options_page_fields() {
$post_types = get_post_types( array( '_builtin' => false, 'public' => true ), 'objects' );
$post_types = get_post_types( array( 'public' => true ), 'objects' );
herrvigg marked this conversation as resolved.
Show resolved Hide resolved

$options = array();
foreach ( $post_types as $post_type ) {
Expand All @@ -47,15 +47,27 @@ function qts_options_page_fields() {
$options[] = qts_options_page_build_slug_fields( $taxonomy, "taxonomies", "taxonomy_" );
}

return $options;
return array_filter($options);
herrvigg marked this conversation as resolved.
Show resolved Hide resolved
}

function qts_options_page_build_slug_fields( $object, $target_section, $id_prefix ) {
if ( ! is_array($object->rewrite) ) {
if ( $object->rewrite ){
$slug = $object->name;
}else{
return array();
herrvigg marked this conversation as resolved.
Show resolved Hide resolved
}
} else if (array_key_exists( 'slug', $object->rewrite ) ) {
$slug = ltrim( $object->rewrite['slug'], "/" );
} else {
$slug = $object->name;
}

herrvigg marked this conversation as resolved.
Show resolved Hide resolved
return array(
"section" => $target_section,
"id" => QTS_PREFIX . $id_prefix . $object->name,
"title" => qtranxf_use( qtranxf_getLanguage(), $object->label ),
"desc" => sprintf( '<code>https://example.org/<u>%s</u>/some-%s/</code>', array_key_exists( 'slug', $object->rewrite ) ? ltrim( $object->rewrite['slug'], "/" ) : $object->name, $object->name ),
"desc" => sprintf( '<code>https://example.org/<u>%s</u>/some-%s/</code>', $slug, $object->name ),
'class' => 'qts-slug', // used in qts_validate_options. TODO: cleaner way to be considered...
"type" => "multi-text",
"choices" => get_multi_txt_choices(),
Expand Down