PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.5
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.5
8.0.5 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 All 47 releases
← All changes | includes/functions/achievement-types.php +193 -0 7.9.3 → 8.0.5 View file →
@@ -1,0 +1,193 @@
1 +<?php
2 +/**
3 + * Achievement Types Functions
4 + *
5 + * @package GamiPress\Achievement_Types_Functions
6 + * @author GamiPress <[email protected]>, Ruben Garcia <[email protected]>
7 + * @since 1.4.6
8 + */
9 +// Exit if accessed directly
10 +if( !defined( 'ABSPATH' ) ) exit;
11 +
12 +/**
13 + * Get registered achievement types
14 + *
15 + * Returns a multidimensional array of slug, single name and plural name for all achievement types.
16 + *
17 + * @since 1.0.0
18 + *
19 + * @return array An array of our registered achievement types
20 + */
21 +function gamipress_get_achievement_types() {
22 +
23 + return GamiPress()->achievement_types;
24 +
25 +}
26 +
27 +/**
28 + * Get registered achievement type slugs
29 + *
30 + * @since 1.0.0
31 + *
32 + * @return array An array of all our registered achievement type slugs (empty array if none)
33 + */
34 +function gamipress_get_achievement_types_slugs() {
35 +
36 + // Assume we have no registered achievement types
37 + $achievement_type_slugs = array();
38 +
39 + // If we do have any achievement types, loop through each and add their slug to our array
40 + foreach ( GamiPress()->achievement_types as $slug => $data ) {
41 + $achievement_type_slugs[] = $slug;
42 + }
43 +
44 + // Finally, return our data
45 + return $achievement_type_slugs;
46 +
47 +}
48 +
49 +/**
50 + * Get the desired achievement type
51 + *
52 + * @since 1.4.6
53 + *
54 + * @param string|int|WP_Post $achievement_type
55 + *
56 + * @return array|false The achievement type object if is registered, if not return false
57 + */
58 +function gamipress_get_achievement_type( $achievement_type ) {
59 +
60 + // Check if is an WP_Post
61 + if( $achievement_type instanceof WP_Post ) {
62 +
63 + if( $achievement_type->post_type === 'achievement-type' ) {
64 + // If WP_Post given is an achievement type post, try to find it by ID
65 + $achievement_type = $achievement_type->ID;
66 + } else {
67 + // Else the WP_Post given is an achievement post, so the achievement type is on post_type field
68 + $achievement_type = $achievement_type->post_type;
69 + }
70 +
71 + }
72 +
73 + if( gettype( $achievement_type ) === 'string' && isset( GamiPress()->achievement_types[$achievement_type] ) ) {
74 + return GamiPress()->achievement_types[$achievement_type];
75 + }
76 +
77 + if( is_numeric( $achievement_type ) ) {
78 + return gamipress_get_achievement_type_by_id( $achievement_type );
79 + }
80 +
81 + // Achievement type can not be found
82 + return false;
83 +
84 +}
85 +
86 +/**
87 + * Get the desired achievement type by ID
88 + *
89 + * @since 1.4.6
90 + *
91 + * @param int $achievement_type_id
92 + *
93 + * @return array|false The achievement type object if is registered, if not return false
94 + */
95 +function gamipress_get_achievement_type_by_id( $achievement_type_id ) {
96 +
97 + $achievement_type_id = absint( $achievement_type_id );
98 +
99 + // Bail if wrong ID given
100 + if( $achievement_type_id === 0 ) {
101 + return false;
102 + }
103 +
104 + // Loop all registered achievement types to find what matches the given ID
105 + foreach ( GamiPress()->achievement_types as $slug => $data ) {
106 + if( absint( $data['ID'] ) === $achievement_type_id ) {
107 + return $data;
108 + }
109 + }
110 +
111 + // Achievement type can not be found
112 + return false;
113 +
114 +}
115 +
116 +/**
117 + * Get the desired achievement type ID
118 + *
119 + * @since 1.4.6
120 + *
121 + * @param string|int|WP_Post $achievement_type
122 + *
123 + * @return array|false The achievement type ID if is registered, if not return false
124 + */
125 +function gamipress_get_achievement_type_id( $achievement_type ) {
126 +
127 + $achievement_type = gamipress_get_achievement_type( $achievement_type );
128 +
129 + if( $achievement_type ) {
130 + return $achievement_type['ID'];
131 + }
132 +
133 + return false;
134 +
135 +}
136 +
137 +/**
138 + * Get the desired achievement type singular name
139 + *
140 + * @since 1.4.6
141 + *
142 + * @param string|int|WP_Post $achievement_type
143 + * @param bool $force_return If set to true, will return "Achievement" if achievement type is not registered or singular name is empty
144 + *
145 + * @return array|false The achievement type singular name if is registered, if not return false
146 + */
147 +function gamipress_get_achievement_type_singular( $achievement_type, $force_return = false ) {
148 +
149 + $achievement_type = gamipress_get_achievement_type( $achievement_type );
150 +
151 + if( $achievement_type ) {
152 +
153 + // If force return and achievement type singular name is empty, return "Achievement" as singular name
154 + if( $force_return && empty( $achievement_type['singular_name'] ) ) {
155 + return __( 'Achievement', 'gamipress' );
156 + }
157 +
158 + // Return the achievement type singular name
159 + return $achievement_type['singular_name'];
160 + }
161 +
162 + return $force_return ? __( 'Achievement', 'gamipress' ) : false;
163 +
164 +}
165 +
166 +/**
167 + * Get the desired achievement type plural name
168 + *
169 + * @since 1.4.6
170 + *
171 + * @param string|int|WP_Post $achievement_type
172 + * @param bool $force_return If set to true, will return "Achievements" if achievement type is not registered or plural name is empty
173 + *
174 + * @return array|false The achievement type plural name if is registered, if not return false
175 + */
176 +function gamipress_get_achievement_type_plural( $achievement_type, $force_return = false ) {
177 +
178 + $achievement_type = gamipress_get_achievement_type( $achievement_type );
179 +
180 + if( $achievement_type ) {
181 +
182 + // If force return and achievement type plural name is empty, return "Achievements" as plural name
183 + if( $force_return && empty( $achievement_type['plural_name'] ) ) {
184 + return __( 'Achievements', 'gamipress' );
185 + }
186 +
187 + // Return the achievement type singular name
188 + return $achievement_type['plural_name'];
189 + }
190 +
191 + return $force_return ? __( 'Achievements', 'gamipress' ) : false;
192 +
193 +}