Twitter\WordPress\Shortcodes\Follow::sanitizeShortcodeParameters PHP Method

sanitizeShortcodeParameters() public static method

Be liberal in what we accept in shortcode syntax before constructing a Follow button
Since: 1.0.0
public static sanitizeShortcodeParameters ( array $attributes = [] ) : array
$attributes array 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['screen_name'])) {
            $screen_name = \Twitter\Helpers\Validators\ScreenName::trim($attributes['screen_name']);
            if ($screen_name) {
                $options['screen_name'] = $screen_name;
            }
            unset($screen_name);
        }
        foreach (array('show_count', 'show_screen_name') as $falsey_option) {
            // check for falsey values passed to shortcode
            if (isset($attributes[$falsey_option])) {
                if (false === $attributes[$falsey_option] || '0' == $attributes[$falsey_option] || is_string($attributes[$falsey_option]) && in_array(strtolower($attributes[$falsey_option]), array('false', 'no', 'off'))) {
                    $options[$falsey_option] = false;
                }
            }
        }
        // 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

Ejemplo n.º 1
0
 /**
  * Test hiding Twitter screen name through a shortcode attribute value
  *
  * @since 1.0.0
  *
  * @covers ::sanitizeShortcodeParameters
  * @small
  *
  * @dataProvider falseyShortcodeParameterProvider
  *
  * @param bool|int|string $falsey_value falsey value to test
  *
  * @return void
  */
 public function testSanitizeShortcodeParametersShowScreenName($falsey_value)
 {
     $options = \Twitter\WordPress\Shortcodes\Follow::sanitizeShortcodeParameters(array('show_screen_name' => $falsey_value));
     $this->assertTrue(isset($options['show_screen_name']) && false === $options['show_screen_name'], 'Failed to disable screen name display from attribute');
 }