Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
plugins
Prevent CiviCRM Content in widgets
Commits
edd91808
Commit
edd91808
authored
Aug 06, 2021
by
Andrei Mondoc
Browse files
Update prevent-civicrm-content-in-widgets.php
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
prevent-civicrm-content-in-widgets.php
0 → 100644
View file @
edd91808
<?php
/*
--------------------------------------------------------------------------------
Plugin Name: Prevent CiviCRM Content in widgets
Description: Prevents CiviCRM rendering (duplicate) content on widgets that use apply_filters( 'the_content' ), more widget names can be added using the 'cv/prevent_content_in_widgets/widget_names' filter.
Author: Andrei Mondoc
Version: 0.1
--------------------------------------------------------------------------------
*/
/**
* Filters CiviCRM's context and removes
* Civi basepage content (the_content) filter
* for posts that use apply_filters('the_content')
* preventing CiviCRM from injecting markup in those.
*
* @param string $ctx The CiviCRM context
* @return string $ctx The CiviCRM context
*/
add_filter
(
'civicrm_context'
,
function
(
$ctx
)
{
// bail if not in basepage context
if
(
$ctx
!=
'basepage'
)
return
$ctx
;
/**
* Filters sidebar widget params, and removes
* Civi content filter if applicable.
*
* @param array $params The Widget display arguments
* @return array $params The Widget display arguments
*/
add_filter
(
'dynamic_sidebar_params'
,
function
(
$params
)
{
list
(
$args
)
=
$params
;
/**
* Filter the widgets to check
* for removing CiviCRM content.
*
* @param array $widgets_to_prevent The widget names to prevent displaying Civi content
* @param array $widget_args The widget display arguments
*/
$widgets_to_prevent
=
apply_filters
(
'cv/prevent_content_in_widgets/widget_names'
,
[
'Reusable block'
],
$args
);
if
(
!
in_array
(
$args
[
'widget_name'
],
$widgets_to_prevent
)
)
return
$params
;
// remove civi content filter
remove_filter
(
'the_content'
,
[
civi_wp
()
->
basepage
,
'basepage_render'
]
);
// add civi content filter back
add_action
(
'dynamic_sidebar_after'
,
function
()
{
if
(
has_filter
(
'the_content'
,
[
civi_wp
()
->
basepage
,
'basepage_render'
]
)
)
return
;
add_filter
(
'the_content'
,
[
civi_wp
()
->
basepage
,
'basepage_render'
]
);
}
);
return
$params
;
}
);
return
$ctx
;
}
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment