Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CommunityVoice
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
10
Issues
10
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Artefacts
CommunityVoice
Commits
5c855c8d
Commit
5c855c8d
authored
Sep 18, 2017
by
Cyrille37
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
filter on CPT
#48
parent
c4b643ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
13 deletions
+52
-13
Settings.php
wp-content/plugins/CommunityVoice/Settings.php
+3
-1
Vote_UI.php
wp-content/plugins/CommunityVoice/Vote_UI.php
+49
-12
No files found.
wp-content/plugins/CommunityVoice/Settings.php
View file @
5c855c8d
...
...
@@ -8,13 +8,15 @@
class
Settings
{
const
SETTING_NAME
=
'CommunityVoice_settings'
;
const
SETTING_CPT_ONLY
=
'CPT_only'
;
private
$settings
;
private
$settingsList
;
function
__construct
()
{
$this
->
settingsList
=
[
[
'id'
=>
'CPT_only'
,
'label'
=>
'Custom post type only : '
,
'type'
=>
'text'
,
'description'
=>
'Vote actif seulement pour les articles de ce type.'
],
[
'id'
=>
self
::
SETTING_CPT_ONLY
,
'label'
=>
'Custom post type only : '
,
'type'
=>
'text'
,
'description'
=>
'Vote actif seulement pour les articles de ce type.'
],
[
'id'
=>
'activate_negative_vote'
,
'label'
=>
'Activate negative vote : '
,
'type'
=>
'checkbox'
,
'description'
=>
'Activer les votes négatifs.'
],
[
'id'
=>
'automatically_display_vote'
,
'label'
=>
'Automatically display vote : '
,
'type'
=>
'checkbox'
,
'description'
=>
''
],
];
...
...
wp-content/plugins/CommunityVoice/Vote_UI.php
View file @
5c855c8d
...
...
@@ -16,15 +16,40 @@ class Vote_UI
}
add_shortcode
(
"comment_nbr"
,
array
(
$this
,
"get_comment_nbr"
)
);
add_shortcode
(
"positive_vote_nbr"
,
array
(
$this
,
"get_positive_vote_nbr"
)
);
add_shortcode
(
"negative_vote_nbr"
,
array
(
$this
,
"get_negative_vote_nbr"
)
);
add_shortcode
(
"positive_vote_btn"
,
array
(
$this
,
"display_positive_vote_btn"
)
);
add_shortcode
(
"negative_vote_btn"
,
array
(
$this
,
"display_negative_vote_btn"
)
);
}
/**
* Should display ot not display the Vote UI ?
* @return boolean
*/
protected
function
shouldDisplayVoteUI
()
{
$cpt_only
=
CommunityVoice
::
$Settings
->
getSetting
(
\Settings
::
SETTING_CPT_ONLY
);
if
(
empty
(
$cpt_only
)
)
return
true
;
$currentPost
=
get_post
();
if
(
!
empty
(
$currentPost
)
)
{
if
(
$currentPost
->
post_type
==
$cpt_only
)
return
true
;
}
return
false
;
}
function
display_negative_vote_btn
(
$atts
=
[]
)
{
if
(
!
is_user_logged_in
()
)
if
(
!
$this
->
shouldDisplayVoteUI
()
)
return
''
;
if
(
!
is_user_logged_in
()
)
return
"Vous devez être connecté pour voter."
;
$id
=
get_post
()
->
ID
;
...
...
@@ -43,7 +68,10 @@ class Vote_UI
function
display_positive_vote_btn
(
$atts
=
[]
)
{
if
(
!
is_user_logged_in
()
)
if
(
!
$this
->
shouldDisplayVoteUI
()
)
return
''
;
if
(
!
is_user_logged_in
()
)
return
"Vous devez être connecté pour voter."
;
$id
=
get_post
()
->
ID
;
...
...
@@ -62,7 +90,10 @@ class Vote_UI
function
get_negative_vote_nbr
()
{
$nbVote
=
get_post
()
->
negative_vote
!==
null
?
get_post
()
->
negative_vote
:
0
;
if
(
!
$this
->
shouldDisplayVoteUI
()
)
return
''
;
$nbVote
=
get_post
()
->
negative_vote
!==
null
?
get_post
()
->
negative_vote
:
0
;
return
'<span class="nb_vote_'
.
CommunityVoice_vote
::
MINUS
.
'_'
.
get_post
()
->
ID
.
'">'
.
$nbVote
.
'</span>'
;
...
...
@@ -70,7 +101,10 @@ class Vote_UI
function
get_positive_vote_nbr
()
{
$nbVote
=
get_post
()
->
positive_vote
!==
null
?
get_post
()
->
positive_vote
:
0
;
if
(
!
$this
->
shouldDisplayVoteUI
()
)
return
''
;
$nbVote
=
get_post
()
->
positive_vote
!==
null
?
get_post
()
->
positive_vote
:
0
;
return
'<span class="nb_vote_'
.
CommunityVoice_vote
::
PLUS
.
'_'
.
get_post
()
->
ID
.
'">'
.
$nbVote
.
'</span>'
;
...
...
@@ -109,6 +143,9 @@ class Vote_UI
*/
function
display_positive_vote_count
(
$content
)
{
if
(
!
$this
->
shouldDisplayVoteUI
()
)
return
''
;
$post
=
get_post
();
$nbvote
=
$post
->
positive_vote
;
if
(
(
CommunityVoice
::
$Settings
->
getSetting
(
"CPT_only"
)
!==
false
&&
$post
->
post_type
===
CommunityVoice
::
$Settings
->
getSetting
(
"CPT_only"
)
)
||
CommunityVoice
::
$Settings
->
getSetting
(
"CPT_only"
)
===
false
)
...
...
@@ -131,6 +168,9 @@ class Vote_UI
*/
function
display_negative_vote_count
(
$content
)
{
if
(
!
$this
->
shouldDisplayVoteUI
()
)
return
''
;
$post
=
get_post
();
$nbvote
=
$post
->
negative_vote
;
if
(
(
CommunityVoice
::
$Settings
->
getSetting
(
'CPT_only'
)
!==
false
&&
$post
->
post_type
===
CommunityVoice
::
$Settings
->
getSetting
(
"CPT_only"
)
)
||
CommunityVoice
::
$Settings
->
getSetting
(
"CPT_only"
)
===
false
)
...
...
@@ -153,14 +193,11 @@ class Vote_UI
*/
function
display_vote_buttons
(
$content
)
{
$post
=
get_post
();
$id
=
$post
->
ID
;
$cpt_only
=
CommunityVoice
::
$Settings
->
getSetting
(
'CPT_only'
);
if
(
$cpt_only
===
false
||
(
$cpt_only
!==
false
&&
$post
->
post_type
===
$cpt_only
)
)
{
return
$this
->
display_positive_vote_btn
()
.
$this
->
display_negative_vote_btn
()
.
$content
;
}
return
$content
;
if
(
!
$this
->
shouldDisplayVoteUI
()
)
return
''
;
return
$this
->
display_positive_vote_btn
()
.
$this
->
display_negative_vote_btn
()
.
$content
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment