@@ -17,71 +17,71 @@ |
||
| 17 | 17 | * @package Wordlift\Mappings\Validators |
| 18 | 18 | */ |
| 19 | 19 | class Post_Type_Rule_Validator implements Rule_Validator { |
| 20 | - /** |
|
| 21 | - * @since 3.25.0 |
|
| 22 | - * Enum for the post type rule validator. |
|
| 23 | - */ |
|
| 24 | - const POST_TYPE = 'post_type'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Post_Type_Rule_Validator constructor. |
|
| 28 | - * |
|
| 29 | - * When initializing the class hooks to `wl_mappings_rule_validators`. |
|
| 30 | - */ |
|
| 31 | - public function __construct() { |
|
| 32 | - |
|
| 33 | - add_filter( 'wl_mappings_rule_validators', array( $this, 'wl_mappings_rule_validators' ) ); |
|
| 34 | - |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Hook to `wl_mappings_rule_validators` to register ourselves. |
|
| 39 | - * |
|
| 40 | - * @param array $value An array with validators. |
|
| 41 | - * |
|
| 42 | - * @return array An array with validators plus ours. |
|
| 43 | - */ |
|
| 44 | - public function wl_mappings_rule_validators( $value ) { |
|
| 45 | - |
|
| 46 | - $value[ self::POST_TYPE ] = $this; |
|
| 47 | - |
|
| 48 | - return $value; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * {@inheritdoc} |
|
| 53 | - */ |
|
| 54 | - public function get_label() { |
|
| 55 | - return __( 'Post Type', 'wordlift' ); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * {@inheritdoc} |
|
| 60 | - */ |
|
| 61 | - public function is_valid( $identifier, $operator, $operand_1, $operand_2, $type ) { |
|
| 62 | - /** |
|
| 63 | - * If this is not done then this will validate for term |
|
| 64 | - * which causes a bug, so this rule validator would return false |
|
| 65 | - * when the current thing is not a post. |
|
| 66 | - */ |
|
| 67 | - if ( $type !== Jsonld_Converter::POST ) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - // Get the post type and then check whether it matches or not according to the operator. |
|
| 71 | - $post_type = get_post_type( $identifier ); |
|
| 72 | - |
|
| 73 | - switch ( $operator ) { |
|
| 74 | - case Rule_Validator::IS_NOT_EQUAL_TO: |
|
| 75 | - return $post_type !== $operand_2; |
|
| 76 | - |
|
| 77 | - case Rule_Validator::IS_EQUAL_TO: |
|
| 78 | - return $post_type === $operand_2; |
|
| 79 | - |
|
| 80 | - default: |
|
| 81 | - |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 20 | + /** |
|
| 21 | + * @since 3.25.0 |
|
| 22 | + * Enum for the post type rule validator. |
|
| 23 | + */ |
|
| 24 | + const POST_TYPE = 'post_type'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Post_Type_Rule_Validator constructor. |
|
| 28 | + * |
|
| 29 | + * When initializing the class hooks to `wl_mappings_rule_validators`. |
|
| 30 | + */ |
|
| 31 | + public function __construct() { |
|
| 32 | + |
|
| 33 | + add_filter( 'wl_mappings_rule_validators', array( $this, 'wl_mappings_rule_validators' ) ); |
|
| 34 | + |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Hook to `wl_mappings_rule_validators` to register ourselves. |
|
| 39 | + * |
|
| 40 | + * @param array $value An array with validators. |
|
| 41 | + * |
|
| 42 | + * @return array An array with validators plus ours. |
|
| 43 | + */ |
|
| 44 | + public function wl_mappings_rule_validators( $value ) { |
|
| 45 | + |
|
| 46 | + $value[ self::POST_TYPE ] = $this; |
|
| 47 | + |
|
| 48 | + return $value; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * {@inheritdoc} |
|
| 53 | + */ |
|
| 54 | + public function get_label() { |
|
| 55 | + return __( 'Post Type', 'wordlift' ); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * {@inheritdoc} |
|
| 60 | + */ |
|
| 61 | + public function is_valid( $identifier, $operator, $operand_1, $operand_2, $type ) { |
|
| 62 | + /** |
|
| 63 | + * If this is not done then this will validate for term |
|
| 64 | + * which causes a bug, so this rule validator would return false |
|
| 65 | + * when the current thing is not a post. |
|
| 66 | + */ |
|
| 67 | + if ( $type !== Jsonld_Converter::POST ) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + // Get the post type and then check whether it matches or not according to the operator. |
|
| 71 | + $post_type = get_post_type( $identifier ); |
|
| 72 | + |
|
| 73 | + switch ( $operator ) { |
|
| 74 | + case Rule_Validator::IS_NOT_EQUAL_TO: |
|
| 75 | + return $post_type !== $operand_2; |
|
| 76 | + |
|
| 77 | + case Rule_Validator::IS_EQUAL_TO: |
|
| 78 | + return $post_type === $operand_2; |
|
| 79 | + |
|
| 80 | + default: |
|
| 81 | + |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function __construct() { |
| 32 | 32 | |
| 33 | - add_filter( 'wl_mappings_rule_validators', array( $this, 'wl_mappings_rule_validators' ) ); |
|
| 33 | + add_filter('wl_mappings_rule_validators', array($this, 'wl_mappings_rule_validators')); |
|
| 34 | 34 | |
| 35 | 35 | } |
| 36 | 36 | |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return array An array with validators plus ours. |
| 43 | 43 | */ |
| 44 | - public function wl_mappings_rule_validators( $value ) { |
|
| 44 | + public function wl_mappings_rule_validators($value) { |
|
| 45 | 45 | |
| 46 | - $value[ self::POST_TYPE ] = $this; |
|
| 46 | + $value[self::POST_TYPE] = $this; |
|
| 47 | 47 | |
| 48 | 48 | return $value; |
| 49 | 49 | } |
@@ -52,25 +52,25 @@ discard block |
||
| 52 | 52 | * {@inheritdoc} |
| 53 | 53 | */ |
| 54 | 54 | public function get_label() { |
| 55 | - return __( 'Post Type', 'wordlift' ); |
|
| 55 | + return __('Post Type', 'wordlift'); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * {@inheritdoc} |
| 60 | 60 | */ |
| 61 | - public function is_valid( $identifier, $operator, $operand_1, $operand_2, $type ) { |
|
| 61 | + public function is_valid($identifier, $operator, $operand_1, $operand_2, $type) { |
|
| 62 | 62 | /** |
| 63 | 63 | * If this is not done then this will validate for term |
| 64 | 64 | * which causes a bug, so this rule validator would return false |
| 65 | 65 | * when the current thing is not a post. |
| 66 | 66 | */ |
| 67 | - if ( $type !== Jsonld_Converter::POST ) { |
|
| 67 | + if ($type !== Jsonld_Converter::POST) { |
|
| 68 | 68 | return false; |
| 69 | 69 | } |
| 70 | 70 | // Get the post type and then check whether it matches or not according to the operator. |
| 71 | - $post_type = get_post_type( $identifier ); |
|
| 71 | + $post_type = get_post_type($identifier); |
|
| 72 | 72 | |
| 73 | - switch ( $operator ) { |
|
| 73 | + switch ($operator) { |
|
| 74 | 74 | case Rule_Validator::IS_NOT_EQUAL_TO: |
| 75 | 75 | return $post_type !== $operand_2; |
| 76 | 76 | |