@@ -10,50 +10,50 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Videoobject_Duplicate_Remover { |
| 12 | 12 | |
| 13 | - public function __construct() { |
|
| 14 | - add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 ); |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * @param $jsonld array The final jsonld. |
|
| 19 | - * @param $post_id int The post id. |
|
| 20 | - * |
|
| 21 | - * @return array Filtered jsonld. |
|
| 22 | - */ |
|
| 23 | - public function wl_after_get_jsonld( $jsonld, $post_id ) { |
|
| 24 | - |
|
| 25 | - if ( ! is_array( $jsonld ) |
|
| 26 | - || ! count( $jsonld ) > 1 |
|
| 27 | - || ! array_key_exists( 0, $jsonld ) ) { |
|
| 28 | - // Return early if there are no referenced entities. |
|
| 29 | - return $jsonld; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - $post_jsonld = array_shift( $jsonld ); |
|
| 33 | - |
|
| 34 | - // we need to loop through all the items and remove the faq markup. |
|
| 35 | - foreach ( $jsonld as $key => &$value ) { |
|
| 36 | - if ( ! array_key_exists( '@type', $value ) ) { |
|
| 37 | - continue; |
|
| 38 | - } |
|
| 39 | - $type = $value['@type']; |
|
| 40 | - |
|
| 41 | - if ( ( is_string( $type ) && $type !== 'Article' ) |
|
| 42 | - || ( is_array( $type ) && ! in_array( 'Article', $type ) ) ) { |
|
| 43 | - continue; |
|
| 44 | - } |
|
| 45 | - // Video doesnt exist, dont try to remove it. |
|
| 46 | - if ( ! array_key_exists( 'video', $value ) ) { |
|
| 47 | - continue; |
|
| 48 | - } |
|
| 49 | - unset( $jsonld[ $key ]['video'] ); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - // Add the post jsonld to front of jsonld array. |
|
| 53 | - array_unshift( $jsonld, $post_jsonld ); |
|
| 54 | - |
|
| 55 | - return $jsonld; |
|
| 56 | - } |
|
| 13 | + public function __construct() { |
|
| 14 | + add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 ); |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * @param $jsonld array The final jsonld. |
|
| 19 | + * @param $post_id int The post id. |
|
| 20 | + * |
|
| 21 | + * @return array Filtered jsonld. |
|
| 22 | + */ |
|
| 23 | + public function wl_after_get_jsonld( $jsonld, $post_id ) { |
|
| 24 | + |
|
| 25 | + if ( ! is_array( $jsonld ) |
|
| 26 | + || ! count( $jsonld ) > 1 |
|
| 27 | + || ! array_key_exists( 0, $jsonld ) ) { |
|
| 28 | + // Return early if there are no referenced entities. |
|
| 29 | + return $jsonld; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + $post_jsonld = array_shift( $jsonld ); |
|
| 33 | + |
|
| 34 | + // we need to loop through all the items and remove the faq markup. |
|
| 35 | + foreach ( $jsonld as $key => &$value ) { |
|
| 36 | + if ( ! array_key_exists( '@type', $value ) ) { |
|
| 37 | + continue; |
|
| 38 | + } |
|
| 39 | + $type = $value['@type']; |
|
| 40 | + |
|
| 41 | + if ( ( is_string( $type ) && $type !== 'Article' ) |
|
| 42 | + || ( is_array( $type ) && ! in_array( 'Article', $type ) ) ) { |
|
| 43 | + continue; |
|
| 44 | + } |
|
| 45 | + // Video doesnt exist, dont try to remove it. |
|
| 46 | + if ( ! array_key_exists( 'video', $value ) ) { |
|
| 47 | + continue; |
|
| 48 | + } |
|
| 49 | + unset( $jsonld[ $key ]['video'] ); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + // Add the post jsonld to front of jsonld array. |
|
| 53 | + array_unshift( $jsonld, $post_jsonld ); |
|
| 54 | + |
|
| 55 | + return $jsonld; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | class Videoobject_Duplicate_Remover { |
| 12 | 12 | |
| 13 | 13 | public function __construct() { |
| 14 | - add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 ); |
|
| 14 | + add_filter('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10, 2); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -20,37 +20,37 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @return array Filtered jsonld. |
| 22 | 22 | */ |
| 23 | - public function wl_after_get_jsonld( $jsonld, $post_id ) { |
|
| 23 | + public function wl_after_get_jsonld($jsonld, $post_id) { |
|
| 24 | 24 | |
| 25 | - if ( ! is_array( $jsonld ) |
|
| 26 | - || ! count( $jsonld ) > 1 |
|
| 27 | - || ! array_key_exists( 0, $jsonld ) ) { |
|
| 25 | + if ( ! is_array($jsonld) |
|
| 26 | + || ! count($jsonld) > 1 |
|
| 27 | + || ! array_key_exists(0, $jsonld)) { |
|
| 28 | 28 | // Return early if there are no referenced entities. |
| 29 | 29 | return $jsonld; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - $post_jsonld = array_shift( $jsonld ); |
|
| 32 | + $post_jsonld = array_shift($jsonld); |
|
| 33 | 33 | |
| 34 | 34 | // we need to loop through all the items and remove the faq markup. |
| 35 | - foreach ( $jsonld as $key => &$value ) { |
|
| 36 | - if ( ! array_key_exists( '@type', $value ) ) { |
|
| 35 | + foreach ($jsonld as $key => &$value) { |
|
| 36 | + if ( ! array_key_exists('@type', $value)) { |
|
| 37 | 37 | continue; |
| 38 | 38 | } |
| 39 | 39 | $type = $value['@type']; |
| 40 | 40 | |
| 41 | - if ( ( is_string( $type ) && $type !== 'Article' ) |
|
| 42 | - || ( is_array( $type ) && ! in_array( 'Article', $type ) ) ) { |
|
| 41 | + if ((is_string($type) && $type !== 'Article') |
|
| 42 | + || (is_array($type) && ! in_array('Article', $type))) { |
|
| 43 | 43 | continue; |
| 44 | 44 | } |
| 45 | 45 | // Video doesnt exist, dont try to remove it. |
| 46 | - if ( ! array_key_exists( 'video', $value ) ) { |
|
| 46 | + if ( ! array_key_exists('video', $value)) { |
|
| 47 | 47 | continue; |
| 48 | 48 | } |
| 49 | - unset( $jsonld[ $key ]['video'] ); |
|
| 49 | + unset($jsonld[$key]['video']); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Add the post jsonld to front of jsonld array. |
| 53 | - array_unshift( $jsonld, $post_jsonld ); |
|
| 53 | + array_unshift($jsonld, $post_jsonld); |
|
| 54 | 54 | |
| 55 | 55 | return $jsonld; |
| 56 | 56 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param $entity_type_service \Wordlift_Entity_Type_Service |
| 29 | 29 | * @param \Wordlift_Property_Getter $property_getter |
| 30 | 30 | */ |
| 31 | - public function __construct( $entity_type_service, $property_getter ) { |
|
| 31 | + public function __construct($entity_type_service, $property_getter) { |
|
| 32 | 32 | parent::__construct(); |
| 33 | 33 | $this->entity_type_service = $entity_type_service; |
| 34 | 34 | $this->property_getter = $property_getter; |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | public function init_all_dependencies() { |
| 39 | 39 | new Entity_Type(); |
| 40 | 40 | new Term_Metabox(); |
| 41 | - $jsonld = new Jsonld_Generator( $this->entity_type_service, $this->property_getter ); |
|
| 41 | + $jsonld = new Jsonld_Generator($this->entity_type_service, $this->property_getter); |
|
| 42 | 42 | $jsonld->init(); |
| 43 | 43 | $term_save_hook = new Term_Save(); |
| 44 | 44 | $term_save_hook->init(); |
@@ -13,47 +13,47 @@ |
||
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | class Vocabulary_Terms_Loader extends Default_Loader { |
| 16 | - /** |
|
| 17 | - * @var \Wordlift_Entity_Type_Service |
|
| 18 | - */ |
|
| 19 | - private $entity_type_service; |
|
| 20 | - /** |
|
| 21 | - * @var \Wordlift_Property_Getter |
|
| 22 | - */ |
|
| 23 | - private $property_getter; |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Vocabulary_Terms_Loader constructor. |
|
| 28 | - * |
|
| 29 | - * @param $entity_type_service \Wordlift_Entity_Type_Service |
|
| 30 | - * @param \Wordlift_Property_Getter $property_getter |
|
| 31 | - */ |
|
| 32 | - public function __construct( $entity_type_service, $property_getter ) { |
|
| 33 | - parent::__construct(); |
|
| 34 | - $this->entity_type_service = $entity_type_service; |
|
| 35 | - $this->property_getter = $property_getter; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - public function init_all_dependencies() { |
|
| 40 | - new Entity_Type(); |
|
| 41 | - new Term_Metabox(); |
|
| 42 | - $jsonld = new Jsonld_Generator( $this->entity_type_service, $this->property_getter ); |
|
| 43 | - $jsonld->init(); |
|
| 44 | - $term_save_hook = new Term_Save(); |
|
| 45 | - $term_save_hook->init(); |
|
| 46 | - $post_jsonld = new Post_Jsonld(); |
|
| 47 | - $post_jsonld->init(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - protected function get_feature_slug() { |
|
| 51 | - return 'no-vocabulary-terms'; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - protected function get_feature_default_value() { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 16 | + /** |
|
| 17 | + * @var \Wordlift_Entity_Type_Service |
|
| 18 | + */ |
|
| 19 | + private $entity_type_service; |
|
| 20 | + /** |
|
| 21 | + * @var \Wordlift_Property_Getter |
|
| 22 | + */ |
|
| 23 | + private $property_getter; |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Vocabulary_Terms_Loader constructor. |
|
| 28 | + * |
|
| 29 | + * @param $entity_type_service \Wordlift_Entity_Type_Service |
|
| 30 | + * @param \Wordlift_Property_Getter $property_getter |
|
| 31 | + */ |
|
| 32 | + public function __construct( $entity_type_service, $property_getter ) { |
|
| 33 | + parent::__construct(); |
|
| 34 | + $this->entity_type_service = $entity_type_service; |
|
| 35 | + $this->property_getter = $property_getter; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + public function init_all_dependencies() { |
|
| 40 | + new Entity_Type(); |
|
| 41 | + new Term_Metabox(); |
|
| 42 | + $jsonld = new Jsonld_Generator( $this->entity_type_service, $this->property_getter ); |
|
| 43 | + $jsonld->init(); |
|
| 44 | + $term_save_hook = new Term_Save(); |
|
| 45 | + $term_save_hook->init(); |
|
| 46 | + $post_jsonld = new Post_Jsonld(); |
|
| 47 | + $post_jsonld->init(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + protected function get_feature_slug() { |
|
| 51 | + return 'no-vocabulary-terms'; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + protected function get_feature_default_value() { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | \ No newline at end of file |
@@ -15,52 +15,52 @@ |
||
| 15 | 15 | |
| 16 | 16 | abstract class Relation { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var int |
|
| 20 | - */ |
|
| 21 | - private $id; |
|
| 18 | + /** |
|
| 19 | + * @var int |
|
| 20 | + */ |
|
| 21 | + private $id; |
|
| 22 | 22 | |
| 23 | - private $relation_type; |
|
| 23 | + private $relation_type; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Represents a subject type. |
|
| 27 | - * @var int {@link Object_Type_Enum} |
|
| 28 | - */ |
|
| 29 | - private $subject_type; |
|
| 25 | + /** |
|
| 26 | + * Represents a subject type. |
|
| 27 | + * @var int {@link Object_Type_Enum} |
|
| 28 | + */ |
|
| 29 | + private $subject_type; |
|
| 30 | 30 | |
| 31 | - public function __construct( $id, $relation_type, $subject_type ) { |
|
| 32 | - $this->id = $id; |
|
| 33 | - $this->relation_type = $relation_type; |
|
| 34 | - $this->subject_type = $subject_type; |
|
| 35 | - } |
|
| 31 | + public function __construct( $id, $relation_type, $subject_type ) { |
|
| 32 | + $this->id = $id; |
|
| 33 | + $this->relation_type = $relation_type; |
|
| 34 | + $this->subject_type = $subject_type; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Return Object id. |
|
| 39 | - * @return int |
|
| 40 | - */ |
|
| 41 | - public function get_object_id() { |
|
| 42 | - return $this->id; |
|
| 43 | - } |
|
| 37 | + /** |
|
| 38 | + * Return Object id. |
|
| 39 | + * @return int |
|
| 40 | + */ |
|
| 41 | + public function get_object_id() { |
|
| 42 | + return $this->id; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return int Represents the {@link Object_Type_Enum} |
|
| 47 | - */ |
|
| 48 | - abstract function get_object_type(); |
|
| 45 | + /** |
|
| 46 | + * @return int Represents the {@link Object_Type_Enum} |
|
| 47 | + */ |
|
| 48 | + abstract function get_object_type(); |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @return int Represents the {@link Object_Type_Enum} |
|
| 52 | - */ |
|
| 53 | - function get_subject_type() { |
|
| 54 | - return $this->subject_type; |
|
| 55 | - } |
|
| 50 | + /** |
|
| 51 | + * @return int Represents the {@link Object_Type_Enum} |
|
| 52 | + */ |
|
| 53 | + function get_subject_type() { |
|
| 54 | + return $this->subject_type; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Returns relation type. |
|
| 60 | - * @return string Relation type {@link WL_WHAT_RELATION} etc. |
|
| 61 | - */ |
|
| 62 | - function get_relation_type() { |
|
| 63 | - return $this->relation_type; |
|
| 64 | - } |
|
| 58 | + /** |
|
| 59 | + * Returns relation type. |
|
| 60 | + * @return string Relation type {@link WL_WHAT_RELATION} etc. |
|
| 61 | + */ |
|
| 62 | + function get_relation_type() { |
|
| 63 | + return $this->relation_type; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | 67 | \ No newline at end of file |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | private $subject_type; |
| 30 | 30 | |
| 31 | - public function __construct( $id, $relation_type, $subject_type ) { |
|
| 31 | + public function __construct($id, $relation_type, $subject_type) { |
|
| 32 | 32 | $this->id = $id; |
| 33 | 33 | $this->relation_type = $relation_type; |
| 34 | 34 | $this->subject_type = $subject_type; |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | |
| 17 | 17 | class Term_Relation extends Relation { |
| 18 | 18 | |
| 19 | - function get_object_type() { |
|
| 20 | - return Object_Type_Enum::TERM; |
|
| 21 | - } |
|
| 19 | + function get_object_type() { |
|
| 20 | + return Object_Type_Enum::TERM; |
|
| 21 | + } |
|
| 22 | 22 | } |
| 23 | 23 | \ No newline at end of file |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | |
| 15 | 15 | use Wordlift\Object_Type_Enum; |
| 16 | 16 | |
| 17 | -class Term_Relation extends Relation { |
|
| 17 | +class Term_Relation extends Relation { |
|
| 18 | 18 | |
| 19 | 19 | function get_object_type() { |
| 20 | 20 | return Object_Type_Enum::TERM; |
@@ -16,8 +16,8 @@ |
||
| 16 | 16 | |
| 17 | 17 | class Post_Relation extends Relation { |
| 18 | 18 | |
| 19 | - function get_object_type() { |
|
| 20 | - return Object_Type_Enum::POST; |
|
| 21 | - } |
|
| 19 | + function get_object_type() { |
|
| 20 | + return Object_Type_Enum::POST; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | } |
| 24 | 24 | \ No newline at end of file |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | |
| 15 | 15 | use Wordlift\Object_Type_Enum; |
| 16 | 16 | |
| 17 | -class Post_Relation extends Relation { |
|
| 17 | +class Post_Relation extends Relation { |
|
| 18 | 18 | |
| 19 | 19 | function get_object_type() { |
| 20 | 20 | return Object_Type_Enum::POST; |
@@ -11,15 +11,15 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Synonyms_Service extends Singleton { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @return Synonyms_Service |
|
| 16 | - */ |
|
| 17 | - public static function get_instance() { |
|
| 18 | - return parent::get_instance(); |
|
| 19 | - } |
|
| 14 | + /** |
|
| 15 | + * @return Synonyms_Service |
|
| 16 | + */ |
|
| 17 | + public static function get_instance() { |
|
| 18 | + return parent::get_instance(); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function get_synonyms( $term_id ) { |
|
| 22 | - return get_term_meta( $term_id, \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ); |
|
| 23 | - } |
|
| 21 | + public function get_synonyms( $term_id ) { |
|
| 22 | + return get_term_meta( $term_id, \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -18,8 +18,8 @@ |
||
| 18 | 18 | return parent::get_instance(); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public function get_synonyms( $term_id ) { |
|
| 22 | - return get_term_meta( $term_id, \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY ); |
|
| 21 | + public function get_synonyms($term_id) { |
|
| 22 | + return get_term_meta($term_id, \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | private static $instance = null; |
| 13 | 13 | |
| 14 | 14 | public static function get_instance() { |
| 15 | - if ( self::$instance === null ) { |
|
| 15 | + if (self::$instance === null) { |
|
| 16 | 16 | self::$instance = new Features_Registry(); |
| 17 | 17 | } |
| 18 | 18 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @param $feature Feature |
| 24 | 24 | */ |
| 25 | - public function register_feature( $feature ) { |
|
| 25 | + public function register_feature($feature) { |
|
| 26 | 26 | $this->features[] = $feature; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param $default_value bool |
| 32 | 32 | * @param $callback callable |
| 33 | 33 | */ |
| 34 | - public function register_feature_from_slug( $feature_slug, $default_value, $callback ) { |
|
| 34 | + public function register_feature_from_slug($feature_slug, $default_value, $callback) { |
|
| 35 | 35 | $this->features[] = new Feature( |
| 36 | 36 | $feature_slug, |
| 37 | 37 | $default_value, |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function initialize_all_features() { |
| 43 | - foreach ( $this->features as $feature ) { |
|
| 43 | + foreach ($this->features as $feature) { |
|
| 44 | 44 | /** |
| 45 | 45 | * @var $feature Feature |
| 46 | 46 | */ |
| 47 | 47 | $feature_slug = $feature->feature_slug; |
| 48 | - if ( apply_filters( "wl_feature__enable__${feature_slug}", $feature->default_value ) ) { |
|
| 49 | - call_user_func( $feature->callback ); |
|
| 48 | + if (apply_filters("wl_feature__enable__${feature_slug}", $feature->default_value)) { |
|
| 49 | + call_user_func($feature->callback); |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | } |
@@ -4,54 +4,54 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Features_Registry { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @var array<Feature> |
|
| 9 | - */ |
|
| 10 | - private $features = array(); |
|
| 11 | - |
|
| 12 | - private static $instance = null; |
|
| 13 | - |
|
| 14 | - public static function get_instance() { |
|
| 15 | - if ( self::$instance === null ) { |
|
| 16 | - self::$instance = new Features_Registry(); |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - return self::$instance; |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @param $feature Feature |
|
| 24 | - */ |
|
| 25 | - public function register_feature( $feature ) { |
|
| 26 | - $this->features[] = $feature; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @param $feature_slug string |
|
| 31 | - * @param $default_value bool |
|
| 32 | - * @param $callback callable |
|
| 33 | - */ |
|
| 34 | - public function register_feature_from_slug( $feature_slug, $default_value, $callback ) { |
|
| 35 | - $this->features[] = new Feature( |
|
| 36 | - $feature_slug, |
|
| 37 | - $default_value, |
|
| 38 | - $callback |
|
| 39 | - ); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function initialize_all_features() { |
|
| 43 | - foreach ( $this->features as $feature ) { |
|
| 44 | - /** |
|
| 45 | - * @var $feature Feature |
|
| 46 | - */ |
|
| 47 | - $feature_slug = $feature->feature_slug; |
|
| 48 | - if ( apply_filters( "wl_feature__enable__${feature_slug}", $feature->default_value ) ) { |
|
| 49 | - call_user_func( $feature->callback ); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function clear_all() { |
|
| 55 | - $this->features = array(); |
|
| 56 | - } |
|
| 7 | + /** |
|
| 8 | + * @var array<Feature> |
|
| 9 | + */ |
|
| 10 | + private $features = array(); |
|
| 11 | + |
|
| 12 | + private static $instance = null; |
|
| 13 | + |
|
| 14 | + public static function get_instance() { |
|
| 15 | + if ( self::$instance === null ) { |
|
| 16 | + self::$instance = new Features_Registry(); |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + return self::$instance; |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @param $feature Feature |
|
| 24 | + */ |
|
| 25 | + public function register_feature( $feature ) { |
|
| 26 | + $this->features[] = $feature; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @param $feature_slug string |
|
| 31 | + * @param $default_value bool |
|
| 32 | + * @param $callback callable |
|
| 33 | + */ |
|
| 34 | + public function register_feature_from_slug( $feature_slug, $default_value, $callback ) { |
|
| 35 | + $this->features[] = new Feature( |
|
| 36 | + $feature_slug, |
|
| 37 | + $default_value, |
|
| 38 | + $callback |
|
| 39 | + ); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function initialize_all_features() { |
|
| 43 | + foreach ( $this->features as $feature ) { |
|
| 44 | + /** |
|
| 45 | + * @var $feature Feature |
|
| 46 | + */ |
|
| 47 | + $feature_slug = $feature->feature_slug; |
|
| 48 | + if ( apply_filters( "wl_feature__enable__${feature_slug}", $feature->default_value ) ) { |
|
| 49 | + call_user_func( $feature->callback ); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function clear_all() { |
|
| 55 | + $this->features = array(); |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | \ No newline at end of file |
@@ -6,103 +6,103 @@ |
||
| 6 | 6 | namespace Wordlift\Metabox\Field; |
| 7 | 7 | |
| 8 | 8 | interface Field { |
| 9 | - /** |
|
| 10 | - * Return nonce HTML. |
|
| 11 | - * |
|
| 12 | - * Overwrite this method in a child class to obtain custom behaviour. |
|
| 13 | - */ |
|
| 14 | - public function html_nonce(); |
|
| 9 | + /** |
|
| 10 | + * Return nonce HTML. |
|
| 11 | + * |
|
| 12 | + * Overwrite this method in a child class to obtain custom behaviour. |
|
| 13 | + */ |
|
| 14 | + public function html_nonce(); |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Verify nonce. |
|
| 18 | - * |
|
| 19 | - * Overwrite this method in a child class to obtain custom behaviour. |
|
| 20 | - * |
|
| 21 | - * @return bool Nonce verification. |
|
| 22 | - */ |
|
| 23 | - public function verify_nonce(); |
|
| 16 | + /** |
|
| 17 | + * Verify nonce. |
|
| 18 | + * |
|
| 19 | + * Overwrite this method in a child class to obtain custom behaviour. |
|
| 20 | + * |
|
| 21 | + * @return bool Nonce verification. |
|
| 22 | + */ |
|
| 23 | + public function verify_nonce(); |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Load data from DB and store the resulting array in $this->data. |
|
| 27 | - * |
|
| 28 | - * Overwrite this method in a child class to obtain custom behaviour. |
|
| 29 | - */ |
|
| 30 | - function get_data(); |
|
| 25 | + /** |
|
| 26 | + * Load data from DB and store the resulting array in $this->data. |
|
| 27 | + * |
|
| 28 | + * Overwrite this method in a child class to obtain custom behaviour. |
|
| 29 | + */ |
|
| 30 | + function get_data(); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Sanitizes data before saving to DB. Default sanitization trashes empty |
|
| 34 | - * values. |
|
| 35 | - * |
|
| 36 | - * Stores the sanitized values into $this->data so they can be later processed. |
|
| 37 | - * Overwrite this method in a child class to obtain custom behaviour. |
|
| 38 | - * |
|
| 39 | - * @param array $values Array of values to be sanitized and then stored into |
|
| 40 | - * $this->data. |
|
| 41 | - * |
|
| 42 | - * @return array | string Return sanitized data. |
|
| 43 | - */ |
|
| 44 | - public function sanitize_data( $values ); |
|
| 32 | + /** |
|
| 33 | + * Sanitizes data before saving to DB. Default sanitization trashes empty |
|
| 34 | + * values. |
|
| 35 | + * |
|
| 36 | + * Stores the sanitized values into $this->data so they can be later processed. |
|
| 37 | + * Overwrite this method in a child class to obtain custom behaviour. |
|
| 38 | + * |
|
| 39 | + * @param array $values Array of values to be sanitized and then stored into |
|
| 40 | + * $this->data. |
|
| 41 | + * |
|
| 42 | + * @return array | string Return sanitized data. |
|
| 43 | + */ |
|
| 44 | + public function sanitize_data( $values ); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Sanitize a single value. Called from $this->sanitize_data. Default |
|
| 48 | - * sanitization excludes empty values. |
|
| 49 | - * |
|
| 50 | - * Overwrite this method in a child class to obtain custom behaviour. |
|
| 51 | - * |
|
| 52 | - * @param string $value The value to sanitize. |
|
| 53 | - * |
|
| 54 | - * @return mixed Returns sanitized value, or null. |
|
| 55 | - */ |
|
| 56 | - public function sanitize_data_filter( $value ); |
|
| 46 | + /** |
|
| 47 | + * Sanitize a single value. Called from $this->sanitize_data. Default |
|
| 48 | + * sanitization excludes empty values. |
|
| 49 | + * |
|
| 50 | + * Overwrite this method in a child class to obtain custom behaviour. |
|
| 51 | + * |
|
| 52 | + * @param string $value The value to sanitize. |
|
| 53 | + * |
|
| 54 | + * @return mixed Returns sanitized value, or null. |
|
| 55 | + */ |
|
| 56 | + public function sanitize_data_filter( $value ); |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Save data to DB. |
|
| 60 | - * |
|
| 61 | - * Overwrite this method in a child class to obtain custom behaviour. |
|
| 62 | - * |
|
| 63 | - * @param array $values Array of values to be sanitized and then stored into $this->data. |
|
| 64 | - */ |
|
| 65 | - function save_data( $values ); |
|
| 58 | + /** |
|
| 59 | + * Save data to DB. |
|
| 60 | + * |
|
| 61 | + * Overwrite this method in a child class to obtain custom behaviour. |
|
| 62 | + * |
|
| 63 | + * @param array $values Array of values to be sanitized and then stored into $this->data. |
|
| 64 | + */ |
|
| 65 | + function save_data( $values ); |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Returns the HTML tag that will contain the Field. By default the we |
|
| 69 | - * return a <div> with data- attributes on cardinality and expected types. |
|
| 70 | - * |
|
| 71 | - * It is useful to provide data- attributes for the JS scripts. |
|
| 72 | - * |
|
| 73 | - * Overwrite this method in a child class to obtain custom behaviour. |
|
| 74 | - */ |
|
| 75 | - public function html_wrapper_open(); |
|
| 67 | + /** |
|
| 68 | + * Returns the HTML tag that will contain the Field. By default the we |
|
| 69 | + * return a <div> with data- attributes on cardinality and expected types. |
|
| 70 | + * |
|
| 71 | + * It is useful to provide data- attributes for the JS scripts. |
|
| 72 | + * |
|
| 73 | + * Overwrite this method in a child class to obtain custom behaviour. |
|
| 74 | + */ |
|
| 75 | + public function html_wrapper_open(); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Returns Field HTML (nonce included). |
|
| 79 | - * |
|
| 80 | - * Overwrite this method (or methods called from this method) in a child |
|
| 81 | - * class to obtain custom behaviour. |
|
| 82 | - * |
|
| 83 | - * The HTML fragment includes the following parts: |
|
| 84 | - * * html wrapper open. |
|
| 85 | - * * heading. |
|
| 86 | - * * nonce. |
|
| 87 | - * * stored values. |
|
| 88 | - * * an empty input when there are no stored values. |
|
| 89 | - * * an add button to add more values. |
|
| 90 | - * * html wrapper close. |
|
| 91 | - */ |
|
| 92 | - public function html(); |
|
| 77 | + /** |
|
| 78 | + * Returns Field HTML (nonce included). |
|
| 79 | + * |
|
| 80 | + * Overwrite this method (or methods called from this method) in a child |
|
| 81 | + * class to obtain custom behaviour. |
|
| 82 | + * |
|
| 83 | + * The HTML fragment includes the following parts: |
|
| 84 | + * * html wrapper open. |
|
| 85 | + * * heading. |
|
| 86 | + * * nonce. |
|
| 87 | + * * stored values. |
|
| 88 | + * * an empty input when there are no stored values. |
|
| 89 | + * * an add button to add more values. |
|
| 90 | + * * html wrapper close. |
|
| 91 | + */ |
|
| 92 | + public function html(); |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Return a single <input> tag for the Field. |
|
| 96 | - * |
|
| 97 | - * @param mixed $value Input value. |
|
| 98 | - * |
|
| 99 | - * @return string The html code fragment. |
|
| 100 | - */ |
|
| 101 | - public function html_input( $value ); |
|
| 94 | + /** |
|
| 95 | + * Return a single <input> tag for the Field. |
|
| 96 | + * |
|
| 97 | + * @param mixed $value Input value. |
|
| 98 | + * |
|
| 99 | + * @return string The html code fragment. |
|
| 100 | + */ |
|
| 101 | + public function html_input( $value ); |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Returns closing for the wrapper HTML tag. |
|
| 105 | - */ |
|
| 106 | - public function html_wrapper_close(); |
|
| 103 | + /** |
|
| 104 | + * Returns closing for the wrapper HTML tag. |
|
| 105 | + */ |
|
| 106 | + public function html_wrapper_close(); |
|
| 107 | 107 | |
| 108 | 108 | } |
| 109 | 109 | \ No newline at end of file |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return array | string Return sanitized data. |
| 43 | 43 | */ |
| 44 | - public function sanitize_data( $values ); |
|
| 44 | + public function sanitize_data($values); |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * Sanitize a single value. Called from $this->sanitize_data. Default |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return mixed Returns sanitized value, or null. |
| 55 | 55 | */ |
| 56 | - public function sanitize_data_filter( $value ); |
|
| 56 | + public function sanitize_data_filter($value); |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Save data to DB. |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @param array $values Array of values to be sanitized and then stored into $this->data. |
| 64 | 64 | */ |
| 65 | - function save_data( $values ); |
|
| 65 | + function save_data($values); |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * Returns the HTML tag that will contain the Field. By default the we |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @return string The html code fragment. |
| 100 | 100 | */ |
| 101 | - public function html_input( $value ); |
|
| 101 | + public function html_input($value); |
|
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * Returns closing for the wrapper HTML tag. |
@@ -19,12 +19,12 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class Wordlift_Metabox_Field_Select extends Wl_Metabox_Field { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @inheritdoc |
|
| 24 | - */ |
|
| 25 | - public function html_input( $text ) { |
|
| 26 | - @ob_start(); |
|
| 27 | - ?> |
|
| 22 | + /** |
|
| 23 | + * @inheritdoc |
|
| 24 | + */ |
|
| 25 | + public function html_input( $text ) { |
|
| 26 | + @ob_start(); |
|
| 27 | + ?> |
|
| 28 | 28 | <div class="wl-input-wrapper"> |
| 29 | 29 | |
| 30 | 30 | <select name="wl_metaboxes[<?php echo $this->meta_name ?>]" id="<?php echo esc_attr( $this->meta_name ); ?>" style="width:88%;"> |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | </div> |
| 42 | 42 | <?php |
| 43 | 43 | |
| 44 | - $html = ob_get_clean(); |
|
| 45 | - return $html; |
|
| 46 | - } |
|
| 44 | + $html = ob_get_clean(); |
|
| 45 | + return $html; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | } |
@@ -21,15 +21,15 @@ |
||
| 21 | 21 | /** |
| 22 | 22 | * @inheritdoc |
| 23 | 23 | */ |
| 24 | - public function html_input( $text ) { |
|
| 24 | + public function html_input($text) { |
|
| 25 | 25 | @ob_start(); |
| 26 | 26 | ?> |
| 27 | 27 | <div class="wl-input-wrapper"> |
| 28 | 28 | |
| 29 | - <select name="wl_metaboxes[<?php echo $this->meta_name ?>]" id="<?php echo esc_attr( $this->meta_name ); ?>" style="width:88%;"> |
|
| 30 | - <?php foreach ( $this->raw_custom_field['options'] as $option => $label ): ?> |
|
| 29 | + <select name="wl_metaboxes[<?php echo $this->meta_name ?>]" id="<?php echo esc_attr($this->meta_name); ?>" style="width:88%;"> |
|
| 30 | + <?php foreach ($this->raw_custom_field['options'] as $option => $label): ?> |
|
| 31 | 31 | |
| 32 | - <option value="<?php echo esc_attr( $option ); ?>" <?php selected( $text, $option ); ?>> |
|
| 32 | + <option value="<?php echo esc_attr($option); ?>" <?php selected($text, $option); ?>> |
|
| 33 | 33 | <?php echo $label; ?> |
| 34 | 34 | </option> |
| 35 | 35 | |