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
458dc748
Commit
458dc748
authored
2 years ago
by
Erick Hitter
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop' into 'main'
Initial release See merge request
!1
parents
5b100b83
e2ed3de9
No related branches found
No related tags found
1 merge request
!1
Initial release
Pipeline
#5147
passed
2 years ago
Stage: test
Stage: security
Stage: deploy
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitlab-ci.yml
+11
-0
11 additions, 0 deletions
.gitlab-ci.yml
eth-embed-anchor-fm.php
+20
-0
20 additions, 0 deletions
eth-embed-anchor-fm.php
inc/class-plugin.php
+186
-0
186 additions, 0 deletions
inc/class-plugin.php
phpcs.xml
+3
-1
3 additions, 1 deletion
phpcs.xml
with
220 additions
and
1 deletion
.gitlab-ci.yml
+
11
−
0
View file @
458dc748
include
:
-
remote
:
https://git-cdn.e15r.co/gitlab/ci/wordpress/-/raw/main/plugins/default.yml
# Plugin does not support 5.6 or 7.0.
PHPunit:PHP5.6:MySQL
:
rules
:
-
if
:
$PIPELINE_PHP_5_6 != '1'
when
:
never
PHPunit:PHP7.0:MySQL
:
rules
:
-
if
:
$PIPELINE_PHP_7_0 != '1'
when
:
never
This diff is collapsed.
Click to expand it.
eth-embed-anchor-fm.php
+
20
−
0
View file @
458dc748
...
...
@@ -27,3 +27,23 @@
*/
namespace
ETH_Embed_Anchor_FM
;
/**
* Perform setup actions after plugin loads.
*
* @return void
*/
function
action_plugins_loaded
()
{
load_plugin_textdomain
(
'eth-embed-anchor-fm'
,
false
,
dirname
(
plugin_basename
(
__FILE__
)
)
.
'/languages/'
);
}
add_action
(
'plugins_loaded'
,
__NAMESPACE__
.
'\action_plugins_loaded'
);
/**
* Load plugin classes.
*/
require_once
__DIR__
.
'/inc/class-plugin.php'
;
Plugin
::
get_instance
();
This diff is collapsed.
Click to expand it.
inc/class-plugin.php
0 → 100644
+
186
−
0
View file @
458dc748
<?php
/**
* Plugin functionality.
*
* @package ETH_Embed_Anchor_FM
*/
namespace
ETH_Embed_Anchor_FM
;
/**
* Class Plugin.
*/
class
Plugin
{
/**
* Regex pattern to match URL to be oEmbedded.
*
* @var string
*/
private
const
OEMBED_FORMAT
=
'#^https://anchor\.fm/(?!api)([^/]+)/episodes/([^/\s]+)/?#i'
;
/**
* Anchor oEmbed endpoint with placeholder.
*
* @var string
*/
private
const
OEMBED_ENDPOINT
=
'https://anchor.fm/api/v3/episodes/__EPISODE_ID__/oembed'
;
/**
* Placeholder in self::OEMBED_ENDPOINT to be replaced with episode ID.
*
* @var string
*/
private
const
EPISODE_ID_PLACEHOLDER
=
'__EPISODE_ID__'
;
/**
* Shortcode tag.
*
* @var string
*/
private
const
SHORTCODE_TAG
=
'eth_anchor_fm'
;
/**
* Singleton.
*
* @var Plugin
*/
private
static
$_instance
=
null
;
/**
* Implement singleton.
*
* @return Plugin
*/
public
static
function
get_instance
():
Plugin
{
if
(
!
is_a
(
self
::
$_instance
,
__CLASS__
)
)
{
self
::
$_instance
=
new
self
();
self
::
$_instance
->
_setup
();
}
return
self
::
$_instance
;
}
/**
* Silence is golden!
*/
private
function
__construct
()
{
// Add nothing here.
}
/**
* Register hooks.
*
* @return void
*/
private
function
_setup
():
void
{
add_action
(
'init'
,
[
$this
,
'action_init'
]
);
add_filter
(
'oembed_fetch_url'
,
[
$this
,
'filter_oembed_fetch_url'
],
10
,
3
);
}
/**
* Register oEmbed handler.
*
* @return void
*/
public
function
action_init
():
void
{
wp_oembed_add_provider
(
self
::
OEMBED_FORMAT
,
self
::
OEMBED_ENDPOINT
,
true
);
add_shortcode
(
self
::
SHORTCODE_TAG
,
[
$this
,
'do_shortcode'
]
);
}
/**
* Filter oEmbed URL.
*
* Anchor.fm's oEmbed endpoint is specific to an episode ID, which must be
* extracted from the episode URL.
*
* @param string $provider URL of the oEmbed provider.
* @param string $url URL of the content to be embedded.
* @param array $args Optional. Additional arguments for retrieving
* embed HTML.
* @return string
*/
public
function
filter_oembed_fetch_url
(
string
$provider
,
string
$url
,
array
$args
=
[]
):
string
{
if
(
0
!==
stripos
(
$provider
,
self
::
OEMBED_ENDPOINT
)
)
{
return
$provider
;
}
if
(
!
preg_match
(
self
::
OEMBED_FORMAT
,
$url
,
$matches
)
)
{
return
''
;
}
$episode_slug_parts
=
explode
(
'-'
,
$matches
[
2
]
);
$id
=
array_pop
(
$episode_slug_parts
);
$provider
=
str_replace
(
self
::
EPISODE_ID_PLACEHOLDER
,
$id
,
self
::
OEMBED_ENDPOINT
);
// Anchor.fm's oEmbed endpoint offers limited support for arguments.
if
(
isset
(
$args
[
'width'
],
$args
[
'height'
]
)
)
{
$provider
=
add_query_arg
(
[
'maxwidth'
=>
(
int
)
$args
[
'width'
],
'maxheight'
=>
(
int
)
$args
[
'height'
],
],
$provider
);
}
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.
phpcs.xml
+
3
−
1
View file @
458dc748
...
...
@@ -26,7 +26,9 @@
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<config
name=
"minimum_supported_wp_version"
value=
"4.7"
/>
<rule
ref=
"WordPress"
/>
<rule
ref=
"WordPress"
>
<exclude
name=
"Generic.Arrays.DisallowShortArraySyntax"
/>
</rule>
<rule
ref=
"WordPressVIPMinimum"
/>
<rule
ref=
"WordPress-VIP-Go"
/>
<rule
ref=
"WordPress.NamingConventions.PrefixAllGlobals"
>
...
...
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