/** * Add metaboxes for an specific Page Template * @since 1.0.0 * @param bool $display To display or not * @param array $meta_box Metabox config array * @return bool Whether to display this metabox on the current page. */ public static function check_page_template($display, $meta_box) { if (!isset($meta_box['show_on']['key']) || 'page-template' !== $meta_box['show_on']['key']) { return $display; } $object_id = cpmb_Meta_Box::get_object_id(); if (!$object_id || cpmb_Meta_Box::get_object_type() !== 'post') { return false; } // Get current template $current_template = get_post_meta($object_id, '_wp_page_template', true); // See if there's a match if ($current_template && in_array($current_template, (array) $meta_box['show_on']['value'])) { return true; } return false; }
public static function file($field, $meta, $object_id, $object_type) { $input_type_url = 'hidden'; if ('url' == $field['allow'] || is_array($field['allow']) && in_array('url', $field['allow'])) { $input_type_url = 'text'; } echo '<input class="cpmb_upload_file" type="' . $input_type_url . '" size="45" id="', $field['id'], '" name="', $field['id'], '" value="', $meta, '" />'; echo '<input class="cpmb_upload_button button" type="button" value="' . __('Add or Upload File', 'cpmb') . '" />'; $_id_name = $field['id'] . '_id'; $_id_meta = get_metadata($object_type, $object_id, $_id_name, !isset($field['multiple']) || !$field['multiple']); // If there is no ID saved yet, try to get it from the url if ($meta && !$_id_meta) { $_id_meta = cpmb_Meta_Box::image_id_from_url(esc_url_raw($meta)); } echo '<input class="cpmb_upload_file_id" type="hidden" id="', $_id_name, '" name="', $_id_name, '" value="', $_id_meta, '" />', self::desc($field['desc'], true), '<div id="', $field['id'], '_status" class="cpmb_media_status">'; if (!empty($meta)) { if (self::is_valid_img_ext($meta)) { echo '<div class="img_status">'; echo '<img style="max-width: 350px; width: 100%; height: auto;" src="', $meta, '" alt="" />'; echo '<p><a href="#" class="cpmb_remove_file_button" rel="', $field['id'], '">' . __('Remove Image', 'cpmb') . '</a></p>'; echo '</div>'; } else { // $file_ext = self::get_file_ext( $meta ); $parts = explode('/', $meta); for ($i = 0; $i < count($parts); ++$i) { $title = $parts[$i]; } echo __('File:', 'cpmb'), ' <strong>', $title, '</strong> (<a href="', $meta, '" target="_blank" rel="external">' . __('Download', 'cpmb') . '</a> / <a href="#" class="cpmb_remove_file_button" rel="', $field['id'], '">' . __('Remove', 'cpmb') . '</a>)'; } } echo '</div>'; }
/** * Sets the object type * @since 1.0.0 * @return string Object type */ public static function set_object_type($object_type) { return self::$object_type = $object_type; }