Source of file class-settings.php
Size: 3,383 Bytes - Last Modified: 2016-01-09T12:24:53-05:00
../src/lib/class-settings.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344
Covered by 17 test(s):
45
Covered by 17 test(s):
46474849505152535455
Covered by 1 test(s):
56
Covered by 1 test(s):
57
Covered by 1 test(s):
5859
Covered by 1 test(s):
60
Covered by 1 test(s):
616263646566676869707172
Covered by 1 test(s):
73
Covered by 1 test(s):
74
Covered by 1 test(s):
75
Covered by 1 test(s):
7677
Covered by 1 test(s):
78
Covered by 1 test(s):
798081828384858687888990
Covered by 1 test(s):
91
Covered by 1 test(s):
9293949596979899100101102
Covered by 6 test(s):
103
Covered by 6 test(s):
104
Covered by 6 test(s):
105
Covered by 6 test(s):
106
Covered by 6 test(s):
107
Covered by 6 test(s):
108109110111112113114115116117118
Covered by 6 test(s):
119
Covered by 6 test(s):
120
Covered by 6 test(s):
121
Covered by 6 test(s):
122
Covered by 6 test(s):
123
Covered by 6 test(s):
124125126127128129130131132
Covered by 1 test(s):
133134135
| <?php /** * Settings Class * * @category PHP * @package WpWodify * @subpackage Settings * @since File available since release 1.0.x * @author Cory Collier <corycollier@corycollier.com> */ namespace WpWodify; /** * Settings Class * * @category PHP * @package WpWodify * @subpackage Settings * @since Class available since release 1.0.x * @author Cory Collier <corycollier@corycollier.com> */ class Settings { /** * Stores the name of the section. * @var string */ protected $name; /** * Stores the plugin specific prefix for names in the settings. * @var string */ protected $prefix = 'wp-wodify-'; /** * Constructor. * * @param string $name The name of the settings instance. * * @param string $slug The uri slug for the settings instance. */ public function __construct($name) { $this->name = $name; } /** * Adds a section to the settings instance. * * @param mixed $callback The callback for the section. * * @return WpWodify\Settings Returns $this, for object-chaining. */ public function add_section($callback) { $name = $this->name; $human = $this->humanize($name); $slug = $this->get_slug(); \add_settings_section($name, $human, $callback, $slug); return $this; } /** * Adds a field to the settings section. * * @param string $name The name of the field. * @param mixed $callback The callback for dispalying the field. * * @return WpWodify\Settings Returns $this, for object-chaining. */ public function add_field($name, $callback) { $title = $this->humanize($name); $section = $this->name; $name = $this->prefix . $name; $slug = $this->get_slug(); \add_settings_field($name, $title, $callback, $slug, $section); return $this; } /** * Register's a setting. * * @param string $name The name of the setting. * @param string $group The group that the setting belongs to. * * @return WpWodify\Settings Returns $this, for object-chaining. */ public function register($name, $group) { \register_setting($group, $name); return $this; } /** * Takes a machine string, and makes it more human friendly. * * @param string $string The machine string. * * @return string The human string. */ protected function humanize($string) { $string = trim(strtr($string, array( '-' => ' ', '_' => ' ', ))); $string = ucwords($string); return $string; } /** * Takes a human string, and makes it more machine friendly. * * @param string $string The input string. * * @return string The machine string. */ protected function machinify($string) { $string = strtr(trim($string), array( ' ' => '-', ',' => '', )); $string = strtolower($string); return $string; } /** * Gets the slug for the settings section. * * @return string The unique slug for the settings section */ protected function get_slug() { return $this->prefix . $this->name . '-settings'; } } |