Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
External Permalinks Redux
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
External Permalinks Redux
Merge requests
!14
Add native block-editor support
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add native block-editor support
add/gutenberg-control
into
master
Overview
0
Commits
22
Pipelines
14
Changes
2
Merged
Erick Hitter
requested to merge
add/gutenberg-control
into
master
3 years ago
Overview
0
Commits
22
Pipelines
14
Changes
2
Expand
Add
wp-scripts
for build
Enqueue script, excluding it from widget block editor
Localize script with configurable/filterable options
Localize script with titles for post types to match current functionality
Register meta and set sanitization callbacks
Allow meta to be accessed via endpoint
Create sidebar plugin to show the two fields used by the plugin
Edited
3 years ago
by
Erick Hitter
0
0
Merge request reports
Compare
master
version 13
089c59b9
3 years ago
version 12
11b10e1c
3 years ago
version 11
e8df00ba
3 years ago
version 10
a772546c
3 years ago
version 9
b7aa7f4e
3 years ago
version 8
ed90a2db
3 years ago
version 7
44797235
3 years ago
version 6
26a0fab0
3 years ago
version 5
609b7730
3 years ago
version 4
be659782
3 years ago
version 3
0755575d
3 years ago
version 2
11bf59dd
3 years ago
version 1
b5b55616
3 years ago
master (base)
and
version 3
latest version
9a60bbed
22 commits,
3 years ago
version 13
089c59b9
21 commits,
3 years ago
version 12
11b10e1c
19 commits,
3 years ago
version 11
e8df00ba
18 commits,
3 years ago
version 10
a772546c
17 commits,
3 years ago
version 9
b7aa7f4e
16 commits,
3 years ago
version 8
ed90a2db
10 commits,
3 years ago
version 7
44797235
7 commits,
3 years ago
version 6
26a0fab0
6 commits,
3 years ago
version 5
609b7730
5 commits,
3 years ago
version 4
be659782
3 commits,
3 years ago
version 3
0755575d
2 commits,
3 years ago
version 2
11bf59dd
1 commit,
3 years ago
version 1
b5b55616
2 commits,
3 years ago
2 files
+
37
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
inc/class-external-permalinks-redux-block-editor.php
0 → 100644
+
180
−
0
Options
<?php
/**
* Block editor support.
*
* @package External_Permalinks_Redux
*/
/**
* Class Block_Editor.
*/
class
External_Permalinks_Redux_Block_Editor
{
/**
* Singleton!
*
* @var self
*/
protected
static
$instance
;
/**
* Instantiate class as a singleton.
*
* @return object
*/
public
static
function
get_instance
()
{
if
(
empty
(
self
::
$instance
)
)
{
self
::
$instance
=
new
self
();
self
::
$instance
->
_setup
();
}
return
self
::
$instance
;
}
/**
* Unused constructor.
*/
final
private
function
__construct
()
{}
/**
* Set up class.
*
* @return void
*/
protected
function
_setup
()
{
add_action
(
'rest_api_init'
,
array
(
$this
,
'register_meta'
)
);
add_filter
(
'is_protected_meta'
,
array
(
$this
,
'allow_meta_updates'
),
10
,
3
);
add_action
(
'enqueue_block_editor_assets'
,
array
(
$this
,
'enqueue'
)
);
}
/**
* Register meta for access in block editor.
*
* @return void
*/
public
function
register_meta
()
{
global
$wp_version
;
if
(
!
function_exists
(
'register_meta'
)
||
version_compare
(
$wp_version
,
'4.6.0'
,
'<'
)
)
{
return
;
}
register_meta
(
'post'
,
external_permalinks_redux
::
get_instance
()
->
meta_key_target
,
array
(
'default'
=>
''
,
'description'
=>
__
(
'Redirect destination'
,
'external-permalinks-redux'
),
'type'
=>
'string'
,
'sanitize_callback'
=>
'esc_url_raw'
,
'show_in_rest'
=>
true
,
'single'
=>
true
,
)
);
register_meta
(
'post'
,
external_permalinks_redux
::
get_instance
()
->
meta_key_type
,
array
(
'default'
=>
0
,
'description'
=>
__
(
'Redirect status code'
,
'external-permalinks-redux'
),
'type'
=>
'integer'
,
'sanitize_callback'
=>
'absint'
,
'show_in_rest'
=>
true
,
'single'
=>
true
,
)
);
}
/**
* Allow meta updates from REST API.
*
* @param bool $protected Whether meta is protected or not.
* @param string $meta_key Meta key.
* @param string $meta_type Meta key type.
* @return bool
*/
public
function
allow_meta_updates
(
$protected
,
$meta_key
,
$meta_type
)
{
if
(
'post'
!==
$meta_type
)
{
return
$protected
;
}
if
(
external_permalinks_redux
::
get_instance
()
->
meta_key_target
===
$meta_key
||
external_permalinks_redux
::
get_instance
()
->
meta_key_type
===
$meta_key
)
{
return
false
;
}
return
$protected
;
}
/**
* Enqueue block-editor script.
*
* @return void
*/
public
function
enqueue
()
{
global
$pagenow
;
if
(
'widgets.php'
===
$pagenow
)
{
return
;
}
$asset_data
=
require_once
dirname
(
dirname
(
__FILE__
)
)
.
'/assets/build/index.asset.php'
;
$asset_handle
=
'external-permalinks-redux'
;
wp_enqueue_script
(
$asset_handle
,
plugins_url
(
'assets/build/index.js'
,
dirname
(
__FILE__
)
),
$asset_data
[
'dependencies'
],
$asset_data
[
'version'
],
true
);
wp_localize_script
(
$asset_handle
,
'externalPermalinksReduxConfig'
,
array
(
'metaKeys'
=>
array
(
'target'
=>
external_permalinks_redux
::
get_instance
()
->
meta_key_target
,
'type'
=>
external_permalinks_redux
::
get_instance
()
->
meta_key_type
,
),
'postTypes'
=>
external_permalinks_redux
::
get_instance
()
->
post_types
,
'statusCodes'
=>
$this
->
_get_status_codes
(),
)
);
}
/**
* Format status codes for use with `SelectControl` component.
*
* @return array
*/
protected
function
_get_status_codes
()
{
$codes
=
external_permalinks_redux
::
get_instance
()
->
status_codes
;
$formatted
=
array
(
array
(
'label'
=>
__
(
'-- Select --'
,
'external-permalinks-redux'
),
'value'
=>
0
,
),
);
foreach
(
$codes
as
$code
=>
$label
)
{
$formatted
[]
=
array
(
'label'
=>
$label
,
'value'
=>
$code
,
);
}
return
$formatted
;
}
}
Loading