PluginProbe
Depicter — Popup & Slider Builder / 1.3.2
Depicter — Popup & Slider Builder v1.3.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / modules / wpemerge-app-core / src / Sidebar / Sidebar.php

Sidebar.php in Depicter — Popup & Slider Builder 1.3.2, at modules/wpemerge-app-core/src/Sidebar/Sidebar.php

61 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package WPEmergeAppCore
4 * @author Atanas Angelov <hi@atanas.dev>
5 * @copyright 2017-2020 Atanas Angelov
6 * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
7 * @link https://wpemerge.com/
8 */
9
10 namespace WPEmergeAppCore\Sidebar;
11
12 class Sidebar {
13 /**
14 * Check if the current page is part of the blog structure.
15 *
16 * @return boolean
17 */
18 protected function isBlog() {
19 return ( is_home() || is_archive() || is_search() || ( is_single() && get_post_type() === 'post' ) );
20 }
21
22 /**
23 * Get the post id that should be checked for a custom sidebar for the current request.
24 *
25 * @return int
26 */
27 protected function getSidebarPostId() {
28 $post_id = intval( get_the_ID() );
29
30 if ( $this->isBlog() ) {
31 $post_id = intval( get_option( 'page_for_posts' ) );
32 }
33
34 $post_id = intval( apply_filters( 'wpemerge_app_core_sidebar_context_post_id', $post_id ) );
35
36 return $post_id;
37 }
38
39 /**
40 * Get the current sidebar id.
41 *
42 * @param string $default Default sidebar to use if a custom one is not specified.
43 * @param string $meta_key Meta key to check for a custom sidebar id.
44 * @return string
45 */
46 public function getCurrentSidebarId( $default = 'default-sidebar', $meta_key = '_custom_sidebar' ) {
47 $post_id = $this->getSidebarPostId();
48 $sidebar = $default;
49
50 if ( $post_id ) {
51 $sidebar = get_post_meta( $post_id, $meta_key, true );
52 }
53
54 if ( empty( $sidebar ) ) {
55 $sidebar = $default;
56 }
57
58 return $sidebar;
59 }
60 }
61