wordpress插件
WordPress’s popularity owes much to it’s easy administration panels. Unfortunately, it can still be daunting for non-technical users such as your clients. At best they’ll require a little training, hand-holding and support. At worst, they’ll play around with plugin installation, edit some theme code, then expect you to clear up the mess.
WordPress的普及很大程度上归功于它易于管理的面板。 不幸的是,对于非技术用户(例如您的客户)来说,这仍然可能令人生畏。 充其量,他们将需要一些培训,手持和支持。 最糟糕的是,他们会玩转插件安装,编辑一些主题代码,然后期望您清理混乱。
I’ve written a number of “Make WordPress Easier for Clients” articles (see part 1 and part 2). In those examples, code was placed in the theme’s functions.php file. That’s still a viable solution if you have one WordPress installation per client or each is configured differently.
我写了许多“使WordPress更容易为客户使用”的文章(请参阅第1 部分和第2部分 )。 在这些示例中,代码被放置在主题的functions.php文件中。 如果每个客户端安装一个WordPress,或者每个客户端的配置不同,那仍然是一个可行的解决方案。
In this article, however, we’ll create a plugin. Plugins have a couple of advantages:
但是,在本文中,我们将创建一个插件。 插件有两个优点:
Your code resides in one file which can make maintenance easier. 您的代码驻留在一个文件中,这可以简化维护。 If you’re running a WordPress network with multiple sites (previously known as WordPress MU), you can activate a single plugin across the network so it’s applied to every site. 如果您正在运行具有多个站点的WordPress网络(以前称为WordPress MU),则可以在网络上激活一个插件,以便将其应用于每个站点。Our plugin will be contained in a single PHP file. We’ll name it easy-admin.php and place it in the WordPress plugin folder (wp-content/plugins/). Ideally, the file should be UTF-8 encoded. If your text editor doesn’t permit UTF-8, well, use a better editor! That said, those using English are unlikely to experience issues with ANSI-encoded files.
我们的插件将包含在一个PHP文件中。 我们将其命名为easy-admin.php并将其放置在WordPress插件文件夹(wp-content / plugins /)中。 理想情况下,文件应为UTF-8编码。 如果您的文本编辑器不允许使用UTF-8,请使用更好的编辑器! 就是说,那些使用英语的人不太可能会遇到ANSI编码文件的问题。
A PHP tag and header comments are required at the top of the file, e.g.
文件顶部需要PHP标记和标头注释,例如
<?php /* Plugin Name: Easy Administration Plugin URI: https://www.sitepoint.com/wordpress-easy-administration-plugin-1 Description: Simplifies WordPress administration panels. Version: 1.0 Author: Craig Buckler Author URI: http://optimalworks.net/ License: GPL2 */You can change the header details, but ensure the definition tags remain — WordPress uses them to recognize your plugin.
您可以更改标题详细信息,但确保保留定义标签-WordPress使用它们来识别您的插件。
You can now install your plugin by activating it in the “Plugins” section of the WordPress administration panels. Those with a WordPress network can activate it for all sites in the “Network Admin” section. It won’t do anything yet, but you can now add whichever features you require…
现在,您可以通过在WordPress管理面板的“插件”部分中激活插件来安装插件。 拥有WordPress网络的用户可以在“网络管理员”部分的所有站点上激活它。 它不会做任何事情,但是您现在可以添加所需的任何功能…
The WordPress logo is lovely but few clients will care what CMS they’re using. It might be more helpful to show their site name. Append the following code to easy-admin.php; it replaces the login page logo with the name and uses a pleasing CSS3-letterpress text:
WordPress徽标很漂亮,但是很少有客户会关心他们使用的CMS。 显示其站点名称可能会更有用。 将以下代码附加到easy-admin.php; 它将登录页面徽标替换为名称,并使用令人愉悦CSS3-letterpress文本:
// login page logo function custom_login_logo() { echo '<style>h1 a, h1 a:hover, h1 a:focus { font-size: 1.4em; font-weight: normal; text-align: center; text-indent: 0; line-height: 1.1em; text-decoration: none; color: #dadada; text-shadow: 0 -1px 1px #666, 0 1px 1px #fff; background-image: none !important; }</style>'; } add_action('login_head', 'custom_login_logo');The WordPress icon is shown next to the site name in the header. There’s nothing wrong with it but some clients will question why there’s a ‘W’ next to their site. To remove it, append the following code to easy-admin.php:
WordPress图标显示在标题中站点名称旁边。 它没有任何问题,但是一些客户会质疑为什么他们的站点旁边有一个“ W”。 要删除它,请将以下代码附加到easy-admin.php:
// remove administration page header logo function remove_admin_logo() { echo '<style>img#header-logo { display: none; }</style>'; } add_action('admin_head', 'remove_admin_logo');The footer provides links to WordPress, documentation and feedback. Few clients are likely to find it useful so you can replace it with your own support details. Append the following code to easy-admin.php and change the echo statement to output to a suitable message:
页脚提供指向WordPress,文档和反馈的链接。 很少有客户会觉得它有用,因此您可以用自己的支持详细信息替换它。 将以下代码附加到easy-admin.php并更改echo语句以输出为合适的消息:
// change administration panel footer function change_footer_admin() { echo 'For support, please call 123456 or email <a href="mailto:support@mysite.net">mailto:support@mysite.net</a>'; } add_filter('admin_footer_text', 'change_footer_admin');The dark-gray Admin Bar was introduced in WordPress 3.1. Personally, I don’t find it particularly useful. It can also confuse clients; they may think all visitors can see the bar or use it to access dangerous features such as ‘Appearance’. Fortunately, we can remove it with one line in easy-admin.php:
深灰色管理栏是WordPress 3.1中引入的 。 就我个人而言,我认为它不是特别有用。 它还可能使客户感到困惑; 他们可能会认为所有访客都可以看到该栏,或使用它访问诸如“外观”之类的危险功能。 幸运的是,我们可以在easy-admin.php中用一行删除它:
// remove admin bar add_filter('show_admin_bar', '__return_false');That’s enough configuration for today. In my next WordPress post, we’ll add further functions to simplify the dashboard, post and page panels.
今天的配置已经足够。 在我的下一篇WordPress帖子中,我们将添加更多功能来简化仪表板,帖子和页面面板。
翻译自: https://www.sitepoint.com/wordpress-easy-administration-plugin-1/
wordpress插件