PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.8
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.8
8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 7.8.7 All 46 releases
gamipress / integrations / shortlinkspro / includes / requirements.php

requirements.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.8, at integrations/shortlinkspro/includes/requirements.php

96 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Requirements
4 *
5 * @package GamiPress\ShortLinksPro\Requirements
6 * @since 1.0.0
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Add the form field to the requirement object
13 *
14 * @param $requirement
15 * @param $requirement_id
16 *
17 * @return array
18 */
19 function gamipress_shortlinkspro_requirement_object( $requirement, $requirement_id ) {
20
21 if( isset( $requirement['trigger_type'] )
22 && ( $requirement['trigger_type'] === 'gamipress_shortlinkspro_click_specific_category') ) {
23 // Field form
24 $requirement['shortlinkspro_category'] = get_post_meta( $requirement_id, '_gamipress_shortlinkspro_category', true );
25 }
26
27 if( isset( $requirement['trigger_type'] )
28 && ( $requirement['trigger_type'] === 'gamipress_shortlinkspro_click_specific_tag') ) {
29 // Field form
30 $requirement['shortlinkspro_tag'] = get_post_meta( $requirement_id, '_gamipress_shortlinkspro_tag', true );
31 }
32
33 return $requirement;
34 }
35 add_filter( 'gamipress_requirement_object', 'gamipress_shortlinkspro_requirement_object', 10, 2 );
36
37 /**
38 * Form field on requirements UI
39 *
40 * @param $requirement_id
41 * @param $post_id
42 */
43 function gamipress_shortlinkspro_requirement_ui_fields( $requirement_id, $post_id ) {
44
45 // Get the categories
46 $categories = gamipress_shortlinkspro_get_link_categories();
47 $selected_category = get_post_meta( $requirement_id, '_gamipress_shortlinkspro_category', true );
48
49 // Get the tags
50 $tags = gamipress_shortlinkspro_get_link_tags();
51 $selected_tag = get_post_meta( $requirement_id, '_gamipress_shortlinkspro_tag', true ); ?>
52
53 <span class="shortlinkspro-category">
54 <select>
55 <?php foreach( $categories as $category ) : ?>
56 <option value="<?php echo $category->id; ?>" <?php selected( $selected_category, $category->id ); ?>><?php echo $category->name; ?></option>
57 <?php endforeach; ?>
58 </select>
59 </span>
60
61 <span class="shortlinkspro-tag">
62 <select>
63 <?php foreach( $tags as $tag ) : ?>
64 <option value="<?php echo $tag->id; ?>" <?php selected( $selected_tag, $tag->id ); ?>><?php echo $tag->name; ?></option>
65 <?php endforeach; ?>
66 </select>
67 </span>
68
69 <?php
70 }
71 add_action( 'gamipress_requirement_ui_html_after_achievement_post', 'gamipress_shortlinkspro_requirement_ui_fields', 10, 2 );
72
73 /**
74 * Custom handler to save the form on requirements UI
75 *
76 * @param $requirement_id
77 * @param $requirement
78 */
79 function gamipress_shortlinkspro_ajax_update_requirement( $requirement_id, $requirement ) {
80
81 if( isset( $requirement['trigger_type'] )
82 && ( $requirement['trigger_type'] === 'gamipress_shortlinkspro_click_specific_category' ) ) {
83
84 // Category
85 update_post_meta( $requirement_id, '_gamipress_shortlinkspro_category', $requirement['shortlinkspro_category'] );
86 }
87
88 if( isset( $requirement['trigger_type'] )
89 && ( $requirement['trigger_type'] === 'gamipress_shortlinkspro_click_specific_tag' ) ) {
90
91 // Tag
92 update_post_meta( $requirement_id, '_gamipress_shortlinkspro_tag', $requirement['shortlinkspro_tag'] );
93 }
94
95 }
96 add_action( 'gamipress_ajax_update_requirement', 'gamipress_shortlinkspro_ajax_update_requirement', 10, 2 );