Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example: add support for new schema.org type in Schema Premium plugin https://schema.press/introducing-schema-premium/
<?php //* do not include php tag
/**
* @package Schema Premium - Class Schema New Type
* @category Core
* @author Hesham Zebida
* @version 1.0.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists('Schema_WP_New_Type') ) :
/**
* Schema Type
*
* @since 1.0.0
*/
class Schema_WP_New_Type {
/** @var string Current Type */
protected $type = 'Type';
/**
* Constructor
*
* @since 1.0.0
*/
public function __construct () {
$this->init();
}
/**
* Init
*
* @since 1.0.0
*/
public function init() {
add_filter( 'schema_premium_get_default_schemas', array( $this, 'schema_type' ) );
add_filter( 'schema_premium_types', array( $this, 'schema_type_extend' ) );
}
/**
* Get schema type label
*
* @since 1.0.0
* @return array
*/
public function label() {
return __('Type');
}
/**
* Get schema type comment
*
* @since 1.0.0
* @return array
*/
public function comment() {
return __('An article, such as a news article or piece of investigative report. Newspapers and magazines have articles of many different types and this is intended to cover them all. (See also blog post).');
}
/**
* Extend schema types
*
* @since 1.0.0
* @return array
*/
public function schema_type_extend( $schema_types ) {
$schema_types[$this->type] = array
(
'label' => $this->label(),
'value' => $this->type
);
return $schema_types;
}
/**
* Get schema type
*
* @since 1.0.0
* @return array
*/
public function schema_type( $schema ) {
$schema[$this->type] = array (
'id' => $this->type,
'lable' => $this->label(),
'comment' => $this->comment(),
'properties' => $this->properties(),
'subtypes' => $this->subtypes(),
);
return apply_filters( 'schema_Type', $schema );
}
/**
* Get sub types
*
* @since 1.0.0
* @return array
*/
public function subtypes() {}
/**
* Get properties
*
* @since 1.0.0
* @return array
*/
public function properties() {}
/**
* Schema output
*
* @since 1.0.0
* @return array
*/
public function schema_output( $post_id = null ) {}
}
new Schema_WP_New_Type();
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment