Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QTS: replace slugs metabox only if existing #1209

Merged
merged 2 commits into from
Aug 7, 2022

Conversation

spleen1981
Copy link
Contributor

fixes #1207

remove_meta_box( 'slugdiv', null, 'normal' );
add_meta_box( 'qts_sectionid', __( 'Slugs per language', 'qtranslate' ), 'qtranxf_slugs_draw_meta_box', null, 'side', 'high' );
//Replace slugs metabox only if existing and not already removed
if ( ! empty($wp_meta_boxes[ get_current_screen()->id ][ 'normal' ][ 'core' ][ 'slugdiv' ] ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't test at this moment. Is this robust enough if one key is missing? I'm afraid empty will raise an exception if one key is missing - unlike unset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on php.net,

empty() is essentially the concise equivalent to !isset($var) || $var == false

which is what we need here, because that key may not be existing or may be false if already removed, so we should be covered.

@herrvigg herrvigg merged commit 784556f into master Aug 7, 2022
@herrvigg herrvigg deleted the slugs_fix_unneeded_metabox branch September 4, 2022 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP error and irrelevant Slugs metabox in custom admin pages
2 participants