Home> CMS Tutorial> WordPress> body text

Fifty Actions for WordPress - Demo 50 Examples (from 41 to 50)

WBOY
Release: 2023-09-03 17:25:07
Original
1327 people have browsed it

WordPress 的五十个动作 - 演示 50 个示例(从 41 到 50)

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!

Injected into the plug-in management page

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.

Add styles to your plugin management page

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) ?>
Copy after login

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!

Process it before processing the Ping

"Ping" is one of the oldest features of WordPress, and thepre_pingaction allows us to process a ping before it is processed.

Disable self-ping

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/ ?>
Copy after login

From now on, your WordPress installation will not ping its own posts.

Useget_header()function

When the template calls theget_header()function, theget_headeroperation is called, which is a function that is very suitable for modifying the WordPress front-end header.

Activate simple maintenance mode

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:

Copy after login

Since only administrators (and super administrators) have the'activate_plugins'ability, the site will be closed to everyone except administrators.

Tampering with the login page

The

login_headaction helps us control thetag on the login page.

Eliminate the shaking effect of incorrect credentials

If you don't like the "shaking" effect that occurs when users submit incorrect login information, you can remove it using the following function:

Copy after login

But I like this effect.

Using the Dashboard Footer

Sometimes, we may want to control the footer of the admin panel - not the footer section itself, but the section before thetag.admin_footerdoes exactly that.

Add quick styles for post status

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/ ?>
Copy after login

Queue scripts and styles in login page

We can usewp_enqueue_scriptsto queue content to the front end, or we can useadmin_enqueue_scriptsto queue content to the backend. What about the login page? You guessed it:login_enqueue_scriptsis our hook this time!

Change the logo above the login form

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/ ?>
Copy after login

Put thelogin-logo.pngfile into the theme’s/images/folder, and you’re good to go!

Add custom columns to user list

Do you know the user list in the "All Users" page of the admin panel? Themanage_users_custom_columnaction allows us to add a new custom column to this list with the help of the accompanying filter.

Show the user's registration date in one column

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/ ?>
Copy after login

Now you know more about your members.

Activate using plugin

What do you do when you need to check if a plugin is activated in WordPress? Well, you use theactivated_pluginhook: this handy little action is triggered when the plugin is activated.

每次激活插件时向管理员发送电子邮件

假设您有很多客户网站(使用您的电子邮件地址安装),并且当客户在其网站上安装并激活新插件时,您需要收到通知。

只需使用此函数并将其挂接到activated_plugins即可:

Copy after login

处理配色方案选项

自 WordPress 3.0 起,我们的管理面板有了“配色方案”,并且我们可以编辑、添加或删除配色方案。admin_color_scheme_picker操作使用户可以更改颜色方案。

删除更改配色方案的选项

这个例子不需要太多介绍:如果您需要剥夺用户更改配色方案的权利(例如,因为您有一个特殊的配色方案并且您不希望用户将其更改回来)为默认值),使用下面的代码片段删除该选项:

Copy after login

嘿,我们刚刚从同名的动作挂钩中删除了一个函数。我知道,这很奇怪。

处理注销过程

用户登录、用户注销,当他们注销时,将调用wp_logout操作。

注销后将用户重定向到主页

从 WordPress 网站注销有点奇怪:您会被重定向到登录页面,就像 WordPress 需要您再次登录一样。以下是解决该问题并将用户注销时重定向到主页的方法:

Copy after login

现在,每次用户注销时,他们都会看到主页而不是登录表单。

第五部分结束

我们刚刚完成了本文中的最后一批 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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!