| 1 |
<?php |
| 2 |
/** |
| 3 |
* Metaboxes |
| 4 |
* |
| 5 |
* @package wpstream-theme |
| 6 |
*/ |
| 7 |
|
| 8 |
|
| 9 |
add_filter( 'rwmb_meta_boxes', 'wpstream_theme_register_metabox', PHP_INT_MAX ); |
| 10 |
/** |
| 11 |
* Register metabox. |
| 12 |
* Adds theme settings to the post page. |
| 13 |
* |
| 14 |
* @param $meta_boxes |
| 15 |
* @return mixed |
| 16 |
*/ |
| 17 |
function wpstream_theme_register_metabox( $meta_boxes ) { |
| 18 |
$prefix = 'wpstream_theme_'; |
| 19 |
|
| 20 |
$post_types = array( 'post', 'page', 'product', 'wpstream_product', 'wpstream_product_vod', 'wpstream_bundles' ); |
| 21 |
|
| 22 |
$meta_boxes[] = array( |
| 23 |
'title' => esc_html__( 'Hello WPStream settings', 'hello-wpstream' ), |
| 24 |
'id' => 'wpstream-theme-settings', |
| 25 |
'post_types' => $post_types, |
| 26 |
'context' => 'side', |
| 27 |
'priority' => 'low', |
| 28 |
'fields' => array( |
| 29 |
array( |
| 30 |
'name' => esc_html__( 'Show sidebar?', 'hello-wpstream' ), |
| 31 |
'id' => $prefix . 'show_sidebar_on_post', |
| 32 |
'type' => 'select', |
| 33 |
'placeholder' => esc_html__('Use global','hello-wpstream'), |
| 34 |
'options' => array( |
| 35 |
'1' => esc_html__( 'Yes', 'hello-wpstream' ), |
| 36 |
'0' => esc_html__( 'No', 'hello-wpstream' ), |
| 37 |
), |
| 38 |
'desc' => esc_html__( 'Use this option for override global settings.', 'hello-wpstream' ), |
| 39 |
), |
| 40 |
array( |
| 41 |
'name' => esc_html__( 'Use transparent header?', 'hello-wpstream' ), |
| 42 |
'id' => $prefix . 'use_transparent_on_post', |
| 43 |
'type' => 'select', |
| 44 |
'placeholder' => esc_html__('Use global','hello-wpstream'), |
| 45 |
'options' => array( |
| 46 |
'1' => esc_html__( 'Yes', 'hello-wpstream' ), |
| 47 |
'0' => esc_html__( 'No', 'hello-wpstream' ), |
| 48 |
), |
| 49 |
'desc' => esc_html__( 'Use this option for override global settings.', 'hello-wpstream' ), |
| 50 |
), |
| 51 |
), |
| 52 |
); |
| 53 |
|
| 54 |
$meta_boxes[] = array( |
| 55 |
'title' => esc_html__( 'WPStream Page settings', 'hello-wpstream' ), |
| 56 |
'id' => 'wpstream-theme-page-settings', |
| 57 |
'post_types' => array ('page'), |
| 58 |
'context' => 'side', |
| 59 |
'priority' => 'low', |
| 60 |
'fields' => array( |
| 61 |
array( |
| 62 |
'name' => esc_html__( 'Show page title?', 'hello-wpstream' ), |
| 63 |
'id' => $prefix . 'show_page_title', |
| 64 |
'type' => 'select', |
| 65 |
'placeholder' => esc_html__('Use global','hello-wpstream'), |
| 66 |
'options' => array( |
| 67 |
'1' => esc_html__( 'Yes', 'hello-wpstream' ), |
| 68 |
'0' => esc_html__( 'No', 'hello-wpstream' ), |
| 69 |
), |
| 70 |
'desc' => esc_html__( 'Use this option for override global settings.', 'hello-wpstream' ), |
| 71 |
), |
| 72 |
), |
| 73 |
); |
| 74 |
|
| 75 |
return $meta_boxes; |
| 76 |
} |
| 77 |
|
| 78 |
add_filter( 'rwmb_meta_boxes', 'wpstream_metabox_vod_to_channel' ); |
| 79 |
|
| 80 |
/** |
| 81 |
* Define metabox for attaching VOD to Channel. |
| 82 |
* |
| 83 |
* @param array $meta_boxes The array of existing metaboxes. |
| 84 |
* @return array The modified array of metaboxes. |
| 85 |
*/ |
| 86 |
function wpstream_metabox_vod_to_channel( $meta_boxes ) { |
| 87 |
$prefix = 'wpstream_theme_'; |
| 88 |
$meta_boxes[] = array( |
| 89 |
'title' => esc_html__( 'Attach VOD to Channel', 'hello-wpstream' ), |
| 90 |
'post_types' => 'wpstream_product_vod', // Replace with your custom post type slug. |
| 91 |
'fields' => array( |
| 92 |
array( |
| 93 |
'name' => esc_html__( 'Select the channel', 'hello-wpstream' ), |
| 94 |
'id' => $prefix . 'attach_to_channel', |
| 95 |
'type' => 'select', |
| 96 |
'options' => wpstream_get_channels_for_metaboxes(), |
| 97 |
'placeholder' => esc_html__( 'Select the channel', 'hello-wpstream' ), |
| 98 |
), |
| 99 |
), |
| 100 |
); |
| 101 |
|
| 102 |
return $meta_boxes; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Get channels for metaboxes |
| 107 |
*/ |
| 108 |
function wpstream_get_channels_for_metaboxes() { |
| 109 |
if ( class_exists( 'WooCommerce' ) ) { |
| 110 |
$post_type = array( 'product', 'wpstream_product' ); |
| 111 |
$taxonomy_array = array( |
| 112 |
'relation' => 'OR', |
| 113 |
array( |
| 114 |
'taxonomy' => 'product_type', |
| 115 |
'field' => 'slug', |
| 116 |
'terms' => array( 'live_stream' ), |
| 117 |
), |
| 118 |
array( |
| 119 |
'taxonomy' => 'product_type', |
| 120 |
'operator' => 'NOT EXISTS', |
| 121 |
), |
| 122 |
); |
| 123 |
|
| 124 |
} else { |
| 125 |
$post_type = 'wpstream_product'; |
| 126 |
$taxonomy_array = array(); |
| 127 |
} |
| 128 |
|
| 129 |
$args = array( |
| 130 |
'post_type' => $post_type, |
| 131 |
'posts_per_page' => 50, |
| 132 |
'tax_query' => $taxonomy_array, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query |
| 133 |
|
| 134 |
); |
| 135 |
$query_list = new WP_Query( $args ); |
| 136 |
$options = array(); |
| 137 |
|
| 138 |
if ( $query_list->have_posts() ) { |
| 139 |
while ( $query_list->have_posts() ) : |
| 140 |
$query_list->the_post(); |
| 141 |
$the_id = get_the_ID(); |
| 142 |
$the_title = get_the_title( $the_id ); |
| 143 |
$post_type = get_post_type( $the_id ); |
| 144 |
$product_type = ''; |
| 145 |
if ( get_post_type( $the_id ) === 'product' ) { |
| 146 |
$product_type = get_post_meta( $the_id, '_product_type', true ); |
| 147 |
} |
| 148 |
|
| 149 |
$options[ intval( $the_id ) ] = esc_html( $the_title ); |
| 150 |
endwhile; |
| 151 |
} |
| 152 |
|
| 153 |
return $options; |
| 154 |
} |
| 155 |
|
| 156 |
add_filter( 'rwmb_meta_boxes', 'wpstream_theme_register_gallery_metabox' ); |
| 157 |
/** |
| 158 |
* Register gallery metabox for specified post types. |
| 159 |
* |
| 160 |
* @param array $meta_boxes The array of existing metaboxes. |
| 161 |
* @return array The modified array of metaboxes. |
| 162 |
*/ |
| 163 |
function wpstream_theme_register_gallery_metabox( $meta_boxes ) { |
| 164 |
$prefix = 'wpstream_theme_'; |
| 165 |
|
| 166 |
$meta_boxes[] = array( |
| 167 |
'title' => esc_html__( 'Gallery Metabox', 'hello-wpstream' ), |
| 168 |
'post_types' => array( 'post', 'wpstream_product', 'wpstream_product_vod', 'wpstream_bundles' ), // Replace with your custom post type slug. |
| 169 |
'fields' => array( |
| 170 |
array( |
| 171 |
'name' => 'Gallery Images', |
| 172 |
'id' => $prefix . 'gallery', |
| 173 |
'type' => 'image_advanced', |
| 174 |
'max_file_uploads' => 20, // Set the maximum number of allowed images. |
| 175 |
), |
| 176 |
), |
| 177 |
); |
| 178 |
|
| 179 |
return $meta_boxes; |
| 180 |
} |
| 181 |
|
| 182 |
add_filter( 'rwmb_meta_boxes', 'wpstream_theme_register_video_trailer_metabox' ); |
| 183 |
/** |
| 184 |
* Register video trailer metabox for specified post types. |
| 185 |
* |
| 186 |
* @param array $meta_boxes The array of existing metaboxes. |
| 187 |
* @return array The modified array of metaboxes. |
| 188 |
*/ |
| 189 |
function wpstream_theme_register_video_trailer_metabox( $meta_boxes ) { |
| 190 |
$prefix = 'wpstream_theme_'; |
| 191 |
|
| 192 |
$meta_boxes[] = array( |
| 193 |
'title' => 'Video Trailer', |
| 194 |
'post_types' => array( 'product', 'post', 'wpstream_product', 'wpstream_product_vod', 'wpstream_bundles' ), // Replace 'product' with the appropriate post type where you want the metabox to appear. |
| 195 |
'fields' => array( |
| 196 |
array( |
| 197 |
'name' => 'Video Trailer', |
| 198 |
'id' => 'video_trailer', |
| 199 |
'type' => 'file_advanced', |
| 200 |
'max_file_uploads' => 1, |
| 201 |
'mime_type' => 'video', // Set the allowed MIME types for videos, e.g., 'video/mp4', 'video/webm', 'video/quicktime', etc. |
| 202 |
'desc' => esc_html__( 'Upload a video trailer for your content. Supported formats: MP4, MOV', 'hello-wpstream' ), |
| 203 |
), |
| 204 |
), |
| 205 |
); |
| 206 |
|
| 207 |
$meta_boxes[] = array( |
| 208 |
'title' => 'Video Preview', |
| 209 |
'post_types' => array( 'product', 'post', 'wpstream_product', 'wpstream_product_vod', 'wpstream_bundles' ), // Replace 'product' with the appropriate post type where you want the metabox to appear. |
| 210 |
'fields' => array( |
| 211 |
array( |
| 212 |
'name' => 'Video Preview', |
| 213 |
'id' => 'video_preview', |
| 214 |
'type' => 'file_advanced', |
| 215 |
'max_file_uploads' => 1, |
| 216 |
'mime_type' => 'video', // Set the allowed MIME types for videos, e.g., 'video/mp4', 'video/webm', 'video/quicktime', etc. |
| 217 |
'desc' => esc_html__( 'Upload a video preview; this plays when a user hovers over the product image in an item list. Maximum resolution: 480x270. Supported formats: MP4, MOV.', 'hello-wpstream' ), |
| 218 |
), |
| 219 |
), |
| 220 |
); |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
$meta_boxes[] = array( |
| 225 |
'title' => 'Logo', |
| 226 |
'post_types' => array( 'product', 'wpstream_product', 'wpstream_product_vod', 'wpstream_bundles' ), // Replace 'product' with the appropriate post type where you want the metabox to appear. |
| 227 |
'fields' => array( |
| 228 |
array( |
| 229 |
'name' => 'Media Logo', |
| 230 |
'id' => 'media_logo', |
| 231 |
'type' => 'single_image', |
| 232 |
'desc' => esc_html__( 'Upload a logo image that will appear on the media header section', 'hello-wpstream' ), |
| 233 |
), |
| 234 |
), |
| 235 |
); |
| 236 |
|
| 237 |
return $meta_boxes; |
| 238 |
} |
| 239 |
|