![5d8b0e13bdf2f962156a1b7c1665683f](https://user-images.githubusercontent.com/48084051/229556850-49b37d01-97da-485b-b39f-d13d8077bd2a.jpg)

## Dynamic Connector Block

Dynamic connector block allows you to add dynamic content based on different conditions on each post.

## Hooks and Filters

Dynamic connector block comes with hooks and filters that allows developers to do necessary changes smoothly.

### `dynamic_connector_block_query_args`

This filter allows you to add custom query argument before the actual block query is processed.

#### Arguments

| Parameter    | Type    | Description                                                                                   |
| :----------- | :------ | :-------------------------------------------------------------------------------------------- |
| `query`      | `array` | The current [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/) arguments |
| `attributes` | `array` | Current block attributes                                                                      |
| `post_id`    | `int`   | Post id at which the block is processing the result                                           |

#### Example

Here is a quick example using the filter to modify the queried posts scoped to the searched term "Recipe".

```php
add_filter( 'dynamic_connector_block_query_args', function( $query, $attributes, $post_id ) {

    $query[ 's' ] = 'Recipe';
    return $query;

}, 10, 3 );
```

### `dynamic_connector_block_conditional_posts`

This filter allows you to modify the queried posts result obtained from the `WP_Query` query. Can be useful to add complex condition on posts required to your needs.

#### Arguments

| Parameter    | Type        | Description                                         |
| :----------- | :---------- | :-------------------------------------------------- |
| `$posts`     | `WP_Post[]` | Currently queried posts objects                     |
| `attributes` | `array`     | Current block attributes                            |
| `post_id`    | `int`       | Post id at which the block is processing the result |

#### Example

The following basic example shortlists the queried posts to posts which title starts with the term "Recipe".

```php
add_filter( 'dynamic_connector_block_conditional_posts', function( $posts, $attributes, $post_id ) {

  $shortlisted_posts = array();

  foreach ( $posts as $post ) {

      if ( str_starts_with( $post->post_title, 'Recipe' ) ) {
          $shortlisted_posts[] = $post;
      }

  }

  return $shortlisted_posts;
}, 10, 3 )
```

## Changelog

= Version 1.0.5

-   Refactor: Add longer prefix.
-   Refactor: Add GPL license header.
-   Fix: Prevent direct access to PHP files.

= Version 1.0.4

-   Refactor: Add licensing support.

= Version 1.0.3

-   Fix: Missing group selector on the block with Automatic block inserter plugin.

= Version 1.0.2

-   Tweak: Add support for ABI post type.

= Version 1.0.1

-   Dev: Update freemius SDK.

= Version 1.0.0

-   New: Initial Release.
