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/filters.php +89 -61 7.9.8 → 8.0.5 View file →
@@ -258,9 +258,10 @@
258 258 *
259 259 * @return string
260 260 */
261 261 $points_awards_heading = apply_filters( 'gamipress_points_awards_heading', $points_awards_heading, $points_awards, $user_id, $template_args );
262 -
262 + $a['heading_size'] = gamipress_sanitize_title_size_option( $a['heading_size'] );
263 +
263 264 $output .= '<' . $a['heading_size'] . ' class="gamipress-points-awards-heading">' . $points_awards_heading . '</' . $a['heading_size'] . '>';
264 265
265 266 }
266 267
@@ -385,8 +386,9 @@
385 386 *
386 387 * @return string
387 388 */
388 389 $points_deducts_heading = apply_filters( 'gamipress_points_deducts_heading', $points_deducts_heading, $points_deducts, $user_id, $template_args );
390 + $a['heading_size'] = gamipress_sanitize_title_size_option( $a['heading_size'] );
389 391
390 392 $output .= '<' . $a['heading_size'] . ' class="gamipress-points-deducts-heading">' . $points_deducts_heading . '</' . $a['heading_size'] . '>';
391 393
392 394 }
@@ -537,8 +539,9 @@
537 539 *
538 540 * @return string
539 541 */
540 542 $steps_heading = apply_filters( 'gamipress_steps_heading', $steps_heading, $steps, $user_id, $template_args );
543 + $a['heading_size'] = gamipress_sanitize_title_size_option( $a['heading_size'] );
541 544
542 545 $output .= '<' . $a['heading_size'] . ' class="gamipress-achievement-steps-heading">' . $steps_heading . '</' . $a['heading_size'] . '>';
543 546
544 547 }
@@ -543,25 +546,32 @@
543 546
544 547 }
545 548
546 549 $output .= '<' . $container .' class="gamipress-achievement-steps gamipress-required-achievements">';
550 + $credential = gamipress_get_the_credential();
547 551
548 552 // Concatenate our output
549 553 foreach ( $steps as $step ) {
550 554
551 - $can_earn = true;
555 + $earned_status = 'user-has-not-earned';
552 556
553 - if( $user_id === 0 ) {
554 - $earned_status = 'user-has-not-earned';
555 - } else {
556 - // Check if user can earn this step and add the earned class
557 - $can_earn = gamipress_can_user_earn_requirement( $step->ID, $user_id );
558 - $earned_status = $can_earn ? 'user-has-not-earned' : 'user-has-earned';
559 - }
557 + if( ! $credential ) {
560 558
561 - // Force earned class if user can't earn this step but has earned it in the past
562 - if( ! $can_earn && gamipress_has_user_earned_achievement( $step->ID, $user_id ) ) {
563 - $earned_status = 'user-has-earned';
559 + $can_earn = true;
560 +
561 + if( $user_id === 0 ) {
562 + $earned_status = 'user-has-not-earned';
563 + } else {
564 + // Check if user can earn this step and add the earned class
565 + $can_earn = gamipress_can_user_earn_requirement( $step->ID, $user_id );
566 + $earned_status = $can_earn ? 'user-has-not-earned' : 'user-has-earned';
567 + }
568 +
569 + // Force earned class if user can't earn this step but has earned it in the past
570 + if( ! $can_earn && gamipress_has_user_earned_achievement( $step->ID, $user_id ) ) {
571 + $earned_status = 'user-has-earned';
572 + }
573 +
564 574 }
565 575
566 576 $title = $step->post_title;
567 577
@@ -777,8 +787,10 @@
777 787 * @return string The HTML markup for our times earned output
778 788 */
779 789 function gamipress_achievement_global_times_earned_markup( $achievement_id = 0, $template_args = array() ) {
780 790
791 + global $wpdb;
792 +
781 793 // Grab the current post ID if no achievement_id was specified
782 794 if ( ! $achievement_id ) {
783 795 global $post;
784 796 $achievement_id = $post->ID;
@@ -785,10 +797,15 @@
785 797 }
786 798
787 799 $maximum_earnings = absint( gamipress_get_post_meta( $achievement_id, '_gamipress_global_maximum_earnings' ) );
788 800
789 - $earned_times = gamipress_get_earnings_count( array( 'post_id' => $achievement_id ) );
801 + $user_earnings = GamiPress()->db->user_earnings;
790 802
803 + $earned_times = absint( $wpdb->get_var( $wpdb->prepare(
804 + "SELECT COUNT( DISTINCT ue.user_id ) FROM {$user_earnings} AS ue WHERE ue.post_id = %d",
805 + absint( $achievement_id )
806 + ) ) );
807 +
791 808 /**
792 809 * Filter to override the minimum times required to show the achievement times earned by all users text, by default 1
793 810 *
794 811 * @since 2.0.0
@@ -808,17 +825,20 @@
808 825
809 826 $post_type = gamipress_get_post_type( $achievement_id );
810 827 $achievement_type_singular = gamipress_get_achievement_type_singular( $post_type );
811 828
812 - // Setup the times earned text based on if achievements has unlimited times to be earned
829 + // Set up the times earned text based on if achievements has unlimited times to be earned
813 830 if( $maximum_earnings === 0 ) {
814 - $times_earned_pattern = __( '%d users have earned this %s', 'gamipress' );
815 -
816 - $times_earned_text = sprintf( $times_earned_pattern, $earned_times, $achievement_type_singular );
831 + $times_earned_text = sprintf( __( '%d users have earned this %s', 'gamipress' ),
832 + $earned_times,
833 + $achievement_type_singular
834 + );
817 835 } else {
818 - $times_earned_pattern = __( '%d of %d users have earned this %s', 'gamipress' );
819 -
820 - $times_earned_text = sprintf( $times_earned_pattern, $earned_times, $maximum_earnings, $achievement_type_singular );
836 + $times_earned_text = sprintf( __( '%d of %d users have earned this %s', 'gamipress' ),
837 + $earned_times,
838 + $maximum_earnings,
839 + $achievement_type_singular
840 + );
821 841 }
822 842
823 843 /**
824 844 * Filter to override the achievement times earned by all users text
@@ -1235,9 +1255,9 @@
1235 1255 }
1236 1256
1237 1257 $user_id = get_current_user_id();
1238 1258
1239 - // Guest not supported yet (basically because they has not earned this)
1259 + // Guest not allowed (basically because they have not earned this)
1240 1260 if( $user_id === 0 ) {
1241 1261 return '';
1242 1262 }
1243 1263
@@ -1256,9 +1276,9 @@
1256 1276 }
1257 1277
1258 1278 $social_networks = gamipress_get_option( 'social_networks', false );
1259 1279
1260 - // Bail if not social networks enabled
1280 + // Bail if no social networks enabled
1261 1281 if( empty( $social_networks ) ) {
1262 1282 return '';
1263 1283 }
1264 1284
@@ -1285,9 +1305,9 @@
1285 1305 'pinterest' => __( 'Pinterest', 'gamipress' ),
1286 1306 );
1287 1307
1288 1308 // Setup vars
1289 - $url = get_the_permalink( $achievement_id );
1309 + $url = gamipress_get_credential_url( $achievement_id, $user_id );
1290 1310 $title = get_the_title( $achievement_id );
1291 1311 $image = get_the_post_thumbnail_url( $achievement_id );
1292 1312
1293 1313 // Get the achievement twitter text
@@ -1429,9 +1449,9 @@
1429 1449 'pinterest' => __( 'Pinterest', 'gamipress' ),
1430 1450 );
1431 1451
1432 1452 // Setup vars
1433 - $url = get_the_permalink( $rank_id );
1453 + $url = gamipress_get_credential_url( $rank_id, $user_id );
1434 1454 $title = get_the_title( $rank_id );
1435 1455 $image = get_the_post_thumbnail_url( $rank_id );
1436 1456
1437 1457 // Get the rank twitter text
@@ -1554,13 +1574,12 @@
1554 1574 $earned_message = '';
1555 1575
1556 1576 if ( gamipress_has_user_earned_achievement( $achievement_id, $user_id ) ) {
1557 1577
1558 - $achievement_types = gamipress_get_achievement_types();
1559 - $achievement_type = $achievement_types[gamipress_get_post_type( $achievement_id )];
1578 + $earned_message .= '<div class="gamipress-achievement-earned"><p>'
1579 + . sprintf( __( 'You have earned this %s!', 'gamipress' ), gamipress_get_achievement_type_singular( gamipress_get_post_type( $achievement_id ), true ) )
1580 + . '</p></div>';
1560 1581
1561 - $earned_message .= '<div class="gamipress-achievement-earned"><p>' . sprintf( __( 'You have earned this %s!', 'gamipress' ), $achievement_type['singular_name'] ) . '</p></div>';
1562 -
1563 1582 if ( $congrats_text = gamipress_get_post_meta( $achievement_id, '_gamipress_congratulations_text' ) ) {
1564 1583 $earned_message .= '<div class="gamipress-achievement-congratulations">' . wpautop( $congrats_text ) . '</div>';
1565 1584 }
1566 1585 }
@@ -1593,19 +1612,28 @@
1593 1612
1594 1613 $user_id = absint( $user_id );
1595 1614 $achievement_id = absint( $achievement_id );
1596 1615
1597 - if( $user_id === 0 ) {
1598 - $user_id = get_current_user_id();
1599 - }
1616 + if( $user_id === 0 ) $user_id = get_current_user_id();
1617 + if( $user_id === 0 ) return false;
1600 1618
1601 - if( $user_id === 0 ) {
1602 - return false;
1619 + $cache = gamipress_get_cache( 'has_user_earned_achievement', array(), false );
1620 +
1621 + if( isset( $cache[$user_id] ) && isset( $cache[$user_id][$achievement_id] ) ) {
1622 + // If result already cached, use it
1623 + $earned = $cache[$user_id][$achievement_id];
1624 + } else {
1625 + // Not cached result
1626 + $earned = gamipress_get_earnings_count( array( 'user_id' => $user_id, 'post_id' => $achievement_id ) );
1627 + $earned = $earned > 0;
1628 +
1629 + // Update the cache
1630 + if( ! isset( $cache[$user_id] ) ) $cache[$user_id] = array();
1631 + $cache[$user_id][$achievement_id] = $earned;
1632 +
1633 + gamipress_set_cache( 'has_user_earned_achievement', $cache );
1603 1634 }
1604 1635
1605 - $earned = gamipress_get_earnings_count( array( 'user_id' => $user_id, 'post_id' => $achievement_id ) );
1606 - $earned = $earned > 0;
1607 -
1608 1636 /**
1609 1637 * Available filter to override the has user earned achievement result.
1610 1638 *
1611 1639 * @since 1.0.0
@@ -1678,9 +1706,8 @@
1678 1706 // Generate post link
1679 1707 $link = gamipress_generate_post_link_by_post_id( $next_post_id, $rel );
1680 1708 }
1681 1709
1682 -
1683 1710 return $link;
1684 1711
1685 1712 }
1686 1713
@@ -1742,21 +1769,15 @@
1742 1769 function gamipress_generate_post_link_by_post_id( $post_id, $rel ) {
1743 1770
1744 1771 $post = gamipress_get_post( $post_id );
1745 1772
1746 - if( ! $post ) {
1747 - return '';
1748 - }
1773 + if( ! $post ) return '';
1749 1774
1750 1775 // Title of the post
1751 1776 $title = get_the_title( $post->ID );
1752 1777
1753 1778 if ( empty( $post->post_title ) ) {
1754 - if( $rel === 'next' ) {
1755 - $title = __( 'Next Post' );
1756 - } else {
1757 - $title = __( 'Previous Post' );
1758 - }
1779 + $title = ( $rel === 'next' ) ? __( 'Next Post' ) : __( 'Previous Post' );
1759 1780 }
1760 1781
1761 1782 $nav = ($rel == 'next') ? '%s <span class="meta-nav">→</span>' : '<span class="meta-nav">←</span> %s';
1762 1783
@@ -1776,15 +1797,11 @@
1776 1797 * @return string The formatted title
1777 1798 */
1778 1799 function gamipress_log_title_format( $title, $id = null ) {
1779 1800
1780 - if( $id === null ) {
1781 - return $title;
1782 - }
1801 + if( $id === null ) return $title;
1783 1802
1784 - if( empty( $title ) ) {
1785 - $title = gamipress_get_parsed_log( $id );
1786 - }
1803 + if( empty( $title ) ) $title = gamipress_get_parsed_log( $id );
1787 1804
1788 1805 return $title;
1789 1806 }
1790 1807 add_filter( 'gamipress_render_log_title', 'gamipress_log_title_format', 10, 2 );
@@ -1880,8 +1897,9 @@
1880 1897 *
1881 1898 * @return string
1882 1899 */
1883 1900 $requirements_heading = apply_filters( 'gamipress_rank_requirements_heading', $requirements_heading, $requirements, $user_id, $template_args );
1901 + $a['heading_size'] = gamipress_sanitize_title_size_option( $a['heading_size'] );
1884 1902
1885 1903 $output .= '<' . $a['heading_size'] . ' class="gamipress-rank-requirements-heading">' . $requirements_heading . '</' . $a['heading_size'] . '>';
1886 1904
1887 1905 }
@@ -1886,18 +1904,22 @@
1886 1904
1887 1905 }
1888 1906
1889 1907 $output .= '<' . $container .' class="gamipress-rank-requirements gamipress-required-requirements">';
1908 + $credential = gamipress_get_the_credential();
1890 1909
1891 1910 // Concatenate our output
1892 1911 foreach ( $requirements as $requirement ) {
1912 + $earned_status = 'user-has-not-earned';
1893 1913
1894 - if( $user_id === 0 ) {
1895 - $earned_status = 'user-has-not-earned';
1896 - } else {
1897 - // Check if user can earn this requirement and add the earned class
1898 - $can_earn = gamipress_can_user_earn_requirement( $requirement->ID, $user_id );
1899 - $earned_status = $can_earn ? 'user-has-not-earned' : 'user-has-earned';
1914 + if( ! $credential ) {
1915 + if( $user_id === 0 ) {
1916 + $earned_status = 'user-has-not-earned';
1917 + } else {
1918 + // Check if user can earn this requirement and add the earned class
1919 + $can_earn = gamipress_can_user_earn_requirement( $requirement->ID, $user_id );
1920 + $earned_status = $can_earn ? 'user-has-not-earned' : 'user-has-earned';
1921 + }
1900 1922 }
1901 1923
1902 1924 $title = $requirement->post_title;
1903 1925
@@ -1984,13 +2006,12 @@
1984 2006 $earned_message = '';
1985 2007
1986 2008 if ( gamipress_has_user_earned_rank( $rank_id, $user_id ) ) {
1987 2009
1988 - $rank_types = gamipress_get_rank_types();
1989 - $rank_type = $rank_types[gamipress_get_post_type( $rank_id )];
2010 + $earned_message .= '<div class="gamipress-rank-earned"><p>'
2011 + . sprintf( __( 'You have reached this %s!', 'gamipress' ), gamipress_get_rank_type_singular( gamipress_get_post_type( $rank_id ), true ) )
2012 + . '</p></div>';
1990 2013
1991 - $earned_message .= '<div class="gamipress-rank-earned"><p>' . sprintf( __( 'You have reached this %s!', 'gamipress' ), $rank_type['singular_name']) . '</p></div>';
1992 -
1993 2014 if ( $congrats_text = gamipress_get_post_meta( $rank_id, '_gamipress_congratulations_text' ) ) {
1994 2015 $earned_message .= '<div class="gamipress-rank-congratulations">' . wpautop( $congrats_text ) . '</div>';
1995 2016 }
1996 2017 }
@@ -2287,8 +2308,15 @@
2287 2308
2288 2309 $column_output = date_i18n( get_option( 'date_format' ), strtotime( $user_earning->date ) );
2289 2310
2290 2311 break;
2312 + case 'actions':
2313 +
2314 + $render_credential = ( gamipress_is_achievement( $user_earning->post_type ) || gamipress_is_rank( $user_earning->post_type ) );
2315 +
2316 + $column_output .= $render_credential ? gamipress_get_credential_link( $user_earning ) : '';
2317 +
2318 + break;
2291 2319 }
2292 2320
2293 2321 return $column_output;
2294 2322