Adding custom field in course setting to add custom item in course menu

1. Go to WP Admin -> Plugins -> Editor -> WPLMS Customizer -> Customizer_class.php

2. Add following lines in _construct function:

add_filter('wplms_course_nav_menu',array($this,'wplms_course_custom_nav_menu_item'));
add_action('wplms_load_templates',array($this,'wplms_course_custom_section_area')); 
add_filter('wplms_course_metabox',array($this,'wplms_custom_item'));
add_filter('wplms_course_locate_template',array($this,'wplms_course_nav_custom_section'),10,2);

3. Add following functions in Class:

PHP Code:

function wplms_custom_item($references){
           $prefix = 'vibe_';
           $references[]=array( // Text Input
           'label' => __('Custom item menu','vibe-customtypes'), // <label>
           'desc'  => __('Put description','vibe-customtypes'), // description
           'id'    => $prefix.'references', // field id and name
           'type'  => 'editor' // type of field
                               );
           return $references;
           
       }
function wplms_course_nav_custom_section($template,$action){
             if($action == 'references'){
                 $template= array(get_template_directory('course/single/plugins.php'));
             }
             return $template;
       }
       function wplms_course_custom_section_area(){
           if(!isset($_GET['action']) || ($_GET['action'] != 'references') )
           return;
         
           echo '<h3 class="heading">'.__('custom  heading','vibe').'</h3>';
                $custom_info = get_post_meta(get_the_ID(),'vibe_references',false);
               if(isset($custom_info) && is_array($custom_info)){
                   foreach($custom_info as $k=>$val){
                        
                      echo __($val);
                       
                   }
               }
              
 
       }
 
       function wplms_course_custom_nav_menu_item($course_menu_custom){
         $link = bp_get_course_permalink();
         $course_menu_custom['references']=array(
                                       'id' => 'references',
                                       'label'=>__('custom item','vibe'),
                                       'action' => 'references',
                                       'link'=> $link,
                                   );
         if (is_user_logged_in()){return $course_menu_custom;
         }
         else{
           unset($course_menu_custom);
           return $course_menu_custom;
         }
        
       }

 

Was this article helpful?

Related Articles