0

I am trying to remove the option to edit the Permalink.

I know how to hide it with CSS and I have. But a hacker could simply just go to Inspect Element and change display: none; to display: block; and then be able to modify the Permalink.

So is there a way to block that option? Or can I check if the user submits to verify that the permalink was not modify?

  • Are you using a multisite and want to disable permalink settings for site admins? – birgire Jul 30 '14 at 20:43
  • 1
    I guess you are talking about the post slug, right? – tfrommen Jul 30 '14 at 21:05
  • I had to also stop a user from editing the title and I was able to make it work... But I don't know how to do it for the slug. – jnbdz Jul 31 '14 at 15:01
  • You're right... I am talking about slug. My bad. – jnbdz Jul 31 '14 at 15:05
0

Should be as simple as this:

add_filter('pre_update_option_permalink_structure', 'my_chgcb');
function my_chgcb($newval, $oldval) {
    return $oldval;
}

This disables any changes to the permalink setting. You can additionally hide it using CSS.

  • My bad I want to protect against the Slug editor after the title input. I don't want certain users to be able to edit the slug for an article. I already use CSS. But I want to make sure they can change it. – jnbdz Jul 31 '14 at 15:37
0

Option 1

Setting your Permalink structure is actually writing the chosen rules to your .HTACCESS file, so once you have your desired permalink structure set, change permissions for your .HTACCESS file back to 644 so that the file is no longer writable. This will prevent any changes being made to the file even if new settings are updated via your dashboard.

Option 2

You could "hard code" your permalink structure in your functions.php file so the function always overrides/replaces any changes made via the dashboard.

This way, even if someone managed to reveal this section via CSS and tried to update the permalink structure it wouldn't work because your function would overwrite that update every time your site runs.

You can find the values you can pass to this option here. WordPress Codex Permalink Options

Just update the line SET option_value = '$your-permalink-structure-goes-here' as below (currently set to Month and name) to your desired permalink structure and you are good to go.

function royal_set_permalinks() {  
global $wpdb;    
// Set Permalink Structure
$wpdb->query("UPDATE " . $wpdb->prefix . "options SET option_value = '/%year%/%monthnum%/%postname%/' WHERE option_name = 'permalink_structure'");  
}
add_action('init','royal_set_permalinks');

Hope that helps you out :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.