Closed bobbingwide closed 9 years ago
As you said this is currently possible.
Regarding 124 - I think its reasonable idea. However I don't actually think it would affect this issue. I'd say that if you're extending one plugin that adds a shortcode to shortcake - then your plugin should make sure its adding this later.
Why not use apply_filters
and add_filter
to the parameters? Tested it and it works fine.
Why not use apply_filters and add_filter to the parameters? Tested it and it works fine.
Huh? Explain further?
The original post was regarding extending a shortcode's parameters. For example, I did this with the pullquote
demo:
$attrs = array(
array(
'label' => 'Quote',
'attr' => 'content',
'type' => 'textarea',
),
);
$attrs = apply_filters( 'add_more_pullquote_attributes', $attrs );
shortcode_ui_register_for_shortcode(
'pullquote',
array(
// Display label. String. Required.
'label' => 'Pullquote',
// Icon/image for shortcode. Optional. src or dashicons-$icon. Defaults to carrot.
'listItemImage' => 'dashicons-editor-quote',
// Available shortcode attributes and default values. Required. Array.
// Attribute model expects 'attr', 'type' and 'label'
// Supported field types: text, checkbox, textarea, radio, select, email, url, number, and date.
'attrs' => $attrs,
)
);
Then somewhere else:
add_filter( 'add_more_pullquote_attributes', 'my_extension_pullquote_attributes' );
function my_extension_pullquote_attributes( $attrs ) {
$attrs[] =
array(
'label' => 'Cite',
'attr' => 'source',
'type' => 'text',
);
return $attrs;
}
Yes something like this would work.
I think there are a few ways you could approach this. Another would be to use register_shortcode_ui
to register the shortcode again. If you need to get the attributes added previously you could use the get_shortcode
method.
Either way - I think this is the responsibility of your code rather than something to handle in Shortcake - so I'm going to close this ticket.
@mattheu I agree
I have a number of shortcodes in one plugin which are extended by one or more other plugins. The other plugins add new parameters to the shortcode. When only the base plugin is active then the syntax need not reflect the additional parameters. When the extensions are active then these should be shown.
Example: The [bw_telephone] shortcode is extended by the oik-users plugin so that the telephone number displayed is that for a selected user, specified using
user=uid|email|slug|login
Q. Does the current implementation allow a plugin to extend an existing registration of a shortcode? A. Yes, if it uses shortcode_ui_get_register_shortcode() first, it can then update the definition and re-register it.
Q. But how does the extension plugin know the right time to do it? A. Related: #124