• Resolved Jakes

    (@johanppmedia)


    Hi there,

    We are using the following function to block posts containing certain words, the post will then be set to draft until the user removes these words. This is working with wordpress default editor.

    When using WPUF front-end form, the form does not complete, it only spins but never shows these errors. Could you please indicate how we can allow this function on the front-end form?

    function jhnppdraft( $post_id, $post ) {
    
        $prohibited_words = explode( ',', 'blockedwords, testblock' );
        $found_words      = array();
        $content          = $post->post_content;
        foreach( $prohibited_words as $word ) {
        if( strpos( $content, $word ) !== false )
          $found_words[] = $word;
      }
        /** check if words are found */
        if ( $prohibited_words ) {
    
            /** set post status to draft */
            wp_update_post( array(
                'ID'          => $post_id,
                'post_status' => 'draft',
            ) );
            /** show error if words are used */
            wp_die(
        sprintf(
          __(
            'Your post has been set to draft since it contains the following words: ("%s"). Please remove them and try publishing again.',
            'jhnpp'
          ),
          implode( '", "', $found_words )
        )
      );
        }
    }
    
    add_action( 'publish_post', 'jhnppdraft', 10, 2 );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Custom post draft function not working with front end form’ is closed to new replies.