| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shortcode Twitter |
| 4 |
* |
| 5 |
* @link https://codesupply.co |
| 6 |
* @since 1.0.0 |
| 7 |
* |
| 8 |
* @package PowerKit |
| 9 |
* @subpackage PowerKit/shortcodes |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Twitter Shortcode |
| 14 |
* |
| 15 |
* @param array $atts User defined attributes in shortcode tag. |
| 16 |
* @param string $content Shorcode tag content. |
| 17 |
* @return string Shortcode result HTML. |
| 18 |
*/ |
| 19 |
function powerkit_twitter_shortcode( $atts, $content = '' ) { |
| 20 |
$params = powerkit_shortcode_atts( shortcode_atts( array( |
| 21 |
'title' => esc_html__( 'Twitter Feed', 'powerkit' ), |
| 22 |
'username' => '', |
| 23 |
'number' => 5, |
| 24 |
'template' => 'default', |
| 25 |
'header' => true, |
| 26 |
'button' => true, |
| 27 |
'replies' => false, |
| 28 |
'retweets' => false, |
| 29 |
), $atts ) ); |
| 30 |
|
| 31 |
ob_start(); |
| 32 |
|
| 33 |
powerkit_twitter_get_recent( $params, 'powerkit_twitter_shortcode_cache' ); |
| 34 |
|
| 35 |
return ob_get_clean(); |
| 36 |
} |
| 37 |
add_shortcode( 'powerkit_twitter_feed', 'powerkit_twitter_shortcode' ); |
| 38 |
|
| 39 |
/** |
| 40 |
* Map Twitter Shortcode into the Basic Shortcodes Plugin |
| 41 |
*/ |
| 42 |
if ( function_exists( 'powerkit_basic_shortcodes_register' ) ) : |
| 43 |
|
| 44 |
$shortcode_map = array( |
| 45 |
'name' => 'twitter', |
| 46 |
'title' => esc_html__( 'Twitter Feed', 'powerkit' ), |
| 47 |
'priority' => 100, |
| 48 |
'base' => 'powerkit_twitter_feed', |
| 49 |
'autoregister' => false, |
| 50 |
'fields' => array( |
| 51 |
array( |
| 52 |
'type' => 'input', |
| 53 |
'name' => 'username', |
| 54 |
'label' => esc_html__( 'Twitter user ID', 'powerkit' ), |
| 55 |
), |
| 56 |
array( |
| 57 |
'type' => 'input', |
| 58 |
'name' => 'number', |
| 59 |
'label' => esc_html__( 'Number of tweets to displays', 'powerkit' ), |
| 60 |
'default' => 5, |
| 61 |
), |
| 62 |
array( |
| 63 |
'type' => 'checkbox', |
| 64 |
'name' => 'header', |
| 65 |
'label' => esc_html__( 'Display header', 'powerkit' ), |
| 66 |
'default' => true, |
| 67 |
), |
| 68 |
array( |
| 69 |
'type' => 'checkbox', |
| 70 |
'name' => 'button', |
| 71 |
'label' => esc_html__( 'Display follow button', 'powerkit' ), |
| 72 |
'default' => true, |
| 73 |
), |
| 74 |
array( |
| 75 |
'type' => 'checkbox', |
| 76 |
'name' => 'replies', |
| 77 |
'label' => esc_html__( 'Include replies', 'powerkit' ), |
| 78 |
'default' => false, |
| 79 |
), |
| 80 |
array( |
| 81 |
'type' => 'checkbox', |
| 82 |
'name' => 'retweets', |
| 83 |
'label' => esc_html__( 'Include retweets', 'powerkit' ), |
| 84 |
'default' => false, |
| 85 |
), |
| 86 |
), |
| 87 |
); |
| 88 |
|
| 89 |
$templates = apply_filters( 'powerkit_twitter_templates', array() ); |
| 90 |
|
| 91 |
if ( count( (array) $templates ) > 1 ) { |
| 92 |
$shortcode_map['fields'][] = array( |
| 93 |
'type' => 'select', |
| 94 |
'name' => 'template', |
| 95 |
'label' => esc_html__( 'Template', 'powerkit' ), |
| 96 |
'default' => 'default', |
| 97 |
'options' => powerkit_twitter_get_templates_options(), |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
powerkit_basic_shortcodes_register( $shortcode_map ); |
| 102 |
|
| 103 |
endif; |
| 104 |
|