Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Camo Image Proxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WP Plugins
Camo Image Proxy
Commits
33bba8d0
Commit
33bba8d0
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Settings page
parent
d4f73c32
No related branches found
No related tags found
3 merge requests
!6
add linting
,
!5
WIP: Add JUnit reporting
,
!4
WIP: Initial release
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
camo-image-proxy.php
+13
-3
13 additions, 3 deletions
camo-image-proxy.php
inc/class-options-page.php
+57
-3
57 additions, 3 deletions
inc/class-options-page.php
inc/class-options.php
+29
-3
29 additions, 3 deletions
inc/class-options.php
inc/functions.php
+1
-1
1 addition, 1 deletion
inc/functions.php
with
100 additions
and
10 deletions
camo-image-proxy.php
+
13
−
3
View file @
33bba8d0
...
...
@@ -29,11 +29,21 @@ require_once PLUGIN_PATH . '/inc/class-options.php';
/**
* Options page
*/
if
(
is_admin
()
)
{
require_once
PLUGIN_PATH
.
'/inc/class-options-page.php'
;
}
require_once
PLUGIN_PATH
.
'/inc/class-options-page.php'
;
/**
* Assorted functions
*/
require_once
PLUGIN_PATH
.
'/inc/functions.php'
;
/**
* Load plugin singletons
*/
function
init
()
{
Options
::
instance
();
if
(
is_admin
()
)
{
Options_Page
::
instance
();
}
}
add_action
(
'init'
,
__NAMESPACE__
.
'\init'
);
This diff is collapsed.
Click to expand it.
inc/class-options-page.php
+
57
−
3
View file @
33bba8d0
...
...
@@ -13,10 +13,36 @@ namespace Camo_Image_Proxy;
class
Options_Page
{
use
Singleton
;
/**
* Settings screen section
*
* @var string
*/
private
$section
=
'camp-image-proxy'
;
/**
* Field labels
*
* @var array
*/
private
$labels
=
[];
/**
* Option name
*
* @var string
*/
private
$name
;
/**
* Hooks
*/
public
function
setup
()
{
$this
->
name
=
Options
::
instance
()
->
name
;
$this
->
labels
[
'host'
]
=
__
(
'Host'
,
'camo-image-proxy'
);
$this
->
labels
[
'key'
]
=
__
(
'Shared Key'
,
'camo-image-proxy'
);
add_action
(
'admin_init'
,
[
$this
,
'action_admin_init'
]
);
}
...
...
@@ -24,9 +50,37 @@ class Options_Page {
* Add fields to Media settings page
*/
public
function
action_admin_init
()
{
//register_setting();
register_setting
(
'media'
,
$this
->
name
,
[
Options
::
instance
(),
'sanitize_all'
]
);
add_settings_section
(
$this
->
section
,
__
(
'Camo Image Proxy'
,
'camo-image-proxy'
),
'__return_false'
,
'media'
);
foreach
(
$this
->
labels
as
$key
=>
$label
)
{
$args
=
[
'option'
=>
$key
,
'label'
=>
$label
,
];
add_settings_field
(
$key
,
$label
,
[
$this
,
'screen'
],
'media'
,
$this
->
section
,
$args
);
}
}
/**
* Render options field
*
* @param array $args Field arguments.
*/
public
function
screen
(
$args
)
{
$value
=
Options
::
instance
()
->
get
(
$args
[
'option'
]
);
$input_type
=
'host'
===
$args
[
'option'
]
?
'url'
:
'text'
;
$name
=
sprintf
(
'%1$s[%2$s]'
,
$this
->
name
,
$args
[
'option'
]
);
$html_id
=
sprintf
(
'%1$s-%2$s'
,
str_replace
(
'_'
,
'-'
,
$this
->
name
),
$args
[
'option'
]
);
//add_settings_section();
//add_settings_field();
?>
<input
type=
"
<?php
echo
esc_attr
(
$input_type
);
?>
"
name=
"
<?php
echo
esc_html
(
$name
);
?>
"
class=
"regular-text"
id=
"
<?php
echo
esc_attr
(
$html_id
);
?>
"
value=
"
<?php
echo
esc_attr
(
$value
);
?>
"
/>
<?php
}
}
This diff is collapsed.
Click to expand it.
inc/class-options.php
+
29
−
3
View file @
33bba8d0
...
...
@@ -80,6 +80,21 @@ class Options {
* @return bool
*/
public
function
set
(
string
$option
,
$value
)
:
bool
{
$value
=
$this
->
sanitize
(
$option
,
$value
);
$options
=
$this
->
get_all
();
$options
[
$option
]
=
$value
;
return
update_option
(
$this
->
name
,
$options
);
}
/**
* Sanitize option
*
* @param string $option Plugin option.
* @param mixed $value Option value to sanitize.
* @return mixed
*/
public
function
sanitize
(
string
$option
,
$value
)
{
switch
(
$option
)
{
case
'host'
:
$value
=
esc_url
(
$value
);
...
...
@@ -93,9 +108,20 @@ class Options {
return
false
;
}
$options
=
$this
->
get_all
()
;
$options
[
$option
]
=
$value
;
return
$value
;
}
return
update_option
(
$this
->
name
,
$options
);
/**
* Sanitize array of options
*
* @param array $options Options to sanitize.
* @return array
*/
public
function
sanitize_all
(
array
$options
)
:
array
{
foreach
(
$options
as
$option
=>
$value
)
{
$options
[
$option
]
=
$this
->
sanitize
(
$option
,
$value
);
}
return
$options
;
}
}
This diff is collapsed.
Click to expand it.
inc/functions.php
+
1
−
1
View file @
33bba8d0
...
...
@@ -12,6 +12,6 @@ namespace Camo_Image_Proxy;
*
* @return object
*/
function
o
ptions
()
{
function
O
ptions
()
{
return
Options
::
instance
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment