Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Add fork of WeDevs wordpress-settings-api-class #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
.DS_Store
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "wp-settings-api",
"type": "library",
"description": "WordPress settings API Abstraction Class",
"keywords": ["wp","wordpress", "settings-api"],
"homepage": "https://github.com/wp-graphql/wp-settings-api",
"license": "GPLv2",
"authors": [
{
"name": "Tareq Hasan",
"email": "[email protected]",
"homepage": "http://tareq.wedevs.com",
"role": "Developer"
}
],
"require": {
"php": ">=5.2.4"
},
"autoload": {
"classmap": ["src/"]
}
}
202 changes: 202 additions & 0 deletions example/oop-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<?php

/**
* WordPress settings API demo class
*
* @author Tareq Hasan
*/
if ( !class_exists('WPGraphQL_Settings_API_Test' ) ):
class WPGraphQL_Settings_API_Test {

private $settings_api;

function __construct() {
$this->settings_api = new WPGraphQL_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_options_page( 'Settings API', 'Settings API', 'delete_posts', 'settings_api_test', array($this, 'plugin_page') );
}

function get_settings_sections() {
$sections = array(
array(
'id' => 'wedevs_basics',
'title' => __( 'Basic Settings', 'wedevs' )
),
array(
'id' => 'wedevs_advanced',
'title' => __( 'Advanced Settings', 'wedevs' )
)
);
return $sections;
}

/**
* Returns all the settings fields
*
* @return array settings fields
*/
function get_settings_fields() {
$settings_fields = array(
'wedevs_basics' => array(
array(
'name' => 'text_val',
'label' => __( 'Text Input', 'wedevs' ),
'desc' => __( 'Text input description', 'wedevs' ),
'placeholder' => __( 'Text Input placeholder', 'wedevs' ),
'type' => 'text',
'default' => 'Title',
'sanitize_callback' => 'sanitize_text_field'
),
array(
'name' => 'number_input',
'label' => __( 'Number Input', 'wedevs' ),
'desc' => __( 'Number field with validation callback `floatval`', 'wedevs' ),
'placeholder' => __( '1.99', 'wedevs' ),
'min' => 0,
'max' => 100,
'step' => '0.01',
'type' => 'number',
'default' => 'Title',
'sanitize_callback' => 'floatval'
),
array(
'name' => 'textarea',
'label' => __( 'Textarea Input', 'wedevs' ),
'desc' => __( 'Textarea description', 'wedevs' ),
'placeholder' => __( 'Textarea placeholder', 'wedevs' ),
'type' => 'textarea'
),
array(
'name' => 'html',
'desc' => __( 'HTML area description. You can use any <strong>bold</strong> or other HTML elements.', 'wedevs' ),
'type' => 'html'
),
array(
'name' => 'checkbox',
'label' => __( 'Checkbox', 'wedevs' ),
'desc' => __( 'Checkbox Label', 'wedevs' ),
'type' => 'checkbox'
),
array(
'name' => 'radio',
'label' => __( 'Radio Button', 'wedevs' ),
'desc' => __( 'A radio button', 'wedevs' ),
'type' => 'radio',
'options' => array(
'yes' => 'Yes',
'no' => 'No'
)
),
array(
'name' => 'selectbox',
'label' => __( 'A Dropdown', 'wedevs' ),
'desc' => __( 'Dropdown description', 'wedevs' ),
'type' => 'select',
'default' => 'no',
'options' => array(
'yes' => 'Yes',
'no' => 'No'
)
),
array(
'name' => 'password',
'label' => __( 'Password', 'wedevs' ),
'desc' => __( 'Password description', 'wedevs' ),
'type' => 'password',
'default' => ''
),
array(
'name' => 'file',
'label' => __( 'File', 'wedevs' ),
'desc' => __( 'File description', 'wedevs' ),
'type' => 'file',
'default' => '',
'options' => array(
'button_label' => 'Choose Image'
)
)
),
'wedevs_advanced' => array(
array(
'name' => 'color',
'label' => __( 'Color', 'wedevs' ),
'desc' => __( 'Color description', 'wedevs' ),
'type' => 'color',
'default' => ''
),
array(
'name' => 'password',
'label' => __( 'Password', 'wedevs' ),
'desc' => __( 'Password description', 'wedevs' ),
'type' => 'password',
'default' => ''
),
array(
'name' => 'wysiwyg',
'label' => __( 'Advanced Editor', 'wedevs' ),
'desc' => __( 'WP_Editor description', 'wedevs' ),
'type' => 'wysiwyg',
'default' => ''
),
array(
'name' => 'multicheck',
'label' => __( 'Multile checkbox', 'wedevs' ),
'desc' => __( 'Multi checkbox description', 'wedevs' ),
'type' => 'multicheck',
'default' => array('one' => 'one', 'four' => 'four'),
'options' => array(
'one' => 'One',
'two' => 'Two',
'three' => 'Three',
'four' => 'Four'
)
),
)
);

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;
Loading