Lock Posts Plugin - Custom Function?

Hello,

So I love the concept behind the Lock Posts plugin. So I am wondering if there would be a way (or if there is a function from the plugin that can be hooked in to) to check if a custom field in the database has a certain value, and if it does then the post would be locked.

I am using Advanced Custom Fields, and was thinking maybe I could put together some form of a php if statement that would see if a specific text field has a value to it and if so lock that post.

Any advice would be appreciated, thanks!

  • Vaughan

    Hi Danny,

    Hope you're well?

    I've just looked through the code (it's only 1 file)

    Unfortunately there are no hooks at all in the plugin to hook into, so you would need to modify the plugin code directly.

    It basicly adds an action in the save_post action. which calls the function update() when a post is saved depending on the option selected in the meta box.

    So you could probably add your code into the update() function itself.

    /**
    	 * Update post status
    	 *
    	 */
    	function update( $post_id ) {
    		if ( !empty( $_POST['post_lock_status'] ) && is_super_admin() )
    			update_post_meta( $post_id, '_post_lock_status', $_POST['post_lock_status'] );
    	}

    so do something like this;

    /**
    	 * Update post status
    	 *
    	 */
    	function update( $post_id ) {
            if($_POST['advanced_custom_field'] == 'whatever') {
                $_POST['post_lock_status'] = 'locked';
            }
    		if ( !empty( $_POST['post_lock_status'] ) && is_super_admin() )
    			update_post_meta( $post_id, '_post_lock_status', $_POST['post_lock_status'] );
    	}

    I don't know how advanced custom fields works, but I presume, it submits the data as $_POST along with the rest? in which case you just need to see check the $_POST to find out which value it is.

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.