我正在用许多小部件构建一个网站。它们是高度定制的。
当站点处于活动状态时,几个管理员/编辑器必须编辑这些小部件。
现在,我很害怕看到一个小部件(及其配置)可以在一次鼠标移动中完全擦除(将其从侧栏中删除)。
有没有什么方法可以防止小部件被删除,同时保持编辑其内容的能力?
此外,在我看来,管理中的widget管理页面为“添加widget”模块提供了太多的空间,而为“激活的widget”模块提供的空间不足。这在创建站点时很有用,但在完成站点时却毫无用处。有没有办法切换这些模块的大小?
非常感谢
我正在用许多小部件构建一个网站。它们是高度定制的。
当站点处于活动状态时,几个管理员/编辑器必须编辑这些小部件。
现在,我很害怕看到一个小部件(及其配置)可以在一次鼠标移动中完全擦除(将其从侧栏中删除)。
有没有什么方法可以防止小部件被删除,同时保持编辑其内容的能力?
此外,在我看来,管理中的widget管理页面为“添加widget”模块提供了太多的空间,而为“激活的widget”模块提供的空间不足。这在创建站点时很有用,但在完成站点时却毫无用处。有没有办法切换这些模块的大小?
非常感谢
我能想到的解决方案是删除可用的面板和不活动的小部件,这样就没有地方可以拖动(和删除)侧栏中使用的小部件。
你可以注入其他东西来填补这个空白。
在本例中,只有一个用户能够添加/删除小部件。
function wpse_53398_script_printer(){
// used to display the front end site
$site = get_site_url();
// here you can filter who can add/delete widgets
global $current_user;
if ( \'kursus\' == $current_user->data->user_login )
{
echo <<<HTML
<!-- CSS to hide the widgets descriptions = real estate gains -->
<style type="text/css">#widget-list .widget-description {display:none;}</style>
<script type="text/javascript">
jQuery(document).ready( function($) {
// swaps the placement of the panels Available Widgets and Incactive Widgets
$(\'#available-widgets\').appendTo(\'#widgets-left\');
});
</script>
HTML;
}
else
{
echo <<<HTML
<!-- CSS to prevent the div from briefly appearing before the jQuery can act -->
<style type="text/css">#widgets-left {display:none;}</style>
<script type="text/javascript">
// reload the contents of the iframe
function Reload () {
var f = document.getElementById(\'the-front-end\');
f.src = f.src;
}
jQuery(document).ready( function($) {
// inject other content to fill the void
$(\'<div style="width:70%;"><input type="button" value="Reload front page" onclick="Reload();" style="float:right"><br /><iframe id="the-front-end" src="{$site}" frameborder="0" width="100%" height="700"></div>\').insertBefore(\'#widgets-left\');
// removes the whole left side of the widgets page
$(\'#widgets-left\').remove();
});
</script>
HTML;
}
}
add_action(\'admin_footer-widgets.php\', \'wpse_53398_script_printer\');
重要提示:HTML;
关闭行cannot 在前后有任何空格字符PS:这个Heredoc syntax <<<HTML code HTML;
阻止代码在WPSE中显示正确格式化的PHP。但代码已经过测试,并且可以正常工作
删除小部件的问题更为普遍,它是由开发人员和编辑器使用相同的后端界面引起的。类似的问题,如删除小部件-插入错误大小的图像-添加设计师不想要的字体-创建超出允许范围的菜单项。。还有更多
解决方案很简单,为编辑器提供自己的界面。最好的方法可能是:让这个界面看起来像网站本身。这种方法就是我所说的“前端CMS”
这个frontend editor 插件是一个免费的插件,可以用于此。我自己写了一个插件,将这一理念更进一步,frontendcms.com. 然而,它不是免费的。
下面有一个函数,用admin_init 行动function my_flush_rewrites() { global $wp_rewrite; $wp_rewrite->flush_rules(); } 像这样add_action(\'admin_init\', \'my_flush_rewrites\'); 我很好奇,这叫什么时候?是否在每次页面加载时都调用此函数?希望不会