Skip to content

Commit

Permalink
Merging version 4.3.0
Browse files Browse the repository at this point in the history
4.2.3
  • Loading branch information
rahularyan committed Mar 21, 2022
2 parents 243cd86 + b31ed87 commit 03300fc
Show file tree
Hide file tree
Showing 12 changed files with 694 additions and 232 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -3,8 +3,8 @@
**Donate link:** https://www.paypal.me/anspress
**Tags:** question, answer, q&a, forum, profile, stackoverflow, quora, buddypress
**Requires at least:** 4.7
**Tested up to:** 5.8
**Stable tag:** 4.2.0
**Tested up to:** 5.9
**Stable tag:** 4.2.3
**License:** GPLv2 or later
**Demo:** https://anspress.net/demo/?product=anspress
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html
Expand Down
26 changes: 26 additions & 0 deletions activate.php
Expand Up @@ -275,6 +275,31 @@ public function activity_table() {
)' . $this->charset_collate . ';';
}

/**
* AnsPress reputation events table.
*
* @since 4.3.0
*/
public function reputation_events_table() {
global $wpdb;

$this->tables[] = 'CREATE TABLE ' . $wpdb->ap_reputation_events . ' (
rep_events_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
slug varchar(100) NOT NULL,
icon varchar(100) NOT NULL,
label varchar(100) NOT NULL,
description varchar(200) NOT NULL,
activity varchar(200) NOT NULL,
parent varchar(100) NOT NULL DEFAULT "",
points int(5) NOT NULL DEFAULT 0,
PRIMARY KEY (rep_events_id),
UNIQUE (slug),
KEY slug_key (slug),
KEY points_key (points),
KEY parent_key (parent)
)' . $this->charset_collate . ';';
}

/**
* Insert and update tables
*/
Expand All @@ -288,6 +313,7 @@ public function insert_tables() {
$this->reputation_table();
$this->subscribers_table();
$this->activity_table();
$this->reputation_events_table();

require_once ABSPATH . 'wp-admin/includes/upgrade.php';

Expand Down
226 changes: 120 additions & 106 deletions addons/reputation/reputation.php
Expand Up @@ -122,121 +122,135 @@ public function load_options() {
* Register default reputation events.
*/
public function register_default_events() {
ap_register_reputation_event(
'register',
array(
'points' => 10,
'label' => __( 'Registration', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user account is created', 'anspress-question-answer' ),
'icon' => 'apicon-question',
'activity' => __( 'Registered', 'anspress-question-answer' ),
'parent' => 'question',
)
);
$events_db = wp_cache_get( 'all', 'ap_get_all_reputation_events' );

ap_register_reputation_event(
'ask',
array(
'points' => 2,
'label' => __( 'Asking', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user asks a question', 'anspress-question-answer' ),
'icon' => 'apicon-question',
'activity' => __( 'Asked a question', 'anspress-question-answer' ),
'parent' => 'question',
)
);
if ( false === $events_db ) {
$events_db = ap_get_all_reputation_events();
}

ap_register_reputation_event(
'answer',
array(
'points' => 5,
'label' => __( 'Answering', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user answers a question', 'anspress-question-answer' ),
'icon' => 'apicon-answer',
'activity' => __( 'Posted an answer', 'anspress-question-answer' ),
'parent' => 'answer',
)
);
// If already in DB return from here.
if ( ! $events_db ) {
$events = array(
array(
'slug' => 'register',
'label' => __( 'Registration', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user account is created', 'anspress-question-answer' ),
'icon' => 'apicon-question',
'activity' => __( 'Registered', 'anspress-question-answer' ),
'parent' => 'question',
'points' => 10,
),
array(
'slug' => 'ask',
'points' => 2,
'label' => __( 'Asking', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user asks a question', 'anspress-question-answer' ),
'icon' => 'apicon-question',
'activity' => __( 'Asked a question', 'anspress-question-answer' ),
'parent' => 'question',
),
array(
'slug' => 'answer',
'points' => 5,
'label' => __( 'Answering', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user answers a question', 'anspress-question-answer' ),
'icon' => 'apicon-answer',
'activity' => __( 'Posted an answer', 'anspress-question-answer' ),
'parent' => 'answer',
),
array(
'slug' => 'comment',
'points' => 2,
'label' => __( 'Commenting', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user comments on question or answer', 'anspress-question-answer' ),
'icon' => 'apicon-comments',
'activity' => __( 'Commented on a post', 'anspress-question-answer' ),
'parent' => 'comment',
),
array(
'slug' => 'select_answer',
'points' => 2,
'label' => __( 'Selecting an Answer', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user selects an answer for their question', 'anspress-question-answer' ),
'icon' => 'apicon-check',
'activity' => __( 'Selected an answer as best', 'anspress-question-answer' ),
'parent' => 'question',
),
array(
'slug' => 'best_answer',
'points' => 10,
'label' => __( 'Answer selected as best', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user\'s answer is selected as best', 'anspress-question-answer' ),
'icon' => 'apicon-check',
'activity' => __( 'Answer was selected as best', 'anspress-question-answer' ),
'parent' => 'answer',
),
array(
'slug' => 'received_vote_up',
'points' => 10,
'label' => __( 'Received up vote', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user receives an upvote', 'anspress-question-answer' ),
'icon' => 'apicon-thumb-up',
'activity' => __( 'Received an upvote', 'anspress-question-answer' ),
),
array(
'slug' => 'received_vote_down',
'points' => -2,
'label' => __( 'Received down vote', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user receives a down vote', 'anspress-question-answer' ),
'icon' => 'apicon-thumb-down',
'activity' => __( 'Received a down vote', 'anspress-question-answer' ),
),
array(
'slug' => 'given_vote_up',
'points' => 0,
'label' => __( 'Gives an up vote', 'anspress-question-answer' ),
'description' => __( 'Points taken from user when they give an up vote', 'anspress-question-answer' ),
'icon' => 'apicon-thumb-up',
'activity' => __( 'Given an up vote', 'anspress-question-answer' ),
),
array(
'slug' => 'given_vote_down',
'points' => 0,
'label' => __( 'Gives down vote', 'anspress-question-answer' ),
'description' => __( 'Points taken from user when they give a down vote', 'anspress-question-answer' ),
'icon' => 'apicon-thumb-down',
'activity' => __( 'Given a down vote', 'anspress-question-answer' ),
),
);

ap_register_reputation_event(
'comment',
array(
'points' => 2,
'label' => __( 'Commenting', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user comments on question or answer', 'anspress-question-answer' ),
'icon' => 'apicon-comments',
'activity' => __( 'Commented on a post', 'anspress-question-answer' ),
'parent' => 'comment',
)
);
$custom_points = get_option( 'anspress_reputation_events', array() );

ap_register_reputation_event(
'select_answer',
array(
'points' => 2,
'label' => __( 'Selecting an Answer', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user selects an answer for their question', 'anspress-question-answer' ),
'icon' => 'apicon-check',
'activity' => __( 'Selected an answer as best', 'anspress-question-answer' ),
'parent' => 'question',
)
);
foreach ( $events as $event ) {
$points = isset( $custom_points[ $event['slug'] ] ) ? (int) $custom_points[ $event['slug'] ] : (int) $event['points'];

ap_register_reputation_event(
'best_answer',
array(
'points' => 10,
'label' => __( 'Answer selected as best', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user\'s answer is selected as best', 'anspress-question-answer' ),
'icon' => 'apicon-check',
'activity' => __( 'Answer was selected as best', 'anspress-question-answer' ),
'parent' => 'answer',
)
);
ap_insert_reputation_event(
$event['slug'],
$event['label'],
$event['description'],
$points,
! empty( $event['activity'] ) ? $event['activity'] : '',
! empty( $event['parent'] ) ? $event['parent'] : ''
);
}

ap_register_reputation_event(
'received_vote_up',
array(
'points' => 10,
'label' => __( 'Received up vote', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user receives an upvote', 'anspress-question-answer' ),
'icon' => 'apicon-thumb-up',
'activity' => __( 'Received an upvote', 'anspress-question-answer' ),
)
);
$events_db = ap_get_all_reputation_events();

ap_register_reputation_event(
'received_vote_down',
array(
'points' => -2,
'label' => __( 'Received down vote', 'anspress-question-answer' ),
'description' => __( 'Points awarded when user receives a down vote', 'anspress-question-answer' ),
'icon' => 'apicon-thumb-down',
'activity' => __( 'Received a down vote', 'anspress-question-answer' ),
)
);
wp_cache_set( 'all', $events_db, 'ap_get_all_reputation_events' );
}

ap_register_reputation_event(
'given_vote_up',
array(
'points' => 0,
'label' => __( 'Gives an up vote', 'anspress-question-answer' ),
'description' => __( 'Points taken from user when they give an up vote', 'anspress-question-answer' ),
'icon' => 'apicon-thumb-up',
'activity' => __( 'Given an up vote', 'anspress-question-answer' ),
)
);
if ( empty( $events_db ) ) {
return;
}

ap_register_reputation_event(
'given_vote_down',
array(
'points' => 0,
'label' => __( 'Gives down vote', 'anspress-question-answer' ),
'description' => __( 'Points taken from user when they give a down vote', 'anspress-question-answer' ),
'icon' => 'apicon-thumb-down',
'activity' => __( 'Given a down vote', 'anspress-question-answer' ),
)
);
// Fallback for register events.
foreach ( $events_db as $event ) {
$args = (array) $event;

unset( $args['slug'] );

ap_register_reputation_event( $event->slug, $args );
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion admin/anspress-admin.php
Expand Up @@ -688,7 +688,7 @@ public static function anspress_notice() {
foreach ( $messages as $msg ) {
if ( $msg['show'] ) {
$class = 'ap-notice notice notice-' . $msg['type'];
wp_kses_post(
echo wp_kses_post(
sprintf(
'<div class="%1$s %4$s"><p>%2$s%3$s</p></div>',
esc_attr( $class ),
Expand Down
7 changes: 4 additions & 3 deletions anspress-question-answer.php
Expand Up @@ -15,7 +15,7 @@
* Plugin URI: https://anspress.net
* Description: The most advance community question and answer system for WordPress
* Donate link: https://paypal.me/anspress
* Version: 4.2.3
* Version: 4.3.0
* Author: Rahul Aryan
* Author URI: https://anspress.net
* License: GPL-3.0+
Expand All @@ -31,7 +31,7 @@
}

// Define database version.
define( 'AP_DB_VERSION', 35 );
define( 'AP_DB_VERSION', 37 );

// Check if using required PHP version.
if ( version_compare( PHP_VERSION, '7.2' ) < 0 ) {
Expand Down Expand Up @@ -67,7 +67,7 @@ class AnsPress {
* @access private
* @var string
*/
private $_plugin_version = '4.2.3'; // phpcs:ignore
private $_plugin_version = '4.3.0'; // phpcs:ignore

/**
* Class instance
Expand Down Expand Up @@ -315,6 +315,7 @@ private function includes() {
require_once ANSPRESS_DIR . 'widgets/questions.php';
require_once ANSPRESS_DIR . 'widgets/breadcrumbs.php';
require_once ANSPRESS_DIR . 'widgets/ask-form.php';
require_once ANSPRESS_DIR . 'widgets/leaderboard.php';

require_once ANSPRESS_DIR . 'lib/class-anspress-upgrader.php';
require_once ANSPRESS_DIR . 'lib/class-form.php';
Expand Down
14 changes: 8 additions & 6 deletions includes/functions.php
Expand Up @@ -1096,16 +1096,18 @@ function ap_whitelist_array( $master_keys, $array ) {
*
* @since unknown
* @since 4.1.2 Added `ap_activity` table.
* @since 4.3.0 Added `ap_reputation_events`.
*/
function ap_append_table_names() {
global $wpdb;

$wpdb->ap_qameta = $wpdb->prefix . 'ap_qameta';
$wpdb->ap_votes = $wpdb->prefix . 'ap_votes';
$wpdb->ap_views = $wpdb->prefix . 'ap_views';
$wpdb->ap_reputations = $wpdb->prefix . 'ap_reputations';
$wpdb->ap_subscribers = $wpdb->prefix . 'ap_subscribers';
$wpdb->ap_activity = $wpdb->prefix . 'ap_activity';
$wpdb->ap_qameta = $wpdb->prefix . 'ap_qameta';
$wpdb->ap_votes = $wpdb->prefix . 'ap_votes';
$wpdb->ap_views = $wpdb->prefix . 'ap_views';
$wpdb->ap_reputations = $wpdb->prefix . 'ap_reputations';
$wpdb->ap_subscribers = $wpdb->prefix . 'ap_subscribers';
$wpdb->ap_activity = $wpdb->prefix . 'ap_activity';
$wpdb->ap_reputation_events = $wpdb->prefix . 'ap_reputation_events';
}
ap_append_table_names();

Expand Down

0 comments on commit 03300fc

Please sign in to comment.