WordPress links car that mark as spam posts

Thus you bots not is annoyed by dn all spam, their goal always is to place a comment with one or more links on one website, have I written a short script, What in the function.php must be added. The script marked all comments as spam, containing a link.

add_action( 'comment_post', 'show_message_function', 10, 2 );
function show_message_function( $comment_ID, $comment_approved ) {
   $comment = get_comment( $comment_ID);
   if(!empty($comment)){
      $content = $comment->comment_content;
      if(!empty($content)){
         $content = strtolower($content);
         $hasLink = strpos($content, 'http') !== false || strpos($content, 'www.') !== false || strpos($content, 'href') !== false;
         if($hasLink){
            //when has link, set to spam
            $commentarr = array();
            $commentarr['comment_ID'] = $comment_ID;
            $commentarr['comment_approved'] = 'spam';
            wp_update_comment( $commentarr );
         }
      }

   }

}

WordPress test data for the development of a play

In the development of the theme, it is Very much convenient to have test data, as multiple of posts, in certain formats and special content, as e.g.. Therefore come videos.

There are two ways of test data in the system to import:

1. Import of a set records with the importer plugin, e.g..

https://wpcom-themes.svn.automattic.com/demo/theme-unit-test-data.xml

or

2. using a plugin to create a configurable amount of post, Users and comments, bpsw.: Show me data creator

 

WordPress article tags are not inserted

You can easily stumble across the problem, that the <p>-Tags (Paragrapgh tags) not automatically inserted in the blog.

To solve the problem, had you simply run the hook before, that is paragraph tags:

$content = get_the_content();

echo  apply_filters('the_content', $content);

This arose as a result, that the content had to be encoded according to iso. The feature would finally the_content() been the right choice, that this automatically done.

This is with me happened, When you use WordPress without a theme, but only as a content provider by means of:

define('WP_USE_THEMES', false);

WordPress integration in Yii project

If you want to intgrieren a WordPress blog in the Yii framework and wants to keep the layout of the page, allows WordPress, the WordPress API to use without having to create a theme.

The blog/news section should address: foo.com/news/ be available.

WordPress upload

WordPress can be installed as usual and should be in the folder hierarchy in the following directory on selbr level, How unpack the Yii project are:

yii-project
  assets
  protected
wordpress

She should be used as a database, as the Yii project and all Worpdress tables a prefix should get (by default “wp_” in the wp-config).

After you wp-config has adapted the, must still routing be adapted by Yii before installing by WordPress.

Yii create controller more…

WordPress Posts mit Custom Field finden

Mit einem einfach Query lassen sich Posts mit einem bestimmten custom-field suchen und ausgeben. Die Posts werden zusätzlich nach dem Erscheinungsdatum sortiert.

$my_custom_field = 'my_cool_custom_field';

$queryCustomField = new WP_Query(
    array (
        'meta_key' => $my_custom_field,
        'orderby' => 'date',
        'order' => 'DESC',
        'posts_per_page' => 5,
        'post_status' => array( 'publish')
    )
);

while ($queryCustomField->have_posts()) :;
    $queryCustomField->the_post();
    $my_custom_field = get_post_meta($post->ID, $my_custom_field, true);
endwhile;

wp_reset_postdata();

WordPress: Categories identify with most articles within x days

In order to realize such a query, It takes a little MySQL in conjunction with WordPress. With the functiongetCategoriesWithMostArticlesInLastDays() can you determine the most popular X categories within the last Y days:

function getCategoriesWithMostArticlesInLastDays($categoriesCount, $lastDaysCount)
{
    global $wpdb;
    $querystr = "
    SELECT $wpdb->terms.name AS categoryName,COUNT($wpdb->terms.term_id) AS countCategory, $wpdb->terms.term_id as categoryId
    FROM $wpdb->posts
        LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
        LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
        LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
    WHERE
        $wpdb->posts.post_status = 'publish'
        AND $wpdb->posts.post_type = 'post'
        AND $wpdb->posts.post_date > TIMESTAMP(DATE_SUB(NOW(), INTERVAL $lastDaysCount DAY ))
        AND $wpdb->term_taxonomy.taxonomy = 'category'
    GROUP BY $wpdb->terms.term_id
    ORDER BY COUNT($wpdb->terms.term_id) DESC
    LIMIT $categoriesCount
";
    $categoriesWithMostArticlesInLastDays = $wpdb->get_results($querystr, ARRAY_A);
    foreach($categoriesWithMostArticlesInLastDays as  $key => $category)
    {
        $categoriesWithMostArticlesInLastDays[$key]["link"] = get_category_link($category['categoryId']);
    }
    return $categoriesWithMostArticlesInLastDays;
}