PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
← All changes | includes/frontend/dynamic-content/interpreter.php +18 -5 2.9.1 → 2.14.0 View file →
@@ -18,10 +18,12 @@
18 18 'link' => Interpreters\Link::class,
19 19 'image' => Interpreters\Image::class,
20 20 ];
21 21 protected string $content;
22 - public function __construct( string $content ) {
22 + protected array $context;
23 + public function __construct( string $content, $context = [] ) {
23 24 $this->content = $content;
25 + $this->context = $context;
24 26 $this->parse();// exit;
25 27 }
26 28 public function parse() : void {
27 29 $this->content = preg_replace_callback(
@@ -29,10 +31,14 @@
29 31 [ $this, 'apply_changes' ],
30 32 $this->content
31 33 );
32 34 }
33 - public function apply_changes( array $matches ) : string {
34 - return is_null( $ins = ( new ArgumentParser( ...$this->filter( $matches ), ...[ $this->interpreters ] ) )->interpret() ) ? '' : $ins->content();
35 + public function apply_changes( array $matches ): string {
36 + $filtered = $this->filter( $matches ); // returns an array
37 + $args = array_merge( $filtered, [ $this->interpreters, $this->context ] );
38 + $parser = new ArgumentParser( ...$args );
39 + $ins = $parser->interpret();
40 + return is_null( $ins ) ? '' : $ins->content();
35 41 }
36 42
37 43 public function filter( array $matches ) : array {
38 44 $is_richtext = false;
@@ -46,9 +52,16 @@
46 52 $is_richtext
47 53 ];
48 54 }
49 55
50 - public static function init( string $content ) : string {
51 - $ins = new self( $content );
56 + public static function init( string $content, $block, $instance ) : string {
57 + // This filter runs for EVERY block on the page (including core and
58 + // third-party blocks). The regex in parse() is expensive, so skip it
59 + // unless the block actually contains a dynamic-content marker.
60 + if ( false === strpos( $content, 'ablocks_dc' )
61 + && false === strpos( $content, 'ablocks-richtext-dynamic-content' ) ) {
62 + return $content;
63 + }
64 + $ins = new self( $content, $instance->context );
52 65 return $ins->content;
53 66 }
54 67 }