daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Display Divi Settings for all custom post types
  4.  *
  5.  * @package DiviColt
  6.  * @since 1.1
  7.  */
  8.  
  9. add_action('add_meta_boxes', 'divicolt_add_meta_box');
  10. function divicolt_add_meta_box()
  11. {
  12.     foreach (get_post_types() as $post_type) {
  13.         if (et_pb_is_allowed( 'page_options' )) {
  14.             if (post_type_supports($post_type, 'editor') and function_exists('et_single_settings_meta_box')) {
  15.                 $obj= get_post_type_object( $post_type );
  16.                 add_meta_box('et_settings_meta_box', sprintf(__('Divi %s Settings', 'Divi'), $obj->labels->singular_name), 'et_single_settings_meta_box', $post_type, 'side', 'high');
  17.             }
  18.         }
  19.  
  20.     }
  21. }
  22.  
  23. add_action('admin_head', 'divicolt_admin_js');
  24. function divicolt_admin_js()
  25. {
  26.     $s = get_current_screen();
  27.     if (!empty($s->post_type) and $s->post_type != 'page' and $s->post_type != 'post') {
  28.         ?>
  29.         <script>
  30.             jQuery(function ($) {
  31.                 $('#et_pb_layout').insertAfter($('#et_pb_main_editor_wrap'));
  32.             });
  33.         </script>
  34.         <?php
  35.     }
  36. }
  37.  
  38. /*
  39.  * Modified function to copy the Setting Box from Posts to other post types
  40.  * @since 1.5
  41. */
  42. function et_single_settings_meta_box( $post ) {
  43.     $post_id = get_the_ID();
  44.  
  45.     wp_nonce_field( basename( __FILE__ ), 'et_settings_nonce' );
  46.  
  47.     $page_layout = get_post_meta( $post_id, '_et_pb_page_layout', true );
  48.  
  49.     $side_nav = get_post_meta( $post_id, '_et_pb_side_nav', true );
  50.  
  51.     $project_nav = get_post_meta( $post_id, '_et_pb_project_nav', true );
  52.  
  53.     $post_hide_nav = get_post_meta( $post_id, '_et_pb_post_hide_nav', true );
  54.     $post_hide_nav = $post_hide_nav && 'off' === $post_hide_nav ? 'default' : $post_hide_nav;
  55.  
  56.     $show_title = get_post_meta( $post_id, '_et_pb_show_title', true );
  57.  
  58.     if ( is_rtl() ) {
  59.         $page_layouts = array(
  60.             'et_left_sidebar'    => esc_html__( 'Left Sidebar', 'Divi' ),
  61.             'et_right_sidebar'   => esc_html__( 'Right Sidebar', 'Divi' ),
  62.             'et_full_width_page' => esc_html__( 'Fullwidth', 'Divi' ),
  63.         );
  64.     } else {
  65.         $page_layouts = array(
  66.             'et_right_sidebar'   => esc_html__( 'Right Sidebar', 'Divi' ),
  67.             'et_left_sidebar'    => esc_html__( 'Left Sidebar', 'Divi' ),
  68.             'et_full_width_page' => esc_html__( 'Fullwidth', 'Divi' ),
  69.         );
  70.     }
  71.  
  72.     $layouts = array(
  73.         'light' => esc_html__( 'Light', 'Divi' ),
  74.         'dark'  => esc_html__( 'Dark', 'Divi' ),
  75.     );
  76.     $post_bg_color  = ( $bg_color = get_post_meta( $post_id, '_et_post_bg_color', true ) ) && '' !== $bg_color
  77.         ? $bg_color
  78.         : '#ffffff';
  79.     $post_use_bg_color = get_post_meta( $post_id, '_et_post_use_bg_color', true )
  80.         ? true
  81.         : false;
  82.     $post_bg_layout = ( $layout = get_post_meta( $post_id, '_et_post_bg_layout', true ) ) && '' !== $layout
  83.         ? $layout
  84.         : 'light'; ?>
  85.  
  86.     <p class="et_pb_page_settings et_pb_page_layout_settings">
  87.         <label for="et_pb_page_layout" style="display: block; font-weight: bold; margin-bottom: 5px;"><?php esc_html_e( 'Page Layout', 'Divi' ); ?>: </label>
  88.  
  89.         <select id="et_pb_page_layout" name="et_pb_page_layout">
  90.             <?php
  91.             foreach ( $page_layouts as $layout_value => $layout_name ) {
  92.                 printf( '<option value="%2$s"%3$s>%1$s</option>',
  93.                     esc_html( $layout_name ),
  94.                     esc_attr( $layout_value ),
  95.                     selected( $layout_value, $page_layout, false )
  96.                 );
  97.             } ?>
  98.         </select>
  99.     </p>
  100.     <p class="et_pb_page_settings et_pb_side_nav_settings" style="display: none;">
  101.         <label for="et_pb_side_nav" style="display: block; font-weight: bold; margin-bottom: 5px;"><?php esc_html_e( 'Dot Navigation', 'Divi' ); ?>: </label>
  102.  
  103.         <select id="et_pb_side_nav" name="et_pb_side_nav">
  104.             <option value="off" <?php selected( 'off', $side_nav ); ?>><?php esc_html_e( 'Off', 'Divi' ); ?></option>
  105.             <option value="on" <?php selected( 'on', $side_nav ); ?>><?php esc_html_e( 'On', 'Divi' ); ?></option>
  106.         </select>
  107.     </p>
  108.     <p class="et_pb_page_settings">
  109.         <label for="et_pb_post_hide_nav" style="display: block; font-weight: bold; margin-bottom: 5px;"><?php esc_html_e( 'Hide Nav Before Scroll', 'Divi' ); ?>: </label>
  110.  
  111.         <select id="et_pb_post_hide_nav" name="et_pb_post_hide_nav">
  112.             <option value="default" <?php selected( 'default', $post_hide_nav ); ?>><?php esc_html_e( 'Default', 'Divi' ); ?></option>
  113.             <option value="no" <?php selected( 'no', $post_hide_nav ); ?>><?php esc_html_e( 'Off', 'Divi' ); ?></option>
  114.             <option value="on" <?php selected( 'on', $post_hide_nav ); ?>><?php esc_html_e( 'On', 'Divi' ); ?></option>
  115.         </select>
  116.     </p>
  117.  
  118.     <?php foreach (get_post_types() as $post_type) {
  119.     if ( $post->post_type == $post_type ) : ?>
  120.         <p class="et_pb_page_settings et_pb_single_title" style="display: none;">
  121.             <label for="et_single_title" style="display: block; font-weight: bold; margin-bottom: 5px;"><?php esc_html_e( 'Post Title', 'Divi' ); ?>: </label>
  122.  
  123.             <select id="et_single_title" name="et_single_title">
  124.                 <option value="on" <?php selected( 'on', $show_title ); ?>><?php esc_html_e( 'Show', 'Divi' ); ?></option>
  125.                 <option value="off" <?php selected( 'off', $show_title ); ?>><?php esc_html_e( 'Hide', 'Divi' ); ?></option>
  126.             </select>
  127.         </p>
  128.  
  129.         <p class="et_divi_quote_settings et_divi_audio_settings et_divi_link_settings et_divi_format_setting et_pb_page_settings">
  130.             <label for="et_post_use_bg_color" style="display: block; font-weight: bold; margin-bottom: 5px;"><?php esc_html_e( 'Use Background Color', 'Divi' ); ?></label>
  131.             <input name="et_post_use_bg_color" type="checkbox" id="et_post_use_bg_color" <?php checked( $post_use_bg_color ); ?> />
  132.         </p>
  133.  
  134.         <p class="et_post_bg_color_setting et_divi_format_setting et_pb_page_settings">
  135.             <input id="et_post_bg_color" name="et_post_bg_color" class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value', 'Divi' ); ?>" value="<?php echo esc_attr( $post_bg_color ); ?>" data-default-color="#ffffff" />
  136.         </p>
  137.  
  138.         <p class="et_divi_quote_settings et_divi_audio_settings et_divi_link_settings et_divi_format_setting">
  139.             <label for="et_post_bg_layout" style="font-weight: bold; margin-bottom: 5px;"><?php esc_html_e( 'Text Color', 'Divi' ); ?>: </label>
  140.             <select id="et_post_bg_layout" name="et_post_bg_layout">
  141.                 <?php
  142.                 foreach ( $layouts as $layout_name => $layout_title )
  143.                     printf( '<option value="%s"%s>%s</option>',
  144.                         esc_attr( $layout_name ),
  145.                         selected( $layout_name, $post_bg_layout, false ),
  146.                         esc_html( $layout_title )
  147.                     );
  148.                 ?>
  149.             </select>
  150.         </p>
  151.     <?php endif; }
  152.  
  153.     if ( 'project' === $post->post_type ) : ?>
  154.         <p class="et_pb_page_settings et_pb_project_nav" style="display: none;">
  155.             <label for="et_project_nav" style="display: block; font-weight: bold; margin-bottom: 5px;"><?php esc_html_e( 'Project Navigation', 'Divi' ); ?>: </label>
  156.  
  157.             <select id="et_project_nav" name="et_project_nav">
  158.                 <option value="off" <?php selected( 'off', $project_nav ); ?>><?php esc_html_e( 'Hide', 'Divi' ); ?></option>
  159.                 <option value="on" <?php selected( 'on', $project_nav ); ?>><?php esc_html_e( 'Show', 'Divi' ); ?></option>
  160.             </select>
  161.         </p>
  162.     <?php endif;
  163. }
  164.  
  165. function divicolt_post_settings_save_details( $post_id, $post ){
  166.     global $pagenow;
  167.  
  168.     if ( 'post.php' !== $pagenow || ! $post || ! is_object( $post ) ) {
  169.         return;
  170.     }
  171.  
  172.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  173.         return;
  174.     }
  175.  
  176.     $post_type = get_post_type_object( $post->post_type );
  177.     if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) {
  178.         return;
  179.     }
  180.  
  181.     if ( ! isset( $_POST['et_settings_nonce'] ) || ! wp_verify_nonce( $_POST['et_settings_nonce'], basename( __FILE__ ) ) ) {
  182.         return;
  183.     }
  184.  
  185.     if ( isset( $_POST['et_post_use_bg_color'] ) )
  186.         update_post_meta( $post_id, '_et_post_use_bg_color', true );
  187.     else
  188.         delete_post_meta( $post_id, '_et_post_use_bg_color' );
  189.  
  190.     if ( isset( $_POST['et_post_bg_color'] ) )
  191.         update_post_meta( $post_id, '_et_post_bg_color', sanitize_text_field( $_POST['et_post_bg_color'] ) );
  192.     else
  193.         delete_post_meta( $post_id, '_et_post_bg_color' );
  194.  
  195.     if ( isset( $_POST['et_post_bg_layout'] ) )
  196.         update_post_meta( $post_id, '_et_post_bg_layout', sanitize_text_field( $_POST['et_post_bg_layout'] ) );
  197.     else
  198.         delete_post_meta( $post_id, '_et_post_bg_layout' );
  199.  
  200.     if ( isset( $_POST['et_single_title'] ) )
  201.         update_post_meta( $post_id, '_et_pb_show_title', sanitize_text_field( $_POST['et_single_title'] ) );
  202.     else
  203.         delete_post_meta( $post_id, '_et_pb_show_title' );
  204.  
  205.     if ( isset( $_POST['et_pb_post_hide_nav'] ) )
  206.         update_post_meta( $post_id, '_et_pb_post_hide_nav', sanitize_text_field( $_POST['et_pb_post_hide_nav'] ) );
  207.     else
  208.         delete_post_meta( $post_id, '_et_pb_post_hide_nav' );
  209.  
  210.     if ( isset( $_POST['et_project_nav'] ) )
  211.         update_post_meta( $post_id, '_et_pb_project_nav', sanitize_text_field( $_POST['et_project_nav'] ) );
  212.     else
  213.         delete_post_meta( $post_id, '_et_pb_project_nav' );
  214.  
  215.     if ( isset( $_POST['et_pb_page_layout'] ) ) {
  216.         update_post_meta( $post_id, '_et_pb_page_layout', sanitize_text_field( $_POST['et_pb_page_layout'] ) );
  217.     } else {
  218.         delete_post_meta( $post_id, '_et_pb_page_layout' );
  219.     }
  220.  
  221.     if ( isset( $_POST['et_pb_side_nav'] ) ) {
  222.         update_post_meta( $post_id, '_et_pb_side_nav', sanitize_text_field( $_POST['et_pb_side_nav'] ) );
  223.     } else {
  224.         delete_post_meta( $post_id, '_et_pb_side_nav' );
  225.     }
  226. }
  227. add_action( 'save_post', 'divicolt_post_settings_save_details', 10, 2 );
RAW Paste Data
Top