Skip to content

Instantly share code, notes, and snippets.

@diegoliv
Created May 21, 2014 22:24
Show Gist options
  • Save diegoliv/274f09e3f3d9094b204c to your computer and use it in GitHub Desktop.
Save diegoliv/274f09e3f3d9094b204c to your computer and use it in GitHub Desktop.
Plugin for CPT's and CT's - needs to resolve issues with CT archive for CT that are binded to two or more CPT's
<?php
/**
* Plugin class. This class should ideally be used to work with the
* public-facing side of the WordPress site.
*
* If you're interested in introducing administrative or dashboard
* functionality, then refer to `class-plugin-name-admin.php`
*
* @package Tesla_CPTS
*/
class Tesla_CPTS {
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.0.0
*
* @var string
*/
const VERSION = '1.0.0';
/**
*
* Unique identifier for your plugin.
*
*
* The variable name is used as the text domain when internationalizing strings
* of text. Its value should match the Text Domain file header in the main
* plugin file.
*
* @since 1.0.0
*
* @var string
*/
protected $plugin_slug = 'tesla-cpts';
/**
* Instance of this class.
*
* @since 1.0.0
*
* @var object
*/
protected static $instance = null;
/**
* Initialize the plugin by setting localization and loading public scripts
* and styles.
*
* @since 1.0.0
*/
private function __construct() {
// Load plugin text domain
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
// register CPT's and taxonomy
add_action( 'init', array( $this, 'register_cpts' ), 0 );
add_action( 'init', array( $this, 'register_taxonomies' ), 0 );
add_action( 'init', array( $this, 'register_product_taxonomy' ), 0 );
// posts 2 posts plugin
add_action( 'p2p_init', array( $this, 'cursos_to_disciplinas' ) );
add_action( 'p2p_init', array( $this, 'cursos_to_empresas' ) );
add_action( 'p2p_init', array( $this, 'professores_to_disciplinas' ) );
add_action( 'p2p_init', array( $this, 'videos_to_cursos' ) );
add_action( 'p2p_init', array( $this, 'videos_to_products' ) );
// change featured image labels
add_action( 'add_meta_boxes', array( $this, 'featured_image_metabox_title' ), 10, 2 );
add_filter( 'admin_post_thumbnail_html', array( $this, 'admin_post_thumbnail_html' ) );
add_filter( 'pre_get_posts', array( $this, 'filter_tax_archive' ) );
}
/**
* Return the plugin slug.
*
* @since 1.0.0
*
* @return Plugin slug variable.
*/
public function get_plugin_slug() {
return $this->plugin_slug;
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
$domain = $this->plugin_slug;
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, FALSE, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' );
}
/**
* Register the custom post types with filters to change the default behavior
*
* @since 1.0.0
*/
public function register_cpts() {
// CURSOS ==================================================================================//
$labels = apply_filters( 'tesla_cpt_cursos_labels', array(
'name' => _x( 'Cursos', 'Post Type General Name', $this->plugin_slug ),
'singular_name' => _x( 'Curso', 'Post Type Singular Name', $this->plugin_slug ),
'menu_name' => __( 'Cursos', $this->plugin_slug ),
'parent_item_colon' => __( 'Curso pai:', $this->plugin_slug ),
'all_items' => __( 'Todos os Cursos', $this->plugin_slug ),
'view_item' => __( 'Ver Cursos', $this->plugin_slug ),
'add_new_item' => __( 'Adicionar Novo Curso', $this->plugin_slug ),
'add_new' => __( 'Novo Curso', $this->plugin_slug ),
'edit_item' => __( 'Editar Curso', $this->plugin_slug ),
'update_item' => __( 'Atualizar Curso', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Cursos', $this->plugin_slug ),
'not_found' => __( 'Nenhum curso encontrado', $this->plugin_slug ),
'not_found_in_trash' => __( 'Nenhum curso encontrado na lixeira', $this->plugin_slug ),
) );
$rewrite = array(
'slug' => apply_filters( 'tesla_cpt_cursos_slug' , _x( 'cursos', 'Post Type Slug', $this->plugin_slug ) ),
'with_front' => true,
'pages' => true,
'feeds' => false,
);
$args = apply_filters( 'tesla_cpt_cursos_args', array(
'label' => _x( 'Cursos', 'Post Type Label', $this->plugin_slug ),
'description' => __( 'Cursos oferecidos pela empresa.', $this->plugin_slug ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
'taxonomies' => array( 'tesla-formacao' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 20,
'menu_icon' => 'dashicons-welcome-learn-more', // dashicons - @since WordPress 3.8
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
) );
register_post_type( 'tesla-cursos', $args );
// PROFESSORES ================================================================================//
$labels = apply_filters( 'tesla_cpt_professores_labels', array(
'name' => _x( 'Professores', 'Post Type General Name', $this->plugin_slug ),
'singular_name' => _x( 'Professor', 'Post Type Singular Name', $this->plugin_slug ),
'menu_name' => __( 'Professores', $this->plugin_slug ),
'parent_item_colon' => __( 'Professor pai:', $this->plugin_slug ),
'all_items' => __( 'Professores', $this->plugin_slug ),
'view_item' => __( 'Ver Professores', $this->plugin_slug ),
'add_new_item' => __( 'Adicionar Novo Professor', $this->plugin_slug ),
'add_new' => __( 'Novo Professor', $this->plugin_slug ),
'edit_item' => __( 'Editar Professor', $this->plugin_slug ),
'update_item' => __( 'Atualizar Professor', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Professores', $this->plugin_slug ),
'not_found' => __( 'Nenhum professor encontrado', $this->plugin_slug ),
'not_found_in_trash' => __( 'Nenhum professor encontrado na lixeira', $this->plugin_slug ),
) );
$rewrite = array(
'slug' => apply_filters( 'tesla_cpt_professores_slug' , _x( 'professores/professor', 'Post Type Slug', $this->plugin_slug ) ),
'with_front' => true,
'pages' => true,
'feeds' => false,
);
$args = apply_filters( 'tesla_cpt_professores_args', array(
'label' => _x( 'Professores', 'Post Type Label', $this->plugin_slug ),
'description' => __( 'Professores do Tesla Concursos.', $this->plugin_slug ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=tesla-cursos',
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => 20,
'menu_icon' => 'dashicons-businessman', // dashicons - @since WordPress 3.8
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
) );
register_post_type( 'tesla-professores', $args );
// DISCIPLINAS ================================================================================//
$labels = apply_filters( 'tesla_cpt_disciplinas_labels', array(
'name' => _x( 'Disciplinas', 'Post Type General Name', $this->plugin_slug ),
'singular_name' => _x( 'Disciplina', 'Post Type Singular Name', $this->plugin_slug ),
'menu_name' => __( 'Disciplinas', $this->plugin_slug ),
'parent_item_colon' => __( 'Disciplina pai:', $this->plugin_slug ),
'all_items' => __( 'Disciplinas', $this->plugin_slug ),
'view_item' => __( 'Ver Disciplinas', $this->plugin_slug ),
'add_new_item' => __( 'Adicionar Nova Disciplina', $this->plugin_slug ),
'add_new' => __( 'Nova Disciplina', $this->plugin_slug ),
'edit_item' => __( 'Editar Disciplina', $this->plugin_slug ),
'update_item' => __( 'Atualizar Disciplina', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Disciplinas', $this->plugin_slug ),
'not_found' => __( 'Nenhuma disciplina encontrada', $this->plugin_slug ),
'not_found_in_trash' => __( 'Nenhuma disciplina encontrada na lixeira', $this->plugin_slug ),
) );
$rewrite = array(
'slug' => apply_filters( 'tesla_cpt_disciplinas_slug' , _x( 'disciplinas/disciplina', 'Post Type Slug', $this->plugin_slug ) ),
'with_front' => true,
'pages' => true,
'feeds' => false,
);
$args = apply_filters( 'tesla_cpt_disciplinas_args', array(
'label' => _x( 'Disciplinas', 'Post Type Label', $this->plugin_slug ),
'description' => __( 'Disciplinas dos Cursos ministrados no Tesla Concursos.', $this->plugin_slug ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'revisions' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=tesla-cursos',
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => 20,
'menu_icon' => 'dashicons-book-alt', // dashicons - @since WordPress 3.8
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
) );
register_post_type( 'tesla-disciplinas', $args );
// EMPRESAS ================================================================================//
$labels = apply_filters( 'tesla_cpt_empresas_labels', array(
'name' => _x( 'Empresas', 'Post Type General Name', $this->plugin_slug ),
'singular_name' => _x( 'Empresa', 'Post Type Singular Name', $this->plugin_slug ),
'menu_name' => __( 'Empresas', $this->plugin_slug ),
'parent_item_colon' => __( 'Empresa pai:', $this->plugin_slug ),
'all_items' => __( 'Empresas', $this->plugin_slug ),
'view_item' => __( 'Ver Empresas', $this->plugin_slug ),
'add_new_item' => __( 'Adicionar Nova Empresa', $this->plugin_slug ),
'add_new' => __( 'Nova Empresa', $this->plugin_slug ),
'edit_item' => __( 'Editar Empresa', $this->plugin_slug ),
'update_item' => __( 'Atualizar Empresa', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Empresas', $this->plugin_slug ),
'not_found' => __( 'Nenhuma empresa encontrada', $this->plugin_slug ),
'not_found_in_trash' => __( 'Nenhuma empresa encontrada na lixeira', $this->plugin_slug ),
) );
$rewrite = array(
'slug' => apply_filters( 'tesla_cpt_empresas_slug' , _x( 'empresas/empresa', 'Post Type Slug', $this->plugin_slug ) ),
'with_front' => true,
'pages' => true,
'feeds' => false,
);
$args = apply_filters( 'tesla_cpt_empresas_args', array(
'label' => _x( 'Empresas', 'Post Type Label', $this->plugin_slug ),
'description' => __( 'Empresas relacionadas aos Cursos ministrados no Tesla Concursos.', $this->plugin_slug ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=tesla-cursos',
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => 20,
'menu_icon' => 'dashicons-groups', // dashicons - @since WordPress 3.8
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
) );
register_post_type( 'tesla-empresas', $args );
// VÍDEOS ================================================================================//
$labels = apply_filters( 'tesla_cpt_videos_labels', array(
'name' => _x( 'Vídeos', 'Post Type General Name', $this->plugin_slug ),
'singular_name' => _x( 'Vídeo', 'Post Type Singular Name', $this->plugin_slug ),
'menu_name' => __( 'Vídeos', $this->plugin_slug ),
'parent_item_colon' => __( 'Vídeo pai:', $this->plugin_slug ),
'all_items' => __( 'Vídeos', $this->plugin_slug ),
'view_item' => __( 'Ver Vídeos', $this->plugin_slug ),
'add_new_item' => __( 'Adicionar Novo Vídeo', $this->plugin_slug ),
'add_new' => __( 'Novo Vídeo', $this->plugin_slug ),
'edit_item' => __( 'Editar Vídeo', $this->plugin_slug ),
'update_item' => __( 'Atualizar Vídeo', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Vídeo', $this->plugin_slug ),
'not_found' => __( 'Nenhum vídeo encontrado', $this->plugin_slug ),
'not_found_in_trash' => __( 'Nenhum vídeo encontrado na lixeira', $this->plugin_slug ),
) );
$rewrite = array(
'slug' => apply_filters( 'tesla_cpt_videos_slug' , _x( 'videos', 'Post Type Slug', $this->plugin_slug ) ),
'with_front' => true,
'pages' => true,
'feeds' => false,
);
$args = apply_filters( 'tesla_cpt_videos_args', array(
'label' => _x( 'Vídeos', 'Post Type Label', $this->plugin_slug ),
'description' => __( 'Vídeos dos Canais do Tesla Concursos no Youtube.', $this->plugin_slug ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'revisions' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => 20,
'menu_icon' => 'dashicons-video-alt3', // dashicons - @since WordPress 3.8
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
) );
register_post_type( 'tesla-videos', $args );
}
/**
* Register the custom taxonomy with filters to change the default behavior
*
* @since 1.0.0
*
*/
public function register_taxonomies() {
$labels = apply_filters( 'tesla_tax_formacao_labels' ,array(
'name' => _x( 'Formações Acadêmicas', 'Taxonomy General Name', $this->plugin_slug ),
'singular_name' => _x( 'Formação Acadêmica', 'Taxonomy Singular Name', $this->plugin_slug ),
'menu_name' => __( 'Formações', $this->plugin_slug ),
'all_items' => __( 'Todos as Formações', $this->plugin_slug ),
'parent_item' => __( 'Formação Pai', $this->plugin_slug ),
'parent_item_colon' => __( 'Formação Pai:', $this->plugin_slug ),
'new_item_name' => __( 'Novo nome de Formação', $this->plugin_slug ),
'add_new_item' => __( 'Adicionar nova Formação', $this->plugin_slug ),
'edit_item' => __( 'Editar Formação', $this->plugin_slug ),
'update_item' => __( 'Atualizar Formação', $this->plugin_slug ),
'separate_items_with_commas' => __( 'Separe formações acadêmicas com vírgulas', $this->plugin_slug ),
'search_items' => __( 'Pesquisar formações', $this->plugin_slug ),
'add_or_remove_items' => __( 'Adiciona ou remova formações', $this->plugin_slug ),
'choose_from_most_used' => __( 'Escolha entre as formações mais usadas', $this->plugin_slug ),
) );
$rewrite = array(
'slug' => apply_filters( 'tesla_tax_formacao_slug', _x( 'formacao-academica', 'Taxonomy Slug', $this->plugin_slug ) ),
'with_front' => true,
'hierarchical' => false,
);
$args = apply_filters( 'tesla_tax_formacao_args', array(
'labels' => $labels,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => false,
'rewrite' => $rewrite,
) );
register_taxonomy( 'tesla-formacao', array( 'tesla-cursos', 'product' ), $args );
$labels = apply_filters( 'tesla_tax_canais_labels' ,array(
'name' => _x( 'Canais', 'Taxonomy General Name', $this->plugin_slug ),
'singular_name' => _x( 'Canal de Vídeo', 'Taxonomy Singular Name', $this->plugin_slug ),
'menu_name' => __( 'Canais', $this->plugin_slug ),
'all_items' => __( 'Todos os Canais', $this->plugin_slug ),
'parent_item' => __( 'Canal Pai', $this->plugin_slug ),
'parent_item_colon' => __( 'Canal Pai:', $this->plugin_slug ),
'new_item_name' => __( 'Novo nome de Canal', $this->plugin_slug ),
'add_new_item' => __( 'Adicionar novo Canal', $this->plugin_slug ),
'edit_item' => __( 'Editar Canal', $this->plugin_slug ),
'update_item' => __( 'Atualizar Canal', $this->plugin_slug ),
'separate_items_with_commas' => __( 'Separe canais com vírgulas', $this->plugin_slug ),
'search_items' => __( 'Pesquisar canais', $this->plugin_slug ),
'add_or_remove_items' => __( 'Adicione ou remova canais', $this->plugin_slug ),
'choose_from_most_used' => __( 'Escolha entre os canais mais usados', $this->plugin_slug ),
) );
$rewrite = array(
'slug' => apply_filters( 'tesla_tax_canais_slug', _x( 'canais', 'Taxonomy Slug', $this->plugin_slug ) ),
'with_front' => true,
'hierarchical' => false,
);
$args = apply_filters( 'tesla_tax_canais_args', array(
'labels' => $labels,
'hierarchical' => true,
'public' => false,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'rewrite' => $rewrite,
) );
register_taxonomy( 'tesla-canais', 'tesla-videos', $args );
}
public function register_product_taxonomy(){
register_taxonomy_for_object_type( 'tesla-formacao', 'product' );
}
/**
* POSTS 2 POSTS PLUGIN
*
* functions to create connections between CPT's
*/
// Cursos <-> Disciplinas
public function cursos_to_disciplinas() {
p2p_register_connection_type( array(
'name' => 'cursos_to_disciplinas',
'from' => 'tesla-cursos',
'to' => 'tesla-disciplinas',
'sortable' => 'any',
'admin_column' => 'any',
'admin_dropdown' => 'any',
'admin_box' => array(
'show' => 'any',
'context' => 'advanced'
),
'title' => array(
'from' => __( 'Disciplinas deste Curso', $this->plugin_slug ),
'to' => __( 'Cursos com esta Disciplina', $this->plugin_slug )
),
'from_labels' => array(
'singular_name' => __( 'Curso', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Cursos', $this->plugin_slug ),
'not_found' => __( 'Nenhum Curso encontrado.', $this->plugin_slug ),
'create' => __( 'Criar conexões', $this->plugin_slug ),
),
'to_labels' => array(
'singular_name' => __( 'Disciplina', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Disciplinas', $this->plugin_slug ),
'not_found' => __( 'Nenhuma Disciplina Encontrada.', $this->plugin_slug ),
'create' => __( 'Criar conexões', $this->plugin_slug ),
),
) );
}
// Cursos <-> Empresas
public function cursos_to_empresas() {
p2p_register_connection_type( array(
'name' => 'cursos_to_empresas',
'from' => 'tesla-cursos',
'to' => 'tesla-empresas',
'sortable' => 'to',
'admin_column' => 'any',
'admin_dropdown' => 'any',
'cardinality' => 'many-to-many',
'admin_box' => array(
'show' => 'any',
'context' => 'advanced'
),
'title' => array(
'from' => __( 'Empresa referente ao Curso', $this->plugin_slug ),
'to' => __( 'Cursos para concursos realizados por esta Empresa', $this->plugin_slug )
),
'from_labels' => array(
'singular_name' => __( 'Curso', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Cursos', $this->plugin_slug ),
'not_found' => __( 'Nenhum Curso encontrado.', $this->plugin_slug ),
'create' => __( 'Criar conexões', $this->plugin_slug ),
),
'to_labels' => array(
'singular_name' => __( 'Empresa', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Empresas', $this->plugin_slug ),
'not_found' => __( 'Nenhuma Empresa Encontrada.', $this->plugin_slug ),
'create' => __( 'Criar conexões', $this->plugin_slug ),
),
) );
}
// Professores <-> Disciplinas
public function professores_to_disciplinas() {
p2p_register_connection_type( array(
'name' => 'professores_to_disciplinas',
'from' => 'tesla-professores',
'to' => 'tesla-disciplinas',
'admin_column' => 'any',
'cardinality' => 'one-to-many',
'admin_box' => array(
'show' => 'any',
'context' => 'advanced'
),
'title' => array(
'from' => __( 'Disciplina Ministrada', $this->plugin_slug ),
'to' => __( 'Professor da Disciplina', $this->plugin_slug )
),
'from_labels' => array(
'singular_name' => __( 'Professor', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Professores', $this->plugin_slug ),
'not_found' => __( 'Nenhum Professor encontrado.', $this->plugin_slug ),
'create' => __( 'Criar conexões', $this->plugin_slug ),
),
'to_labels' => array(
'singular_name' => __( 'Disciplina', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Disciplinas', $this->plugin_slug ),
'not_found' => __( 'Nenhuma Disciplina Encontrada.', $this->plugin_slug ),
'create' => __( 'Criar conexões', $this->plugin_slug ),
),
) );
}
// Vídeos <-> Cursos
public function videos_to_cursos() {
p2p_register_connection_type( array(
'name' => 'videos_to_cursos',
'from' => 'tesla-videos',
'to' => 'tesla-cursos',
'cardinality' => 'one-to-many',
'admin_box' => array(
'show' => 'to',
'context' => 'advanced'
),
'title' => array(
'to' => __( 'Vídeo para este Curso', $this->plugin_slug )
),
'to_labels' => array(
'singular_name' => __( 'Vídeo', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Vídeos', $this->plugin_slug ),
'not_found' => __( 'Nenhum Vídeo encontrado.', $this->plugin_slug ),
'create' => __( 'Selecionar Vídeo', $this->plugin_slug ),
),
) );
}
// Vídeos <-> Apostilas
public function videos_to_products() {
p2p_register_connection_type( array(
'name' => 'videos_to_products',
'from' => 'tesla-videos',
'to' => 'product',
'cardinality' => 'one-to-many',
'admin_box' => array(
'show' => 'to',
'context' => 'advanced'
),
'title' => array(
'to' => __( 'Vídeo para esta Apostila', $this->plugin_slug )
),
'to_labels' => array(
'singular_name' => __( 'Vídeo', $this->plugin_slug ),
'search_items' => __( 'Pesquisar Vídeos', $this->plugin_slug ),
'not_found' => __( 'Nenhum Vídeo encontrado.', $this->plugin_slug ),
'create' => __( 'Selecionar Vídeo', $this->plugin_slug ),
),
) );
}
// Featured image metaboxes
public function featured_image_metabox_title( $post_type, $post ) {
switch ( $post_type ) {
case 'tesla-cursos':
remove_meta_box( 'postimagediv', 'tesla-cursos', 'side' );
add_meta_box( 'postimagediv', __( 'Imagem do Curso', $this->plugin_slug ), 'post_thumbnail_meta_box', 'tesla-cursos', 'side', 'low' );
break;
case 'tesla-professores':
remove_meta_box( 'postimagediv', 'tesla-professores', 'side' );
add_meta_box( 'postimagediv', __( 'Foto do Professor', $this->plugin_slug ), 'post_thumbnail_meta_box', 'tesla-professores', 'side', 'low' );
break;
case 'tesla-empresas':
remove_meta_box( 'postimagediv', 'tesla-empresas', 'side' );
add_meta_box( 'postimagediv', __( 'Logotipo da Empresa', $this->plugin_slug ), 'post_thumbnail_meta_box', 'tesla-empresas', 'side', 'low' );
break;
}
}
public function admin_post_thumbnail_html( $content ) {
$content = str_replace( __( 'Set featured image' ), __( 'Inserir Imagem', $this->plugin_slug ), $content );
$content = str_replace( __( 'Remove featured image' ), __( 'Remover Imagem', $this->plugin_slug ), $content );
return $content;
}
function filter_tax_archive( $query ) {
if ( $query->is_main_query() && $query->is_tax( 'tesla-formacao' ) ) {
$query->set( 'post_type', array( 'tesla-cursos' ) );
return $query;
}
}
}
<?php
/**
* Plugin Name: Tesla Custom Post Types
* Plugin URI: http://www.teslaconcursos.com.br
* Description: Habilita o gerenciamento de Cursos, Disciplinas, Empresas, Professores e Formações Acadêmicas para o site do Tesla Concursos. IMPORTANTE: Requer que os plugins "Advanced Custom Fields" e "Posts2Posts" estejam ativos!
* Version: 1.0.0
* Author: Favolla Comunicação
* Author URI: http://favolla.com.br
* Text Domain: tesla-cpts
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/*----------------------------------------------------------------------------*
* Public-Facing Functionality
*----------------------------------------------------------------------------*/
require_once( plugin_dir_path( __FILE__ ) . 'class-tesla-cpts.php' );
function tesla_display_notices(){
$plugins = array(
'advanced-custom-fields/acf.php' => __( 'O plugin <strong>Advanced Custom Fields</strong> não está ativado!', 'tesla-cpts' ),
'posts-to-posts/posts-to-posts.php' => __( 'O plugin <strong>Posts 2 Posts</strong> não está ativado!', 'tesla-cpts' )
);
foreach( $plugins as $plugin => $notice ){
if( !is_plugin_active( $plugin ) ){
echo '<div class="error"><p>' . $notice . '</p></div>';
return;
}
}
}
// Display the admin notification
add_action( 'admin_notices', 'tesla_display_notices' );
add_action( 'plugins_loaded', array( 'Tesla_CPTS', 'get_instance' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment