/**
  * Clean up provided shortcode values
  *
  * @since 1.3.0
  *
  * @param array $attributes provided shortcode attributes {
  *   @type string shortcode attribute name
  *   @type mixed  shortcode attribute value
  * }
  *
  * @return array simplified shortcode values with defaults removed {
  *   @type string      shortcode attribute name
  *   @type bool|string shortcode attribute value
  * }
  */
 public static function sanitizeShortcodeParameters($attributes = array())
 {
     if (!is_array($attributes)) {
         return array();
     }
     $options = array();
     if (isset($attributes['username'])) {
         $username = \Twitter\Helpers\Validators\PeriscopeUsername::trim($attributes['username']);
         if ($username) {
             $options['username'] = $username;
         }
         unset($username);
     }
     // large is the only option
     if (isset($attributes['size'])) {
         if (is_string($attributes['size']) && in_array(strtolower($attributes['size']), array('large', 'l'))) {
             $options['size'] = 'large';
         }
     }
     return $options;
 }
Exemple #2
0
 /**
  * Require username
  *
  * @since 1.3.0
  */
 public function __construct($username, $validate = true)
 {
     $username = \Twitter\Helpers\Validators\PeriscopeUsername::trim($username);
     if (false === $validate || \Twitter\Helpers\Validators\PeriscopeUsername::isValid($username)) {
         $this->username = $username;
     }
 }
Exemple #3
0
 /**
  * Clean up user inputted Periscope username value before saving the option
  *
  * @since 1.3.0
  *
  * @param string $username inputted Periscope username value
  *
  * @return string sanitized Periscope username value
  */
 public static function sanitize($username)
 {
     if (!is_string($username)) {
         return '';
     }
     $username = trim($username);
     if (!$username) {
         return '';
     }
     $username = sanitize_text_field($username);
     if (!$username) {
         return '';
     }
     return \Twitter\Helpers\Validators\PeriscopeUsername::sanitize($username);
 }