Advertisement
Guest User

Nitro Metaboxes

a guest
Nov 25th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 33.09 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @version    1.0
  4.  * @package    WR_Theme
  5.  * @author     WooRockets Team <support@woorockets.com>
  6.  * @copyright  Copyright (C) 2014 WooRockets.com. All Rights Reserved.
  7.  * @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
  8.  *
  9.  * Websites: http://www.woorockets.com
  10.  */
  11.  
  12. /**
  13.  * Plug additional meta boxes into WordPress.
  14.  *
  15.  * @package  WR_Theme
  16.  * @since    1.0
  17.  */
  18. class WR_Nitro_Meta_Box extends RW_Meta_Box {
  19.     /**
  20.      * Variable to hold the initialization state.
  21.      *
  22.      * @var  boolean
  23.      */
  24.     protected static $initialized = false;
  25.  
  26.     /**
  27.      * Initialize pluggable functions.
  28.      *
  29.      * @return  void
  30.      */
  31.     public static function initialize() {
  32.         // Do nothing if pluggable functions already initialized.
  33.         if ( self::$initialized ) {
  34.             return;
  35.         }
  36.  
  37.         // Remove original RW Meta Box init action.
  38.         remove_action( 'admin_init', 'rwmb_register_meta_boxes' );
  39.  
  40.         // Add action to init RW Meta Box.
  41.         add_action( 'admin_init', array( __CLASS__, 'register_meta_boxes' ) );
  42.  
  43.         // Register necessary actions / filters to hook WR Nitro meta boxes into WordPress.
  44.         add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_admin_assets' ) );
  45.  
  46.         add_filter( 'rwmb_meta_boxes'        , array( __CLASS__, 'meta_boxes'         ) );
  47.         add_filter( 'rwmb_outside_conditions', array( __CLASS__, 'outside_conditions' ) );
  48.  
  49.         // Register filter to verify page option values before saving.
  50.         add_filter( 'update_post_metadata', array( __CLASS__, 'verify' ), 10, 5 );
  51.  
  52.         // Register filter to synchronize default option values with current theme customizer values.
  53.         add_filter( 'rwmb_field_meta', array( __CLASS__, 'get_meta' ), 10, 3 );
  54.  
  55.         // State that initialization completed.
  56.         self::$initialized = true;
  57.     }
  58.  
  59.     /**
  60.      * Initialize RW Meta Box.
  61.      *
  62.      * @return  void
  63.      */
  64.     public static function register_meta_boxes() {
  65.         // Get meta boxes to register.
  66.         $meta_boxes = apply_filters( 'rwmb_meta_boxes', array() );
  67.  
  68.         if ( is_array( $meta_boxes ) ) {
  69.             // Load all custom fields.
  70.             static $loaded;
  71.  
  72.             if ( ! isset( $loaded ) ) {
  73.                 foreach ( glob( dirname( __FILE__ ) . '/fields/*.php' ) as $file ) {
  74.                     include_once $file;
  75.                 }
  76.  
  77.                 $loaded = true;
  78.             }
  79.  
  80.             // Instantiate all meta boxes.
  81.             foreach ( $meta_boxes as $meta_box ) {
  82.                 $meta_box = new self( $meta_box );
  83.             }
  84.         }
  85.     }
  86.  
  87.     /**
  88.      * Enqueue required admin assets.
  89.      *
  90.      * @return  void
  91.      */
  92.     public static function enqueue_admin_assets() {
  93.         global $post;
  94.  
  95.         // Enqueue scripts and styles for registered pages (post types) only
  96.         $types = array( 'post', 'page', 'nitro-portfolio', 'masonry-builder' );
  97.  
  98.         if ( isset( $post->post_type ) && in_array( $post->post_type, $types ) ) {
  99.             // Load custom style.
  100.             wp_enqueue_style( 'wr-metabox', get_template_directory_uri() . '/assets/woorockets/css/admin/meta-box.css' );
  101.         }
  102.     }
  103.  
  104.     /**
  105.      * Register additional meta boxes.
  106.      *
  107.      * @param   array  $meta_boxes  Current meta boxes.
  108.      *
  109.      * @return  array
  110.      */
  111.     public static function meta_boxes( $meta_boxes ) {
  112.         $posts = array(
  113.             'posts_per_page'   => -1,
  114.             'offset'           => 0,
  115.             'orderby'          => 'date',
  116.             'order'            => 'DESC',
  117.             'post_type'        => 'header_builder',
  118.             'post_status'      => array( 'header_normal', 'header_default' ),
  119.             'suppress_filters' => true,
  120.         );
  121.  
  122.         $posts = get_posts( $posts );
  123.         $header_layout = array();
  124.  
  125.         global $wr_nitro_options;
  126.  
  127.         // Style of list product
  128.         $shop_layout = $wr_nitro_options['wc_archive_style'];
  129.  
  130.         foreach ( $posts as $key => $value ) {
  131.             $header_layout[ $value->ID ] = $value->post_title;
  132.         }
  133.  
  134.         // Additional meta box for post.
  135.         $meta_boxes[] = array(
  136.             'id'         => 'wr_post_option',
  137.             'post_types' => array( 'post' ),
  138.             'title'      => WR_Nitro::_( 'Post Settings' ),
  139.             'context'    => 'normal',
  140.             'priority'   => 'high',
  141.             'autosave'   => true,
  142.             'fields'     => array(
  143.                 array(
  144.                     'name' => WR_Nitro::_( 'Enable large post' ),
  145.                     'id'   => 'masonry_large',
  146.                     'type' => 'checkbox',
  147.                     'desc' => WR_Nitro::_( '<br /><i>Support Masonry layout only</i>' ),
  148.                     'std'  => 0,
  149.                 ),
  150.                 array(
  151.                     'name' => WR_Nitro::_( 'Add image gallery' ),
  152.                     'id'   => 'format_gallery',
  153.                     'type' => 'image_advanced',
  154.                 ),
  155.                 array(
  156.                     'name'     => WR_Nitro::_( 'Video Source' ),
  157.                     'id'       => 'format_video',
  158.                     'type'     => 'select',
  159.                     'options'  => array(
  160.                         'link' => WR_Nitro::_( 'Video Link' ),
  161.                         'file' => WR_Nitro::_( 'Video Upload File' ),
  162.                     ),
  163.                 ),
  164.                 array(
  165.                     'name'    => WR_Nitro::_( 'Video Link' ),
  166.                     'id'      => 'format_video_url',
  167.                     'desc'    => WR_Nitro::_( '(Support Youtube and Vimeo video)' ),
  168.                     'type'    => 'oembed',
  169.                     'visible' => array( 'format_video', '=', 'link' ),
  170.                 ),
  171.                 array(
  172.                     'name'             => WR_Nitro::_( 'Upload video' ),
  173.                     'id'               => 'format_video_file',
  174.                     'desc'             => WR_Nitro::_( 'Support .mp4 file format only' ),
  175.                     'type'             => 'file_advanced',
  176.                     'max_file_uploads' => 1,
  177.                     'mime_type'        => 'video',
  178.                     'visible'          => array( 'format_video', '=', 'file' ),
  179.                 ),
  180.                 array(
  181.                     'name'     => WR_Nitro::_( 'Audio Source' ),
  182.                     'id'       => 'format_audio',
  183.                     'type'     => 'select',
  184.                     'options'  => array(
  185.                         'link' => WR_Nitro::_( 'Soundcloud Link' ),
  186.                         'file' => WR_Nitro::_( 'Upload audio' ),
  187.                     ),
  188.                 ),
  189.                 array(
  190.                     'name' => WR_Nitro::_( 'Soundcloud Link' ),
  191.                     'id'   => 'format_audio_url',
  192.                     'type' => 'oembed',
  193.                     'visible' => array( 'format_audio', '=', 'link' ),
  194.                 ),
  195.                 array(
  196.                     'name'             => WR_Nitro::_( 'Upload Audio' ),
  197.                     'id'               => 'format_audio_file',
  198.                     'desc'             => WR_Nitro::_( 'Support .mp3 file format only' ),
  199.                     'type'             => 'file_advanced',
  200.                     'max_file_uploads' => 1,
  201.                     'mime_type'        => 'audio',
  202.                     'visible' => array( 'format_audio', '=', 'file' ),
  203.                 ),
  204.                 array(
  205.                     'name' => WR_Nitro::_( 'Quote content' ),
  206.                     'desc' => WR_Nitro::_( 'You can write the Quote content here.' ),
  207.                     'id'   => 'format_quote_content',
  208.                     'type' => 'textarea',
  209.                     'cols' => '30',
  210.                     'rows' => '6',
  211.                 ),
  212.                 array(
  213.                     'name'  => WR_Nitro::_( 'Quote author' ),
  214.                     'id'    => 'format_quote_author',
  215.                     'type'  => 'text',
  216.                     'clone' => false,
  217.                 ),
  218.                 array(
  219.                     'name' => WR_Nitro::_( 'Link to' ),
  220.                     'id'   => 'format_link_url',
  221.                     'type' => 'text',
  222.                 ),
  223.             )
  224.         );
  225.  
  226.         // Additional meta box for page.
  227.         $meta_boxes[] = array(
  228.             'id'         => 'wr_page_option',
  229.             'post_types' => array( 'page' ),
  230.             'title'      => WR_Nitro::_( 'Page Settings' ),
  231.             'context'    => 'normal',
  232.             'priority'   => 'high',
  233.             'autosave'   => true,
  234.             'fields'     => array(
  235.                 array(
  236.                     'name' => WR_Nitro::_( 'Use Global Settings' ),
  237.                     'id'   => 'global_opt',
  238.                     'type' => 'toggle',
  239.                     'std'  => 1,
  240.                     'tab'  => WR_Nitro::_( 'General' ),
  241.                 ),
  242.                 array(
  243.                     'name' => WR_Nitro::_( 'Stretch Row And Content' ),
  244.                     'id'   => 'wr_layout_stretch',
  245.                     'type' => 'toggle',
  246.                     'std'  => 0,
  247.                     'tab'  => WR_Nitro::_( 'General' ),
  248.                 ),
  249.                 array(
  250.                     'name'   => WR_Nitro::_( 'Boxed Layout' ),
  251.                     'id'     => 'wr_layout_boxed',
  252.                     'type'   => 'toggle',
  253.                     'hidden' => array( 'global_opt', '=', 1 ),
  254.                     'std'    => 0,
  255.                     'tab'    => WR_Nitro::_( 'General' ),
  256.                 ),
  257.                 array(
  258.                     'name'   => WR_Nitro::_( 'Background Color' ),
  259.                     'id'     => 'wr_layout_boxed_bg_color',
  260.                     'type'   => 'colors',
  261.                     'hidden' => array( 'wr_layout_boxed', '=', 0 ),
  262.                     'tab'    => WR_Nitro::_( 'General' ),
  263.                 ),
  264.                 array(
  265.                     'name'             => WR_Nitro::_( 'Background Image' ),
  266.                     'id'               => 'wr_layout_boxed_bg_image',
  267.                     'type'             => 'image_advanced',
  268.                     'max_file_uploads' => 1,
  269.                     'hidden'           => array( 'wr_layout_boxed', '=', 0 ),
  270.                     'tab'              => WR_Nitro::_( 'General' ),
  271.                 ),
  272.                 array(
  273.                     'name' => WR_Nitro::_( 'Background Position' ),
  274.                     'id'   => 'wr_layout_boxed_bg_image_position',
  275.                     'type' => 'select',
  276.                     'options'  => array(
  277.                         'left top'      => WR_Nitro::_( 'Left Top' ),
  278.                         'left center'   => WR_Nitro::_( 'Left Center' ),
  279.                         'left bottom'   => WR_Nitro::_( 'Left Bottom' ),
  280.                         'right top'     => WR_Nitro::_( 'Right Top' ),
  281.                         'right center'  => WR_Nitro::_( 'Right Center' ),
  282.                         'right bottom'  => WR_Nitro::_( 'Right Bottom' ),
  283.                         'center top'    => WR_Nitro::_( 'Center Top' ),
  284.                         'center center' => WR_Nitro::_( 'Center Center' ),
  285.                         'center bottom' => WR_Nitro::_( 'Center Bottom' ),
  286.                     ),
  287.                     'visible' => array( 'wr_layout_boxed_bg_image', '>', 0 ),
  288.                     'tab'     => WR_Nitro::_( 'General' ),
  289.                 ),
  290.                 array(
  291.                     'name' => WR_Nitro::_( 'Background Repeat' ),
  292.                     'id'   => 'wr_layout_boxed_bg_image_repeat',
  293.                     'type' => 'select',
  294.                     'options'  => array(
  295.                         'no-repeat' => WR_Nitro::_( 'No Repeat' ),
  296.                         'repeat'    => WR_Nitro::_( 'Repeat' ),
  297.                         'repeat-x'  => WR_Nitro::_( 'Repeat X' ),
  298.                         'repeat-y'  => WR_Nitro::_( 'Repeat Y' ),
  299.                     ),
  300.                     'visible' => array( 'wr_layout_boxed_bg_image', '>', 0 ),
  301.                     'tab'    => WR_Nitro::_( 'General' ),
  302.                 ),
  303.                 array(
  304.                     'name' => WR_Nitro::_( 'Background Size' ),
  305.                     'id'   => 'wr_layout_boxed_bg_image_size',
  306.                     'type' => 'select',
  307.                     'options'  => array(
  308.                         'auto' => WR_Nitro::_( 'auto' ),
  309.                         'cover'   => WR_Nitro::_( 'Cover' ),
  310.                         'contain' => WR_Nitro::_( 'Contain' ),
  311.                         'initial' => WR_Nitro::_( 'Initial' ),
  312.                     ),
  313.                     'visible' => array( 'wr_layout_boxed_bg_image', '>', 0 ),
  314.                     'tab'    => WR_Nitro::_( 'General' ),
  315.                 ),
  316.                 array(
  317.                     'name' => WR_Nitro::_( 'Background Attachment' ),
  318.                     'id'   => 'wr_layout_boxed_bg_image_attachment',
  319.                     'type' => 'select',
  320.                     'options'  => array(
  321.                         'scroll' => WR_Nitro::_( 'Scroll' ),
  322.                         'fixed'  => WR_Nitro::_( 'Fixed' ),
  323.                     ),
  324.                     'visible' => array( 'wr_layout_boxed_bg_image', '>', 0 ),
  325.                     'tab'    => WR_Nitro::_( 'General' ),
  326.                 ),
  327.                 array(
  328.                     'name'   => WR_Nitro::_( 'Parallax Background' ),
  329.                     'id'     => 'wr_layout_boxed_bg_parallax',
  330.                     'type'   => 'toggle',
  331.                     'std'    => 0,
  332.                     'visible' => array( 'wr_layout_boxed_bg_image', '>', 0 ),
  333.                     'tab'    => WR_Nitro::_( 'General' ),
  334.                 ),
  335.                 array(
  336.                     'name'   => WR_Nitro::_( 'Mask Overlay Color' ),
  337.                     'id'     => 'wr_layout_boxed_bg_mask_color',
  338.                     'type'   => 'colors',
  339.                     'std'    => '#000',
  340.                     'hidden' => array( 'wr_layout_boxed', '=', 0 ),
  341.                     'tab'    => WR_Nitro::_( 'General' ),
  342.                 ),
  343.                 array(
  344.                     'name'    => WR_Nitro::_( 'Choose Header Layout' ),
  345.                     'id'      => 'header_layout',
  346.                     'type'    => 'select',
  347.                     'options' => $header_layout,
  348.                     'hidden'  => array( 'global_opt', '=', 1 ),
  349.                     'tab'     => WR_Nitro::_( 'General' ),
  350.                 ),
  351.                 array(
  352.                     'type'   => 'divider',
  353.                     'id'     => 'divider_01',
  354.                     'hidden' => array( 'global_opt', '=', 1 ),
  355.                     'tab'    => WR_Nitro::_( 'General' ),
  356.                 ),
  357.                 array(
  358.                     'name' => WR_Nitro::_( 'Page Layout' ),
  359.                     'id'   => 'page_layout',
  360.                     'type' => 'image_select',
  361.                     'options'  => array(
  362.                         'left-sidebar'  => get_template_directory_uri() . '/assets/woorockets/images/admin/lc.png',
  363.                         'no-sidebar'    => get_template_directory_uri() . '/assets/woorockets/images/admin/c.png',
  364.                         'right-sidebar' => get_template_directory_uri() . '/assets/woorockets/images/admin/cr.png',
  365.                     ),
  366.                     'std' => 'no-sidebar',
  367.                     'hidden' => array( 'global_opt', '=', 1 ),
  368.                     'tab'    => WR_Nitro::_( 'General' ),
  369.                 ),
  370.                 array(
  371.                     'name'    => WR_Nitro::_( 'Select Sidebar' ),
  372.                     'id'      => 'page_layout_sidebar',
  373.                     'type'    => 'select',
  374.                     'options' => WR_Nitro_Helper::get_sidebars(),
  375.                     'std'     => 'primary-sidebar',
  376.                     'hidden'  => array( 'page_layout', '=', 'no-sidebar' ),
  377.                     'tab'     => WR_Nitro::_( 'General' ),
  378.                 ),
  379.                 array(
  380.                     'name'       => WR_Nitro::_( 'Sidebar Width' ),
  381.                     'id'         => 'page_layout_sidebar_width',
  382.                     'type'       => 'slider',
  383.                     'suffix'     => WR_Nitro::_( ' Columns' ),
  384.                     'js_options' => array(
  385.                         'min'  => 2,
  386.                         'max'  => 6,
  387.                         'step' => 1,
  388.                     ),
  389.                     'std'    => 3,
  390.                     'hidden' => array( 'page_layout', '=', 'no-sidebar' ),
  391.                     'tab'    => WR_Nitro::_( 'General' ),
  392.                 ),
  393.                 array(
  394.                     'type'   => 'divider',
  395.                     'id'     => 'divider_02',
  396.                     'hidden' => array( 'global_opt', '=', 1 ),
  397.                     'tab'    => WR_Nitro::_( 'General' ),
  398.                 ),
  399.                 array(
  400.                     'name' => WR_Nitro::_( 'Content Width' ),
  401.                     'id'   => 'wr_layout_content_width_unit',
  402.                     'type' => 'radio',
  403.                     'options'  => array(
  404.                         'pixel'      => WR_Nitro::_( 'px' ),
  405.                         'percentage' => WR_Nitro::_( '%' ),
  406.                     ),
  407.                     'std'    => 'pixel',
  408.                     'hidden' => array( 'global_opt', '=', 1 ),
  409.                     'tab'    => WR_Nitro::_( 'General' ),
  410.                 ),
  411.                 array(
  412.                     'name'       => '&nbsp;',
  413.                     'id'         => 'wr_layout_content_width',
  414.                     'type'       => 'slider',
  415.                     'suffix'     => 'px',
  416.                     'js_options' => array(
  417.                         'min'  => 760,
  418.                         'max'  => 1920,
  419.                         'step' => 10,
  420.                     ),
  421.                     'std'    => 1170,
  422.                     'hidden' => array( 'wr_layout_content_width_unit', '!=', 'pixel' ),
  423.                     'tab'    => WR_Nitro::_( 'General' ),
  424.                 ),
  425.                 array(
  426.                     'name'       => '&nbsp;',
  427.                     'id'         => 'wr_layout_content_width_percentage',
  428.                     'type'       => 'slider',
  429.                     'suffix'     => '%',
  430.                     'js_options' => array(
  431.                         'min'  => 20,
  432.                         'max'  => 100,
  433.                         'step' => 1,
  434.                     ),
  435.                     'std'    => 100,
  436.                     'hidden' => array( 'wr_layout_content_width_unit', '!=', 'percentage' ),
  437.                     'tab'    => WR_Nitro::_( 'General' ),
  438.                 ),
  439.                 array(
  440.                     'name'       => WR_Nitro::_( 'Gutter Width' ),
  441.                     'id'         => 'wr_layout_gutter_width',
  442.                     'type'       => 'slider',
  443.                     'suffix'     => 'px',
  444.                     'js_options' => array(
  445.                         'min'  => 20,
  446.                         'max'  => 60,
  447.                         'step' => 10,
  448.                     ),
  449.                     'std'    => 30,
  450.                     'hidden' => array( 'global_opt', '=', 1 ),
  451.                     'tab'    => WR_Nitro::_( 'General' ),
  452.                 ),
  453.                 array(
  454.                     'name'       => WR_Nitro::_( 'Offset Width' ),
  455.                     'id'         => 'wr_layout_offset',
  456.                     'type'       => 'slider',
  457.                     'suffix'     => 'px',
  458.                     'js_options' => array(
  459.                         'min'  => 0,
  460.                         'max'  => 100,
  461.                         'step' => 5,
  462.                     ),
  463.                     'std'    => 0,
  464.                     'hidden' => array( 'wr_layout_boxed', '=', 1 ),
  465.                     'tab'    => WR_Nitro::_( 'General' ),
  466.                 ),
  467.                 array(
  468.                     'name'   => WR_Nitro::_( 'Offset Background Color' ),
  469.                     'id'     => 'wr_layout_offset_color',
  470.                     'type'   => 'colors',
  471.                     'std'    => '#000',
  472.                     'hidden' => array( 'wr_layout_boxed', '=', 1 ),
  473.                     'tab'    => WR_Nitro::_( 'General' ),
  474.                 ),
  475.                 array(
  476.                     'name' => WR_Nitro::_( 'Enable Title Of Page' ),
  477.                     'id'   => 'wr_page_title',
  478.                     'type' => 'toggle',
  479.                     'std'  => 1,
  480.                     'hidden' => array( 'global_opt', '=', 1 ),
  481.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  482.                 ),
  483.                 array(
  484.                     'name' => WR_Nitro::_( 'Page Title Layout' ),
  485.                     'id'   => 'wr_page_title_layout',
  486.                     'type' => 'select',
  487.                     'options'  => array(
  488.                         '1' => WR_Nitro::_( 'Layout 1' ),
  489.                         '2' => WR_Nitro::_( 'Layout 2' ),
  490.                     ),
  491.                     'std'    => '1',
  492.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  493.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  494.                 ),
  495.                 array(
  496.                     'name' => WR_Nitro::_( 'Full Section' ),
  497.                     'id'   => 'wr_page_title_fullscreen',
  498.                     'type' => 'toggle',
  499.                     'std'  => 0,
  500.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  501.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  502.                 ),
  503.                 array(
  504.                     'name' => WR_Nitro::_( 'Show Breadcrumb' ),
  505.                     'id'   => 'wr_page_title_breadcrumbs',
  506.                     'type' => 'toggle',
  507.                     'std'  => 0,
  508.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  509.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  510.                 ),
  511.                 array(
  512.                     'name'    => WR_Nitro::_( 'Link Color' ),
  513.                     'id'      => 'wr_page_title_link_colors',
  514.                     'type'    => 'colors',
  515.                     'tab'     => WR_Nitro::_( 'Page Title' ),
  516.                     'options' => array(
  517.                         'normal' => WR_Nitro::_( 'Normal State' ),
  518.                         'hover'  => WR_Nitro::_( 'Hover State' ),
  519.                     ),
  520.                     'std'     => array(
  521.                         'normal' => '#d6aa74',
  522.                         'hover'  => '#d6aa74',
  523.                     ),
  524.                     'hidden'  => array( 'wr_page_title', '=', 0 ),
  525.                 ),
  526.                 array(
  527.                     'name' => WR_Nitro::_( 'Content Alignment' ),
  528.                     'id'   => 'wr_page_title_align',
  529.                     'type' => 'radio',
  530.                     'options'  => array(
  531.                         'left'   => WR_Nitro::_( 'Left' ),
  532.                         'center' => WR_Nitro::_( 'Center' ),
  533.                         'right'  => WR_Nitro::_( 'Right' ),
  534.                     ),
  535.                     'std'    => 'left',
  536.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  537.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  538.                 ),
  539.                 array(
  540.                     'name'   => WR_Nitro::_( 'Separator Color' ),
  541.                     'id'     => 'wr_page_title_sep_color',
  542.                     'type'   => 'colors',
  543.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  544.                     'std'    => '#e9e9e9',
  545.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  546.                 ),
  547.                 array(
  548.                     'name'       => WR_Nitro::_( 'Min Height' ),
  549.                     'id'         => 'wr_page_title_min_height',
  550.                     'type'       => 'slider',
  551.                     'suffix'     => 'px',
  552.                     'js_options' => array(
  553.                         'min'  => 225,
  554.                         'max'  => 500,
  555.                         'step' => 50,
  556.                     ),
  557.                     'std'    => 225,
  558.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  559.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  560.                 ),
  561.                 array(
  562.                     'type'   => 'divider',
  563.                     'id'     => 'divider_03',
  564.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  565.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  566.                 ),
  567.                 array(
  568.                     'name'   => WR_Nitro::_( 'Background Color' ),
  569.                     'id'     => 'wr_page_title_bg_color',
  570.                     'type'   => 'colors',
  571.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  572.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  573.                 ),
  574.                 array(
  575.                     'name'             => WR_Nitro::_( 'Background Image' ),
  576.                     'id'               => 'wr_page_title_bg_image',
  577.                     'type'             => 'image_advanced',
  578.                     'max_file_uploads' => 1,
  579.                     'hidden'           => array( 'wr_page_title', '=', 0 ),
  580.                     'tab'              => WR_Nitro::_( 'Page Title' ),
  581.                 ),
  582.                 array(
  583.                     'name' => WR_Nitro::_( 'Background Position' ),
  584.                     'id'   => 'wr_page_title_bg_image_position',
  585.                     'type' => 'select',
  586.                     'options'  => array(
  587.                         'left top'      => WR_Nitro::_( 'Left Top' ),
  588.                         'left center'   => WR_Nitro::_( 'Left Center' ),
  589.                         'left bottom'   => WR_Nitro::_( 'Left Bottom' ),
  590.                         'right top'     => WR_Nitro::_( 'Right Top' ),
  591.                         'right center'  => WR_Nitro::_( 'Right Center' ),
  592.                         'right bottom'  => WR_Nitro::_( 'Right Bottom' ),
  593.                         'center top'    => WR_Nitro::_( 'Center Top' ),
  594.                         'center center' => WR_Nitro::_( 'Center Center' ),
  595.                         'center bottom' => WR_Nitro::_( 'Center Bottom' ),
  596.                     ),
  597.                     'hidden' => array( 'wr_page_title_bg_image', 0 ),
  598.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  599.                 ),
  600.                 array(
  601.                     'name' => WR_Nitro::_( 'Background Repeat' ),
  602.                     'id'   => 'wr_page_title_bg_image_repeat',
  603.                     'type' => 'select',
  604.                     'options'  => array(
  605.                         'no-repeat' => WR_Nitro::_( 'No Repeat' ),
  606.                         'repeat'    => WR_Nitro::_( 'Repeat' ),
  607.                         'repeat-x'  => WR_Nitro::_( 'Repeat X' ),
  608.                         'repeat-y'  => WR_Nitro::_( 'Repeat Y' ),
  609.                     ),
  610.                     'hidden' => array( 'wr_page_title_bg_image', 0 ),
  611.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  612.                 ),
  613.                 array(
  614.                     'name' => WR_Nitro::_( 'Background Size' ),
  615.                     'id'   => 'wr_page_title_bg_image_size',
  616.                     'type' => 'select',
  617.                     'options'  => array(
  618.                         'auto' => WR_Nitro::_( 'auto' ),
  619.                         'cover'   => WR_Nitro::_( 'Cover' ),
  620.                         'contain' => WR_Nitro::_( 'Contain' ),
  621.                         'initial' => WR_Nitro::_( 'Initial' ),
  622.                     ),
  623.                     'hidden' => array( 'wr_page_title_bg_image', 0 ),
  624.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  625.                 ),
  626.                 array(
  627.                     'name' => WR_Nitro::_( 'Background Attachment' ),
  628.                     'id'   => 'wr_page_title_bg_image_attachment',
  629.                     'type' => 'select',
  630.                     'options'  => array(
  631.                         'scroll' => WR_Nitro::_( 'Scroll' ),
  632.                         'fixed'  => WR_Nitro::_( 'Fixed' ),
  633.                     ),
  634.                     'hidden' => array( 'wr_page_title_bg_image', 0 ),
  635.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  636.                 ),
  637.                 array(
  638.                     'name'   => WR_Nitro::_( 'Mask Overlay Color' ),
  639.                     'id'     => 'wr_page_title_mask_color',
  640.                     'type'   => 'colors',
  641.                     'std'    => 'rgba(0, 0, 0, 0)',
  642.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  643.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  644.                 ),
  645.                 array(
  646.                     'name'   => WR_Nitro::_( 'Parallax Background' ),
  647.                     'id'     => 'wr_page_title_parallax',
  648.                     'type'   => 'toggle',
  649.                     'std'    => 1,
  650.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  651.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  652.                 ),
  653.                 array(
  654.                     'type'   => 'divider',
  655.                     'id'     => 'divider_04',
  656.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  657.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  658.                 ),
  659.                 array(
  660.                     'name'   => WR_Nitro::_( 'Heading Fonts' ),
  661.                     'id'     => 'wr_page_title_heading_font',
  662.                     'type'   => 'typography',
  663.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  664.                     'std'    => array(
  665.                         'family'    => 'Lato',
  666.                         'bold'      => 0,
  667.                         'italic'    => 0,
  668.                         'underline' => 0,
  669.                         'uppercase' => 0,
  670.                         'color'     => '#646464',
  671.                     ),
  672.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  673.                 ),
  674.                 array(
  675.                     'name'       => WR_Nitro::_( 'Heading Text Size' ),
  676.                     'id'         => 'wr_page_title_heading_font_size',
  677.                     'desc'       => WR_Nitro::_( '' ),
  678.                     'type'       => 'slider',
  679.                     'suffix'     => 'px',
  680.                     'js_options' => array(
  681.                         'min'  => 10,
  682.                         'max'  => 100,
  683.                         'step' => 1,
  684.                     ),
  685.                     'std'    => 44,
  686.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  687.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  688.                 ),
  689.                 array(
  690.                     'name'       => WR_Nitro::_( 'Heading Line Height' ),
  691.                     'id'         => 'wr_page_title_heading_line_height',
  692.                     'desc'       => WR_Nitro::_( '' ),
  693.                     'type'       => 'slider',
  694.                     'suffix'     => 'px',
  695.                     'js_options' => array(
  696.                         'min'  => 10,
  697.                         'max'  => 100,
  698.                         'step' => 1,
  699.                     ),
  700.                     'std'    => 24,
  701.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  702.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  703.                 ),
  704.                 array(
  705.                     'name'       => WR_Nitro::_( 'Heading Letter Spacing' ),
  706.                     'id'         => 'wr_page_title_heading_letter_spacing',
  707.                     'desc'       => WR_Nitro::_( '' ),
  708.                     'type'       => 'slider',
  709.                     'suffix'     => 'px',
  710.                     'js_options' => array(
  711.                         'min'  => 0,
  712.                         'max'  => 10,
  713.                         'step' => 1,
  714.                     ),
  715.                     'std'    => 0,
  716.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  717.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  718.                 ),
  719.                 array(
  720.                     'type'   => 'divider',
  721.                     'id'     => 'divider_05',
  722.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  723.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  724.                 ),
  725.                 array(
  726.                     'name'   => WR_Nitro::_( 'Sub Heading Fonts' ),
  727.                     'id'     => 'wr_page_title_sub_heading_font',
  728.                     'type'   => 'typography',
  729.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  730.                     'std'    => array(
  731.                         'family'    => 'Lato',
  732.                         'bold'      => 0,
  733.                         'italic'    => 0,
  734.                         'underline' => 0,
  735.                         'uppercase' => 0,
  736.                         'color'     => '#646464',
  737.                     ),
  738.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  739.                 ),
  740.                 array(
  741.                     'name'       => WR_Nitro::_( 'Sub Heading Text Size' ),
  742.                     'id'         => 'wr_page_title_sub_heading_font_size',
  743.                     'desc'       => WR_Nitro::_( 'Select grid to display sidebar.' ),
  744.                     'type'       => 'slider',
  745.                     'suffix'     => 'px',
  746.                     'js_options' => array(
  747.                         'min'  => 10,
  748.                         'max'  => 100,
  749.                         'step' => 1,
  750.                     ),
  751.                     'std'    => 44,
  752.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  753.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  754.                 ),
  755.                 array(
  756.                     'name'       => WR_Nitro::_( 'Sub Heading Line Height' ),
  757.                     'id'         => 'wr_page_title_sub_heading_line_height',
  758.                     'desc'       => WR_Nitro::_( 'Select grid to display sidebar.' ),
  759.                     'type'       => 'slider',
  760.                     'suffix'     => 'px',
  761.                     'js_options' => array(
  762.                         'min'  => 10,
  763.                         'max'  => 100,
  764.                         'step' => 1,
  765.                     ),
  766.                     'std'    => 24,
  767.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  768.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  769.                 ),
  770.                 array(
  771.                     'name'       => WR_Nitro::_( 'Sub Heading Letter Spacing' ),
  772.                     'id'         => 'wr_page_title_sub_heading_letter_spacing',
  773.                     'desc'       => WR_Nitro::_( 'Select grid to display sidebar.' ),
  774.                     'type'       => 'slider',
  775.                     'suffix'     => 'px',
  776.                     'js_options' => array(
  777.                         'min'  => 0,
  778.                         'max'  => 10,
  779.                         'step' => 1,
  780.                     ),
  781.                     'std'    => 0,
  782.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  783.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  784.                 ),
  785.                 array(
  786.                     'type'   => 'divider',
  787.                     'id'     => 'divider_06',
  788.                     'tab'    => WR_Nitro::_( 'Page Title' ),
  789.                     'hidden' => array( 'wr_page_title', '=', 0 ),
  790.                 ),
  791.                 array(
  792.                     'name'   => WR_Nitro::_( 'Enable Page Scroll Effects' ),
  793.                     'id'     => 'page_scroll',
  794.                     'type'   => 'toggle',
  795.                     'std'    => 0,
  796.                     'hidden' => array( 'global_opt', '=', 1 ),
  797.                     'tab'    => WR_Nitro::_( 'Page Scroll Effects' ),
  798.                 ),
  799.                 array(
  800.                     'name'   => WR_Nitro::_( 'Enable Navigation' ),
  801.                     'id'     => 'page_scroll_navigation',
  802.                     'type'   => 'toggle',
  803.                     'std'    => 1,
  804.                     'hidden' => array( 'page_scroll', '=', 0 ),
  805.                     'tab'    => WR_Nitro::_( 'Page Scroll Effects' ),
  806.                 ),
  807.                 array(
  808.                     'name'   => WR_Nitro::_( 'Hijacking' ),
  809.                     'id'     => 'page_scroll_hijacking',
  810.                     'type'   => 'toggle',
  811.                     'std'    => 1,
  812.                     'hidden' => array( 'page_scroll', '=', 0 ),
  813.                     'tab'    => WR_Nitro::_( 'Page Scroll Effects' ),
  814.                 ),
  815.                 array(
  816.                     'name' => WR_Nitro::_( 'Effects' ),
  817.                     'id'   => 'page_scroll_effect',
  818.                     'type' => 'select',
  819.                     'options'  => array(
  820.                         'none'      => WR_Nitro::_( 'None' ),
  821.                         'scaleDown' => WR_Nitro::_( 'Scale Down' ),
  822.                         'gallery'   => WR_Nitro::_( 'Gallery' ),
  823.                         'rotate'    => WR_Nitro::_( 'Rotate' ),
  824.                         'opacity'   => WR_Nitro::_( 'Opacity' ),
  825.                         'fixed'     => WR_Nitro::_( 'Fixed' ),
  826.                     ),
  827.                     'hidden' => array( 'page_scroll', '=', 0 ),
  828.                     'tab'    => WR_Nitro::_( 'Page Scroll Effects' ),
  829.                 ),
  830.             )
  831.         );
  832.  
  833.         // Get current theme customize options.
  834.         $theme_options = WR_Nitro_Customize::get_theme_options();
  835.  
  836.         // Apply current theme customize options as default values for page options.
  837.         foreach ( $meta_boxes as $i => $meta_box ) {
  838.             if ( isset( $meta_box['fields'] ) ) {
  839.                 foreach ( $meta_box['fields'] as $k => $field ) {
  840.                     if ( isset( $field['id'] ) && isset( $theme_options[ $field['id'] ] ) ) {
  841.                         if ( is_bool( $theme_options[ $field['id'] ] ) ) {
  842.                             $meta_boxes[ $i ]['fields'][ $k ]['std'] = $theme_options[ $field['id'] ] ? 1 : 0;
  843.                         } else {
  844.                             $meta_boxes[ $i ]['fields'][ $k ]['std'] = $theme_options[ $field['id'] ];
  845.                         }
  846.                     }
  847.                 }
  848.             }
  849.         }
  850.  
  851.         return $meta_boxes;
  852.     }
  853.  
  854.     /**
  855.      * Visible paramameter of post format.
  856.      *
  857.      * @param   array  $conditions  Current conditions.
  858.      *
  859.      * @return  array
  860.      */
  861.     public static function outside_conditions( $conditions ) {
  862.         // Format gallery
  863.         $conditions['format_gallery'] = array(
  864.             'visible' => array( 'post_format', 'gallery' ),
  865.         );
  866.  
  867.         // Format video
  868.         $conditions['format_video'] = array(
  869.             'visible' => array( 'post_format', 'video' ),
  870.         );
  871.  
  872.         // Format audio
  873.         $conditions['format_audio'] = array(
  874.             'visible' => array( 'post_format', 'audio' ),
  875.         );
  876.  
  877.         // Format quote
  878.         $conditions['format_quote_content'] = array(
  879.             'visible' => array( 'post_format', 'quote' ),
  880.         );
  881.         $conditions['format_quote_author'] = array(
  882.             'visible' => array( 'post_format', 'quote' ),
  883.         );
  884.  
  885.         // Format link
  886.         $conditions['format_link_url'] = array(
  887.             'visible' => array( 'post_format', 'link' ),
  888.         );
  889.  
  890.         return $conditions;
  891.     }
  892.  
  893.     /**
  894.      * Method to verify page option values before saving.
  895.      *
  896.      * @param   null|bool  $check       Whether to allow updating metadata for the given type.
  897.      * @param   int        $object_id   Object ID.
  898.      * @param   string     $meta_key    Meta key.
  899.      * @param   mixed      $meta_value  Meta value. Must be serializable if non-scalar.
  900.      * @param   mixed      $prev_value  Optional. If specified, only update existing metadata entries with the specified value.
  901.      *                                  Otherwise, update all entries.
  902.      *
  903.      * @return  mixed
  904.      */
  905.     public static function verify( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
  906.         // Get current theme customize options.
  907.         $theme_options = WR_Nitro_Customize::get_theme_options();
  908.  
  909.         if ( isset( $theme_options[ $meta_key ] ) ) {
  910.             if ( is_bool( $theme_options[ $meta_key ] ) ) {
  911.                 if ( $meta_value == ( $theme_options[ $meta_key ] ? 1 : 0 ) ) {
  912.                     $check = false;
  913.                 }
  914.             } elseif ( is_array( $theme_options[ $meta_key ] ) ) {
  915.                 if ( ! count( array_diff( $theme_options[ $meta_key ], ( array ) $meta_value ) ) ) {
  916.                     $check = false;
  917.                 }
  918.             } elseif ( $meta_value == $theme_options[ $meta_key ] ) {
  919.                 $check = false;
  920.             }
  921.         }
  922.  
  923.         if ( false === $check ) {
  924.             // Remove meta data.
  925.             delete_post_meta( $object_id, $meta_key );
  926.         }
  927.  
  928.         return $check;
  929.     }
  930.  
  931.     /**
  932.      * Method to synchronize default options values with current theme customizer values.
  933.      *
  934.      * @param   mixed  $meta       Whether to allow updating metadata for the given type.
  935.      * @param   array        $field   Object ID.
  936.      * @param   boolean     $saved    Meta key.
  937.      *
  938.      * @return  mixed
  939.      */
  940.     public static function get_meta( $meta, $field, $saved ) {
  941.         if ( '' == $meta ) {
  942.             // Get current theme customize options.
  943.             $theme_options = WR_Nitro_Customize::get_theme_options();
  944.  
  945.             if ( isset( $theme_options[ $field['id'] ] ) ) {
  946.                 $meta = $theme_options[ $field['id'] ];
  947.             }
  948.         }
  949.  
  950.         return $meta;
  951.     }
  952.  
  953.     /**
  954.      * Callback function to show fields in meta box.
  955.      *
  956.      * @return  void
  957.      */
  958.     function show() {
  959.         global $post;
  960.  
  961.         $saved = self::has_been_saved( $post->ID, $this->fields );
  962.  
  963.         // Container
  964.         printf(
  965.             '<div class="rwmb-meta-box" data-autosave="%s">',
  966.             $this->meta_box['autosave'] ? 'true' : 'false'
  967.         );
  968.  
  969.         wp_nonce_field( "rwmb-save-{$this->meta_box['id']}", "nonce_{$this->meta_box['id']}" );
  970.  
  971.         // Allow users to add custom code before meta box content
  972.         // 1st action applies to all meta boxes
  973.         // 2nd action applies to only current meta box
  974.         do_action( 'rwmb_before', $this );
  975.         do_action( "rwmb_before_{$this->meta_box['id']}", $this );
  976.  
  977.         // Print HTML code for all fields
  978.         $current_tab = null;
  979.         $tab_heading = $tab_body = '';
  980.  
  981.         foreach ( $this->fields as $field ) {
  982.             if ( isset( $field['tab'] ) && $current_tab != $field['tab'] ) {
  983.                 $tab_id = sanitize_key( $field['tab'] );
  984.  
  985.                 // Update tab heading.
  986.                 $tab_heading .= '
  987.                     <li class="' . ( empty( $current_tab ) ? 'active' : '' ) . '">
  988.                         <a href="#' . $tab_id . '">' . $field['tab'] . '</a>
  989.                     </li>';
  990.  
  991.                 // Update tab body.
  992.                 $tab_body .= ( empty( $current_tab ) ? '' : '</div>' ) . '
  993.                     <div id="' . $tab_id . '" class="wr-nitro-tabs-content ' . ( empty( $current_tab ) ? '' : 'hidden' ) . '">';
  994.  
  995.                 $current_tab = $field['tab'];
  996.             }
  997.  
  998.             // Start output buffering to hold field output.
  999.             ob_start();
  1000.  
  1001.             call_user_func( array( self::get_class_name( $field ), 'show' ), $field, $saved );
  1002.  
  1003.             $tab_body .= ob_get_contents();
  1004.  
  1005.             ob_end_clean();
  1006.         }
  1007.  
  1008.         if ( ! empty( $tab_heading ) ) {
  1009.             echo '
  1010.                 <div class="wr-nitro-tabs" id="' . $this->meta_box['id'] . '">
  1011.                     <ul class="wr-nitro-tabs-nav">' . $tab_heading . '</ul>
  1012.                     ' . $tab_body . '</div>
  1013.                 </div>
  1014.                 <script>
  1015.                     (function($) {
  1016.                         $("#' . $this->meta_box['id'] . '").on("click", ".wr-nitro-tabs-nav a", function() {
  1017.                             $("#' . $this->meta_box['id'] . ' .wr-nitro-tabs-nav li").removeClass("active");
  1018.                             $(this).parent().addClass("active");
  1019.                             $("#' . $this->meta_box['id'] . ' .wr-nitro-tabs-content").addClass("hidden").filter($(this).attr("href")).removeClass("hidden");
  1020.                         });
  1021.                     })(jQuery);
  1022.                 </script>';
  1023.         } else {
  1024.             echo '' . $tab_body;
  1025.         }
  1026.  
  1027.         // Include validation settings for this meta-box
  1028.         if ( isset( $this->validation ) && $this->validation ) {
  1029.             echo '
  1030.                 <script>
  1031.                 if ( typeof rwmb == "undefined" )
  1032.                 {
  1033.                     var rwmb = {
  1034.                         validationOptions : jQuery.parseJSON( \'' , json_encode( $this->validation ) , '\' ),
  1035.                         summaryMessage : "' , esc_js( __( 'Please correct the errors highlighted below and try again.', 'meta-box' ) ) , '"
  1036.                     };
  1037.                 }
  1038.                 else
  1039.                 {
  1040.                     var tempOptions = jQuery.parseJSON( \'' , json_encode( $this->validation ) . '\' );
  1041.                     jQuery.extend( true, rwmb.validationOptions, tempOptions );
  1042.                 }
  1043.                 </script>
  1044.             ';
  1045.         }
  1046.  
  1047.         // Allow users to add custom code after meta box content
  1048.         // 1st action applies to all meta boxes
  1049.         // 2nd action applies to only current meta box
  1050.         do_action( 'rwmb_after', $this );
  1051.         do_action( "rwmb_after_{$this->meta_box['id']}", $this );
  1052.  
  1053.         // End container
  1054.         echo '</div>';
  1055.     }
  1056. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement