Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * WordPress settings API class
- *
- * @version 1.0 (23-July-2017)
- *
- * @author Harun R Rayhan <info@harunrrayhan.com>
- * @link https://harunrrayhan.com
- */
- if ( !class_exists('HRX_Settings_API' ) ):
- class HRX_Settings_API {
- private $settings_api;
- function __construct() {
- $this->settings_api = new WeDevs_Settings_API;
- add_action( 'admin_init', array($this, 'admin_init') );
- add_action( 'admin_menu', array($this, 'admin_menu') );
- }
- function admin_init() {
- //set the settings
- $this->settings_api->set_sections( $this->get_settings_sections() );
- $this->settings_api->set_fields( $this->get_settings_fields() );
- //initialize settings
- $this->settings_api->admin_init();
- }
- function admin_menu() {
- add_menu_page( 'GF Checkout Settings', 'GF Checkout', 'delete_posts', 'gf_checkout', array($this, 'plugin_page'), 'dashicons-location', 90);
- }
- function get_settings_sections() {
- $sections = array(
- array(
- 'id' => 'gfc_form',
- 'title' => __( 'Postal Form Settings', 'gf-checkout' )
- ),
- array(
- 'id' => 'gfc_postal',
- 'title' => __( 'Office Settings', 'gf-checkout' )
- )
- );
- return $sections;
- }
- /**
- * Returns all the settings fields
- *
- * @return array settings fields
- */
- function get_settings_fields() {
- $settings_fields = array(
- 'gfc_form' => array(
- array(
- 'name' => 'form_tittle',
- 'label' => __( 'Form Title', 'gf-checkout' ),
- 'desc' => __( 'A title for your postal code search form', 'gf-checkout' ),
- 'placeholder' => __( 'Postal code search form title', 'gf-checkout' ),
- 'type' => 'text',
- 'default' => 'Thank You For Choosing Kodiak',
- 'sanitize_callback' => 'sanitize_text_field'
- ),
- array(
- 'name' => 'form_subtittle',
- 'label' => __( 'Form Sub-Title', 'gf-checkout' ),
- 'desc' => __( 'A sub-title for your postal code search form', 'gf-checkout' ),
- 'placeholder' => __( 'Sub-title', 'gf-checkout' ),
- 'type' => 'text',
- 'default' => 'Please enter your postal code to continue',
- 'sanitize_callback' => 'sanitize_text_field'
- ),
- array(
- 'name' => 'form_placeholder',
- 'label' => __( 'Form Placeholder', 'gf-checkout' ),
- 'desc' => __( 'Placeholde for your postal code search form', 'gf-checkout' ),
- 'placeholder' => __( 'Your Placeholder', 'gf-checkout' ),
- 'type' => 'text',
- 'default' => 'Postal Code',
- 'sanitize_callback' => 'sanitize_text_field'
- ),
- array(
- 'name' => 'form_submit',
- 'label' => __( 'Submit Button Text', 'gf-checkout' ),
- 'desc' => __( 'Text for your postal code search form Submit Button', 'gf-checkout' ),
- 'placeholder' => __( 'Submit Button Text', 'gf-checkout' ),
- 'type' => 'text',
- 'default' => 'Continue',
- 'sanitize_callback' => 'sanitize_text_field'
- ),
- array(
- 'name' => 'error_text',
- 'label' => __( 'Postal Code Error Info', 'gf-checkout' ),
- 'desc' => __( 'User this editor to create <strong>Postal Code Not Found</strong> error data', 'gf-checkout' ),
- 'type' => 'wysiwyg',
- 'default' => ''
- )
- ),
- 'gfc_postal' => array(
- array(
- 'name' => 'current_office_codes',
- 'label' => __( 'Current Office Postal Code', 'gf-checkout' ),
- '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' ),
- 'placeholder' => __( 'Place your current office postal codes', 'gf-checkout' ),
- 'type' => 'textarea'
- ),
- array(
- 'name' => 'current_office_url',
- 'label' => __( 'Current Office URL', 'gf-checkout' ),
- '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' ),
- 'placeholder' => __( 'ex: https://example.com', 'gf-checkout' ),
- 'type' => 'text',
- 'default' => 'http://kodiaksnow.ca/redesign/',
- 'sanitize_callback' => 'sanitize_text_field'
- ),
- array(
- 'name' => 'second_office_codes',
- 'label' => __( 'Second Office Postal Code', 'gf-checkout' ),
- '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' ),
- 'placeholder' => __( 'Place your second office postal codes', 'gf-checkout' ),
- 'type' => 'textarea'
- ),
- array(
- 'name' => 'second_office_url',
- 'label' => __( 'Second Office URL', 'gf-checkout' ),
- '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' ),
- 'placeholder' => __( 'ex: https://example.com', 'gf-checkout' ),
- 'type' => 'text',
- 'default' => '',
- 'sanitize_callback' => 'sanitize_text_field'
- )
- )
- );
- return $settings_fields;
- }
- function plugin_page() {
- echo '<div class="wrap">';
- $this->settings_api->show_navigation();
- $this->settings_api->show_forms();
- echo '</div>';
- }
- /**
- * Get all the pages
- *
- * @return array page names with key value pairs
- */
- function get_pages() {
- $pages = get_pages();
- $pages_options = array();
- if ( $pages ) {
- foreach ($pages as $page) {
- $pages_options[$page->ID] = $page->post_title;
- }
- }
- return $pages_options;
- }
- }
- endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement