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/helpers.php +80 -10 7.9.8 → 8.0.5 View file →
@@ -211,11 +211,10 @@
211 211 * @return bool
212 212 */
213 213 function gamipress_condition_matches( $a, $b, $condition ) {
214 214
215 - if( empty( $condition ) ) {
215 + if( empty( $condition ) )
216 216 $condition = 'equal';
217 - }
218 217
219 218 $matches = false;
220 219
221 220 // Ensure that the element to compare is a string
@@ -331,11 +330,10 @@
331 330 * @return string The post thumbnail image tag.
332 331 */
333 332 function gamipress_get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) {
334 333
335 - if( ! gamipress_has_post_thumbnail( $post ) ) {
334 + if( ! gamipress_has_post_thumbnail( $post ) )
336 335 return '';
337 - }
338 336
339 337 return get_the_post_thumbnail( $post, $size, $attr );
340 338
341 339 }
@@ -352,20 +350,92 @@
352 350 */
353 351 function gamipress_has_post_thumbnail( $post ) {
354 352
355 353 $post = get_post( $post );
354 + if ( ! $post ) return false;
356 355
357 - if ( ! $post ) {
358 - return false;
359 - }
360 -
361 356 $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
362 357
363 - if( ! is_wp_error( $thumbnail_id ) ) {
358 + if( ! is_wp_error( $thumbnail_id ) )
364 359 $thumbnail_id = absint( $thumbnail_id );
365 - }
366 360
367 361 $thumbnail_id = apply_filters( 'post_thumbnail_id', $thumbnail_id, $post );
368 362
369 363 return ( is_wp_error( $thumbnail_id ) ? false : absint( $thumbnail_id ) );
364 +
365 +}
366 +
367 +/**
368 + * Get all public post types slugs
369 + *
370 + * @since 8.0.0
371 + *
372 + * @return array
373 + */
374 +function gamipress_get_post_types_slugs() {
375 + $post_types = get_post_types( array( 'public' => true ), 'objects' );
376 +
377 + return is_array( $post_types ) ? array_keys( $post_types ) : array();
378 +}
379 +
380 +/**
381 + * Validates if value is in array ensuring to return a valid entry from the array
382 + *
383 + * @since 8.0.0
384 + *
385 + * @param string $value
386 + * @param array $array
387 + * @param mixed $default
388 + *
389 + * @return mixed
390 + */
391 +function gamipress_validate_from_array( $value, $array, $default = '' ) {
392 + return is_array( $array ) && in_array( $value, $array ) ? $value : $default;
393 +}
394 +
395 +/**
396 + * Get a random array entry for associative arrays
397 + * For arrays without keys, use PHP array_rand() instead
398 + *
399 + * @since 8.0.0
400 + *
401 + * @param array $array
402 + * @param mixed $default
403 + *
404 + * @return mixed
405 + */
406 +function gamipress_assoc_array_rand( $array, $default = false ) {
407 +
408 + if( is_array( $array ) && count( $array ) ) {
409 + $keys = array_keys( $array );
410 +
411 + if( count( $keys ) === 1 ) {
412 + return $array[ $keys[0] ];
413 + } else {
414 + return $array[ $keys[ array_rand( $keys ) ] ];
415 + }
416 + }
417 +
418 + return $default;
419 +}
420 +
421 +/**
422 + * Join a string with a natural language conjunction at the end (one, two, three or four).
423 + *
424 + * @since 8.0.0
425 + *
426 + * @param array $array Array of words
427 + * @param string $join and|or
428 + *
429 + * @return string
430 + */
431 +function gamipress_join_words( $array, $join = '' ) {
432 +
433 + if( $join === '' ) $join = __( 'and', 'gamipress' );
434 +
435 + $last = array_pop($array);
436 +
437 + if ($array) return implode(', ', $array) . ' ' . $join . ' ' . $last;
438 +
439 + return $last;
370 440
371 441 }