Advertisement
HarunRRayhan

Settings API Extend

Jul 25th, 2017
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.32 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * WordPress settings API class
  5.  *
  6.  * @version 1.0 (23-July-2017)
  7.  *
  8.  * @author Harun R Rayhan <info@harunrrayhan.com>
  9.  * @link https://harunrrayhan.com
  10.  */
  11. if ( !class_exists('HRX_Settings_API' ) ):
  12. class HRX_Settings_API {
  13.  
  14.     private $settings_api;
  15.  
  16.     function __construct() {
  17.         $this->settings_api = new WeDevs_Settings_API;
  18.  
  19.         add_action( 'admin_init', array($this, 'admin_init') );
  20.         add_action( 'admin_menu', array($this, 'admin_menu') );
  21.     }
  22.  
  23.     function admin_init() {
  24.  
  25.         //set the settings
  26.         $this->settings_api->set_sections( $this->get_settings_sections() );
  27.         $this->settings_api->set_fields( $this->get_settings_fields() );
  28.  
  29.         //initialize settings
  30.         $this->settings_api->admin_init();
  31.     }
  32.  
  33.     function admin_menu() {
  34.         add_menu_page( 'GF Checkout Settings', 'GF Checkout', 'delete_posts', 'gf_checkout', array($this, 'plugin_page'), 'dashicons-location', 90);
  35.     }
  36.  
  37.     function get_settings_sections() {
  38.         $sections = array(
  39.             array(
  40.                 'id'    => 'gfc_form',
  41.                 'title' => __( 'Postal Form Settings', 'gf-checkout' )
  42.             ),
  43.             array(
  44.                 'id'    => 'gfc_postal',
  45.                 'title' => __( 'Office Settings', 'gf-checkout' )
  46.             )
  47.         );
  48.         return $sections;
  49.     }
  50.  
  51.     /**
  52.      * Returns all the settings fields
  53.      *
  54.      * @return array settings fields
  55.      */
  56.     function get_settings_fields() {
  57.         $settings_fields = array(
  58.             'gfc_form' => array(
  59.                 array(
  60.                     'name'              => 'form_tittle',
  61.                     'label'             => __( 'Form Title', 'gf-checkout' ),
  62.                     'desc'              => __( 'A title for your postal code search form', 'gf-checkout' ),
  63.                     'placeholder'       => __( 'Postal code search form title', 'gf-checkout' ),
  64.                     'type'              => 'text',
  65.                     'default'           => 'Thank You For Choosing Kodiak',
  66.                     'sanitize_callback' => 'sanitize_text_field'
  67.                 ),
  68.                 array(
  69.                     'name'              => 'form_subtittle',
  70.                     'label'             => __( 'Form Sub-Title', 'gf-checkout' ),
  71.                     'desc'              => __( 'A sub-title for your postal code search form', 'gf-checkout' ),
  72.                     'placeholder'       => __( 'Sub-title', 'gf-checkout' ),
  73.                     'type'              => 'text',
  74.                     'default'           => 'Please enter your postal code to continue',
  75.                     'sanitize_callback' => 'sanitize_text_field'
  76.                 ),
  77.                 array(
  78.                     'name'              => 'form_placeholder',
  79.                     'label'             => __( 'Form Placeholder', 'gf-checkout' ),
  80.                     'desc'              => __( 'Placeholde for your postal code search form', 'gf-checkout' ),
  81.                     'placeholder'       => __( 'Your Placeholder', 'gf-checkout' ),
  82.                     'type'              => 'text',
  83.                     'default'           => 'Postal Code',
  84.                     'sanitize_callback' => 'sanitize_text_field'
  85.                 ),
  86.                 array(
  87.                     'name'              => 'form_submit',
  88.                     'label'             => __( 'Submit Button Text', 'gf-checkout' ),
  89.                     'desc'              => __( 'Text for your postal code search form Submit Button', 'gf-checkout' ),
  90.                     'placeholder'       => __( 'Submit Button Text', 'gf-checkout' ),
  91.                     'type'              => 'text',
  92.                     'default'           => 'Continue',
  93.                     'sanitize_callback' => 'sanitize_text_field'
  94.                 ),
  95.                 array(
  96.                     'name'    => 'error_text',
  97.                     'label'   => __( 'Postal Code Error Info', 'gf-checkout' ),
  98.                     'desc'    => __( 'User this editor to create <strong>Postal Code Not Found</strong> error data', 'gf-checkout' ),
  99.                     'type'    => 'wysiwyg',
  100.                     'default' => ''
  101.                 )
  102.             ),
  103.             'gfc_postal' => array(
  104.                  array(
  105.                     'name'        => 'current_office_codes',
  106.                     'label'       => __( 'Current Office Postal Code', 'gf-checkout' ),
  107.                     'desc'        => __( 'Put your current office postal codes as comma(,) seperated list without any space or line break. Ex: <strong><i>XXXXXX,123456,234567,YYYYYY</i></strong>', 'gf-checkout' ),
  108.                     'placeholder' => __( 'Place your current office postal codes', 'gf-checkout' ),
  109.                     'type'        => 'textarea'
  110.                 ),
  111.                 array(
  112.                     'name'              => 'current_office_url',
  113.                     'label'             => __( 'Current Office URL', 'gf-checkout' ),
  114.                     'desc'              => __( 'Put your current office form URL. Keep in mind to include either <strong><i>http://</i></strong> or <strong><i>https://</i></strong>', 'gf-checkout' ),
  115.                     'placeholder'       => __( 'ex: https://example.com', 'gf-checkout' ),
  116.                     'type'              => 'text',
  117.                     'default'           => 'http://kodiaksnow.ca/redesign/',
  118.                     'sanitize_callback' => 'sanitize_text_field'
  119.                 ),
  120.                 array(
  121.                     'name'        => 'second_office_codes',
  122.                     'label'       => __( 'Second Office Postal Code', 'gf-checkout' ),
  123.                     'desc'        => __( 'Put your second office postal codes as comma(,) seperated list without any space or line break. Ex: <strong><i>XXXXXX,123456,234567,YYYYYY</i></strong>', 'gf-checkout' ),
  124.                     'placeholder' => __( 'Place your second office postal codes', 'gf-checkout' ),
  125.                     'type'        => 'textarea'
  126.                 ),
  127.                 array(
  128.                     'name'              => 'second_office_url',
  129.                     'label'             => __( 'Second Office URL', 'gf-checkout' ),
  130.                     'desc'              => __( 'Put your second office form URL. Keep in mind to include either <strong><i>http://</i></strong> or <strong><i>https://</i></strong>', 'gf-checkout' ),
  131.                     'placeholder'       => __( 'ex: https://example.com', 'gf-checkout' ),
  132.                     'type'              => 'text',
  133.                     'default'           => '',
  134.                     'sanitize_callback' => 'sanitize_text_field'
  135.                 )
  136.             )
  137.         );
  138.  
  139.         return $settings_fields;
  140.     }
  141.  
  142.     function plugin_page() {
  143.         echo '<div class="wrap">';
  144.  
  145.         $this->settings_api->show_navigation();
  146.         $this->settings_api->show_forms();
  147.  
  148.         echo '</div>';
  149.     }
  150.  
  151.     /**
  152.      * Get all the pages
  153.      *
  154.      * @return array page names with key value pairs
  155.      */
  156.     function get_pages() {
  157.         $pages = get_pages();
  158.         $pages_options = array();
  159.         if ( $pages ) {
  160.             foreach ($pages as $page) {
  161.                 $pages_options[$page->ID] = $page->post_title;
  162.             }
  163.         }
  164.  
  165.         return $pages_options;
  166.     }
  167.  
  168. }
  169. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement