Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter mannski

    (@mannski)

    Thanks, darrinb. Using add_meta_boxes worked for me. Here’s the working code:

    function superadmin_restrict_pages() {
    	global $post;
    	$protected_value_status = get_post_meta( $post->ID, 'protected_value', true );
    	if (!current_user_can('manage_network') && $protected_value_status == 'Protected' ) {
    		wp_die( sprintf( __( 'You do not have permission to access this area.' ) ) . sprintf( '<br /><a href="javascript:history.go(-1);">Go back</a>' ));
    	}
    }
    add_action('add_meta_boxes' , 'superadmin_restrict_pages');

    I also wanted to remove “Quick Edit” and the other options from the all-pages screen (edit.php). Here’s what worked for me. It removes the “Edit”, “Quick Edit”, and “Trash” options from any page that has the designated custom field.

    function superadmin_remove_quick_edit_options($actions, $post) {
    	global $post;
    	$protected_value_status = get_post_meta( $post->ID, 'protected_value', true );
    	if (!current_user_can('manage_network') && $protected_value_status == 'Protected' ) {
        		unset($actions['inline hide-if-no-js'],$actions['trash'], $actions['edit']);
        		return $actions;
        	}
        	else {
        		return $actions;
        	}
    }
    add_filter('post_row_actions', 'superadmin_remove_quick_edit_options', 10, 2);
    add_filter('page_row_actions', 'superadmin_remove_quick_edit_options', 10, 2);
    Thread Starter mannski

    (@mannski)

    I fixed the issue. I’m not sure why this was causing a problem, but I had two dependences in my “if” statement:

    if (!current_user_can('manage_network') && other_function()) {

    When I removed the second dependency (so that it was the same as my first post), it worked fine.

    Thread Starter mannski

    (@mannski)

    I don’t use a functionality plugin, but I looked at the code closely to make sure it all looked correct. I tried adding it to my site in two different ways: first, to a plugin I created to manage user permissions; when that didn’t work, I removed it and pasted it in my theme’s functions.php file. Same result.

    I was able to get this working by putting the “if” statement within another larger function whose purpose was to remove several pages from the admin menu.

    Looks like the important thing is to use admin_init hook. I had been using admin_menu to remove items from the admin menu, but that doesn’t seem to work on Jetpack.

    Thread Starter mannski

    (@mannski)

    Thanks, Jeremy. I’m not sure why, but your solution is not working for me either. In fact, it’s making the entire admin area of the site go white, like it’s causing a PHP error.

    Thread Starter mannski

    (@mannski)

    Worked like a charm. Thanks! I will likely purchase the plugin but wanted to test the Lite version to make sure it worked well for our purposes.

    Thread Starter mannski

    (@mannski)

    Thanks. I don’t think it was a cache issue. Once I changed the image Title, the URL no longer went to that image, and that happened immediately. As I said, I totally understand why the url was going to that media post, but what I want to find is a way to trump them if I create a page and happen to put it at the same URL.

    Thread Starter mannski

    (@mannski)

    bythegram – Sorry, as I just noted, changing the image title fixed the URL issue. I tried changing the image title back to the original, but it’s no longer going to the image.

    Here’s some more information that may be helpful: the image was uploaded to the /faculty/ page, so the original post URL for it was /faculty/einstein/ , and the bio page URL was originally /albert-einstein/ (created by default). Then the parent page was set to “Faculty” so the URL changed to /faculty/albert-einstein/ and then the URL was manually changed to leave out the “albert” portion, so it became /faculty/einstein/ .

    So, it makes sense that /faculty/einstein was showing the picture because that was the first post at that URL. But the problem is media being able to trump URLs that are being used for pages (even if those pages are created later).

    Thread Starter mannski

    (@mannski)

    Update: I did find out that changing the picture’s Title to anything besides “einstein” allowed the bio page to show at the /faculty/einstein/ URL. But that’s not much better than renaming the image file and uploading it again, or changing the bio page URL. It’s a solution, but not the right kind of solution.

Viewing 8 replies - 1 through 8 (of 8 total)