Advertisement
verygoodplugins

Untitled

Mar 23rd, 2018
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.55 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) {
  4.     exit; // Exit if accessed directly
  5. }
  6.  
  7. class WPF_WPEP extends WPF_Integrations_Base {
  8.  
  9.     /**
  10.      * Gets things started
  11.      *
  12.      * @access  public
  13.      * @since   1.0
  14.      * @return  void
  15.      */
  16.  
  17.     public function init() {
  18.  
  19.         $this->slug = 'wpep';
  20.  
  21.         // Apply tags on course completion
  22.         add_action( 'wpep_user_set_course_data', array( $this, 'apply_tags_wpep_complete' ), 10, 7 );
  23.  
  24.         // Restricted item button test
  25.         add_filter( 'wpep_text_view_course', array( $this, 'restricted_item_button_text' ), 10, 2 );
  26.  
  27.         // Settings
  28.         add_action( 'wpf_meta_box_content', array( $this, 'meta_box_content' ), 40, 2 );
  29.  
  30.     }
  31.  
  32.  
  33.     /**
  34.      * Applies tags when a WPEP course is completed
  35.      *
  36.      * @access public
  37.      * @return void
  38.      */
  39.  
  40.     public function apply_tags_wpep_complete( $key, $progress, $course_id, $section_id, $lesson_id, $user_id, $updated ) {
  41.  
  42.         if( $key == 'course_completed' && $progress == 1 ) {
  43.  
  44.             $wpf_settings = get_post_meta( $course_id, 'wpf-settings', true );
  45.  
  46.             if ( ! empty( $wpf_settings['apply_tags_wpep'] ) ) {
  47.                 wp_fusion()->user->apply_tags( $wpf_settings['apply_tags_wpep'], $user_id );
  48.             }
  49.  
  50.         }
  51.  
  52.     }
  53.  
  54.     /**
  55.      * Displays restricted item button text in course grid
  56.      *
  57.      * @access public
  58.      * @return void
  59.      */
  60.  
  61.     public function restricted_item_button_text( $text, $course_id ) {
  62.  
  63.         if( ! wp_fusion()->access->user_can_access( $course_id ) ) {
  64.  
  65.             $settings = get_post_meta( $course_id, 'wpf-settings', true );
  66.  
  67.             if( !empty( $settings['restricted_button_text'] ) ) {
  68.                 $text = $settings['restricted_button_text'];
  69.             }
  70.  
  71.         }
  72.  
  73.         return $text;
  74.  
  75.  
  76.     }
  77.  
  78.  
  79.     /**
  80.      * Adds WPEP fields to WPF meta box
  81.      *
  82.      * @access public
  83.      * @return void
  84.      */
  85.  
  86.     public function meta_box_content( $post, $settings ) {
  87.  
  88.         if ( $post->post_type != 'courses' ) {
  89.             return;
  90.         }
  91.  
  92.         echo '<p><label for="wpf-apply-tags-wpep"><small>Apply these tags when marked complete:</small></label>';
  93.  
  94.         wpf_render_tag_multiselect( array( 'setting' => $settings['apply_tags_wpep'], 'meta_name' => 'wpf-settings', 'field_id' => 'apply_tags_wpep' ) );
  95.  
  96.         echo '</p>';
  97.  
  98.         echo '<p><label for="wpf-restricted-course-message"><small>Button text to display when course is restricted:</small></label>';
  99.  
  100.         if( !isset( $settings['restricted_button_text'] ) ) {
  101.             $settings['restricted_button_text'] = '';
  102.         }
  103.  
  104.         echo '<input type="text" id="wpf-restricted-course-message" name="wpf-settings[restricted_button_text]" value="' . $settings['restricted_button_text']  . '">';
  105.  
  106.         echo '</p>';
  107.  
  108.     }
  109.  
  110.  
  111. }
  112.  
  113. new WPF_WPEP;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement