-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap-collapse-menu.php
137 lines (102 loc) · 4.06 KB
/
bootstrap-collapse-menu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/*
Plugin Name: Bootstrap Collapse Menu Widget
Plugin URI: https://github.com/ThemeAvenue/Bootstrap-Collapse-Menu
Description: Add a WordPress custom menu in any widget area to display it using the Bootstrap Collapse style.
Version: 1.0.0
Author: ThemeAvenue
Author URI: http://themeavenue.net
Author Email: [email protected]
Text Domain: bcmw
Domain Path: /lang/
Network: false
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Copyright 2013 ThemeAvenue ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Bootstrap_Collapse_Menu extends WP_Widget {
/*--------------------------------------------------*/
/* Constructor
/*--------------------------------------------------*/
/**
* Specifies the classname and description, instantiates the widget,
* loads localization files, and includes necessary stylesheets and JavaScript.
*/
public function __construct() {
// load plugin text domain
add_action( 'init', array( $this, 'widget_textdomain' ) );
parent::__construct(
'bootstrap-collapse-menu',
__( 'Bootstrap Collapse Menu Widget', 'bcmw' ),
array(
'classname' => 'Bootstrap_Collapse_Menu',
'description' => __( 'Add a WordPress custom menu in any widget area to display it using the Bootstrap Collapse style.', 'bcmw' )
)
);
require_once( plugin_dir_path( __FILE__ ) . '/bootstrap-collapse-nav-walker.php' );
} // end constructor
/*--------------------------------------------------*/
/* Widget API Functions
/*--------------------------------------------------*/
/**
* Outputs the content of the widget.
*
* @param array args The array of form elements
* @param array instance The current instance of the widget
*/
public function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
echo $before_widget;
echo $before_title . strip_tags( $instance['title'] ) . $after_title;
// TODO: Here is where you manipulate your widget's values based on their input fields
include( plugin_dir_path( __FILE__ ) . 'views/widget.php' );
echo $after_widget;
} // end widget
/**
* Processes the widget's options to be saved.
*
* @param array new_instance The new instance of values to be generated via the update.
* @param array old_instance The previous instance of values before the update.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['menu'] = strip_tags( $new_instance['menu'] );
return $instance;
} // end widget
/**
* Generates the administration form for the widget.
*
* @param array instance The array of keys and values for the widget.
*/
public function form( $instance ) {
// TODO: Define default values for your variables
$instance = wp_parse_args(
(array) $instance,
array( 'menu' => '', 'title' => '' )
);
// Display the admin form
include( plugin_dir_path(__FILE__) . 'views/admin.php' );
} // end form
/*--------------------------------------------------*/
/* Public Functions
/*--------------------------------------------------*/
/**
* Loads the Widget's text domain for localization and translation.
*/
public function widget_textdomain() {
// TODO be sure to change 'widget-name' to the name of *your* plugin
load_plugin_textdomain( 'bcmw', false, plugin_dir_path( __FILE__ ) . 'lang/' );
} // end widget_textdomain
} // end class
add_action( 'widgets_init', create_function( '', 'register_widget("Bootstrap_Collapse_Menu");' ) );