-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this helper will get reusable blocks content and render it
- Loading branch information
1 parent
6424603
commit 630ab76
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* Helpers for reusable blocks. | ||
* | ||
* @package EightshiftLibs\Helpers | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EightshiftLibs\Helpers; | ||
|
||
/** | ||
* Trait ReusableBlockTrait helper. | ||
*/ | ||
trait ReusableBlockTrait | ||
{ | ||
/** | ||
* Render reusable blocks content. | ||
* | ||
* This helper will get reusable blocks content and render it. | ||
* | ||
* @param int $commonContent ID of the reusable block content to render. | ||
* | ||
* @return string Rendered content. | ||
*/ | ||
public static function renderReusableBlock(int $commonContent): string | ||
{ | ||
$blocks = \parse_blocks(\get_the_content(null, false, $commonContent)); | ||
|
||
$renderedContent = ''; | ||
|
||
foreach ($blocks as $block) { | ||
$renderedContent .= \apply_filters('the_content', \render_block($block)); | ||
} | ||
|
||
return $renderedContent; | ||
} | ||
} |