setIcon('scribble') ->make([ 'rewrite' => [ 'slug' => 'projects', 'with_front' => false, ], 'for' => [ 'art', 'design', 'development', 'strategy', 'writing' ], 'hierarchical' => true, ]) ->setAll([ 'show_feed', 'show_directory', 'is_content' ]); } function ajv_project_fields():void { if (!class_exists('JVBase\registrar\Registrar')) { return; } $project = Registrar::getInstance('project'); //$directory = $project->getConfig('directory'); //$breadcrumbs = $project->config('breadcrumbs'); //$breadcrumbs->setCrumb('project'); $fields = $project->fields(); $fields->addField( 'city', [ 'type' => 'selector', 'subtype' => 'taxonomy', 'isReference' => true, 'taxonomy' => 'city', 'label' => 'City', 'quickEdit' => true, ] ); $fields->addField( 'thumbnail', [ 'type' => 'upload', 'multiple' => false, 'label' => 'Featured Image', ] ); $fields->addField( 'summary', [ 'type' => 'textarea', 'quill' => true, 'label' => 'Summary', ] ); $fields->addField( 'target', [ 'type' => 'taxonomy', 'isReference' => true, 'taxonomy' => 'target', 'label' => 'Target Audience', 'quickEdit' => true, ] ); $fields->addField( 'started', [ 'type' => 'date', 'label' => 'Started', 'quickEdit' => true, ] ); $fields->addField( 'ended', [ 'type' => 'date', 'label' => 'Ended', 'quickEdit' => true, ] ); $fields->addField( 'budget', [ 'type' => 'radio', 'label' => 'Budget', 'options' => [ 'low' => '$', 'medium-low'=> '$$', 'medium' => '$$$', 'medium-high'=> '$$$$', 'high' => '$$$$$', ] ] ); $fields->addField( 'timeline', [ 'type' => 'text', 'label' => 'Timeline', 'quickEdit' => true, ] ); $fields->addField('needs', [ 'type' => 'repeater', 'label' => 'Needs', 'fields' => [ 'need' => [ 'type' => 'text', 'label' => 'Need', 'required' => true ], 'image' => [ 'type' => 'upload', 'multiple' => true, 'label' => 'Example Image' ], 'fulfilled' => [ 'type' => 'textarea', 'quill' => true, 'label' => 'How I fulfilled it' ] ] ]); $fields->addField('wants', [ 'type' => 'repeater', 'label' => 'Wants', 'fields' => [ 'need' => [ 'type' => 'text', 'label' => 'Need', 'required' => true ], 'image' => [ 'type' => 'upload', 'multiple' => true, 'label' => 'Example Image' ], 'fulfilled' => [ 'type' => 'textarea', 'quill' => true, 'label' => 'How I fulfilled it' ] ] ]); $fields->addField( 'forType', [ 'type' => 'repeater', 'label' => 'Person, Organization, or LocalBusiness this is for', 'fields' => [ 'type' => [ 'type' => 'select', 'label' => 'Type', 'options' => [ 'JVBase\managers\SEO\render\Thing\Person' => 'Person', 'JVBase\managers\SEO\render\Thing\Organization\LocalBusiness\LocalBusiness' => 'Local Business', 'JVBase\managers\SEO\render\Thing\Organization\Organization' => 'Organization' ] ], 'name' => [ 'type' => 'text', 'label' => 'Name', ], 'url' => [ 'type' => 'url', 'label' => 'Website', ], 'location' => [ 'type' => 'text', 'label' => 'Location', ], ] ] ); $fields->addCommon('review'); $fields->addCommon('wiki'); } //function ajv_project():array //{ // return [ // 'singular' => 'Project', // 'plural' => 'Projects', // 'icon' => 'cards-three', // 'show_feed' => true, // 'show_directory' => true, // 'approve_new' => false, // 'rewrite' => [ // 'slug' => 'projects', // 'with_front' => false, // 'hierarchical' => true, // ], // 'hierarchical' => true, // 'for_content' => [ // 'art', // 'project', // 'development', // 'strategy', // 'writing', // ], // 'seo' => [ // 'schema' => [ // 'type' => 'CreativeWork', // 'name' => '{{name}}', // 'description' => '{{description}}', // 'dateCreated' => '{{started}}', // 'keywords' => '{{target.name}}', // ], // 'meta' => [ // 'title' => '{{name}} | Project by JakeVan', // 'description' => '{{description}}', // ], // 'archive' => [ // 'type' => 'CollectionPage', // 'name' => '{{name}}', // 'description' => '{{description}}', // ], // ], // 'fields' => [ // 'term_name' => [ // 'label' => 'Name', // 'type' => 'text', // 'quickEdit' => true, // ], // 'city' => [ // 'type' => 'taxonomy', // 'isReference' => true, // 'taxonomy' => 'city', // 'autocomplete' => true, // 'quickEdit' => true, // 'label' => 'City', // ], // 'target' => [ // 'type' => 'taxonomy', // 'isReference' => true, // 'taxonomy' => 'target', // 'autocomplete' => true, // 'quickEdit' => true, // 'label' => 'Target Audience', // ], // 'started' => [ // 'type' => 'date', // 'label' => 'Started', // 'quickEdit' => true, // ], // 'ended' => [ // 'type' => 'date', // 'label' => 'Ended', // 'quickEdit' => true, // ], // 'budget' => [ // 'type' => 'radio', // 'label' => 'Budget', // 'options' => [ // 'low' => '$', // 'medium-low'=> '$$', // 'medium' => '$$$', // 'medium-high'=> '$$$$', // 'high' => '$$$$$', // ] // ], // 'timeline' => [ // 'type' => 'text', // 'label' => 'Timeline', // 'quickEdit' => true, // ], // 'url' => [ // 'type' => 'url', // 'label' => 'Project URL', // 'quickEdit' => true, // ], // 'description' => [ // 'type' => 'textarea', // 'quill' => true, // 'quickEdit' => true, // 'label' => 'Project Description', // ], // 'needs' => [ // 'type' => 'repeater', // 'label' => 'Needs', // 'fields'=> [ // 'need' => [ // 'type' => 'text', // 'label' => 'Need', // 'required' => true // ], // 'fulfilled' => [ // 'type' => 'textarea', // 'quill' => true, // 'label' => 'How I fulfilled it' // ] // ] // ], // 'wants' => [ // 'type' => 'repeater', // 'label' => 'Wants', // 'fields'=> [ // 'need' => [ // 'type' => 'text', // 'label' => 'Want', // 'required' => true // ], // 'fulfilled' => [ // 'type' => 'textarea', // 'quill' => true, // 'label' => 'How I fulfilled it' // ] // ] // ], // // 'common' => [ 'wiki' ] // ] // ]; //} function ajv_project_schema():array { return [ // 'type' => 'JVBase\managers\SEO\render\Thing\CreativeWork\CreativeWork', 'name' => 'Projects by JakeVan', 'description' => 'Each project can have multiple aspects - from Design to Strategy.', // 'primaryImageOfPage' => '{{thumbnail}}', ]; } function ajv_project_meta():array { return[ 'name' => '{{name}} | Project', ]; } function ajv_project_archive(array $defaults):array { return array_merge($defaults, [ 'name' => '{{name}} | Project', 'description' => '{{description}}', 'primaryImageOfPage' => '{{thumbnail}}', 'about' => [ 'type' => 'JVBase\managers\SEO\render\Thing\CreativeWork\CreativeWork', 'name' => '{{name}}', 'creator' => '{{CREATOR}}', 'sourceOrganization'=> '{{forType}}', 'abstract' => '{{summary}}' ], ]); } function ajv_project_reference_schema(array $defaults):array { return $defaults; } function ajv_render_project_cover(int $ID):string { return ''; $background = ''; $meta = Meta::forTerm($ID); $thumbnail = $meta->get('thumbnail'); if ($thumbnail !== '') { $background = str_replace('getAll(); $extra = 'Edmonton'; if ($fields['city'] !== '') { $cities = explode(',', $fields['city']); $temp = []; foreach ($cities as $city) { $term = get_term($city, 'ajv_city'); if ($term && !is_wp_error($term)) { $temp[] = $term->name; } } if (!empty($temp)) { $extra = jvbCommaList($temp); } } $extra .= ' Made Project'; return ''.$extra.''.$fields['name'].'.'; } add_filter('jvbSummaryHeaderExtra', 'ajv_project_summary_extra', 11, 2); function ajv_project_summary_extra(string $return, string $type):string { if ($type !== 'project') { return $return; } return '

Or see all projects.

'; } add_filter('jvbBeforeSummary', 'ajv_project_before_summary', 10, 2); function ajv_project_before_summary(string $return, string $type):string { if ($type !== 'project') { return $return; } $meta = Meta::forTerm(get_queried_object_id()); $fields = $meta->getAll(); $rows = []; if ($fields['city'] !== '') { $rows[] = jvbMetaTermList($fields['city'], 'city'); } if ($fields['target'] !== '') { $rows[] = jvbMetaTermList($fields['target'], 'target'); } if ($fields['started'] !== '') { $rows[] = ''.jvbIcon('calendar-blank').'Started:'; } if ($fields['ended'] !== '') { $rows[] = 'Ended:'; } if ($fields['budget'] !== '') { $budget = ''; for ($i = 0; $i <= (int) $fields['budget']; $i++) { $budget .= '$'; } $title = match((int)$fields['budget']) { 0 => 'Low', 1 => 'Medium Low', 2 => 'Medium', 3 => 'Medium High', 4 => 'High' }; $rows[] = ''.jvbIcon('currency-dollar-simple').'Budget:'.$budget.''; } if ($fields['timeline'] !== '') { $rows[] = ''.jvbIcon('hourglass-medium').'Timeline:'.$fields['timeline']; } $summary = ''; if (!empty($rows)) { $summary = '

At a Glance

'; } return $summary; } add_filter('jvbSummaryImage', 'ajv_project_summary_image', 10, 2); function ajv_project_summary_image(string $return, string $type):string { if ($type !== 'project') { return $return; } $meta = Meta::forTerm(get_queried_object_id()); $thumbnail = $meta->get('thumbnail'); return $thumbnail === '' ? '' : jvbFormatImage((int)$thumbnail); } add_filter('jvbSummaryDetails', 'ajv_project_summary_details', 10, 2); function ajv_project_summary_details(array $return, string $type):array { if ($type !== 'project') { return $return; } $return = []; $meta = Meta::forTerm(get_queried_object_id()); $fields = $meta->getAll(); if ($fields['summary'] !== '') { $return['about-this-project'] = $fields['summary']; } if (!empty($fields['needs'])) { $return['needs'] = ajvb_format_needs($fields['needs']); } if (!empty($fields['wants'])) { $return['wants'] = ajvb_format_wants($fields['wants']); } if (!empty($fields['review'])) { $return['review'] = $fields['review']; } return $return; } add_filter('jvbSummaryIsOpen', 'ajv_open_project_summary', 10, 2); function ajv_open_project_summary(bool $isOpen, string $type):bool { if ($type !== 'project') { return $isOpen; } return true; } add_filter('jvbSummaryDetailsTitle', 'ajv_project_summary_label', 10, 2); function ajv_project_summary_label(string $title, string $type):string { return 'More about this project'; } add_filter('render_block', 'ajv_project_content', 9999, 2); function ajv_project_content(string $OG, array $block):string { if ($block['blockName'] !== 'jvb/summary') { return $OG; } if (!is_tax(BASE.'project')) { return $OG; } $menu = Cache::for('project_menu'); $ID = get_queried_object_id(); $menu->connect('term'); $registrar = Registrar::getInstance('project'); $menu->flush(); $nav = $menu->remember($ID, function() use ($registrar, $ID) { $types = array_map(function ($type) { return jvbCheckBase($type); }, $registrar->registrar->for); $menu = []; foreach ($types as $type) { $query = new WP_Query([ 'post_type' => $type, 'post_status' => 'publish', 'tax_query' => [[ 'taxonomy' => BASE.'project', 'terms' => $ID ]], 'posts_per_page' => 1, 'fields' => 'ids', ]); if ($query->have_posts()) { $typeRegistrar = Registrar::getInstance($type); $menu[jvbNoBase($type)] = $typeRegistrar; } wp_reset_postdata(); } if (!empty($menu)) { global $wp; $base = home_url( $wp->request ); $current = home_url(add_query_arg($_GET, $wp->request)); $class = $current === $base ? ' class="current"' : ''; $nav = sprintf( ''; return $nav; } return ''; }); global $_GET; $content = array_key_exists('content', $_GET) ? $_GET['content'] : 'all'; $cache = Cache::for($content)->connect('term'); $cache->flush(); $page = $_GET['jpage']??1; $key = $cache->generateKey([ 'id' => $ID, 'page' => $page ]); return $OG.$cache->remember( $key, function() use ($content, $ID, $page, $nav, $registrar) { $post_types = ($content === 'all') ? array_map(function ($type) { return jvbCheckBase($type); },$registrar->registrar->for) : jvbCheckBase($content); $args = [ 'post_type' => $post_types, 'posts_per_page' => 20, 'paged' => $page, 'fields' => 'ids', 'tax_query' => [[ 'taxonomy' => BASE.'project', 'field' => 'term_id', 'terms' => $ID ]] ]; $posts = new WP_Query($args); $section = '

Project Parts

'.$nav; if (!empty($posts->posts)) { $section .= ''; $total = $posts->max_num_pages; if ($total > 1) { $big = 999999999; // need an unlikely integer $format = ($content === 'all') ? '' : '&content='.$content; echo paginate_links([ 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?jpage=%#%'.$format, 'current' => $page, 'total' => $total ]); } } else { $section .= '

Nothing here yet.

'; } $section .= '
'; wp_reset_postdata(); return $section; } ); } add_filter('jvbSummaryOnThisPage', 'ajv_project_on_this_page', 10, 2); function ajv_project_on_this_page(array $ids, string $type):array { if ($type !== 'project'){ return $ids; } $ids[] = 'project-parts'; return $ids; }