post_types = apply_filters( 'ocean_gallery_metabox_post_types', array( 'post', ) ); // Add metabox to corresponding post types foreach( $this->post_types as $key => $val ) { add_action( 'add_meta_boxes_'. $val, array( $this, 'add_meta' ), 20 ); } // Save metabox add_action( 'save_post', array( $this, 'save_meta' ) ); // Load scripts and styles. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); } /** * Adds the gallery metabox * * @since 1.0.0 */ public function add_meta( $post ) { add_meta_box( 'oceanwp-gallery-metabox', __( 'Image Gallery', 'ocean-extra' ), array( $this, 'render' ), $post->post_type, 'normal', 'high' ); } /** * Load scripts and styles * * @since 1.1.1 */ public function enqueue_scripts( $hook ) { // Only needed on these admin screens if ( $hook != 'edit.php' && $hook != 'post.php' && $hook != 'post-new.php' ) { return; } // Get global post global $post; // Return if post is not object if ( ! is_object( $post ) ) { return; } // Return if wrong post type if ( ! in_array( $post->post_type, $this->post_types ) ) { return; } // Enqueue the main script. wp_enqueue_script( 'oceanwp-gallery-js', plugins_url( '/js/gallery-metabox.min.js', __FILE__ ), array( 'jquery' ), '', true ); // Enqueue the main style. wp_enqueue_style( 'oceanwp-gallery-css', plugins_url( '/css/gallery-metabox.min.css', __FILE__ ) ); } /** * Render the gallery metabox * * @since 1.0.0 */ public function render() { global $post; ?>
get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'href' => get_permalink( $attachment->ID ), 'src' => $attachment->guid, 'title' => $attachment->post_title, ); } } /** * Return gallery count * * @since 1.0.0 */ if ( ! function_exists( 'oceanwp_gallery_count' ) ) { function oceanwp_gallery_count() { $ids = oceanwp_get_gallery_ids(); return count( $ids ); } } /** * Check if lightbox is enabled * * @since 1.0.0 */ if ( ! function_exists( 'oceanwp_gallery_is_lightbox_enabled' ) ) { function oceanwp_gallery_is_lightbox_enabled() { if ( 'on' == get_post_meta( get_the_ID(), 'ocean_gallery_link_images', true ) ) { return true; } } }