YITH Essential Kit for WooCommerce #1 - Version 1.0.8

Version Description

  • Updated: All YITH plugins to latest version
Download this release

Release Info

Developer yithemes
Plugin Icon 128x128 YITH Essential Kit for WooCommerce #1
Version 1.0.8
Comparing to
See all releases

Code changes from version 1.0.7 to 1.0.8

Files changed (61) hide show
  1. README.txt +6 -2
  2. init.php +1 -1
  3. languages/yith-jetpack.pot +41 -43
  4. modules/yith-woocommerce-advanced-reviews/class.yith-woocommerce-advanced-reviews.php +1639 -1637
  5. modules/yith-woocommerce-advanced-reviews/init.php +2 -2
  6. modules/yith-woocommerce-ajax-navigation/assets/css/admin.css +6 -1
  7. modules/yith-woocommerce-ajax-navigation/assets/js/yith-wcan-admin.js +2 -16
  8. modules/yith-woocommerce-ajax-navigation/includes/class.yith-wcan-admin.php +0 -28
  9. modules/yith-woocommerce-ajax-navigation/init.php +2 -2
  10. modules/yith-woocommerce-ajax-navigation/languages/yith_wc_ajxnav-it_IT.mo +0 -0
  11. modules/yith-woocommerce-ajax-navigation/languages/yith_wc_ajxnav-it_IT.po +37 -37
  12. modules/yith-woocommerce-ajax-navigation/languages/yith_wc_ajxnav-tr_TR.mo +0 -0
  13. modules/yith-woocommerce-ajax-navigation/languages/yith_wc_ajxnav-tr_TR.po +34 -29
  14. modules/yith-woocommerce-ajax-navigation/languages/yith_wc_ajxnav.pot +12 -12
  15. modules/yith-woocommerce-ajax-navigation/widgets/class.yith-wcan-navigation-widget.php +3 -3
  16. modules/yith-woocommerce-ajax-navigation/widgets/class.yith-wcan-reset-navigation-widget.php +1 -1
  17. modules/yith-woocommerce-catalog-mode/class.yith-woocommerce-catalog-mode.php +8 -1
  18. modules/yith-woocommerce-catalog-mode/init.php +4 -4
  19. modules/yith-woocommerce-catalog-mode/plugin-options/settings-options.php +1 -1
  20. modules/yith-woocommerce-colors-labels-variations/assets/js/frontend.js +2 -0
  21. modules/yith-woocommerce-colors-labels-variations/assets/js/frontend.min.js +1 -1
  22. modules/yith-woocommerce-colors-labels-variations/changelog.txt +6 -0
  23. modules/yith-woocommerce-colors-labels-variations/class.yith-wccl-frontend.php +36 -0
  24. modules/yith-woocommerce-colors-labels-variations/init.php +3 -3
  25. modules/yith-woocommerce-colors-labels-variations/templates/single-product/add-to-cart/variable-wccl.php +12 -1
  26. modules/yith-woocommerce-product-vendors/includes/class.yith-vendors-admin.php +10 -40
  27. modules/yith-woocommerce-product-vendors/init.php +2 -2
  28. modules/yith-woocommerce-quick-view/init.php +3 -3
  29. modules/yith-woocommerce-quick-view/templates/yith-quick-view-content.php +2 -2
  30. modules/yith-woocommerce-review-reminder/class.yith-woocommerce-review-reminder.php +26 -69
  31. modules/yith-woocommerce-review-reminder/includes/admin/class-yith-custom-table.php +48 -28
  32. modules/yith-woocommerce-review-reminder/init.php +86 -6
  33. modules/yith-woocommerce-review-reminder/plugin-options/mail-options.php +8 -13
  34. modules/yith-woocommerce-review-reminder/templates/admin/premium.php +52 -25
  35. modules/yith-woocommerce-zoom-magnifier/assets/css/frontend.css +6 -0
  36. modules/yith-woocommerce-zoom-magnifier/assets/images/yith-woocommerce-zoom-magnifier-video.jpg +0 -0
  37. modules/yith-woocommerce-zoom-magnifier/assets/js/frontend.js +1 -1
  38. modules/yith-woocommerce-zoom-magnifier/assets/js/yith_magnifier.js +16 -11
  39. modules/yith-woocommerce-zoom-magnifier/assets/js/yith_magnifier.min.js +1 -1
  40. modules/yith-woocommerce-zoom-magnifier/class.yith-wcmg-admin.php +163 -165
  41. modules/yith-woocommerce-zoom-magnifier/class.yith-wcmg-frontend.php +145 -146
  42. modules/yith-woocommerce-zoom-magnifier/class.yith-wcmg.php +1 -1
  43. modules/yith-woocommerce-zoom-magnifier/functions.yith-wcmg.php +56 -45
  44. modules/yith-woocommerce-zoom-magnifier/init.php +3 -3
  45. modules/yith-woocommerce-zoom-magnifier/languages/ywzm-it_IT.mo +0 -0
  46. modules/yith-woocommerce-zoom-magnifier/languages/ywzm-it_IT.po +167 -88
  47. modules/yith-woocommerce-zoom-magnifier/languages/ywzm.pot +70 -64
  48. modules/yith-woocommerce-zoom-magnifier/lib/class.yith-woocommerce-zoom-magnifier.php +1 -1
  49. modules/yith-woocommerce-zoom-magnifier/lib/class.yith-ywzm-custom-types.php +177 -207
  50. modules/yith-woocommerce-zoom-magnifier/lib/class.yith-ywzm-plugin-fw-loader.php +1 -1
  51. modules/yith-woocommerce-zoom-magnifier/plugin-options/general-options.php +50 -49
  52. modules/yith-woocommerce-zoom-magnifier/templates/admin/premium.php +13 -15
  53. modules/yith-woocommerce-zoom-magnifier/templates/single-product/product-thumbnails-magnifier.php +4 -0
  54. modules/yith-woocommerce-zoom-magnifier/yit-common/yith-panel.php +3 -9
  55. plugin-fw/assets/js/yit-cpt-unlimited.js +1 -1
  56. plugin-fw/assets/js/yit-cpt-unlimited.min.js +1 -1
  57. plugin-fw/lib/yit-cpt-unlimited.php +1 -1
  58. plugin-fw/lib/yit-video.php +12 -4
  59. plugin-fw/yit-functions.php +5 -0
  60. templates/yith-single-plugin.php +1 -1
  61. yith-jetpack.php +130 -11
README.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: yithemes
4
  Tags: woocommerce,jetpack,woocommerce jetpack, essential, kit, plugins, plugin, product, e-commerce, ecommerce, commerce, shop, yith, yit, yithemes,yith woocommerce colors and labels variations, colors and labels variations,colors and labels variations jetpack,yith woocommerce zoom magnifier,zoom magnifier,zoom magnifier jetpack,yith woocommerce wishlist,wishlist,wishlist jetpack,yith woocommerce compare,compare,compare jetpack,yith woocommerce ajax product filter,ajax product filter,ajax product filter jetpack,yith woocommerce ajax search,ajax search,ajax search jetpack,yith woocommerce catalog mode,catalog mode,catalog mode jetpack,yith woocommerce order tracking,order tracking,order tracking jetpack, yith woocommerce advanced reviews,advanced reviews,advanced reviews jetpack,yith woocommerce badges management,badges management,badges management jetpack,yith woocommerce cart messages,cart messages,cart messages jetpack,yith woocommerce review reminder,review reminder,review reminder jetpack,yith woocommerce quick view,quick view,quick view jetpack,yith live chat,live chat,live chat jetpack,yith woocommerce eu vat,eu vat,eu vat jetpack,yith woocommerce mailchimp,mailchimp,mailchimp jetpack,yith woocommerce stripe,stripe, stripe jetpack,yith infinite scrolling,infinite scrolling,infinite scrolling jetpack,yith woocommerce request a quote,request a quote,request a quote jetpack,yith woocommerce waiting list,waiting list,waiting list jetpack,yith woocommerce tab manager,tab manager,tab manager jetpack,yith woocommerce multi vendor,multi vendor,multi vendor jetpack,product vendor,products vendor,products vendor jetpack, booster for woocommerce
5
  Requires at least: 3.5.1
6
  Tested up to: 4.2.4
7
- Stable tag: 1.0.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -150,6 +150,10 @@ YITH Essential Kit for WooCommerce #1 will add a new submenu called "YITH Essent
150
 
151
  == Changelog ==
152
 
 
 
 
 
153
  = 1.0.7 =
154
 
155
  * Updated: YITH WooCommerce Badge Mangement
@@ -187,5 +191,5 @@ YITH Essential Kit for WooCommerce #1 will add a new submenu called "YITH Essent
187
 
188
  == Upgrade Notice ==
189
 
190
- Last Stable Tag 1.0.7
191
 
4
  Tags: woocommerce,jetpack,woocommerce jetpack, essential, kit, plugins, plugin, product, e-commerce, ecommerce, commerce, shop, yith, yit, yithemes,yith woocommerce colors and labels variations, colors and labels variations,colors and labels variations jetpack,yith woocommerce zoom magnifier,zoom magnifier,zoom magnifier jetpack,yith woocommerce wishlist,wishlist,wishlist jetpack,yith woocommerce compare,compare,compare jetpack,yith woocommerce ajax product filter,ajax product filter,ajax product filter jetpack,yith woocommerce ajax search,ajax search,ajax search jetpack,yith woocommerce catalog mode,catalog mode,catalog mode jetpack,yith woocommerce order tracking,order tracking,order tracking jetpack, yith woocommerce advanced reviews,advanced reviews,advanced reviews jetpack,yith woocommerce badges management,badges management,badges management jetpack,yith woocommerce cart messages,cart messages,cart messages jetpack,yith woocommerce review reminder,review reminder,review reminder jetpack,yith woocommerce quick view,quick view,quick view jetpack,yith live chat,live chat,live chat jetpack,yith woocommerce eu vat,eu vat,eu vat jetpack,yith woocommerce mailchimp,mailchimp,mailchimp jetpack,yith woocommerce stripe,stripe, stripe jetpack,yith infinite scrolling,infinite scrolling,infinite scrolling jetpack,yith woocommerce request a quote,request a quote,request a quote jetpack,yith woocommerce waiting list,waiting list,waiting list jetpack,yith woocommerce tab manager,tab manager,tab manager jetpack,yith woocommerce multi vendor,multi vendor,multi vendor jetpack,product vendor,products vendor,products vendor jetpack, booster for woocommerce
5
  Requires at least: 3.5.1
6
  Tested up to: 4.2.4
7
+ Stable tag: 1.0.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
150
 
151
  == Changelog ==
152
 
153
+ = 1.0.8 =
154
+
155
+ * Updated: All YITH plugins to latest version
156
+
157
  = 1.0.7 =
158
 
159
  * Updated: YITH WooCommerce Badge Mangement
191
 
192
  == Upgrade Notice ==
193
 
194
+ Last Stable Tag 1.0.8
195
 
init.php CHANGED
@@ -7,7 +7,7 @@ Text Domain: yith-jetpack
7
  Domain Path: /languages/
8
  Author: YIThemes
9
  Author URI: http://yithemes.com/
10
- Version: 1.0.7
11
  */
12
 
13
  if ( ! defined( 'ABSPATH' ) ) {
7
  Domain Path: /languages/
8
  Author: YIThemes
9
  Author URI: http://yithemes.com/
10
+ Version: 1.0.8
11
  */
12
 
13
  if ( ! defined( 'ABSPATH' ) ) {
languages/yith-jetpack.pot CHANGED
@@ -1,8 +1,8 @@
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: YIT Framework\n"
4
- "POT-Creation-Date: 2015-08-07 11:18+0100\n"
5
- "PO-Revision-Date: 2015-08-11 14:05+0100\n"
6
  "Last-Translator: Giustino Borzacchiello <giustinob@gmail.com>\n"
7
  "Language-Team: \n"
8
  "Language: en\n"
@@ -19,159 +19,157 @@ msgstr ""
19
  "X-Poedit-SearchPathExcluded-0: plugin-fw\n"
20
  "X-Poedit-SearchPathExcluded-1: modules\n"
21
 
22
- #: templates/yith-list-plugins.php:27
23
  msgid "Module <strong>activated</strong>."
24
  msgstr ""
25
 
26
- #: templates/yith-list-plugins.php:30
27
- msgid "Module <strong>deactivated</strong>."
28
- msgstr ""
29
-
30
  #: templates/yith-list-plugins.php:34
31
- msgid "Modules <strong>activated</strong>."
32
  msgstr ""
33
 
34
  #: templates/yith-list-plugins.php:38
35
- msgid "Modules <strong>deactivated</strong>."
36
  msgstr ""
37
 
38
  #: templates/yith-list-plugins.php:42
39
- msgid "YITH WooCommerce JetPack 1"
40
  msgstr ""
41
 
42
- #: templates/yith-list-plugins.php:44
43
  msgid ""
44
  "Here you can activate or deactive some of our plugins to enhance your e-"
45
  "commerce site."
46
  msgstr ""
47
 
48
- #: templates/yith-list-plugins.php:49
 
49
  msgid "Activate all"
50
- msgstr ""
51
 
52
- #: templates/yith-list-plugins.php:50
53
  msgid "Deactivate all"
54
  msgstr ""
55
 
56
- #: templates/yith-list-plugins.php:59
57
  msgid "All"
58
  msgstr ""
59
 
60
- #: templates/yith-list-plugins.php:60
61
  msgid "Active"
62
  msgstr ""
63
 
64
- #: templates/yith-list-plugins.php:61
65
  msgid "Inactive"
66
  msgstr ""
67
 
68
- #: templates/yith-single-plugin.php:50
69
  #, fuzzy, php-format
70
  msgid "By %s"
71
  msgstr ""
72
  "Note: Delivery and taxes are estimated%s and will be updated during checkout "
73
  "based on your billing and shipping information."
74
 
75
- #: templates/yith-single-plugin.php:55
76
  #, php-format
77
  msgid "Deactivate %s now"
78
  msgstr ""
79
 
80
- #: templates/yith-single-plugin.php:55
81
  msgid "Deactivate"
82
  msgstr ""
83
 
84
- #: templates/yith-single-plugin.php:67
85
  #, php-format
86
  msgid "activate %s now"
87
  msgstr ""
88
 
89
- #: templates/yith-single-plugin.php:67
 
90
  msgid "Activate"
91
- msgstr ""
92
 
93
- #: templates/yith-single-plugin.php:74
94
  #, php-format
95
  msgid "More information about %s"
96
  msgstr ""
97
 
98
- #: templates/yith-single-plugin.php:74
99
  msgid "More Details"
100
  msgstr ""
101
 
102
- #: templates/yith-single-plugin.php:80
103
  msgid "Premium Installed"
104
  msgstr ""
105
 
106
- #: templates/yith-single-plugin.php:84
107
  msgid "Premium Version"
108
  msgstr ""
109
 
110
- #: templates/yith-single-plugin.php:88
111
  #, php-format
112
  msgid "Premium Version of %s"
113
  msgstr ""
114
 
115
- #: templates/yith-single-plugin.php:91
116
  msgid "M j, Y @ H:i"
117
  msgstr ""
118
 
119
- #: templates/yith-single-plugin.php:126
120
  msgid "Last Updated:"
121
  msgstr ""
122
 
123
- #: templates/yith-single-plugin.php:127
124
  #, php-format
125
  msgid "%s ago"
126
  msgstr ""
127
 
128
- #: templates/yith-single-plugin.php:138
129
  msgctxt "Active plugin installs"
130
  msgid "1+ Million"
131
  msgstr ""
132
 
133
- #: templates/yith-single-plugin.php:145
134
  msgctxt "Downloaded"
135
  msgid "1+ Million"
136
  msgstr ""
137
 
138
- #: templates/yith-single-plugin.php:150
139
  #, php-format
140
  msgid "%s Download, %s Active Installs"
141
  msgstr ""
142
 
143
- #: yith-jetpack.php:86
144
  msgid "Plugins List"
145
  msgstr ""
146
 
147
- #: yith-jetpack.php:392
148
  msgid "YIT Plugins"
149
  msgstr ""
150
 
151
- #: yith-jetpack.php:425
152
  #, php-format
153
  msgid ""
154
  "There are new plugins available on <b>%s</b>, <a href=\"%s\">take a look at "
155
  "them</a> !"
156
  msgstr ""
157
 
158
- #: yith-jetpack.php:475 yith-jetpack.php:507
159
  msgid "The module is not valid."
160
  msgstr ""
161
 
162
- #: yith-jetpack.php:475 yith-jetpack.php:480 yith-jetpack.php:484
163
- #: yith-jetpack.php:507 yith-jetpack.php:512 yith-jetpack.php:516
164
  msgid "Back to modules"
165
  msgstr ""
166
 
167
- #: yith-jetpack.php:480
168
  msgid "The module is already activated."
169
  msgstr ""
170
 
171
- #: yith-jetpack.php:484 yith-jetpack.php:516
172
  msgid "Activation of the module is not possible."
173
  msgstr ""
174
 
175
- #: yith-jetpack.php:512
176
  msgid "The module is already deactivated."
177
  msgstr ""
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: YIT Framework\n"
4
+ "POT-Creation-Date: 2015-09-09 10:27+0100\n"
5
+ "PO-Revision-Date: 2015-09-09 10:27+0100\n"
6
  "Last-Translator: Giustino Borzacchiello <giustinob@gmail.com>\n"
7
  "Language-Team: \n"
8
  "Language: en\n"
19
  "X-Poedit-SearchPathExcluded-0: plugin-fw\n"
20
  "X-Poedit-SearchPathExcluded-1: modules\n"
21
 
22
+ #: templates/yith-list-plugins.php:31
23
  msgid "Module <strong>activated</strong>."
24
  msgstr ""
25
 
 
 
 
 
26
  #: templates/yith-list-plugins.php:34
27
+ msgid "Module <strong>deactivated</strong>."
28
  msgstr ""
29
 
30
  #: templates/yith-list-plugins.php:38
31
+ msgid "Modules <strong>activated</strong>."
32
  msgstr ""
33
 
34
  #: templates/yith-list-plugins.php:42
35
+ msgid "Modules <strong>deactivated</strong>."
36
  msgstr ""
37
 
38
+ #: templates/yith-list-plugins.php:48
39
  msgid ""
40
  "Here you can activate or deactive some of our plugins to enhance your e-"
41
  "commerce site."
42
  msgstr ""
43
 
44
+ #: templates/yith-list-plugins.php:53
45
+ #, fuzzy
46
  msgid "Activate all"
47
+ msgstr "TUTTI PARI PARI"
48
 
49
+ #: templates/yith-list-plugins.php:54
50
  msgid "Deactivate all"
51
  msgstr ""
52
 
53
+ #: templates/yith-list-plugins.php:63
54
  msgid "All"
55
  msgstr ""
56
 
57
+ #: templates/yith-list-plugins.php:64
58
  msgid "Active"
59
  msgstr ""
60
 
61
+ #: templates/yith-list-plugins.php:65
62
  msgid "Inactive"
63
  msgstr ""
64
 
65
+ #: templates/yith-single-plugin.php:54
66
  #, fuzzy, php-format
67
  msgid "By %s"
68
  msgstr ""
69
  "Note: Delivery and taxes are estimated%s and will be updated during checkout "
70
  "based on your billing and shipping information."
71
 
72
+ #: templates/yith-single-plugin.php:59
73
  #, php-format
74
  msgid "Deactivate %s now"
75
  msgstr ""
76
 
77
+ #: templates/yith-single-plugin.php:59
78
  msgid "Deactivate"
79
  msgstr ""
80
 
81
+ #: templates/yith-single-plugin.php:71
82
  #, php-format
83
  msgid "activate %s now"
84
  msgstr ""
85
 
86
+ #: templates/yith-single-plugin.php:71
87
+ #, fuzzy
88
  msgid "Activate"
89
+ msgstr "TUTTI PARI PARI"
90
 
91
+ #: templates/yith-single-plugin.php:78
92
  #, php-format
93
  msgid "More information about %s"
94
  msgstr ""
95
 
96
+ #: templates/yith-single-plugin.php:78
97
  msgid "More Details"
98
  msgstr ""
99
 
100
+ #: templates/yith-single-plugin.php:84
101
  msgid "Premium Installed"
102
  msgstr ""
103
 
104
+ #: templates/yith-single-plugin.php:88
105
  msgid "Premium Version"
106
  msgstr ""
107
 
108
+ #: templates/yith-single-plugin.php:92
109
  #, php-format
110
  msgid "Premium Version of %s"
111
  msgstr ""
112
 
113
+ #: templates/yith-single-plugin.php:95
114
  msgid "M j, Y @ H:i"
115
  msgstr ""
116
 
117
+ #: templates/yith-single-plugin.php:130
118
  msgid "Last Updated:"
119
  msgstr ""
120
 
121
+ #: templates/yith-single-plugin.php:131
122
  #, php-format
123
  msgid "%s ago"
124
  msgstr ""
125
 
126
+ #: templates/yith-single-plugin.php:142
127
  msgctxt "Active plugin installs"
128
  msgid "1+ Million"
129
  msgstr ""
130
 
131
+ #: templates/yith-single-plugin.php:149
132
  msgctxt "Downloaded"
133
  msgid "1+ Million"
134
  msgstr ""
135
 
136
+ #: templates/yith-single-plugin.php:154
137
  #, php-format
138
  msgid "%s Download, %s Active Installs"
139
  msgstr ""
140
 
141
+ #: yith-jetpack.php:100
142
  msgid "Plugins List"
143
  msgstr ""
144
 
145
+ #: yith-jetpack.php:405
146
  msgid "YIT Plugins"
147
  msgstr ""
148
 
149
+ #: yith-jetpack.php:438
150
  #, php-format
151
  msgid ""
152
  "There are new plugins available on <b>%s</b>, <a href=\"%s\">take a look at "
153
  "them</a> !"
154
  msgstr ""
155
 
156
+ #: yith-jetpack.php:488 yith-jetpack.php:520
157
  msgid "The module is not valid."
158
  msgstr ""
159
 
160
+ #: yith-jetpack.php:488 yith-jetpack.php:493 yith-jetpack.php:497
161
+ #: yith-jetpack.php:520 yith-jetpack.php:525 yith-jetpack.php:529
162
  msgid "Back to modules"
163
  msgstr ""
164
 
165
+ #: yith-jetpack.php:493
166
  msgid "The module is already activated."
167
  msgstr ""
168
 
169
+ #: yith-jetpack.php:497 yith-jetpack.php:529
170
  msgid "Activation of the module is not possible."
171
  msgstr ""
172
 
173
+ #: yith-jetpack.php:525
174
  msgid "The module is already deactivated."
175
  msgstr ""
modules/yith-woocommerce-advanced-reviews/class.yith-woocommerce-advanced-reviews.php CHANGED
@@ -1,1734 +1,1736 @@
1
  <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit; // Exit if accessed directly
4
  }
5
 
6
- if ( ! class_exists( 'YITH_WooCommerce_Advanced_Reviews' ) ) {
7
-
8
- /**
9
- * Implements features of FREE version of YWAR plugin
10
- *
11
- * @class YITH_WooCommerce_Advanced_Reviews
12
- * @package Yithemes
13
- * @since 1.0.0
14
- * @author Your Inspiration Themes
15
- */
16
- class YITH_WooCommerce_Advanced_Reviews {
17
- /**
18
- * @var $_panel Panel Object
19
- */
20
- protected $_panel;
21
-
22
- /**
23
- * @var $_premium string Premium tab template file name
24
- */
25
- protected $_premium = 'premium.php';
26
-
27
- /**
28
- * @var string Premium version landing link
29
- */
30
- protected $_premium_landing = 'http://yithemes.com/themes/plugins/yith-woocommerce-advanced-reviews/';
31
-
32
- /**
33
- * @var string Plugin official documentation
34
- */
35
- protected $_official_documentation = 'http://yithemes.com/docs-plugins/yith-woocommerce-advanced-reviews/';
36
-
37
- /**
38
- * @var string Advanced Reviews panel page
39
- */
40
- protected $_panel_page = 'yith_ywar_panel';
41
-
42
- /**
43
- * @var $enable_title Let users to add a title when writing a review
44
- */
45
- protected $enable_title = 0;
46
-
47
- /**
48
- * @var $enable_attachments Let users to add attachments when submit a review
49
- */
50
- protected $enable_attachments = 0;
51
-
52
- /**
53
- * @var $attachments_limit Set the maximum number of attachments a users can add when submit a review
54
- */
55
- protected $attachments_limit = 0;
56
-
57
- public $post_type_name = "ywar_reviews";
58
-
59
- public $items_for_page = 10;
60
-
61
- public $meta_key_rating = "_ywar_rating";
62
- public $meta_key_product_id = "_ywar_product_id";
63
- public $meta_key_imported = "_ywar_imported";
64
- public $meta_key_approved = "_ywar_approved";
65
- public $meta_key_thumb_ids = "_ywar_thumb_ids";
66
- public $meta_key_comment_id = "_ywar_comment_id";
67
-
68
- /**
69
- * @var string meta_key used for saving data about segnalation of inappropriate content from users
70
- */
71
- public $meta_key_inappropriate_list = "_ywar_inappropriate_list";
72
-
73
- /**
74
- * @var string meta_key used for saving data about inappropriate reviews
75
- */
76
- public $meta_key_inappropriate_count = "_ywar_inappropriate_count";
77
-
78
- /**
79
- * @var string meta_key used for saving data about inappropriate reviews
80
- */
81
- public $meta_key_featured = "_ywar_featured";
82
-
83
- /**
84
- * @var string meta_key used for saving data about upvotes
85
- */
86
- public $meta_key_upvotes_count = "_ywar_upvotes_count";
87
-
88
- /**
89
- * @var string meta_key used for saving data about downvotes
90
- */
91
- public $meta_key_downvotes_count = "_ywar_downvotes_count";
92
-
93
- /**
94
- * @var string meta_key used for saving data about reviews votes
95
- */
96
- public $meta_key_votes = "_ywar_votes";
97
-
98
- /**
99
- * @var string meta_key used for saving data about replies status
100
- */
101
- public $meta_key_stop_reply = "_ywar_stop_reply";
102
-
103
- /**
104
- * @var string meta_key used for saving review's user id
105
- */
106
- public $meta_key_review_user_id = "_ywar_review_user_id";
107
-
108
- /**
109
- * @var string meta_key used for saving review's author
110
- */
111
- public $meta_key_review_author = "_ywar_review_author";
112
-
113
- /**
114
- * @var string meta_key used for saving review author's email
115
- */
116
- public $meta_key_review_author_email = "_ywar_review_author_email";
117
-
118
- /**
119
- * @var string meta_key used for saving review author's url
120
- */
121
- public $meta_key_review_author_url = "_ywar_review_author_url";
122
-
123
- /**
124
- * @var string meta_key used for saving review author's IP
125
- */
126
- public $meta_key_review_author_IP = "_ywar_review_author_IP";
127
-
128
- public $custom_column_review = "review-text";
129
 
130
- public $custom_column_rating = "review-rating";
131
 
132
- public $custom_column_date = "review-date";
133
 
134
- public $custom_column_author = "review-author";
135
 
136
- public $custom_column_product = "product";
137
 
138
- /**
139
- * @var string action name for "approve" review
140
- */
141
- protected $approve_review_action = "approve-review";
142
 
143
- /**
144
- * @var string action name for "untrash" review
145
- */
146
- protected $untrash_review_action = "untrash";
147
 
148
- /**
149
- * @var string action name for "unapprove" review
150
- */
151
- protected $unapprove_review_action = "unapprove-review";
152
 
153
- /**
154
- * Single instance of the class
155
- *
156
- * @since 1.0.0
157
- */
158
- protected static $instance;
159
 
160
- /**
161
- * Returns single instance of the class
162
- *
163
- * @since 1.0.0
164
- */
165
- public static function get_instance() {
166
- if ( is_null( self::$instance ) ) {
167
- self::$instance = new self();
168
- }
169
 
170
- return self::$instance;
171
- }
172
 
173
- /**
174
- * Constructor
175
- *
176
- * Initialize plugin and registers actions and filters to be used
177
- *
178
- * @since 1.0
179
- * @author Lorenzo Giuffrida
180
- */
181
- protected function __construct() {
182
- if ( ! function_exists( 'WC' ) ) {
183
- return;
184
- }
185
 
186
- add_action( 'admin_menu', array( $this, 'add_menu_item' ) );
187
 
188
- add_action( 'init', array( $this, 'initialize_settings' ) );
189
 
190
- //region ******* YIT Plugin Framework *********
191
 
192
- // Load Plugin Framework
193
- add_action( 'after_setup_theme', array( $this, 'plugin_fw_loader' ), 1 );
194
 
195
 
196
- // Add row meta
197
- add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 );
198
 
199
- // Add stylesheets and scripts files
200
- add_action( 'admin_menu', array( $this, 'register_panel' ), 5 );
201
 
202
- // register plugin pointer
203
- add_action( 'admin_init', array( $this, 'register_pointer' ) );
204
 
205
- // verify import reviews action request
206
- add_action( "admin_init", array( $this, "check_import_actions" ) );
207
 
208
 
209
- //Add action links
210
- add_filter( 'plugin_action_links_' . plugin_basename( YITH_YWAR_DIR . '/' . basename( YITH_YWAR_FILE ) ), array(
211
- $this,
212
- 'action_links'
213
- ) );
214
 
215
- add_action( 'yith_advanced_reviews_premium', array( $this, 'premium_tab' ) );
216
 
217
- //endregion
218
 
219
- //region *********** Add stylesheets and scripts files ************
220
 
221
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
222
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
223
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles_scripts' ) );
224
 
225
- //endregion
226
 
227
- //region *********** Advanced reviews post type functionalities
228
 
229
- add_action( 'init', array( $this, 'register_post_type' ) );
230
 
231
 
232
- //endregion
233
 
234
- //region *********** Review table
235
 
236
- add_filter( 'yith_advanced_reviews_row_actions', array( $this, 'add_review_actions' ), 10, 2 );
237
 
238
- add_filter( 'post_class', array( $this, 'add_review_table_class' ), 10, 3 );
239
 
240
- /**
241
- * intercept approve and unapprove actions
242
- */
243
- add_action( "admin_action_{$this->approve_review_action}", array( $this, 'update_review_attributes' ) );
244
- add_action( "admin_action_{$this->unapprove_review_action}", array( $this, 'update_review_attributes' ) );
245
- add_action( "admin_action_{$this->untrash_review_action}", array( $this, 'update_review_attributes' ) );
246
 
247
- //endregion ******************************************
248
 
249
- // Load reviews template
250
- add_filter( 'comments_template', array(
251
- $this,
252
- 'show_advanced_reviews_template'
253
- ), 99 );
254
 
255
- // Save additional comment fields on comment submit
256
- add_action( 'comment_post', array( $this, 'submit_review' ) );
257
 
258
- // redirect to product page on comment submitted
259
- add_filter( 'comment_post_redirect', array( $this, 'redirect_after_submit_review' ), 10, 2 );
260
 
261
- add_filter( 'woocommerce_product_review_comment_form_args', array(
262
- $this,
263
- 'add_fields_to_comment_form'
264
- ) );
265
 
266
- // Add custom fields "Title" on top of comment form
267
- add_action( 'comment_form_logged_in_after', array( $this, 'add_custom_fields_on_comment_form' ) );
268
- add_action( 'comment_form_after_fields', array( $this, 'add_custom_fields_on_comment_form' ) );
269
 
270
- add_filter( 'yith_advanced_reviews_review_content', array( $this, 'show_expanded_review_content' ) );
271
 
272
- add_filter( 'woocommerce_product_tabs', array( $this, 'update_tab_reviews_count' ), 20 );
273
 
274
- /**
275
- * Add summary bars for product rating
276
- */
277
- add_action( 'yith_advanced_reviews_before_reviews', array( $this, 'load_reviews_summary' ) );
278
 
279
- // Show details with average rating for the current product
280
- add_action( 'ywar_summary_prepend', array( $this, 'add_reviews_average_info' ) );
281
 
282
- add_filter( 'wc_get_template', array( $this, 'wc_get_template' ), 99, 5 );
283
 
284
- add_filter( 'woocommerce_product_get_rating_html', array( $this, 'get_product_rating_html' ), 99, 2 );
285
 
286
- //region ***************** Show, edit and save back-end review metabox
287
- // Add a new metabox for editing and saving title comment in meta_comment table
288
- add_action( 'add_meta_boxes', array( $this, 'add_plugin_metabox' ), 1 );
289
 
290
- // save the custom fields
291
- add_action( 'save_post', array( $this, 'save_plugin_metabox' ), 1, 2 );
292
 
293
- add_action( 'admin_menu', array( $this, 'remove_unwanted_custom_post_type_features' ), 5 );
294
- add_action( 'admin_head', array( $this, 'hide_unwanted_custom_post_type_features' ) );
295
- //endregion
296
 
297
- add_action( 'woocommerce_admin_field_ywar_import_previous_reviews', array(
298
- $this,
299
- 'show_import_reviews_button'
300
- ), 10, 1 );
301
 
302
- add_action( 'wp_ajax_convert_reviews', array( $this, 'convert_reviews_callback' ) );
303
- }
304
 
305
- /**
306
- * Add the Commissions menu item in dashboard menu
307
- *
308
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
309
- * @since 1.0
310
- * @return void
311
- * @see wp-admin\includes\plugin.php -> add_menu_page()
312
- */
313
- public function add_menu_item() {
314
 
315
- $args = apply_filters( 'yith_wc_product_vendors_commissions_menu_items', array(
316
- 'page_title' => __( 'Reviews', 'ywar' ),
317
- 'menu_title' => __( 'Reviews', 'ywar' ),
318
- 'capability' => 'edit_products',
319
- 'menu_slug' => __( 'Reviews', 'ywar' ),
320
- 'function' => array( $this, 'show_reviews_table' ),
321
- 'icon' => 'dashicons-star-filled',
322
- 'position' => 8 /* After WC Products */
323
- )
324
- );
325
 
326
- extract( $args );
327
 
328
- add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon, $position );
329
- }
330
 
331
- /**
332
- * Show the reviews table
333
- *
334
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
335
- * @since 1.0
336
- * @return void
337
- * @fire yith_vendors_commissions_template hooks
338
- */
339
- public function show_reviews_table() {
340
- if ( ! class_exists( 'WP_Posts_List_Table' ) ) {
341
- require_once( ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php' );
342
- }
343
-
344
- require_once( YITH_YWAR_DIR . 'lib/class.yith-advanced-reviews-list-table.php' );
345
-
346
- $product_reviews = new YITH_Advanced_Reviews_List_Table();
347
- $product_reviews->prepare_items();
348
-
349
- wc_get_template( 'ywar-product-reviews-table.php', array( 'product_reviews' => $product_reviews ), YITH_YWAR_TEMPLATES_DIR, YITH_YWAR_TEMPLATES_DIR );
350
- }
351
-
352
- /**
353
- * Intercept review action url and do the requested job
354
- */
355
- public function update_review_attributes() {
356
-
357
- if ( ! isset( $_GET["review_id"] ) ) {
358
- return;
359
- }
360
-
361
- $review_id = $_GET["review_id"];
362
-
363
- $current_filter = current_filter();
364
-
365
- switch ( $current_filter ) {
366
- case "admin_action_{$this->approve_review_action}" :
367
- update_post_meta( $review_id, $this->meta_key_approved, 1 );
368
-
369
- break;
370
-
371
- case "admin_action_{$this->unapprove_review_action}" :
372
- update_post_meta( $review_id, $this->meta_key_approved, 0 );
373
-
374
- break;
375
-
376
- case "admin_action_{$this->untrash_review_action}" :
377
- $my_post = array(
378
- 'ID' => $review_id,
379
- 'post_status' => 'publish'
380
- );
381
-
382
- // Update the post into the database
383
- wp_update_post( $my_post );
384
-
385
- break;
386
- }
387
-
388
- wp_redirect( esc_url_raw( remove_query_arg( array( 'action', 'action2' ), $_SERVER['HTTP_REFERER'] ) ) );
389
- }
390
-
391
- public function add_review_table_class( $classes, $class, $post_id ) {
392
-
393
- if ( $this->post_type_name != get_post_type( $post_id ) ) {
394
- return $classes;
395
- }
396
-
397
- unset( $classes["review-unapproved"] );
398
- unset( $classes["review-approved"] );
399
-
400
- $approve = get_post_meta( $post_id, $this->meta_key_approved, true );
401
-
402
- if ( 1 == $approve ) {
403
- $classes[] = "review-approved";
404
- } elseif ( 0 == $approve ) {
405
- $classes[] = "review-unapproved";
406
- }
407
-
408
- return apply_filters( 'yith_advanced_reviews_table_class', $classes, $post_id );
409
- }
410
-
411
- /**
412
- * Build a url to be using as action url in row actions
413
- *
414
- * @param $action action to be performed
415
- * @param $post_id review id
416
- *
417
- * @return string|void the url used to send an "approve" action for a specific review
418
- */
419
- public function review_action_url( $action, $post_id ) {
420
- return admin_url( "admin.php?action=$action&post_type={$this->post_type_name}&review_id=$post_id" );
421
- }
422
-
423
- /**
424
- * Build an "untrash" action url
425
- *
426
- * @param $review the review on which the action is performed
427
- *
428
- * @return string|void action url
429
- */
430
- public function untrash_review_url( $review ) {
431
- return $this->review_action_url( $this->untrash_review_action, $review->ID );
432
- }
433
-
434
- /**
435
- * Build an "approve" action url
436
- *
437
- * @param $review the review on which the action is performed
438
- *
439
- * @return string|void action url
440
- */
441
- public function approve_review_url( $review ) {
442
- return $this->review_action_url( $this->approve_review_action, $review->ID );
443
- }
444
-
445
- /**
446
- * Build an "unapprove" action url
447
- *
448
- * @param $review the review on which the action is performed
449
- *
450
- * @return string|void action url
451
- */
452
- public function unapprove_review_url( $review ) {
453
- return $this->review_action_url( $this->unapprove_review_action, $review->ID );
454
- }
455
-
456
- public function add_review_actions( $actions, $post ) {
457
-
458
- if ( $post->post_type != $this->post_type_name ) {
459
- return $actions;
460
- }
461
-
462
- $approved = get_post_meta( $post->ID, $this->meta_key_approved, true );
463
-
464
- unset( $actions['view'] );
465
- unset( $actions['inline hide-if-no-js'] );
466
-
467
- if ( ! $approved ) {
468
- $actions['approve-review'] = '<a href="' . $this->approve_review_url( $post ) . '" title="' . esc_attr( __( 'Approve review', 'ywar' ) ) . '" rel="permalink">' . __( 'Approve', 'ywar' ) . '</a>';
469
- } elseif ( $approved ) {
470
- $actions['unapprove-review'] = '<a href="' . $this->unapprove_review_url( $post ) . '" title="' . esc_attr( __( 'Unapprove review', 'ywar' ) ) . '" rel="permalink">' . __( 'Unapprove', 'ywar' ) . '</a>';
471
- }
472
-
473
- return apply_filters( 'yith_advanced_reviews_review_actions', $actions, $post );
474
- }
475
-
476
- public function get_average_rating( $product_id ) {
477
- global $wpdb;
478
-
479
- $query = $wpdb->prepare( "
480
  select avg(meta_value)
481
  from {$wpdb->prefix}postmeta pm
482
  where meta_key = '{$this->meta_key_rating}' and post_id in
483
  (select post_id from {$wpdb->prefix}postmeta where meta_key = '{$this->meta_key_product_id}' and meta_value = %d and post_id IN
484
- (select post_id from {$wpdb->prefix}postmeta where meta_key = '{$this->meta_key_approved}' and meta_value = 1))", $product_id );
485
 
486
- $count = $wpdb->get_var( $query );
487
 
488
- return number_format( $count, 2 );
489
- }
490
 
491
- public function add_reviews_average_info( $product ) {
492
 
493
- if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) {
494
- return;
495
- }
496
 
497
- global $product;
498
 
499
- $average = $this->get_average_rating( $product->id );
500
 
501
- $count = count( $this->get_product_reviews_by_rating( $product->id ) );
502
 
503
- if ( $count > 0 ) {
504
- echo '<div class="woocommerce-product-rating">
505
- <div class="star-rating" title="' . sprintf( __( 'Rated %s out of 5', 'ywar' ), $average ) . '">
506
- <span style="width:' . ( ( $average / 5 ) * 100 ) . '%"></span>
507
  </div>
508
- <span class="ywar_review_count">' . sprintf( "%d %s", $count, _n( " review", " reviews", $count, 'ywar' ) ) . '</span><span class="review-rating-value"> ' . esc_html( $average ) . ' ' . __( "out of 5 stars", 'ywar' ) . '</span>
509
  </div>';
510
- }
511
- }
512
-
513
- //region *********** YIT Plugin Framework ****************
514
-
515
-
516
- /**
517
- * Enqueue css file
518
- *
519
- * @since 1.0
520
- * @access public
521
- * @return void
522
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
523
- */
524
- public function plugin_fw_loader() {
525
- if ( ! defined( 'YIT' ) || ! defined( 'YIT_CORE_PLUGIN' ) ) {
526
- require_once( 'plugin-fw/yit-plugin.php' );
527
- }
528
- }
529
-
530
- /**
531
- * plugin_row_meta
532
- *
533
- * add the action links to plugin admin page
534
- *
535
- * @param $plugin_meta
536
- * @param $plugin_file
537
- * @param $plugin_data
538
- * @param $status
539
- *
540
- * @return Array
541
- * @since 1.0
542
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
543
- * @use plugin_row_meta
544
- */
545
- public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
546
- if ( ( defined( 'YITH_YWAR_INIT' ) && ( YITH_YWAR_INIT == $plugin_file ) ) ||
547
- ( defined( 'YITH_YWAR_FREE_INIT' ) && ( YITH_YWAR_FREE_INIT == $plugin_file ) )
548
- ) {
549
- $plugin_meta[] = '<a href="' . $this->_official_documentation . '" target="_blank">' . __( 'Plugin Documentation', 'ywar' ) . '</a>';
550
- }
551
-
552
- return $plugin_meta;
553
- }
554
-
555
- /**
556
- * Action Links
557
- *
558
- * add the action links to plugin admin page
559
- *
560
- * @param $links | links plugin array
561
- *
562
- * @return mixed Array
563
- * @since 1.0
564
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
565
- * @return mixed
566
- * @use plugin_action_links_{$plugin_file_name}
567
- */
568
- public function action_links( $links ) {
569
-
570
- $links[] = '<a href="' . admin_url( "admin.php?page={$this->_panel_page}" ) . '">' . __( 'Settings', 'ywar' ) . '</a>';
571
-
572
- if ( defined( 'YITH_YWAR_FREE_INIT' ) ) {
573
- $links[] = '<a href="' . $this->get_premium_landing_uri() . '" target="_blank">' . __( 'Premium Version', 'ywar' ) . '</a>';
574
- }
575
-
576
- return $links;
577
- }
578
-
579
- public function register_pointer() {
580
- if ( ! class_exists( 'YIT_Pointers' ) ) {
581
- include_once( 'plugin-fw/lib/yit-pointers.php' );
582
- }
583
-
584
- $premium_message = defined( 'YITH_YWAR_PREMIUM' )
585
- ? ''
586
- : __( 'YITH WooCommerce Advanced Reviews is available in an outstanding PREMIUM version with many new options, discover it now.', 'ywar' ) .
587
- ' <a href="' . $this->get_premium_landing_uri() . '">' . __( 'Premium version', 'ywar' ) . '</a>';
588
-
589
- $args[] = array(
590
- 'screen_id' => 'plugins',
591
- 'pointer_id' => 'yith_ywar_panel',
592
- 'target' => '#toplevel_page_yit_plugin_panel',
593
- 'content' => sprintf( '<h3> %s </h3> <p> %s </p>',
594
- __( 'YITH WooCommerce Advanced Reviews', 'ywar' ),
595
- __( 'In YIT Plugins tab you can find YITH WooCommerce Advanced Reviews options. From this menu you can access all settings of YITH plugins activated.', 'ywar' ) . '<br>' . $premium_message
596
- ),
597
- 'position' => array( 'edge' => 'left', 'align' => 'center' ),
598
- 'init' => defined( 'YITH_YWAR_PREMIUM' ) ? YITH_YWAR_INIT : YITH_YWAR_FREE_INIT
599
- );
600
-
601
- $args[] = array(
602
- 'screen_id' => 'update',
603
- 'pointer_id' => 'yith_ywar_panel',
604
- 'target' => '#toplevel_page_yit_plugin_panel',
605
- 'content' => sprintf( '<h3> %s </h3> <p> %s </p>',
606
- __( 'YITH WooCommerce Advanced Reviews', 'ywar' ),
607
- __( 'From now on, you can find all YITH WooCommerce Advanced Reviews options in YIT Plugin -> Advanced Reviews instead of WooCommerce -> Settings -> Advanced Reviews, as in the previous version. Any time one of our plugins is updated, a new entry will be added to this menu.', 'ywar' ) . $premium_message
608
- ),
609
- 'position' => array( 'edge' => 'left', 'align' => 'center' ),
610
- 'init' => defined( 'YITH_YWAR_PREMIUM' ) ? YITH_YWAR_INIT : YITH_YWAR_FREE_INIT
611
- );
612
-
613
- YIT_Pointers()->register( $args );
614
- }
615
-
616
- /**
617
- * Get the premium landing uri
618
- *
619
- * @since 1.0.0
620
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
621
- * @return string The premium landing link
622
- */
623
- public function get_premium_landing_uri() {
624
- return defined( 'YITH_REFER_ID' ) ? $this->_premium_landing . '?refer_id=' . YITH_REFER_ID : $this->_premium_landing . '?refer_id=1030585';
625
- }
626
-
627
- /**
628
- * Add a panel under YITH Plugins tab
629
- *
630
- * @return void
631
- * @since 1.0
632
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
633
- * @use /Yit_Plugin_Panel class
634
- * @see plugin-fw/lib/yit-plugin-panel.php
635
- */
636
- public function register_panel() {
637
-
638
- if ( ! empty( $this->_panel ) ) {
639
- return;
640
- }
641
-
642
- $admin_tabs = array(
643
- 'general' => __( 'General', 'ywar' ),
644
- 'layout' => __( 'Layout', 'ywar' )
645
- );
646
-
647
- if ( defined( 'YITH_YWAR_PREMIUM' ) ) {
648
- $admin_tabs['premium'] = __( 'Voting/Review settings', 'ywar' );
649
- } else {
650
- $admin_tabs['premium-landing'] = __( 'Premium Version', 'ywar' );
651
- }
652
-
653
- $args = array(
654
- 'create_menu_page' => true,
655
- 'parent_slug' => '',
656
- 'page_title' => __( 'Advanced Reviews', 'ywar' ),
657
- 'menu_title' => __( 'Advanced Reviews', 'ywar' ),
658
- 'capability' => 'manage_options',
659
- 'parent' => '',
660
- 'parent_page' => 'yit_plugin_panel',
661
- 'page' => $this->_panel_page,
662
- 'admin-tabs' => $admin_tabs,
663
- 'options-path' => YITH_YWAR_DIR . '/plugin-options'
664
- );
665
-
666
- /* === Fixed: not updated theme === */
667
- if ( ! class_exists( 'YIT_Plugin_Panel_WooCommerce' ) ) {
668
- require_once( 'plugin-fw/lib/yit-plugin-panel-wc.php' );
669
- }
670
-
671
- $this->_panel = new YIT_Plugin_Panel_WooCommerce( $args );
672
- }
673
-
674
- /**
675
- * Premium Tab Template
676
- *
677
- * Load the premium tab template on admin page
678
- *
679
- * @return void
680
- * @since 1.0
681
- * @author Andrea Grillo <andrea.grillo@yithemes.com>
682
- * @return void
683
- */
684
- public function premium_tab() {
685
- $premium_tab_template = YITH_YWAR_TEMPLATE_PATH . '/admin/' . $this->_premium;
686
- if ( file_exists( $premium_tab_template ) ) {
687
- include_once( $premium_tab_template );
688
- }
689
- }
690
-
691
- //endregion
692
-
693
- //region *********** Add stylesheets and scripts files ************
694
-
695
- /**
696
- * Add scripts
697
- *
698
- * @since 1.0
699
- * @author Lorenzo Giuffrida
700
- */
701
- public function enqueue_scripts() {
702
- // register and enqueue ajax calls related script file
703
- wp_register_script( "attachments-script", YITH_YWAR_URL . 'assets/js/ywar-attachments.js', array( 'jquery' ) );
704
-
705
- wp_localize_script( 'attachments-script', 'attach', array(
706
- 'limit_multiple_upload' => $this->attachments_limit
707
- ) );
708
- wp_enqueue_script( 'attachments-script' );
709
- }
710
-
711
- /**
712
- * Enqueue css file
713
- *
714
- * @since 1.0
715
- * @author Lorenzo Giuffrida
716
- */
717
- public function enqueue_styles() {
718
- wp_enqueue_style( 'yit-style', YITH_YWAR_ASSETS_URL . '/css/yit-advanced-reviews.css' );
719
- }
720
-
721
- /**
722
- * Enqueue scripts on administration comment page
723
- *
724
- * @param $hook
725
- */
726
- function enqueue_admin_styles_scripts( $hook ) {
727
-
728
- /** Add Woocommerce.css file */
729
- $styles = (array) WC_Frontend_Scripts::get_styles();
730
-
731
- if ( array_key_exists( 'woocommerce-general', $styles ) ) {
732
- wp_enqueue_style( 'woocommerce-general', $styles['woocommerce-general']['src'] );
733
- }
734
-
735
- wp_enqueue_style( 'yith-google-fonts', '//fonts.googleapis.com/css?family=Raleway:500,700,800,400' );
736
- wp_enqueue_style( 'yit-style', YITH_YWAR_ASSETS_URL . '/css/yit-advanced-reviews.css' );
737
-
738
- wp_register_script( "ajax-back-end-script", YITH_YWAR_URL . 'assets/js/ywar-back-end.js', array(
739
- 'jquery',
740
- 'jquery-blockui'
741
- ) );
742
-
743
- $loader = apply_filters( 'yith_advanced_reviews_loader_gif', YITH_YWAR_ASSETS_URL . '/images/loading.gif' );
744
-
745
- wp_localize_script( 'ajax-back-end-script', 'ywar', array(
746
- 'loader' => $loader,
747
- 'ajax_url' => admin_url( 'admin-ajax.php' )
748
- ) );
749
-
750
- wp_enqueue_script( "ajax-back-end-script" );
751
- }
752
-
753
- //endregion
754
-
755
- //region *********** Advanced reviews post type functionalities
756
-
757
- /**
758
- * Register advanced reviews post type
759
- */
760
- public function register_post_type() {
761
- // Set UI labels for Custom Post Type
762
- $labels = array(
763
- 'name' => _x( 'Reviews', 'Post Type General Name', 'ywar' ),
764
- 'singular_name' => _x( 'Review', 'Post Type Singular Name', 'ywar' ),
765
- 'menu_name' => __( 'Reviews', 'ywar' ),
766
- 'parent_item_colon' => __( 'Parent Review', 'ywar' ),
767
- 'all_items' => __( 'All reviews', 'ywar' ),
768
- 'view_item' => __( 'View review', 'ywar' ),
769
- 'add_new_item' => __( 'Add New Review', 'ywar' ),
770
- 'add_new' => __( 'Add New', 'ywar' ),
771
- 'edit_item' => __( 'Edit Review', 'ywar' ),
772
- 'update_item' => __( 'Update Review', 'ywar' ),
773
- 'search_items' => __( 'Search Review', 'ywar' ),
774
- 'not_found' => __( 'Not Found', 'ywar' ),
775
- 'not_found_in_trash' => __( 'Not found in bin', 'ywar' ),
776
- );
 
 
777
 
778
  // Set other options for Custom Post Type
779
 
780
- $args = array(
781
- 'label' => __( 'YIT Product reviews', 'ywar' ),
782
- 'description' => __( 'Advanced WooCommerce product reviews', 'ywar' ),
783
- 'labels' => $labels,
784
  // Features this CPT supports in Post Editor
785
- 'supports' => array(
786
- 'title',
787
- 'editor',
788
- 'author',
789
- ),
790
- /* A hierarchical CPT is like Pages and can have
791
- * Parent and child items. A non-hierarchical CPT
792
- * is like Posts.
793
- */
794
- 'hierarchical' => true,
795
- 'public' => true,
796
- 'show_ui' => false,
797
- 'show_in_menu' => true,
798
- 'show_in_nav_menus' => false,
799
- 'show_in_admin_bar' => true,
800
- 'menu_position' => 9,
801
- 'can_export' => true,
802
- 'has_archive' => true,
803
- 'exclude_from_search' => true,
804
- 'publicly_queryable' => false,
805
- 'capability_type' => 'page',
806
- 'menu_icon' => 'dashicons-star-filled',
807
- 'query_var' => false,
808
- );
809
 
810
  // Registering your Custom Post Type
811
- register_post_type( $this->post_type_name, $args );
812
-
813
-
814
- }
815
-
816
-
817
- /**
818
- * Default query arguments to be used where querying to review custom post type
819
- *
820
- * @param $product_id
821
- *
822
- * @return array
823
- */
824
- function default_query_args( $product_id ) {
825
- return array(
826
- 'numberposts' => - 1, //By default retrieve all reviews
827
- 'offset' => 0,
828
- 'orderby' => 'post_date',
829
- 'order' => 'DESC',
830
- 'post_type' => 'ywar_reviews',
831
- 'post_parent' => '0',
832
- 'post_status' => 'publish',
833
- 'meta_query' => array(
834
- 'relation' => 'AND',
835
- array(
836
- 'key' => $this->meta_key_product_id,
837
- 'value' => $product_id,
838
- 'compare' => '=',
839
- 'type' => 'numeric'
840
- ),
841
- array(
842
- 'key' => $this->meta_key_approved,
843
- 'value' => 1,
844
- 'compare' => '=',
845
- 'type' => 'numeric'
846
- )
847
- )
848
- );
849
- }
850
-
851
- /**
852
- * Retrieve reviews for a product
853
- *
854
- * @param $product_id product id for whose retrieve the reviews
855
- */
856
- public function get_product_reviews( $product_id = null, $args = null ) {
857
-
858
- if ( $args == null ) {
859
- $args = $this->default_query_args( $product_id );
860
- }
861
-
862
- // if $product_id is null, retrieve all reviews without filters
863
- if ( is_null( $product_id ) ) {
864
- unset( $args['meta_query'] );
865
- }
866
-
867
- return get_posts( $args );
868
- }
869
-
870
-
871
- /**
872
- * Return the number of reviews for a specific product
873
- *
874
- * @param $product_id product id for whose retrieve the reviews
875
- */
876
- public function get_product_reviews_by_rating( $product_id, $rating = 0 ) {
877
- $args = $this->default_query_args( $product_id );
878
- if ( $rating > 0 ) {
879
- $args['meta_query'][] = array(
880
- 'key' => $this->meta_key_rating,
881
- 'value' => $rating,
882
- 'compare' => '=',
883
- 'type' => 'numeric'
884
- );
885
- }
886
-
887
- return $this->get_product_reviews( $product_id, $args );
888
- }
889
-
890
-
891
- /**
892
- * Show the reviews for a specific product
893
- *
894
- * @param $product_id product id for whose should be shown the reviews
895
- */
896
- public function reviews_list( $product_id, $args = null ) {
897
- $reviews = $this->get_product_reviews( $product_id, $args );
898
-
899
- foreach ( $reviews as $review ) {
900
- $this->show_review( $review );
901
- }
902
- }
903
-
904
- /**
905
- * Call the review template and show the review
906
- *
907
- * @param $review review to be shown
908
- */
909
- public function show_review( $review, $featured = false, $classes = '' ) {
910
- global $ywar_review;
911
- $ywar_review = $review;
912
- wc_get_template( 'ywar-review.php', array(
913
- 'review' => $review,
914
- 'featured' => $featured,
915
- 'classes' => $classes
916
- ), '', YITH_YWAR_TEMPLATES_DIR );
917
- }
918
-
919
- //endregion
920
-
921
- /**
922
- * Initialize plugin options
923
- *
924
- * @since 1.0
925
- * @access public
926
- * @access public
927
- * @return void
928
- * @author Lorenzo Giuffrida
929
- */
930
- public function initialize_settings() {
931
- $this->enable_title = get_option( 'ywar_enable_review_title' ) === 'yes';
932
- $this->enable_attachments = get_option( 'ywar_enable_attachments' ) === 'yes';
933
- $this->attachments_limit = get_option( 'ywar_max_attachments' );
934
- }
935
-
936
- /**
937
- * Return the right path to the reviews template file
938
- *
939
- * @param $template the template that is currently used
940
- *
941
- * @return mixed|void new template path, only for product comments page
942
- */
943
- public function show_advanced_reviews_template( $template ) {
944
-
945
- if ( get_post_type() === 'product' ) {
946
- // return apply_filters( 'ywar_show_advanced_reviews_template', YITH_YWAR_TEMPLATES_DIR . "ywar-product-reviews.php" );
947
- return wc_locate_template( "ywar-product-reviews.php", '', YITH_YWAR_TEMPLATES_DIR );
948
- }
949
-
950
- return $template;
951
- }
952
-
953
- /**
954
- * Create new Advanced Review post type when a comment is saved to database
955
- *
956
- * @since 1.0
957
- * @author Lorenzo Giuffrida
958
- */
959
- public function submit_review( $comment_id ) {
960
- if ( ! isset( $_POST ) ) {
961
- return;
962
- }
963
-
964
- $review_title = $this->enable_title && isset( $_POST["title"] ) ? wp_strip_all_tags( $_POST["title"] ) : '';
965
-
966
- $post_parent = apply_filters( 'yith_advanced_reviews_post_parent', $_POST["comment_parent"] );
967
-
968
- $comment = get_comment( $comment_id );
969
-
970
- // Create post object
971
- $my_post = array(
972
- 'post_author' => $comment->user_id,
973
- 'post_title' => $review_title,
974
- 'post_content' => $comment->comment_content,
975
- 'post_status' => 'publish',
976
- 'post_author' => get_current_user_id(),
977
- 'post_type' => $this->post_type_name,
978
- 'post_parent' => $post_parent,
979
- 'review_user_id' => $comment->user_id,
980
- 'review_rating' => ( isset( $_POST["rating"] ) ? $_POST["rating"] : 0 ),
981
- 'review_product_id' => $comment->comment_post_ID,
982
- 'review_comment_id' => $comment_id,
983
- 'review_approved' => apply_filters( 'yith_advanced_reviews_approve_new_review', true ),
984
- 'review_author' => $comment->comment_author,
985
- 'review_author_email' => $comment->comment_author_email,
986
- 'review_author_IP' => $comment->comment_author_IP,
987
- 'review_author_url' => $comment->comment_author_url
988
- );
989
-
990
- // Insert the post into the database
991
- $review_id = $this->insert_review( $my_post );
992
-
993
- $this->submit_attachments( $review_id );
994
- }
995
-
996
- public function insert_review( $args ) {
997
- // Create post object
998
- $defaults = array(
999
- 'post_title' => '',
1000
- 'post_content' => '',
1001
- 'post_status' => 'publish',
1002
- 'post_author' => 0,
1003
- 'post_type' => $this->post_type_name,
1004
- 'post_parent' => 0,
1005
- 'review_user_id' => 0,
1006
- 'review_approved' => 1,
1007
- 'review_rating' => 0,
1008
- 'review_product_id' => 0,
1009
- 'review_comment_id' => 0,
1010
- 'review_upvotes' => 0,
1011
- 'review_downvotes' => 0,
1012
- 'review_votes' => array(),
1013
- 'review_inappropriate_list' => array(),
1014
- 'review_inappropriate_count' => 0,
1015
- 'review_is_featured' => 0,
1016
- 'review_is_reply_blocked' => 0,
1017
- 'review_thumbnails' => array(),
1018
- 'review_author' => '',
1019
- 'review_author_email' => '',
1020
- 'review_author_url' => '',
1021
- 'review_author_IP' => ''
1022
- );
1023
-
1024
- $args = wp_parse_args( $args, $defaults );
1025
-
1026
- // Insert the post into the database
1027
- $review_id = wp_insert_post( $args );
1028
-
1029
- // Set rating only for top level reviews, not for replies
1030
- if ( 0 != $args["post_parent"] ) {
1031
- update_post_meta( $review_id, $this->meta_key_rating, 0 );
1032
- } else {
1033
- update_post_meta( $review_id, $this->meta_key_rating, $args["review_rating"] );
1034
- }
1035
-
1036
- update_post_meta( $review_id, $this->meta_key_rating, $args["review_rating"] );
1037
- update_post_meta( $review_id, $this->meta_key_approved, $args["review_approved"] );
1038
- update_post_meta( $review_id, $this->meta_key_product_id, $args["review_product_id"] );
1039
- update_post_meta( $review_id, $this->meta_key_comment_id, $args["review_comment_id"] );
1040
- update_post_meta( $review_id, $this->meta_key_thumb_ids, $args["review_thumbnails"] );
1041
-
1042
- update_post_meta( $review_id, $this->meta_key_upvotes_count, $args["review_upvotes"] );
1043
- update_post_meta( $review_id, $this->meta_key_downvotes_count, $args["review_downvotes"] );
1044
- update_post_meta( $review_id, $this->meta_key_votes, $args["review_votes"] );
1045
-
1046
- update_post_meta( $review_id, $this->meta_key_inappropriate_list, $args["review_inappropriate_list"] );
1047
- update_post_meta( $review_id, $this->meta_key_inappropriate_count, $args["review_inappropriate_count"] );
1048
- update_post_meta( $review_id, $this->meta_key_featured, $args["review_is_featured"] );
1049
- update_post_meta( $review_id, $this->meta_key_stop_reply, $args["review_is_reply_blocked"] );
1050
-
1051
- update_post_meta( $review_id, $this->meta_key_review_user_id, $args["review_user_id"] );
1052
- update_post_meta( $review_id, $this->meta_key_review_author, $args["review_author"] );
1053
- update_post_meta( $review_id, $this->meta_key_review_author_email, $args["review_author_email"] );
1054
- update_post_meta( $review_id, $this->meta_key_review_author_url, $args["review_author_url"] );
1055
- update_post_meta( $review_id, $this->meta_key_review_author_IP, $args["review_author_IP"] );
1056
-
1057
- return $review_id;
1058
- }
1059
-
1060
- /**
1061
- * redirect to product page on comment submitted
1062
- */
1063
- public function redirect_after_submit_review( $location, $comment ) {
1064
- // Set the new comment as imported so it will not imported when clicking on "convert reviews", creating duplicated entries
1065
- update_comment_meta( $comment->comment_ID, $this->meta_key_imported, 1 );
1066
-
1067
- return get_permalink( $comment->comment_post_ID );
1068
- }
1069
-
1070
- /**
1071
- * Add custom field "Title" on top of comment form
1072
- *
1073
- * Check if the "enable title" option is activated and add a title field on comment form
1074
- *
1075
- * @return void
1076
- *
1077
- * @since 1.0
1078
- * @author Lorenzo Giuffrida
1079
- */
1080
- public function add_custom_fields_on_comment_form() {
1081
-
1082
- if ( ! is_product() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1083
- return;
1084
- }
1085
-
1086
- if ( $this->enable_title ) {
1087
- echo '<p class="comment-form-title"><label for="title">' . __( 'Review title', 'ywar' ) . '</label><input type="text" name="title" id="title"/></p>';
1088
- }
1089
- }
1090
-
1091
- //region *********** attachments ********************
1092
-
1093
- /**
1094
- * Submit attachments from a comment form
1095
- *
1096
- * Check if attachment option is enabled and option value is satisfied, then upload attachment files.
1097
- *
1098
- * @param int $review_id the review id the files are referred.
1099
- *
1100
- * @return void
1101
- *
1102
- * @since 1.0
1103
- * @author Lorenzo Giuffrida
1104
- */
1105
- public function submit_attachments( $review_id ) {
1106
- // check if attachments are enabled
1107
- if ( ! $this->enable_attachments ) {
1108
- return;
1109
- }
1110
-
1111
- if ( $_FILES ) {
1112
- $files = $_FILES["uploadFile"];
1113
- $files_count = count( $files['name'] );
1114
-
1115
- // check for attachments limits
1116
- if ( ( $this->attachments_limit > 0 ) && ( $files_count > $this->attachments_limit ) ) {
1117
- return;
1118
- }
1119
-
1120
- $attacchments_array = array();
1121
-
1122
- foreach ( $files['name'] as $key => $value ) {
1123
- if ( $files['name'][ $key ] ) {
1124
- $file = array(
1125
- 'name' => $files['name'][ $key ],
1126
- 'type' => $files['type'][ $key ],
1127
- 'tmp_name' => $files['tmp_name'][ $key ],
1128
- 'error' => $files['error'][ $key ],
1129
- 'size' => $files['size'][ $key ]
1130
- );
1131
- $_FILES = array( "uploadFile" => $file );
1132
-
1133
- foreach ( $_FILES as $file => $array ) {
1134
- $attachId = $this->insert_attachment( $file, $review_id );
1135
-
1136
- // enqueue attachments to current comment
1137
- array_push( $attacchments_array, $attachId );
1138
- }
1139
- }
1140
- }
1141
-
1142
- // save review with attachments array
1143
- update_post_meta( $review_id, $this->meta_key_thumb_ids, $attacchments_array );
1144
- }
1145
- }
1146
-
1147
- /**
1148
- * Add attachment to media library
1149
- *
1150
- * @param int $postId
1151
- * @param string $fileHandler
1152
- *
1153
- * @return void
1154
- *
1155
- * @since 1.0
1156
- * @author Lorenzo Giuffrida
1157
- */
1158
- public function insert_attachment( $fileHandler, $postId ) {
1159
- if ( $_FILES[ $fileHandler ]['error'] !== UPLOAD_ERR_OK ) {
1160
- __return_false();
1161
- }
1162
-
1163
- require_once( ABSPATH . "wp-admin" . '/includes/image.php' );
1164
- require_once( ABSPATH . "wp-admin" . '/includes/file.php' );
1165
- require_once( ABSPATH . "wp-admin" . '/includes/media.php' );
1166
-
1167
- return media_handle_upload( $fileHandler, $postId );
1168
- }
1169
-
1170
- /**
1171
- * Append attachment fields on comment form
1172
- *
1173
- * @param object $comment_form
1174
- *
1175
- * @return object $comment_form
1176
- *
1177
- * @since 1.0
1178
- * @author Lorenzo Giuffrida
1179
- */
1180
- public function add_fields_to_comment_form( $comment_form ) {
1181
- $current_content = $comment_form['comment_field'];
1182
-
1183
- // In case of a page refresh following a reply request, don't add additional fields
1184
- $hide_rating = isset( $_REQUEST["replytocom"] ) ? "hide-rating" : '';
1185
- $selected = isset( $_REQUEST["replytocom"] ) ? "selected" : '';
1186
-
1187
- if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) {
1188
- $comment_form['comment_field'] = '<p class="' . $hide_rating . ' comment-form-rating">
1189
- <label for="rating">' . __( 'Your Rate', 'ywar' ) . '</label>
1190
  <select name="rating" id="rating">
1191
- <option value="">' . __( 'Rate&hellip;', 'ywar' ) . '</option>
1192
- <option value="5">' . __( 'Perfect', 'ywar' ) . '</option>
1193
- <option value="4">' . __( 'Good', 'ywar' ) . '</option>
1194
- <option value="3">' . __( 'Average', 'ywar' ) . '</option>
1195
- <option value="2">' . __( 'Not that bad', 'ywar' ) . '</option>
1196
- <option value="1" ' . $selected . '>' . __( 'Very Poor', 'ywar' ) . '</option>';
1197
-
1198
- $comment_form['comment_field'] .= '</select></p>' . $current_content;
1199
- }
1200
-
1201
- if ( $this->enable_attachments ) {
1202
- $comment_form['comment_field'] .= '<p class="upload_section ' . $hide_rating . '" >
1203
- <label for="uploadFile" > ' . __( 'Attachments', 'ywar' ) . ' </label >
1204
- <input type = "button" value = "' . __( 'Choose file(s)', 'ywar' ) . '" id = "do_uploadFile" />
1205
  <input type = "file" name = "uploadFile[]" id = "uploadFile" accept = "image/*" multiple = "2" />
1206
  </p>
1207
  <p>
1208
  <ul id = "uploadFileList" ></ul>
1209
  </p> ';
1210
- }
1211
-
1212
- return $comment_form;
1213
- }
1214
-
1215
- //endregion
1216
-
1217
- /**
1218
- * Display a customized comment content
1219
- *
1220
- * @param string $text
1221
- *
1222
- * @return string customized comment content
1223
- *
1224
- * @since 1.0
1225
- * @author Lorenzo Giuffrida
1226
- */
1227
- public function show_expanded_review_content( $review ) {
1228
-
1229
- if ( ! is_product() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1230
- return $review->post_content;
1231
- }
1232
-
1233
- $review_title = '';
1234
- $thumbnail_div = $this->get_thumbnails( $review );
1235
-
1236
- if ( $this->enable_title ) {
1237
- // Add review title before review content text
1238
- if ( ! empty( $review->post_title ) ) {
1239
- $review_title = '<span class="review_title"> ' . esc_attr( $review->post_title ) . '</span> ';
1240
- }
1241
- }
1242
-
1243
- return $review_title . $review->post_content . $thumbnail_div;
1244
- }
1245
-
1246
- /**
1247
- * Get an HTML formatted attachment section
1248
- *
1249
- * @param $review the review for whose retrieve attachments
1250
- */
1251
- public function get_thumbnails( $review ) {
1252
- $is_toplevel = ( 0 == $review->post_parent );
1253
- $thumbnail_div = '';
1254
-
1255
- if ( $is_toplevel && $this->enable_attachments ) {
1256
-
1257
- if ( $thumbs = get_post_meta( $review->ID, $this->meta_key_thumb_ids, true ) ) {
1258
-
1259
- $thumbnail_div = '<div class="review_thumbnail horizontalRule"> ';
1260
-
1261
- foreach ( $thumbs as $thumb_id ) {
1262
- $file_url = wp_get_attachment_url( $thumb_id );
1263
- $image_thumb = wp_get_attachment_image_src( $thumb_id, array( 100, 100 ), true );
1264
-
1265
- $thumbnail_div .= "<a href='$file_url' data-rel = \"prettyPhoto[review-gallery-$review->ID]\"><img class=\"ywar_thumbnail\" src='{$image_thumb[0]}' width='70px' height='70px'></a>";
1266
- }
1267
- $thumbnail_div .= ' </div> ';
1268
- }
1269
- }
1270
-
1271
- return $thumbnail_div;
1272
- }
1273
-
1274
- /**
1275
- * Alter text on tab reviews, fixing wrong count of reviews(even replies to reviews were used
1276
- *
1277
- * @param $tabs tabs with description for product reviews
1278
- *
1279
- * @return mixed
1280
- */
1281
- public function update_tab_reviews_count( $tabs ) {
1282
- global $product;
1283
-
1284
- if ( isset( $tabs['reviews'] ) ) {
1285
- $tabs['reviews']['title'] = sprintf( __( 'Reviews(%d)', 'ywar' ), count( $this->get_product_reviews_by_rating( $product->id ) ) );
1286
- }
1287
-
1288
- return $tabs;
1289
- }
1290
-
1291
- /**
1292
- * Collect data about reviews rating and show a summary grouped by stars
1293
- *
1294
- * @param object $template a custom template to be shown
1295
- *
1296
- * @return object $template
1297
- *
1298
- * @since 1.0
1299
- * @author Lorenzo Giuffrida
1300
- */
1301
- public function load_reviews_summary( $template ) {
1302
- if ( ! is_product() ) {
1303
- return $template;
1304
- }
1305
-
1306
- global $product;
1307
- global $review_stats;
1308
- $review_stats = array(
1309
- '1' => count( $this->get_product_reviews_by_rating( $product->id, 1 ) ),
1310
- '2' => count( $this->get_product_reviews_by_rating( $product->id, 2 ) ),
1311
- '3' => count( $this->get_product_reviews_by_rating( $product->id, 3 ) ),
1312
- '4' => count( $this->get_product_reviews_by_rating( $product->id, 4 ) ),
1313
- '5' => count( $this->get_product_reviews_by_rating( $product->id, 5 ) ),
1314
- 'total' => count( $this->get_product_reviews_by_rating( $product->id ) )
1315
- );
1316
-
1317
- wc_get_template( 'ywar-single-product-reviews.php', null, '', YITH_YWAR_TEMPLATES_DIR );
1318
- }
1319
-
1320
- /**
1321
- * Add a metabox on review page for review's title
1322
- *
1323
- * @return void
1324
- *
1325
- * @since 1.0
1326
- * @author Lorenzo Giuffrida
1327
- */
1328
- public function add_plugin_metabox() {
1329
- add_meta_box( 'reviews-metabox', __( 'Review attributes', 'ywar' ), array(
1330
- $this,
1331
- 'display_plugin_metabox'
1332
- ), $this->post_type_name, 'normal', 'high' );
1333
- }
1334
-
1335
- /**
1336
- * Display a meta box with additional review data, like title and thumbnails
1337
- *
1338
- * @return void
1339
- *
1340
- * @since 1.0
1341
- * @author Lorenzo Giuffrida
1342
- */
1343
- public function display_plugin_metabox() {
1344
- global $post;
1345
-
1346
- $rating_div = '';
1347
- $thumbnail_div = '';
1348
-
1349
- $current = get_post_meta( $post->ID, $this->meta_key_rating, true );
1350
- ?>
1351
- <select name="rating" id="rating">
1352
- <?php for ( $rating = 0; $rating <= 5; $rating ++ ) {
1353
- echo sprintf( '<option value="%1$s"%2$s>%1$s</option>', $rating, selected( $current, $rating, false ) );
1354
- } ?>
1355
- </select>
1356
-
1357
- <?php
1358
- // Generate a hidden nonce used for verifying if a request to update the following values came from here
1359
- echo '<input type="hidden" name="review_metabox_nonce" id="review_metabox_nonce" value="' .
1360
- wp_create_nonce( plugin_basename( __FILE__ ) ) . '" />';
1361
-
1362
- $review_thumbnails = get_post_meta( $post->ID, $this->meta_key_thumb_ids, true );
1363
-
1364
- if ( isset ( $review_thumbnails ) && is_array( $review_thumbnails ) ) {
1365
- $thumbnail_div = '<div style = "padding-top: 10px;padding-bottom: 10px;overflow:hidden"> ';
1366
- foreach ( $review_thumbnails as $thumb_id ) {
1367
- $file_url = wp_get_attachment_url( $thumb_id );
1368
- // $image_thumb = wp_get_attachment_image($thumb_id, array(100, 100), true );
1369
- $image_thumb = wp_get_attachment_image_src( $thumb_id, array( 100, 100 ), true );
1370
-
1371
- $thumbnail_div .= "<a href='$file_url'><img src='{$image_thumb[0]}' width='{$image_thumb[1]}' height='{$image_thumb[2]}'></a>";
1372
- }
1373
- $thumbnail_div .= '</div >';
1374
- }
1375
-
1376
- echo $thumbnail_div;
1377
- }
1378
-
1379
- /**
1380
- * Save the Metabox Data
1381
- *
1382
- * @param $post_id
1383
- * @param $post
1384
- *
1385
- * @return mixed
1386
- */
1387
- function save_plugin_metabox( $post_id, $post ) {
1388
-
1389
- if ( ! isset( $_POST['review_metabox_nonce'] ) ) {
1390
- return $post->ID;
1391
- }
1392
-
1393
- // verify the save request started from review edit page...
1394
- if ( ! wp_verify_nonce( $_POST['review_metabox_nonce'], plugin_basename( __FILE__ ) ) ) {
1395
- return $post->ID;
1396
- }
1397
-
1398
- // Check for authorization
1399
- if ( ! current_user_can( 'edit_post', $post->ID ) ) {
1400
- return $post->ID;
1401
- }
1402
-
1403
- // OK, we're authenticated: we need to find and save the data
1404
- // We'll put it into an array to make it easier to loop though.
1405
- if ( isset( $_POST['rating'] ) ) {
1406
- $rating = $_POST['rating'];
1407
-
1408
- if ( is_numeric( $rating ) && ( $rating > 0 ) && ( $rating <= 5 ) ) {
1409
- update_post_meta( $post_id, $this->meta_key_rating, $rating );
1410
- }
1411
- }
1412
- }
1413
-
1414
- /**
1415
- * Remove features for the review custom post type
1416
- */
1417
- public function remove_unwanted_custom_post_type_features() {
1418
- global $submenu;
1419
-
1420
- // Remove Add new for review custom post type
1421
- unset( $submenu["edit.php?post_type={$this->post_type_name}"][10] );
1422
- }
1423
-
1424
- public function hide_unwanted_custom_post_type_features() {
1425
- if ( $this->post_type_name == get_post_type() ) {
1426
- echo '<style type="text/css">
1427
 
1428
  .add-new-h2 {
1429
  display:none;
1430
  }
1431
 
1432
  </style>';
1433
- }
1434
- }
1435
-
1436
- //region ******* Retrieve postmeta values
1437
-
1438
- /**
1439
- * Retrieve value for the "rating" meta_key for a specific review
1440
- *
1441
- * @param $review_id review id from which retrieve the meta_value
1442
- *
1443
- * @return mixed meta_value for "rating" meta_key
1444
- */
1445
- function get_meta_value_rating( $review_id ) {
1446
- return get_post_meta( $review_id, $this->meta_key_rating, true );
1447
- }
1448
-
1449
- /**
1450
- * Retrieve value for the "approved" meta_key for a specific review
1451
- *
1452
- * @param $review_id review id from which retrieve the meta_value
1453
- *
1454
- * @return mixed meta_value for "approved" meta_key
1455
- */
1456
- function get_meta_value_approved( $review_id ) {
1457
- return get_post_meta( $review_id, $this->meta_key_approved, true );
1458
- }
1459
-
1460
- /**
1461
- * Retrieve value for the "product_id" meta_key for a specific review
1462
- *
1463
- * @param $review_id review id from which retrieve the meta_value
1464
- *
1465
- * @return mixed meta_value for "product_id" meta_key
1466
- */
1467
- function get_meta_value_product_id( $review_id ) {
1468
- return get_post_meta( $review_id, $this->meta_key_product_id, true );
1469
- }
1470
-
1471
- /**
1472
- * Retrieve information about the review author
1473
- *
1474
- * @param $review_id review id from which retrieve the meta_value
1475
- *
1476
- * @return array author's information
1477
- */
1478
- function get_meta_value_author( $review_id ) {
1479
- return array(
1480
- 'review_user_id' => get_post_meta( $review_id, $this->meta_key_review_user_id, true ),
1481
- 'review_author' => get_post_meta( $review_id, $this->meta_key_review_author, true ),
1482
- 'review_author_email' => get_post_meta( $review_id, $this->meta_key_review_author_email, true ),
1483
- 'review_author_url' => get_post_meta( $review_id, $this->meta_key_review_author_url, true ),
1484
- 'review_author_IP' => get_post_meta( $review_id, $this->meta_key_review_author_IP, true )
1485
- );
1486
- }
1487
-
1488
- //endregion
1489
-
1490
- public function wc_get_template( $located, $template_name, $args, $template_path, $default_path ) {
1491
- if ( "single-product/rating.php" != $template_name ) {
1492
- return $located;
1493
- }
1494
-
1495
- $located = wc_locate_template( "ywar-rating.php", $template_path, $default_path );
1496
-
1497
- if ( file_exists( $located ) ) {
1498
- return $located;
1499
- }
1500
-
1501
- return YITH_YWAR_TEMPLATES_DIR . 'ywar-rating.php';
1502
- }
1503
-
1504
- public function get_product_rating_html( $rating_html, $rating ) {
1505
- global $product;
1506
- $rating_html = '';
1507
-
1508
- $rating = $this->get_average_rating( $product->id );
1509
-
1510
- if ( $rating > 0 ) {
1511
-
1512
- $rating_html = '<div class="star-rating" title="' . sprintf( __( 'Rated %s out of 5', 'ywar' ), $rating ) . '">';
1513
-
1514
- $rating_html .= '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%"><strong class="rating">' . $rating . '</strong> ' . __( 'out of 5', 'ywar' ) . '</span>';
1515
-
1516
- $rating_html .= '</div>';
1517
- }
1518
-
1519
- return $rating_html;
1520
- }
1521
-
1522
- //region *********** Convert reviews from standard system to YITH Advanced reviews
1523
-
1524
- /**
1525
- * Show import button for starting convertion from standard system to YITH Advanced reviews
1526
- *
1527
- * @param array $args
1528
- */
1529
- public function show_import_reviews_button( $args = array() ) {
1530
- if ( ! empty( $args ) ) {
1531
- $args['value'] = ( get_option( $args['id'] ) ) ? get_option( $args['id'] ) : '';
1532
- extract( $args );
1533
- }
1534
-
1535
- ?>
1536
- <tr valign="top">
1537
- <th scope="row">
1538
-
1539
- </th>
1540
-
1541
- <td class="forminp forminp-color plugin-option">
1542
- <div class="convert-reviews">
1543
- <a href="<?php echo esc_url( add_query_arg( "convert-reviews", "start" ) ); ?>"
1544
- class="button convert-reviews"><?php _e( "Convert reviews", "ywar" ); ?></a>
1545
-
1546
- <div style="display: inline-block; width: 65%; margin-left: 15px;"><span
1547
- class="description"><?php _e( "If this is the first time you install the YITH Advanced Reviews plugin, or if you are using an older version prior to the 1.1.0, first you have to convert the older reviews if you want to use them.", "ywar" ); ?></span>
1548
- </div>
1549
- </div>
1550
- </td>
1551
- </tr>
1552
- <?php
1553
- }
1554
-
1555
- /**
1556
- * Convert previous reviews into new YITH Advanced review type
1557
- *
1558
- * @since 1.0
1559
- * @author Lorenzo Giuffrida
1560
- */
1561
- public function convert_reviews_callback() {
1562
-
1563
- $review_converted = $this->import_previous_reviews();
1564
- $response = '';
1565
-
1566
- if ( $review_converted ) {
1567
- $response = sprintf( __( 'Task completed. %d reviews have been processed and converted.', 'ywar' ), $review_converted );
1568
- } else {
1569
- $response = __( 'Task completed. No review to convert has been found.', 'ywar' );
1570
- }
1571
-
1572
- wp_send_json( array( "value" => $response ) );
1573
- }
1574
-
1575
- /**
1576
- * Set a maximum execution time
1577
- *
1578
- * @param $seconds time in seconds
1579
- */
1580
- private function set_time_limit( $seconds ) {
1581
- $check_safe_mode = ini_get( 'safe_mode' );
1582
- if ( ( ! $check_safe_mode ) || ( 'OFF' == strtoupper( $check_safe_mode ) ) ) {
1583
- @set_time_limit( $seconds );
1584
- }
1585
- }
1586
-
1587
- /**
1588
- * Read and convert previous reviews into new advanced reviews using custom post type
1589
- */
1590
- public function import_previous_reviews() {
1591
- global $wpdb;
1592
-
1593
- $review_converted = 0;
1594
-
1595
- $query = "SELECT *
1596
  FROM {$wpdb->prefix}comments as co left join {$wpdb->prefix}commentmeta as cm
1597
  on co.comment_ID = cm.comment_id
1598
  where ((co.comment_approved = '0') or (co.comment_approved = '1')) and cm.meta_key = 'rating'";
1599
 
1600
- $results = $wpdb->get_results( $query );
1601
-
1602
- // manage parent relationship and update all reviews when import ends
1603
- $review_ids = array();
1604
- $parent_review = array();
1605
-
1606
- foreach ( $results as $comment ) {
1607
-
1608
- // Check if comment_meta exists for previous reviews and is not still imported
1609
- if ( "1" === get_comment_meta( $comment->comment_ID, $this->meta_key_imported, true ) ) {
1610
- // comment still imported, update only author data (Fix for upgrade from 1.1.2 to 1.2.3 then skip it!
1611
-
1612
- // Retrieve review(post) id linked to current comment
1613
- $args = array(
1614
- 'post_type' => 'ywar_reviews',
1615
- 'meta_query' => array(
1616
- array(
1617
- 'key' => $this->meta_key_comment_id,
1618
- 'value' => $comment->comment_ID,
1619
- 'compare' => '=',
1620
- 'type' => 'numeric'
1621
- )
1622
- )
1623
- );
1624
- $reviews = get_posts( $args );
1625
-
1626
- if ( isset( $reviews ) ) {
1627
- $review = $reviews[0];
1628
-
1629
- // Update review meta
1630
- update_post_meta( $review->ID, $this->meta_key_review_user_id, $comment->user_id );
1631
- update_post_meta( $review->ID, $this->meta_key_review_author, $comment->comment_author );
1632
- update_post_meta( $review->ID, $this->meta_key_review_author_email, $comment->comment_author_email );
1633
- update_post_meta( $review->ID, $this->meta_key_review_author_url, $comment->comment_author_url );
1634
- update_post_meta( $review->ID, $this->meta_key_review_author_IP, $comment->comment_author_IP );
1635
- }
1636
-
1637
- continue;
1638
- }
1639
-
1640
- // Set execution time
1641
- $this->set_time_limit( 30 );
1642
-
1643
- $val = get_comment_meta( $comment->comment_ID, "title", true );
1644
- $title = $val ? $val : '';
1645
-
1646
- $val = get_comment_meta( $comment->comment_ID, "thumb_ids", true );
1647
- $thumb_ids = $val ? $val : array();
1648
-
1649
- $val = get_comment_meta( $comment->comment_ID, "rating", true );
1650
- $rating = $val ? $val : 0;
1651
-
1652
- // Import previous settings for "stop reply" from the comment
1653
- $val = get_comment_meta( $comment->comment_ID, "no_reply", true );
1654
- $no_reply = $val ? $val : 0;
1655
-
1656
- // Import previous settings for "votes" from the comment
1657
- $val = get_comment_meta( $comment->comment_ID, "votes", true );
1658
- $votes = $val ? $val : array();
1659
-
1660
- // Extract upvotes and downvotes count
1661
- $votes_grouped = array_count_values( array_values( $votes ) );
1662
- $yes_votes = isset( $votes_grouped['1'] ) && is_numeric( $votes_grouped['1'] ) ? $votes_grouped['1'] : 0;
1663
- $no_votes = isset( $votes_grouped['-1'] ) && is_numeric( $votes_grouped['-1'] ) ? $votes_grouped['-1'] : 0;
1664
-
1665
- // Create post object
1666
- $args = array(
1667
- 'post_author' => $comment->user_id,
1668
- 'post_date' => $comment->comment_date,
1669
- 'post_date_gmt' => $comment->comment_date_gmt,
1670
- 'post_content' => $comment->comment_content,
1671
- 'post_title' => $title,
1672
- 'review_user_id' => $comment->user_id,
1673
- 'review_approved' => $comment->comment_approved,
1674
- 'review_product_id' => $comment->comment_post_ID,
1675
- 'review_thumbnails' => $thumb_ids,
1676
- 'review_comment_id' => $comment->comment_ID,
1677
- 'review_rating' => $rating,
1678
- 'review_is_reply_blocked' => $no_reply,
1679
- 'review_votes' => $votes,
1680
- 'review_upvotes' => $yes_votes,
1681
- 'review_downvotes' => $no_votes,
1682
- 'review_author' => $comment->comment_author,
1683
- 'review_author_email' => $comment->comment_author_email,
1684
- 'review_author_url' => $comment->comment_author_url,
1685
- 'review_author_IP' => $comment->comment_author_IP
1686
- );
1687
-
1688
- // Insert the post into the database
1689
- $review_id = $this->insert_review( $args );
1690
-
1691
- $review_ids[ $comment->comment_ID ] = $review_id;
1692
-
1693
- // If current comment have parent, store it and update all relationship when the import ends
1694
- if ( $comment->comment_parent > 0 ) {
1695
- $parent_review[ $review_id ] = $comment->comment_parent;
1696
- }
1697
-
1698
- // set current comment as imported
1699
- update_comment_meta( $comment->comment_ID, $this->meta_key_imported, 1 );
1700
- $review_converted ++;
1701
- }
1702
-
1703
- // if some hierarchical comment was found, update the review created
1704
- foreach ( $parent_review as $key => $value ) {
1705
- if ( isset( $review_ids[ $value ] ) ) {
1706
-
1707
- //update the post which id is in $key, setting parent to $review_ids[$value]
1708
- $args = array(
1709
- 'ID' => $key,
1710
- 'post_parent' => $review_ids[ $value ]
1711
- );
1712
-
1713
- // Update the post into the database
1714
- wp_update_post( $args );
1715
- }
1716
- }
1717
-
1718
- return $review_converted;
1719
- }
1720
-
1721
- /**
1722
- * On plugin init check query vars for commands to convert previous reviews
1723
- */
1724
- function check_import_actions() {
1725
- if ( isset( $_GET["convert-reviews"] ) ) {
1726
-
1727
- $this->import_previous_reviews();
1728
-
1729
- wp_redirect( esc_url( remove_query_arg( "convert-reviews" ) ) );
1730
- }
1731
- }
1732
- //endregion
1733
- }
1734
  }
1
  <?php
2
+ if (!defined('ABSPATH')) {
3
+ exit; // Exit if accessed directly
4
  }
5
 
6
+ if (!class_exists('YITH_WooCommerce_Advanced_Reviews')) {
7
+
8
+ /**
9
+ * Implements features of FREE version of YWAR plugin
10
+ *
11
+ * @class YITH_WooCommerce_Advanced_Reviews
12
+ * @package Yithemes
13
+ * @since 1.0.0
14
+ * @author Your Inspiration Themes
15
+ */
16
+ class YITH_WooCommerce_Advanced_Reviews {
17
+ /**
18
+ * @var $_panel Panel Object
19
+ */
20
+ protected $_panel;
21
+
22
+ /**
23
+ * @var $_premium string Premium tab template file name
24
+ */
25
+ protected $_premium = 'premium.php';
26
+
27
+ /**
28
+ * @var string Premium version landing link
29
+ */
30
+ protected $_premium_landing = 'http://yithemes.com/themes/plugins/yith-woocommerce-advanced-reviews/';
31
+
32
+ /**
33
+ * @var string Plugin official documentation
34
+ */
35
+ protected $_official_documentation = 'http://yithemes.com/docs-plugins/yith-woocommerce-advanced-reviews/';
36
+
37
+ /**
38
+ * @var string Advanced Reviews panel page
39
+ */
40
+ protected $_panel_page = 'yith_ywar_panel';
41
+
42
+ /**
43
+ * @var $enable_title Let users to add a title when writing a review
44
+ */
45
+ protected $enable_title = 0;
46
+
47
+ /**
48
+ * @var $enable_attachments Let users to add attachments when submit a review
49
+ */
50
+ protected $enable_attachments = 0;
51
+
52
+ /**
53
+ * @var $attachments_limit Set the maximum number of attachments a users can add when submit a review
54
+ */
55
+ protected $attachments_limit = 0;
56
+
57
+ public $post_type_name = "ywar_reviews";
58
+
59
+ public $items_for_page = 10;
60
+
61
+ public $meta_key_rating = "_ywar_rating";
62
+ public $meta_key_product_id = "_ywar_product_id";
63
+ public $meta_key_imported = "_ywar_imported";
64
+ public $meta_key_approved = "_ywar_approved";
65
+ public $meta_key_thumb_ids = "_ywar_thumb_ids";
66
+ public $meta_key_comment_id = "_ywar_comment_id";
67
+
68
+ /**
69
+ * @var string meta_key used for saving data about segnalation of inappropriate content from users
70
+ */
71
+ public $meta_key_inappropriate_list = "_ywar_inappropriate_list";
72
+
73
+ /**
74
+ * @var string meta_key used for saving data about inappropriate reviews
75
+ */
76
+ public $meta_key_inappropriate_count = "_ywar_inappropriate_count";
77
+
78
+ /**
79
+ * @var string meta_key used for saving data about inappropriate reviews
80
+ */
81
+ public $meta_key_featured = "_ywar_featured";
82
+
83
+ /**
84
+ * @var string meta_key used for saving data about upvotes
85
+ */
86
+ public $meta_key_upvotes_count = "_ywar_upvotes_count";
87
+
88
+ /**
89
+ * @var string meta_key used for saving data about downvotes
90
+ */
91
+ public $meta_key_downvotes_count = "_ywar_downvotes_count";
92
+
93
+ /**
94
+ * @var string meta_key used for saving data about reviews votes
95
+ */
96
+ public $meta_key_votes = "_ywar_votes";
97
+
98
+ /**
99
+ * @var string meta_key used for saving data about replies status
100
+ */
101
+ public $meta_key_stop_reply = "_ywar_stop_reply";
102
+
103
+ /**
104
+ * @var string meta_key used for saving review's user id
105
+ */
106
+ public $meta_key_review_user_id = "_ywar_review_user_id";
107
+
108
+ /**
109
+ * @var string meta_key used for saving review's author
110
+ */
111
+ public $meta_key_review_author = "_ywar_review_author";
112
+
113
+ /**
114
+ * @var string meta_key used for saving review author's email
115
+ */
116
+ public $meta_key_review_author_email = "_ywar_review_author_email";
117
+
118
+ /**
119
+ * @var string meta_key used for saving review author's url
120
+ */
121
+ public $meta_key_review_author_url = "_ywar_review_author_url";
122
+
123
+ /**
124
+ * @var string meta_key used for saving review author's IP
125
+ */
126
+ public $meta_key_review_author_IP = "_ywar_review_author_IP";
127
+
128
+ public $custom_column_review = "review-text";
129
 
130
+ public $custom_column_rating = "review-rating";
131
 
132
+ public $custom_column_date = "review-date";
133
 
134
+ public $custom_column_author = "review-author";
135
 
136
+ public $custom_column_product = "product";
137
 
138
+ /**
139
+ * @var string action name for "approve" review
140
+ */
141
+ protected $approve_review_action = "approve-review";
142
 
143
+ /**
144
+ * @var string action name for "untrash" review
145
+ */
146
+ protected $untrash_review_action = "untrash";
147
 
148
+ /**
149
+ * @var string action name for "unapprove" review
150
+ */
151
+ protected $unapprove_review_action = "unapprove-review";
152
 
153
+ /**
154
+ * Single instance of the class
155
+ *
156
+ * @since 1.0.0
157
+ */
158
+ protected static $instance;
159
 
160
+ /**
161
+ * Returns single instance of the class
162
+ *
163
+ * @since 1.0.0
164
+ */
165
+ public static function get_instance() {
166
+ if (is_null(self::$instance)) {
167
+ self::$instance = new self();
168
+ }
169
 
170
+ return self::$instance;
171
+ }
172
 
173
+ /**
174
+ * Constructor
175
+ *
176
+ * Initialize plugin and registers actions and filters to be used
177
+ *
178
+ * @since 1.0
179
+ * @author Lorenzo Giuffrida
180
+ */
181
+ protected function __construct() {
182
+ if (!function_exists('WC')) {
183
+ return;
184
+ }
185
 
186
+ add_action('admin_menu', array($this, 'add_menu_item'));
187
 
188
+ add_action('init', array($this, 'initialize_settings'));
189
 
190
+ //region ******* YIT Plugin Framework *********
191
 
192
+ // Load Plugin Framework
193
+ add_action('after_setup_theme', array($this, 'plugin_fw_loader'), 1);
194
 
195
 
196
+ // Add row meta
197
+ add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 4);
198
 
199
+ // Add stylesheets and scripts files
200
+ add_action('admin_menu', array($this, 'register_panel'), 5);
201
 
202
+ // register plugin pointer
203
+ add_action('admin_init', array($this, 'register_pointer'));
204
 
205
+ // verify import reviews action request
206
+ add_action("admin_init", array($this, "check_import_actions"));
207
 
208
 
209
+ //Add action links
210
+ add_filter('plugin_action_links_' . plugin_basename(YITH_YWAR_DIR . '/' . basename(YITH_YWAR_FILE)), array(
211
+ $this,
212
+ 'action_links'
213
+ ));
214
 
215
+ add_action('yith_advanced_reviews_premium', array($this, 'premium_tab'));
216
 
217
+ //endregion
218
 
219
+ //region *********** Add stylesheets and scripts files ************
220
 
221
+ add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
222
+ add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
223
+ add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles_scripts'));
224
 
225
+ //endregion
226
 
227
+ //region *********** Advanced reviews post type functionalities
228
 
229
+ add_action('init', array($this, 'register_post_type'));
230
 
231
 
232
+ //endregion
233
 
234
+ //region *********** Review table
235
 
236
+ add_filter('yith_advanced_reviews_row_actions', array($this, 'add_review_actions'), 10, 2);
237
 
238
+ add_filter('post_class', array($this, 'add_review_table_class'), 10, 3);
239
 
240
+ /**
241
+ * intercept approve and unapprove actions
242
+ */
243
+ add_action("admin_action_{$this->approve_review_action}", array($this, 'update_review_attributes'));
244
+ add_action("admin_action_{$this->unapprove_review_action}", array($this, 'update_review_attributes'));
245
+ add_action("admin_action_{$this->untrash_review_action}", array($this, 'update_review_attributes'));
246
 
247
+ //endregion ******************************************
248
 
249
+ // Load reviews template
250
+ add_filter('comments_template', array(
251
+ $this,
252
+ 'show_advanced_reviews_template'
253
+ ), 99);
254
 
255
+ // Save additional comment fields on comment submit
256
+ add_action('comment_post', array($this, 'submit_review'));
257
 
258
+ // redirect to product page on comment submitted
259
+ add_filter('comment_post_redirect', array($this, 'redirect_after_submit_review'), 10, 2);
260
 
261
+ add_filter('woocommerce_product_review_comment_form_args', array(
262
+ $this,
263
+ 'add_fields_to_comment_form'
264
+ ));
265
 
266
+ // Add custom fields "Title" on top of comment form
267
+ add_action('comment_form_logged_in_after', array($this, 'add_custom_fields_on_comment_form'));
268
+ add_action('comment_form_after_fields', array($this, 'add_custom_fields_on_comment_form'));
269
 
270
+ add_filter('yith_advanced_reviews_review_content', array($this, 'show_expanded_review_content'));
271
 
272
+ add_filter('woocommerce_product_tabs', array($this, 'update_tab_reviews_count'), 20);
273
 
274
+ /**
275
+ * Add summary bars for product rating
276
+ */
277
+ add_action('yith_advanced_reviews_before_reviews', array($this, 'load_reviews_summary'));
278
 
279
+ // Show details with average rating for the current product
280
+ add_action('ywar_summary_prepend', array($this, 'add_reviews_average_info'));
281
 
282
+ add_filter('wc_get_template', array($this, 'wc_get_template'), 99, 5);
283
 
284
+ add_filter('woocommerce_product_get_rating_html', array($this, 'get_product_rating_html'), 99, 2);
285
 
286
+ //region ***************** Show, edit and save back-end review metabox
287
+ // Add a new metabox for editing and saving title comment in meta_comment table
288
+ add_action('add_meta_boxes', array($this, 'add_plugin_metabox'), 1);
289
 
290
+ // save the custom fields
291
+ add_action('save_post', array($this, 'save_plugin_metabox'), 1, 2);
292
 
293
+ add_action('admin_menu', array($this, 'remove_unwanted_custom_post_type_features'), 5);
294
+ add_action('admin_head', array($this, 'hide_unwanted_custom_post_type_features'));
295
+ //endregion
296
 
297
+ add_action('woocommerce_admin_field_ywar_import_previous_reviews', array(
298
+ $this,
299
+ 'show_import_reviews_button'
300
+ ), 10, 1);
301
 
302
+ add_action('wp_ajax_convert_reviews', array($this, 'convert_reviews_callback'));
303
+ }
304
 
305
+ /**
306
+ * Add the Commissions menu item in dashboard menu
307
+ *
308
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
309
+ * @since 1.0
310
+ * @return void
311
+ * @see wp-admin\includes\plugin.php -> add_menu_page()
312
+ */
313
+ public function add_menu_item() {
314
 
315
+ $args = apply_filters('yith_wc_product_vendors_commissions_menu_items', array(
316
+ 'page_title' => __('Reviews', 'ywar'),
317
+ 'menu_title' => __('Reviews', 'ywar'),
318
+ 'capability' => 'edit_products',
319
+ 'menu_slug' => __('Reviews', 'ywar'),
320
+ 'function' => array($this, 'show_reviews_table'),
321
+ 'icon' => 'dashicons-star-filled',
322
+ 'position' => 8 /* After WC Products */
323
+ )
324
+ );
325
 
326
+ extract($args);
327
 
328
+ add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon, $position);
329
+ }
330
 
331
+ /**
332
+ * Show the reviews table
333
+ *
334
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
335
+ * @since 1.0
336
+ * @return void
337
+ * @fire yith_vendors_commissions_template hooks
338
+ */
339
+ public function show_reviews_table() {
340
+ if (!class_exists('WP_Posts_List_Table')) {
341
+ require_once(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php');
342
+ }
343
+
344
+ require_once(YITH_YWAR_DIR . 'lib/class.yith-advanced-reviews-list-table.php');
345
+
346
+ $product_reviews = new YITH_Advanced_Reviews_List_Table();
347
+ $product_reviews->prepare_items();
348
+
349
+ wc_get_template('ywar-product-reviews-table.php', array('product_reviews' => $product_reviews), YITH_YWAR_TEMPLATES_DIR, YITH_YWAR_TEMPLATES_DIR);
350
+ }
351
+
352
+ /**
353
+ * Intercept review action url and do the requested job
354
+ */
355
+ public function update_review_attributes() {
356
+
357
+ if (!isset($_GET["review_id"])) {
358
+ return;
359
+ }
360
+
361
+ $review_id = $_GET["review_id"];
362
+
363
+ $current_filter = current_filter();
364
+
365
+ switch ($current_filter) {
366
+ case "admin_action_{$this->approve_review_action}" :
367
+ update_post_meta($review_id, $this->meta_key_approved, 1);
368
+
369
+ break;
370
+
371
+ case "admin_action_{$this->unapprove_review_action}" :
372
+ update_post_meta($review_id, $this->meta_key_approved, 0);
373
+
374
+ break;
375
+
376
+ case "admin_action_{$this->untrash_review_action}" :
377
+ $my_post = array(
378
+ 'ID' => $review_id,
379
+ 'post_status' => 'publish'
380
+ );
381
+
382
+ // Update the post into the database
383
+ wp_update_post($my_post);
384
+
385
+ break;
386
+ }
387
+
388
+ wp_redirect(esc_url_raw(remove_query_arg(array('action', 'action2'), $_SERVER['HTTP_REFERER'])));
389
+ }
390
+
391
+ public function add_review_table_class($classes, $class, $post_id) {
392
+
393
+ if ($this->post_type_name != get_post_type($post_id)) {
394
+ return $classes;
395
+ }
396
+
397
+ unset($classes["review-unapproved"]);
398
+ unset($classes["review-approved"]);
399
+
400
+ $approve = get_post_meta($post_id, $this->meta_key_approved, true);
401
+
402
+ if (1 == $approve) {
403
+ $classes[] = "review-approved";
404
+ } elseif (0 == $approve) {
405
+ $classes[] = "review-unapproved";
406
+ }
407
+
408
+ return apply_filters('yith_advanced_reviews_table_class', $classes, $post_id);
409
+ }
410
+
411
+ /**
412
+ * Build a url to be using as action url in row actions
413
+ *
414
+ * @param $action action to be performed
415
+ * @param $post_id review id
416
+ *
417
+ * @return string|void the url used to send an "approve" action for a specific review
418
+ */
419
+ public function review_action_url($action, $post_id) {
420
+ return admin_url("admin.php?action=$action&post_type={$this->post_type_name}&review_id=$post_id");
421
+ }
422
+
423
+ /**
424
+ * Build an "untrash" action url
425
+ *
426
+ * @param $review the review on which the action is performed
427
+ *
428
+ * @return string|void action url
429
+ */
430
+ public function untrash_review_url($review) {
431
+ return $this->review_action_url($this->untrash_review_action, $review->ID);
432
+ }
433
+
434
+ /**
435
+ * Build an "approve" action url
436
+ *
437
+ * @param $review the review on which the action is performed
438
+ *
439
+ * @return string|void action url
440
+ */
441
+ public function approve_review_url($review) {
442
+ return $this->review_action_url($this->approve_review_action, $review->ID);
443
+ }
444
+
445
+ /**
446
+ * Build an "unapprove" action url
447
+ *
448
+ * @param $review the review on which the action is performed
449
+ *
450
+ * @return string|void action url
451
+ */
452
+ public function unapprove_review_url($review) {
453
+ return $this->review_action_url($this->unapprove_review_action, $review->ID);
454
+ }
455
+
456
+ public function add_review_actions($actions, $post) {
457
+
458
+ if ($post->post_type != $this->post_type_name) {
459
+ return $actions;
460
+ }
461
+
462
+ $approved = get_post_meta($post->ID, $this->meta_key_approved, true);
463
+
464
+ unset($actions['view']);
465
+ unset($actions['inline hide-if-no-js']);
466
+
467
+ if (!$approved) {
468
+ $actions['approve-review'] = '<a href="' . $this->approve_review_url($post) . '" title="' . esc_attr(__('Approve review', 'ywar')) . '" rel="permalink">' . __('Approve', 'ywar') . '</a>';
469
+ } elseif ($approved) {
470
+ $actions['unapprove-review'] = '<a href="' . $this->unapprove_review_url($post) . '" title="' . esc_attr(__('Unapprove review', 'ywar')) . '" rel="permalink">' . __('Unapprove', 'ywar') . '</a>';
471
+ }
472
+
473
+ return apply_filters('yith_advanced_reviews_review_actions', $actions, $post);
474
+ }
475
+
476
+ public function get_average_rating($product_id) {
477
+ global $wpdb;
478
+
479
+ $query = $wpdb->prepare("
480
  select avg(meta_value)
481
  from {$wpdb->prefix}postmeta pm
482
  where meta_key = '{$this->meta_key_rating}' and post_id in
483
  (select post_id from {$wpdb->prefix}postmeta where meta_key = '{$this->meta_key_product_id}' and meta_value = %d and post_id IN
484
+ (select post_id from {$wpdb->prefix}postmeta where meta_key = '{$this->meta_key_approved}' and meta_value = 1))", $product_id);
485
 
486
+ $count = $wpdb->get_var($query);
487
 
488
+ return number_format($count, 2);
489
+ }
490
 
491
+ public function add_reviews_average_info($product) {
492
 
493
+ if (get_option('woocommerce_enable_review_rating') === 'no') {
494
+ return;
495
+ }
496
 
497
+ global $product;
498
 
499
+ $average = $this->get_average_rating($product->id);
500
 
501
+ $count = count($this->get_product_reviews_by_rating($product->id));
502
 
503
+ if ($count > 0) {
504
+ echo '<div class="woocommerce-product-rating">
505
+ <div class="star-rating" title="' . sprintf(__('Rated %s out of 5', 'ywar'), $average) . '">
506
+ <span style="width:' . (($average / 5) * 100) . '%"></span>
507
  </div>
508
+ <span class="ywar_review_count">' . sprintf("%d %s", $count, _n(" review", " reviews", $count, 'ywar')) . '</span><span class="review-rating-value"> ' . esc_html($average) . ' ' . __("out of 5 stars", 'ywar') . '</span>
509
  </div>';
510
+ }
511
+ }
512
+
513
+ //region *********** YIT Plugin Framework ****************
514
+
515
+
516
+ /**
517
+ * Enqueue css file
518
+ *
519
+ * @since 1.0
520
+ * @access public
521
+ * @return void
522
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
523
+ */
524
+ public function plugin_fw_loader() {
525
+ if (!defined('YIT') || !defined('YIT_CORE_PLUGIN')) {
526
+ require_once('plugin-fw/yit-plugin.php');
527
+ }
528
+ }
529
+
530
+ /**
531
+ * plugin_row_meta
532
+ *
533
+ * add the action links to plugin admin page
534
+ *
535
+ * @param $plugin_meta
536
+ * @param $plugin_file
537
+ * @param $plugin_data
538
+ * @param $status
539
+ *
540
+ * @return Array
541
+ * @since 1.0
542
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
543
+ * @use plugin_row_meta
544
+ */
545
+ public function plugin_row_meta($plugin_meta, $plugin_file, $plugin_data, $status) {
546
+ if ((defined('YITH_YWAR_INIT') && (YITH_YWAR_INIT == $plugin_file)) ||
547
+ (defined('YITH_YWAR_FREE_INIT') && (YITH_YWAR_FREE_INIT == $plugin_file))
548
+ ) {
549
+ $plugin_meta[] = '<a href="' . $this->_official_documentation . '" target="_blank">' . __('Plugin Documentation', 'ywar') . '</a>';
550
+ }
551
+
552
+ return $plugin_meta;
553
+ }
554
+
555
+ /**
556
+ * Action Links
557
+ *
558
+ * add the action links to plugin admin page
559
+ *
560
+ * @param $links | links plugin array
561
+ *
562
+ * @return mixed Array
563
+ * @since 1.0
564
+ * @author Andrea Grillo <andrea.grillo@yithemes.com>
565
+ * @return mixed
566
+ * @use plugin_action_links_{$plugin_file_name}
567
+ */
568
+ public function action_links($links) {
569
+