Advertisement
fauzanjeg

JKIT || Polylang Compatible for JKIT Template

Aug 1st, 2022 (edited)
1,503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. /** START || JKIT Polylang Compatible for JKIT Template */
  2. /** Add Language Condition in Dashboard Template */
  3. function jkit_custom_template_condition_fields( $fields, $value, $page ) {
  4.     $fields['language'] = array(
  5.         'type'        => 'select',
  6.         'title'       => esc_html__( 'Language', 'jeg-elementor-kit' ),
  7.         'description' => esc_html__( 'Select the language for the template.', 'jeg-elementor-kit' ),
  8.         'options'     => call_user_func(
  9.             function() {
  10.                 $languages = pll_the_languages( array( 'raw' => 1 ) );
  11.                 $options = array( '' => esc_html__( 'All Language', 'jeg-elementor-kit' ) );
  12.  
  13.                 foreach ( $languages as $locale => $language ) {
  14.                     $options[ $locale ] = $language['name'];
  15.                 }
  16.  
  17.                 return $options;
  18.             }
  19.         ),
  20.         'default'     => '',
  21.     );
  22.  
  23.     return $fields;
  24. }
  25. add_filter( 'jkit_template_condition_fields', 'jkit_custom_template_condition_fields', 10, 3 );
  26.  
  27. /** Add Language Condition for Template */
  28. function jkit_custom_check_template_contions( $flag, $post_id, $header_id, $conditions ) {
  29.     if ( $conditions ) {
  30.         foreach ( $conditions as $condition ) {
  31.             if ( ! empty( $condition['language'] ) ) {
  32.                 $flag = $flag && $condition['language'] === pll_current_language();
  33.             }
  34.         }
  35.     }
  36.  
  37.     return $flag;
  38. }
  39. add_filter( 'jkit_check_template_conditions', 'jkit_custom_check_template_contions', 10, 4 );
  40. /** END || JKIT Polylang Compatible for JKIT Template */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement