Skip to content

Commit 6ba3ee4

Browse files
authored
v0.5.8 Merge pull request #111 from JoryHogeveen/dev
v0.5.8
2 parents 078d27c + 7f84a84 commit 6ba3ee4

15 files changed

+345
-213
lines changed

includes/class-control-trigger.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ final class OCS_Off_Canvas_Sidebars_Control_Trigger extends OCS_Off_Canvas_Sideb
6767
'div',
6868
);
6969

70+
/**
71+
* HTML elements that are rendered considered link elements.
72+
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel
73+
* @since 0.5.8
74+
* @var array
75+
*/
76+
public static $link_elements = array(
77+
'a',
78+
'area',
79+
'form',
80+
'link',
81+
);
82+
7083
/**
7184
* Do not allow this class to be instantiated.
7285
*/
@@ -127,6 +140,13 @@ public static function render( $sidebar_id, $args = array() ) {
127140
}
128141
}
129142

143+
// Fix link elements XFN. See https://github.com/JoryHogeveen/off-canvas-sidebars/issues/116
144+
if ( in_array( $args['element'], self::$link_elements, true ) ) {
145+
if ( empty( $args['attr']['rel'] ) ) {
146+
$args['attr']['rel'] = 'nofollow';
147+
}
148+
}
149+
130150
$attr = array(
131151
'class' => array(),
132152
);

includes/class-frontend.php

Lines changed: 86 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @author Jory Hogeveen <[email protected]>
1717
* @package Off_Canvas_Sidebars
1818
* @since 0.1.0
19-
* @version 0.5.7
19+
* @version 0.5.8
2020
* @uses \OCS_Off_Canvas_Sidebars_Base Extends class
2121
*/
2222
final class OCS_Off_Canvas_Sidebars_Frontend extends OCS_Off_Canvas_Sidebars_Base
@@ -32,16 +32,63 @@ final class OCS_Off_Canvas_Sidebars_Frontend extends OCS_Off_Canvas_Sidebars_Bas
3232
/**
3333
* Class constructor.
3434
* @since 0.3.0 Private constructor.
35+
* @since 0.5.8 Check if init hook is running or already done.
3536
* @access private
3637
*/
3738
private function __construct() {
38-
39-
if ( $this->get_settings( 'enable_frontend' ) ) {
40-
$this->default_actions();
39+
if ( did_action( 'init' ) || doing_action( 'init' ) ) {
40+
$this->init();
41+
} else {
42+
add_action( 'init', array( $this, 'init' ) );
4143
}
4244

4345
add_action( 'wp_enqueue_scripts', array( $this, 'add_styles_scripts' ) );
44-
add_action( 'wp_head', array( $this, 'add_inline_styles' ) );
46+
}
47+
48+
/**
49+
* Initialize frontend.
50+
* Add default actions.
51+
*
52+
* @since 0.1.0
53+
* @since 0.5.8 Renamed from `default_actions` and made public.
54+
*/
55+
public function init() {
56+
/**
57+
* Enable or disable frontend rendering.
58+
*
59+
* @since 0.5.8
60+
*
61+
* @param bool $enabled Whether to enable frontend.
62+
*/
63+
if ( ! apply_filters( 'ocs_enable_frontend', (bool) $this->get_settings( 'enable_frontend' ) ) ) {
64+
return;
65+
}
66+
67+
$before_hook = $this->get_website_before_hook();
68+
$after_hook = $this->get_website_after_hook();
69+
70+
$before_prio = $this->get_settings( 'website_before_hook_priority' );
71+
$after_prio = $this->get_settings( 'website_after_hook_priority' );
72+
73+
if ( ! is_numeric( $before_prio ) ) {
74+
$before_prio = 5; // Early addition.
75+
}
76+
if ( ! is_numeric( $after_prio ) ) {
77+
$after_prio = 50; // Late addition.
78+
if ( 'wp_footer' === $after_hook ) {
79+
$after_prio = -50; // Early addition (before scripts).
80+
}
81+
}
82+
83+
$before_prio = apply_filters( 'ocs_website_before_hook_priority', $before_prio );
84+
$after_prio = apply_filters( 'ocs_website_after_hook_priority', $after_prio );
85+
86+
add_action( $before_hook, array( $this, 'before_site' ), $before_prio );
87+
add_action( $after_hook, array( $this, 'after_site' ), $after_prio );
88+
89+
/* EXPERIMENTAL */
90+
//add_action( 'wp_footer', array( $this, 'after_site' ), 0 ); // enforce first addition.
91+
//add_action( 'wp_footer', array( $this, 'after_site_script' ), 99999 ); // enforce almost last addition.
4592

4693
add_filter( 'body_class', array( $this, 'filter_body_class' ) );
4794
}
@@ -64,6 +111,7 @@ public function filter_body_class( $classes ) {
64111
* Get the hook to open the website wrapper.
65112
*
66113
* @since 0.5.6
114+
* @since 0.5.8 Set default to wp_body_open instead of website_before.
67115
* @return string
68116
*/
69117
public function get_website_before_hook() {
@@ -73,7 +121,7 @@ public function get_website_before_hook() {
73121
if ( 'genesis' === get_template() ) {
74122
$before_hook = 'genesis_before';
75123
} else {
76-
$before_hook = 'website_before';
124+
$before_hook = 'wp_body_open';
77125
}
78126
}
79127

@@ -84,6 +132,7 @@ public function get_website_before_hook() {
84132
* Get the hook to close the website wrapper.
85133
*
86134
* @since 0.5.6
135+
* @since 0.5.8 Set default to wp_footer instead of website_after.
87136
* @return string
88137
*/
89138
public function get_website_after_hook() {
@@ -93,47 +142,13 @@ public function get_website_after_hook() {
93142
if ( 'genesis' === get_template() ) {
94143
$after_hook = 'genesis_after';
95144
} else {
96-
$after_hook = 'website_after';
145+
$after_hook = 'wp_footer';
97146
}
98147
}
99148

100149
return trim( apply_filters( 'ocs_website_after_hook', $after_hook ) );
101150
}
102151

103-
/**
104-
* Add default actions
105-
*
106-
* @since 0.1.0
107-
*/
108-
private function default_actions() {
109-
110-
$before_hook = $this->get_website_before_hook();
111-
$after_hook = $this->get_website_after_hook();
112-
113-
$before_prio = $this->get_settings( 'website_before_hook_priority' );
114-
$after_prio = $this->get_settings( 'website_after_hook_priority' );
115-
116-
if ( ! is_numeric( $before_prio ) ) {
117-
$before_prio = 5; // Early addition.
118-
}
119-
if ( ! is_numeric( $after_prio ) ) {
120-
$after_prio = 50; // Late addition.
121-
if ( 'wp_footer' === $after_hook ) {
122-
$after_prio = -50; // Early addition (before scripts).
123-
}
124-
}
125-
126-
$before_prio = apply_filters( 'ocs_website_before_hook_priority', $before_prio );
127-
$after_prio = apply_filters( 'ocs_website_after_hook_priority', $after_prio );
128-
129-
add_action( $before_hook, array( $this, 'before_site' ), $before_prio );
130-
add_action( $after_hook, array( $this, 'after_site' ), $after_prio );
131-
132-
/* EXPERIMENTAL */
133-
//add_action( 'wp_footer', array( $this, 'after_site' ), 0 ); // enforce first addition.
134-
//add_action( 'wp_footer', array( $this, 'after_site_script' ), 99999 ); // enforce almost last addition.
135-
}
136-
137152
/**
138153
* before_site action hook
139154
*
@@ -531,6 +546,16 @@ public function do_control_trigger( $sidebar_id, $args = array() ) {
531546
* @since 0.2.2 Add FastClick library.
532547
*/
533548
public function add_styles_scripts() {
549+
/**
550+
* Enable or disable frontend assets.
551+
*
552+
* @since 0.5.8
553+
*
554+
* @param bool $enabled Whether to enable frontend.
555+
*/
556+
if ( ! apply_filters( 'ocs_enable_assets', true ) ) {
557+
return;
558+
}
534559

535560
// @todo Validate and use minified files
536561
$suffix = '';//defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
@@ -567,22 +592,22 @@ public function add_styles_scripts() {
567592
'_debug' => (bool) ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
568593
)
569594
);
595+
596+
wp_add_inline_style( 'off-canvas-sidebars', $this->get_inline_styles() );
570597
}
571598

572599
/**
573-
* Add inline styles.
600+
* Get inline styles.
574601
*
575602
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
576603
* @SuppressWarnings(PHPMD.NPathComplexity)
577604
* @todo Refactor to enable above checks?
578605
*
579-
* @since 0.1.0
606+
* @since 0.1.0 Added as output method `add_inline_styles` in `wp_head` action.
607+
* @since 0.5.8 Refactored and renamed to a getter method.
608+
* @return string
580609
*/
581-
public function add_inline_styles() {
582-
if ( is_admin() ) {
583-
return;
584-
}
585-
610+
public function get_inline_styles() {
586611
$prefix = $this->get_settings( 'css_prefix' );
587612
$css = '';
588613

@@ -635,9 +660,19 @@ public function add_inline_styles() {
635660
}
636661
} // End foreach().
637662

638-
if ( $css ) {
639-
echo '<style type="text/css">' . $css . '</style>';
640-
}
663+
/**
664+
* Modify the inline styles.
665+
*
666+
* @since 0.5.8
667+
*
668+
* @param string $css The rendered inline styles.
669+
* @param string $prefix The CSS prefix.
670+
*
671+
* @return string
672+
*/
673+
$css = apply_filters( 'ocs_inline_styles', $css, $prefix );
674+
675+
return $css;
641676
}
642677

643678
/**

includes/class-menu-meta-box.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public function wp_get_nav_menu_items( $items ) {
248248

249249
if ( off_canvas_sidebars_frontend()->is_sidebar_enabled( $sidebar_id ) ) {
250250
$item->url = '';
251+
$item->xfn = 'nofollow';
251252

252253
$link_classes = OCS_Off_Canvas_Sidebars_Control_Trigger::get_trigger_classes( $sidebar_id );
253254

includes/class-ocs.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,19 @@ private function db_update() {
554554
$settings['compatibility_position_fixed'] = 'custom-js';
555555
}
556556
}
557+
558+
// Upgrade to 0.5.8
559+
if ( version_compare( $db_version, '0.5.8', '<' ) ) {
560+
// Set default values pre-0.5.8 to prevent breaking backwards compatibility.
561+
if ( 'genesis' !== get_template() ) {
562+
if ( empty( $settings['website_before_hook'] ) ) {
563+
$settings['website_before_hook'] = 'website_before';
564+
}
565+
if ( empty( $settings['website_after_hook'] ) ) {
566+
$settings['website_after_hook'] = 'website_after';
567+
}
568+
}
569+
}
557570
}
558571

559572
$settings['db_version'] = $this->db_version;

includes/class-settings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ final class OCS_Off_Canvas_Sidebars_Settings extends OCS_Off_Canvas_Sidebars_Bas
5555
'scroll_lock' => 0,
5656
'background_color_type' => '',
5757
'background_color' => '',
58-
'website_before_hook' => 'website_before',
59-
'website_after_hook' => 'website_after',
58+
'website_before_hook' => '',
59+
'website_after_hook' => '',
6060
'website_before_hook_priority' => '',
6161
'website_after_hook_priority' => '',
6262
'use_fastclick' => 0,

includes/class-tab-general.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ protected function get_tab_fields() {
175175
$theme_hooks_wiki = esc_html__( 'Click here for a list of currently known compatible theme hooks', OCS_DOMAIN );
176176
$theme_hooks_wiki = '<a href="https://github.com/JoryHogeveen/off-canvas-sidebars/wiki/Compatible-theme-hooks" target="_blank" rel="noopener noreferrer">' . $theme_hooks_wiki . '</a>';
177177

178-
$before_hook = 'website_before';
179-
$after_hook = 'website_after';
178+
$before_hook = 'wp_body_open';
179+
$after_hook = 'wp_footer';
180180
if ( 'genesis' === get_template() ) {
181181
$before_hook = 'genesis_before';
182182
$after_hook = 'genesis_after';

js/fixed-scrolltop.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@
1818

1919
$window.on( 'ocs_initialized', function () {
2020

21-
ocsOffCanvasSidebars.debug('start fixed-scrolltop.js');
21+
ocsOffCanvasSidebars.debug( 'start fixed-scrolltop.js' );
2222

2323
var curScrollTopElements,
2424
scrollTarget = ocs_site = ocsOffCanvasSidebars.container;
25-
if ( 'auto' !== ocs_site.css('overflow-y') ) {
25+
if ( 'auto' !== ocs_site.css( 'overflow-y' ) ) {
2626
scrollTarget = $window;
2727
}
2828

2929
function run() {
30-
if ( 'none' !== ocs_site.css('transform') ) {
30+
if ( 'none' !== ocs_site.css( 'transform' ) ) {
3131
curScrollTopElements = ocsOffCanvasSidebars.getFixedElements();
3232
ocsOffCanvasSidebars.scrollTopFixed();
3333
scrollTarget.on( 'scroll resize', function() {
3434
var newScrollTopElements = ocsOffCanvasSidebars.getFixedElements();
3535
curScrollTopElements = curScrollTopElements.add( newScrollTopElements );
3636
ocsOffCanvasSidebars.scrollTopFixed();
3737
} );
38-
scrollTarget.on( 'slidebar_event', ocsOffCanvasSidebars.slidebarEventFixed );
38+
ocsOffCanvasSidebars.events.add_action( 'opening closing', 'ocs_fixed_scrolltop', ocsOffCanvasSidebars.slidebarEventFixed, 99 );
3939
}
4040
}
4141

@@ -74,9 +74,9 @@
7474
}
7575
curScrollTopElements.each( function() {
7676
var $this = $(this);
77-
if ( 'fixed' === $this.css('position') ) {
78-
var top = $this.css('top'),
79-
bottom = $this.css('bottom'),
77+
if ( 'fixed' === $this.css( 'position' ) ) {
78+
var top = $this.css( 'top' ),
79+
bottom = $this.css( 'bottom' ),
8080
px;
8181
if ( 'auto' === top && 'auto' !== bottom ) {
8282
px = ( scrollTop + winHeight ) - ( conOffset.top + conHeight ) + gblOffset.top;

js/fixed-scrolltop.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)