@@ -11,45 +11,45 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Data_Source_Factory { |
| 13 | 13 | |
| 14 | - private static $instance = null; |
|
| 15 | - |
|
| 16 | - private $data_sources = array(); |
|
| 17 | - |
|
| 18 | - public function __construct() { |
|
| 19 | - $this->data_sources = array( |
|
| 20 | - 'acf' => new Acf_Data_Source(), |
|
| 21 | - 'meta' => new Meta_Data_Source() |
|
| 22 | - ); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @param $identifier int post id or term id based on type. |
|
| 27 | - * @param $property_data array |
|
| 28 | - * @param $type string post or term. |
|
| 29 | - * |
|
| 30 | - * @return mixed |
|
| 31 | - */ |
|
| 32 | - public function get_data( $identifier, $property_data, $type ) { |
|
| 33 | - switch ( $property_data['field_type'] ) { |
|
| 34 | - case Jsonld_Converter::FIELD_TYPE_ACF: |
|
| 35 | - return $this->data_sources['acf']->get_data( $identifier, $property_data, $type ); |
|
| 36 | - case Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD: |
|
| 37 | - return $this->data_sources['meta']->get_data( $identifier, $property_data, $type ); |
|
| 38 | - default: |
|
| 39 | - return $property_data['field_name']; |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @return Data_Source_Factory |
|
| 46 | - */ |
|
| 47 | - public static function get_instance() { |
|
| 48 | - if ( self::$instance === null ) { |
|
| 49 | - self::$instance = new Data_Source_Factory(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - return self::$instance; |
|
| 53 | - } |
|
| 14 | + private static $instance = null; |
|
| 15 | + |
|
| 16 | + private $data_sources = array(); |
|
| 17 | + |
|
| 18 | + public function __construct() { |
|
| 19 | + $this->data_sources = array( |
|
| 20 | + 'acf' => new Acf_Data_Source(), |
|
| 21 | + 'meta' => new Meta_Data_Source() |
|
| 22 | + ); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @param $identifier int post id or term id based on type. |
|
| 27 | + * @param $property_data array |
|
| 28 | + * @param $type string post or term. |
|
| 29 | + * |
|
| 30 | + * @return mixed |
|
| 31 | + */ |
|
| 32 | + public function get_data( $identifier, $property_data, $type ) { |
|
| 33 | + switch ( $property_data['field_type'] ) { |
|
| 34 | + case Jsonld_Converter::FIELD_TYPE_ACF: |
|
| 35 | + return $this->data_sources['acf']->get_data( $identifier, $property_data, $type ); |
|
| 36 | + case Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD: |
|
| 37 | + return $this->data_sources['meta']->get_data( $identifier, $property_data, $type ); |
|
| 38 | + default: |
|
| 39 | + return $property_data['field_name']; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @return Data_Source_Factory |
|
| 46 | + */ |
|
| 47 | + public static function get_instance() { |
|
| 48 | + if ( self::$instance === null ) { |
|
| 49 | + self::$instance = new Data_Source_Factory(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + return self::$instance; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | } |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @return mixed |
| 31 | 31 | */ |
| 32 | - public function get_data( $identifier, $property_data, $type ) { |
|
| 33 | - switch ( $property_data['field_type'] ) { |
|
| 32 | + public function get_data($identifier, $property_data, $type) { |
|
| 33 | + switch ($property_data['field_type']) { |
|
| 34 | 34 | case Jsonld_Converter::FIELD_TYPE_ACF: |
| 35 | - return $this->data_sources['acf']->get_data( $identifier, $property_data, $type ); |
|
| 35 | + return $this->data_sources['acf']->get_data($identifier, $property_data, $type); |
|
| 36 | 36 | case Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD: |
| 37 | - return $this->data_sources['meta']->get_data( $identifier, $property_data, $type ); |
|
| 37 | + return $this->data_sources['meta']->get_data($identifier, $property_data, $type); |
|
| 38 | 38 | default: |
| 39 | 39 | return $property_data['field_name']; |
| 40 | 40 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @return Data_Source_Factory |
| 46 | 46 | */ |
| 47 | 47 | public static function get_instance() { |
| 48 | - if ( self::$instance === null ) { |
|
| 48 | + if (self::$instance === null) { |
|
| 49 | 49 | self::$instance = new Data_Source_Factory(); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -13,6 +13,6 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | interface Abstract_Data_Source { |
| 15 | 15 | |
| 16 | - public function get_data( $identifier, $property, $type ); |
|
| 16 | + public function get_data( $identifier, $property, $type ); |
|
| 17 | 17 | |
| 18 | 18 | } |
@@ -13,6 +13,6 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | interface Abstract_Data_Source { |
| 15 | 15 | |
| 16 | - public function get_data( $identifier, $property, $type ); |
|
| 16 | + public function get_data($identifier, $property, $type); |
|
| 17 | 17 | |
| 18 | 18 | } |
@@ -17,56 +17,56 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Taxonomy_Term_Rule_Validator implements Rule_Validator { |
| 19 | 19 | |
| 20 | - const TAXONOMY = 'taxonomy'; |
|
| 20 | + const TAXONOMY = 'taxonomy'; |
|
| 21 | 21 | |
| 22 | - public function __construct() { |
|
| 23 | - add_filter( 'wl_mappings_rule_validators', array( $this, 'wl_mappings_rule_validators' ) ); |
|
| 24 | - } |
|
| 22 | + public function __construct() { |
|
| 23 | + add_filter( 'wl_mappings_rule_validators', array( $this, 'wl_mappings_rule_validators' ) ); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Hook to `wl_mappings_rule_validators` to register ourselves. |
|
| 28 | - * |
|
| 29 | - * @param array $value An array with validators. |
|
| 30 | - * |
|
| 31 | - * @return array An array with validators plus ours. |
|
| 32 | - */ |
|
| 33 | - public function wl_mappings_rule_validators( $value ) { |
|
| 34 | - $value[ self::TAXONOMY ] = $this; |
|
| 26 | + /** |
|
| 27 | + * Hook to `wl_mappings_rule_validators` to register ourselves. |
|
| 28 | + * |
|
| 29 | + * @param array $value An array with validators. |
|
| 30 | + * |
|
| 31 | + * @return array An array with validators plus ours. |
|
| 32 | + */ |
|
| 33 | + public function wl_mappings_rule_validators( $value ) { |
|
| 34 | + $value[ self::TAXONOMY ] = $this; |
|
| 35 | 35 | |
| 36 | - return $value; |
|
| 37 | - } |
|
| 36 | + return $value; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - public function get_label() { |
|
| 41 | - return __( 'TaxonomyTerm', 'wordlift' ); |
|
| 42 | - } |
|
| 40 | + public function get_label() { |
|
| 41 | + return __( 'TaxonomyTerm', 'wordlift' ); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function is_valid( $identifier, $operator, $operand_1, $taxonomy, $type ) { |
|
| 45 | - if ( $type !== Jsonld_Converter::TERM ) { |
|
| 46 | - return false; |
|
| 47 | - } |
|
| 48 | - $current_term = get_term( $identifier ); |
|
| 49 | - // If it is not a term page, then return false for two operators. |
|
| 50 | - if ( ! $current_term instanceof \WP_Term ) { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - $terms = get_terms( $taxonomy, array( 'get' => 'all' ) ); |
|
| 54 | - $terms = array_map( function ( $term ) { |
|
| 55 | - /** |
|
| 56 | - * @var $term \WP_Term |
|
| 57 | - */ |
|
| 58 | - return $term->term_id; |
|
| 59 | - }, $terms ); |
|
| 60 | - if ( $operator === Rule_Validator::IS_EQUAL_TO ) { |
|
| 61 | - // if we dont have term id, then skip the flow. |
|
| 62 | - // If we are in term page, then we need to check if the current |
|
| 63 | - // term belongs to the taxonomy |
|
| 64 | - return in_array( $current_term->term_id, $terms ); |
|
| 65 | - } |
|
| 44 | + public function is_valid( $identifier, $operator, $operand_1, $taxonomy, $type ) { |
|
| 45 | + if ( $type !== Jsonld_Converter::TERM ) { |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | + $current_term = get_term( $identifier ); |
|
| 49 | + // If it is not a term page, then return false for two operators. |
|
| 50 | + if ( ! $current_term instanceof \WP_Term ) { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + $terms = get_terms( $taxonomy, array( 'get' => 'all' ) ); |
|
| 54 | + $terms = array_map( function ( $term ) { |
|
| 55 | + /** |
|
| 56 | + * @var $term \WP_Term |
|
| 57 | + */ |
|
| 58 | + return $term->term_id; |
|
| 59 | + }, $terms ); |
|
| 60 | + if ( $operator === Rule_Validator::IS_EQUAL_TO ) { |
|
| 61 | + // if we dont have term id, then skip the flow. |
|
| 62 | + // If we are in term page, then we need to check if the current |
|
| 63 | + // term belongs to the taxonomy |
|
| 64 | + return in_array( $current_term->term_id, $terms ); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - if ( $operator === Rule_Validator::IS_NOT_EQUAL_TO ) { |
|
| 68 | - return ! in_array( $current_term->term_id, $terms ); |
|
| 69 | - } |
|
| 67 | + if ( $operator === Rule_Validator::IS_NOT_EQUAL_TO ) { |
|
| 68 | + return ! in_array( $current_term->term_id, $terms ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | const TAXONOMY = 'taxonomy'; |
| 21 | 21 | |
| 22 | 22 | public function __construct() { |
| 23 | - add_filter( 'wl_mappings_rule_validators', array( $this, 'wl_mappings_rule_validators' ) ); |
|
| 23 | + add_filter('wl_mappings_rule_validators', array($this, 'wl_mappings_rule_validators')); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -30,42 +30,42 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return array An array with validators plus ours. |
| 32 | 32 | */ |
| 33 | - public function wl_mappings_rule_validators( $value ) { |
|
| 34 | - $value[ self::TAXONOMY ] = $this; |
|
| 33 | + public function wl_mappings_rule_validators($value) { |
|
| 34 | + $value[self::TAXONOMY] = $this; |
|
| 35 | 35 | |
| 36 | 36 | return $value; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | public function get_label() { |
| 41 | - return __( 'TaxonomyTerm', 'wordlift' ); |
|
| 41 | + return __('TaxonomyTerm', 'wordlift'); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function is_valid( $identifier, $operator, $operand_1, $taxonomy, $type ) { |
|
| 45 | - if ( $type !== Jsonld_Converter::TERM ) { |
|
| 44 | + public function is_valid($identifier, $operator, $operand_1, $taxonomy, $type) { |
|
| 45 | + if ($type !== Jsonld_Converter::TERM) { |
|
| 46 | 46 | return false; |
| 47 | 47 | } |
| 48 | - $current_term = get_term( $identifier ); |
|
| 48 | + $current_term = get_term($identifier); |
|
| 49 | 49 | // If it is not a term page, then return false for two operators. |
| 50 | - if ( ! $current_term instanceof \WP_Term ) { |
|
| 50 | + if ( ! $current_term instanceof \WP_Term) { |
|
| 51 | 51 | return false; |
| 52 | 52 | } |
| 53 | - $terms = get_terms( $taxonomy, array( 'get' => 'all' ) ); |
|
| 54 | - $terms = array_map( function ( $term ) { |
|
| 53 | + $terms = get_terms($taxonomy, array('get' => 'all')); |
|
| 54 | + $terms = array_map(function($term) { |
|
| 55 | 55 | /** |
| 56 | 56 | * @var $term \WP_Term |
| 57 | 57 | */ |
| 58 | 58 | return $term->term_id; |
| 59 | - }, $terms ); |
|
| 60 | - if ( $operator === Rule_Validator::IS_EQUAL_TO ) { |
|
| 59 | + }, $terms); |
|
| 60 | + if ($operator === Rule_Validator::IS_EQUAL_TO) { |
|
| 61 | 61 | // if we dont have term id, then skip the flow. |
| 62 | 62 | // If we are in term page, then we need to check if the current |
| 63 | 63 | // term belongs to the taxonomy |
| 64 | - return in_array( $current_term->term_id, $terms ); |
|
| 64 | + return in_array($current_term->term_id, $terms); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if ( $operator === Rule_Validator::IS_NOT_EQUAL_TO ) { |
|
| 68 | - return ! in_array( $current_term->term_id, $terms ); |
|
| 67 | + if ($operator === Rule_Validator::IS_NOT_EQUAL_TO) { |
|
| 68 | + return ! in_array($current_term->term_id, $terms); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | } |
@@ -16,144 +16,144 @@ |
||
| 16 | 16 | use Wordlift\Mappings\Validators\Rule_Groups_Validator; |
| 17 | 17 | |
| 18 | 18 | final class Mappings_Validator { |
| 19 | - const TRASH_CATEGORY = 'trash'; |
|
| 20 | - const ACTIVE_CATEGORY = 'active'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * The {@link Mappings_DBO} instance to test. |
|
| 24 | - * |
|
| 25 | - * @since 3.25.0 |
|
| 26 | - * @access private |
|
| 27 | - * @var Mappings_DBO $dbo The {@link Mappings_DBO} instance to test. |
|
| 28 | - */ |
|
| 29 | - private $dbo; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var Rule_Groups_Validator |
|
| 33 | - */ |
|
| 34 | - private $rule_groups_validator; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Constructor for Wordlift_Mapping_Validator. |
|
| 38 | - * |
|
| 39 | - * @param Mappings_DBO $dbo The {@link Mappings_DBO} instance. |
|
| 40 | - * @param Rule_Groups_Validator $rule_groups_validator |
|
| 41 | - */ |
|
| 42 | - public function __construct( $dbo, $rule_groups_validator ) { |
|
| 43 | - |
|
| 44 | - $this->dbo = $dbo; |
|
| 45 | - $this->rule_groups_validator = $rule_groups_validator; |
|
| 46 | - |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * This method is used to filter properties based on presence |
|
| 51 | - * of certain key values. |
|
| 52 | - * |
|
| 53 | - * @param $items array Array of properties. |
|
| 54 | - * |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - private static function filter_properties_for_required_keys( $items ) { |
|
| 58 | - return array_filter( |
|
| 59 | - $items, |
|
| 60 | - function ( $item ) { |
|
| 61 | - /** |
|
| 62 | - * Since the properties might also be passed |
|
| 63 | - * by external plugins, we might need to check if |
|
| 64 | - * they have correct data format. |
|
| 65 | - */ |
|
| 66 | - if ( ! array_key_exists( 'property_name', $item ) || |
|
| 67 | - ! array_key_exists( 'field_type', $item ) || |
|
| 68 | - ! array_key_exists( 'field_name', $item ) || |
|
| 69 | - ! array_key_exists( 'transform_function', $item ) |
|
| 70 | - ) { |
|
| 71 | - // If these keys doesnt exist, then dont process. |
|
| 72 | - return false; |
|
| 73 | - } else { |
|
| 74 | - // If the keys exist, then filter it. |
|
| 75 | - return true; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - ); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Validates two values based on the passed logic |
|
| 83 | - * a single rule passes the user defined logic. |
|
| 84 | - * |
|
| 85 | - * @param string $key The key which every object has mapped to our value. |
|
| 86 | - * @param array $items The array of items. |
|
| 87 | - * @param string $status The value which the items should have. |
|
| 88 | - * |
|
| 89 | - * @return array |
|
| 90 | - */ |
|
| 91 | - private static function get_property_item_by_status( $key, $items, $status ) { |
|
| 92 | - return array_filter( |
|
| 93 | - $items, |
|
| 94 | - function ( $item ) use ( $key, $status ) { |
|
| 95 | - return $item[ $key ] === (string) $status; |
|
| 96 | - } |
|
| 97 | - ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Validates a post id with the list of active mapping items and check if |
|
| 102 | - * a mapping can be applied. |
|
| 103 | - * |
|
| 104 | - * @param int $identifier The post id or term id based on type. |
|
| 105 | - * |
|
| 106 | - * @param string $type Post or term. |
|
| 107 | - * |
|
| 108 | - * @return array |
|
| 109 | - */ |
|
| 110 | - public function validate( $identifier, $type ) { |
|
| 111 | - // Reset the valid property items before making the validation. |
|
| 112 | - $properties = array(); |
|
| 113 | - |
|
| 114 | - // Filter registered properties |
|
| 115 | - $filter_registered_properties = array(); |
|
| 116 | - |
|
| 117 | - // Get active mappings. |
|
| 118 | - $mappings = $this->dbo->get_active_mappings(); |
|
| 119 | - /** |
|
| 120 | - * Apply this filter to get mappings from external plugins. |
|
| 121 | - * |
|
| 122 | - * @param $mappings array Array of mappings from database. |
|
| 123 | - * @param $identifier int The post id or term id based on type. |
|
| 124 | - */ |
|
| 125 | - $mappings = apply_filters( 'wl_mappings_post', $mappings, $identifier ); |
|
| 126 | - |
|
| 127 | - // Get all active rule groups for the mapping items. |
|
| 128 | - foreach ( $mappings as $mapping ) { |
|
| 129 | - if ( array_key_exists( 'mapping_id', $mapping ) ) { |
|
| 130 | - $rule_groups = $this->dbo->get_rule_groups_by_mapping( (int) $mapping['mapping_id'] ); |
|
| 131 | - $should_apply_mapping = $this->rule_groups_validator->is_valid( $identifier, $rule_groups, $type ); |
|
| 132 | - if ( $should_apply_mapping ) { |
|
| 133 | - $mapping_item_properties = $this->dbo->get_properties( $mapping['mapping_id'] ); |
|
| 134 | - $properties = array_merge( $properties, $mapping_item_properties ); |
|
| 135 | - } |
|
| 136 | - } else { |
|
| 137 | - /** |
|
| 138 | - * This is a programmatically defined mapping, |
|
| 139 | - * so we will have the rule groups and the properties in the array keys |
|
| 140 | - */ |
|
| 141 | - if ( array_key_exists( 'properties', $mapping ) && |
|
| 142 | - is_array( $mapping['properties'] ) ) { |
|
| 143 | - $filter_registered_properties = array_merge( $filter_registered_properties, $mapping['properties'] ); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - // Filter all registered properties based on required key values. |
|
| 148 | - $filter_registered_properties = self::filter_properties_for_required_keys( $filter_registered_properties ); |
|
| 149 | - $active_properties = self::get_property_item_by_status( |
|
| 150 | - 'property_status', |
|
| 151 | - $properties, |
|
| 152 | - self::ACTIVE_CATEGORY |
|
| 153 | - ); |
|
| 154 | - |
|
| 155 | - // Merge ui defined properties with filter registered properties. |
|
| 156 | - return array_merge( $active_properties, $filter_registered_properties ); |
|
| 157 | - } |
|
| 19 | + const TRASH_CATEGORY = 'trash'; |
|
| 20 | + const ACTIVE_CATEGORY = 'active'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * The {@link Mappings_DBO} instance to test. |
|
| 24 | + * |
|
| 25 | + * @since 3.25.0 |
|
| 26 | + * @access private |
|
| 27 | + * @var Mappings_DBO $dbo The {@link Mappings_DBO} instance to test. |
|
| 28 | + */ |
|
| 29 | + private $dbo; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var Rule_Groups_Validator |
|
| 33 | + */ |
|
| 34 | + private $rule_groups_validator; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Constructor for Wordlift_Mapping_Validator. |
|
| 38 | + * |
|
| 39 | + * @param Mappings_DBO $dbo The {@link Mappings_DBO} instance. |
|
| 40 | + * @param Rule_Groups_Validator $rule_groups_validator |
|
| 41 | + */ |
|
| 42 | + public function __construct( $dbo, $rule_groups_validator ) { |
|
| 43 | + |
|
| 44 | + $this->dbo = $dbo; |
|
| 45 | + $this->rule_groups_validator = $rule_groups_validator; |
|
| 46 | + |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * This method is used to filter properties based on presence |
|
| 51 | + * of certain key values. |
|
| 52 | + * |
|
| 53 | + * @param $items array Array of properties. |
|
| 54 | + * |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + private static function filter_properties_for_required_keys( $items ) { |
|
| 58 | + return array_filter( |
|
| 59 | + $items, |
|
| 60 | + function ( $item ) { |
|
| 61 | + /** |
|
| 62 | + * Since the properties might also be passed |
|
| 63 | + * by external plugins, we might need to check if |
|
| 64 | + * they have correct data format. |
|
| 65 | + */ |
|
| 66 | + if ( ! array_key_exists( 'property_name', $item ) || |
|
| 67 | + ! array_key_exists( 'field_type', $item ) || |
|
| 68 | + ! array_key_exists( 'field_name', $item ) || |
|
| 69 | + ! array_key_exists( 'transform_function', $item ) |
|
| 70 | + ) { |
|
| 71 | + // If these keys doesnt exist, then dont process. |
|
| 72 | + return false; |
|
| 73 | + } else { |
|
| 74 | + // If the keys exist, then filter it. |
|
| 75 | + return true; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Validates two values based on the passed logic |
|
| 83 | + * a single rule passes the user defined logic. |
|
| 84 | + * |
|
| 85 | + * @param string $key The key which every object has mapped to our value. |
|
| 86 | + * @param array $items The array of items. |
|
| 87 | + * @param string $status The value which the items should have. |
|
| 88 | + * |
|
| 89 | + * @return array |
|
| 90 | + */ |
|
| 91 | + private static function get_property_item_by_status( $key, $items, $status ) { |
|
| 92 | + return array_filter( |
|
| 93 | + $items, |
|
| 94 | + function ( $item ) use ( $key, $status ) { |
|
| 95 | + return $item[ $key ] === (string) $status; |
|
| 96 | + } |
|
| 97 | + ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Validates a post id with the list of active mapping items and check if |
|
| 102 | + * a mapping can be applied. |
|
| 103 | + * |
|
| 104 | + * @param int $identifier The post id or term id based on type. |
|
| 105 | + * |
|
| 106 | + * @param string $type Post or term. |
|
| 107 | + * |
|
| 108 | + * @return array |
|
| 109 | + */ |
|
| 110 | + public function validate( $identifier, $type ) { |
|
| 111 | + // Reset the valid property items before making the validation. |
|
| 112 | + $properties = array(); |
|
| 113 | + |
|
| 114 | + // Filter registered properties |
|
| 115 | + $filter_registered_properties = array(); |
|
| 116 | + |
|
| 117 | + // Get active mappings. |
|
| 118 | + $mappings = $this->dbo->get_active_mappings(); |
|
| 119 | + /** |
|
| 120 | + * Apply this filter to get mappings from external plugins. |
|
| 121 | + * |
|
| 122 | + * @param $mappings array Array of mappings from database. |
|
| 123 | + * @param $identifier int The post id or term id based on type. |
|
| 124 | + */ |
|
| 125 | + $mappings = apply_filters( 'wl_mappings_post', $mappings, $identifier ); |
|
| 126 | + |
|
| 127 | + // Get all active rule groups for the mapping items. |
|
| 128 | + foreach ( $mappings as $mapping ) { |
|
| 129 | + if ( array_key_exists( 'mapping_id', $mapping ) ) { |
|
| 130 | + $rule_groups = $this->dbo->get_rule_groups_by_mapping( (int) $mapping['mapping_id'] ); |
|
| 131 | + $should_apply_mapping = $this->rule_groups_validator->is_valid( $identifier, $rule_groups, $type ); |
|
| 132 | + if ( $should_apply_mapping ) { |
|
| 133 | + $mapping_item_properties = $this->dbo->get_properties( $mapping['mapping_id'] ); |
|
| 134 | + $properties = array_merge( $properties, $mapping_item_properties ); |
|
| 135 | + } |
|
| 136 | + } else { |
|
| 137 | + /** |
|
| 138 | + * This is a programmatically defined mapping, |
|
| 139 | + * so we will have the rule groups and the properties in the array keys |
|
| 140 | + */ |
|
| 141 | + if ( array_key_exists( 'properties', $mapping ) && |
|
| 142 | + is_array( $mapping['properties'] ) ) { |
|
| 143 | + $filter_registered_properties = array_merge( $filter_registered_properties, $mapping['properties'] ); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + // Filter all registered properties based on required key values. |
|
| 148 | + $filter_registered_properties = self::filter_properties_for_required_keys( $filter_registered_properties ); |
|
| 149 | + $active_properties = self::get_property_item_by_status( |
|
| 150 | + 'property_status', |
|
| 151 | + $properties, |
|
| 152 | + self::ACTIVE_CATEGORY |
|
| 153 | + ); |
|
| 154 | + |
|
| 155 | + // Merge ui defined properties with filter registered properties. |
|
| 156 | + return array_merge( $active_properties, $filter_registered_properties ); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param Mappings_DBO $dbo The {@link Mappings_DBO} instance. |
| 40 | 40 | * @param Rule_Groups_Validator $rule_groups_validator |
| 41 | 41 | */ |
| 42 | - public function __construct( $dbo, $rule_groups_validator ) { |
|
| 42 | + public function __construct($dbo, $rule_groups_validator) { |
|
| 43 | 43 | |
| 44 | 44 | $this->dbo = $dbo; |
| 45 | 45 | $this->rule_groups_validator = $rule_groups_validator; |
@@ -54,19 +54,19 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @return array |
| 56 | 56 | */ |
| 57 | - private static function filter_properties_for_required_keys( $items ) { |
|
| 57 | + private static function filter_properties_for_required_keys($items) { |
|
| 58 | 58 | return array_filter( |
| 59 | 59 | $items, |
| 60 | - function ( $item ) { |
|
| 60 | + function($item) { |
|
| 61 | 61 | /** |
| 62 | 62 | * Since the properties might also be passed |
| 63 | 63 | * by external plugins, we might need to check if |
| 64 | 64 | * they have correct data format. |
| 65 | 65 | */ |
| 66 | - if ( ! array_key_exists( 'property_name', $item ) || |
|
| 67 | - ! array_key_exists( 'field_type', $item ) || |
|
| 68 | - ! array_key_exists( 'field_name', $item ) || |
|
| 69 | - ! array_key_exists( 'transform_function', $item ) |
|
| 66 | + if ( ! array_key_exists('property_name', $item) || |
|
| 67 | + ! array_key_exists('field_type', $item) || |
|
| 68 | + ! array_key_exists('field_name', $item) || |
|
| 69 | + ! array_key_exists('transform_function', $item) |
|
| 70 | 70 | ) { |
| 71 | 71 | // If these keys doesnt exist, then dont process. |
| 72 | 72 | return false; |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| 91 | - private static function get_property_item_by_status( $key, $items, $status ) { |
|
| 91 | + private static function get_property_item_by_status($key, $items, $status) { |
|
| 92 | 92 | return array_filter( |
| 93 | 93 | $items, |
| 94 | - function ( $item ) use ( $key, $status ) { |
|
| 95 | - return $item[ $key ] === (string) $status; |
|
| 94 | + function($item) use ($key, $status) { |
|
| 95 | + return $item[$key] === (string) $status; |
|
| 96 | 96 | } |
| 97 | 97 | ); |
| 98 | 98 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @return array |
| 109 | 109 | */ |
| 110 | - public function validate( $identifier, $type ) { |
|
| 110 | + public function validate($identifier, $type) { |
|
| 111 | 111 | // Reset the valid property items before making the validation. |
| 112 | 112 | $properties = array(); |
| 113 | 113 | |
@@ -122,30 +122,30 @@ discard block |
||
| 122 | 122 | * @param $mappings array Array of mappings from database. |
| 123 | 123 | * @param $identifier int The post id or term id based on type. |
| 124 | 124 | */ |
| 125 | - $mappings = apply_filters( 'wl_mappings_post', $mappings, $identifier ); |
|
| 125 | + $mappings = apply_filters('wl_mappings_post', $mappings, $identifier); |
|
| 126 | 126 | |
| 127 | 127 | // Get all active rule groups for the mapping items. |
| 128 | - foreach ( $mappings as $mapping ) { |
|
| 129 | - if ( array_key_exists( 'mapping_id', $mapping ) ) { |
|
| 130 | - $rule_groups = $this->dbo->get_rule_groups_by_mapping( (int) $mapping['mapping_id'] ); |
|
| 131 | - $should_apply_mapping = $this->rule_groups_validator->is_valid( $identifier, $rule_groups, $type ); |
|
| 132 | - if ( $should_apply_mapping ) { |
|
| 133 | - $mapping_item_properties = $this->dbo->get_properties( $mapping['mapping_id'] ); |
|
| 134 | - $properties = array_merge( $properties, $mapping_item_properties ); |
|
| 128 | + foreach ($mappings as $mapping) { |
|
| 129 | + if (array_key_exists('mapping_id', $mapping)) { |
|
| 130 | + $rule_groups = $this->dbo->get_rule_groups_by_mapping((int) $mapping['mapping_id']); |
|
| 131 | + $should_apply_mapping = $this->rule_groups_validator->is_valid($identifier, $rule_groups, $type); |
|
| 132 | + if ($should_apply_mapping) { |
|
| 133 | + $mapping_item_properties = $this->dbo->get_properties($mapping['mapping_id']); |
|
| 134 | + $properties = array_merge($properties, $mapping_item_properties); |
|
| 135 | 135 | } |
| 136 | 136 | } else { |
| 137 | 137 | /** |
| 138 | 138 | * This is a programmatically defined mapping, |
| 139 | 139 | * so we will have the rule groups and the properties in the array keys |
| 140 | 140 | */ |
| 141 | - if ( array_key_exists( 'properties', $mapping ) && |
|
| 142 | - is_array( $mapping['properties'] ) ) { |
|
| 143 | - $filter_registered_properties = array_merge( $filter_registered_properties, $mapping['properties'] ); |
|
| 141 | + if (array_key_exists('properties', $mapping) && |
|
| 142 | + is_array($mapping['properties'])) { |
|
| 143 | + $filter_registered_properties = array_merge($filter_registered_properties, $mapping['properties']); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | // Filter all registered properties based on required key values. |
| 148 | - $filter_registered_properties = self::filter_properties_for_required_keys( $filter_registered_properties ); |
|
| 148 | + $filter_registered_properties = self::filter_properties_for_required_keys($filter_registered_properties); |
|
| 149 | 149 | $active_properties = self::get_property_item_by_status( |
| 150 | 150 | 'property_status', |
| 151 | 151 | $properties, |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | ); |
| 154 | 154 | |
| 155 | 155 | // Merge ui defined properties with filter registered properties. |
| 156 | - return array_merge( $active_properties, $filter_registered_properties ); |
|
| 156 | + return array_merge($active_properties, $filter_registered_properties); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | } |
@@ -9,66 +9,66 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Wordlift_Context_Cards_Service { |
| 11 | 11 | |
| 12 | - public function enqueue_scripts() { |
|
| 12 | + public function enqueue_scripts() { |
|
| 13 | 13 | |
| 14 | - $show_context_cards = apply_filters( 'wl_context_cards_show', true ); |
|
| 15 | - $context_cards_base_url = apply_filters( 'wl_context_cards_base_url', get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/jsonld' ) ); |
|
| 14 | + $show_context_cards = apply_filters( 'wl_context_cards_show', true ); |
|
| 15 | + $context_cards_base_url = apply_filters( 'wl_context_cards_base_url', get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/jsonld' ) ); |
|
| 16 | 16 | |
| 17 | - /* |
|
| 17 | + /* |
|
| 18 | 18 | * Do not load wordlift-cloud on a non-static home page |
| 19 | 19 | * |
| 20 | 20 | * @since 3.27.4 |
| 21 | 21 | */ |
| 22 | - if ( is_front_page() && is_home() ) { |
|
| 23 | - // Default homepage - force hide |
|
| 24 | - $show_context_cards = false; |
|
| 25 | - } elseif ( is_front_page() ) { |
|
| 26 | - // Static homepage - do nothing |
|
| 27 | - } elseif ( is_home() ) { |
|
| 28 | - // Blog page - force hide |
|
| 29 | - $show_context_cards = false; |
|
| 30 | - } |
|
| 22 | + if ( is_front_page() && is_home() ) { |
|
| 23 | + // Default homepage - force hide |
|
| 24 | + $show_context_cards = false; |
|
| 25 | + } elseif ( is_front_page() ) { |
|
| 26 | + // Static homepage - do nothing |
|
| 27 | + } elseif ( is_home() ) { |
|
| 28 | + // Blog page - force hide |
|
| 29 | + $show_context_cards = false; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - if ( $show_context_cards ) { |
|
| 33 | - wp_enqueue_script( 'wordlift-cloud' ); |
|
| 34 | - wp_localize_script( 'wordlift-cloud', '_wlCloudSettings', array( |
|
| 35 | - 'selector' => 'a.wl-entity-page-link', |
|
| 36 | - 'url' => $context_cards_base_url |
|
| 37 | - ) ); |
|
| 38 | - } |
|
| 32 | + if ( $show_context_cards ) { |
|
| 33 | + wp_enqueue_script( 'wordlift-cloud' ); |
|
| 34 | + wp_localize_script( 'wordlift-cloud', '_wlCloudSettings', array( |
|
| 35 | + 'selector' => 'a.wl-entity-page-link', |
|
| 36 | + 'url' => $context_cards_base_url |
|
| 37 | + ) ); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - add_filter( 'wl_anchor_data_attributes', array( $this, 'anchor_data_attributes' ), 10, 2 ); |
|
| 41 | - } |
|
| 40 | + add_filter( 'wl_anchor_data_attributes', array( $this, 'anchor_data_attributes' ), 10, 2 ); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function anchor_data_attributes( $attributes, $post_id ) { |
|
| 43 | + public function anchor_data_attributes( $attributes, $post_id ) { |
|
| 44 | 44 | |
| 45 | - $supported_types = Wordlift_Entity_Service::valid_entity_post_types(); |
|
| 46 | - $post_type = get_post_type( $post_id ); |
|
| 47 | - $enabled_templates = apply_filters( 'wl_context_cards_enabled_templates', array( 'product' ) ); |
|
| 45 | + $supported_types = Wordlift_Entity_Service::valid_entity_post_types(); |
|
| 46 | + $post_type = get_post_type( $post_id ); |
|
| 47 | + $enabled_templates = apply_filters( 'wl_context_cards_enabled_templates', array( 'product' ) ); |
|
| 48 | 48 | |
| 49 | - if ( in_array( $post_type, $supported_types ) && in_array( $post_type, $enabled_templates ) ) { |
|
| 49 | + if ( in_array( $post_type, $supported_types ) && in_array( $post_type, $enabled_templates ) ) { |
|
| 50 | 50 | |
| 51 | - $additional_attributes = array( 'post-type-template' => $post_type ); |
|
| 51 | + $additional_attributes = array( 'post-type-template' => $post_type ); |
|
| 52 | 52 | |
| 53 | - switch($post_type){ |
|
| 54 | - case 'product': |
|
| 55 | - $product = wc_get_product( $post_id ); |
|
| 56 | - $additional_attributes['template-payload'] = json_encode( |
|
| 57 | - array( |
|
| 58 | - 'regular_price' => $product->get_regular_price(), |
|
| 59 | - 'currency_symbol' => get_woocommerce_currency_symbol(), |
|
| 60 | - 'discount_pc' => ($product->get_sale_price() && ($product->get_regular_price() > 0)) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0, |
|
| 61 | - 'average_rating' => $product->get_average_rating(), |
|
| 62 | - 'rating_count' => $product->get_rating_count(), |
|
| 63 | - 'rating_html' => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ) |
|
| 64 | - ) |
|
| 65 | - ); |
|
| 66 | - } |
|
| 53 | + switch($post_type){ |
|
| 54 | + case 'product': |
|
| 55 | + $product = wc_get_product( $post_id ); |
|
| 56 | + $additional_attributes['template-payload'] = json_encode( |
|
| 57 | + array( |
|
| 58 | + 'regular_price' => $product->get_regular_price(), |
|
| 59 | + 'currency_symbol' => get_woocommerce_currency_symbol(), |
|
| 60 | + 'discount_pc' => ($product->get_sale_price() && ($product->get_regular_price() > 0)) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0, |
|
| 61 | + 'average_rating' => $product->get_average_rating(), |
|
| 62 | + 'rating_count' => $product->get_rating_count(), |
|
| 63 | + 'rating_html' => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ) |
|
| 64 | + ) |
|
| 65 | + ); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - return $attributes + $additional_attributes; |
|
| 69 | - } |
|
| 68 | + return $attributes + $additional_attributes; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - return $attributes; |
|
| 72 | - } |
|
| 71 | + return $attributes; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | } |
@@ -11,56 +11,56 @@ |
||
| 11 | 11 | |
| 12 | 12 | public function enqueue_scripts() { |
| 13 | 13 | |
| 14 | - $show_context_cards = apply_filters( 'wl_context_cards_show', true ); |
|
| 15 | - $context_cards_base_url = apply_filters( 'wl_context_cards_base_url', get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/jsonld' ) ); |
|
| 14 | + $show_context_cards = apply_filters('wl_context_cards_show', true); |
|
| 15 | + $context_cards_base_url = apply_filters('wl_context_cards_base_url', get_rest_url(null, WL_REST_ROUTE_DEFAULT_NAMESPACE.'/jsonld')); |
|
| 16 | 16 | |
| 17 | 17 | /* |
| 18 | 18 | * Do not load wordlift-cloud on a non-static home page |
| 19 | 19 | * |
| 20 | 20 | * @since 3.27.4 |
| 21 | 21 | */ |
| 22 | - if ( is_front_page() && is_home() ) { |
|
| 22 | + if (is_front_page() && is_home()) { |
|
| 23 | 23 | // Default homepage - force hide |
| 24 | 24 | $show_context_cards = false; |
| 25 | - } elseif ( is_front_page() ) { |
|
| 25 | + } elseif (is_front_page()) { |
|
| 26 | 26 | // Static homepage - do nothing |
| 27 | - } elseif ( is_home() ) { |
|
| 27 | + } elseif (is_home()) { |
|
| 28 | 28 | // Blog page - force hide |
| 29 | 29 | $show_context_cards = false; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if ( $show_context_cards ) { |
|
| 33 | - wp_enqueue_script( 'wordlift-cloud' ); |
|
| 34 | - wp_localize_script( 'wordlift-cloud', '_wlCloudSettings', array( |
|
| 32 | + if ($show_context_cards) { |
|
| 33 | + wp_enqueue_script('wordlift-cloud'); |
|
| 34 | + wp_localize_script('wordlift-cloud', '_wlCloudSettings', array( |
|
| 35 | 35 | 'selector' => 'a.wl-entity-page-link', |
| 36 | 36 | 'url' => $context_cards_base_url |
| 37 | - ) ); |
|
| 37 | + )); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - add_filter( 'wl_anchor_data_attributes', array( $this, 'anchor_data_attributes' ), 10, 2 ); |
|
| 40 | + add_filter('wl_anchor_data_attributes', array($this, 'anchor_data_attributes'), 10, 2); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function anchor_data_attributes( $attributes, $post_id ) { |
|
| 43 | + public function anchor_data_attributes($attributes, $post_id) { |
|
| 44 | 44 | |
| 45 | 45 | $supported_types = Wordlift_Entity_Service::valid_entity_post_types(); |
| 46 | - $post_type = get_post_type( $post_id ); |
|
| 47 | - $enabled_templates = apply_filters( 'wl_context_cards_enabled_templates', array( 'product' ) ); |
|
| 46 | + $post_type = get_post_type($post_id); |
|
| 47 | + $enabled_templates = apply_filters('wl_context_cards_enabled_templates', array('product')); |
|
| 48 | 48 | |
| 49 | - if ( in_array( $post_type, $supported_types ) && in_array( $post_type, $enabled_templates ) ) { |
|
| 49 | + if (in_array($post_type, $supported_types) && in_array($post_type, $enabled_templates)) { |
|
| 50 | 50 | |
| 51 | - $additional_attributes = array( 'post-type-template' => $post_type ); |
|
| 51 | + $additional_attributes = array('post-type-template' => $post_type); |
|
| 52 | 52 | |
| 53 | - switch($post_type){ |
|
| 53 | + switch ($post_type) { |
|
| 54 | 54 | case 'product': |
| 55 | - $product = wc_get_product( $post_id ); |
|
| 55 | + $product = wc_get_product($post_id); |
|
| 56 | 56 | $additional_attributes['template-payload'] = json_encode( |
| 57 | 57 | array( |
| 58 | 58 | 'regular_price' => $product->get_regular_price(), |
| 59 | 59 | 'currency_symbol' => get_woocommerce_currency_symbol(), |
| 60 | - 'discount_pc' => ($product->get_sale_price() && ($product->get_regular_price() > 0)) ? round( 1 - ( $product->get_sale_price() / $product->get_regular_price() ), 2 ) * 100 : 0, |
|
| 60 | + 'discount_pc' => ($product->get_sale_price() && ($product->get_regular_price() > 0)) ? round(1 - ($product->get_sale_price() / $product->get_regular_price()), 2) * 100 : 0, |
|
| 61 | 61 | 'average_rating' => $product->get_average_rating(), |
| 62 | 62 | 'rating_count' => $product->get_rating_count(), |
| 63 | - 'rating_html' => wc_get_rating_html( $product->get_average_rating(), $product->get_rating_count() ) |
|
| 63 | + 'rating_html' => wc_get_rating_html($product->get_average_rating(), $product->get_rating_count()) |
|
| 64 | 64 | ) |
| 65 | 65 | ); |
| 66 | 66 | } |
@@ -22,109 +22,109 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class Wordlift_Public { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * The ID of this plugin. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - * @access private |
|
| 30 | - * @var string $plugin_name The ID of this plugin. |
|
| 31 | - */ |
|
| 32 | - private $plugin_name; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * The version of this plugin. |
|
| 36 | - * |
|
| 37 | - * @since 1.0.0 |
|
| 38 | - * @access private |
|
| 39 | - * @var string $version The current version of this plugin. |
|
| 40 | - */ |
|
| 41 | - private $version; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Initialize the class and set its properties. |
|
| 45 | - * |
|
| 46 | - * @param string $plugin_name The name of the plugin. |
|
| 47 | - * @param string $version The version of this plugin. |
|
| 48 | - * |
|
| 49 | - * @since 1.0.0 |
|
| 50 | - * |
|
| 51 | - */ |
|
| 52 | - public function __construct( $plugin_name, $version ) { |
|
| 53 | - |
|
| 54 | - $this->plugin_name = $plugin_name; |
|
| 55 | - $this->version = $version; |
|
| 56 | - |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Register the stylesheets for the public-facing side of the site. |
|
| 61 | - * |
|
| 62 | - * @since 3.19.3 Register the `wordlift-ui` css. |
|
| 63 | - * @since 3.19.2 The call to this function is commented out in `class-wordlift.php` because `wordlift-public.css` |
|
| 64 | - * is empty. |
|
| 65 | - * @since 1.0.0 |
|
| 66 | - */ |
|
| 67 | - public function enqueue_styles() { |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * An instance of this class should be passed to the run() function |
|
| 71 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
| 72 | - * in that particular class. |
|
| 73 | - * |
|
| 74 | - * The Wordlift_Loader will then create the relationship |
|
| 75 | - * between the defined hooks and the functions defined in this |
|
| 76 | - * class. |
|
| 77 | - */ |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Add the `wordlift-font-awesome` unless some 3rd party sets the flag to false. |
|
| 81 | - * |
|
| 82 | - * @param bool $include Whether to include or not font-awesome (default true). |
|
| 83 | - * |
|
| 84 | - * @since 3.19.3 |
|
| 85 | - * |
|
| 86 | - */ |
|
| 87 | - $deps = apply_filters( 'wl_include_font_awesome', true ) |
|
| 88 | - ? array( 'wordlift-font-awesome' ) |
|
| 89 | - : array(); |
|
| 90 | - wp_register_style( 'wordlift-font-awesome', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' ); |
|
| 91 | - wp_register_style( 'wordlift-ui', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' ); |
|
| 92 | - |
|
| 93 | - // You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective. |
|
| 94 | - // |
|
| 95 | - // @see https://github.com/insideout10/wordlift-plugin/issues/821 |
|
| 96 | - // |
|
| 97 | - // wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-public.css', array(), $this->version, 'all' ); |
|
| 98 | - |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Register the stylesheets for the public-facing side of the site. |
|
| 103 | - * |
|
| 104 | - * @since 1.0.0 |
|
| 105 | - */ |
|
| 106 | - public function enqueue_scripts() { |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * This function is provided for demonstration purposes only. |
|
| 110 | - * |
|
| 111 | - * An instance of this class should be passed to the run() function |
|
| 112 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
| 113 | - * in that particular class. |
|
| 114 | - * |
|
| 115 | - * The Wordlift_Loader will then create the relationship |
|
| 116 | - * between the defined hooks and the functions defined in this |
|
| 117 | - * class. |
|
| 118 | - */ |
|
| 119 | - |
|
| 120 | - $settings = self::get_settings(); |
|
| 121 | - |
|
| 122 | - // Note that we switched the js to be loaded in footer, since it is loading |
|
| 123 | - // the json-ld representation. |
|
| 124 | - wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true ); |
|
| 125 | - wp_localize_script( $this->plugin_name, 'wlSettings', $settings ); |
|
| 126 | - |
|
| 127 | - /* |
|
| 25 | + /** |
|
| 26 | + * The ID of this plugin. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + * @access private |
|
| 30 | + * @var string $plugin_name The ID of this plugin. |
|
| 31 | + */ |
|
| 32 | + private $plugin_name; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * The version of this plugin. |
|
| 36 | + * |
|
| 37 | + * @since 1.0.0 |
|
| 38 | + * @access private |
|
| 39 | + * @var string $version The current version of this plugin. |
|
| 40 | + */ |
|
| 41 | + private $version; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Initialize the class and set its properties. |
|
| 45 | + * |
|
| 46 | + * @param string $plugin_name The name of the plugin. |
|
| 47 | + * @param string $version The version of this plugin. |
|
| 48 | + * |
|
| 49 | + * @since 1.0.0 |
|
| 50 | + * |
|
| 51 | + */ |
|
| 52 | + public function __construct( $plugin_name, $version ) { |
|
| 53 | + |
|
| 54 | + $this->plugin_name = $plugin_name; |
|
| 55 | + $this->version = $version; |
|
| 56 | + |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Register the stylesheets for the public-facing side of the site. |
|
| 61 | + * |
|
| 62 | + * @since 3.19.3 Register the `wordlift-ui` css. |
|
| 63 | + * @since 3.19.2 The call to this function is commented out in `class-wordlift.php` because `wordlift-public.css` |
|
| 64 | + * is empty. |
|
| 65 | + * @since 1.0.0 |
|
| 66 | + */ |
|
| 67 | + public function enqueue_styles() { |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * An instance of this class should be passed to the run() function |
|
| 71 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
| 72 | + * in that particular class. |
|
| 73 | + * |
|
| 74 | + * The Wordlift_Loader will then create the relationship |
|
| 75 | + * between the defined hooks and the functions defined in this |
|
| 76 | + * class. |
|
| 77 | + */ |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Add the `wordlift-font-awesome` unless some 3rd party sets the flag to false. |
|
| 81 | + * |
|
| 82 | + * @param bool $include Whether to include or not font-awesome (default true). |
|
| 83 | + * |
|
| 84 | + * @since 3.19.3 |
|
| 85 | + * |
|
| 86 | + */ |
|
| 87 | + $deps = apply_filters( 'wl_include_font_awesome', true ) |
|
| 88 | + ? array( 'wordlift-font-awesome' ) |
|
| 89 | + : array(); |
|
| 90 | + wp_register_style( 'wordlift-font-awesome', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' ); |
|
| 91 | + wp_register_style( 'wordlift-ui', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' ); |
|
| 92 | + |
|
| 93 | + // You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective. |
|
| 94 | + // |
|
| 95 | + // @see https://github.com/insideout10/wordlift-plugin/issues/821 |
|
| 96 | + // |
|
| 97 | + // wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-public.css', array(), $this->version, 'all' ); |
|
| 98 | + |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Register the stylesheets for the public-facing side of the site. |
|
| 103 | + * |
|
| 104 | + * @since 1.0.0 |
|
| 105 | + */ |
|
| 106 | + public function enqueue_scripts() { |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * This function is provided for demonstration purposes only. |
|
| 110 | + * |
|
| 111 | + * An instance of this class should be passed to the run() function |
|
| 112 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
| 113 | + * in that particular class. |
|
| 114 | + * |
|
| 115 | + * The Wordlift_Loader will then create the relationship |
|
| 116 | + * between the defined hooks and the functions defined in this |
|
| 117 | + * class. |
|
| 118 | + */ |
|
| 119 | + |
|
| 120 | + $settings = self::get_settings(); |
|
| 121 | + |
|
| 122 | + // Note that we switched the js to be loaded in footer, since it is loading |
|
| 123 | + // the json-ld representation. |
|
| 124 | + wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true ); |
|
| 125 | + wp_localize_script( $this->plugin_name, 'wlSettings', $settings ); |
|
| 126 | + |
|
| 127 | + /* |
|
| 128 | 128 | * Add WordLift's version. |
| 129 | 129 | * Can be disabled via filter 'wl_disable_version_js' since 3.21.1 |
| 130 | 130 | * |
@@ -133,126 +133,126 @@ discard block |
||
| 133 | 133 | * @see https://github.com/insideout10/wordlift-plugin/issues/843. |
| 134 | 134 | * @see https://github.com/insideout10/wordlift-plugin/issues/926. |
| 135 | 135 | */ |
| 136 | - $show_version_default = false; |
|
| 137 | - $show_version = apply_filters( 'wl_disable_version_js', $show_version_default ); |
|
| 136 | + $show_version_default = false; |
|
| 137 | + $show_version = apply_filters( 'wl_disable_version_js', $show_version_default ); |
|
| 138 | 138 | |
| 139 | - if ( $show_version ) { |
|
| 140 | - wp_localize_script( $this->plugin_name, 'wordlift', array( |
|
| 141 | - 'version' => $this->version, |
|
| 142 | - ) ); |
|
| 143 | - } |
|
| 139 | + if ( $show_version ) { |
|
| 140 | + wp_localize_script( $this->plugin_name, 'wordlift', array( |
|
| 141 | + 'version' => $this->version, |
|
| 142 | + ) ); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /* |
|
| 145 | + /* |
|
| 146 | 146 | * Register wordlift-cloud script which is shared by |
| 147 | 147 | * Navigator, Products Navigator, Faceted Search, Context Cards |
| 148 | 148 | * |
| 149 | 149 | * @since 3.22.0 |
| 150 | 150 | * |
| 151 | 151 | */ |
| 152 | - $deps = $this->wp_version_compare( '>=', '5.0' ) ? array( 'wp-hooks' ) : array(); |
|
| 152 | + $deps = $this->wp_version_compare( '>=', '5.0' ) ? array( 'wp-hooks' ) : array(); |
|
| 153 | 153 | |
| 154 | - /* |
|
| 154 | + /* |
|
| 155 | 155 | * Added defer to wordlift-cloud |
| 156 | 156 | * |
| 157 | 157 | * @since 3.27.4 |
| 158 | 158 | */ |
| 159 | - add_filter( 'script_loader_tag', function ( $tag, $handle ) { |
|
| 160 | - if ( 'wordlift-cloud' !== $handle ) { |
|
| 161 | - return $tag; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return str_replace( ' src', ' defer="defer" src', $tag ); |
|
| 165 | - }, 10, 2 ); |
|
| 166 | - wp_register_script( 'wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true ); |
|
| 167 | - |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Get the settings array. |
|
| 172 | - * |
|
| 173 | - * @return array An array with the settings. |
|
| 174 | - * @since 3.19.1 |
|
| 175 | - * |
|
| 176 | - */ |
|
| 177 | - public static function get_settings() { |
|
| 178 | - |
|
| 179 | - // Prepare a settings array for client-side functions. |
|
| 180 | - $settings = array( |
|
| 181 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
|
| 182 | - 'apiUrl' => get_home_url( null, 'wl-api/' ), |
|
| 183 | - 'jsonld_url' => rest_url( '/wordlift/v1/jsonld/' ) |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - // If we're in a single page, then print out the post id. |
|
| 187 | - if ( is_singular() ) { |
|
| 188 | - $settings['postId'] = get_the_ID(); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Add flag that we are on home/blog page. |
|
| 192 | - if ( is_home() || is_front_page() ) { |
|
| 193 | - $settings['isHome'] = true; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - // As of 2020-02-15, we publish the JSON-LD in the head, see Jsonld_Adaper. |
|
| 197 | - $settings['jsonld_enabled'] = false; |
|
| 198 | - |
|
| 199 | - // By default only enable JSON-LD on supported entity pages (includes |
|
| 200 | - // `page`, `post` and `entity` by default) and on the home page. |
|
| 201 | - // |
|
| 202 | - // @see https://github.com/insideout10/wordlift-plugin/issues/733 |
|
| 203 | - // $jsonld_enabled = is_home() || is_front_page() || Wordlift_Entity_Type_Service::is_valid_entity_post_type( get_post_type() ); |
|
| 204 | - |
|
| 205 | - // Add the JSON-LD enabled flag, when set to false, the JSON-LD won't |
|
| 206 | - // be loaded. |
|
| 207 | - // |
|
| 208 | - // @see https://github.com/insideout10/wordlift-plugin/issues/642. |
|
| 209 | - // $settings['jsonld_enabled'] = apply_filters( 'wl_jsonld_enabled', $jsonld_enabled ); |
|
| 210 | - |
|
| 211 | - return $settings; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Get the public JavaScript URL. |
|
| 216 | - * |
|
| 217 | - * Using this function is encouraged, since the public JavaScript is also used by the {@link Wordlift_WpRocket_Adapter} |
|
| 218 | - * in order to avoid breaking optimizations. |
|
| 219 | - * |
|
| 220 | - * @return string The URL to the public JavaScript. |
|
| 221 | - * @see https://github.com/insideout10/wordlift-plugin/issues/842. |
|
| 222 | - * |
|
| 223 | - * @since 3.19.4 |
|
| 224 | - * |
|
| 225 | - */ |
|
| 226 | - public static function get_public_js_url() { |
|
| 227 | - |
|
| 228 | - return plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/bundle.js'; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Get the Cloud JavaScript URL. |
|
| 233 | - * |
|
| 234 | - * @see https://github.com/insideout10/wordlift-plugin/issues/971 |
|
| 235 | - * @since 3.23.0 |
|
| 236 | - * @return string The URL to the Cloud JavaScript. |
|
| 237 | - */ |
|
| 238 | - public static function get_cloud_js_url() { |
|
| 239 | - |
|
| 240 | - return plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/wordlift-cloud.js'; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Helper function to check WP version |
|
| 245 | - * |
|
| 246 | - * @since 3.26.0 |
|
| 247 | - * |
|
| 248 | - * @param string $operator |
|
| 249 | - * @param string $version |
|
| 250 | - * |
|
| 251 | - * @return mixed |
|
| 252 | - */ |
|
| 253 | - private function wp_version_compare( $operator = '>', $version = '5.0' ) { |
|
| 254 | - global $wp_version; |
|
| 255 | - |
|
| 256 | - return version_compare( $wp_version, $version, $operator ); |
|
| 257 | - } |
|
| 159 | + add_filter( 'script_loader_tag', function ( $tag, $handle ) { |
|
| 160 | + if ( 'wordlift-cloud' !== $handle ) { |
|
| 161 | + return $tag; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return str_replace( ' src', ' defer="defer" src', $tag ); |
|
| 165 | + }, 10, 2 ); |
|
| 166 | + wp_register_script( 'wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true ); |
|
| 167 | + |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Get the settings array. |
|
| 172 | + * |
|
| 173 | + * @return array An array with the settings. |
|
| 174 | + * @since 3.19.1 |
|
| 175 | + * |
|
| 176 | + */ |
|
| 177 | + public static function get_settings() { |
|
| 178 | + |
|
| 179 | + // Prepare a settings array for client-side functions. |
|
| 180 | + $settings = array( |
|
| 181 | + 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
|
| 182 | + 'apiUrl' => get_home_url( null, 'wl-api/' ), |
|
| 183 | + 'jsonld_url' => rest_url( '/wordlift/v1/jsonld/' ) |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + // If we're in a single page, then print out the post id. |
|
| 187 | + if ( is_singular() ) { |
|
| 188 | + $settings['postId'] = get_the_ID(); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Add flag that we are on home/blog page. |
|
| 192 | + if ( is_home() || is_front_page() ) { |
|
| 193 | + $settings['isHome'] = true; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + // As of 2020-02-15, we publish the JSON-LD in the head, see Jsonld_Adaper. |
|
| 197 | + $settings['jsonld_enabled'] = false; |
|
| 198 | + |
|
| 199 | + // By default only enable JSON-LD on supported entity pages (includes |
|
| 200 | + // `page`, `post` and `entity` by default) and on the home page. |
|
| 201 | + // |
|
| 202 | + // @see https://github.com/insideout10/wordlift-plugin/issues/733 |
|
| 203 | + // $jsonld_enabled = is_home() || is_front_page() || Wordlift_Entity_Type_Service::is_valid_entity_post_type( get_post_type() ); |
|
| 204 | + |
|
| 205 | + // Add the JSON-LD enabled flag, when set to false, the JSON-LD won't |
|
| 206 | + // be loaded. |
|
| 207 | + // |
|
| 208 | + // @see https://github.com/insideout10/wordlift-plugin/issues/642. |
|
| 209 | + // $settings['jsonld_enabled'] = apply_filters( 'wl_jsonld_enabled', $jsonld_enabled ); |
|
| 210 | + |
|
| 211 | + return $settings; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Get the public JavaScript URL. |
|
| 216 | + * |
|
| 217 | + * Using this function is encouraged, since the public JavaScript is also used by the {@link Wordlift_WpRocket_Adapter} |
|
| 218 | + * in order to avoid breaking optimizations. |
|
| 219 | + * |
|
| 220 | + * @return string The URL to the public JavaScript. |
|
| 221 | + * @see https://github.com/insideout10/wordlift-plugin/issues/842. |
|
| 222 | + * |
|
| 223 | + * @since 3.19.4 |
|
| 224 | + * |
|
| 225 | + */ |
|
| 226 | + public static function get_public_js_url() { |
|
| 227 | + |
|
| 228 | + return plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/bundle.js'; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Get the Cloud JavaScript URL. |
|
| 233 | + * |
|
| 234 | + * @see https://github.com/insideout10/wordlift-plugin/issues/971 |
|
| 235 | + * @since 3.23.0 |
|
| 236 | + * @return string The URL to the Cloud JavaScript. |
|
| 237 | + */ |
|
| 238 | + public static function get_cloud_js_url() { |
|
| 239 | + |
|
| 240 | + return plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/wordlift-cloud.js'; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Helper function to check WP version |
|
| 245 | + * |
|
| 246 | + * @since 3.26.0 |
|
| 247 | + * |
|
| 248 | + * @param string $operator |
|
| 249 | + * @param string $version |
|
| 250 | + * |
|
| 251 | + * @return mixed |
|
| 252 | + */ |
|
| 253 | + private function wp_version_compare( $operator = '>', $version = '5.0' ) { |
|
| 254 | + global $wp_version; |
|
| 255 | + |
|
| 256 | + return version_compare( $wp_version, $version, $operator ); |
|
| 257 | + } |
|
| 258 | 258 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @since 1.0.0 |
| 50 | 50 | * |
| 51 | 51 | */ |
| 52 | - public function __construct( $plugin_name, $version ) { |
|
| 52 | + public function __construct($plugin_name, $version) { |
|
| 53 | 53 | |
| 54 | 54 | $this->plugin_name = $plugin_name; |
| 55 | 55 | $this->version = $version; |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | * @since 3.19.3 |
| 85 | 85 | * |
| 86 | 86 | */ |
| 87 | - $deps = apply_filters( 'wl_include_font_awesome', true ) |
|
| 88 | - ? array( 'wordlift-font-awesome' ) |
|
| 87 | + $deps = apply_filters('wl_include_font_awesome', true) |
|
| 88 | + ? array('wordlift-font-awesome') |
|
| 89 | 89 | : array(); |
| 90 | - wp_register_style( 'wordlift-font-awesome', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' ); |
|
| 91 | - wp_register_style( 'wordlift-ui', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' ); |
|
| 90 | + wp_register_style('wordlift-font-awesome', plugin_dir_url(dirname(__FILE__)).'css/wordlift-font-awesome'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.css', array(), $this->version, 'all'); |
|
| 91 | + wp_register_style('wordlift-ui', plugin_dir_url(dirname(__FILE__)).'css/wordlift-ui'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.css', $deps, $this->version, 'all'); |
|
| 92 | 92 | |
| 93 | 93 | // You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective. |
| 94 | 94 | // |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | // Note that we switched the js to be loaded in footer, since it is loading |
| 123 | 123 | // the json-ld representation. |
| 124 | - wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true ); |
|
| 125 | - wp_localize_script( $this->plugin_name, 'wlSettings', $settings ); |
|
| 124 | + wp_enqueue_script($this->plugin_name, self::get_public_js_url(), array(), $this->version, true); |
|
| 125 | + wp_localize_script($this->plugin_name, 'wlSettings', $settings); |
|
| 126 | 126 | |
| 127 | 127 | /* |
| 128 | 128 | * Add WordLift's version. |
@@ -134,12 +134,12 @@ discard block |
||
| 134 | 134 | * @see https://github.com/insideout10/wordlift-plugin/issues/926. |
| 135 | 135 | */ |
| 136 | 136 | $show_version_default = false; |
| 137 | - $show_version = apply_filters( 'wl_disable_version_js', $show_version_default ); |
|
| 137 | + $show_version = apply_filters('wl_disable_version_js', $show_version_default); |
|
| 138 | 138 | |
| 139 | - if ( $show_version ) { |
|
| 140 | - wp_localize_script( $this->plugin_name, 'wordlift', array( |
|
| 139 | + if ($show_version) { |
|
| 140 | + wp_localize_script($this->plugin_name, 'wordlift', array( |
|
| 141 | 141 | 'version' => $this->version, |
| 142 | - ) ); |
|
| 142 | + )); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /* |
@@ -149,21 +149,21 @@ discard block |
||
| 149 | 149 | * @since 3.22.0 |
| 150 | 150 | * |
| 151 | 151 | */ |
| 152 | - $deps = $this->wp_version_compare( '>=', '5.0' ) ? array( 'wp-hooks' ) : array(); |
|
| 152 | + $deps = $this->wp_version_compare('>=', '5.0') ? array('wp-hooks') : array(); |
|
| 153 | 153 | |
| 154 | 154 | /* |
| 155 | 155 | * Added defer to wordlift-cloud |
| 156 | 156 | * |
| 157 | 157 | * @since 3.27.4 |
| 158 | 158 | */ |
| 159 | - add_filter( 'script_loader_tag', function ( $tag, $handle ) { |
|
| 160 | - if ( 'wordlift-cloud' !== $handle ) { |
|
| 159 | + add_filter('script_loader_tag', function($tag, $handle) { |
|
| 160 | + if ('wordlift-cloud' !== $handle) { |
|
| 161 | 161 | return $tag; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - return str_replace( ' src', ' defer="defer" src', $tag ); |
|
| 165 | - }, 10, 2 ); |
|
| 166 | - wp_register_script( 'wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true ); |
|
| 164 | + return str_replace(' src', ' defer="defer" src', $tag); |
|
| 165 | + }, 10, 2); |
|
| 166 | + wp_register_script('wordlift-cloud', self::get_cloud_js_url(), $deps, Wordlift::get_instance()->get_version(), true); |
|
| 167 | 167 | |
| 168 | 168 | } |
| 169 | 169 | |
@@ -178,18 +178,18 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | // Prepare a settings array for client-side functions. |
| 180 | 180 | $settings = array( |
| 181 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
|
| 182 | - 'apiUrl' => get_home_url( null, 'wl-api/' ), |
|
| 183 | - 'jsonld_url' => rest_url( '/wordlift/v1/jsonld/' ) |
|
| 181 | + 'ajaxUrl' => admin_url('admin-ajax.php'), |
|
| 182 | + 'apiUrl' => get_home_url(null, 'wl-api/'), |
|
| 183 | + 'jsonld_url' => rest_url('/wordlift/v1/jsonld/') |
|
| 184 | 184 | ); |
| 185 | 185 | |
| 186 | 186 | // If we're in a single page, then print out the post id. |
| 187 | - if ( is_singular() ) { |
|
| 187 | + if (is_singular()) { |
|
| 188 | 188 | $settings['postId'] = get_the_ID(); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | // Add flag that we are on home/blog page. |
| 192 | - if ( is_home() || is_front_page() ) { |
|
| 192 | + if (is_home() || is_front_page()) { |
|
| 193 | 193 | $settings['isHome'] = true; |
| 194 | 194 | } |
| 195 | 195 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public static function get_public_js_url() { |
| 227 | 227 | |
| 228 | - return plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/bundle.js'; |
|
| 228 | + return plugin_dir_url(dirname(__FILE__)).'js/dist/bundle.js'; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | public static function get_cloud_js_url() { |
| 239 | 239 | |
| 240 | - return plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/wordlift-cloud.js'; |
|
| 240 | + return plugin_dir_url(dirname(__FILE__)).'js/dist/wordlift-cloud.js'; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @return mixed |
| 252 | 252 | */ |
| 253 | - private function wp_version_compare( $operator = '>', $version = '5.0' ) { |
|
| 253 | + private function wp_version_compare($operator = '>', $version = '5.0') { |
|
| 254 | 254 | global $wp_version; |
| 255 | 255 | |
| 256 | - return version_compare( $wp_version, $version, $operator ); |
|
| 256 | + return version_compare($wp_version, $version, $operator); |
|
| 257 | 257 | } |
| 258 | 258 | } |
@@ -11,60 +11,60 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Acf_Data_Source implements Abstract_Data_Source { |
| 13 | 13 | |
| 14 | - public function get_data( $identifier, $property_data, $type ) { |
|
| 14 | + public function get_data( $identifier, $property_data, $type ) { |
|
| 15 | 15 | |
| 16 | - if ( ! function_exists( 'get_field' ) || ! function_exists( 'get_field_object' ) ) { |
|
| 17 | - return array(); |
|
| 18 | - } |
|
| 16 | + if ( ! function_exists( 'get_field' ) || ! function_exists( 'get_field_object' ) ) { |
|
| 17 | + return array(); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - return $this->get_data_for_acf_field( $property_data['field_name'], $identifier, $type ); |
|
| 21 | - } |
|
| 20 | + return $this->get_data_for_acf_field( $property_data['field_name'], $identifier, $type ); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Gets data from acf, format the data if it is a repeater field. |
|
| 25 | - * |
|
| 26 | - * @param $field_name string |
|
| 27 | - * @param $identifier int Identifier ( post id or term id ) |
|
| 28 | - * |
|
| 29 | - * @return array|mixed |
|
| 30 | - */ |
|
| 31 | - private function get_data_for_acf_field( $field_name, $identifier, $type ) { |
|
| 32 | - if ( $type === Jsonld_Converter::TERM ) { |
|
| 33 | - $term = get_term( $identifier ); |
|
| 34 | - // Data fetching method for term is different. |
|
| 35 | - $field_data = get_field_object( $field_name, $term ); |
|
| 36 | - $data = get_field( $field_name, $term ); |
|
| 37 | - } else { |
|
| 38 | - $field_data = get_field_object( $field_name, $identifier ); |
|
| 39 | - $data = get_field( $field_name, $identifier ); |
|
| 40 | - } |
|
| 41 | - // only process if it is a repeater field, else return the data. |
|
| 42 | - if ( is_array( $field_data ) && array_key_exists( 'type', $field_data ) |
|
| 43 | - && $field_data['type'] === 'repeater' ) { |
|
| 44 | - /** |
|
| 45 | - * check if we have only one sub field, currently we only support one subfield, |
|
| 46 | - * so each repeater item should be checked if there is a single sub field. |
|
| 47 | - */ |
|
| 48 | - if ( is_array( $data ) && |
|
| 49 | - count( $data ) > 0 && |
|
| 50 | - count( array_keys( $data[0] ) ) === 1 ) { |
|
| 51 | - $repeater_formatted_data = array(); |
|
| 52 | - foreach ( $data as $item ) { |
|
| 53 | - $repeater_formatted_data = array_merge( $repeater_formatted_data, array_values( $item ) ); |
|
| 54 | - } |
|
| 55 | - // Remove non unique values. |
|
| 56 | - $repeater_formatted_data = array_unique( $repeater_formatted_data ); |
|
| 57 | - // Remove empty values |
|
| 58 | - $repeater_formatted_data = array_filter( $repeater_formatted_data, function ( $item ) { |
|
| 59 | - return is_array( $item ) || strlen( $item ); |
|
| 60 | - } ); |
|
| 23 | + /** |
|
| 24 | + * Gets data from acf, format the data if it is a repeater field. |
|
| 25 | + * |
|
| 26 | + * @param $field_name string |
|
| 27 | + * @param $identifier int Identifier ( post id or term id ) |
|
| 28 | + * |
|
| 29 | + * @return array|mixed |
|
| 30 | + */ |
|
| 31 | + private function get_data_for_acf_field( $field_name, $identifier, $type ) { |
|
| 32 | + if ( $type === Jsonld_Converter::TERM ) { |
|
| 33 | + $term = get_term( $identifier ); |
|
| 34 | + // Data fetching method for term is different. |
|
| 35 | + $field_data = get_field_object( $field_name, $term ); |
|
| 36 | + $data = get_field( $field_name, $term ); |
|
| 37 | + } else { |
|
| 38 | + $field_data = get_field_object( $field_name, $identifier ); |
|
| 39 | + $data = get_field( $field_name, $identifier ); |
|
| 40 | + } |
|
| 41 | + // only process if it is a repeater field, else return the data. |
|
| 42 | + if ( is_array( $field_data ) && array_key_exists( 'type', $field_data ) |
|
| 43 | + && $field_data['type'] === 'repeater' ) { |
|
| 44 | + /** |
|
| 45 | + * check if we have only one sub field, currently we only support one subfield, |
|
| 46 | + * so each repeater item should be checked if there is a single sub field. |
|
| 47 | + */ |
|
| 48 | + if ( is_array( $data ) && |
|
| 49 | + count( $data ) > 0 && |
|
| 50 | + count( array_keys( $data[0] ) ) === 1 ) { |
|
| 51 | + $repeater_formatted_data = array(); |
|
| 52 | + foreach ( $data as $item ) { |
|
| 53 | + $repeater_formatted_data = array_merge( $repeater_formatted_data, array_values( $item ) ); |
|
| 54 | + } |
|
| 55 | + // Remove non unique values. |
|
| 56 | + $repeater_formatted_data = array_unique( $repeater_formatted_data ); |
|
| 57 | + // Remove empty values |
|
| 58 | + $repeater_formatted_data = array_filter( $repeater_formatted_data, function ( $item ) { |
|
| 59 | + return is_array( $item ) || strlen( $item ); |
|
| 60 | + } ); |
|
| 61 | 61 | |
| 62 | - // re-index all the values. |
|
| 63 | - return array_values( $repeater_formatted_data ); |
|
| 64 | - } |
|
| 65 | - } |
|
| 62 | + // re-index all the values. |
|
| 63 | + return array_values( $repeater_formatted_data ); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - // Return normal acf data if it is not a repeater field. |
|
| 68 | - return $data; |
|
| 69 | - } |
|
| 67 | + // Return normal acf data if it is not a repeater field. |
|
| 68 | + return $data; |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -11,13 +11,13 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | class Acf_Data_Source implements Abstract_Data_Source { |
| 13 | 13 | |
| 14 | - public function get_data( $identifier, $property_data, $type ) { |
|
| 14 | + public function get_data($identifier, $property_data, $type) { |
|
| 15 | 15 | |
| 16 | - if ( ! function_exists( 'get_field' ) || ! function_exists( 'get_field_object' ) ) { |
|
| 16 | + if ( ! function_exists('get_field') || ! function_exists('get_field_object')) { |
|
| 17 | 17 | return array(); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - return $this->get_data_for_acf_field( $property_data['field_name'], $identifier, $type ); |
|
| 20 | + return $this->get_data_for_acf_field($property_data['field_name'], $identifier, $type); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -28,39 +28,39 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return array|mixed |
| 30 | 30 | */ |
| 31 | - private function get_data_for_acf_field( $field_name, $identifier, $type ) { |
|
| 32 | - if ( $type === Jsonld_Converter::TERM ) { |
|
| 33 | - $term = get_term( $identifier ); |
|
| 31 | + private function get_data_for_acf_field($field_name, $identifier, $type) { |
|
| 32 | + if ($type === Jsonld_Converter::TERM) { |
|
| 33 | + $term = get_term($identifier); |
|
| 34 | 34 | // Data fetching method for term is different. |
| 35 | - $field_data = get_field_object( $field_name, $term ); |
|
| 36 | - $data = get_field( $field_name, $term ); |
|
| 35 | + $field_data = get_field_object($field_name, $term); |
|
| 36 | + $data = get_field($field_name, $term); |
|
| 37 | 37 | } else { |
| 38 | - $field_data = get_field_object( $field_name, $identifier ); |
|
| 39 | - $data = get_field( $field_name, $identifier ); |
|
| 38 | + $field_data = get_field_object($field_name, $identifier); |
|
| 39 | + $data = get_field($field_name, $identifier); |
|
| 40 | 40 | } |
| 41 | 41 | // only process if it is a repeater field, else return the data. |
| 42 | - if ( is_array( $field_data ) && array_key_exists( 'type', $field_data ) |
|
| 43 | - && $field_data['type'] === 'repeater' ) { |
|
| 42 | + if (is_array($field_data) && array_key_exists('type', $field_data) |
|
| 43 | + && $field_data['type'] === 'repeater') { |
|
| 44 | 44 | /** |
| 45 | 45 | * check if we have only one sub field, currently we only support one subfield, |
| 46 | 46 | * so each repeater item should be checked if there is a single sub field. |
| 47 | 47 | */ |
| 48 | - if ( is_array( $data ) && |
|
| 49 | - count( $data ) > 0 && |
|
| 50 | - count( array_keys( $data[0] ) ) === 1 ) { |
|
| 48 | + if (is_array($data) && |
|
| 49 | + count($data) > 0 && |
|
| 50 | + count(array_keys($data[0])) === 1) { |
|
| 51 | 51 | $repeater_formatted_data = array(); |
| 52 | - foreach ( $data as $item ) { |
|
| 53 | - $repeater_formatted_data = array_merge( $repeater_formatted_data, array_values( $item ) ); |
|
| 52 | + foreach ($data as $item) { |
|
| 53 | + $repeater_formatted_data = array_merge($repeater_formatted_data, array_values($item)); |
|
| 54 | 54 | } |
| 55 | 55 | // Remove non unique values. |
| 56 | - $repeater_formatted_data = array_unique( $repeater_formatted_data ); |
|
| 56 | + $repeater_formatted_data = array_unique($repeater_formatted_data); |
|
| 57 | 57 | // Remove empty values |
| 58 | - $repeater_formatted_data = array_filter( $repeater_formatted_data, function ( $item ) { |
|
| 59 | - return is_array( $item ) || strlen( $item ); |
|
| 58 | + $repeater_formatted_data = array_filter($repeater_formatted_data, function($item) { |
|
| 59 | + return is_array($item) || strlen($item); |
|
| 60 | 60 | } ); |
| 61 | 61 | |
| 62 | 62 | // re-index all the values. |
| 63 | - return array_values( $repeater_formatted_data ); |
|
| 63 | + return array_values($repeater_formatted_data); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -2,50 +2,50 @@ |
||
| 2 | 2 | |
| 3 | 3 | class Wordlift_Timeline_Widget extends WP_Widget { |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * Sets up the widgets name etc |
|
| 7 | - */ |
|
| 8 | - public function __construct() { |
|
| 9 | - // widget actual processes |
|
| 10 | - parent::__construct( |
|
| 11 | - 'wl_timeline_widget', // Base ID |
|
| 12 | - __( 'WordLift Timeline Widget', 'wordlift' ), // Name |
|
| 13 | - array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ), ) // Args |
|
| 14 | - ); |
|
| 15 | - } |
|
| 5 | + /** |
|
| 6 | + * Sets up the widgets name etc |
|
| 7 | + */ |
|
| 8 | + public function __construct() { |
|
| 9 | + // widget actual processes |
|
| 10 | + parent::__construct( |
|
| 11 | + 'wl_timeline_widget', // Base ID |
|
| 12 | + __( 'WordLift Timeline Widget', 'wordlift' ), // Name |
|
| 13 | + array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ), ) // Args |
|
| 14 | + ); |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Outputs the content of the widget |
|
| 19 | - * |
|
| 20 | - * @param array $args |
|
| 21 | - * @param array $instance |
|
| 22 | - */ |
|
| 23 | - public function widget( $args, $instance ) { |
|
| 24 | - // outputs the content of the widget |
|
| 25 | - echo do_shortcode( '[wl_timeline global=true]' ); |
|
| 26 | - } |
|
| 17 | + /** |
|
| 18 | + * Outputs the content of the widget |
|
| 19 | + * |
|
| 20 | + * @param array $args |
|
| 21 | + * @param array $instance |
|
| 22 | + */ |
|
| 23 | + public function widget( $args, $instance ) { |
|
| 24 | + // outputs the content of the widget |
|
| 25 | + echo do_shortcode( '[wl_timeline global=true]' ); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Outputs the options form on admin |
|
| 30 | - * |
|
| 31 | - * @param array $instance The widget options |
|
| 32 | - */ |
|
| 33 | - public function form( $instance ) { |
|
| 34 | - // outputs the options form on admin |
|
| 35 | - } |
|
| 28 | + /** |
|
| 29 | + * Outputs the options form on admin |
|
| 30 | + * |
|
| 31 | + * @param array $instance The widget options |
|
| 32 | + */ |
|
| 33 | + public function form( $instance ) { |
|
| 34 | + // outputs the options form on admin |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Processing widget options on save |
|
| 39 | - * |
|
| 40 | - * @param array $new_instance The new options |
|
| 41 | - * @param array $old_instance The previous options |
|
| 42 | - */ |
|
| 43 | - public function update( $new_instance, $old_instance ) { |
|
| 44 | - // processes widget options to be saved |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * Processing widget options on save |
|
| 39 | + * |
|
| 40 | + * @param array $new_instance The new options |
|
| 41 | + * @param array $old_instance The previous options |
|
| 42 | + */ |
|
| 43 | + public function update( $new_instance, $old_instance ) { |
|
| 44 | + // processes widget options to be saved |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | function wl_register_timeline_widget() { |
| 49 | 49 | |
| 50 | - register_widget( 'WordLift_Timeline_Widget' ); |
|
| 50 | + register_widget( 'WordLift_Timeline_Widget' ); |
|
| 51 | 51 | } |
@@ -9,8 +9,8 @@ discard block |
||
| 9 | 9 | // widget actual processes |
| 10 | 10 | parent::__construct( |
| 11 | 11 | 'wl_timeline_widget', // Base ID |
| 12 | - __( 'WordLift Timeline Widget', 'wordlift' ), // Name |
|
| 13 | - array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ), ) // Args |
|
| 12 | + __('WordLift Timeline Widget', 'wordlift'), // Name |
|
| 13 | + array('description' => __('Displays entities of type event using an interactive timeline.', 'wordlift'),) // Args |
|
| 14 | 14 | ); |
| 15 | 15 | } |
| 16 | 16 | |
@@ -20,9 +20,9 @@ discard block |
||
| 20 | 20 | * @param array $args |
| 21 | 21 | * @param array $instance |
| 22 | 22 | */ |
| 23 | - public function widget( $args, $instance ) { |
|
| 23 | + public function widget($args, $instance) { |
|
| 24 | 24 | // outputs the content of the widget |
| 25 | - echo do_shortcode( '[wl_timeline global=true]' ); |
|
| 25 | + echo do_shortcode('[wl_timeline global=true]'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @param array $instance The widget options |
| 32 | 32 | */ |
| 33 | - public function form( $instance ) { |
|
| 33 | + public function form($instance) { |
|
| 34 | 34 | // outputs the options form on admin |
| 35 | 35 | } |
| 36 | 36 | |
@@ -40,12 +40,12 @@ discard block |
||
| 40 | 40 | * @param array $new_instance The new options |
| 41 | 41 | * @param array $old_instance The previous options |
| 42 | 42 | */ |
| 43 | - public function update( $new_instance, $old_instance ) { |
|
| 43 | + public function update($new_instance, $old_instance) { |
|
| 44 | 44 | // processes widget options to be saved |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | function wl_register_timeline_widget() { |
| 49 | 49 | |
| 50 | - register_widget( 'WordLift_Timeline_Widget' ); |
|
| 50 | + register_widget('WordLift_Timeline_Widget'); |
|
| 51 | 51 | } |
@@ -10,54 +10,54 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class Wordlift_Chord_Widget extends WP_Widget { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Sets up the widgets name etc |
|
| 15 | - */ |
|
| 16 | - public function __construct() { |
|
| 17 | - // widget actual processes. |
|
| 18 | - parent::__construct( |
|
| 19 | - 'wl_chord_widget', // Base ID. |
|
| 20 | - __( 'Chord Widget', 'wordlift' ), // Name. |
|
| 21 | - array( |
|
| 22 | - 'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ), |
|
| 23 | - ) // Args. |
|
| 24 | - ); |
|
| 25 | - } |
|
| 13 | + /** |
|
| 14 | + * Sets up the widgets name etc |
|
| 15 | + */ |
|
| 16 | + public function __construct() { |
|
| 17 | + // widget actual processes. |
|
| 18 | + parent::__construct( |
|
| 19 | + 'wl_chord_widget', // Base ID. |
|
| 20 | + __( 'Chord Widget', 'wordlift' ), // Name. |
|
| 21 | + array( |
|
| 22 | + 'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ), |
|
| 23 | + ) // Args. |
|
| 24 | + ); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Outputs the content of the widget |
|
| 29 | - * |
|
| 30 | - * @param array $args widget args. |
|
| 31 | - * @param array $instance widget instance. |
|
| 32 | - */ |
|
| 33 | - // @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found |
|
| 34 | - public function widget( $args, $instance ) { |
|
| 35 | - // outputs the content of the widget. |
|
| 36 | - echo do_shortcode( '[wl_chord global=true]' ); |
|
| 37 | - } |
|
| 27 | + /** |
|
| 28 | + * Outputs the content of the widget |
|
| 29 | + * |
|
| 30 | + * @param array $args widget args. |
|
| 31 | + * @param array $instance widget instance. |
|
| 32 | + */ |
|
| 33 | + // @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found |
|
| 34 | + public function widget( $args, $instance ) { |
|
| 35 | + // outputs the content of the widget. |
|
| 36 | + echo do_shortcode( '[wl_chord global=true]' ); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Outputs the options form on admin |
|
| 41 | - * |
|
| 42 | - * @param array $instance The widget options. |
|
| 43 | - * |
|
| 44 | - * @return string|void |
|
| 45 | - */ |
|
| 46 | - public function form( $instance ) { |
|
| 47 | - // outputs the options form on admin. |
|
| 48 | - } |
|
| 39 | + /** |
|
| 40 | + * Outputs the options form on admin |
|
| 41 | + * |
|
| 42 | + * @param array $instance The widget options. |
|
| 43 | + * |
|
| 44 | + * @return string|void |
|
| 45 | + */ |
|
| 46 | + public function form( $instance ) { |
|
| 47 | + // outputs the options form on admin. |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Processing widget options on save |
|
| 52 | - * |
|
| 53 | - * @param array $new_instance The new options. |
|
| 54 | - * @param array $old_instance The previous options. |
|
| 55 | - * |
|
| 56 | - * @return array|void |
|
| 57 | - */ |
|
| 58 | - public function update( $new_instance, $old_instance ) { |
|
| 59 | - // processes widget options to be saved. |
|
| 60 | - } |
|
| 50 | + /** |
|
| 51 | + * Processing widget options on save |
|
| 52 | + * |
|
| 53 | + * @param array $new_instance The new options. |
|
| 54 | + * @param array $old_instance The previous options. |
|
| 55 | + * |
|
| 56 | + * @return array|void |
|
| 57 | + */ |
|
| 58 | + public function update( $new_instance, $old_instance ) { |
|
| 59 | + // processes widget options to be saved. |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -67,5 +67,5 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | function wl_register_chord_widget() { |
| 69 | 69 | |
| 70 | - register_widget( 'WordLift_Chord_Widget' ); |
|
| 70 | + register_widget( 'WordLift_Chord_Widget' ); |
|
| 71 | 71 | } |
| 72 | 72 | \ No newline at end of file |
@@ -17,9 +17,9 @@ discard block |
||
| 17 | 17 | // widget actual processes. |
| 18 | 18 | parent::__construct( |
| 19 | 19 | 'wl_chord_widget', // Base ID. |
| 20 | - __( 'Chord Widget', 'wordlift' ), // Name. |
|
| 20 | + __('Chord Widget', 'wordlift'), // Name. |
|
| 21 | 21 | array( |
| 22 | - 'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ), |
|
| 22 | + 'description' => __('The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift'), |
|
| 23 | 23 | ) // Args. |
| 24 | 24 | ); |
| 25 | 25 | } |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | * @param array $instance widget instance. |
| 32 | 32 | */ |
| 33 | 33 | // @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 34 | - public function widget( $args, $instance ) { |
|
| 34 | + public function widget($args, $instance) { |
|
| 35 | 35 | // outputs the content of the widget. |
| 36 | - echo do_shortcode( '[wl_chord global=true]' ); |
|
| 36 | + echo do_shortcode('[wl_chord global=true]'); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return string|void |
| 45 | 45 | */ |
| 46 | - public function form( $instance ) { |
|
| 46 | + public function form($instance) { |
|
| 47 | 47 | // outputs the options form on admin. |
| 48 | 48 | } |
| 49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return array|void |
| 57 | 57 | */ |
| 58 | - public function update( $new_instance, $old_instance ) { |
|
| 58 | + public function update($new_instance, $old_instance) { |
|
| 59 | 59 | // processes widget options to be saved. |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -67,5 +67,5 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | function wl_register_chord_widget() { |
| 69 | 69 | |
| 70 | - register_widget( 'WordLift_Chord_Widget' ); |
|
| 70 | + register_widget('WordLift_Chord_Widget'); |
|
| 71 | 71 | } |
| 72 | 72 | \ No newline at end of file |