Skip to content

Instantly share code, notes, and snippets.

@BhargavBhandari90
Created January 23, 2023 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BhargavBhandari90/6f24ddf7f2d7608620b9d42c990a56af to your computer and use it in GitHub Desktop.
Save BhargavBhandari90/6f24ddf7f2d7608620b9d42c990a56af to your computer and use it in GitHub Desktop.
WordPress Image Editor
<?php
add_shortcode( 'post_list', 'bunty_shortcode' );
function bunty_shortcode( $attr ) {
ob_start();
include_once ABSPATH . 'wp-admin/includes/image-edit.php';
wp_image_editor( 26288 ); // change this with attachment ID.
return ob_get_clean();
}
function bwp_script_callback() {
wp_enqueue_style( 'imgareaselect' );
wp_enqueue_script(
'image-edit',
trailingslashit( site_url( 'wp-admin' ) ) . 'js/image-edit.js',
array( 'wp-i18n', 'jquery', 'jquery-ui-core', 'json2', 'imgareaselect', 'wp-a11y', 'wp-ajax-response' )
);
}
add_action( 'wp_enqueue_scripts', 'bwp_script_callback' );
function bwp_head() {
?>
<script>
var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); ?>';
</script>
<?php
}
add_action( 'wp_head', 'bwp_head' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment