Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions inc/class-img-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ public static function get_shortcode_ui_args() {
'label' => esc_html__( 'Alt', 'image-shortcake' ),
'attr' => 'alt',
'type' => 'text',
'encode' => true,
'placeholder' => esc_attr__( 'Alt text for the image', 'image-shortcake' ),
'description' => esc_html__( 'Double quotes and HTML tags are not allowed', 'image-shortcake' ),
),

array(
'label' => esc_html__( 'Caption', 'image-shortcake' ),
'attr' => 'caption',
'type' => 'text',
'encode' => true,
'placeholder' => esc_attr__( 'Caption for the image', 'image-shortcake' ),
'description' => esc_html__( 'Double quotes and HTML tags are not allowed', 'image-shortcake' ),
),

array(
Expand Down Expand Up @@ -150,24 +150,30 @@ public static function reversal( $content ) {
*
* @param array $attrs Shortcode attributes. See definitions in
* @function `get_shortcode_ui_args()`
* @param (not used) Inner content argument
* @param string $shortcode_tag
* @return string
*/
public static function callback( $attr ) {

$attr = wp_parse_args( $attr, array(
'attachment' => 0,
'size' => 'full',
'alt' => '',
'classes' => '',
'caption' => '',
'align' => 'alignnone',
'linkto' => '',
) );
public static function callback( $attr, $_null, $shortcode_tag ) {

// Get all registered args; shortcode_atts() needs a whitelist of args
$shortcode_args = static::get_shortcode_ui_args();
$registered_atts = array_fill_keys( wp_list_pluck( $shortcode_args['attrs'], 'attr' ), null );
$args_with_defaults = array_merge( $registered_atts,
array(
'src' => null,
'size' => 'full',
'classes' => '',
'align' => 'alignnone',
)
);

$attr = shortcode_atts( $args_with_defaults, $attr, $shortcode_tag );

/**
* Filter the shortcode attributes before rendering
*
*
* @param
* @param array Shortcode attributes, decoded and merged with defaults.
*/
$attr = apply_filters( 'img_shortcode_attrs', $attr );

Expand Down Expand Up @@ -211,9 +217,9 @@ public static function callback( $attr ) {

// If a link is specified, wrap the image in a link tag
if ( ! empty( $attr['linkto'] ) &&
( in_array( $attr['linkto'], array( 'file', 'attachment' ), true ) ||
( 'custom' === $attr['linkto'] && ! empty( $attr['url'] ) ) ) ) {
$image_html = self::linkify( $image_html, $attr );
( in_array( $attr['linkto'], array( 'file', 'attachment' ), true ) ||
( 'custom' === $attr['linkto'] && ! empty( $attr['url'] ) ) ) ) {
$image_html = self::linkify( $image_html, $attr );
}

/**
Expand Down