onetone_metaboxClass

The Class.

Defined (1)

The class is defined in the following location(s).

/includes/metabox-options.php  
  1. class onetone_metaboxClass { 
  2.  
  3. /** 
  4. * Hook into the appropriate actions when the class is constructed. 
  5. */ 
  6. public function __construct() { 
  7. add_action( 'add_meta_boxes', array( $this, 'onetone_add_meta_box' ) ); 
  8. add_action( 'save_post', array( $this, 'onetone_save' ) ); 
  9.  
  10. /** 
  11. * Adds the meta box container. 
  12. */ 
  13. public function onetone_add_meta_box( $post_type ) { 
  14. $post_types = array( 'page'); //limit meta box to certain post types 
  15. if ( in_array( $post_type, $post_types )) { 
  16. add_meta_box( 
  17. 'onetone_page_meta_box' 
  18. , __( 'Onetone Metabox Options', 'onetone' ) 
  19. , array( $this, 'onetone_render_meta_box_content' ) 
  20. , $post_type 
  21. , 'advanced' 
  22. , 'high' 
  23. ); 
  24. // get onetone sliders from plugin magee shrotcodes 
  25.  
  26. public static function onetone_sliders_meta() { 
  27. $onetone_sliders[] = array( 
  28. 'label' => __( 'Select a slider', 'onetone' ),  
  29. 'value' => '' 
  30. ); 
  31. $onetone_custom_slider = new WP_Query( array( 'post_type' => 'magee_slider', 'post_status'=>'publish', 'posts_per_page' => -1 ) ); 
  32. while ( $onetone_custom_slider->have_posts() ) { 
  33. $onetone_custom_slider->the_post(); 
  34.  
  35. $onetone_sliders[] = array( 
  36. 'label' => get_the_title(),  
  37. 'value' => get_the_ID() 
  38. ); 
  39. wp_reset_postdata(); 
  40. return $onetone_sliders; 
  41.  
  42. /** 
  43. * Save the meta when the post is saved. 
  44. * @param int $post_id The ID of the post being saved. 
  45. */ 
  46. public function onetone_save( $post_id ) { 
  47.  
  48. /** 
  49. * We need to verify this came from the our screen and with proper authorization,  
  50. * because save_post can be triggered at other times. 
  51. */ 
  52.  
  53.  
  54. // Check if our nonce is set. 
  55. if ( ! isset( $_POST['onetone_inner_custom_box_nonce'] ) ) 
  56. return $post_id; 
  57.  
  58. $nonce = $_POST['onetone_inner_custom_box_nonce']; 
  59.  
  60. // Verify that the nonce is valid. 
  61. if ( ! wp_verify_nonce( $nonce, 'onetone_inner_custom_box' ) ) 
  62. return $post_id; 
  63.  
  64.  
  65.  
  66. // If this is an autosave, our form has not been submitted,  
  67. // so we don't want to do anything. 
  68. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )  
  69. return $post_id; 
  70.  
  71. // Check the user's permissions. 
  72. if ( 'page' == $_POST['post_type'] ) { 
  73.  
  74. if ( ! current_user_can( 'edit_page', $post_id ) ) 
  75. return $post_id; 
  76.  
  77. } else { 
  78.  
  79. if ( ! current_user_can( 'edit_post', $post_id ) ) 
  80. return $post_id; 
  81.  
  82.  
  83. /** OK, its safe for us to save the data now. */ 
  84.  
  85. // Sanitize the user input. 
  86. //$show_breadcrumb = sanitize_text_field( $_POST['onetone_show_breadcrumb'] ); 
  87. //$onetone_layout = sanitize_text_field( $_POST['onetone_layout'] ); 
  88.  
  89. if( isset($_POST) && $_POST ) { 
  90.  
  91.  
  92. $post_metas = array(); 
  93. $post_metas['header_position'] = isset($_POST['header_position'])?$_POST['header_position']:'top'; 
  94. $post_metas['full_width'] = isset($_POST['full_width'])?$_POST['full_width']:'no'; 
  95. $post_metas['padding_top'] = isset($_POST['padding_top'])?$_POST['padding_top']:''; 
  96. $post_metas['padding_bottom'] = isset($_POST['padding_bottom'])?$_POST['padding_bottom']:''; 
  97. $post_metas['display_breadcrumb'] = isset($_POST['display_breadcrumb'])?$_POST['display_breadcrumb']:'yes'; 
  98. $post_metas['nav_menu'] = isset($_POST['nav_menu'])?$_POST['nav_menu']:''; 
  99. $post_metas['page_layout'] = isset($_POST['page_layout'])?$_POST['page_layout']:'none'; 
  100. $post_metas['left_sidebar'] = isset($_POST['left_sidebar'])?$_POST['left_sidebar']:''; 
  101. $post_metas['right_sidebar'] = isset($_POST['right_sidebar'])?$_POST['right_sidebar']:''; 
  102. $post_metas['slider_banner'] = isset($_POST['slider_banner'])?$_POST['slider_banner']:'0'; 
  103. $post_metas['banner_position'] = isset($_POST['banner_position'])?$_POST['banner_position']:'1'; 
  104. $post_metas['magee_slider'] = isset($_POST['magee_slider'])?$_POST['magee_slider']:''; 
  105. $post_metas['display_title'] = isset($_POST['display_title'])?$_POST['display_title']:'yes'; 
  106.  
  107. $onetone_post_meta = json_encode( $post_metas ); 
  108. // Update the meta field. 
  109. update_post_meta( $post_id, '_onetone_post_meta', $onetone_post_meta ); 
  110.  
  111.  
  112.  
  113.  
  114. /** 
  115. * Render Meta Box content. 
  116. * @param WP_Post $post The post object. 
  117. */ 
  118. public function onetone_render_meta_box_content( $post ) { 
  119.  
  120. global $wp_registered_sidebars; 
  121.  
  122. // $magee_sliders = self::onetone_sliders_meta(); 
  123.  
  124. // Add an nonce field so we can check for it later. 
  125. wp_nonce_field( 'onetone_inner_custom_box', 'onetone_inner_custom_box_nonce' ); 
  126.  
  127. // Use get_post_meta to retrieve an existing value from the database. 
  128. $page_meta = get_post_meta( $post->ID , '_onetone_post_meta', true); 
  129. $page_metas = @json_decode( $page_meta, true ); 
  130. if( $page_metas ) 
  131. extract( $page_metas ); 
  132.  
  133.  
  134. /************ get nav menus*************/ 
  135.  
  136. $nav_menus[] = array( 
  137. 'label' => __( 'Default', 'onetone' ),  
  138. 'value' => '' 
  139. ); 
  140. $menus = get_registered_nav_menus(); 
  141.  
  142. foreach ( $menus as $location => $description ) { 
  143. $nav_menus[] = array( 
  144. 'label' => $description,  
  145. 'value' => $location 
  146. ); 
  147.  
  148.  
  149. /** sidebars */ 
  150.  
  151. $sidebars[] = array( 
  152. 'label' => __( 'None', 'onetone' ),  
  153. 'value' => '' 
  154. ); 
  155.  
  156. foreach( $wp_registered_sidebars as $key => $value) { 
  157.  
  158. $sidebars[] = array( 
  159. 'label' => $value['name'],  
  160. 'value' => $value['id'],  
  161. ); 
  162.  
  163. // Display the form, using the current value. 
  164. $full_width = isset( $full_width )? $full_width:'no';  
  165. $page_layout = isset( $page_layout )? $page_layout:'none';  
  166. $left_sidebar = isset( $left_sidebar )? $left_sidebar:'';  
  167. $right_sidebar = isset( $right_sidebar )? $right_sidebar:'';  
  168. $display_breadcrumb = isset( $display_breadcrumb )? $display_breadcrumb:'yes';  
  169. $display_title = isset( $display_title )? $display_title:'yes';  
  170.  
  171. $padding_top = isset( $padding_top )? $padding_top:'50px'; 
  172. $padding_bottom = isset( $padding_bottom )? $padding_top:'50px'; 
  173.  
  174. echo '<p class="meta-options"><label for="full_width" style="display: inline-block;width: 150px;">'; 
  175. _e( 'Content Full Width', 'onetone' ); 
  176. echo '</label> '; 
  177. echo '<select name="full_width" id="full_width"> 
  178. <option '.selected($full_width, 'no', false).' value="no">'.__("No", "onetone").'</option> 
  179. <option '.selected($full_width, 'yes', false).' value="yes">'.__("Yes", "onetone").'</option> 
  180. </select></p>'; 
  181.  
  182.  
  183. echo '<p class="meta-options"><label for="display_breadcrumb" style="display: inline-block;width: 150px;">'; 
  184. _e( 'Display Breadcrumb', 'onetone' ); 
  185. echo '</label> '; 
  186. echo '<select name="display_breadcrumb" id="display_breadcrumb"> 
  187. <option '.selected($display_breadcrumb, 'yes', false).' value="yes">'.__("Yes", "onetone").'</option> 
  188. <option '.selected($display_breadcrumb, 'no', false).' value="no">'.__("No", "onetone").'</option> 
  189. </select></p>'; 
  190.  
  191. echo '<p class="meta-options"><label for="padding_top" style="display: inline-block;width: 150px;">'; 
  192. _e( 'Padding Top', 'onetone' ); 
  193. echo '</label> '; 
  194. echo '<input name="padding_top" type="text" value="'.$padding_top.'" />'; 
  195. echo '</p>'; 
  196.  
  197. echo '<p class="meta-options"><label for="padding_bottom" style="display: inline-block;width: 150px;">'; 
  198. _e( 'Padding Bottom', 'onetone' ); 
  199. echo '</label> '; 
  200. echo '<input name="padding_bottom" type="text" value="'.$padding_bottom.'" />'; 
  201. echo '</p>';  
  202.  
  203. echo '<p class="meta-options"><label for="page_layout" style="display: inline-block;width: 150px;">'; 
  204. _e( 'Page Layout', 'onetone' ); 
  205. echo '</label> '; 
  206. echo '<select name="page_layout" id="page_layout"> 
  207. <option '.selected($page_layout, 'none', false).' value="none">'.__("No Sidebar", "onetone").'</option> 
  208. <option '.selected($page_layout, 'left', false).' value="left">'.__("Left Sidebar", "onetone").'</option> 
  209. <option '.selected($page_layout, 'right', false).' value="right">'.__("Right Sidebar", "onetone").'</option> 
  210. <option '.selected($page_layout, 'both', false).' value="both">'.__("Both Sidebar", "onetone").'</option> 
  211. </select></p>'; 
  212.  
  213.  
  214. echo '<p class="meta-options"><label for="left_sidebar" style="display: inline-block;width: 150px;">'; 
  215. _e( 'Select Left Sidebar', 'onetone' ); 
  216. echo '</label> '; 
  217. echo '<select name="left_sidebar" id="left_sidebar">'; 
  218. foreach( $sidebars as $sidebar ) { 
  219. echo '<option '.selected($left_sidebar, $sidebar['value'], false).' value="'.$sidebar['value'].'">'.$sidebar['label'].'</option>'; 
  220. echo '</select></p>'; 
  221.  
  222. echo '<p class="meta-options"><label for="right_sidebar" style="display: inline-block;width: 150px;">'; 
  223. _e( 'Select Right Sidebar', 'onetone' ); 
  224. echo '</label> '; 
  225. echo '<select name="right_sidebar" id="right_sidebar">'; 
  226. foreach( $sidebars as $sidebar ) { 
  227. echo '<option '.selected($right_sidebar, $sidebar['value'], false).' value="'.$sidebar['value'].'">'.$sidebar['label'].'</option>'; 
  228. echo '</select></p>'; 
  229.  
  230.  
  231.