Measures for "has_cap is deprecated from version 2.0.0" warning in PHP debugging of WordPress

update Last updated: March 27, 2023 at 12:57 PM

I've been wondering about this for a while, but when running the WordPrees platform on this server in debug mode, the following warning message was logged.

[16-May-2020 11:21:32 UTC] PHP Deprecated: has_cap was called with deprecated arguments from version 2.0.0. User-level use is not recommended. Use permissions instead. in /.../wp-includes/functions.php on line 4997


After investigating the "Stack trace" following the above log, we found that there was a problem with some old plugins. Specifically, the third parameter of the WordPress APIs "add_menu_page()" and "add_options_page()", and the fourth parameter of "add_submenu_page()" are set with direct literals and the authority setting is It is considered deprecated in current WordPress.

These parameters ('$capability') are specifications that specify the authority group with a string, and the specification at the user level (0 to 10) of the old specification is deprecated in WordPress 3.0. ⇒ User types and permissions

At present, even if the above warning is left as it is, the system will work for the time being because upward compatibility is maintained. However, I cannot deny the possibility that WordPress will eventually stop working, so I decided to fix it while I had free time due to the self-restraint of Corona.

Therefore, using Grep of "Hidemaru editor" that runs on Windows shown in the featured image, search keywords "add_menu_page(" and "add_submenu_page" for the php program in the directory under "wp-content/", and I tried Grep search using "add_options_page(".
(You can ssh to the core server with Tera Term and use the Linux shell command "grep")

As a result, we discovered that there were three problems with the homepage builder plug-ins "hpbseo.php" and "hpbtools.php", and the Custom More Link Complete plug-in "custom-more-link-complete.php". , was corrected as follows.


Homepage Builder Plug-in Fixes

(1) hpbseo.php (class clsHpbSeo_AdminMenu)

	function add_pages() {
		//メニュー追加
		add_menu_page(
			"hpb SEO設定", 
			"hpb SEO設定", 
			8,
			__FILE__, 
			array($this, 'fncAdminMenu'),
			PLUGIN_IMG_URL . IMG_MENU,
			'3.1'	//表示位置(hpbダッシュボード=3)
		);
	}

	function add_pages_err() {
		//メニュー追加
		add_menu_page(
			"hpb SEO設定", 
			"hpb SEO設定", 
			8,
			__FILE__, 
			array($this, 'fncAdminMenuErr'),
			PLUGIN_IMG_URL . IMG_MENU,
			'3.1'	//表示位置(hpbダッシュボード=3)
		);
	}


Modify function add_menu_page() of class "clsHpbSeo_AdminMenu" described in hpbseo.php above as follows. In the listing below, it actually starts at line 733.
In the list above, the access rights are set to '8' (Normal), so you'll need to change this to admin rights.

	function add_pages() {
		//メニュー追加
		add_menu_page(
			"hpb SEO設定", 
			"hpb SEO設定", 
			'administrator',
			__FILE__, 
			array($this, 'fncAdminMenu'),
			PLUGIN_IMG_URL . IMG_MENU,
			'3.1'	//表示位置(hpbダッシュボード=3)
		);
	}

	function add_pages_err() {
		//メニュー追加
		add_menu_page(
			"hpb SEO設定", 
			"hpb SEO設定", 
			'administrator',
			__FILE__, 
			array($this, 'fncAdminMenuErr'),
			PLUGIN_IMG_URL . IMG_MENU,
			'3.1'	//表示位置(hpbダッシュボード=3)
		);
	}


(2) hpbtools.php
"hpbtools.php" is a plugin that manages the homepage builder dashboard. The following two lines are subject to correction. I currently have a contributor setting of 'level_1'.

function hpb_option() {
	$icon_url = HPB_PLUGIN_URL.'/image/admin/menu_hpb.png';	add_menu_page( 'HPBTOOL', 'hpbダッシュボード', 'level_1', 'hpb_main', 'hpb_admin_home', $icon_url, 3 );
	add_submenu_page( 'hpb_main', 'ホーム', 'ホーム', 'level_1', 'hpb_main', 'hpb_admin_home' );


Change the permissions to administrator as follows:

function hpb_option() {
	$icon_url = HPB_PLUGIN_URL.'/image/admin/menu_hpb.png';	add_menu_page( 'HPBTOOL', 'hpbダッシュボード', 'administrator', 'hpb_main', 'hpb_admin_home', $icon_url, 3 );
	add_submenu_page( 'hpb_main', 'ホーム', 'ホーム', 'administrator', 'hpb_main', 'hpb_admin_home' );


2020.09.20 Postscript
In addition to the WordPress incompatibility problem mentioned above, the dashboard plugin "hpb Dashboard" of the homepage builder has the incompatibility problem of "breadcrumb list" in Google search (data-vocabulary.org schema that Google has ended support used), social button SSL incompatibility, Facebook's "Like button" script incompatibility, and it has not been updated for 5 years.
We have already dealt with those issues, but for the sake of publicity, we have reported the above issues to the WordPress support forum on the hpb Dashboard linked below.

🔗 Impossible with the Latest Versions of WordPress and Google/Social Buttons


For your reference, in "hpbtools.php", the correction to the latest version of Facebook's old "Like button" is posted in the following article.



In addition to the above problems, we also found jQuery incompatibility problems with the website builder SEO plugin "hpb seo plugin for WordPress", so we contacted the developer as follows and have already dealt with it. increase.

🔗 Request for Recovery of Plugins (2 positions)


2023.03.29 Added
Regarding the WordPress function of the homepage builder, the details are summarized in the following article, including the background.


Custom More Link Complete Plug-in Fixes

The Custom More Link Complete plugin has access rights set to '9' (secondary administrator) as shown below. (Actually line 286 of “custom-more-link-complete.php”)

/*
 * Adds plugin options menu option to WordPress options
 */
function dl_custom_more_link_complete_add_option_menu(){
        add_options_page('Custom More Link Complete Options Page', 'Custom More Link Complete', 9, __FILE__, 'dl_custom_more_link_complete_options');
}


Change this to 'manage_options' which allows access to admin settings like this: For general plugins, it is better not to give large privileges like 'administrator'.

/*
 * Adds plugin options menu option to WordPress options
 */
function dl_custom_more_link_complete_add_option_menu(){
        add_options_page('Custom More Link Complete Options Page', 'Custom More Link Complete', 'manage_options', __FILE__, 'dl_custom_more_link_complete_options');
}


With the above work, the warning in the PHP debug mode of WordPress disappeared, and it was refreshing! 😀

2023.03.27 Added
The plugin "Custom More Link Complete" has not been updated for a long time and is no longer compatible with WordPress and PHP versions, so we have stopped using this plugin and deleted it.

Currently, as an alternative to this plugin, I am currently using the following plugin "Auto Limit Posts Reloaded" that displays the list of posted articles in excerpts and displays "Read more".

Add this entry to the hasebookmark
X (post)

Leave a Reply