Tag: WordPress functions

  • For WordPress users, checking existing comments for spam

    For WordPress users, checking existing comments for spam

    CleanTalk offers more protection from spam bots to sites by WordPress. The new version provides a unique opportunity to test existing spam comments.

    CleanTalk adds new features in CleanTalk Anti-Spam, our solutions are reliable, easy and efficient. Work of the module is absolutely invisible for visitors and allows to renounce forever the ways of protection complicating communication on the website (CAPTCHA, question and answer, etc.). CleanTalk allows you to automate protection from spam and registering of spam bots.

    Cloud anti-spam service CleanTalk released a new version of the anti-spam plugin for WordPress, the new version has a unique function of automatic check for spam of the existing comments on the site.

    This allows administrators of the Web sites automatically check and identify spam bots comments, which were not detected by conventional anti-spam tools.

    This function is present only for WordPress, it will gradually be introduced for other CMS.

    CleanTalk identifies spam bots, using its own algorithms to estimate the parameters visitor, on the basis of these tests is formed its own database of spam bots. Checking existing comments is made on the basis of the nearly 2 million of certain spam bots. Detailed statistic allows CleanTalk customers to control the whole process.

    “The team CleanTalk has been developing a cloud spam protection system for four years and has created a truly reliable anti-spam service designed for you to guarantee your safety”.

    Download the new version anti spam by CleanTalk for WordPress

  • Little-known functions in WordPress

    CleanTalk is a SaaS spam protection service for Web-sites. CleanTalk uses protection methods which are invisible for site visitors. Connecting to the service eliminates needs for CAPTCHA, questions and answers and other methods of protection, complicating the exchange of information on the site.

    Has it ever happened that during parsing code-party plugin or theme you found quite useful standard function, which did not know before? At such moments, any developer feels a sense of worthlessness, remembering he reinvented the wheel in previous projects.

    In order to reduce the amount of frustration, I decided to describe a few little-known but very useful features:

    make_clickable
    Find in the text links and make them clickable.
    Example:

    $string = "This is a long text that contains some links like https://www.wordpress.org and https://www.wordpress.com .";
    echo make_clickable( $string ); 
    

    popuplinks
    Adds  target='_ blank' rel='external' to all the links in the text.
    Example:

    $string = "This is a long text that contains some links like <a href='https://www.wordpress.org'>https://www.wordpress.org</a> and <a href='https://www.wordpress.com'>https://www.wordpress.com</a> .";
    echo popuplinks( $string ); 
    

    wp_list_pluck
    Takes out certain fields from the collection.
    Example:

    $posts = get_posts();
    $ids = wp_list_pluck( $posts, 'ID' ); // [1, 2, 3, ...]
    

    antispambot
    Converts email addresses to symbols HTML for protection from spambots.
    Example:

    $email = 'ex*****@em***.com';
    echo '<a href="mailto:' . antispambot( $email ) . '">' . antispambot( $email ) . '</a>';
    

    checked / selected
    Adds an attribute checked (selected) if the first argument is equal to the second.
    Example:

    <input type="checkbox" name="remember" value="1" <?php checked( $remember ) ?> />
    <select name="options">
        <option value="1" <?php selected( $options, 1 ); ?>>1</option>
        <option value="2" <?php selected( $options, 2 ); ?>>2</option>
        <option value="3" <?php selected( $options, 3 ); ?>>3</option>
    </select>
    

    human_time_diff
    Represents the difference in time in human-readable form.
    Example:

    $published = get_the_time( 'U' );
    echo human_time_diff( $published ); // 2 days
    

    wp_send_json_success / wp_send_json_error
    Displays data in a JSON format for Ajax requests.
    Example:

    if( $success ) {
        $result = array(
            'message'	=> 'Saved',
            'ID'		=> 1
        );
        wp_send_json_success( $result ); // { "success": true, "data": { "message": "Saved", "ID": 1 } }
    }
    else {
        wp_send_json_error(); // { "success": false }
    }
    

    wp_remote_get / wp_remote_post
    Receives data from a third-party web resource.
    Example:

    $response = wp_remote_get( "https://api.twitter.com/1.1/search/tweets.json?q=%23WordPress", array( 'timeout' => 10 ) );
    $tweets = wp_remote_retrieve_body( $response );
    

    wp_is_mobile
    Specifies the user’s device.
    Example:

    if ( wp_is_mobile() ) {
        get_footer( 'mobile' );
    }
    else {
        get_footer();
    }
    

    wp_oembed_get
    Converts a link to a media resource in the code of the player.
    Example:

    $youtube_url = 'https://www.youtube.com/watch?v=Lcvh0DgytH8';
    $embed_code = wp_oembed_get( $youtube_url, array( 'width' => 800 ) );
    

    wp_tempnam
    Creates a temporary file with a unique name.
    Example:

    wp_tempnam( 'cache.log', get_temp_dir() );
    

    zeroise
    Complements the number with zeros to the specified length.
    Example:

    $tickets_count = 8;
    echo zeroise( $tickets_count, 3 ); // 008
    

    capital_P_dangit
    Corrects common errors in brand name WordPress.
    Example:

    $string = "I Love WordPress";
    echo capital_P_dangit( $string ); // I Love WordPress
    

    get_num_queries
    Shows the total number of SQL-queries to the database page.
    Example:

    <!-- Number of queries: <?php echo get_num_queries(); ?> -->
    

    wp_text_diff
    Finds the differences in the text and displays them in a convenient form for comparison.
    Example:

    $left_string = 'This is the original string';
    $right_string = 'This is the revised string';
    echo wp_text_diff( $left_string, $right_string );
    

    submit_button
    Generates code for the button.
    Example:

    <?php submit_button( __( 'Save Changes' ) ); ?>
    

    enjoy 🙂

    This text is a translation of article “Малоизвестные функции в WordPress” by Pingbull published on habrahabr.ru.

    Forums and blogs without spam

    CleanTalk is a SaaS spam protection service for Web-sites. CleanTalk uses protection methods which are invisible for site visitors. Connecting to the service eliminates needs for CAPTCHA, questions and answers and other methods of protection, complicating the exchange of information on the site.