Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly
- }
- class WPF_WPEP extends WPF_Integrations_Base {
- /**
- * Gets things started
- *
- * @access public
- * @since 1.0
- * @return void
- */
- public function init() {
- $this->slug = 'wpep';
- // Apply tags on course completion
- add_action( 'wpep_user_set_course_data', array( $this, 'apply_tags_wpep_complete' ), 10, 7 );
- // Restricted item button test
- add_filter( 'wpep_text_view_course', array( $this, 'restricted_item_button_text' ), 10, 2 );
- // Settings
- add_action( 'wpf_meta_box_content', array( $this, 'meta_box_content' ), 40, 2 );
- }
- /**
- * Applies tags when a WPEP course is completed
- *
- * @access public
- * @return void
- */
- public function apply_tags_wpep_complete( $key, $progress, $course_id, $section_id, $lesson_id, $user_id, $updated ) {
- if( $key == 'course_completed' && $progress == 1 ) {
- $wpf_settings = get_post_meta( $course_id, 'wpf-settings', true );
- if ( ! empty( $wpf_settings['apply_tags_wpep'] ) ) {
- wp_fusion()->user->apply_tags( $wpf_settings['apply_tags_wpep'], $user_id );
- }
- }
- }
- /**
- * Displays restricted item button text in course grid
- *
- * @access public
- * @return void
- */
- public function restricted_item_button_text( $text, $course_id ) {
- if( ! wp_fusion()->access->user_can_access( $course_id ) ) {
- $settings = get_post_meta( $course_id, 'wpf-settings', true );
- if( !empty( $settings['restricted_button_text'] ) ) {
- $text = $settings['restricted_button_text'];
- }
- }
- return $text;
- }
- /**
- * Adds WPEP fields to WPF meta box
- *
- * @access public
- * @return void
- */
- public function meta_box_content( $post, $settings ) {
- if ( $post->post_type != 'courses' ) {
- return;
- }
- echo '<p><label for="wpf-apply-tags-wpep"><small>Apply these tags when marked complete:</small></label>';
- wpf_render_tag_multiselect( array( 'setting' => $settings['apply_tags_wpep'], 'meta_name' => 'wpf-settings', 'field_id' => 'apply_tags_wpep' ) );
- echo '</p>';
- echo '<p><label for="wpf-restricted-course-message"><small>Button text to display when course is restricted:</small></label>';
- if( !isset( $settings['restricted_button_text'] ) ) {
- $settings['restricted_button_text'] = '';
- }
- echo '<input type="text" id="wpf-restricted-course-message" name="wpf-settings[restricted_button_text]" value="' . $settings['restricted_button_text'] . '">';
- echo '</p>';
- }
- }
- new WPF_WPEP;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement