Skip to content

Commit

Permalink
Arreglats errors i afegides millores d'integració
Browse files Browse the repository at this point in the history
  • Loading branch information
paussus committed Oct 15, 2020
1 parent 8d4739d commit 8173309
Show file tree
Hide file tree
Showing 15 changed files with 1,339 additions and 862 deletions.
224 changes: 160 additions & 64 deletions admin/class-gendernaut-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,78 +75,152 @@ public function __construct( $plugin_name, $version, $textdomain = null ) {
$this->settings_manager = new WeDevs_Settings_API();
}

/**
* Return all the available "templates": both page templates and single-post_type.php
*
* @return array
*/
protected function get_available_templates() {
$post_templates = wp_get_theme()->get_post_templates();
$templates_folder = wp_get_theme()->get_template_directory();
foreach($post_templates as $post_type => $templates) {
$post_type_object = get_post_type_object($post_type);

foreach($templates as $template_filename => $template_name){
$templates[$templates_folder . '/' . $template_filename] = "{$post_type_object->labels->singular_name}: {$template_name}";
unset($templates[$template_filename]);
}
}

$post_types = $this->post_type_labels();
foreach ($post_types as $post_type => $label) {
if (file_exists($templates_folder . "/single-" . $post_type . ".php")) {
$templates[$templates_folder . "/single-" . $post_type . ".php"] = "{$label}: " . __( 'Default', $this->textdomain );
}
}

$post_type_object = get_post_type_object("post");
$templates = array('default' => "{$post_type_object->labels->singular_name}: " . __( 'Default', $this->textdomain )) + $templates;

return $templates;
}

// TODO: Comentar.
public function init_settings() {
public function custom_post_type_settings($defaults, $template = false) {
$settings = array(
'create_post_type' => array(
'name' => 'create_post_type',
'label' => __( 'Create Post Type', $this->textdomain ),
'type' => 'checkbox',
),
'post_type_singular' => array(
'name' => 'post_type_singular',
'label' => __( "Post Type Singular Name (Default: {$defaults['post_type_singular']})", $this->textdomain ),
'type' => 'text',
'default' => __($defaults['post_type_singular'], $this->textdomain),
'sanitize_callback' => 'trim',
),
'post_type_plural' => array(
'name' => 'post_type_plural',
'label' => __( "Post Type Plural Name (Default: {$defaults['post_type_plural']})", $this->textdomain ),
'type' => 'text',
'default' => __($defaults['post_type_plural'], $this->textdomain),
'sanitize_callback' => 'trim',
),
'post_type_menu' => array(
'name' => 'post_type_menu',
'label' => __( "Name in the Admin Menu (Default: {$defaults['post_type_menu']})", $this->textdomain ),
'type' => 'text',
'default' => __($defaults['post_type_menu'], $this->textdomain),
'sanitize_callback' => 'trim',
),
'archive_slug' => array(
'name' => 'archive_slug',
'label' => __( "Post Type Archive slug (Default: {$defaults['archive_slug']})", $this->textdomain ),
'type' => 'text',
'default' => $defaults['archive_slug'],
'sanitize_callback' => 'trim',
),
'create_taxonomy' => array(
'name' => 'create_taxonomy',
'label' => __( 'Create Custom Taxonomy', $this->textdomain ),
'type' => 'checkbox',
),
'taxonomy_singular' => array(
'name' => 'taxonomy_singular',
'label' => __( "Taxonomy Singular Name (Default: {$defaults['taxonomy_singular']})", $this->textdomain ),
'type' => 'text',
'default' => __($defaults['taxonomy_singular'], $this->textdomain),
'sanitize_callback' => 'trim',
),
'taxonomy_plural' => array(
'name' => 'taxonomy_plural',
'label' => __( "Taxonomy Plural Name (Default: {$defaults['taxonomy_plural']})", $this->textdomain ),
'type' => 'text',
'default' => __($defaults['taxonomy_plural'], $this->textdomain),
'sanitize_callback' => 'trim',
),
'taxonomy_slug' => array(
'name' => 'taxonomy_slug',
'label' => __( "Taxonomy Archive slug (Default: {$defaults['taxonomy_slug']})", $this->textdomain ),
'type' => 'text',
'default' => $defaults['taxonomy_slug'],
'sanitize_callback' => 'trim',
),
);

if ($template) {
$templates = $this->get_available_templates();
$settings['template'] = array(
'name' => 'template',
'label' => __('Template', $this->textdomain),
'desc' => __('Select how the archive contents are shown. In case of problems select', $this->textdomain) . ' ' . $templates['default'],
'type' => 'select',
'options' => $templates
);
}

return $settings;
}

// TODO: Comentar.
public function init_settings() {

$this->sections = array(
array(
'id' => 'gendernaut_post_type',
'title' => __( 'Custom Post Type', $this->textdomain ),
),
array(
'id' => 'gendernaut_sources_post_type',
'title' => __( 'Custom Sources Post Type', $this->textdomain ),
),
);

$this->settings = array(
'gendernaut_post_type' => array(
'create_post_type' => array(
'name' => 'create_post_type',
'label' => __( 'Create Custom Post Type', $this->textdomain ),
'type' => 'checkbox',
),
'post_type_singular' => array(
'name' => 'post_type_singular',
'label' => __( 'Post Type Singular Name (Default: Entry)', $this->textdomain ),
'type' => 'text',
'default' => __('Entry', $this->textdomain),
'sanitize_callback' => 'trim',
),
'post_type_plural' => array(
'name' => 'post_type_plural',
'label' => __( 'Post Type Plural Name (Default: Entries)', $this->textdomain ),
'type' => 'text',
'default' => __('Entries', $this->textdomain),
'sanitize_callback' => 'trim',
),
'post_type_menu' => array(
'name' => 'post_type_menu',
'label' => __( 'Name in the Admin Menu (Default: Archive)', $this->textdomain ),
'type' => 'text',
'default' => __('Archive', $this->textdomain),
'sanitize_callback' => 'trim',
),
'archive_slug' => array(
'name' => 'archive_slug',
'label' => __( 'Post Type Archive slug (Default: archive)', $this->textdomain ),
'type' => 'text',
'default' => 'archive',
'sanitize_callback' => 'trim',
),
'create_taxonomy' => array(
'name' => 'create_taxonomy',
'label' => __( 'Create Custom Taxonomy', $this->textdomain ),
'type' => 'checkbox',
),
'taxonomy_singular' => array(
'name' => 'taxonomy_singular',
'label' => __( 'Taxonomy Singular Name (Default: Type)', $this->textdomain ),
'type' => 'text',
'default' => __('Type', $this->textdomain),
'sanitize_callback' => 'trim',
),
'taxonomy_plural' => array(
'name' => 'taxonomy_plural',
'label' => __( 'Taxonomy Plural Name (Default: Types)', $this->textdomain ),
'type' => 'text',
'default' => __('Types', $this->textdomain),
'sanitize_callback' => 'trim',
),
'taxonomy_slug' => array(
'name' => 'taxonomy_slug',
'label' => __( 'Taxonomy Archive slug (Default: type)', $this->textdomain ),
'type' => 'text',
'default' => 'type',
'sanitize_callback' => 'trim',
),
)
'gendernaut_post_type' => $this->custom_post_type_settings(
array(
'post_type_singular' => 'Entry',
'post_type_plural' => 'Entries',
'post_type_menu' => 'Archive',
'archive_slug' => 'archive',
'taxonomy_singular' => 'Type',
'taxonomy_plural' => 'Types',
'taxonomy_slug' => 'type',
),
true
),
'gendernaut_sources_post_type' => $this->custom_post_type_settings(
array(
'post_type_singular' => 'Source',
'post_type_plural' => 'Sources',
'post_type_menu' => 'Sources',
'archive_slug' => 'sources',
'taxonomy_singular' => 'Source Type',
'taxonomy_plural' => 'Source Types',
'taxonomy_slug' => 'source_type',
)
),
);
}

Expand All @@ -173,6 +247,17 @@ public function add_post_type_settings() {

foreach ($post_types as $post_type => $label) {
$key = $this->get_post_type_section_key($post_type);
$post_type_archive_url = get_post_type_archive_link($post_type);

if (empty($post_type_archive_url)) {
continue;
}

$available_views = $views;
if (! gendernaut()->has_gendernaut_timeline_field($post_type)) {
unset($available_views['timeline']);
}

$taxonomies = $this->taxonomy_labels($post_type);
$sort_options = array_merge(
$this->get_simple_sort_options(),
Expand All @@ -186,14 +271,16 @@ public function add_post_type_settings() {
$this->settings[$key] = array(
'use_gendernaut' => array(
'name' => 'use_gendernaut',
'label' => __( 'Use Gendernaut Archive', $this->textdomain ),
'label' => __( 'Use Gendernaut Archive', $this->textdomain ),
'desc' => __( 'If active you can view the entries at', $this->textdomain ) . ' ' . $post_type_archive_url,
'type' => 'checkbox',
),
'views' => array(
'name' => 'views',
'label' => __( 'Show Views:', $this->textdomain ),
'type' => 'multicheck',
'options' => $views,
'default' => array('grid' => 'grid'),
'options' => $available_views,
),
'filter_by' => array(
'name' => 'filter_by',
Expand Down Expand Up @@ -236,6 +323,15 @@ public function add_post_type_settings() {
'sanitize_callback' => 'trim',
),
);

if ($post_type === 'gendernaut_archive') {
$this->settings[$key]['custom_field_timeline'] = array(
'name' => 'custom_field_timeline',
'label' => __( 'Custom Field Name for timeline Year', $this->textdomain ),
'desc' => __( 'If it is not defined the timeline view is not available', $this->textdomain ),
'type' => 'text',
);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gendernaut.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @wordpress-plugin
* Plugin Name: Gendernaut
* Plugin URI: https://tallerestampa.com
* Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
* Description: Permet crear un arxiu de continguts i visualitzar-lo de 3 formes diferents: matriu, línia de temps i llistat.
* Version: 1.0.0
* Author: Taller Estampa
* Author URI: https://tallerestampa.com
Expand Down
78 changes: 40 additions & 38 deletions includes/class-gendernaut-post-types-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,45 +241,63 @@ private function load_dependencies() {
}

/**
* Add self-defined Post Type Definitions if needed.
* Create custom post type and taxonomy
*
* @since 1.0.0
* @access private
* @param string $options_section The section from where to get the options.
* @param string $post_type The post type name.
* @param string $taxonomy The taxonomy name.
* @param boolean $post_thumbnails Whether to add the post-thumbnails capability to the post type.
*/
private function populate_post_type_defs() {
$create_post_type = gendernaut()->get_option('create_post_type', 'gendernaut_post_type');
private function create_custom_post_type_and_taxonomy($options_section, $post_type, $taxonomy, $post_thumbnails) {
$create_post_type = gendernaut()->get_option('create_post_type', $options_section);

if ( $create_post_type === 'on' ) {
$post_type = 'gendernaut_archive';
$sing_name = gendernaut()->get_option( 'post_type_singular', $options_section );

$sing_name = gendernaut()->get_option('post_type_singular', 'gendernaut_post_type' );
$plur_name = gendernaut()->get_option( 'post_type_plural', $options_section );

$plur_name = gendernaut()->get_option('post_type_plural', 'gendernaut_post_type' );
$menu_name = gendernaut()->get_option( 'post_type_menu', $options_section );

$menu_name = gendernaut()->get_option('post_type_menu', 'gendernaut_post_type' );
$rewrite = gendernaut()->get_option( 'archive_slug', $options_section );

$rewrite = gendernaut()->get_option('archive_slug', 'gendernaut_post_type' );
$this->add_post_type_def( $post_type, $sing_name, $plur_name, $rewrite, array(
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields' ),
'labels' => array( 'menu_name' => $menu_name )
) );

$this->add_post_type_def($post_type, $sing_name, $plur_name, $rewrite, array(
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'),
'labels' => array( 'menu_name' => $menu_name )
));

add_theme_support('post-thumbnails', ['gendernaut_archive']);
if ($post_thumbnails) {
add_theme_support( 'post-thumbnails', [ 'gendernaut_archive' ] );
}

$create_tax = gendernaut()->get_option('create_taxonomy', 'gendernaut_post_type');
$create_tax = gendernaut()->get_option( 'create_taxonomy', $options_section );

if ( $create_tax === 'on' ) {
$taxonomy = 'gendernaut_tax';

$sing_name = gendernaut()->get_option('taxonomy_singular', 'gendernaut_post_type' );
$sing_name = gendernaut()->get_option( 'taxonomy_singular', $options_section );

$plur_name = gendernaut()->get_option('taxonomy_plural', 'gendernaut_post_type' );
$plur_name = gendernaut()->get_option( 'taxonomy_plural', $options_section );

$rewrite = gendernaut()->get_option('taxonomy_slug', 'gendernaut_post_type' );
$rewrite = gendernaut()->get_option( 'taxonomy_slug', $options_section );

$this->add_taxonomy_def($taxonomy, $post_type, $sing_name, $plur_name, $rewrite);
$this->add_taxonomy_def( $taxonomy, $post_type, $sing_name, $plur_name, $rewrite );
}
}
}

/**
* Add self-defined Post Type Definitions if needed.
*
* @since 1.0.0
* @access private
*/
private function populate_post_type_defs() {
$this->create_custom_post_type_and_taxonomy('gendernaut_post_type', 'gendernaut_archive', 'gendernaut_tax', true);

$create_post_type = gendernaut()->get_option('create_post_type', 'gendernaut_post_type');

if ( $create_post_type === 'on' ) {
$post_type = 'gendernaut_archive';

$taxonomy = 'gendernaut_col';
$sing_name = __('Col·lecció', $this->textdomain);
Expand All @@ -292,22 +310,6 @@ private function populate_post_type_defs() {
$this->add_taxonomy_field_def($taxonomy, 'g_col_public', __("Pública", $this->textdomain), __("Indica si la col·lecció és pública", $this->textdomain), false, true);
}

$post_type = 'gendernaut_biblio';
$sing_name = __('Font', $this->textdomain);
$plur_name = __('Fonts', $this->textdomain);
$menu_name = __('Fonts', $this->textdomain);
$rewrite = 'fonts';

$this->add_post_type_def($post_type, $sing_name, $plur_name, $rewrite, array(
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'),
'labels' => array( 'menu_name' => $menu_name )
));

$taxonomy = 'gendernaut_biblio_type';
$sing_name = __('Tipus de Font', $this->textdomain);
$plur_name = __('Tipus de Fonts', $this->textdomain);
$rewrite = 'type';

$this->add_taxonomy_def($taxonomy, $post_type, $sing_name, $plur_name, $rewrite);
$this->create_custom_post_type_and_taxonomy('gendernaut_sources_post_type', 'gendernaut_biblio', 'gendernaut_biblio_type', false);
}
}
Loading

0 comments on commit 8173309

Please sign in to comment.