array( 'post' ),
'image_size' => 'large',
'show_arrows' => true,
);
return wp_parse_args( get_option( self::OPTION_NAME, array() ), $defaults );
}
/**
* Registra una voce propria nel menu principale di WordPress, invece
* di nasconderla dentro "Impostazioni" dove un utente alle prime
* armi difficilmente la troverebbe da solo.
*/
public function register_menu() {
add_menu_page(
__( 'Multipix', 'multipix' ),
__( 'Multipix', 'multipix' ),
'manage_options',
self::PAGE_SLUG,
array( $this, 'render_page' ),
'dashicons-format-gallery'
);
}
/**
* Aggiunge il link "Impostazioni" nella lista dei plugin.
*
* @param string[] $links Link esistenti.
* @return string[]
*/
public function add_settings_link( $links ) {
$url = admin_url( 'admin.php?page=' . self::PAGE_SLUG );
$link = '' . esc_html__( 'Settings', 'multipix' ) . '';
array_unshift( $links, $link );
return $links;
}
/**
* Registra l'opzione tramite la Settings API di WordPress.
*/
public function register_settings() {
register_setting(
self::OPTION_NAME,
self::OPTION_NAME,
array( $this, 'sanitize' )
);
}
/**
* Valida e ripulisce i dati inviati dal form prima di salvarli.
*
* @param array $input Dati grezzi dal form.
* @return array
*/
public function sanitize( $input ) {
$output = array();
$allowed_post_types = array_keys( $this->get_selectable_post_types() );
$submitted_post_types = isset( $input['post_types'] ) && is_array( $input['post_types'] )
? array_map( 'sanitize_key', $input['post_types'] )
: array();
$output['post_types'] = array_values( array_intersect( $submitted_post_types, $allowed_post_types ) );
if ( empty( $output['post_types'] ) ) {
$output['post_types'] = array( 'post' );
}
$allowed_sizes = array_keys( $this->get_image_sizes() );
$output['image_size'] = ( isset( $input['image_size'] ) && in_array( $input['image_size'], $allowed_sizes, true ) )
? $input['image_size']
: 'large';
$output['show_arrows'] = ! empty( $input['show_arrows'] );
return $output;
}
/**
* Punto di estensione 'multipix_supported_post_types': applica il
* tipo di contenuto scelto nelle impostazioni.
*
* @param string[] $post_types Valore di default.
* @return string[]
*/
public function filter_post_types( $post_types ) {
$settings = self::get_settings();
return ! empty( $settings['post_types'] ) ? $settings['post_types'] : $post_types;
}
/**
* Punto di estensione 'multipix_main_image_size'.
*
* @param string $size Valore di default.
* @return string
*/
public function filter_image_size( $size ) {
$settings = self::get_settings();
return ! empty( $settings['image_size'] ) ? $settings['image_size'] : $size;
}
/**
* Punto di estensione 'multipix_show_navigation_arrows'.
*
* @param bool $show Valore di default.
* @return bool
*/
public function filter_show_arrows( $show ) {
$settings = self::get_settings();
return ! empty( $settings['show_arrows'] );
}
/**
* Tipi di contenuto pubblici selezionabili (esclusi gli allegati).
*
* @return WP_Post_Type[]
*/
protected function get_selectable_post_types() {
$post_types = get_post_types( array( 'public' => true ), 'objects' );
unset( $post_types['attachment'] );
return $post_types;
}
/**
* Dimensioni immagine disponibili per la slide principale.
*
* @return array
*/
protected function get_image_sizes() {
return array(
'medium' => __( 'Medium', 'multipix' ),
'medium_large' => __( 'Medium large', 'multipix' ),
'large' => __( 'Large (recommended)', 'multipix' ),
'full' => __( 'Original size', 'multipix' ),
);
}
/**
* Stampa la pagina di impostazioni.
*/
public function render_page() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$settings = self::get_settings();
?>
tag. */
esc_html__( 'If your theme uses a builder (BeTheme, Divi, Elementor...) that doesn\'t display the featured image in the standard way, insert the shortcode %s at the point in the template where you want the slider to appear.', 'multipix' ),
'[multipix_gallery]'
);
?>