Last active
May 24, 2018 23:06
-
-
Save rajamohammed/16fd799567b876249ef8f1e29317a3a5 to your computer and use it in GitHub Desktop.
WPLMS theme Add language in advanced search file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add language filter | |
*/ | |
// Add languages to theme options | |
add_filter('vibe_option_custom_sections','wpisle_add_language_option'); | |
function wpisle_add_language_option($sections) { | |
$sections[] = array( | |
'icon' => 'desktop', | |
'title' => __('Course Languages', 'vibe'), | |
'desc' => '<p class="description">'.__('Languages for course','vibe').'..</p>', | |
'fields' => array( | |
array( | |
'id' => 'lmslanguages', | |
'type' => 'textarea', | |
'title' => __('Languages', 'vibe'), | |
'sub_desc' => __('', 'vibe'), | |
'desc' => __('Insert all or supported languages add one per line, DO NOT ADD ANY SPECIAL CHARACTERS in Sidebar name', 'vibe'), | |
'std'=>'' | |
) | |
), | |
); | |
return $sections; | |
} | |
/** | |
* Get language options and list in the dropdown | |
*/ | |
function get_languages_options($frontend='') { | |
$languages = explode(PHP_EOL, vibe_get_option('lmslanguages') ) ; | |
$language_array = []; | |
foreach ($languages as $lang ) { | |
$language_array[] = array('value' => $lang, 'label'=> $lang ); | |
} | |
// All meta is stored with vibe_ prefix | |
$prefix = 'vibe_'; | |
$language_options = array( // Single checkbox | |
'label' => __('Course Language','vibe-customtypes'), // <label> | |
'text' => __('Course Language','vibe-customtypes'), // for front end | |
'desc' => __('Language of instruction.','vibe-customtypes'), // description | |
'id' => $prefix.'course_language', // field id and name | |
'type' => 'select', // type of field | |
'options' => $language_array, | |
'std' => '' | |
); | |
return $language_options; | |
} | |
//apply_filters('wplms_'.$metabox.'_metabox',$metabox_settings); | |
// Add Language to course metabox | |
add_filter('wplms_course_metabox','wpisle_add_language_meta'); | |
function wpisle_add_language_meta($metabox_settings) { | |
$languages = preg_split( '/\r\n|\r|\n/', vibe_get_option('lmslanguages') ) ; | |
$language_array = []; | |
foreach ($languages as $lang ) { | |
$language_array[] = array('value' => $lang, 'label'=> $lang ); | |
} | |
// All meta is stored with vibe_ prefix | |
$prefix = 'vibe_'; | |
$language_options = array( // Single checkbox | |
'label' => __('Course Language','vibe-customtypes'), // <label> | |
'text' => __('Course Language','vibe-customtypes'), // for front end | |
'desc' => __('Language of instruction.','vibe-customtypes'), // description | |
'id' => $prefix.'course_language', // field id and name | |
'type' => 'select', // type of field | |
'options' => $language_array, | |
'std' => '' | |
); | |
$metabox_settings[] = $language_options; | |
return $metabox_settings; | |
} | |
// Add language to course widget | |
add_filter('wplms_course_details_widget','wplms_custom_course_details_information',9999999); | |
function wplms_custom_course_details_information($details){ | |
; | |
$custom_info = get_post_meta(get_the_ID(),'vibe_course_language'); | |
if(isset($custom_info) && is_array($custom_info)){ | |
foreach($custom_info as $k=>$val){ | |
$details[]='<li>'.htmlspecialchars_decode($val).' <i class="fa fa-language" aria-hidden="true"></i></li>'; | |
} | |
} | |
return $details; | |
} | |
//include language in search query param | |
add_filter('query_vars','language_query_var'); | |
function language_query_var($vars){ | |
$vars[] = 'lang'; | |
return $vars; | |
} | |
// Add language filter to query | |
add_action( 'pre_get_posts', 'lang_pre_get_posts', 1 ); | |
function lang_pre_get_posts($query){ | |
$meta_query = array(); | |
if( !empty( get_query_var( 'lang' ) ) ){ | |
$meta_query[] = array( 'key' => 'vibe_course_language', | |
'value' => get_query_var( 'lang' ), | |
'compare' => '=' ); | |
} | |
if( count( $meta_query ) > 1 ){ | |
$meta_query['relation'] = 'AND'; | |
} | |
if( count( $meta_query ) > 0 ){ | |
$query->set( 'meta_query', $meta_query ); | |
} | |
} | |
// Display language selection in front end course creation under pricing | |
add_filter('wplms_course_creation_tabs','wpisle_create_course_unset_price',10); | |
function wpisle_create_course_unset_price($tabs) { | |
// Add language option | |
$languages = preg_split( '/\r\n|\r|\n/',vibe_get_option('lmslanguages'));//explode(PHP_EOL, vibe_get_option('lmslanguages') ) ; | |
$language_array = []; | |
foreach ($languages as $lang ) { | |
$language_array[] = array('value' => trim($lang) , 'label'=> trim($lang) ); | |
} | |
// All meta is stored with vibe_ prefix | |
$prefix = 'vibe_'; | |
$course_id = intval($_GET['action']); | |
//$language_selected = get_post_meta($course_id,$prefix.'course_language')[0]; | |
//var_dump($language_array); | |
$language_options = array( // Single checkbox | |
'label' => __('Course Language','vibe-customtypes'), // <label> | |
'text' => __('Course Language','vibe-customtypes'), // for front end | |
'desc' => __('Language of instruction.','vibe-customtypes'), // description | |
'id' => $prefix.'course_language', // field id and name | |
'type' => 'select', // type of field | |
'options' => $language_array, | |
'std' => '' | |
); | |
// add language as one of fields in course pricing tab | |
$tabs['course_pricing']['fields'][] = $language_options; | |
return $tabs; | |
} | |
// save language meta | |
add_action('wplms_front_end_save_course_pricing','wpisle_courses_create_as_product',100); | |
function wpisle_courses_create_as_product($course_id) { | |
$settings = json_decode( stripslashes($_POST['settings']) ); | |
//lanugage meta | |
$vibe_course_language = $settings[0]; | |
update_post_meta($course_id,$vibe_course_language->id,$vibe_course_language->value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
include this code in child theme functions.php this would create a new option in the wplms theme option to add languages, Option is created in Advanced Search widget to include language drop-down, and language is displayed in course widget