forked from ethymos/delibera
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdelibera_widgets.php
86 lines (80 loc) · 2.42 KB
/
delibera_widgets.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
<?php
/**
* Código responsável por habilitar carregamento das widgets
*/
/**
* Inclui no menu lateral do wp admin menu para plugin
*
* @package Widget
* @subpackage Admin
*/
function delibera_widgets_add_meta_box()
{
add_meta_box( 'delibera_widgets-meta-box', __('Delibera'), 'delibera_widgets_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
}
add_action( 'admin_init', 'delibera_widgets_add_meta_box' );
/**
* Carrega scripts necessários para inclusão de item do menu
*
* @package Widget
* @subpackage Admin
*/
function delibera_widgets_admin_script()
{
if(substr($_SERVER['REQUEST_URI'], -(strlen('nav-menus.php'))) == 'nav-menus.php')
{
wp_enqueue_script('delibera_widgets_admin_script_nav_menus',plugin_dir_url(__FILE__).'/js/delibera_nav_menu.js', array('jquery'));
}
}
add_action( 'admin_print_scripts', 'delibera_widgets_admin_script' );
/**
* Apresenta widget na interface do wordpress
*
* @package Widget
* @subpackage Admin
*/
function delibera_widgets_nav_menu_item_link_meta_box()
{
?>
<script type="text/javascript">
<!--
function delibera_addMenuItemToBottom()
{
//var processMethod = wpNavMenu.addMenuItemToBottom;
var processMethod = delibera_addMenuItemToBottom_processMethod;
var callback = function(){
};
var url = "<?php echo get_post_type_archive_link('pauta') ?>";
var label = "Delibera";
wpNavMenu.addItemToMenu({
'-1': {
'menu-item-type': 'custom',
'menu-item-url': url,
'menu-item-title': label,
'menu-item-classes': 'delibera-menu-item'
}
}, processMethod, callback);
}
//-->
</script>
<div class="custom-meta-box" id="custom-meta-box">
<p><?php _e('Clique no botão abaixo para adicionar um link para a página que lista as pautas no menu.')?></p>
<button class="button-secondary submit-add-to-menu" onclick="delibera_addMenuItemToBottom();"><?php _e('Adicionar')?></button>
</div>
<?php
}
/**
* Inicializa dinamicamente as widgets disponiveis
* @package Widget
* @subpackage Admin
*/
add_action( 'widgets_init', function()
{
$widgets = array('WidgetListaPropostas');
foreach ($widgets as $widgetName)
{
require_once dirname(__FILE__).'/widgets/'.$widgetName.'/'.$widgetName.'.php';
register_widget( $widgetName );
}
});
?>