array( $this, 'render_modula_album' ), 'editor_script' => 'albums-gutenberg', 'editor_style' => 'albums-gutenberg', ) ); } public function generate_js_vars() { wp_localize_script( 'albums-gutenberg', 'modulaAlbumsVars', apply_filters( 'modula_albums_gutenberg_vars', array( 'adminURL' => admin_url(), 'ajaxURL' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'modula_nonce' ), 'gutenbergAlbumsTitle' => esc_html__( 'Modula Albums', 'modula-albums') ) ) ); } public function render_modula_album( $atts ) { if ( ! isset( $atts['id'] ) ) { return; } return do_shortcode( '[modula-album id="' . $atts['id'] . '"]' ); } public function get_album_meta() { $id = $_POST['id']; $nonce = $_POST['nonce']; if ( ! wp_verify_nonce( $nonce, 'modula_nonce' ) ) { wp_send_json_error(); die(); } $galleries = get_post_meta( $id, 'modula-album-galleries', true ); if ( ! is_array( $galleries ) ) { wp_send_json_error(); die(); } foreach ($galleries as $key=>$gallery) : $gallery_id = $galleries[$key]['id']; $gal_images = get_post_meta($gallery_id, 'modula-images', true); $i = 0; if ( 0 != $galleries[ $key ]['cover'] && ! empty( $galleries[ $key ]['cover'] ) ) { $image_obj = wp_get_attachment_image_src($galleries[$key]['cover'], 'large'); $images[$key]['src'] = $image_obj[0]; $images[$key]['width'] = $image_obj[1]; $images[$key]['height'] = $image_obj[2]; } else { foreach ($gal_images as $image) { if ($i < 1) { $image_obj = wp_get_attachment_image_src($image['id'], 'large'); $images[$key]['src'] = $image_obj[0]; $images[$key]['width'] = $image_obj[1]; $images[$key]['height'] = $image_obj[2]; } $i++; } } endforeach; echo json_encode( $images ); die(); } } new Modula_Albums_Gutenberg();