Last active
May 6, 2016 13:24
-
-
Save devudit/7dc95d61887ee72551e87bfa396fd5b4 to your computer and use it in GitHub Desktop.
Add custom tag on post slider of Master Slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* @wordpress-plugin | |
* Plugin Name: Custom Tags For Master Slider | |
* Plugin URI: http://uditrawat.com | |
* Description: Custom Tags For Master Slider | |
* Version: 1.3 | |
* Author: Udit Rawat | |
* Author URI: http://uditrawat.com | |
* Text Domain: emerico | |
*/ | |
class HomeSlider | |
{ | |
/** | |
* Instance of this class. | |
* | |
* @since 1.0.0 | |
* | |
* @var object | |
*/ | |
protected static $instance = null; | |
/** | |
* Return an instance of this class. | |
* | |
* @since 1.0.0 | |
* | |
* @return object A single instance of this class. | |
*/ | |
public static function get_instance() | |
{ | |
// If the single instance hasn't been set, set it now. | |
if (null == self::$instance) { | |
self::$instance = new self; | |
} | |
return self::$instance; | |
} | |
/** | |
* Class constructor | |
* | |
* @since 1.0.0 | |
*/ | |
private function __construct() | |
{ | |
// Add new tag to master slider tag list | |
add_filter('masterslider_post_slider_tags_list', [$this, 'master_slider_add_project_tags'], 10, 1); | |
// Add value of newly added tag | |
add_filter('masterslider_get_template_tag_value', [$this, 'master_slider_tag_values'], 10, 4); | |
} | |
/** | |
* @param $tags | |
* @return array | |
*/ | |
function master_slider_add_project_tags($tags) | |
{ | |
$tags[] = [ | |
'name' => 'project_business_partners', | |
'label' => __('Project Business Partners', 'emerico'), | |
'type' => 'post' // POST_TYPE | |
]; | |
$tags[] = [ | |
'name' => 'project_npo_partners', | |
'label' => __('Project NPO Partners', 'emerico'), | |
'type' => 'post' // POST_TYPE | |
]; | |
$tags[] = [ | |
'name' => 'project_call_to_action', | |
'label' => __('Project Call To Action', 'emerico'), | |
'type' => 'post' // POST_TYPE | |
]; | |
return $tags; | |
} | |
/** | |
* @param $value | |
* @param $tag_name | |
* @param $project | |
* @param $args | |
* @return bool|mixed|null|string|void | |
*/ | |
function master_slider_tag_values($value, $tag_name, $project, $args) | |
{ | |
switch ($tag_name) { | |
case 'project_business_partners': | |
$value = 'Custom value here'; // CUSTOM VALUE FOR TAG HERE | |
break; | |
case 'project_npo_partners': | |
$value = 'Custom value here'; // CUSTOM VALUE FOR TAG HERE | |
break; | |
case 'project_call_to_action': | |
$value = 'Custom value here'; // CUSTOM VALUE FOR TAG HERE | |
break; | |
} | |
return $value; | |
} | |
} | |
if(class_exists('Master_Slider')) | |
add_action( 'plugins_loaded', array( 'HomeSlider', 'get_instance' ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment