Пример #1
0
function ml_post_published_notification($post_id)
{
    $post = get_post($post_id, OBJECT);
    $alert = $post->post_title;
    $custom_properties = array('post_id' => $post_id);
    //tags
    $tags = array();
    //subscriptions
    if (ml_subscriptions_enable()) {
        $tags[] = "all";
        $capabilities = ml_subscriptions_post_capabilities($post);
        foreach ($capabilities as $c) {
            $tags[] = $c;
        }
    } else {
        $tags[] = "all";
        $categories = wp_get_post_categories($post->ID);
        foreach ($categories as $c) {
            if ($c != NULL) {
                $tags[] = $c;
            }
        }
    }
    ml_send_notification($alert, true, NULL, $custom_properties, $tags, $post_id);
}
Пример #2
0
/**
 * Get posts from database
 *
 * @param $query_array
 * @param $user_category
 * @param $real_offset
 *
 * @return array
 */
function ml_get_posts($query_array, $user_category, $real_offset)
{
    if (!isset($_POST["post_id"])) {
        wp_reset_postdata();
        $query = new WP_Query($query_array);
        $posts = $query->get_posts();
        wp_reset_postdata();
        if ($user_category == null) {
            $sticky_category_1 = get_option('sticky_category_1');
            $sticky_category_2 = get_option('sticky_category_2');
        }
        //must be the second, first because the first will be prepended
        if ($sticky_category_2 && ($real_offset == null || $real_offset == 0)) {
            //loading second 3 posts of the sticky category
            $cat = ml_get_category($sticky_category_2);
            if ($cat) {
                $query_array['posts_per_page'] = get_option('ml_sticky_category_2_posts', 3);
                $query_array['category_name'] = null;
                $query_array['category'] = null;
                $query_array['cat'] = $cat->cat_ID;
                $cat_2_posts = get_posts($query_array);
                foreach ($cat_2_posts as $p) {
                    $p->sticky = true;
                    foreach ($posts as $i => $v) {
                        if ($v->ID == $p->ID) {
                            array_splice($posts, $i, 1);
                        }
                    }
                }
                $posts = array_merge($cat_2_posts, $posts);
            }
        }
        if ($sticky_category_1 && ($real_offset == null || $real_offset == 0)) {
            //loading first 3 posts of the sticky category
            $cat = get_category($sticky_category_1);
            if ($cat) {
                $query_array['posts_per_page'] = get_option('ml_sticky_category_1_posts', 3);
                $query_array['category_name'] = null;
                $query_array['category'] = null;
                $query_array['cat'] = $cat->cat_ID;
                $cat_1_posts = get_posts($query_array);
                foreach ($cat_1_posts as $p) {
                    $p->sticky = true;
                    foreach ($posts as $i => $v) {
                        if ($v->ID == $p->ID) {
                            array_splice($posts, $i, 1);
                        }
                    }
                }
                $posts = array_merge($cat_1_posts, $posts);
            }
        }
    } else {
        $single_post_id = $_POST['post_id'];
        $posts = array();
        $posts[0] = get_post($single_post_id);
    }
    //subscriptions system enabled?
    if (ml_subscriptions_enable()) {
        //user login using $_POST['username'] and $_POST['password']
        $user = ml_login_wordpress($_POST['username'], $_POST['password']);
        if (get_class($user) == "WP_User") {
            //loggedin
            //subscriptions: filter posts using capabilities
            $posts = ml_subscriptions_filter_posts($posts, $user->ID);
        } else {
            $posts = ml_subscriptions_filter_posts($posts, null);
        }
    }
    return $posts;
}