Advertisement
longnguyenwp

Martin Rybos

Feb 2nd, 2021
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.09 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: Plugin by Divart
  4. * Plugin URI: https://www.divart.sk/
  5. * Description: This is the very first plugin I ever created.
  6. * Version: 1.0
  7. * Author: Martin z Divartu
  8. * Author URI: https://www.divart.sk/
  9. **/
  10. ?>
  11. <?php
  12.  
  13. add_theme_support( 'woocommerce', array(
  14. 'thumbnail_image_width' => 550,
  15. 'single_image_width' => 722,
  16. ) );
  17.  
  18. register_activation_hook( __FILE__, function() {
  19.   add_option('Activated_Plugin','Plugin-Slug');
  20.   /* activation code here */
  21. });
  22.  
  23. add_action('admin_init','load_plugin');
  24. function load_plugin() {
  25.     if(is_admin()&&get_option('Activated_Plugin')=='Plugin-Slug') {
  26.      delete_option('Activated_Plugin');
  27.      /* do some stuff once right after activation */
  28.     }
  29. }
  30.  
  31. function tutsplus_register_post_type() {
  32.  
  33.        
  34.     // movies
  35.     $labels = array(
  36.         'name' => __( 'DiSliders' , 'tutsplus' ),
  37.         'singular_name' => __( 'DiSlider' , 'tutsplus' ),
  38.         'add_new' => __( 'New Slide' , 'tutsplus' ),
  39.         'add_new_item' => __( 'Add New Slide' , 'tutsplus' ),
  40.         'edit_item' => __( 'Edit Slide' , 'tutsplus' ),
  41.         'new_item' => __( 'New Slide' , 'tutsplus' ),
  42.         'view_item' => __( 'View Slide' , 'tutsplus' ),
  43.         'search_items' => __( 'Search Slides' , 'tutsplus' ),
  44.         'not_found' =>  __( 'No Slide Found' , 'tutsplus' ),
  45.         'not_found_in_trash' => __( 'No Slides found in Trash' , 'tutsplus' ),
  46.     );
  47.     $args = array(
  48.         'labels' => $labels,
  49.         'has_archive' => true,
  50.         'public' => true,
  51.         'hierarchical' => false,
  52.         'supports' => array(
  53.             'title',
  54.             'thumbnail',
  55.              
  56.            
  57.         ),
  58.         'rewrite'   => array( 'slug' => 'dislider' ),
  59.         'show_in_rest' => true
  60.  
  61.     );
  62.     register_post_type( 'divart_slider', $args );
  63.          
  64. }
  65.  
  66. add_action( 'init', 'tutsplus_register_post_type' );
  67.  
  68. //gallery
  69. //gallery
  70.  
  71. function gallery_register_post_type() {
  72.  
  73.        
  74.     // movies
  75.     $labels = array(
  76.         'name' => __( 'DiGalleries' , 'tutsplusss' ),
  77.         'singular_name' => __( 'DiGallery' , 'tutsplusss' ),
  78.         'add_new' => __( 'New Gallery' , 'tutsplusss' ),
  79.         'add_new_item' => __( 'Add New Gallery' , 'tutsplusss' ),
  80.         'edit_item' => __( 'Edit Gallery' , 'tutsplusss' ),
  81.         'new_item' => __( 'New Gallery' , 'tutsplusss' ),
  82.         'view_item' => __( 'View Gallery' , 'tutsplusss' ),
  83.         'search_items' => __( 'Search Gallery' , 'tutsplusss' ),
  84.         'not_found' =>  __( 'No Gallery Found' , 'tutsplusss' ),
  85.         'not_found_in_trash' => __( 'No Gallery found in Trash' , 'tutsplusss' ),
  86.     );
  87.     $args = array(
  88.         'labels' => $labels,
  89.         'has_archive' => true,
  90.         'public' => true,
  91.         'hierarchical' => false,
  92.         'supports' => array(
  93.             'title',
  94.             'thumbnail',
  95.              
  96.            
  97.         ),
  98.         'rewrite'   => array( 'slug' => 'gallery' ),
  99.         'show_in_rest' => true
  100.  
  101.     );
  102.     register_post_type( 'divart_gallery', $args );
  103.          
  104. }
  105.  
  106. add_action( 'init', 'gallery_register_post_type' );  
  107.  
  108. //gallery
  109. //gallery
  110.  
  111. //mainsettingspage
  112. // Register a theme options page
  113. add_filter( 'mb_settings_pages', function ( $settings_pages ) {
  114.     $settings_pages[] = array(
  115.         'id'          => 'dimainsettings',
  116.         'option_name' => 'DiSettings',
  117.         'menu_title'  => 'DiSettings',  
  118.         'icon_url'    => 'dashicons-edit',
  119.         'style'       => 'no-boxes',
  120.         'columns'     => 1,
  121.         'tabs'        => array(
  122.             'general' => 'General Settings',
  123.             'faq'     => 'FAQ & Help',
  124.         ),
  125.     );
  126.     return $settings_pages;
  127. });
  128.  
  129. //mainsettingspage
  130.  
  131. add_filter( 'rwmb_meta_boxes', 'meta_box_group_demo_register' );
  132. function meta_box_group_demo_register( $meta_boxes ) {
  133.    
  134. //mainsettingspage
  135.  
  136. $meta_boxes[] = array(
  137.         'id'             => 'general',
  138.         'title'          => 'General',
  139.         'settings_pages' => 'dimainsettings',
  140.         'tab'            => 'general',
  141.         'fields' => array(
  142.             array(
  143.                 'name' => 'Logo',
  144.                 'id'   => 'logo',
  145.                 'type' => 'file_input',
  146.             ),
  147.            
  148.             array(
  149.                 'name'        => 'Meta Description',
  150.                 'id'          => 'meta_description',
  151.                'type'        => 'textarea',
  152.                 'placeholder' => 'Meta Description',
  153.                 'rows'        => 4,
  154.             ),
  155.            
  156.             array(
  157.                 'name'        => 'Meta Keywords',
  158.                 'id'          => 'meta_keywords',
  159.                'type'        => 'textarea',
  160.                 'placeholder' => 'Meta Description',
  161.                 'rows'        => 4,
  162.             ),
  163.            
  164.            
  165.         ),
  166.     );
  167.    
  168.     $meta_boxes[] = array(
  169.         'id'             => 'info',
  170.         'title'          => 'Theme Info',
  171.         'settings_pages' => 'dimainsettings',
  172.         'tab'            => 'faq',
  173.         'fields'         => array(
  174.             array(
  175.                 'type' => 'custom_html',
  176.                 'std'  => 'Having questions? Check out our documentation',
  177.             ),
  178.         ),
  179.     );
  180.  
  181. //mainsettingspage  
  182.    
  183.     //gallery
  184.     //gallery
  185.    
  186. $meta_boxes[] = array(
  187.         'title'  => 'Divart Gallery',
  188.         'post_types' => ['divart_gallery'],
  189.         'fields' => array(
  190.             array(
  191.                 'id'     => 'digallery',
  192.                 // Group field
  193.                 'type'   => 'group',
  194.                 // Clone whole group?
  195.                 'clone'  => false,
  196.                 // Drag and drop clones to reorder them?
  197.                 'sort_clone' => false,
  198.                 // Sub-fields
  199.                 'collapsible' => false,
  200.                 'group_title' => 'Gallery', // ID of the subfield
  201.                 'save_state' => true,
  202.                 'fields' => array(
  203.                
  204.                  array(
  205.    
  206.     'name'             => 'Add Gallery',
  207.     'id'               => 'gallimage',
  208.     'type'             => 'image_advanced',
  209.  
  210.     // Delete image from Media Library when remove it from post meta?
  211.     // Note: it might affect other posts if you use same image for multiple posts
  212.     'force_delete'     => false,
  213.  
  214.     // Do not show how many images uploaded/remaining.
  215.     'max_status'       => 'false',
  216.  
  217.     // Image size that displays in the edit page. Possible sizes small,medium,large,original
  218.     'image_size'       => 'thumbnail',
  219. ),
  220.                
  221.                
  222.                     array(
  223.                      'name'             => 'Background Color',
  224.                       'id'               => 'bgcolor',  
  225.                       'type'             => 'color',
  226.        
  227.                 ),  
  228.                
  229.                
  230.                
  231.                           // Nested group level 2
  232.                  
  233.              
  234.                 ),
  235.             ),
  236.         ),
  237.     );  
  238.    
  239.    
  240.     //gall settings
  241.    
  242.     $meta_boxes[] = array(
  243.         'title'  => 'Page Settings',
  244.         'post_types' => ['divart_gallery'],
  245.         'fields' => array(
  246.             array(
  247.                 'id'     => 'disettinggallery',
  248.                 // Group field
  249.                 'type'   => 'group',
  250.                 // Clone whole group?
  251.                 'clone'  => false,
  252.                 // Drag and drop clones to reorder them?
  253.                 'sort_clone' =>false,
  254.                 // Sub-fields
  255.                 'collapsible' => false,
  256.                
  257.                 'save_state' => true,
  258.                 'fields' => array(
  259.            
  260.                      array(
  261.                         'name' => 'Show Title',
  262.                         'id'   => 'hidetitlegall',
  263.                         'type' => 'checkbox',
  264.                     ),
  265.                    
  266.                    
  267.                     array(
  268.                         'name' => 'Show Menu',
  269.                         'id'   => 'hidemenugall',
  270.                         'type' => 'checkbox',
  271.                     ),
  272.            
  273.                         ),
  274.                    
  275.                      ),
  276.  
  277.         ),
  278.     );
  279.    
  280.    
  281.     //gall settings
  282.    
  283.    
  284.     //gallery
  285.     //gallery
  286.    
  287.    
  288.    
  289.    
  290.    
  291.     $meta_boxes[] = array(
  292.         'title'  => 'Divart Slider',
  293.         'post_types' => ['divart_slider'],
  294.         'fields' => array(
  295.             array(
  296.                 'id'     => 'disliders',
  297.                 // Group field
  298.                 'type'   => 'group',
  299.                 // Clone whole group?
  300.                 'clone'  => true,
  301.                 // Drag and drop clones to reorder them?
  302.                 'sort_clone' => true,
  303.                 // Sub-fields
  304.                 'collapsible' => true,
  305.                 'group_title' => 'Slide {#}', // ID of the subfield
  306.                 'save_state' => true,
  307.                 'fields' => array(
  308.                
  309.                
  310.                      array(
  311.                      'name'             => 'Background Image',
  312.                       'id'               => 'bgimg',
  313.                       'type'             => 'url',
  314.        
  315.                 ),  
  316.                
  317.                     array(
  318.                      'name'             => 'Background Color',
  319.                       'id'               => 'bgcolor',  
  320.                       'type'             => 'color',
  321.        
  322.                 ),  
  323.                
  324.                
  325.                    array(
  326.                      'name'             => 'Text Color',
  327.                       'id'               => 'textcolorr',  
  328.                       'type'             => 'color',
  329.        
  330.                 ),  
  331.                
  332.                   array(
  333.     'name'            => 'Text Align',
  334.     'id'              => 'textalign',
  335.     'type'            => 'select',
  336.     // Array of 'value' => 'Label' pairs
  337.     'options'         => array(
  338.         'flex-start'       => 'left',
  339.         'center' => 'center',
  340.         'flex-end' => 'right',
  341.        
  342.     ),
  343.     // Allow to select multiple value?
  344.     'multiple'        => false,
  345.     // Placeholder text
  346.     'placeholder'     => 'Text Align',
  347.     // Display "Select All / None" button?
  348.     'select_all_none' => true,
  349. ),
  350.            
  351.                 array(
  352.     'name'            => 'Select style',
  353.     'id'              => 'selectstyle',
  354.     'type'            => 'select',
  355.     // Array of 'value' => 'Label' pairs
  356.     'options'         => array(
  357.         'spartan'       => 'spartan',
  358.         'julius' => 'julius',
  359.         'archivo' => 'archivo',
  360.         'fashion' => 'fashion',
  361.         'amatic' => 'amatic',
  362.     ),
  363.     // Allow to select multiple value?
  364.     'multiple'        => false,
  365.     // Placeholder text
  366.     'fashion' => 'fashion',
  367.     // Display "Select All / None" button?
  368.     'select_all_none' => true,
  369. ),
  370.  
  371.                     array(
  372.                         'name' => 'Main Header',
  373.                         'id'   => 'mainh',
  374.                         'type' => 'text',
  375.                     ),
  376.                     array(
  377.                         'name' => 'Sub Header',
  378.                         'id'   => 'subh',
  379.                         'type' => 'text',
  380.                     ),
  381.                     array(
  382.                         'name' => 'Main Text',
  383.                         'id'   => 'maintext',
  384.                         'type' => 'textarea',
  385.                         'rows' => 2,
  386.                     ),
  387.                    
  388.                     array(
  389.                         'name' => 'Icon Text',
  390.                         'id'   => 'icontext',
  391.                         'type' => 'textarea',
  392.                         'rows' => 2,
  393.                     ),
  394.                     array(
  395.                         'name' => 'Show Icon',
  396.                         'id'   => 'showicontext',
  397.                         'type' => 'checkbox',
  398.                     ),
  399.                    
  400.                     array(
  401.    
  402.     'name'             => 'Add Gallery',
  403.     'id'               => 'gallimage',
  404.     'type'             => 'image_advanced',
  405.  
  406.     // Delete image from Media Library when remove it from post meta?
  407.     // Note: it might affect other posts if you use same image for multiple posts
  408.     'force_delete'     => false,
  409.  
  410.     // Do not show how many images uploaded/remaining.
  411.     'max_status'       => 'false',
  412.  
  413.     // Image size that displays in the edit page. Possible sizes small,medium,large,original
  414.     'image_size'       => 'thumbnail',
  415. ),
  416.  
  417.                     array(
  418.                         'name' => 'Gallery Name',
  419.                         'id'   => 'gallname',
  420.                         'type' => 'text',
  421.                     ),
  422.                    
  423.                    
  424.                     array(
  425.                         'name' => 'Gallery Icon',
  426.                         'id'   => 'showgallicon',
  427.                         'type' => 'checkbox',
  428.                     ),
  429.                      
  430.                           // Nested group level 2
  431.                     array(
  432.                         'name'   => 'Buttons',
  433.                         'id'     => 'sub_group_btn',
  434.                         'type'   => 'group',
  435.                         'clone'  => true,
  436.                         'fields' => array(
  437.                             // Normal field (cloned)
  438.                             array(
  439.                                 'name'  => 'Button Text',
  440.                                 'id'    => 'buttontext',
  441.                                 'type'  => 'text',
  442.                                
  443.                             ),
  444.                            
  445.                            
  446.                             array(
  447.                      'name'             => 'Button URL',
  448.                       'id'               => 'btnurl',
  449.                       'type'             => 'url',
  450.        
  451.                 ),  
  452.                            
  453.                         ),
  454.                    
  455.                      ),
  456.              
  457.                 ),
  458.             ),
  459.         ),
  460.     );
  461.  
  462.     $meta_boxes[] = array(
  463.         'title'  => 'Divart Post Hero Settings',
  464.         'post_types' => ['post'],
  465.         'fields' => array(
  466.             array(
  467.                 'id'     => 'dipost',
  468.                 // Group field
  469.                 'type'   => 'group',
  470.                 // Clone whole group?
  471.                 'clone'  => false,
  472.                 // Drag and drop clones to reorder them?
  473.                 'sort_clone' =>false,
  474.                 // Sub-fields
  475.                 'collapsible' => false,
  476.                 'group_title' => 'Slidee {#}', // ID of the subfield
  477.                 'save_state' => true,
  478.                 'fields' => array(
  479.                
  480.                 array(
  481.                         'name' => 'Hide Page Title',
  482.                         'id'   => 'hidepagetitle',
  483.                         'type' => 'checkbox',
  484.                     ),
  485.                
  486.                 array(
  487.     'name'            => 'Select style',
  488.     'id'              => 'selectstyle',
  489.     'type'            => 'select',
  490.     // Array of 'value' => 'Label' pairs
  491.     'options'         => array(
  492.         'spartan'       => 'spartan',
  493.         'julius' => 'julius',
  494.         'archivo' => 'archivo',
  495.         'fashion' => 'fashion',
  496.         'amatic' => 'amatic',
  497.        
  498.     ),
  499.     // Allow to select multiple value?
  500.     'multiple'        => false,
  501.     // Placeholder text
  502.     'julius' => 'julius',
  503.     // Display "Select All / None" button?
  504.     'select_all_none' => true,
  505. ),
  506.                      
  507.                    
  508.                      array(
  509.                         'name' => 'Main Header',
  510.                         'id'   => 'mainh',
  511.                         'type' => 'text',
  512.                     ),
  513.                    
  514.                     array(
  515.                         'name' => 'Sub Header',
  516.                         'id'   => 'subh',
  517.                         'type' => 'text',
  518.                     ),
  519.                     array(
  520.                         'name' => 'Main Text',
  521.                         'id'   => 'maintext',
  522.                         'type' => 'textarea',
  523.                         'rows' => 4,
  524.                     ),
  525.                    
  526.                     array(
  527.                      'name'             => 'Text Color',
  528.                       'id'               => 'textcolorr',  
  529.                       'type'             => 'color',
  530.        
  531.                 ),  
  532.                    
  533.                     array(
  534.                         'name'   => 'Buttons',
  535.                         'id'     => 'sub_group_btn',
  536.                         'type'   => 'group',
  537.                         'clone'  => true,
  538.                         'fields' => array(
  539.                             // Normal field (cloned)
  540.                             array(
  541.                                 'name'  => 'Button Text',
  542.                                 'id'    => 'buttontext',
  543.                                 'type'  => 'text',
  544.                                
  545.                             ),
  546.                             array(
  547.                      'name'             => 'Button URL',
  548.                       'id'               => 'btnurl',
  549.                       'type'             => 'url',
  550.        
  551.                 ),  
  552.                         ),
  553.                    
  554.                      ),
  555.        
  556.                 ),
  557.             ),
  558.         ),
  559.     );
  560.  
  561.     $meta_boxes[] = array(
  562.         'title'  => 'Divart Page Hero Settings',
  563.         'post_types' => ['page'],
  564.         'fields' => array(
  565.             array(
  566.                 'id'     => 'dipage',
  567.                 // Group field
  568.                 'type'   => 'group',
  569.                 // Clone whole group?
  570.                 'clone'  => false,
  571.                 // Drag and drop clones to reorder them?
  572.                 'sort_clone' =>false,
  573.                 // Sub-fields
  574.                 'collapsible' => false,
  575.                 'group_title' => 'Slidee {#}', // ID of the subfield
  576.                 'save_state' => true,
  577.                 'fields' => array(
  578.                
  579.                
  580.                 array(
  581.                         'name' => 'Hide Page Title',
  582.                         'id'   => 'hide_pagetitle',
  583.                         'type' => 'checkbox',
  584.                     ),
  585.                
  586.                
  587.                 array(
  588.     'name'            => 'Select style',
  589.     'id'              => 'selectstyle',
  590.     'type'            => 'select',
  591.     // Array of 'value' => 'Label' pairs
  592.     'options'         => array(
  593.         'spartan'       => 'spartan',
  594.         'julius' => 'julius',
  595.         'archivo' => 'archivo',
  596.         'fashion' => 'fashion',
  597.         'amatic' => 'amatic',
  598.        
  599.     ),
  600.     // Allow to select multiple value?
  601.     'multiple'        => false,
  602.     // Placeholder text
  603.     'julius' => 'julius',
  604.     // Display "Select All / None" button?
  605.     'select_all_none' => true,
  606. ),
  607.                
  608.                
  609.                      array(
  610.                         'name' => 'Main Header',
  611.                         'id'   => 'mainh',
  612.                         'type' => 'text',
  613.                     ),
  614.                    
  615.                     array(
  616.                         'name' => 'Sub Header',
  617.                         'id'   => 'subh',
  618.                         'type' => 'text',
  619.                     ),
  620.                     array(
  621.                         'name' => 'Main Text',
  622.                         'id'   => 'maintext',
  623.                         'type' => 'textarea',
  624.                         'rows' => 4,
  625.                     ),
  626.                    
  627.                     array(
  628.                      'name'             => 'Text Color',
  629.                       'id'               => 'textcolorr',  
  630.                       'type'             => 'color',
  631.        
  632.                 ),  
  633.                    
  634.                     array(
  635.                         'name'   => 'Buttons',
  636.                         'id'     => 'sub_group_btn',
  637.                         'type'   => 'group',
  638.                         'clone'  => true,
  639.                         'fields' => array(
  640.                             // Normal field (cloned)
  641.                             array(
  642.                                 'name'  => 'Button Text',
  643.                                 'id'    => 'buttontext',
  644.                                 'type'  => 'text',
  645.                                
  646.                             ),
  647.                            
  648.                             array(
  649.                      'name'             => 'Button URL',
  650.                       'id'               => 'btnurl',
  651.                       'type'             => 'url',
  652.        
  653.                 ),  
  654.                         ),
  655.                    
  656.                      ),
  657.  
  658.                 ),
  659.             ),
  660.         ),
  661.     );
  662.  
  663.     $meta_boxes[] = array(
  664.         'title'  => 'Page Settings',
  665.         'post_types' => ['divart_slider'],
  666.         'fields' => array(
  667.             array(
  668.                 'id'     => 'disettingpage',
  669.                 // Group field
  670.                 'type'   => 'group',
  671.                 // Clone whole group?
  672.                 'clone'  => false,
  673.                 // Drag and drop clones to reorder them?
  674.                 'sort_clone' =>false,
  675.                 // Sub-fields
  676.                 'collapsible' => false,
  677.                
  678.                 'save_state' => true,
  679.                 'fields' => array(
  680.            
  681.                      array(
  682.                         'name' => 'Show Title',
  683.                         'id'   => 'hidetitle',
  684.                         'type' => 'checkbox',
  685.                     ),
  686.                    
  687.                    
  688.                     array(
  689.                         'name' => 'Show Menu',
  690.                         'id'   => 'hidemenu',
  691.                         'type' => 'checkbox',
  692.                     ),
  693.            
  694.                         ),
  695.                    
  696.                      ),
  697.  
  698.         ),
  699.     );
  700.    
  701. // settings
  702. // settings
  703.  
  704. $meta_boxes[] = array(
  705.         'title'  => 'Page Settings',
  706.         'post_types' => ['divart_slider']['page=settings'],
  707.         'fields' => array(
  708.             array(
  709.                 'id'     => 'disettingpageaa',
  710.                 // Group field
  711.                 'type'   => 'group',
  712.                 // Clone whole group?
  713.                 'clone'  => false,
  714.                 // Drag and drop clones to reorder them?
  715.                 'sort_clone' =>false,
  716.                 // Sub-fields
  717.                 'collapsible' => false,
  718.                
  719.                 'save_state' => true,
  720.                 'fields' => array(
  721.    
  722.                      array(
  723.                         'name' => 'Show Title',
  724.                         'id'   => 'hidetitle',
  725.                         'type' => 'checkbox',
  726.                     ),          
  727.                     array(
  728.                         'name' => 'Show Menu',
  729.                         'id'   => 'hidemenu',
  730.                         'type' => 'checkbox',
  731.                     ),
  732.  
  733.                         ),
  734.                    
  735.                      ),
  736.                    
  737.         ),
  738.     );
  739. // settings
  740. // settings
  741.    
  742.    
  743.  
  744.     return $meta_boxes;
  745. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement