book-template/book-template.php

103 lines
3.2 KiB
PHP
Raw Normal View History

2017-12-18 13:05:40 +01:00
<?php
/*
Plugin Name: Book template
Description: Plugin in italiano che aggiunge uno shortcode per la creazione di un box con i dati editoriali di un libro o di un fumetto.
Version: 0.5.2
2017-12-18 13:05:40 +01:00
Author: Gianluigi Filippelli
Author URI: http://dropseaofulaula.blogspot.it/
2017-12-18 13:40:27 +01:00
Plugin URI: https://github.com/ulaulaman/book-template
2018-02-05 12:07:12 +01:00
GitHub Plugin URI: https://github.com/ulaulaman/book-template
2018-01-25 12:42:10 +01:00
License: GPLv2 or later
2017-12-18 13:05:40 +01:00
*/
/* ------------------------------------------------------ */
# Aggiunta metabox
2018-01-25 12:42:10 +01:00
add_action( 'load-post.php', 'bookdata_meta_box_setup' );
add_action( 'load-post-new.php', 'bookdata_meta_box_setup' );
/* Meta box setup function. */
function bookdata_meta_box_setup() {
/* Add meta boxes on the 'add_meta_boxes' hook. */
add_action( 'add_meta_boxes', 'bookdata_meta_box' );
}
2017-12-18 13:05:40 +01:00
function bookdata_meta_box() {
2018-01-25 12:42:10 +01:00
add_meta_box(
'bookdata-post-class', // Unique ID
esc_html__( 'Inserimento dati editoriali', 'example' ), // Title
'bookdata_class_meta_box', // Callback function
'post', // Admin page (or post type)
'side', // Context
'high' // Priority
);
2017-12-18 13:05:40 +01:00
}
2018-01-25 12:42:10 +01:00
/* Display the post meta box. */
function bookdata_class_meta_box( $post ) { ?>
<?php wp_nonce_field( basename( __FILE__ ), 'bookdata_class_nonce' ); ?>
<p>
2018-01-25 18:30:56 +01:00
<label for="bookdata-post-class">Esempio generico [bookdata title="Titolo" author="Autori" publisher="Editore" date="Data" pages ="numero pagine" type="brossurato,cartonato,digitale/on-line" price="prezzo valuta/gratuito"]<br/>In caso di fumetto o libro illustrato, inserire il colore [bookdata ... col="colore,b/n"]<br/>Possono essere inseriti opzionalmente ISBN [bookdata ... isbn="codice"] o ISSN [bookdata ... issn="codice"], il traduttore [bookdata ... translator="Traduttore"] ed eventuali note aggiuntive [dati_editoriali ... notes="Note aggiuntive"]<br/>I dati possono essere inseriti anche in maniera disordinata: ci penserà il plugin a riordinarli.</label></p>
2018-01-25 12:42:10 +01:00
<?php }
2017-12-18 13:05:40 +01:00
# Creazione shortcode dati editoriali
add_shortcode('bookdata', 'bookdata');
function bookdata ($atts, $content = null) {
extract(
shortcode_atts(
array(
'title' => null,
'author' => null,
'translator' => null,
'publisher' => null,
'date' => null,
'pages' => null,
'type' => null,
'col' => null,
'price' => null,
'isbn' => null,
'issn' => null,
'notes' => null,
),
$atts
)
);
$book = '<p><strong>Abbiamo parlato di</strong>:<br/><em>'.$title.'</em><br/>'.$author;
if ( $translator <> null )
{$book = $book.'<br/>Traduzione di '.$translator;}
else
{$book = $book;}
if ( $col <> null )
2018-01-25 18:30:56 +01:00
{$book = $book.'<br/>'.$publisher.', '.$date.'<br/>'.$pages.' pagine, '.$type.', '.$col.' - '.$price;}
2017-12-18 13:05:40 +01:00
else
{$book = $book.'<br/>'.$publisher.', '.$date.'<br/>'.$pages.' pagine, '.$type.' - '.$price;}
if ( $isbn <> null )
{$book = $book.'<br/>ISBN: '.$isbn;}
else
{
if ( $issn <> null )
{$book = $book.'<br/>ISSN: '.$issn;}
else
{$book = $book;}
}
if ( $notes <> null )
{$book = $book.'<br/>'.$notes;}
else
{$book = $book;}
$text = $book;
return $text;
}
/* ------------------------------------------------------ */
?>