[wp-hackers] Extensibility and shortcodes
Luke Bryan
lukebryan at sharefaith.com
Wed Aug 27 07:10:05 UTC 2014
Greetings all,
I was looking at the wp media shortcode and wp-views, and noticed a few
things that seem not-too-portable in the view ajax and rendering:
In ajax-actions.php of Wordpress 4.0 we see this render-and-return routine
requiring a post_id of post the user can edit:
function wp_ajax_parse_media_shortcode() {
global $post, $wp_scripts;
if ( ! $post = get_post( (int) $_REQUEST['post_ID'] ) ) {
wp_send_json_error();
}
if ( empty( $_POST['shortcode'] ) || ! current_user_can( 'edit_post',
$post->ID ) ) {
wp_send_json_error();
}
setup_postdata( $post );
$shortcode = do_shortcode( wp_unslash( $_REQUEST['shortcode'] ) );
if ( empty( $shortcode ) ) {
wp_send_json_error( array(
'type' => 'no-items',
'message' => __( 'No items found.' ),
) );
}
$head = '';
$styles = wpview_media_sandbox_styles();
foreach ( $styles as $style ) {
$head .= '<link type="text/css" rel="stylesheet" href="' . $style .
'">';
}
if ( ! empty( $wp_scripts ) ) {
$wp_scripts->done = array();
}
ob_start();
echo $shortcode;
if ( 'playlist' === $_REQUEST['type'] ) {
wp_underscore_playlist_templates();
wp_print_scripts( 'wp-playlist' );
} else {
wp_print_scripts( 'wp-mediaelement' );
}
wp_send_json_success( array(
'head' => $head,
'body' => ob_get_clean()
) );
}
Why must this ajax call tie to the post-id of the post page containing the
shortcode to be rendered? Is it meant to soon have "symbolically-linked"
galleries and shortcodes that are linked to multiple post-ids, not just
embedded as shortcode in post_content? Or is there another reason for
requiring a post-id of a post the user can edit, not just "0", when
rendering playlist views?
I also noticed the Javascript mce object functions calling that ajax
action were hardcoded to look for an element with a certain id, #post_ID.
(in wp-includes/js/media-views.js, wp-includes/js/mce-view.js). While it
works well for the wp-admin pages as given by Wordpress, it seems it could
use a more generic item, like a property in whatever the current tinymce
editor is? What do you think?
Glad to see there is good progress in wp 4.0
Best regards,
Luke
More information about the wp-hackers
mailing list