PageRenderTime 25ms CodeModel.GetById 43ms RepoModel.GetById 9ms app.codeStats 0ms

/wp-content/themes/selah2018/jsp_inc/metaboxes.php

https://gitlab.com/code26/selah
PHP | 368 lines | 252 code | 27 blank | 89 comment | 22 complexity | f5725843b812b5c38b8afbe7cc5eea43 MD5 | raw file
  1. <?php
  2. $jsp_slideType = '';
  3. function jsp_register_meta_boxes( $meta_boxes )
  4. {
  5. global $jsp_slideType;
  6. $meta_boxes = array();
  7. $prefix = 'jsp_';
  8. if ( isset( $_GET['post'] ) ) {
  9. $post_id = $_GET['post'];
  10. }
  11. elseif ( isset( $_POST['post_ID'] ) ) {
  12. $post_id = $_POST['post_ID'];
  13. }
  14. else {
  15. $post_id = false;
  16. }
  17. // $meta_boxes[] = array(
  18. // 'title' => __( 'Featured Image', 'rwmb' ),
  19. // 'pages' => array( 'post', 'page' ),
  20. // 'context' => 'side',
  21. // 'priority' => 'low',
  22. // 'fields' => array(
  23. // array(
  24. // 'name' => __( '', 'rwmb' ),
  25. // 'id' => "{$prefix}featuredImg",
  26. // 'type' => 'image_advanced',
  27. // 'max_file_uploads' => 1,
  28. // ),
  29. // )
  30. // );
  31. // $meta_boxes[] = array(
  32. // 'title' => __( 'Thumbnail Image', 'rwmb' ),
  33. // 'pages' => array( 'page' ),
  34. // 'context' => 'side',
  35. // 'priority' => 'low',
  36. // 'only_on' => array(
  37. // 'parent_slug' => array('services')
  38. // ),
  39. // 'fields' => array(
  40. // array(
  41. // 'name' => __( '', 'rwmb' ),
  42. // 'id' => "{$prefix}thumbImg",
  43. // 'type' => 'image_advanced',
  44. // 'max_file_uploads' => 1,
  45. // ),
  46. // )
  47. // );
  48. // $meta_boxes[] = array(
  49. // 'id' => 'hero-image',
  50. // 'title' => 'Hero Image',
  51. // 'pages' => array( 'hero' ),
  52. // 'context' => 'side',
  53. // 'priority' => 'default',
  54. // 'fields' => array(
  55. // array(
  56. // 'name' => __( '', 'rwmb' ),
  57. // 'id' => "{$prefix}plupload_hero",
  58. // 'type' => 'plupload_image',
  59. // 'max_file_uploads' => 1,
  60. // ),
  61. // ),
  62. // /*'only_on' => array(
  63. // 'id' => array( 1, 2 ),
  64. // 'slug' => array( 'news', 'blog' ),
  65. // 'template' => array( 'fullwidth.php', 'simple.php' ),
  66. // 'parent' => array( 10 )
  67. // ),*/
  68. // );
  69. // $cardargs = array(
  70. // 'posts_per_page' => -1,
  71. // 'orderby' => 'post_date',
  72. // 'order' => 'DESC',
  73. // 'post_type' => 'cards',
  74. // 'post_status' => 'publish',
  75. // 'suppress_filters' => true
  76. // );
  77. // $cardsArr = get_posts( $cardargs );
  78. // $cards = '';
  79. // foreach ($cardsArr as $card) {
  80. // $cards["$card->ID"] = $card->post_title;
  81. // }
  82. // $meta_boxes[] = array(
  83. // 'id' => 'cards_list',
  84. // 'title' => 'Cards',
  85. // 'pages' => array( 'promotions', 'rewards' ),
  86. // 'context' => 'side',
  87. // 'priority' => 'default',
  88. // 'fields' => array(
  89. // array(
  90. // 'name' => __( '', 'rwmb' ),
  91. // 'id' => "{$prefix}cards_list",
  92. // 'type' => 'checkbox_list',
  93. // // Options of checkboxes, in format 'value' => 'Label'
  94. // 'options' => $cards
  95. // ),
  96. // ),
  97. // );
  98. $meta_boxes[] = array(
  99. 'id' => 'lineup-date',
  100. 'title' => 'Lineup Date',
  101. 'pages' => array( 'lineups' ),
  102. 'context' => 'normal',
  103. 'priority' => 'high',
  104. 'fields' => array(
  105. array(
  106. 'name' => __( ' ', 'selah' ),
  107. 'id' => $prefix . 'lineup_date',
  108. 'type' => 'date',
  109. // jQuery date picker options. See here http://jqueryui.com/demos/datepicker
  110. 'js_options' => array(
  111. 'appendText' => __( ' (yyyy-mm-dd)', 'selah' ),
  112. 'autoSize' => true,
  113. 'buttonText' => __( 'Select Date', 'selah' ),
  114. 'dateFormat' => __( 'yy-mm-dd', 'selah' ),
  115. 'numberOfMonths' => 1,
  116. 'showButtonPanel' => true,
  117. ),
  118. ),
  119. array(
  120. 'name' => __( '', 'selah' ),
  121. 'id' => $prefix . 'lineup_cat',
  122. 'type' => 'taxonomy',
  123. 'taxonomy' => 'lineup-category',
  124. 'placeholder' => 'Select a category',
  125. 'field_type' => 'select'
  126. ),
  127. )
  128. );
  129. $meta_boxes[] = array(
  130. 'id' => 'lineup_list',
  131. 'title' => 'Songs',
  132. 'pages' => array( 'lineups'),
  133. 'context' => 'normal',
  134. 'priority' => 'high',
  135. 'fields' => array(
  136. // Group
  137. array(
  138. 'name' => '', // Optional
  139. 'id' => "{$prefix}lineup_song_item",
  140. 'type' => 'group',
  141. 'class' => 'row',
  142. 'clone' => true,
  143. 'sort_clone' => true,
  144. 'fields' => array(
  145. array(
  146. 'name' => esc_html__( 'Song', 'selah' ),
  147. 'id' => "{$prefix}lineup_song",
  148. 'type' => 'post',
  149. 'post_type' => 'songs',
  150. 'field_type' => 'select_advanced',
  151. 'multiple' => false,
  152. 'placeholder' => esc_html__( 'Select a Song', 'selah' ),
  153. 'query_args' => array(
  154. 'post_status' => 'publish',
  155. 'posts_per_page' => - 1,
  156. ),
  157. 'class' => ''
  158. ),
  159. array(
  160. 'name' => esc_html__( 'Key', 'selah' ),
  161. 'id' => "{$prefix}lineup_song_key",
  162. 'type' => 'select',
  163. 'options' => array(
  164. 'C' => 'C',
  165. 'Db' => 'Db',
  166. 'D' => 'D',
  167. 'Eb' => 'Eb',
  168. 'E' => 'E',
  169. 'F' => 'F',
  170. 'Gb' => 'Gb',
  171. 'G' => 'G',
  172. 'Ab' => 'Ab',
  173. 'A' => 'A',
  174. 'Bb' => 'Bb',
  175. 'B' => 'B',
  176. ),
  177. 'placeholder' => esc_html__( 'Default Key', 'selah' ),
  178. ),
  179. array(
  180. 'name' => __( 'Notes', 'rwmb' ),
  181. 'desc' => __( '', 'rwmb' ),
  182. 'id' => "{$prefix}lineup_song_notes",
  183. 'type' => 'textarea',
  184. 'rows' => 4,
  185. ),
  186. ),
  187. ),
  188. ),
  189. );
  190. $meta_boxes[] = array(
  191. 'id' => 'song-information',
  192. 'title' => 'Song Information',
  193. 'pages' => array( 'songs' ),
  194. 'context' => 'normal',
  195. 'priority' => 'high',
  196. 'fields' => array(
  197. array(
  198. 'name' => __( 'Artist', 'rwmb' ),
  199. 'desc' => __( '', 'rwmb' ),
  200. 'id' => "{$prefix}song_artist",
  201. 'type' => 'text',
  202. ),
  203. array(
  204. 'name' => __( 'Album', 'rwmb' ),
  205. 'desc' => __( '', 'rwmb' ),
  206. 'id' => "{$prefix}song_album",
  207. 'type' => 'text',
  208. ),
  209. array(
  210. 'name' => __( 'Tempo', 'rwmb' ),
  211. 'desc' => __( '', 'rwmb' ),
  212. 'id' => "{$prefix}song_bpm",
  213. 'type' => 'text',
  214. ),
  215. )
  216. );
  217. $meta_boxes[] = array(
  218. 'id' => 'song-resources',
  219. 'title' => 'Resources',
  220. 'pages' => array( 'songs', 'lineups' ),
  221. 'context' => 'normal',
  222. 'priority' => 'high',
  223. 'fields' => array(
  224. // Group
  225. array(
  226. 'name' => '', // Optional
  227. 'id' => "{$prefix}resource_list",
  228. 'type' => 'group',
  229. 'clone' => true,
  230. 'sort_clone' => true,
  231. 'fields' => array(
  232. array(
  233. 'name' => __( 'Description', 'rwmb' ),
  234. 'desc' => __( 'Video, Audio, Custom text', 'rwmb' ),
  235. 'id' => "{$prefix}song_resource_description",
  236. 'type' => 'text',
  237. ),
  238. array(
  239. 'name' => __( 'URL', 'rwmb' ),
  240. 'desc' => __( '', 'rwmb' ),
  241. 'id' => "{$prefix}song_resource_url",
  242. 'type' => 'text',
  243. ),
  244. ),
  245. ),
  246. )
  247. );
  248. if ( class_exists( 'RW_Meta_Box' ) ) {
  249. foreach ( $meta_boxes as $meta_box ) {
  250. if ( isset( $meta_box['only_on'] ) && ! rw_maybe_include( $meta_box['only_on'] ) ) {
  251. continue;
  252. }
  253. new RW_Meta_Box( $meta_box );
  254. }
  255. }
  256. }
  257. add_action( 'admin_init', 'jsp_register_meta_boxes' );
  258. /**
  259. * Check if meta boxes is included
  260. *
  261. * @return bool
  262. */
  263. function rw_maybe_include( $conditions ) {
  264. global $jsp_slideType;
  265. if ( ! defined( 'WP_ADMIN' ) || ! WP_ADMIN ) {
  266. return false;
  267. }
  268. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  269. return true;
  270. }
  271. if ( isset( $_GET['post'] ) ) {
  272. $post_id = $_GET['post'];
  273. }
  274. elseif ( isset( $_POST['post_ID'] ) ) {
  275. $post_id = $_POST['post_ID'];
  276. }
  277. else {
  278. $post_id = false;
  279. }
  280. $post_id = (int) $post_id;
  281. $post = get_post( $post_id );
  282. if ($post) {
  283. foreach ( $conditions as $cond => $v ) {
  284. if ( ! is_array( $v ) ) {
  285. $v = array( $v );
  286. }
  287. switch ( $cond ) {
  288. case 'id':
  289. if ( in_array( $post_id, $v ) ) {
  290. return true;
  291. }
  292. break;
  293. case 'parent':
  294. $post_parent = $post->post_parent;
  295. if ( in_array( $post_parent, $v ) ) {
  296. return true;
  297. }
  298. break;
  299. case 'slug':
  300. $post_slug = $post->post_name;
  301. if ( in_array( $post_slug, $v ) ) {
  302. return true;
  303. }
  304. break;
  305. case 'parent_slug':
  306. $ancestors = $post->ancestors;
  307. if ( $ancestors ) {
  308. $parent_id = get_post( end($ancestors) );
  309. $parent_slug = $parent_id->post_name;
  310. if ( in_array( $parent_slug, $v ) ) {
  311. return true;
  312. }
  313. }
  314. break;
  315. case 'slide':
  316. if ( in_array( $jsp_slideType, $v ) ) {
  317. return true;
  318. }
  319. break;
  320. case 'category':
  321. $categories = get_the_category( $post->ID );
  322. $catslugs = array();
  323. foreach ($categories as $category) {
  324. array_push($catslugs, $category->slug);
  325. }
  326. if ( array_intersect( $catslugs, $v ) ) {
  327. return true;
  328. }
  329. break;
  330. case 'template':
  331. $template = get_post_meta( $post_id, '_wp_page_template', true );
  332. if ( in_array( $template, $v ) ) {
  333. return true;
  334. }
  335. break;
  336. }
  337. }
  338. }
  339. return false;
  340. }
  341. ?>