PATH:
home
/
letacommog
/
entrepro
/
wp-content
/
themes
/
rehub
/
admin
/
metabox
<?php /** * Post Image Gallery */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * RH_Meta_Box_Post. */ class RH_Meta_Box_Post { /** * Is meta boxes saved once? */ private static $saved_meta_boxes = false; /** * Meta box error messages. */ public static $meta_box_errors = array(); /** * Check if th WooCommerce is active */ public static $wc_is_active = false; /** * Constructor. */ public function __construct() { add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 35 ); add_action( 'save_post', array( $this, 'save_meta_boxes' ), 1, 2 ); add_action( 'rehub_process_post_meta', array( $this, 'save' ), 20, 2 ); self::$wc_is_active = class_exists('WooCommerce'); $def_p_types = rehub_option('rehub_ptype_formeta'); $def_p_types = (!empty($def_p_types)) ? (array)$def_p_types : array('post'); if( self::$wc_is_active ){ $def_p_types[] = 'product'; } foreach ($def_p_types as $def_p_type) { add_action( 'rehub_process_' . $def_p_type . '_meta', array( $this, 'save' ), 20, 2 ); } // Error handling (for showing errors from meta boxes on next page load) add_action( 'admin_notices', array( $this, 'output_errors' ) ); add_action( 'shutdown', array( $this, 'save_errors' ) ); } /** * Add an error message. * @param string $text */ public static function add_error( $text ) { self::$meta_box_errors[] = $text; } /** * Save errors to an option. */ public function save_errors() { update_option( 'rehub_meta_box_errors', self::$meta_box_errors ); } /** * Show any stored error messages. */ public function output_errors() { $errors = maybe_unserialize( get_option( 'rehub_meta_box_errors' ) ); if ( ! empty( $errors ) ) { echo '<div id="rehub_errors" class="error notice is-dismissible">'; foreach ( $errors as $error ) { echo '<p>' . wp_kses_post( $error ) . '</p>'; } echo '</div>'; // Clear delete_option( 'rehub_meta_box_errors' ); } } /** * Add Meta boxes. */ public function add_meta_boxes() { $def_p_types = rehub_option('rehub_ptype_formeta'); $def_p_types = (!empty($def_p_types)) ? (array)$def_p_types : array('post'); if( !in_array( 'product', $def_p_types ) ){ add_meta_box( 'rehub-post-images', __( "Post Thumbnails and video", "rehub_framework" ), array( $this, 'output' ), $def_p_types, 'side', 'low' ); } if( self::$wc_is_active ){ add_meta_box( 'rh-wc-product-video', __( "Product video", "rehub_framework" ), array($this, 'wc_output'), 'product', 'side', 'low' ); } } /** * Check if we're saving, the trigger an action based on the post type. */ public function save_meta_boxes( $post_id, $post ) { // $post_id and $post are required if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { return; } // Dont' save meta boxes for revisions or autosaves if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { return; } // Check the nonce if ( empty( $_POST['rehub_meta_nonce'] ) || !wp_verify_nonce( $_POST['rehub_meta_nonce'], 'rehub_save_data' ) ) { return; } // Check the post being saved == the $post_id to prevent triggering this call for other save_post events if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) { return; } // Check user has permission to edit if ( !current_user_can( 'edit_post', $post_id ) ) { return; } self::$saved_meta_boxes = true; // Check the post type $def_p_types = rehub_option('rehub_ptype_formeta'); $def_p_types = (!empty($def_p_types)) ? (array)$def_p_types : array('post'); if( self::$wc_is_active ){ $def_p_types[] = 'product'; } if ( in_array( $post->post_type, $def_p_types ) ) { do_action( 'rehub_process_' . $post->post_type . '_meta', $post_id, $post ); } } /** * Output the metabox. * * @param WP_Post $post */ public static function output( $post ) { ?> <div id="rh_post_images_container"> <ul class="rh_post_images"> <?php if ( metadata_exists( 'post', $post->ID, 'rh_post_image_gallery' ) ) { $post_image_gallery = get_post_meta( $post->ID, 'rh_post_image_gallery', true ); } else { // Backwards compat $attachment_ids = get_posts( 'post_parent=' . $post->ID . '&numberposts=-1&post_type=attachment&orderby=menu_order&order=ASC&post_mime_type=image&fields=ids&meta_value=0' ); $attachment_ids = array_diff( $attachment_ids, array( get_post_thumbnail_id() ) ); $post_image_gallery = implode( ',', $attachment_ids ); } $attachments = array_filter( explode( ',', $post_image_gallery ) ); $update_meta = false; $updated_gallery_ids = array(); if ( ! empty( $attachments ) ) { foreach ( $attachments as $attachment_id ) { $attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' ); // if attachment is empty skip if ( empty( $attachment ) ) { $update_meta = true; continue; } echo '<li class="image" data-attachment_id="' . esc_attr( $attachment_id ) . '"> ' . $attachment . ' <ul class="actions"> <li><a href="#" class="delete tips" data-tip="' . esc_attr__( "Delete image", "rehub_framework" ) . '">' . __( "Delete", "rehub_framework" ) . '</a></li> </ul> </li>'; // rebuild ids to be saved $updated_gallery_ids[] = $attachment_id; } // need to update post meta to set new gallery ids if ( $update_meta ) { update_post_meta( $post->ID, 'rh_post_image_gallery', implode( ',', $updated_gallery_ids ) ); } } ?> </ul> <input type="hidden" id="rh_post_image_gallery" name="rh_post_image_gallery" value="<?php echo esc_attr( $post_image_gallery ); ?>" /> <?php wp_nonce_field( 'rehub_save_data', 'rehub_meta_nonce' ); ?> </div> <p class="rh_add_post_images hide-if-no-js"> <a href="#" data-choose="<?php esc_attr_e( "Add Images to Post Gallery", "rehub_framework" ); ?>" data-update="<?php esc_attr_e( "Add to gallery", "rehub_framework" ); ?>" data-delete="<?php esc_attr_e( "Delete image", "rehub_framework" ); ?>" data-text="<?php esc_attr_e( "Delete", "rehub_framework" ); ?>"><?php _e( "Add post gallery images", "rehub_framework" ); ?></a> </p> <p class="rh_add_post_images hide-if-no-js"> <small><?php _e('Add video links, each link from new line. Youtube and vimeo are supported', 'rehub_framework');?></small> <textarea id="rh_post_image_videos" rows="3" name="rh_post_image_videos"><?php echo get_post_meta( $post->ID, 'rh_post_image_videos', true );?></textarea> </p> <p class="rh_add_post_images hide-if-no-js"><small><?php _e('Some post layouts renders gallery thumbnails automatically. Also, you can add them to post with shortcode [rh_get_post_thumbnails video=1 height=200 justify=1]. video=1 - include also video. Height is maximum height, justify=1 is parameter to show pretty justify gallery. [rh_get_post_videos] will show only videos in full size column', 'rehub_framework');?></small></p> <?php } /** * Output the product metabox. * * @param WP_Post $post */ public static function wc_output( $post ){ global $thepostid; $thepostid = $post->ID; $rh_video_url = get_post_meta( $thepostid, 'rh_product_video', true ); wp_nonce_field( 'rehub_save_data', 'rehub_meta_nonce' ); ?> <div id="product_video_container" class="hide-if-no-js"> <textarea id="rh_product_video" rows="3" name="rh_product_video"><?php echo get_post_meta( $post->ID, 'rh_product_video', true );?></textarea> <p class="howto"><?php _e('Add video links, each link from new line. Youtube and vimeo are supported', 'rehub_framework'); ?></p> </div> <?php } /** * Save meta box data. */ public static function save( $post_id, $post ) { if( !empty($_POST['rh_post_image_gallery']) && !is_array($_POST['rh_post_image_gallery'])){ $attachment_ids = sanitize_text_field( $_POST['rh_post_image_gallery']); $attachment_ids = explode(",", $attachment_ids); $attachment_ids = array_filter($attachment_ids); $attachment_ids = implode(',', $attachment_ids); update_post_meta( $post_id, 'rh_post_image_gallery', $attachment_ids ); }elseif(isset($_POST['rh_post_image_gallery'])){ delete_post_meta( $post_id, 'rh_post_image_gallery' ); } $meta_key = ''; if( self::$wc_is_active && isset($_POST['rh_product_video']) ){ $meta_key = 'rh_product_video'; }else if( isset($_POST['rh_post_image_videos']) ){ $meta_key = 'rh_post_image_videos'; } if( !empty( $meta_key ) ){ $oldvideo = get_post_meta($post_id, $meta_key, true); $newvideo = esc_html($_POST[$meta_key]); if (!empty($newvideo) && $newvideo != $oldvideo) { update_post_meta($post_id, $meta_key, $newvideo); } elseif ('' == $newvideo && $oldvideo) { delete_post_meta($post_id, $meta_key, $oldvideo); } } } } new RH_Meta_Box_Post();
[+]
..
[-] page_toptable.php
[edit]
[-] visual_builder.php
[edit]
[-] aff_links.php
[edit]
[-] page_review.php
[edit]
[-] catalogue_constructor.php
[edit]
[-] woo_review.php
[edit]
[-] offermeta.php
[edit]
[-] post_type_side.php
[edit]
[-] multioffermeta.php
[edit]
[-] post_type.php
[edit]
[-] class-rh-meta-box.php
[edit]
[-] page_meta.php
[edit]
[-] page_topchart.php
[edit]