Skip to content

Commit

Permalink
fix: allow empty field for chained actions fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed May 24, 2024
1 parent b4d18fc commit d4bb631
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions includes/admin/feedzy-rss-feeds-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,14 @@ public function set_settings( $options ) {
/**
* Extract magic tags.
*
* @return string
* @return array|array[]
*/
public function extract_magic_tags() {
preg_match_all( '/\[\[\{(.*)\}\]\]/U', $this->actions, $item_magic_tags, PREG_PATTERN_ORDER );
$can_process = preg_match_all( '/\[\[\{(.*)\}\]\]/U', $this->actions, $item_magic_tags, PREG_PATTERN_ORDER );
if ( ! $can_process ) {
return array();
}

$extract_tags = array();
if ( ! empty( $item_magic_tags[0] ) ) {
$extract_tags = array_map(
Expand All @@ -178,6 +182,10 @@ function( $tag ) {
* Get magic tags.
*/
public function get_tags() {
if ( ! is_array( $this->get_extract_tags() ) ) {
return $this->actions;
}

$replace_to = array_column( $this->get_extract_tags(), 'replace_to' );
$replace_with = array_column( $this->get_extract_tags(), 'replace_with' );
return str_replace( $replace_to, $replace_with, $this->actions );
Expand All @@ -194,6 +202,10 @@ public function get_extract_tags() {
* Get actions.
*/
public function get_actions() {
if ( ! is_array( $this->get_extract_tags() ) ) {
return $this->actions;
}

$replace_with = array_column( $this->get_extract_tags(), 'replace_with' );
$actions = array_map(
function( $action ) {
Expand Down

0 comments on commit d4bb631

Please sign in to comment.