Anti-Splog Plugin & Custom Post Types

Hi, We use the anti-splog plugin at PressBooks.Com. It's a decent plugin but it could be improved.

Looking at the anti-splog source code we see:

//latest post
$post = $wpdb->get_row("SELECT post_title, post_content FROM {$wpdb->base_prefix}{$blog_id}_posts WHERE post_status = 'publish' AND post_type = 'post' AND ID != '1' ORDER BY post_date DESC LIMIT 1");

if ($post)
  $api_data['post_content'] = $post->post_title . "\n" . $post->post_content;

//send blog info to API
ust_http_post('spam_blog', $api_data);

Specifically, I have a problem with:

post_type = 'post'

On PressBooks.Com our post_type(s) will be: 'front-matter', 'part', 'chapter' or 'back-matter'.

Our post_type will never be 'post' (and rarely 'page' as seen elsewhere in the code.)

So, as it stands we aren't sending anything useful your premium server and in return aren't getting much of anything back either.

As we are paying a yearly subscription for a spam-analysis API key, it would be great if the query took custom post_types into consideration.

Sourcecode for the PressBooks plugin, here.

Thank you for your consideration.

  • hughmcguire
    • WPMU DEV Initiate

    Hi Aaron, thanks for the reply.

    I'd be ok with something like:

    $GLOBALS['some_config_variable'] = array( 'front-matter', 'part', 'chapter', 'back-matter');
    
    // ...
    
    // Default
    $types = "post_type = 'post'";
    
    if (isset($GLOBALS['some_config_variable']) && is_array($GLOBALS['some_config_variable'])) {
        $types = '(';
    	foreach($GLOBALS['some_config_variable'] as $type) {
    		$types .= "post_type = '$type' OR ";	// TODO: Sanitize $type
    	}
    	$types = substr($types, 0, -3); // Remove last OR
    	$types .= ')';
    } 
    
    $sql = "SELECT post_title, post_content FROM {$wpdb->base_prefix}{$blog_id}_posts WHERE post_status = 'publish' AND $types AND ID != '1' ORDER BY post_date DESC LIMIT 1"
    $post = $wpdb->get_row( $sql );
    // ...

    Or

    $GLOBALS['some_config_variable'] = ' __I_WRITE_MY_OWN_WHERE_CLAUSE__ ';
    //...
    
    $sql = "SELECT post_title, post_content FROM {$wpdb->base_prefix}{$blog_id}_posts WHERE ($GLOBALS['some_config_variable']} AND ID != '1' ORDER BY post_date DESC LIMIT 1"

    It would be an advanced feature? Just brainstorming, I leave it up to you.

    Cheers.

  • hughmcguire
    • WPMU DEV Initiate

    Hi Aaron

    > Note that bots are only designed for default WP post types, hence the hardcoded limitation.

    Sure, but for us the "bots" (possibly humans) log into PressBooks and fill out our forms, which will create custom post types that we use to create web books.

    PressBooks makes significant changes to:

    * admin interface (customized for books and other structured documents, such as magazines, journals, reports etc.)
    * web presentation layer (again, customized for books and structured documents);

    So our issue is that there is a spam analysis portion that never gets run because no "posts" exist, but junk content is still published.

    Hope this makes sense.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.