You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

148 lines
3.2 KiB

<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://horizontes.info
* @since 1.0.0
*
* @package Reuna_Glossario
* @subpackage Reuna_Glossario/admin
*/
/**
* The admin-specific functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package Reuna_Glossario
* @subpackage Reuna_Glossario/admin
* @author Horizontes Coop. <contato@horizontes.info>
*/
class Reuna_Glossario_Admin {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles()
{
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/reuna-glossario-admin.css', [], $this->version, 'all' );
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts()
{
}
/**
* Register the custom post type to contain the Glossario.
*
* @since 1.0.0
*/
public function register_glossario_post_type()
{
register_extended_post_type('glossario', [
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_rest' => false,
'labels' => [
'name' => 'Glossário',
'singular_name' => 'Termo',
'new_item' => 'Novo termo',
'add_new' => 'Novo termo',
'add_new_item' => 'Adicionar novo termo',
'view_item' => 'Ver termo',
'search_items' => 'Pesquisar termos',
'not_found' => 'Nenhum termo encontrado',
'not_found_in_trash' => 'Nenhum termo encontrado na lixeira',
'all_items' => 'Todos os termos',
'menu_name' => 'Glossário',
],
'supports' => [
'title',
'editor',
'author',
'custom_fields',
'revisions',
],
'menu_icon' => 'dashicons-book',
]);
}
/**
* Display the shortcode associated to a Glossario post below its title
* in the edit screen.
*
* @since 1.0.0
*/
public function display_term_shortcode_after_title($post)
{
if (get_post_type($post) !== 'glossario') {
return;
}
require (plugin_dir_path(__FILE__) . 'partials/shortcode-metabox.php');
}
/**
* Add the post_title_like argument to WP_Query
*
* @since 1.0.0
*/
public function wp_query_by_post_title_like($where, $wp_query)
{
global $wpdb;
$post_title_like = $wp_query->get('post_title_like');
if ($post_title_like) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( $wpdb->esc_like( $post_title_like ) ) . '\'';
}
return $where;
}
}