Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ETH Embed Anchor.fm
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
Service Desk
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
ETH Embed Anchor.fm
Commits
bda594ec
Commit
bda594ec
authored
2 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Add shortcode
parent
92b9e919
Branches
Branches containing commit
No related tags found
1 merge request
!1
Initial release
Pipeline
#5145
failed
2 years ago
Stage: test
Stage: security
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inc/class-plugin.php
+48
-2
48 additions, 2 deletions
inc/class-plugin.php
with
48 additions
and
2 deletions
inc/class-plugin.php
+
48
−
2
View file @
bda594ec
...
...
@@ -32,6 +32,13 @@ class Plugin {
*/
private
const
EPISODE_ID_PLACEHOLDER
=
'__EPISODE_ID__'
;
/**
* Shortcode tag.
*
* @var string
*/
private
const
SHORTCODE_TAG
=
'eth_anchor_fm'
;
/**
* Singleton.
*
...
...
@@ -67,14 +74,13 @@ class Plugin {
*/
private
function
_setup
():
void
{
add_action
(
'init'
,
[
$this
,
'action_init'
]
);
add_filter
(
'oembed_fetch_url'
,
[
$this
,
'filter_oembed_fetch_url'
],
10
,
3
);
// TODO: add shortcode.
}
/**
...
...
@@ -88,6 +94,11 @@ class Plugin {
self
::
OEMBED_ENDPOINT
,
true
);
add_shortcode
(
self
::
SHORTCODE_TAG
,
[
$this
,
'do_shortcode'
]
);
}
/**
...
...
@@ -137,4 +148,39 @@ class Plugin {
return
$provider
;
}
/**
* Render Anchor.fm iframe embed via a shortcode.
*
* @param array $attrs Shortcode attributes.
* @return string
*/
public
function
do_shortcode
(
array
$attrs
):
string
{
$attrs
=
shortcode_atts
(
[
'src'
=>
null
,
'url'
=>
null
,
'width'
=>
'400px'
,
'height'
=>
'102px'
],
$attrs
,
self
::
SHORTCODE_TAG
);
// Fallback in case one passes `url` rather than `src`.
if
(
empty
(
$attrs
[
'src'
]
)
&&
!
empty
(
$attrs
[
'url'
]
)
)
{
$attrs
[
'src'
]
=
$attrs
[
'url'
];
}
if
(
empty
(
$attrs
[
'src'
]
)
)
{
return
''
;
}
return
sprintf
(
'<iframe src="%1$s" width="%2$s" height="%3$s" frameborder="0" scrolling="no"></iframe>'
,
esc_url
(
$attrs
[
'src'
]
),
esc_attr
(
$attrs
[
'width'
]
),
esc_attr
(
$attrs
[
'height'
]
)
);
}
}
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