Skip to:
Content
Pages
Categories
Search
Top
Bottom

About replying custom field security


  • mariririn
    Participant

    @mariririn

    I want to check if the custom field at reply is “AllowedURL”.

    If applicable to “AllowURL”, I would like to have the custom field value go into the database, but can you tell me the correct way to write the following code?

    add_action( 'bbp_new_reply', 'bbp_save_reply_extra_fields', 10, 1 );
    add_action( 'bbp_edit_reply', 'bbp_save_reply_extra_fields', 10, 1 );
    
    function bbp_save_reply_extra_fields( $reply_id ) { 
    	
    	$input_url = $_POST['input_url'];
    	
    	$AllowURL = [
    		'^http?://example.com/[^/]{10}$',
    		'^http?://example.net/[^/]{20}$' 
    	];
    	
    	foreach ( $AllowURL as $AU ){
    		if( @preg_match( '|'.$AU.'|', $input_url ) ) {
    			if ( isset($_POST) && $_POST['input_url']!='' ) {
    				update_post_meta( $reply_id, 'input_url', $_POST['input_url'] );
    			}
    		}
    	}
    	
    }

    I look forward to your response.

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

  • Robin W
    Moderator

    @robin-w

    so what is the code doing/not doing that you want it to ?

    I presume you have $_POST[‘input_url’] set in either the reply post template or a function ?


    mariririn
    Participant

    @mariririn

    Yes, this code does not check URLs. And I write it in “functions.php”.


    Robin W
    Moderator

    @robin-w

    can you post the code that creates the field in the reply form please

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar