Skip to content

Commit

Permalink
QTS/WC: add slug fields to custom post type attributes pages (#1142)
Browse files Browse the repository at this point in the history
* QTS: add hooks for slug fields in custom post type attributes page
* WC: add callbacks for slug fields in products attributes
* QTS: link woocommerce prod attribute slug field to WC module state
* Add `is_module_active` in module handler
Co-authored-by: HerrVigg <herrvigg@gmail.com>
  • Loading branch information
spleen1981 authored Apr 10, 2022
1 parent 4635075 commit 1939a9d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
13 changes: 13 additions & 0 deletions modules/qtx_modules_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ public static function get_active_modules() {
return $active_modules;
}

/**
* Check if a module is active.
*
* @param string $module_id
*
* @bool true if module active.
*/
public static function is_module_active( $module_id ) {
$options_modules = get_option( 'qtranslate_modules', array() );

return isset( $options_modules[ $module_id ] ) && $options_modules[ $module_id ] === QTX_MODULE_STATUS_ACTIVE;
}

/**
* Loads modules previously activated in the options after validation for plugin integration on admin-side.
* Note these should be loaded before "qtranslate_init_language" is triggered.
Expand Down
19 changes: 18 additions & 1 deletion modules/slugs/includes/qtranslate-slug-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
register_uninstall_hook( QTRANSLATE_FILE, 'qts_uninstall' );

/**
* Adds support for qtranslate in taxonomies.
* Add support for taxonomies and optional integration with WooCommerce.
*/
function qts_taxonomies_hooks() {
global $qtranslate_slug;
Expand All @@ -41,6 +41,10 @@ function qts_taxonomies_hooks() {
add_filter( 'manage_' . $taxonomy->name . '_custom_column', 'qts_taxonomy_custom_column', 0, 3 );
}
}

if ( QTX_Modules_Handler::is_module_active( 'woo-commerce' ) ) {
add_action( 'woocommerce_after_add_attribute_fields', 'qts_show_add_term_fields' );
}
}

/**
Expand Down Expand Up @@ -427,6 +431,16 @@ function qts_hide_term_slug_box() {
case 'term.php':
$id = 'slug';
break;
case 'edit.php':
// Handle WooCommerce edit product attributes page.
if ( isset( $_GET['page'] ) && $_GET['page'] == 'product_attributes' ) {
$id = 'attribute_name';
// TODO: actual slug column to be added (javascript seems the only way currently). For the time being, possibly overridden slugs column is hidden.
$additional_jquery =
"$('table tr th:nth-child(2)').hide()" . PHP_EOL .
"$('table tr td:nth-child(2)').hide()" . PHP_EOL;
}
break;
default:
return;
endswitch;
Expand All @@ -436,6 +450,9 @@ function qts_hide_term_slug_box() {
echo " jQuery(document).ready(function($){" . PHP_EOL;
echo " $(\"#" . $id . "\").parent().hide();" . PHP_EOL;
echo " $(\".form-field td #slug\").parent().parent().hide();" . PHP_EOL;
if ( isset( $additional_jquery ) ) {
echo $additional_jquery;
}
echo " });" . PHP_EOL;
echo "</script>" . PHP_EOL;
}
Expand Down

0 comments on commit 1939a9d

Please sign in to comment.