Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added composer file and some enhancements #18

Closed
wants to merge 12 commits into from
102 changes: 99 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,114 @@
<h1 align="center">
<img src="https://i.imgur.com/gVEqftv.jpg" />

WordPress OOP Settings API
WordPress OOP Settings And Metabox API

</h1>


[![Tweet for help](https://img.shields.io/twitter/follow/mrahmadawais.svg?style=social&label=Tweet%20@MrAhmadAwais)](https://twitter.com/mrahmadawais/) [![GitHub stars](https://img.shields.io/github/stars/ahmadawais/WP-OOP-Settings-API.svg?style=social&label=Stars)](https://github.com/ahmadawais/WP-OOP-Settings-API/stargazers) [![GitHub followers](https://img.shields.io/github/followers/ahmadawais.svg?style=social&label=Follow)](https://github.com/ahmadawais?tab=followers) — :point_up: Make sure you :star: and :eyes: this repository!

> Ever wanted to build custom settings inside your WordPress plugin or theme and didn't like the non-DRY approach for creating custom settings via WordPress API? Well, that's why and when I wrote this OOP Wrapper for WordPress Settings API. 🎊
> Ever wanted to build custom settings (or metaboxes) inside your WordPress plugin or theme and didn't like the non-DRY approach for creating custom settings and metaboxes via WordPress API? Well, that's why and when I wrote this OOP Wrapper for WordPress Settings API. 🎊

![Screenshots](https://on.ahmda.ws/qPBC/c)



## Screenshots

![](https://i.imgur.com/EXUoeLZ.png)
![](https://i.imgur.com/sc9816W.png)
![](https://i.imgur.com/0SWjn4A.png)


## COMPOSER INSTALL

* As for now, this package is not yet submited to packagist, you'll have the repository to your composer file like this :
```json
{
"require": {
"ahmadawais/WP-OOP-Settings-API": "dev-master"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/ahmadawais/WP-OOP-Settings-API.git"
}
]
}

```

* You'll be able to use WP_OSA class after requiring vendor/autoload.php

## USAGE

### USAGE For Setting Page
* Prepare an array of options then instanciate WP_OSA
```php
$options =
[
'name' => 'MY_AWESOME_FEATURE',
'title' => 'My Awesome Feature',
'fields' => [
[
'id' => 'ACTIVE',
'type' => 'checkbox',
'title' => 'The feature is active' ,
],
[
'id' => 'FIRST_SETTING',
'type' => 'number',
'title' => 'First setting' ,
'default' => 0 ,
// This setting will be included only if the first checkbox is checked
'show_if' => function(){ return defined('MY_AWESOME_FEATURE_ACTIVE') && MY_AWESOME_FEATURE_ACTIVE == 'on'; }
]
]
];
$setting = new WP_OSA($options);
```
* Once the options are saved, constants MY\_\AWESOME\_FEATURE\_ACTIVE will be available and will be able to set the first setting MY\_AWESOME\_FEATURE\_FIRST\_SETTING


### USAGE For Post Metabox
* Prepare an array of options as well as the metabox definition then instanciate WP_OSA

```php
$options =
[
'name' => 'MY_AWESOME_FEATURE',
'title' => 'My Awesome Feature',
'fields' => [
[
'id' => 'ACTIVE',
'type' => 'checkbox',
'title' => 'The feature is active' ,
],
[
'id' => 'FIRST_SETTING',
'type' => 'number',
'title' => 'First setting' ,
'default' => 0 ,
// This setting will be included only if the first checkbox is checked
'show_if' => function(){ return defined('MY_AWESOME_FEATURE_ACTIVE') && MY_AWESOME_FEATURE_ACTIVE == 'on'; }
]
]
];
$metabox = [
'id' => 'my_metabox',
'title' => 'My Awesome Metabox',
'post_types' => ['post'], // Post types to display meta box
'context' => 'advanced',
'priority' => 'default',
];
$metabox = new WP_OSA($options , $metabox);
```

* Once the metabox is saved, fields will be saved as post metas : MY\_AWESOME\_FEATURE\_FIRST\_ACTIVE and MY\_AWESOME\_FEATURE\_FIRST\_SETTING



## TODO:
- [x] Basic Settings Page
- [x] Tabs on Settings Page with JS
Expand All @@ -37,6 +128,11 @@
- [x] Create Field: `image`
- [x] Create Field: `password`
- [x] Create Field: `color`
- [x] Create Field: `email`
- [x] Create Field: `date`
- [x] Create Field (generated content with callback): `content`
- [x] Create Field: `range`
- [x] Support for post metabox
- [ ] Tutorials
- [ ] Blog post
- [ ] Documentation
Expand All @@ -54,7 +150,7 @@ Release under GNU GPL v2.0
## Credits

@AhmadAwais, @deviorobert, @MaedahBatool
AND @WordPress, @tareq1988, @royboy789, @twigpress.
AND @WordPress, @tareq1988, @royboy789, @twigpress, @rahal.


---
Expand Down
Loading