Twitter\WordPress\Shortcodes\PeriscopeOnAir::sanitizeShortcodeParameters PHP Méthode

sanitizeShortcodeParameters() public static méthode

Clean up provided shortcode values
Since: 1.3.0
public static sanitizeShortcodeParameters ( array $attributes = [] ) : array
$attributes array provided shortcode attributes { @type string shortcode attribute name @type mixed shortcode attribute value }
Résultat 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;
    }

Usage Example

 /**
  * Test extracting a Periscope username from a shortcode through username attribute
  *
  * @since 1.3.0
  *
  * @covers ::sanitizeShortcodeParameters
  * @small
  *
  * @dataProvider usernameProvider
  *
  * @param string $username Twitter username test value
  *
  * @return void
  */
 public function testSanitizeShortcodeParametersScreenName($username)
 {
     $expected = 'twitter';
     $options = \Twitter\WordPress\Shortcodes\PeriscopeOnAir::sanitizeShortcodeParameters(array('username' => $username));
     $this->assertTrue(isset($options['username']) && $options['username'] === $expected, 'Failed to extract screen name from attribute');
 }