Skip to content

Commit

Permalink
Merge branch 'release/5.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmikita committed May 23, 2018
2 parents 1251e9e + 06dd4b1 commit 9f5c36f
Show file tree
Hide file tree
Showing 25 changed files with 1,289 additions and 14 deletions.
11 changes: 11 additions & 0 deletions class/Abstracts/MergeTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,15 @@ public function is_hidden() {
return $this->hidden;
}

/**
* Cleans the value
*
* @since [Next]
* @return void
*/
public function clean_value() {
$this->resolved = false;
$this->value = '';
}

}
15 changes: 15 additions & 0 deletions class/Abstracts/Trigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,20 @@ private function resolve_fields() {

}

/**
* Cleans the merge tags.
*
* @since [Next]
* @return void
*/
private function clean_merge_tags() {

foreach ( $this->get_merge_tags() as $merge_tag ) {
$merge_tag->clean_value();
}

}

/**
* Gets CPT Notification from databse
* Gets their enabled Notifications
Expand Down Expand Up @@ -359,6 +373,7 @@ public function _action() {
$this->set_notifications();
$this->resolve_fields();
$this->roll_out();
$this->clean_merge_tags();

}

Expand Down
26 changes: 26 additions & 0 deletions class/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,32 @@ public function triggers_settings( $settings ) {
) )
->description( __( 'For these post types you will be able to define published, updated, pending moderation etc. notifications', 'notification' ) );

// prepare taxonomies for taxonomies option select.
$valid_taxonomies = apply_filters( 'notification/settings/triggers/valid_taxonomies', get_taxonomies( array( 'public' => true ), 'objects' ) );

$taxonomies = array();
foreach ( $valid_taxonomies as $taxonomy ) {
if ( $taxonomy->name == 'post_format' ) {
continue;
}
$taxonomies[ $taxonomy->name ] = $taxonomy->labels->name;
}

$triggers->add_group( __( 'Taxonomy', 'notification' ), 'taxonomies' )
->add_field( array(
'name' => __( 'Taxonomies', 'notification' ),
'slug' => 'types',
'default' => array( 'category', 'post_tag' ),
'addons' => array(
'multiple' => true,
'pretty' => true,
'options' => $taxonomies
),
'render' => array( new CoreFields\Select(), 'input' ),
'sanitize' => array( new CoreFields\Select(), 'sanitize' ),
) )
->description( __( 'For these taxonomies you will be able to define published, updated and deleted notifications', 'notification' ) );

$triggers->add_group( __( 'Comment', 'notification' ), 'comment' )
->add_field( array(
'name' => __( 'Comment Types', 'notification' ),
Expand Down
79 changes: 79 additions & 0 deletions class/Defaults/MergeTag/Taxonomy/TaxonomyName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* Taxonomy name merge tag
*
* Requirements:
* - Trigger property of the WP_Taxonomy term object
*
* @package notification
*/

namespace BracketSpace\Notification\Defaults\MergeTag\Taxonomy;

use BracketSpace\Notification\Defaults\MergeTag\StringTag;


/**
* Taxonomy name merge tag class
*/
class TaxonomyName extends StringTag {

/**
* Taxonomy slug
*
* @var string
*/
protected $taxonomy;

/**
* Merge tag constructor
*
* @since [Next]
* @param array $params merge tag configuration params.
*/
public function __construct( $params = array() ) {

if ( isset( $params['taxonomy'] ) ) {
$this->taxonomy = $params['taxonomy'];
} else {
$this->taxonomy = 'category';
}

$args = wp_parse_args( $params, array(
'slug' => $this->taxonomy . '_name',
'name' => __( 'Taxonomy name', 'notification' ),
'description' => __( 'Hello World', 'notification' ),
'example' => true,
'resolver' => function( $trigger ) {
return $this->get_nicename();
},
) );

parent::__construct( $args );

}

/**
* Function for checking requirements
*
* @return boolean
*/
public function check_requirements() {
return isset( $this->trigger->taxonomy );
}

/**
* Gets nice, translated taxonomy name
*
* @since [Next]
* @return string taxonomy nicename
*/
public function get_nicename() {
$taxonomy = get_taxonomy( $this->trigger->taxonomy );
if ( empty( $taxonomy ) ) {
return '';
}
return $taxonomy->labels->singular_name;
}

}
65 changes: 65 additions & 0 deletions class/Defaults/MergeTag/Taxonomy/TaxonomySlug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Taxonomy slug merge tag
*
* Requirements:
* - Trigger property of the WP_Taxonomy term object
*
* @package notification
*/

namespace BracketSpace\Notification\Defaults\MergeTag\Taxonomy;

use BracketSpace\Notification\Defaults\MergeTag\StringTag;


/**
* Taxonomy slug merge tag class
*/
class TaxonomySlug extends StringTag {

/**
* Taxonomy slug
*
* @var string
*/
protected $taxonomy;

/**
* Merge tag constructor
*
* @since [Next]
* @param array $params merge tag configuration params.
*/
public function __construct( $params = array() ) {

if ( isset( $params['taxonomy'] ) ) {
$this->taxonomy = $params['taxonomy'];
} else {
$this->taxonomy = 'category';
}

$args = wp_parse_args( $params, array(
'slug' => $this->taxonomy . '_slug',
'name' => __( 'Taxonomy slug', 'notification' ),
'description' => __( 'hello-world', 'notification' ),
'example' => true,
'resolver' => function( $trigger ) {
return $trigger->taxonomy;
},
) );

parent::__construct( $args );

}

/**
* Function for checking requirements
*
* @return boolean
*/
public function check_requirements() {
return isset( $this->trigger->taxonomy );
}

}
51 changes: 51 additions & 0 deletions class/Defaults/MergeTag/Taxonomy/TermDescription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Taxonomy term description merge tag
*
* Requirements:
* - Trigger property of the WP_Taxonomy term object
*
* @package notification
*/

namespace BracketSpace\Notification\Defaults\MergeTag\Taxonomy;

use BracketSpace\Notification\Defaults\MergeTag\StringTag;


/**
* Taxonomy term description merge tag class
*/
class TermDescription extends StringTag {

/**
* Merge tag constructor
*
* @since [Next]
*/
public function __construct() {

$args = wp_parse_args( array(
'slug' => 'term_description',
'name' => __( 'Term description', 'notification' ),
'description' => 'Lorem ipsum sit dolor amet',
'example' => true,
'resolver' => function( $trigger ) {
return $trigger->term->description;
},
) );

parent::__construct( $args );

}

/**
* Function for checking requirements
*
* @return boolean
*/
public function check_requirements() {
return isset( $this->trigger->term->description );
}

}
51 changes: 51 additions & 0 deletions class/Defaults/MergeTag/Taxonomy/TermID.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Taxonomy term ID merge tag
*
* Requirements:
* - Trigger property of the WP_Taxonomy term object
*
* @package notification
*/

namespace BracketSpace\Notification\Defaults\MergeTag\Taxonomy;

use BracketSpace\Notification\Defaults\MergeTag\IntegerTag;


/**
* Taxonomy term ID merge tag class
*/
class TermID extends IntegerTag {

/**
* Merge tag constructor
*
* @since [Next]
*/
public function __construct() {

$args = wp_parse_args( array(
'slug' => 'term_ID',
'name' => __( 'Term ID', 'notification' ),
'description' => '35',
'example' => true,
'resolver' => function( $trigger ) {
return $trigger->term->term_id;
},
) );

parent::__construct( $args );

}

/**
* Function for checking requirements
*
* @return boolean
*/
public function check_requirements() {
return isset( $this->trigger->term->term_id );
}

}
51 changes: 51 additions & 0 deletions class/Defaults/MergeTag/Taxonomy/TermName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Taxonomy term name merge tag
*
* Requirements:
* - Trigger property of the WP_Taxonomy term object
*
* @package notification
*/

namespace BracketSpace\Notification\Defaults\MergeTag\Taxonomy;

use BracketSpace\Notification\Defaults\MergeTag\StringTag;


/**
* Taxonomy term name merge tag class
*/
class TermName extends StringTag {

/**
* Merge tag constructor
*
* @since [Next]
*/
public function __construct() {

$args = wp_parse_args( array(
'slug' => 'term_name',
'name' => __( 'Term name', 'notification' ),
'description' => 'Nature',
'example' => true,
'resolver' => function( $trigger ) {
return $trigger->term->name;

} ) );

parent::__construct( $args );

}

/**
* Function for checking requirements
*
* @return boolean
*/
public function check_requirements() {
return isset( $this->trigger->term->name );
}

}
Loading

0 comments on commit 9f5c36f

Please sign in to comment.