Skip to content

Commit

Permalink
add Ultimate Member integration
Browse files Browse the repository at this point in the history
  • Loading branch information
pryley committed Oct 19, 2024
1 parent 517c9b4 commit ac0596f
Show file tree
Hide file tree
Showing 14 changed files with 819 additions and 68 deletions.
99 changes: 99 additions & 0 deletions config/integrations/ultimatemember.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

return [ // order is intentional
'settings.integrations.ultimatemember.enabled' => [
'default' => 'no',
'label' => _x('Enable Integration?', 'admin-text', 'site-reviews'),
'sanitizer' => 'text',
'tooltip' => sprintf(_x('This will enable the Ultimate Member integration with Site Reviews.', 'admin-text', 'site-reviews'),
sprintf('<a data-expand="#tools-import-reviews" href="%s">%s</a>', glsr_admin_url('tools', 'general'), _x('Import Reviews', 'admin-text', 'site-reviews'))
),
'type' => 'yes_no',
],
'settings.integrations.ultimatemember.display_directory_ratings' => [
'default' => 'no',
'depends_on' => [
'settings.integrations.ultimatemember.enabled' => ['yes'],
],
'label' => _x('Display Directory Ratings?', 'admin-text', 'site-reviews'),
'sanitizer' => 'text',
'tooltip' => _x('This will display the rating of each person in the Member Directory.', 'admin-text', 'site-reviews'),
'type' => 'yes_no',
],
'settings.integrations.ultimatemember.display_empty' => [
'default' => 'no',
'depends_on' => [
'settings.integrations.ultimatemember.enabled' => ['yes'],
'settings.integrations.ultimatemember.display_directory_ratings' => ['yes'],
],
'label' => _x('Display Empty Ratings?', 'admin-text', 'site-reviews'),
'sanitizer' => 'text',
'tooltip' => _x('This will display the rating stars even if the member has no reviews.', 'admin-text', 'site-reviews'),
'type' => 'yes_no',
],
'settings.integrations.ultimatemember.sorting' => [
'class' => 'regular-text',
'default' => '',
'depends_on' => [
'settings.integrations.ultimatemember.enabled' => ['yes'],
'settings.integrations.ultimatemember.display_directory_ratings' => ['yes'],
],
'label' => _x('Member Sorting', 'admin-text', 'site-reviews'),
'options' => [
'' => _x('Average Rating', 'admin-text', 'site-reviews'),
'bayesian' => _x('Bayesian Ranking', 'admin-text', 'site-reviews'),
],
'sanitizer' => 'text',
'tooltip' => _x('This is the method used when sorting members by rating on the Members Directory page.', 'admin-text', 'site-reviews'),
'type' => 'select',
],
'settings.integrations.ultimatemember.display_reviews_tab' => [
'default' => 'no',
'depends_on' => [
'settings.integrations.ultimatemember.enabled' => ['yes'],
],
'label' => _x('Display Reviews Tab?', 'admin-text', 'site-reviews'),
'sanitizer' => 'text',
'tooltip' => _x('This will display the reviews tab in member profiles.', 'admin-text', 'site-reviews'),
'type' => 'yes_no',
],
'settings.integrations.ultimatemember.summary' => [
'class' => 'large-text',
'default' => '[site_reviews_summary assigned_users="profile_id"]',
'depends_on' => [
'settings.integrations.ultimatemember.enabled' => ['yes'],
'settings.integrations.ultimatemember.display_reviews_tab' => ['yes'],
],
'label' => _x('Summary Shortcode', 'admin-text', 'site-reviews'),
'placeholder' => '[site_reviews_summary assigned_users="profile_id"]',
'sanitizer' => 'text',
'tooltip' => _x('Enter the rating summary shortcode used on the profile page', 'admin-text', 'site-reviews'),
'type' => 'text',
],
'settings.integrations.ultimatemember.reviews' => [
'class' => 'large-text',
'default' => '[site_reviews assigned_users="profile_id" hide="assigned_links" pagination="loadmore"]',
'depends_on' => [
'settings.integrations.ultimatemember.enabled' => ['yes'],
'settings.integrations.ultimatemember.display_reviews_tab' => ['yes'],
],
'label' => _x('Reviews Shortcode', 'admin-text', 'site-reviews'),
'placeholder' => '[site_reviews assigned_users="profile_id" hide="assigned_links" pagination="loadmore"]',
'sanitizer' => 'text',
'tooltip' => _x('Enter the latest reviews shortcode used on the profile page', 'admin-text', 'site-reviews'),
'type' => 'text',
],
'settings.integrations.ultimatemember.form' => [
'class' => 'large-text',
'default' => '[site_reviews_form assigned_users="profile_id"]',
'depends_on' => [
'settings.integrations.ultimatemember.enabled' => ['yes'],
'settings.integrations.ultimatemember.display_reviews_tab' => ['yes'],
],
'label' => _x('Form Shortcode', 'admin-text', 'site-reviews'),
'placeholder' => '[site_reviews_form assigned_users="profile_id"]',
'sanitizer' => 'text',
'tooltip' => _x('Enter the form shortcode used on the profile page', 'admin-text', 'site-reviews'),
'type' => 'text',
],
];
Binary file modified languages/site-reviews-en_US.mo
Binary file not shown.
51 changes: 38 additions & 13 deletions languages/site-reviews-en_US.po
Original file line number Diff line number Diff line change
Expand Up @@ -2085,11 +2085,21 @@ msgctxt "admin-text"
msgid "Terms Accepted"
msgstr "Terms Accepted"

#: config/integrations/woocommerce.php:6
#: config/integrations/ultimatemember.php:6, config/integrations/woocommerce.php:6
msgctxt "admin-text"
msgid "Enable Integration?"
msgstr "Enable Integration?"

#: config/integrations/ultimatemember.php:8
msgctxt "admin-text"
msgid "This will enable the Ultimate Member integration with Site Reviews."
msgstr "This will enable the Ultimate Member integration with Site Reviews."

#: config/integrations/ultimatemember.php:9, config/integrations/woocommerce.php:9, views/integrations/woocommerce/tools/import-product-reviews.php:34, views/pages/tools/general/import-reviews.php:6, views/pages/tools/general/import-reviews.php:113
msgctxt "admin-text"
msgid "Import Reviews"
msgstr "Import Reviews"

#: config/integrations/woocommerce.php:8
msgctxt "admin-text"
msgid ""
Expand All @@ -2103,11 +2113,6 @@ msgstr ""
"need to first export them to a CSV file, and then import them using the %s "
"tool."

#: config/integrations/woocommerce.php:9, views/integrations/woocommerce/tools/import-product-reviews.php:34, views/pages/tools/general/import-reviews.php:6, views/pages/tools/general/import-reviews.php:113
msgctxt "admin-text"
msgid "Import Reviews"
msgstr "Import Reviews"

#: config/integrations/woocommerce.php:19
msgctxt "admin-text"
msgid "Rating Style"
Expand Down Expand Up @@ -2982,7 +2987,7 @@ msgctxt "admin-text"
msgid "Tools"
msgstr "Tools"

#: plugin/Controllers/MenuController.php:53, plugin/Controllers/MenuController.php:115, plugin/Controllers/MenuController.php:139
#: plugin/Controllers/MenuController.php:53, plugin/Controllers/MenuController.php:115, plugin/Controllers/MenuController.php:140
msgctxt "admin-text"
msgid "Addons"
msgstr "Addons"
Expand Down Expand Up @@ -3017,7 +3022,7 @@ msgctxt "admin-text"
msgid "API"
msgstr "API"

#: plugin/Controllers/MenuController.php:134, plugin/Controllers/MenuController.php:160
#: plugin/Controllers/MenuController.php:134, plugin/Controllers/MenuController.php:161
msgctxt "admin-text"
msgid "General"
msgstr "General"
Expand All @@ -3037,27 +3042,32 @@ msgctxt "admin-text"
msgid "Schema"
msgstr "Schema"

#: plugin/Controllers/MenuController.php:140
#: plugin/Controllers/MenuController.php:139
msgctxt "admin-text"
msgid "Integrations"
msgstr "Integrations"

#: plugin/Controllers/MenuController.php:141
msgctxt "admin-text"
msgid "Licenses"
msgstr "Licenses"

#: plugin/Controllers/MenuController.php:161
#: plugin/Controllers/MenuController.php:162
msgctxt "admin-text"
msgid "Scheduled Actions"
msgstr "Scheduled Actions"

#: plugin/Controllers/MenuController.php:162, views/pages/tools/sync.php:58
#: plugin/Controllers/MenuController.php:163, views/pages/tools/sync.php:58
msgctxt "admin-text"
msgid "Sync Reviews"
msgstr "Sync Reviews"

#: plugin/Controllers/MenuController.php:163
#: plugin/Controllers/MenuController.php:164
msgctxt "admin-text"
msgid "Console"
msgstr "Console"

#: plugin/Controllers/MenuController.php:164
#: plugin/Controllers/MenuController.php:165
msgctxt "admin-text"
msgid "System Info"
msgstr "System Info"
Expand Down Expand Up @@ -4643,6 +4653,21 @@ msgctxt "admin-text"
msgid "Unapproved Review (Site Reviews)"
msgstr "Unapproved Review (Site Reviews)"

#: plugin/Integrations/UltimateMember/DirectoryController.php:38, plugin/Integrations/UltimateMember/ProfileController.php:38
msgctxt "admin-text"
msgid "Site Reviews: Display User Rating"
msgstr "Site Reviews: Display User Rating"

#: plugin/Integrations/UltimateMember/DirectoryController.php:49, plugin/Integrations/UltimateMember/ProfileController.php:49
msgctxt "admin-text"
msgid "Site Reviews: Highest rated first"
msgstr "Site Reviews: Highest rated first"

#: plugin/Integrations/UltimateMember/DirectoryController.php:50, plugin/Integrations/UltimateMember/ProfileController.php:50
msgctxt "admin-text"
msgid "Site Reviews: Lowest rated first"
msgstr "Site Reviews: Lowest rated first"

#: plugin/Modules/Html/TemplateTags.php:144
msgctxt "admin-text"
msgid "View the review in WordPress &rarr;"
Expand Down
47 changes: 36 additions & 11 deletions languages/site-reviews.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1567,21 +1567,26 @@ msgstr ""
msgid "This review is based on my own experience and is my genuine opinion."
msgstr ""

#: config/integrations/woocommerce.php:6
#: config/integrations/ultimatemember.php:6, config/integrations/woocommerce.php:6
msgctxt "admin-text"
msgid "Enable Integration?"
msgstr ""

#: config/integrations/woocommerce.php:8
#: config/integrations/ultimatemember.php:8
msgctxt "admin-text"
msgid "This will completely replace the default WooCommerce review system with Site Reviews. If you have existing WooCommerce comment reviews, you may need to first export them to a CSV file, and then import them using the %s tool."
msgid "This will enable the Ultimate Member integration with Site Reviews."
msgstr ""

#: config/integrations/woocommerce.php:9, views/integrations/woocommerce/tools/import-product-reviews.php:34, views/pages/tools/general/import-reviews.php:6, views/pages/tools/general/import-reviews.php:113
#: config/integrations/ultimatemember.php:9, config/integrations/woocommerce.php:9, views/integrations/woocommerce/tools/import-product-reviews.php:34, views/pages/tools/general/import-reviews.php:6, views/pages/tools/general/import-reviews.php:113
msgctxt "admin-text"
msgid "Import Reviews"
msgstr ""

#: config/integrations/woocommerce.php:8
msgctxt "admin-text"
msgid "This will completely replace the default WooCommerce review system with Site Reviews. If you have existing WooCommerce comment reviews, you may need to first export them to a CSV file, and then import them using the %s tool."
msgstr ""

#: config/integrations/woocommerce.php:19
msgctxt "admin-text"
msgid "Rating Style"
Expand Down Expand Up @@ -2428,7 +2433,7 @@ msgctxt "admin-text"
msgid "Tools"
msgstr ""

#: plugin/Controllers/MenuController.php:53, plugin/Controllers/MenuController.php:115, plugin/Controllers/MenuController.php:139
#: plugin/Controllers/MenuController.php:53, plugin/Controllers/MenuController.php:115, plugin/Controllers/MenuController.php:140
msgctxt "admin-text"
msgid "Addons"
msgstr ""
Expand Down Expand Up @@ -2463,7 +2468,7 @@ msgctxt "admin-text"
msgid "API"
msgstr ""

#: plugin/Controllers/MenuController.php:134, plugin/Controllers/MenuController.php:160
#: plugin/Controllers/MenuController.php:134, plugin/Controllers/MenuController.php:161
msgctxt "admin-text"
msgid "General"
msgstr ""
Expand All @@ -2483,27 +2488,32 @@ msgctxt "admin-text"
msgid "Schema"
msgstr ""

#: plugin/Controllers/MenuController.php:140
#: plugin/Controllers/MenuController.php:139
msgctxt "admin-text"
msgid "Integrations"
msgstr ""

#: plugin/Controllers/MenuController.php:141
msgctxt "admin-text"
msgid "Licenses"
msgstr ""

#: plugin/Controllers/MenuController.php:161
#: plugin/Controllers/MenuController.php:162
msgctxt "admin-text"
msgid "Scheduled Actions"
msgstr ""

#: plugin/Controllers/MenuController.php:162, views/pages/tools/sync.php:58
#: plugin/Controllers/MenuController.php:163, views/pages/tools/sync.php:58
msgctxt "admin-text"
msgid "Sync Reviews"
msgstr ""

#: plugin/Controllers/MenuController.php:163
#: plugin/Controllers/MenuController.php:164
msgctxt "admin-text"
msgid "Console"
msgstr ""

#: plugin/Controllers/MenuController.php:164
#: plugin/Controllers/MenuController.php:165
msgctxt "admin-text"
msgid "System Info"
msgstr ""
Expand Down Expand Up @@ -4738,6 +4748,21 @@ msgctxt "admin-text"
msgid "Unapproved Review (Site Reviews)"
msgstr ""

#: plugin/Integrations/UltimateMember/DirectoryController.php:38, plugin/Integrations/UltimateMember/ProfileController.php:38
msgctxt "admin-text"
msgid "Site Reviews: Display User Rating"
msgstr ""

#: plugin/Integrations/UltimateMember/DirectoryController.php:49, plugin/Integrations/UltimateMember/ProfileController.php:49
msgctxt "admin-text"
msgid "Site Reviews: Highest rated first"
msgstr ""

#: plugin/Integrations/UltimateMember/DirectoryController.php:50, plugin/Integrations/UltimateMember/ProfileController.php:50
msgctxt "admin-text"
msgid "Site Reviews: Lowest rated first"
msgstr ""

#: plugin/Modules/Html/Form.php:24
msgid "Submit Form"
msgstr ""
Expand Down
46 changes: 46 additions & 0 deletions plugin/Database/CountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace GeminiLabs\SiteReviews\Database;

use GeminiLabs\SiteReviews\Database;
use GeminiLabs\SiteReviews\Helpers\Cast;
use GeminiLabs\SiteReviews\Helpers\Str;
use GeminiLabs\SiteReviews\Modules\Rating;

Expand All @@ -21,6 +22,21 @@ public function posts(int $postId): void
glsr()->action('ratings/count/post', $postId, $counts);
}

public function postsAverage(int $postId): float
{
return Cast::toFloat(get_post_meta($postId, static::META_AVERAGE, true));
}

public function postsRanking(int $postId): float
{
return Cast::toFloat(get_post_meta($postId, static::META_RANKING, true));
}

public function postsReviews(int $postId): int
{
return Cast::toInt(get_post_meta($postId, static::META_REVIEWS, true));
}

public function recalculate(): void
{
$this->recalculateFor('post');
Expand Down Expand Up @@ -53,6 +69,21 @@ public function terms(int $termId): void
glsr()->action('ratings/count/term', $termId, $counts);
}

public function termsAverage(int $termId): float
{
return Cast::toFloat(get_term_meta($termId, static::META_AVERAGE, true));
}

public function termsRanking(int $termId): float
{
return Cast::toFloat(get_term_meta($termId, static::META_RANKING, true));
}

public function termsReviews(int $termId): int
{
return Cast::toInt(get_term_meta($termId, static::META_REVIEWS, true));
}

public function users(int $userId): void
{
$counts = glsr_get_ratings(['assigned_users' => $userId]);
Expand All @@ -62,6 +93,21 @@ public function users(int $userId): void
glsr()->action('ratings/count/user', $userId, $counts);
}

public function usersAverage(int $userId): float
{
return Cast::toFloat(get_user_meta($userId, static::META_AVERAGE, true));
}

public function usersRanking(int $userId): float
{
return Cast::toFloat(get_user_meta($userId, static::META_RANKING, true));
}

public function usersReviews(int $userId): int
{
return Cast::toInt(get_user_meta($userId, static::META_REVIEWS, true));
}

protected function metaId(string $metaGroup): string
{
return "{$metaGroup}_id";
Expand Down
Loading

0 comments on commit ac0596f

Please sign in to comment.