Plugin Directory

Changeset 1900694


Ignore:
Timestamp:
06/28/2018 04:31:44 PM (8 years ago)
Author:
enamakel
Message:

added v1.3.0

Location:
bitwords-io/trunk
Files:
4 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • bitwords-io/trunk/bitwords_admin_settings.php

    r1898118 r1900694  
    66 * Plugin Name:       Bitwords.io
    77 * Description:       Show ads from the Bitwords.io site
    8  * Version:           1.2.2
     8 * Version:           1.3.0
    99 */
    1010if (!defined('WPINC')) die;
     
    8484 */
    8585function bitwordsScripts() {
    86     wp_enqueue_style('bitwords_style', plugin_dir_url(__FILE__) . 'assets/style.css', array(), '1.1.2');
    87     wp_enqueue_script('bitwords_script', plugin_dir_url(__FILE__) . 'assets/script.v2.js', array(), '1.1.2', true);
     86    wp_enqueue_style('bitwords_style', plugin_dir_url(__FILE__) . 'assets/style.v3.min.css', array(), '1.3.0');
     87    wp_enqueue_script('bitwords_script', plugin_dir_url(__FILE__) . 'assets/script.v3.min.js', array(), '1.3.0', true);
    8888}
    8989add_action('wp_enqueue_scripts', 'bitwordsScripts');
     
    120120    $api = new BitwordsAPI();
    121121
    122     // post is published
    123     if ( $new == 'publish' ) {
    124         // get the content of post without tags
    125         $content = wp_strip_all_tags($post->post_content);
    126         // get the url of post thumbnail
    127         $thumbnailUrl = get_the_post_thumbnail_url($post);
     122    // Only process published posts
     123    if ($new != 'publish') return
    128124
    129         // post is updated
    130         if ( $old == 'publish') $post->type = 'update';
    131         // post is pulished
    132         else $post->type = 'publish';
     125    // get the content of post without tags
     126    $content = wp_strip_all_tags($post->post_content);
     127    // get the url of post thumbnail
     128    $thumbnailUrl = get_the_post_thumbnail_url($post);
    133129
    134         // fields for advertisment
    135         $post->title = $post->post_title;
    136         $post->description = $content;
    137         $post->url = $post->guid;
    138         $post->thumbnailUrl = $post->$thumbnailUrl;
     130    // fields for advertisment
     131    $data = array(
     132        'authorId' => intval($post->post_author),
     133        'comments' => intval($post->comment_count),
     134        'content' => $content,
     135        'guid' => $post->guid,
     136        'imageUrl' => get_the_post_thumbnail_url($post),
     137        'postId' => intval($post->ID),
     138        'publishedAt' => $post->post_date,
     139        'title' => $post->post_title,
     140        'url' => get_post_permalink($post),
     141    );
    139142
    140         // send this data to bitwords
    141         $api->sendArticle($post);
    142     } else {
    143         return;
    144     }
     143    // send this data to bitwords
     144    $api->sendPost($data);
    145145}
    146 add_action( 'transition_post_status', 'bitwordsOnArticlePublishOrUpdate', 10, 3 );
     146
     147add_action('transition_post_status', 'bitwordsOnArticlePublishOrUpdate', 10, 3);
  • bitwords-io/trunk/lib/BitwordsAPI.php

    r1897786 r1900694  
    2323        $options = array(
    2424            'method' => 'POST',
    25             'timeout' => 15,
     25            'timeout' => 5,
    2626            'redirection' => 2,
    2727            'blocking' => true,
     
    3535        $response = wp_remote_post($HOST . $url, $options);
    3636
     37        if (is_wp_error($response)) return NULL;
     38
    3739        if ($response["response"]["code"] == 200) {
    3840            $responseBody = json_decode($response["body"]);
    3941            return $responseBody;
    4042        }
    41 
    42         die('bad response from the server');
    4343    }
    4444
     
    7979     * send published or updated articles to bitwords
    8080     */
    81     public function sendArticle ($post) {
    82         $this-> _api('/publishers/wordpress/article', $post);
     81    public function sendPost ($post) {
     82        $this-> _api('/publishers/wordpress/post', $post);
    8383    }
    8484}
Note: See TracChangeset for help on using the changeset viewer.