Commit 5c855c8d by Cyrille37

filter on CPT #48

parent c4b643ca
......@@ -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'=>'' ],
];
......
......@@ -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 ;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment