setIcon('arrows-left-right') ->make([ 'rewrite' => [ 'slug' => 'before-and-after', 'with_front' => false, ], 'taxonomies' => [ 'age', 'body_part', 'goal', 'number', 'person', 'skin_type', 'style', 'theme', 'timeline', ] ]) ->setAll([ 'show_directory', 'show_feed', 'hide_children', 'is_timeline', 'add_image_column' ]); $breadcrumb = $progress->config('breadcrumbs'); $breadcrumb->setTitle('Before & Afters'); //$directory = $progress->getConfig('directory'); } function altr_progress_fields():void { if (!class_exists('JVBase\registrar\Registrar')) { return; } $progress = Registrar::getInstance('progress'); $breadcrumbs = $progress->config('breadcrumbs'); $breadcrumbs->setCrumb(['project', 'form']); $fields = $progress->fields(); $fields->modifyField('post_title', 'for_all', true); $fields->modifyField('post_status', 'for_all', true); $fields->modifyField('post_date', 'for_all', true); $fields->modifyField('post_thumbnail', 'for_all', true); $fields->addField('person', [ 'type' => 'selector', 'subtype' => 'taxonomy', 'taxonomy' => 'person', 'label' => 'Person', 'quickEdit' => true, 'createNew' => true, 'section' => 'progression', 'hint' => 'Not public, just to make it easier to find', ]); $fields->addField('body_part', [ 'type' => 'selector', 'subtype' => 'taxonomy', 'taxonomy' => 'body_part', 'label' => 'Body Part', 'quickEdit' => true, 'createNew' => true, 'section' => 'progression', ]); $fields->addField('goal', [ 'type' => 'selector', 'subtype' => 'taxonomy', 'taxonomy' => 'goal', 'label' => 'Goal', 'quickEdit' => true, 'createNew' => true, 'section' => 'progression', ]); $fields->addField('timeline', [ 'type' => 'selector', 'subtype' => 'taxonomy', 'taxonomy' => 'timeline', 'label' => 'Timeline', 'quickEdit' => true, 'for_all' => true, 'createNew' => true, 'section' => 'progression', ]); $fields->addField('style', [ 'type' => 'selector', 'subtype' => 'taxonomy', 'taxonomy' => 'style', 'label' => 'Tattoo Style', 'quickEdit' => true, 'createNew' => true, 'section' => 'progression', ]); $fields->addField('theme', [ 'type' => 'selector', 'subtype' => 'taxonomy', 'taxonomy' => 'theme', 'label' => 'Tattoo Theme', 'quickEdit' => true, 'createNew' => true, 'section' => 'progression', ]); $fields->addField('skin_type', [ 'type' => 'selector', 'subtype' => 'taxonomy', 'taxonomy' => 'skin_type', 'label' => 'Skin Type', 'quickEdit' => true, 'createNew' => true, 'section' => 'progression', ]); $fields->addField('age', [ 'type' => 'selector', 'subtype' => 'taxonomy', 'taxonomy' => 'age', 'label' => 'Age of Tattoo', 'quickEdit' => true, 'createNew' => true, 'section' => 'progression', ]); $fields->addField('number', [ 'type' => 'text', 'subtype' => 'number', 'label' => 'Number of Treatments', 'quickEdit' => true, 'for_all' => true, 'section' => 'progression', ]); $fields->modifyField('post_content', 'for_all', true); $fields->modifyField('post_content', 'label', 'About this Timeline Point'); $fields->addField('last_date', [ 'type' => 'text', 'subtype' => 'number', 'label' => 'Last Date', 'hidden' => true, ]); $fields->addField('is_update', [ 'type' => 'true_false', 'label' => 'Is Update', 'hint' => 'If this point is not another treatment, but just an update in the progress', 'for_all' => true, ]); $feed = $progress->config('feed'); $feed->setCustomOrder([ 'number' => [ 'label' => 'Number of Treatments', 'icon' => 'hash-straight', 'for' => 'progress' ] ] ); $directory = $progress->config('directory'); $directory->setDirectoryExtra([ 'goal', 'skin_type', 'age' ]); } function altr_progress_schema():array { return [ 'type' => 'JVBase\inc\managers\SEO\render\Thing\CreativeWork\WebPage\CollectionPage\ImageGallery', 'name' => '{{post_title}} | Before and After Laser Tattoo Removal', 'description' => '{{post_excerpt}}', 'temporalCoverage' => '{{post_date}}/{{last_date}}', 'additionalProperty'=> [ ['id'=> 'number-of-sessions','name' => 'Number of sessions', 'value' => '{{number.name}}'], ['id' => 'treatment-area','name' => 'Treatment area', 'value' => '{{body_part.name}}'], ['id' => 'tattoo-style','name' => 'Tattoo style', 'value' => '{{style.name}}'], ['id' => 'skin-type','name' => 'Skin type', 'value' => '{{skin_type.name}}'], ['id' => 'goal','name' => 'Goal', 'value' => '{{goal.name}}'], ], ]; } function altr_progress_meta():array { return[ 'title' => '{{style.name}} {{theme.name}} Tattoo – Before & After {{number}} Laser Removal Sessions', 'description' => 'See this {{style.name}} {{theme.name}} {{age.name}}-old tattoo before and after {{number}} laser tattoo removal treatments on the {{body_part.name}}.', ]; } function altr_progress_archive(array $defaults):array { return array_merge($defaults, [ 'name' => 'Tattoos Before and After Laser Tattoo Removal', ]); } function altr_progress_reference_schema(array $defaults):array { return $defaults; } //function altr_progress():array //{ // return [ // 'singular' => 'Before & After', // 'plural' => 'Before & Afters', // 'dash_title' => 'Progress', // 'dash_description' => 'Manage your before and after posts', // 'breadcrumb' => 'Before & Afters', // 'capability_type' => ['progress', 'progress'], // 'hide_children' => true, // 'is_timeline' => true, // 'show_feed' => true, // 'show_directory'=> true, // 'directory_extra'=> ['goal', 'skin-type','age'], // 'hierarchical' => true, // 'icon' => 'arrows-left-right', // 'rewrite' => [ // 'slug' => 'before-and-after', // 'with_front' => false, // ], // 'sections' => [ // 'progression' => [ // 'label' => 'Progression', // ] // ], // 'custom_order' => [ // 'number' => [ // 'label' => 'Number of Treatments', // 'icon' => 'hash-straight', // 'for' => 'progress', // ] // ], // 'seo' => [ // 'schema' => [ // 'type' => 'BeforeAfter', // 'name' => '{{post_title}}', // 'description' => '{{post_excerpt}}', // 'temporalCoverage' => '{{post_date}}/{{last_date}}', // 'additionalProperty' => [ // ['name' => 'Number of sessions', 'value' => '{{number.name}}'], // ['name' => 'Treatment area', 'value' => '{{body-part.name}}'], // ['name' => 'Tattoo style', 'value' => '{{style.name}}'], // ['name' => 'Skin type', 'value' => '{{skin-type.name}}'], // ['name' => 'Goal', 'value' => '{{goal.name}}'], // ], // 'associatedMedia' => '{{timeline_photos}}', // ], // 'meta' => [ // 'title' => '{{style.name}} {{theme.name}} Tattoo – Before & After {{number}} Laser Removal Sessions', // 'description' => 'See this {{style.name}} {{theme.name}} {{age.name}}-old tattoo before and after {{number}} laser tattoo removal treatments on the {{body_part.name}}.', // ], // 'archive' => [ // 'type' => 'CollectionPage', // 'name' => 'Tattoos Before and After Laser Tattoo Removal', // ], // ], // 'feed' => [ // 'single' => [ // 'pre_title' => 'Before & After Laser Tattoo Removal', // ], // 'archive' => [ // // ], // 'config' => [ // 'is_gallery' => false, // 'content' => 'progress', // 'context' => 'progress', // 'id' => [], // 'class' => [], // ] // ], // 'fields' => [ // 'post_title' => [ // 'type' => 'text', // 'label' => 'Title', // 'quickEdit' => true, // 'section' => 'progression', // 'for_all' => true, // ], // 'post_status' => [ // 'type' => 'radio', // 'label' => 'Status', // 'options' => [ // 'publish' => 'Show', // 'draft' => 'Hide', // 'trash' => 'Scrap', // 'delete' => 'Permanently Delete' // ], // 'for_all' => true, // ], // 'post_date' => [ // 'type' => 'date', // 'label' => 'Date', // 'for_all' => true, // ], // 'post_thumbnail' => [ // 'type' => 'upload', // 'label' => 'Image', // 'quickEdit' => true, // 'section' => 'progression', // 'for_all' => true, // ], // 'person' => [ // 'type' => 'taxonomy', // 'taxonomy' => 'person', // 'autocomplete' => true, // 'label' => 'Person', // 'quickEdit' => true, // 'createNew' => true, // 'section' => 'progression', // 'hint' => 'Not public, just to make it easier to find' // ], // 'body-part' => [ // 'type' => 'taxonomy', // 'taxonomy' => 'body-part', // 'label' => 'Body Part', // 'autocomplete' => true, // 'quickEdit' => true, // 'createNew' => true, // 'section' => 'progression' // ], // 'goal' => [ // 'type' => 'taxonomy', // 'taxonomy' => 'goal', // 'autocomplete' => true, // 'label' => 'Goal', // 'quickEdit' => true, // 'createNew' => true, // 'section' => 'progression' // ], // 'timeline' => [ // 'type' => 'taxonomy', // 'taxonomy' => 'timeline', // 'autocomplete' => true, // 'label' => 'Timeline', // 'quickEdit' => true, // 'createNew' => true, // 'section' => 'progression', // 'for_all' => true, // 'hidden' => true, // ], // 'style' => [ // 'type' => 'taxonomy', // 'taxonomy' => 'style', // 'autocomplete' => true, // 'label' => 'Tattoo Style', // 'quickEdit' => true, // 'createNew' => true, // 'section' => 'progression' // ], // 'theme' => [ // 'type' => 'taxonomy', // 'taxonomy' => 'theme', // 'autocomplete' => true, // 'label' => 'Tattoo Theme', // 'quickEdit' => true, // 'createNew' => true, // 'section' => 'progression' // ], // 'skin-type' => [ // 'type' => 'taxonomy', // 'taxonomy' => 'skin-type', // 'label' => 'Skin Type', // 'autocomplete' => true, // 'quickEdit' => true, // 'createNew' => true, // 'section' => 'progression' // ], // 'age' => [ // 'type' => 'taxonomy', // 'taxonomy' => 'age', // 'autocomplete' => true, // 'label' => 'Age of Tattoo', // 'quickEdit' => true, // 'createNew' => true, // 'section' => 'progression' // ], // 'number' => [ // 'type' => 'text', // 'subtype' => 'number', // 'label' => 'Number of Treatments', // 'quickEdit' => true, // 'section' => 'progression', // 'for_all' => true, // 'hidden' => true, //auto calculated // ], // 'post_content' => [ // 'type' => 'textarea', // 'quill' => true, // 'label' => 'Notes', // 'section' => 'progression', // 'for_all' => true, // ], // 'last_date' => [ // 'type' => 'number', // 'label' => 'Last Date', // 'hidden' => true, // 'default' => 0, // 'for_all' => true, // ] // ], // 'upload_title' => 'Upload Before & Afters', // ]; //} add_filter('jvbFeedItem', 'altr_progress_item', 10, 2); function altr_progress_item(string $out, string $content):string { if ($content !== 'progress') { return $out; } ob_start(); ?>
Before After

Started:

Last treated:

Total Treatments:

    getIcon()) ?>
    getIcon()) ?>
    getIcon()) ?>
    getIcon()) ?>
    getIcon()) ?>
    getIcon()) ?>
routes('content'); global $post; $data = $route->formatTimeline($post); $timeline = $data['fields']['timeline']; if (!is_array($timeline)) { return $out; } $total = count($timeline); if ($total === 1) { return $out; } $total--; $first = 'Before'.jvbFormatImage($timeline[0]['post_thumbnail'],'tiny','medium',false); $last = 'After '.$total.' Tx'.jvbFormatImage($timeline[$total]['post_thumbnail'],'tiny','medium',false); return $first.$last; } add_filter('jvb_directory_render_item', 'altr_progress_directory_item', 10, 4); function altr_progress_directory_item(string $out, array $item, string $content, string $extra):string { if ($content !== 'progress') return $out; $parent = (int)$item['id']; $children = get_children($parent); $before = jvbFormatImage(get_post_thumbnail_id($parent),'tiny','directory-preview',false); $after = ''; if ($children) { $last = array_key_last($children); $after = jvbIcon('logo-triangle-fill').jvbFormatImage(get_post_thumbnail_id($last),'tiny','directory-preview',false); } return '
  • '.$item['name'].''.$extra.'
    '.$before.$after.'
  • '; } add_filter('jvbSEOResolveVariable', 'altr_progress_variables', 10, 6); function altr_progress_variables(mixed $return, string $variable, ?int $ID, ?string $objectType, ?string $contentType, ?Meta $meta):mixed { if ($contentType !== 'progress' || !in_array($variable, ['timeline_photos', 'last_date'])) { return $return; } $children = get_children([ 'post_parent' => $ID, 'post_status' => 'publish', 'order_by' => 'date', 'fields' => 'ids' ]); //Insert the parent to the beginning array_unshift($children, $ID); if ($variable === 'timeline_photos') { return array_map(function ($item) { return get_post_thumbnail_id($item); }, $children); } // $variable === 'last_date' return get_the_date('c', $children[array_key_last($children)]); } add_action('wp_after_insert_post', 'altr_update_progress_alt_text', 999, 3); function altr_update_progress_alt_text(int $ID, WP_Post $post, bool $update, ?WP_Post $before = null) { if ($post->post_type !== 'altr_progress') { return; } $thumbnail = get_post_thumbnail_id($ID); if (!$thumbnail || $thumbnail === 0) { return; } $meta = Meta::forPost($ID); $number = $meta->get('number'); $terms = $meta->getAll(['style', 'body_part','goal', 'skin_type', 'age', 'timeline']); foreach($terms as $slug => $value) { $terms = array_filter( array_map(function($term) use($slug) { return get_term((int)$term, BASE.$slug); },explode(',', $value) ), function($term) { return $term && !is_wp_error($term); } ); switch ($slug) { case 'skin_type': $slug = 'skinType'; break; case 'body_part': $slug = 'bodyPart'; break; } if (empty($terms)) { $$slug = ''; } else { $$slug = jvbCommaList(array_map(function($term){ return $term->name; }, $terms)); } } $title = sprintf( "%s | %s Before & After Laser Tattoo Removal", $post->post_title, $style ); $style = ($style === '') ? $style : ' '.$style; $age = ($age === '') ? $age : ' '.$age.' old'; $bodyPart = ($bodyPart === '') ? $bodyPart : ' on the '.$bodyPart; $skinType = ($skinType === '') ? $skinType : ' on a person with FitzPatrick Skin Type '.$skinType; $timeline = ($timeline === '') ? $timeline : ' '.$timeline.' after their '.$number.' treatment'; $goal = ($goal === '') ? $goal : ' This client is hoping for '.$goal; $alt = sprintf( "A photo of a%s%s tattoo%s%s%s.%s", $style, $age, $bodyPart, //on the ... $skinType, //on a person with FitzPatrick Scale skin type ... $timeline, //", x weeks after their %number% treatment" $goal //"This client is hoping for %goal%." ); wp_update_post([ 'ID' => $thumbnail, 'post_title' => $title ]); update_post_meta($thumbnail, '_wp_attachment_image_alt', $alt); }