If you’ve been following our series, you know that we’re in the final stretch of looking at 50 Actions for WordPress. For those of you just joining us, I highly recommend checking out the previous article (as this article continues where we left off) as well as the articles linked to each of the previous articles.
This will give you an idea of where we are now.
let us start!
Plugins also have requirements: they may require in-page scripts or styles for their own options pages. Content can be injected into thetag of a specific plugin page using the admin_head-(plugin_page)
action.
If you need to add some CSS styling to the plugin’s options page, the following code will help you:
' . '/* your style here */' . ''; } // Example Source: https://codex.wordpress.org/Plugin_API/Action_Reference/admin_head-(plugin_page) ?>
Change the commented out line with your CSS code, replace the second part of the action name with your own plugin (tools_page_myplugin/myplugin
), and you're good to go!
"Ping" is one of the oldest features of WordPress, and thepre_ping
action allows us to process a ping before it is processed.
WordPress does not differentiate between internal and external links when it comes to pinging. To disable self-pinging, you can use this handy little code snippet:
$link ) { if ( 0 === strpos( $link, get_home_url() ) ) { unset( $links[ $l ] ); } } } // Example Source: http://wpdevsnippets.com/remove-slef-pings/ ?>
From now on, your WordPress installation will not ping its own posts.
get_header()
functionWhen the template calls theget_header()
function, theget_header
operation is called, which is a function that is very suitable for modifying the WordPress front-end header.
If you are in a hurry and don't have time to install the "Maintenance Mode" plugin and set its options, you can simply use the code below and issuewp_die()
to everyone except the administrator mistake:
Since only administrators (and super administrators) have the'activate_plugins'
ability, the site will be closed to everyone except administrators.
login_head
action helps us control thetag on the login page.
If you don't like the "shaking" effect that occurs when users submit incorrect login information, you can remove it using the following function:
But I like this effect.
Sometimes, we may want to control the footer of the admin panel - not the footer section itself, but the section before thetag.
admin_footer
does exactly that.
Having a consistent set of colors is one of the things that makes a WordPress admin panel beautiful, but I don’t think there’s any harm in some color coding for content that needs to be visually separated (such as different post statuses).
If you are like me and want to be able to distinguish published posts from drafts or other post statuses, use the following code:
.status-draft { background-color: #FCE3F2; } .status-pending { background-color: #87C5D6; } .status-future { background-color: #C6EBF5; } .status-private { background-color: #F2D46F; } '; } // Example Source: http://wpsnipp.com/index.php/functions-php/change-admin-postpage-color-by-status-draft-pending-published-future-private/ ?>
We can usewp_enqueue_scripts
to queue content to the front end, or we can useadmin_enqueue_scripts
to queue content to the backend. What about the login page? You guessed it:login_enqueue_scripts
is our hook this time!
I love the WordPress logo, but I don’t think it should be displayed every time a user logs into my site. If you're thinking the same thing, you can replace the WordPress logo with your own using this helpful snippet:
' . '#login h1 a {' . 'background-image: url(' . get_bloginfo( 'template_directory' ) . '/images/login-logo.png);' . 'padding-bottom: 30px;' . '}' . ''; } // Example Source: http://wpsnippy.com/add-custom-login-logo-in-your-wordpress-blog/ ?>
Put thelogin-logo.png
file into the theme’s/images/
folder, and you’re good to go!
Do you know the user list in the "All Users" page of the admin panel? Themanage_users_custom_column
action allows us to add a new custom column to this list with the help of the accompanying filter.
Suppose you need to check the registration dates of members in batches. You can check the database record each time you need that information, or you can use this code snippet to add extra columns to the user list:
user_registered; } } // Example Source (Idea): http://tommcfarlin.com/add-custom-user-meta-during-registration/ ?>
Now you know more about your members.
What do you do when you need to check if a plugin is activated in WordPress? Well, you use theactivated_plugin
hook: this handy little action is triggered when the plugin is activated.
假设您有很多客户网站(使用您的电子邮件地址安装),并且当客户在其网站上安装并激活新插件时,您需要收到通知。
只需使用此函数并将其挂接到activated_plugins
即可:
自 WordPress 3.0 起,我们的管理面板有了“配色方案”,并且我们可以编辑、添加或删除配色方案。admin_color_scheme_picker
操作使用户可以更改颜色方案。
这个例子不需要太多介绍:如果您需要剥夺用户更改配色方案的权利(例如,因为您有一个特殊的配色方案并且您不希望用户将其更改回来)为默认值),使用下面的代码片段删除该选项:
嘿,我们刚刚从同名的动作挂钩中删除了一个函数。我知道,这很奇怪。
用户登录、用户注销,当他们注销时,将调用wp_logout
操作。
从 WordPress 网站注销有点奇怪:您会被重定向到登录页面,就像 WordPress 需要您再次登录一样。以下是解决该问题并将用户注销时重定向到主页的方法:
现在,每次用户注销时,他们都会看到主页而不是登录表单。
我们刚刚完成了本文中的最后一批 50 个操作。我希望你喜欢它并从中学到新东西。在下一篇文章中,我们将快速浏览一下我们所看到的内容并结束该系列。
我也想听听你的想法。您对这些行动有何看法?在下面发表您的评论。如果您喜欢这篇文章,别忘了分享!
The above is the detailed content of Fifty Actions for WordPress - Demo 50 Examples (from 41 to 50). For more information, please follow other related articles on the PHP Chinese website!