Skip to content

Commit

Permalink
Merge pull request #566 from YauheniKapliarchuk/v3
Browse files Browse the repository at this point in the history
[#548] Option to Disable WPML menu.
  • Loading branch information
YauheniKapliarchuk authored Apr 18, 2021
2 parents d6099af + 32775ad commit 513bf1f
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 51 deletions.
22 changes: 22 additions & 0 deletions app/Core/ALPSLanguages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace App\Core;

const BASENAME = 'sitepress-multilingual-cms/sitepress.php';

class ALPSLanguages
{
public static function WPMLPluginIsActive()
{
if( !function_exists('is_plugin_active') ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}

return !is_plugin_active(BASENAME);
}

private static function log($data ){
echo '<script>';
echo 'console.log('. json_encode( $data ) .')';
echo '</script>';
}
}
15 changes: 15 additions & 0 deletions app/Core/ALPSPostPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace App\Core;

class ALPSPostPage
{
public static function HideRelatedStories() {
return get_alps_option('project_alps_related_stories_is_hiding_on_post_page');
}

private static function log($data ){
echo '<script>';
echo 'console.log('. json_encode( $data ) .')';
echo '</script>';
}
}
31 changes: 27 additions & 4 deletions app/carbon-fields/cf-post.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Core\ALPSPostPage;
use Carbon_Fields\Container;
use Carbon_Fields\Field;

Expand Down Expand Up @@ -31,19 +32,41 @@ function crb_attach_post_template_fields()
->add_fields([
Field
::make('separator', 'crb_hide_sidebar', __('Hide Sidebar', 'alps'))
->set_width(50),
->set_width(33),
Field
::make('separator', 'crb_hide_img', __('Hide Featured Image', 'alps'))
->set_width(50),
->set_width(33),
Field
::make('separator', 'crb_show_related_stories', __('Show related stories on Post', 'alps'))
->set_width(33),
Field
::make('checkbox', 'hide_sidebar', __('Hide Sidebar', 'alps'))
->set_help_text(__('Hides the sidebar for this entry if it is active.', 'alps'))
->set_option_value('true')
->set_width(50),
->set_width(33),
Field
::make('checkbox', 'hide_featured_image', __('Hide Featured Image', 'alps'))
->set_help_text(__('Hides the featured image on the page/post header for this entry.', 'alps'))
->set_option_value('true')
->set_width(50),
->set_width(33),
Field
::make('checkbox', 'display_related_stories', __('Show related stories on Post', 'alps'))
->set_help_text(__('Hide (default option and managed in theme settings) / show Related Stories on the Post Page.', 'alps'))
->set_option_value('false')
->set_conditional_logic([[
'field' => !ALPSPostPage::HideRelatedStories(),
'value' => false,
'compare' => '='
]])
->set_width(33),
Field
::make('html', 'display_relates_stories_inactive')
->set_html(__('<p style="font-size:13px; margin-top: 0;">This feature is enabled. <br> To activate the feature, enable the option <u><i>"Hide Related Stories on Post page"</i></u> in the theme settings.</p>', 'alps'))
->set_conditional_logic([[
'field' => ALPSPostPage::HideRelatedStories(),
'value' => false,
'compare' => '='
]])
->set_width(33),
]);
}
19 changes: 19 additions & 0 deletions app/carbon-fields/cf-theme-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ function crb_attach_theme_options()
'compare' => '='
]])
->set_width(33),
Field
::make('html', 'crb_alps_languages')
->set_html(__('<h3>ALPS CORE Languages Settings for WPML plugin</h3><p style="font-size:16px">WPML plugin '.(\App\Core\ALPSLanguages::WPMLPluginIsActive() ? 'is not installed or activated' : 'settings is active').'</p>', 'alps')),
Field
::make('checkbox', 'project_alps_languages_hide_selector', __('Hide WPML languages', 'alps'))
->set_option_value('false')
->set_help_text(__('Hiding default WPML languages selector on page.', 'alps'))
->set_conditional_logic([[
'field' => \App\Core\ALPSLanguages::WPMLPluginIsActive(),
'value' => false,
'compare' => '='
]]),
Field
::make('html', 'crb_alps_page_related_stories')
->set_html(__('<h3>ALPS CORE Related Stories</h3><p style="font-size:16px">Settings for displaying </p>', 'alps')),
Field
::make('checkbox', 'project_alps_related_stories_is_hiding_on_post_page', __('Hide Related Stories on Post page', 'alps'))
->set_option_value('false')
->set_help_text(__('Hiding Related Stories on Post page.', 'alps')),
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav class="c-secondary-nav" role="navigation">
<ul class="c-secondary-nav__list">
@if (has_nav_menu('secondary_navigation') or apply_filters('wpml_active_languages', NULL, 'skip_missing=0'))
@if (apply_filters('wpml_active_languages', NULL, 'skip_missing=0'))
@if (apply_filters('wpml_active_languages', NULL, 'skip_missing=0') && !get_alps_option('project_alps_languages_hide_selector'))
@php $languages = icl_get_languages('skip_missing=0'); @endphp
<li class="c-secondary-nav__list-item c-secondary-nav__list-item__languages has-subnav">
<a href="" class="c-secondary-nav__link u-font--secondary-nav u-color--gray u-theme--link-hover--base"><span class="u-icon u-icon--xs u-path-fill--gray">@include('patterns.00-atoms.icons.icon-language')</span>Languages</a>
Expand Down
100 changes: 54 additions & 46 deletions views/patterns/02-organisms/asides/related-stories.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,54 +27,62 @@
'post__not_in' => array($post->ID)
);
$related = new WP_Query($args);
global $post;
$isGlobalHidingRelatedStories = get_alps_option('project_alps_related_stories_is_hiding_on_post_page');
$showRelatedStoriesOnPostPage = get_post_meta($post->ID, $cf_.'display_related_stories', true);
@endphp

<div class="c-related-posts u-spacing">
<div class="c-block__heading u-theme--border-color--darker">
<div class="c-block__heading-title u-theme--color--darker">{{ __('Related Stories', 'alps') }}</div>
</div>
<div class="c-related-posts__blocks u-spacing">
@if ($related->have_posts())
@while ($related->have_posts())
@php
$related->the_post();
$id = get_the_ID();
$title = get_the_title();
$link = get_permalink();
$date = get_the_date('F j, Y');
$category = $category;
@endphp
@if ($isVisibleImage && get_post_thumbnail_id())
@php
$thumb_id = get_post_thumbnail_id();
$thumb_size = 'horiz__4x3';
$image = wp_get_attachment_image_src($thumb_id, $thumb_size . '--s')[0];
$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
$block_class = "c-block--reversed c-media-block--reversed l-grid--7-col";
$block_title_class = "u-theme--color--darker u-font--primary--s";
$block_meta_class = "u-theme--color--dark u-font--secondary--xs";
$block_group_class = "u-flex--justify-start";
$block_content_class = "l-grid-item--4-col l-grid-item--m--3-col l-grid-item--l--1-col u-border--left u-theme--border-color--darker--left u-color--gray u-spacing--half";
$block_img_class = "l-grid-item--2-col l-grid-item--m--1-col l-grid-item--l--1-col u-padding--right";
$title_div = true;
@endphp
@include('patterns.01-molecules.blocks.media-block')
@else
@if (!$isGlobalHidingRelatedStories ||
($isGlobalHidingRelatedStories && $showRelatedStoriesOnPostPage))
<div class="c-related-posts u-spacing">
<div class="c-block__heading u-theme--border-color--darker">
<h3 class="c-block__heading-title u-theme--color--darker">{{ __('Related Stories', 'alps') }}</h3>
</div>
<div class="c-related-posts__blocks u-spacing">
@if ($related->have_posts())
@while ($related->have_posts())
@php
$thumb_id = NULL;
$block_class = "c-block__text u-theme--border-color--darker u-border--left u-padding--bottom u-padding--right u-spacing--half";
$block_title_class = "u-theme--color--darker u-font--primary--s";
$excerpt = get_the_excerpt();
$body = get_the_content();
$excerpt_length = 35;
$title_div = true;
$related->the_post();
$id = get_the_ID();
$title = get_the_title();
$link = get_permalink();
$date = get_the_date('F j, Y');
$category = $category;
@endphp
@include('patterns.01-molecules.blocks.content-block')
@endif
@endwhile
{!! wp_reset_postdata() !!}
@else
{{ __('There are no related stories at this time.', 'alps') }}
@endif
@if ($isVisibleImage && get_post_thumbnail_id())
@php
$thumb_id = get_post_thumbnail_id();
$thumb_size = 'horiz__4x3';
$image = wp_get_attachment_image_src($thumb_id, $thumb_size . '--s')[0];
$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
$block_class = "c-block--reversed c-media-block--reversed l-grid--7-col";
$block_title_class = "u-theme--color--darker u-font--primary--s";
$block_meta_class = "u-theme--color--dark u-font--secondary--xs";
$block_group_class = "u-flex--justify-start";
$block_content_class = "l-grid-item--4-col l-grid-item--m--3-col l-grid-item--l--1-col u-border--left u-theme--border-color--darker--left u-color--gray u-spacing--half";
$block_img_class = "l-grid-item--2-col l-grid-item--m--1-col l-grid-item--l--1-col u-padding--right";
$title_div = true;
@endphp
@include('patterns.01-molecules.blocks.media-block')
@else
@php
$thumb_id = NULL;
$block_class = "c-block__text u-theme--border-color--darker u-border--left u-padding--bottom u-padding--right u-spacing--half";
$block_title_class = "u-theme--color--darker u-font--primary--s";
$excerpt = get_the_excerpt();
$body = get_the_content();
$excerpt_length = 35;
$title_div = true;
@endphp
@include('patterns.01-molecules.blocks.content-block')
@endif
@endwhile
{!! wp_reset_postdata() !!}
@else
{{ __('There are no related stories at this time.', 'alps') }}
@endif
</div>
</div>
</div>
@endif

0 comments on commit 513bf1f

Please sign in to comment.