__( 'WP-Adv-Quiz', 'textdomain' ), 'description' => __( 'This hook award / deducts points for users completing quizzes through the WP-Adv-Quiz plugin.', 'textdomain' ), 'callback' => array( 'myCRED_Hook_WP_Adv_Quiz' ) ); return $installed; } /** * WP-Adv-Quiz Badges * Add support for creating badges for this hook. * @version 1.0 */ add_filter( 'mycred_all_references', 'register_wp_adv_quiz_mycred_badge' ); function register_wp_adv_quiz_mycred_badge( $references ) { $references['completing_quiz'] = __( 'Completing Quiz (WP Adv Quiz)', 'textdomain' ); $references['completing_quiz_full'] = __( 'Completing Quiz Full (WP Adv Quiz)', 'textdomain' ); return $references; } /** * WP-Adv-Quiz Hook Class * @version 1.0.1 */ add_action( 'mycred_pre_init', 'load_wp_adv_quiz_mycred_hook' ); function load_wp_adv_quiz_mycred_hook() { class myCRED_Hook_WP_Adv_Quiz extends myCRED_Hook { /** * Construct Hook */ function __construct( $hook_prefs, $type = 'mycred_default' ) { // We use the abstract classes constructor to construct our own // We need to provide a unique hook id and the default settings parent::__construct( array( 'id' => 'wpadvquiz', 'defaults' => array( 'completed' => array( 'creds' => 1, 'log' => '%plural% for completing quiz', 'limit' => 0 ), 'fullscrore' => array( 'creds' => 1, 'log' => '%plural% for 100% quiz completion', 'limit' => 0 ) ) ), $hook_prefs, $type ); } /** * Hook into WP Adv Quiz * The run() method fires of during WordPress's init instance. * This method must be set and should be used to "hook" into the third-party * plugin that we want to support. * @since 1.0 * @version 1.0 */ function run() { // Zero points means this feature is "off". if ( $this->prefs['completed']['creds'] != 0 ) add_action( 'wp_adv_quiz_completed_quiz', array( $this, 'completed_quiz' ) ); // Zero points means this feature is "off". if ( $this->prefs['fullscrore']['creds'] != 0 ) add_action( 'wp_adv_quiz_completed_quiz_100_percent', array( $this, 'completed_quiz_full' ) ); } /** * Complete Quiz * This instance is provided by WP Adv Quiz and fires of when a * quiz was successfully completed. * @since 1.0 * @version 1.2 */ function completed_quiz() { // Must be logged in if ( ! is_user_logged_in() ) return; // We need a user ID and a Quiz ID $user_id = get_current_user_id(); $quiz_id = absint( $_REQUEST['quizId'] ); // Check for exclusions if ( $this->core->exclude_user( $user_id ) ) return; // Award if not over limit if ( ! $this->over_hook_limit( 'completed', 'completing_quiz', $user_id ) ) $this->core->add_creds( 'completing_quiz', $user_id, $this->prefs['completed']['creds'], $this->prefs['completed']['log'], $quiz_id, array( 'ref_type' => 'post' ), $this->mycred_type ); } /** * Complete Quiz Full * This instance is provided by WP Adv Quiz and fires of when a * quiz was successfully completed with full marks. * @since 1.0 * @version 1.2 */ function completed_quiz_full() { // Must be logged in if ( ! is_user_logged_in() ) return; // We need a user ID and a Quiz ID $user_id = get_current_user_id(); $quiz_id = absint( $_REQUEST['quizId'] ); // Check for exclusions if ( $this->core->exclude_user( $user_id ) ) return; // Award if not over limit if ( ! $this->over_hook_limit( 'fullscrore', 'completing_quiz_full', $user_id ) ) $this->core->add_creds( 'completing_quiz_full', $user_id, $this->prefs['fullscrore']['creds'], $this->prefs['fullscrore']['log'], $quiz_id, array( 'ref_type' => 'post' ), $this->mycred_type ); } /** * Preference for this Hook * The preferences() methos is optional and only needs to be defined * if this hook needs to have settings that a user must have access to. * To ensure the settings are correctly saved, you should use the built-in * $this->field_name() and $this->field_id() methods. They will do the grunt * work for you. * @since 1.0 * @version 1.2.1 */ public function preferences() { $prefs = $this->prefs; ?>
  1.  
  2. core->available_template_tags( array( 'general', 'post' ) ); ?>
  3.  
  4. hook_limit_setting( $this->field_name( array( 'completed' => 'limit' ) ), $this->field_id( array( 'completed' => 'limit' ) ), $prefs['completed']['limit'] ); ?>
  1.  
  2. core->available_template_tags( array( 'general', 'post' ) ); ?>
  3.  
  4. hook_limit_setting( $this->field_name( array( 'fullscrore' => 'limit' ) ), $this->field_id( array( 'fullscrore' => 'limit' ) ), $prefs['fullscrore']['limit'] ); ?>