PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/Avada/framework/metaboxes/metaboxes.php

https://gitlab.com/webkod3r/tripolis
PHP | 272 lines | 211 code | 57 blank | 4 comment | 27 complexity | a73dd08c50acd527fba4167abb0982c0 MD5 | raw file
  1. <?php
  2. class PyreThemeFrameworkMetaboxes {
  3. public function __construct() {
  4. $this->data = Avada()->settings->get_all();
  5. add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
  6. add_action( 'save_post', array( $this, 'save_meta_boxes' ) );
  7. add_action( 'admin_enqueue_scripts', array( $this, 'admin_script_loader' ) );
  8. }
  9. /**
  10. * Load backend scripts
  11. */
  12. function admin_script_loader() {
  13. global $pagenow;
  14. if ( is_admin() && ( in_array( $pagenow, array( 'post-new.php', 'post.php' ) ) ) ) {
  15. $theme_info = wp_get_theme();
  16. wp_enqueue_script( 'jquery.biscuit', get_template_directory_uri() . '/framework/assets/js/jquery.biscuit.js', array( 'jquery' ), $theme_info->get( 'Version' ) );
  17. wp_register_script( 'avada_upload', get_template_directory_uri() . '/framework/assets/js/upload.js', array( 'jquery' ), $theme_info->get( 'Version' ) );
  18. wp_enqueue_script( 'avada_upload' );
  19. wp_enqueue_script( 'media-upload' );
  20. wp_enqueue_script( 'thickbox' );
  21. wp_enqueue_style( 'thickbox' );
  22. }
  23. }
  24. public function add_meta_boxes() {
  25. $post_types = get_post_types( array( 'public' => true ) );
  26. $disallowed = array( 'page', 'post', 'attachment', 'avada_portfolio', 'themefusion_elastic', 'product', 'wpsc-product', 'slide', 'tribe_events' );
  27. foreach ( $post_types as $post_type ) {
  28. if ( in_array( $post_type, $disallowed ) ) {
  29. continue;
  30. }
  31. $this->add_meta_box('post_options', 'Avada Options', $post_type);
  32. }
  33. $this->add_meta_box( 'post_options', 'Fusion Page Options', 'post' );
  34. $this->add_meta_box( 'page_options', 'Fusion Page Options', 'page' );
  35. $this->add_meta_box( 'portfolio_options', 'Fusion Page Options', 'avada_portfolio' );
  36. $this->add_meta_box( 'es_options', 'Elastic Slide Options', 'themefusion_elastic' );
  37. $this->add_meta_box( 'woocommerce_options', 'Fusion Page Options', 'product' );
  38. $this->add_meta_box( 'slide_options', 'Slide Options', 'slide' );
  39. $this->add_meta_box( 'events_calendar_options', 'Events Calendar Options', 'tribe_events' );
  40. }
  41. public function add_meta_box( $id, $label, $post_type ) {
  42. add_meta_box( 'pyre_' . $id, $label, array( $this, $id ), $post_type );
  43. }
  44. public function save_meta_boxes( $post_id ) {
  45. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  46. return;
  47. }
  48. foreach ( $_POST as $key => $value ) {
  49. if ( strstr( $key, 'pyre_') ) {
  50. update_post_meta( $post_id, $key, $value );
  51. }
  52. }
  53. }
  54. public function page_options() {
  55. $this->render_option_tabs( array( 'sliders', 'page', 'header', 'footer', 'sidebars', 'background', 'portfolio_page', 'pagetitlebar' ) );
  56. }
  57. public function post_options() {
  58. $this->render_option_tabs( array( 'post', 'page', 'sliders', 'header', 'footer', 'sidebars', 'background', 'pagetitlebar' ) );
  59. }
  60. public function portfolio_options() {
  61. $this->render_option_tabs( array( 'portfolio_post', 'page', 'sliders', 'header', 'footer', 'sidebars', 'background', 'pagetitlebar' ) );
  62. }
  63. public function woocommerce_options() {
  64. $this->render_option_tabs( array( 'page', 'header', 'footer', 'sidebars', 'sliders', 'background', 'pagetitlebar' ), 'product' );
  65. }
  66. public function es_options() {
  67. include 'options/options_es.php';
  68. }
  69. public function slide_options() {
  70. include 'options/options_slide.php';
  71. }
  72. public function events_calendar_options() {
  73. $this->render_option_tabs( array( 'page', 'sliders', 'header', 'footer', 'sidebars', 'background', 'pagetitlebar' ) );
  74. }
  75. public function render_option_tabs( $requested_tabs, $post_type = 'default' ) {
  76. $tabs_names = array(
  77. 'sliders' => __( 'Sliders', 'Avada' ),
  78. 'page' => __( 'Page', 'Avada' ),
  79. 'post' => __( 'Post', 'Avada' ),
  80. 'header' => __( 'Header', 'Avada' ),
  81. 'footer' => __( 'Footer', 'Avada' ),
  82. 'sidebars' => __( 'Sidebars', 'Avada' ),
  83. 'background' => __( 'Background', 'Avada' ),
  84. 'portfolio' => __( 'Portfolio', 'Avada' ),
  85. 'pagetitlebar' => __( 'Page Title Bar', 'Avada' ),
  86. 'portfolio_page' => __( 'Portfolio', 'Avada' ),
  87. 'portfolio_post' => __( 'Portfolio', 'Avada' ),
  88. 'product' => __( 'Product', 'Avada' )
  89. );
  90. ?>
  91. <ul class="pyre_metabox_tabs">
  92. <?php foreach( $requested_tabs as $key => $tab_name ) : ?>
  93. <?php $class_active = ( $key === 0 ) ? ' class="active"' : ''; ?>
  94. <?php if ( 'page' == $tab_name && 'product' == $post_type ) : ?>
  95. <li<?php echo $class_active; ?>><a href="<?php echo $tab_name; ?>"><?php echo $tabs_names[$post_type]; ?></a></li>
  96. <?php else : ?>
  97. <li<?php echo $class_active; ?>><a href="<?php echo $tab_name; ?>"><?php echo $tabs_names[$tab_name]; ?></a></li>
  98. <?php endif; ?>
  99. <?php endforeach; ?>
  100. </ul>
  101. <div class="pyre_metabox">
  102. <?php foreach ( $requested_tabs as $key => $tab_name ) : ?>
  103. <div class="pyre_metabox_tab" id="pyre_tab_<?php echo $tab_name; ?>">
  104. <?php require_once( 'tabs/tab_' . $tab_name . '.php' ); ?>
  105. </div>
  106. <?php endforeach; ?>
  107. </div>
  108. <div class="clear"></div>
  109. <?php
  110. }
  111. public function text( $id, $label, $desc = '' ) {
  112. global $post;
  113. ?>
  114. <div class="pyre_metabox_field">
  115. <div class="pyre_desc">
  116. <label for="pyre_<?php echo $id; ?>"><?php echo $label; ?></label>
  117. <?php if ( $desc ) : ?>
  118. <p><?php echo $desc; ?></p>
  119. <?php endif; ?>
  120. </div>
  121. <div class="pyre_field">
  122. <input type="text" id="pyre_<?php echo $id; ?>" name="pyre_<?php echo $id; ?>" value="<?php echo get_post_meta( $post->ID, 'pyre_' . $id, true ); ?>" />
  123. </div>
  124. </div>
  125. <?php
  126. }
  127. public function select( $id, $label, $options, $desc = '' ) {
  128. global $post;
  129. ?>
  130. <div class="pyre_metabox_field">
  131. <div class="pyre_desc">
  132. <label for="pyre_<?php echo $id; ?>"><?php echo $label; ?></label>
  133. <?php if ( $desc ) : ?>
  134. <p><?php echo $desc; ?></p>
  135. <?php endif; ?>
  136. </div>
  137. <div class="pyre_field">
  138. <div class="fusion-shortcodes-arrow">&#xf107;</div>
  139. <select id="pyre_<?php echo $id; ?>" name="pyre_<?php echo $id; ?>">
  140. <?php foreach( $options as $key => $option ) : ?>
  141. <?php $selected = ( $key == get_post_meta( $post->ID, 'pyre_' . $id, true ) ) ? 'selected="selected"' : ''; ?>
  142. <option <?php echo $selected; ?> value="<?php echo $key; ?>"><?php echo $option; ?></option>
  143. <?php endforeach; ?>
  144. </select>
  145. </div>
  146. </div>
  147. <?php
  148. }
  149. public function multiple( $id, $label, $options, $desc = '' ) {
  150. global $post;
  151. ?>
  152. <div class="pyre_metabox_field">
  153. <div class="pyre_desc">
  154. <label for="pyre_<?php echo $id; ?>"><?php echo $label; ?></label>
  155. <?php if ( $desc ) : ?>
  156. <p><?php echo $desc; ?></p>
  157. <?php endif; ?>
  158. </div>
  159. <div class="pyre_field">
  160. <select multiple="multiple" id="pyre_<?php echo $id; ?>" name="pyre_<?php echo $id; ?>[]">
  161. <?php foreach ( $options as $key => $option ) : ?>
  162. <?php $selected = ( is_array( get_post_meta( $post->ID, 'pyre_' . $id, true ) ) && in_array( $key, get_post_meta( $post->ID, 'pyre_' . $id, true ) ) ) ? 'selected="selected"' : ''; ?>
  163. <option <?php echo $selected; ?> value="<?php echo $key; ?>"><?php echo $option; ?></option>
  164. <?php endforeach; ?>
  165. </select>
  166. </div>
  167. </div>
  168. <?php
  169. }
  170. public function textarea( $id, $label, $desc = '', $default = '' ) {
  171. global $post;
  172. $db_value = get_post_meta( $post->ID, 'pyre_' . $id, true );
  173. $value = ( metadata_exists( 'post', $post->ID, 'pyre_'. $id ) ) ? $db_value : $default;
  174. $rows = 10;
  175. if ( $id == 'heading' || $id == 'caption' ) {
  176. $rows = 5;
  177. } else if ( 'page_title_custom_text' == $id || 'page_title_custom_subheader' == $id ) {
  178. $rows = 1;
  179. }
  180. ?>
  181. <div class="pyre_metabox_field">
  182. <div class="pyre_desc">
  183. <label for="pyre_<?php echo $id; ?>"><?php echo $label; ?></label>
  184. <?php if ( $desc ) : ?>
  185. <p><?php echo $desc; ?></p>
  186. <?php endif; ?>
  187. </div>
  188. <div class="pyre_field">
  189. <textarea cols="120" rows="<?php echo $rows; ?>" id="pyre_<?php echo $id; ?>" name="pyre_<?php echo $id; ?>"><?php echo $value; ?></textarea>
  190. </div>
  191. </div>
  192. <?php
  193. }
  194. public function upload( $id, $label, $desc = '' ) {
  195. global $post;
  196. ?>
  197. <div class="pyre_metabox_field">
  198. <div class="pyre_desc">
  199. <label for="pyre_<?php echo $id; ?>"><?php echo $label; ?></label>
  200. <?php if ( $desc ) : ?>
  201. <p><?php echo $desc; ?></p>
  202. <?php endif; ?>
  203. </div>
  204. <div class="pyre_field">
  205. <div class="pyre_upload">
  206. <div><input name="pyre_<?php echo $id; ?>" class="upload_field" id="pyre_<?php echo $id; ?>" type="text" value="<?php echo get_post_meta( $post->ID, 'pyre_' . $id, true ); ?>" /></div>
  207. <div class="fusion_upload_button_container"><input class="fusion_upload_button" type="button" value="<?php _e( 'Browse', 'Avada' ); ?>" /></div>
  208. </div>
  209. </div>
  210. </div>
  211. <?php
  212. }
  213. }
  214. $metaboxes = new PyreThemeFrameworkMetaboxes;
  215. // Omit closing PHP tag to avoid "Headers already sent" issues.