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. // Check if our nonce is set. 
  54. if ( ! isset( $_POST['onetone_inner_custom_box_nonce'] ) ) 
  55. return $post_id; 
  56.  
  57. $nonce = $_POST['onetone_inner_custom_box_nonce']; 
  58.  
  59. // Verify that the nonce is valid. 
  60. if ( ! wp_verify_nonce( $nonce, 'onetone_inner_custom_box' ) ) 
  61. return $post_id; 
  62.  
  63.  
  64. // If this is an autosave, our form has not been submitted,  
  65. // so we don't want to do anything. 
  66. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )  
  67. return $post_id; 
  68.  
  69. // Check the user's permissions. 
  70. if ( 'page' == $_POST['post_type'] ) { 
  71.  
  72. if ( ! current_user_can( 'edit_page', $post_id ) ) 
  73. return $post_id; 
  74.  
  75. } else { 
  76.  
  77. if ( ! current_user_can( 'edit_post', $post_id ) ) 
  78. return $post_id; 
  79.  
  80.  
  81. /** OK, its safe for us to save the data now. */ 
  82.  
  83. // Sanitize the user input. 
  84. //$show_breadcrumb = sanitize_text_field( $_POST['onetone_show_breadcrumb'] ); 
  85. //$onetone_layout = sanitize_text_field( $_POST['onetone_layout'] ); 
  86.  
  87. if( isset($_POST) && $_POST ) { 
  88.  
  89. $post_metas = array();  
  90. $post_metas['nav_menu'] = isset($_POST['nav_menu'])?$_POST['nav_menu']:''; 
  91. $post_metas['full_width'] = isset($_POST['full_width'])?$_POST['full_width']:'no'; 
  92. $post_metas['padding_top'] = isset($_POST['padding_top'])?$_POST['padding_top']:''; 
  93. $post_metas['padding_bottom'] = isset($_POST['padding_bottom'])?$_POST['padding_bottom']:''; 
  94. $post_metas['display_breadcrumb'] = isset($_POST['display_breadcrumb'])?$_POST['display_breadcrumb']:''; 
  95. $post_metas['nav_menu'] = isset($_POST['nav_menu'])?$_POST['nav_menu']:''; 
  96. $post_metas['page_layout'] = isset($_POST['page_layout'])?$_POST['page_layout']:'none'; 
  97. $post_metas['left_sidebar'] = isset($_POST['left_sidebar'])?$_POST['left_sidebar']:''; 
  98. $post_metas['right_sidebar'] = isset($_POST['right_sidebar'])?$_POST['right_sidebar']:''; 
  99. $post_metas['slider_banner'] = isset($_POST['slider_banner'])?$_POST['slider_banner']:'0'; 
  100. $post_metas['banner_position'] = isset($_POST['banner_position'])?$_POST['banner_position']:'1'; 
  101. $post_metas['magee_slider'] = isset($_POST['magee_slider'])?$_POST['magee_slider']:''; 
  102. $post_metas['display_title'] = isset($_POST['display_title'])?$_POST['display_title']:'yes'; 
  103. $onetone_post_meta = json_encode( $post_metas ); 
  104. // Update the meta field. 
  105. update_post_meta( $post_id, '_onetone_post_meta', $onetone_post_meta ); 
  106.  
  107.  
  108. /** 
  109. * Render Meta Box content. 
  110. * @param WP_Post $post The post object. 
  111. */ 
  112. public function onetone_render_meta_box_content( $post ) { 
  113.  
  114. global $wp_registered_sidebars; 
  115.  
  116. // $magee_sliders = self::onetone_sliders_meta(); 
  117.  
  118. // Add an nonce field so we can check for it later. 
  119. wp_nonce_field( 'onetone_inner_custom_box', 'onetone_inner_custom_box_nonce' ); 
  120.  
  121. // Use get_post_meta to retrieve an existing value from the database. 
  122. $page_meta = get_post_meta( $post->ID , '_onetone_post_meta', true); 
  123. $page_metas = @json_decode( $page_meta, true ); 
  124. if( $page_metas ) 
  125. extract( $page_metas ); 
  126.  
  127.  
  128. /************ get nav menus*************/ 
  129.  
  130. $nav_menus[] = array( 
  131. 'label' => __( 'Default', 'onetone' ),  
  132. 'value' => '' 
  133. ); 
  134. $menus = get_registered_nav_menus(); 
  135.  
  136. foreach ( $menus as $location => $description ) { 
  137. $nav_menus[] = array( 
  138. 'label' => $description,  
  139. 'value' => $location 
  140. ); 
  141.  
  142.  
  143. /** sidebars */ 
  144.  
  145. $sidebars[] = array( 
  146. 'label' => __( 'None', 'onetone' ),  
  147. 'value' => '' 
  148. ); 
  149.  
  150. foreach( $wp_registered_sidebars as $key => $value) { 
  151.  
  152. $sidebars[] = array( 
  153. 'label' => $value['name'],  
  154. 'value' => $value['id'],  
  155. ); 
  156.  
  157. // Display the form, using the current value. 
  158. $nav_menu = isset( $nav_menu )? $nav_menu:'';  
  159. $full_width = isset( $full_width )? $full_width:'no';  
  160. $page_layout = isset( $page_layout )? $page_layout:'none';  
  161. $left_sidebar = isset( $left_sidebar )? $left_sidebar:'';  
  162. $right_sidebar = isset( $right_sidebar )? $right_sidebar:'';  
  163. $display_breadcrumb = isset( $display_breadcrumb )? $display_breadcrumb:'';  
  164. $display_title = isset( $display_title )? $display_title:'yes';  
  165.  
  166. $padding_top = isset( $padding_top )? $padding_top:'50px'; 
  167. $padding_bottom = isset( $padding_bottom )? $padding_bottom:'50px'; 
  168.  
  169. echo '<p class="meta-options"><label for="left_sidebar" style="display: inline-block;width: 150px;">'; 
  170. _e( 'Custom Menu', 'onetone' ); 
  171. echo '</label> '; 
  172. echo '<select name="nav_menu" id="nav_menu">'; 
  173. foreach( $nav_menus as $nav) { 
  174. echo '<option '.selected($nav_menu, $nav['value'], false).' value="'.$nav['value'].'">'.$nav['label'].'</option>'; 
  175. echo '</select></p>'; 
  176.  
  177. echo '<p class="meta-options"><label for="full_width" style="display: inline-block;width: 150px;">'; 
  178. _e( 'Content Full Width', 'onetone' ); 
  179. echo '</label> '; 
  180. echo '<select name="full_width" id="full_width"> 
  181. <option '.selected($full_width, 'no', false).' value="no">'.__("No", "onetone").'</option> 
  182. <option '.selected($full_width, 'yes', false).' value="yes">'.__("Yes", "onetone").'</option> 
  183. </select></p>'; 
  184.  
  185. echo '<p class="meta-options"><label for="padding_top" style="display: inline-block;width: 150px;">'; 
  186. _e( 'Padding Top', 'onetone' ); 
  187. echo '</label> '; 
  188. echo '<input name="padding_top" type="text" value="'.$padding_top.'" />'; 
  189. echo '</p>'; 
  190.  
  191. echo '<p class="meta-options"><label for="padding_bottom" style="display: inline-block;width: 150px;">'; 
  192. _e( 'Padding Bottom', 'onetone' ); 
  193. echo '</label> '; 
  194. echo '<input name="padding_bottom" type="text" value="'.$padding_bottom.'" />'; 
  195. echo '</p>'; 
  196.  
  197.  
  198. echo '<p class="meta-options"><label for="display_breadcrumb" style="display: inline-block;width: 150px;">'; 
  199. _e( 'Display Breadcrumb', 'onetone' ); 
  200. echo '</label> '; 
  201. echo '<select name="display_breadcrumb" id="display_breadcrumb"> 
  202. <option '.selected( $display_breadcrumb, '', false ).' value="">'.__("Default", "onetone").'</option> 
  203. <option '.selected( $display_breadcrumb, 'yes', false ).' value="yes">'.__("Yes", "onetone").'</option> 
  204. <option '.selected( $display_breadcrumb, 'no', false ).' value="no">'.__("No", "onetone").'</option> 
  205. </select></p>'; 
  206.  
  207.  
  208.  
  209. echo '<p class="meta-options"><label for="page_layout" style="display: inline-block;width: 150px;">'; 
  210. _e( 'Page Layout', 'onetone' ); 
  211. echo '</label> '; 
  212. echo '<select name="page_layout" id="page_layout"> 
  213. <option '.selected($page_layout, 'none', false).' value="none">'.__("No Sidebar", "onetone").'</option> 
  214. <option '.selected($page_layout, 'left', false).' value="left">'.__("Left Sidebar", "onetone").'</option> 
  215. <option '.selected($page_layout, 'right', false).' value="right">'.__("Right Sidebar", "onetone").'</option> 
  216. <option '.selected($page_layout, 'both', false).' value="both">'.__("Both Sidebar", "onetone").'</option> 
  217. </select></p>'; 
  218.  
  219. echo '<p class="meta-options"><label for="left_sidebar" style="display: inline-block;width: 150px;">'; 
  220. _e( 'Select Left Sidebar', 'onetone' ); 
  221. echo '</label> '; 
  222. echo '<select name="left_sidebar" id="left_sidebar">'; 
  223. foreach( $sidebars as $sidebar ) { 
  224. echo '<option '.selected($left_sidebar, $sidebar['value'], false).' value="'.$sidebar['value'].'">'.$sidebar['label'].'</option>'; 
  225. echo '</select></p>'; 
  226.  
  227. echo '<p class="meta-options"><label for="right_sidebar" style="display: inline-block;width: 150px;">'; 
  228. _e( 'Select Right Sidebar', 'onetone' ); 
  229. echo '</label> '; 
  230. echo '<select name="right_sidebar" id="right_sidebar">'; 
  231. foreach( $sidebars as $sidebar ) { 
  232. echo '<option '.selected($right_sidebar, $sidebar['value'], false).' value="'.$sidebar['value'].'">'.$sidebar['label'].'</option>'; 
  233. echo '</select></p>'; 
  234.  
  235.  
  236.