public function test__transition_post_status__ignore_when_locked()
 {
     // The first update sets the lock so the action should only fire once when updating twice
     \wp_transition_post_status('publish', 'publish', $this->post);
     \wp_transition_post_status('publish', 'publish', $this->post);
     $this->assertEquals(1, did_action('wpcom_vip_bump_lastpostmodified'));
 }
 function process_expirations($delta)
 {
     global $post;
     global $wpdb;
     $q = new WP_Query(array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => get_option('fwplpbd_expiration_chunk', 25), 'meta_key' => '_syndication_expiration_date', 'meta_value' => time(), 'meta_compare' => '<='));
     while ($q->have_posts()) {
         $q->the_post();
         $expiration = get_post_meta($post->ID, '_syndication_expiration_date', true);
         if ((int) $expiration and (int) $expiration <= time()) {
             $action = get_post_meta($post->ID, '_syndication_expiration_action', true);
             FeedWordPress::diagnostic('expiration', 'Post [' . $post->ID . '] "' . esc_html($post->post_title) . '" expired as of ' . date('r', (int) $expiration) . ' and will now be ' . ('trash' == $action ? 'trashed' : ('nuke' == $action ? 'deleted permanently' : 'hidden')));
             switch ($action) {
                 case 'trash':
                 case 'nuke':
                     $feed = get_syndication_feed_object($post->ID);
                     $thumbId = get_post_thumbnail_id($post->ID);
                     wp_delete_post($post->ID, 'nuke' == $action);
                     // Check to see whether any other posts
                     // use this as a Featured Image. If not
                     // then zap it.
                     if ("nuke" == $feed->setting('post expiration thumbnail', 'post_expiration_thumbnail', "keep")) {
                         if (strlen($thumbId) > 0) {
                             $qrows = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\tSELECT meta_value FROM {$wpdb->postmeta}\n\t\t\t\t\t\t\tWHERE meta_key = '_thumbnail_id'\n\t\t\t\t\t\t\tAND meta_value = '%d'\n\t\t\t\t\t\t\tAND post_id <> '%d'\n\t\t\t\t\t\t\t", $thumbId, $post->ID));
                             if (count($qrows) < 1) {
                                 FeedWordPress::diagnostic('expiration', 'The expired post [' . $post->ID . ']  had an attached Featured Image, which is not used as the Featured Image for any other post. We will now clean up and the image will be ' . ('trash' == $action ? 'trashed' : ('nuke' == $action ? 'deleted permanently' : 'hidden')));
                                 wp_delete_attachment($thumbId, 'nuke' == $action);
                             } else {
                                 FeedWordPress::diagnostic('expiration', 'The expired post [' . $post->ID . ']  had an attached Featured Image, but it CANNOT be deleted right now because at least one other post uses the same image as its Featured Image.');
                             }
                         }
                     }
                     break;
                 case 'hide':
                 case 'redirect':
                 default:
                     $old_status = $post->post_status;
                     set_post_field('post_status', 'expired', $post->ID);
                     wp_transition_post_status('expired', $old_status, $post);
                     break;
             }
         }
     }
 }
 function update_event_quote($event_id, $quote_id)
 {
     // If the current user is not the client, do not log
     if (get_post_meta($event_id, '_mdjm_event_client', true) != get_current_user_id()) {
         return;
     }
     /* -- Initiate actions for status change -- */
     wp_transition_post_status('mdjm-quote-viewed', 'mdjm-quote-generated', get_post($quote_id));
     if (MDJM_DEBUG == true) {
         MDJM()->debug->log_it('Setting quote to viewed status for quote ' . $quote_id . ' event ' . $event_id, true);
     }
     /* -- Update the post status -- */
     if (wp_update_post(array('ID' => $quote_id, 'post_status' => 'mdjm-quote-viewed'))) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('Quote status updated successfully', false);
         }
         $result = true;
     }
     /* -- Set post meta for read time and update the number of client views -- */
     if ($result == true) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('Updating quote view count', false);
         }
         $view_count = get_post_meta($quote_id, '_mdjm_quote_viewed_count', true);
         if (!empty($view_count)) {
             $view_count++;
         } else {
             $view_count = 1;
         }
         update_post_meta($quote_id, '_mdjm_quote_viewed_count', $view_count);
         // Only update the view date if this is the first viewing
         if ($view_count == 1) {
             if (MDJM_DEBUG == true) {
                 MDJM()->debug->log_it('Updating quote viewed time', false);
             }
             update_post_meta($quote_id, '_mdjm_quote_viewed_date', current_time('mysql'));
         }
     }
     return !empty($result) ? true : false;
 }
Example #4
0
/**
 * Publish a post by transitioning the post status.
 *
 * @since 2.1.0
 * @uses $wpdb
 * @uses do_action() Calls 'edit_post', 'save_post', and 'wp_insert_post' on post_id and post data.
 *
 * @param int $post_id Post ID.
 * @return null
 */
function wp_publish_post($post_id)
{
    global $wpdb;
    $post = get_post($post_id);
    if (empty($post)) {
        return;
    }
    if ('publish' == $post->post_status) {
        return;
    }
    $wpdb->update($wpdb->posts, array('post_status' => 'publish'), array('ID' => $post_id));
    $old_status = $post->post_status;
    $post->post_status = 'publish';
    wp_transition_post_status('publish', $old_status, $post);
    do_action('edit_post', $post_id, $post);
    do_action('save_post', $post_id, $post);
    do_action('wp_insert_post', $post_id, $post);
}
Example #5
0
/**
 * Save home page
 */
function siteorigin_panels_save_home_page()
{
    if (!isset($_POST['_sopanels_home_nonce']) || !wp_verify_nonce($_POST['_sopanels_home_nonce'], 'save')) {
        return;
    }
    if (!current_user_can('edit_theme_options')) {
        return;
    }
    if (!isset($_POST['panels_data'])) {
        return;
    }
    // Check that the home page ID is set and the home page exists
    $page_id = get_option('page_on_front');
    if (empty($page_id)) {
        $page_id = get_option('siteorigin_panels_home_page_id');
    }
    $post_content = wp_unslash($_POST['post_content']);
    if (!$page_id || get_post_meta($page_id, 'panels_data', true) == '') {
        // Lets create a new page
        $page_id = wp_insert_post(array('post_title' => __('Home Page', 'siteorigin-panels'), 'post_status' => !empty($_POST['siteorigin_panels_home_enabled']) ? 'publish' : 'draft', 'post_type' => 'page', 'post_content' => $post_content, 'comment_status' => 'closed'));
        update_option('page_on_front', $page_id);
        update_option('siteorigin_panels_home_page_id', $page_id);
        // Action triggered when creating a new home page through the custom home page interface
        do_action('siteorigin_panels_create_home_page', $page_id);
    } else {
        // `wp_insert_post` does it's own sanitization, but it seems `wp_update_post` doesn't.
        $post_content = sanitize_post_field('post_content', $post_content, $page_id, 'db');
        // Update the post with changed content to save revision if necessary.
        wp_update_post(array('ID' => $page_id, 'post_content' => $post_content));
    }
    // Save the updated page data
    $panels_data = json_decode(wp_unslash($_POST['panels_data']), true);
    $panels_data['widgets'] = siteorigin_panels_process_raw_widgets($panels_data['widgets']);
    $panels_data = siteorigin_panels_styles_sanitize_all($panels_data);
    update_post_meta($page_id, 'panels_data', $panels_data);
    $template = get_post_meta($page_id, '_wp_page_template', true);
    $home_template = siteorigin_panels_setting('home-template');
    if (($template == '' || $template == 'default') && !empty($home_template)) {
        // Set the home page template
        update_post_meta($page_id, '_wp_page_template', $home_template);
    }
    if (!empty($_POST['siteorigin_panels_home_enabled'])) {
        update_option('show_on_front', 'page');
        update_option('page_on_front', $page_id);
        update_option('siteorigin_panels_home_page_id', $page_id);
        wp_publish_post($page_id);
    } else {
        // We're disabling this home page
        update_option('show_on_front', 'posts');
        // Change the post status to draft
        $post = get_post($page_id);
        if ($post->post_status != 'draft') {
            global $wpdb;
            $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $post->ID));
            clean_post_cache($post->ID);
            $old_status = $post->post_status;
            $post->post_status = 'draft';
            wp_transition_post_status('draft', $old_status, $post);
            do_action('edit_post', $post->ID, $post);
            do_action("save_post_{$post->post_type}", $post->ID, $post, true);
            do_action('save_post', $post->ID, $post, true);
            do_action('wp_insert_post', $post->ID, $post, true);
        }
    }
}
Example #6
0
/**
 * Mark the forum as hidden
 *
 * @since bbPress (r2996)
 *
 * @param int $forum_id Optional. Forum id
 * @uses update_post_meta() To update the forum private meta
 * @return bool False on failure, true on success
 */
function bbp_hide_forum($forum_id = 0, $current_visibility = '')
{
    $forum_id = bbp_get_forum_id($forum_id);
    do_action('bbp_hide_forum', $forum_id);
    // Only run queries if visibility is changing
    if (bbp_get_hidden_status_id() !== $current_visibility) {
        // Get private forums
        $private = bbp_get_private_forum_ids();
        // Find this forum in the array
        if (in_array($forum_id, $private)) {
            $offset = array_search($forum_id, $private);
            // Splice around it
            array_splice($private, $offset, 1);
            // Update private forums minus this one
            update_option('_bbp_private_forums', array_unique(array_filter(array_values($private))));
        }
        // Add to '_bbp_hidden_forums' site option
        $hidden = bbp_get_hidden_forum_ids();
        $hidden[] = $forum_id;
        update_option('_bbp_hidden_forums', array_unique(array_filter(array_values($hidden))));
        // Update forums visibility setting
        global $wpdb;
        $wpdb->update($wpdb->posts, array('post_status' => bbp_get_hidden_status_id()), array('ID' => $forum_id));
        wp_transition_post_status(bbp_get_hidden_status_id(), $current_visibility, get_post($forum_id));
        bbp_clean_post_cache($forum_id);
    }
    do_action('bbp_hid_forum', $forum_id);
    return $forum_id;
}
/**
 * Save home page
 */
function siteorigin_panels_save_home_page()
{
    if (!isset($_POST['_sopanels_home_nonce']) || !wp_verify_nonce($_POST['_sopanels_home_nonce'], 'save')) {
        return;
    }
    if (!current_user_can('edit_theme_options')) {
        return;
    }
    // Check that the home page ID is set and the home page exists
    $page_id = get_option('page_on_front');
    if (empty($page_id)) {
        $page_id = get_option('siteorigin_panels_home_page_id');
    }
    if (!$page_id || get_post_meta($page_id, 'panels_data', true) == '') {
        // Lets create a new page
        $page_id = wp_insert_post(array('post_title' => __('Home Page', 'siteorigin-panels'), 'post_status' => $_POST['siteorigin_panels_home_enabled'] == 'true' ? 'publish' : 'draft', 'post_type' => 'page', 'comment_status' => 'closed'));
        update_option('page_on_front', $page_id);
        update_option('siteorigin_panels_home_page_id', $page_id);
    }
    // Save the updated page data
    $panels_data = json_decode(wp_unslash($_POST['panels_data']), true);
    $panels_data['widgets'] = siteorigin_panels_process_raw_widgets($panels_data['widgets']);
    $panels_data = siteorigin_panels_styles_sanitize_all($panels_data);
    update_post_meta($page_id, 'panels_data', $panels_data);
    update_post_meta($page_id, '_wp_page_template', siteorigin_panels_setting('home-template'));
    if (!empty($_POST['siteorigin_panels_home_enabled'])) {
        update_option('show_on_front', 'page');
        update_option('page_on_front', $page_id);
        update_option('siteorigin_panels_home_page_id', $page_id);
        wp_publish_post($page_id);
    } else {
        // We're disabling this home page
        update_option('show_on_front', 'posts');
        // Change the post status to draft
        $post = get_post($page_id);
        if ($post->post_status != 'draft') {
            global $wpdb;
            $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $post->ID));
            clean_post_cache($post->ID);
            $old_status = $post->post_status;
            $post->post_status = 'draft';
            wp_transition_post_status('draft', $old_status, $post);
            do_action('edit_post', $post->ID, $post);
            do_action("save_post_{$post->post_type}", $post->ID, $post, true);
            do_action('save_post', $post->ID, $post, true);
            do_action('wp_insert_post', $post->ID, $post, true);
        }
    }
}
Example #8
0
function grunion_ajax_spam()
{
    global $wpdb;
    if (empty($_POST['make_it'])) {
        return;
    }
    $post_id = (int) $_POST['post_id'];
    check_ajax_referer('grunion-post-status-' . $post_id);
    if (!current_user_can("edit_page", $post_id)) {
        wp_die(__('You are not allowed to manage this item.', 'jetpack'));
    }
    require_once dirname(__FILE__) . '/grunion-contact-form.php';
    $current_menu = '';
    if (preg_match('|post_type=feedback|', $_POST['sub_menu'])) {
        if (preg_match('|post_status=spam|', $_POST['sub_menu'])) {
            $current_menu = 'spam';
        } else {
            if (preg_match('|post_status=trash|', $_POST['sub_menu'])) {
                $current_menu = 'trash';
            } else {
                $current_menu = 'messages';
            }
        }
    }
    $post = get_post($post_id);
    $post_type_object = get_post_type_object($post->post_type);
    $akismet_values = get_post_meta($post_id, '_feedback_akismet_values', TRUE);
    if ($_POST['make_it'] == 'spam') {
        $post->post_status = 'spam';
        $status = wp_insert_post($post);
        wp_transition_post_status('spam', 'publish', $post);
        do_action('contact_form_akismet', 'spam', $akismet_values);
    } elseif ($_POST['make_it'] == 'ham') {
        $post->post_status = 'publish';
        $status = wp_insert_post($post);
        wp_transition_post_status('publish', 'spam', $post);
        do_action('contact_form_akismet', 'spam', $akismet_values);
        $comment_author_email = $reply_to_addr = $message = $to = $headers = false;
        $blog_url = parse_url(site_url());
        // resend the original email
        $email = get_post_meta($post_id, '_feedback_email', TRUE);
        $content_fields = Grunion_Contact_Form_Plugin::parse_fields_from_content($post_id);
        if (!empty($email) && !empty($content_fields)) {
            if (isset($content_fields['_feedback_author_email'])) {
                $comment_author_email = $content_fields['_feedback_author_email'];
            }
            if (isset($email['to'])) {
                $to = $email['to'];
            }
            if (isset($email['message'])) {
                $message = $email['message'];
            }
            if (isset($email['headers'])) {
                $headers = $email['headers'];
            } else {
                $headers = 'From: "' . $content_fields['_feedback_author'] . '" <wordpress@' . $blog_url['host'] . ">\r\n";
                if (!empty($comment_author_email)) {
                    $reply_to_addr = $comment_author_email;
                } elseif (is_array($to)) {
                    $reply_to_addr = $to[0];
                }
                if ($reply_to_addr) {
                    $headers .= 'Reply-To: "' . $content_fields['_feedback_author'] . '" <' . $reply_to_addr . ">\r\n";
                }
                $headers .= "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"";
            }
            $subject = apply_filters('contact_form_subject', $content_fields['_feedback_subject']);
            wp_mail($to, $subject, $message, $headers);
        }
    } elseif ($_POST['make_it'] == 'publish') {
        if (!current_user_can($post_type_object->cap->delete_post, $post_id)) {
            wp_die(__('You are not allowed to move this item out of the Trash.', 'jetpack'));
        }
        if (!wp_untrash_post($post_id)) {
            wp_die(__('Error in restoring from Trash.', 'jetpack'));
        }
    } elseif ($_POST['make_it'] == 'trash') {
        if (!current_user_can($post_type_object->cap->delete_post, $post_id)) {
            wp_die(__('You are not allowed to move this item to the Trash.', 'jetpack'));
        }
        if (!wp_trash_post($post_id)) {
            wp_die(__('Error in moving to Trash.', 'jetpack'));
        }
    }
    $sql = "\n\t\tSELECT post_status,\n\t\t\tCOUNT( * ) AS post_count\n\t\tFROM `{$wpdb->posts}`\n\t\tWHERE post_type =  'feedback'\n\t\tGROUP BY post_status\n\t";
    $status_count = (array) $wpdb->get_results($sql, ARRAY_A);
    $status = array();
    $status_html = '';
    foreach ($status_count as $i => $row) {
        $status[$row['post_status']] = $row['post_count'];
    }
    if (isset($status['publish'])) {
        $status_html .= '<li><a href="edit.php?post_type=feedback"';
        if ($current_menu == 'messages') {
            $status_html .= ' class="current"';
        }
        $status_html .= '>' . __('Messages', 'jetpack') . ' <span class="count">';
        $status_html .= '(' . number_format($status['publish']) . ')';
        $status_html .= '</span></a> |</li>';
    }
    if (isset($status['trash'])) {
        $status_html .= '<li><a href="edit.php?post_status=trash&amp;post_type=feedback"';
        if ($current_menu == 'trash') {
            $status_html .= ' class="current"';
        }
        $status_html .= '>' . __('Trash', 'jetpack') . ' <span class="count">';
        $status_html .= '(' . number_format($status['trash']) . ')';
        $status_html .= '</span></a>';
        if (isset($status['spam'])) {
            $status_html .= ' |';
        }
        $status_html .= '</li>';
    }
    if (isset($status['spam'])) {
        $status_html .= '<li><a href="edit.php?post_status=spam&amp;post_type=feedback"';
        if ($current_menu == 'spam') {
            $status_html .= ' class="current"';
        }
        $status_html .= '>' . __('Spam', 'jetpack') . ' <span class="count">';
        $status_html .= '(' . number_format($status['spam']) . ')';
        $status_html .= '</span></a></li>';
    }
    echo $status_html;
    exit;
}
Example #9
0
 /**
  * Sets the status of a set of products
  *
  * @author Jonathan Davis
  * @since 1.2
  *
  * @param array $ids Set of product IDs to update
  * @param string $status The status to set: publish, draft, trash
  * @return boolean
  **/
 static function publishset(array $ids, $status)
 {
     if (empty($ids) || !is_array($ids)) {
         return false;
     }
     $settings = array('publish', 'draft', 'trash');
     if (!in_array($status, $settings)) {
         return false;
     }
     $table = WPShoppObject::tablename(self::$table);
     $time = current_time('timestamp');
     $post_date_gmt = sDB::mkdatetime($time + get_option('gmt_offset') * 3600);
     $post_date = sDB::mkdatetime($time);
     sDB::query("UPDATE {$table} SET post_status='{$status}', post_date='{$post_date}', post_date_gmt='{$post_date_gmt}', post_modified='{$post_date}', post_modified_gmt='{$post_date_gmt}' WHERE ID in (" . join(',', $ids) . ")");
     foreach ($ids as $id) {
         // Recount taxonomy counts #2968
         $Post = get_post($id);
         switch ($status) {
             case 'trash':
                 do_action('wp_trash_post', $id);
                 break;
             default:
                 do_action('save_post', $id, $Post);
                 break;
         }
         if (function_exists('clean_post_cache')) {
             clean_post_cache($id);
         }
         wp_transition_post_status($status, $Product->status, $Post);
     }
     return true;
 }
/**
 * Save home page
 */
function siteorigin_panels_save_home_page()
{
    if (!isset($_POST['_sopanels_home_nonce']) || !wp_verify_nonce($_POST['_sopanels_home_nonce'], 'save')) {
        return;
    }
    if (empty($_POST['panels_js_complete'])) {
        return;
    }
    if (!current_user_can('edit_theme_options')) {
        return;
    }
    // Check that the home page ID is set and the home page exists
    if (!get_option('siteorigin_panels_home_page_id') || !get_post(get_option('siteorigin_panels_home_page_id'))) {
        // Lets create a new page
        $page_id = wp_insert_post(array('post_title' => __('Home', 'siteorigin-panels'), 'post_status' => $_POST['siteorigin_panels_home_enabled'] == 'true' ? 'publish' : 'draft', 'post_type' => 'page', 'comment_status' => 'closed'));
        update_option('siteorigin_panels_home_page_id', $page_id);
    } else {
        $page_id = get_option('siteorigin_panels_home_page_id');
    }
    // Save the updated page data
    $panels_data = siteorigin_panels_get_panels_data_from_post($_POST);
    update_post_meta($page_id, 'panels_data', $panels_data);
    update_post_meta($page_id, '_wp_page_template', siteorigin_panels_setting('home-template'));
    if ($_POST['siteorigin_panels_home_enabled'] == 'true') {
        update_option('show_on_front', 'page');
        update_option('page_on_front', $page_id);
        wp_publish_post($page_id);
    } else {
        // We're disabling this home page
        if (get_option('page_on_front') == $page_id) {
            // Disable the front page display
            update_option('page_on_front', false);
            if (!get_option('page_for_posts')) {
                update_option('show_on_front', 'posts');
            }
        }
        // Change the post status to draft
        $post = get_post($page_id);
        if ($post->post_status != 'draft') {
            global $wpdb;
            $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $post->ID));
            clean_post_cache($post->ID);
            $old_status = $post->post_status;
            $post->post_status = 'draft';
            wp_transition_post_status('draft', $old_status, $post);
            do_action('edit_post', $post->ID, $post);
            do_action("save_post_{$post->post_type}", $post->ID, $post, true);
            do_action('save_post', $post->ID, $post, true);
            do_action('wp_insert_post', $post->ID, $post, true);
        }
    }
}
Example #11
0
function grunion_ajax_spam()
{
    global $wpdb;
    if (empty($_POST['make_it'])) {
        return;
    }
    $post_id = (int) $_POST['post_id'];
    check_ajax_referer('grunion-post-status-' . $post_id);
    if (!current_user_can("edit_page", $post_id)) {
        wp_die(__('You are not allowed to manage this item.', 'jetpack'));
    }
    require_once dirname(__FILE__) . '/grunion-contact-form.php';
    $current_menu = '';
    if (preg_match('|post_type=feedback|', $_POST['sub_menu'])) {
        if (preg_match('|post_status=spam|', $_POST['sub_menu'])) {
            $current_menu = 'spam';
        } else {
            if (preg_match('|post_status=trash|', $_POST['sub_menu'])) {
                $current_menu = 'trash';
            } else {
                $current_menu = 'messages';
            }
        }
    }
    $post = get_post($post_id);
    $post_type_object = get_post_type_object($post->post_type);
    $akismet_values = get_post_meta($post_id, '_feedback_akismet_values', TRUE);
    if ($_POST['make_it'] == 'spam') {
        $post->post_status = 'spam';
        $status = wp_insert_post($post);
        wp_transition_post_status('spam', 'publish', $post);
        do_action('contact_form_akismet', 'spam', $akismet_values);
    } elseif ($_POST['make_it'] == 'ham') {
        $post->post_status = 'publish';
        $status = wp_insert_post($post);
        wp_transition_post_status('publish', 'spam', $post);
        do_action('contact_form_akismet', 'spam', $akismet_values);
        // resend the original email
        $email = get_post_meta($post_id, '_feedback_email', TRUE);
        wp_mail($email['to'], $email['subject'], $email['message'], $email['headers']);
    } elseif ($_POST['make_it'] == 'publish') {
        if (!current_user_can($post_type_object->cap->delete_post, $post_id)) {
            wp_die(__('You are not allowed to move this item out of the Trash.', 'jetpack'));
        }
        if (!wp_untrash_post($post_id)) {
            wp_die(__('Error in restoring from Trash.', 'jetpack'));
        }
    } elseif ($_POST['make_it'] == 'trash') {
        if (!current_user_can($post_type_object->cap->delete_post, $post_id)) {
            wp_die(__('You are not allowed to move this item to the Trash.', 'jetpack'));
        }
        if (!wp_trash_post($post_id)) {
            wp_die(__('Error in moving to Trash.', 'jetpack'));
        }
    }
    $sql = "\n\t\tSELECT post_status,\n\t\t\tCOUNT( * ) AS post_count\n\t\tFROM `{$wpdb->posts}`\n\t\tWHERE post_type =  'feedback'\n\t\tGROUP BY post_status\n\t";
    $status_count = (array) $wpdb->get_results($sql, ARRAY_A);
    $status = array();
    $status_html = '';
    foreach ($status_count as $i => $row) {
        $status[$row['post_status']] = $row['post_count'];
    }
    if (isset($status['publish'])) {
        $status_html .= '<li><a href="edit.php?post_type=feedback"';
        if ($current_menu == 'messages') {
            $status_html .= ' class="current"';
        }
        $status_html .= '>' . __('Messages', 'jetpack') . ' <span class="count">';
        $status_html .= '(' . number_format($status['publish']) . ')';
        $status_html .= '</span></a> |</li>';
    }
    if (isset($status['trash'])) {
        $status_html .= '<li><a href="edit.php?post_status=trash&amp;post_type=feedback"';
        if ($current_menu == 'trash') {
            $status_html .= ' class="current"';
        }
        $status_html .= '>' . __('Trash', 'jetpack') . ' <span class="count">';
        $status_html .= '(' . number_format($status['trash']) . ')';
        $status_html .= '</span></a>';
        if (isset($status['spam'])) {
            $status_html .= ' |';
        }
        $status_html .= '</li>';
    }
    if (isset($status['spam'])) {
        $status_html .= '<li><a href="edit.php?post_status=spam&amp;post_type=feedback"';
        if ($current_menu == 'spam') {
            $status_html .= ' class="current"';
        }
        $status_html .= '>' . __('Spam', 'jetpack') . ' <span class="count">';
        $status_html .= '(' . number_format($status['spam']) . ')';
        $status_html .= '</span></a></li>';
    }
    echo $status_html;
    exit;
}
Example #12
0
        public function sign_contract()
        {
            global $mdjm, $my_mdjm, $clientzone, $mdjm_settings;
            /* -- Validate the nonce -- */
            if (!isset($_POST['mdjm_sign_event_contract']) || !wp_verify_nonce($_POST['mdjm_sign_event_contract'], 'sign_event_contract')) {
                echo '<script type="text/javascript">' . "\r\n" . 'alert("WordPress Security Validation failed. Please try again");' . "\r\n" . 'history.back();' . "\r\n" . '</script>' . "\r\n";
            }
            /* -- Check the users password is correct -- */
            $pass_cfm = wp_authenticate($my_mdjm['me']->user_login, $_POST['sign_pass_confirm']);
            /* -- Incorrect Password -- */
            if (is_wp_error($pass_cfm)) {
                echo '<script type="text/javascript">' . "\r\n" . 'alert("ERROR: Your password was not entered correctly. Please try again.");' . "\r\n" . 'history.back();' . "\r\n" . '</script>' . "\r\n";
            } else {
                /* -- Remove the save post hook to avoid loops -- */
                remove_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
                /* -- Create a new signed contract instance -- */
                $contract_data = array('post_title' => 'Event Contract: ' . MDJM_EVENT_PREFIX . $this->event->ID, 'post_author' => $my_mdjm['me']->ID, 'post_type' => 'mdjm-signed-contract', 'post_status' => 'publish', 'post_parent' => $this->event->ID, 'ping_status' => 'closed', 'comment_status' => 'closed');
                /* -- Prepare the contract content -- */
                $content = $this->event_contract->post_content;
                $content = apply_filters('the_content', $content);
                $content = str_replace(']]>', ']]&gt;', $content);
                /* -- Shortcode replacements -- */
                $contract_data['post_content'] = $mdjm->filter_content($my_mdjm['me']->ID, $this->event->ID, $content);
                /* -- Append Signatory info -- */
                $contract_data['post_content'] .= '<hr>' . "\r\n";
                $contract_data['post_content'] .= '<p style="font-weight: bold">' . __('Signatory') . ': <span style="text-decoration: underline;">' . ucfirst($_POST['sign_first_name']) . ' ' . ucfirst($_POST['sign_last_name']) . '</span></p>' . "\r\n";
                $contract_data['post_content'] .= '<p style="font-weight: bold">' . __('Date of Signature') . ': <span style="text-decoration: underline;">' . date('jS F Y') . '</span></p>' . "\r\n";
                $contract_data['post_content'] .= '<p style="font-weight: bold">' . __('Verification Method') . ': User Password Confirmation</p>' . "\r\n";
                /* -- Create the Signed Contract Post -- */
                $signed_contract = wp_insert_post($contract_data, true);
                // Success
                if (!is_wp_error($signed_contract)) {
                    if (MDJM_DEBUG == true) {
                        MDJM()->debug->log_it('Client event signed contract created (' . $signed_contract . ')', true);
                    }
                    add_post_meta($signed_contract, '_mdjm_contract_signed_name', ucfirst($_POST['sign_first_name']) . ' ' . ucfirst($_POST['sign_last_name']), true);
                    /* -- Update the event -- */
                    $event_meta = array('_mdjm_event_signed_contract' => $signed_contract, '_mdjm_event_contract_approved' => date('Y-m-d H:i:s'), '_mdjm_event_contract_approver' => ucfirst($_POST['sign_first_name']) . ' ' . ucfirst($_POST['sign_last_name']), '_mdjm_event_contract_approver_ip' => $_SERVER['REMOTE_ADDR'], '_mdjm_event_last_updated_by' => $my_mdjm['me']->ID);
                    /* -- Initiate actions for status change -- */
                    wp_transition_post_status('mdjm-approved', $this->event->post_status, $this->event);
                    /* -- Update the post status -- */
                    wp_update_post(array('ID' => $this->event->ID, 'post_status' => 'mdjm-approved'));
                    foreach ($event_meta as $event_meta_key => $event_meta_value) {
                        update_post_meta($this->event->ID, $event_meta_key, $event_meta_value);
                    }
                    /* -- Update Journal with event updates -- */
                    if (MDJM_JOURNAL == true) {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('	-- Adding journal entry');
                        }
                        mdjm_add_journal(array('user_id' => $my_mdjm['me']->ID, 'event_id' => $this->event->ID, 'comment_content' => 'Contract Approval completed by ' . ucfirst($_POST['sign_first_name']) . ' ' . ucfirst($_POST['sign_last_name'] . '<br>')), array('type' => 'update-event', 'visibility' => '2'));
                    } else {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('	-- Journalling is disabled');
                        }
                    }
                    /* -- Email booking confirmations -- */
                    $contact_client = isset($mdjm_settings['templates']['booking_conf_to_client']) ? true : false;
                    $contact_dj = isset($mdjm_settings['templates']['booking_conf_to_dj']) ? true : false;
                    $client_email = isset($mdjm_settings['templates']['booking_conf_client']) ? $mdjm_settings['templates']['booking_conf_client'] : false;
                    $dj_email = isset($mdjm_settings['templates']['email_dj_confirm']) ? $mdjm_settings['templates']['email_dj_confirm'] : false;
                    if (!is_string(get_post_status($client_email))) {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('ERROR: No email template for the contract has been found ' . __FUNCTION__, $stampit = true);
                        }
                        wp_die('ERROR: Either no email template is defined or an error has occured. Check your Settings.');
                    }
                    if ($contact_client == true) {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Configured to email client with template ID ' . $client_email);
                        }
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Generating email...');
                        }
                        $email_args = array('content' => $client_email, 'to' => get_post_meta($this->event->ID, '_mdjm_event_client', true), 'from' => $mdjm_settings['templates']['booking_conf_from'] == 'dj' ? get_post_meta($this->event->ID, '_mdjm_event_dj', true) : 0, 'journal' => 'email-client', 'event_id' => $this->event->ID, 'html' => true, 'cc_dj' => isset($mdjm_settings['email']['bcc_dj_to_client']) ? true : false, 'cc_admin' => isset($mdjm_settings['email']['bcc_admin_to_client']) ? true : false, 'source' => 'Event Status to Approved');
                        // Filter the email args
                        $email_args = apply_filters('mdjm_booking_conf_email_args', $email_args);
                        // Send the email
                        $approval_email = $mdjm->send_email($email_args);
                        if ($approval_email) {
                            if (MDJM_DEBUG == true) {
                                MDJM()->debug->log_it('	-- Confrmation email sent to client ');
                            }
                        } else {
                            if (MDJM_DEBUG == true) {
                                MDJM()->debug->log_it('	ERROR: Confrmation email was not sent');
                            }
                        }
                    } else {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Not configured to email client');
                        }
                    }
                    if ($contact_dj == true) {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Configured to email DJ with template ID ' . $dj_email);
                        }
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Generating email...');
                        }
                        $approval_dj_email = $mdjm->send_email(array('content' => $dj_email, 'to' => get_post_meta($this->event->ID, '_mdjm_event_dj', true), 'from' => 0, 'journal' => 'email-dj', 'event_id' => $this->event->ID, 'html' => true, 'cc_dj' => false, 'cc_admin' => isset($mdjm_settings['email']['bcc_admin_to_dj']) ? true : false, 'source' => 'Event Status to Approved'));
                        if ($approval_dj_email) {
                            if (MDJM_DEBUG == true) {
                                MDJM()->debug->log_it('	-- Approval email sent to DJ ');
                            }
                        } else {
                            if (MDJM_DEBUG == true) {
                                MDJM()->debug->log_it('	ERROR: Approval email was not sent to DJ');
                            }
                        }
                    } else {
                        if (MDJM_DEBUG == true) {
                            MDJM()->debug->log_it('Not configured to email DJ');
                        }
                    }
                }
                /* -- Re-add the save post hook -- */
                add_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
                if (MDJM_DEBUG == true) {
                    MDJM()->debug->log_it('Completed client signing of contract ' . __METHOD__, true);
                }
                /* -- Email admin to notify of changes -- */
                if (MDJM_NOTIFY_ADMIN == true) {
                    if (MDJM_DEBUG == true) {
                        MDJM()->debug->log_it('Sending event status change notification to admin (Contract Signed)');
                    }
                    $content = '<html>' . "\n" . '<body>' . "\n";
                    $content .= '<p>' . sprintf(__('Good news... %s has just signed their event contract via %s', 'mobile-dj-manager'), '{CLIENT_FULLNAME}', MDJM_APP) . '</p>';
                    $content .= '<hr />' . "\n";
                    $content .= '<h4><a href="' . get_edit_post_link($this->event->ID) . '">' . __('Event ID', 'mobile-dj-manager') . ': ' . MDJM_EVENT_PREFIX . $this->event->ID . '</a></h4>' . "\n";
                    $content .= '<p>' . "\n";
                    $content .= __('Date', 'mobile-dj-manager') . ': {EVENT_DATE}<br />' . "\n";
                    $content .= __('Type', 'mobile-dj-manager') . ': ' . MDJM()->events->get_event_type($this->event->ID) . '<br />' . "\n";
                    $event_stati = mdjm_all_event_status();
                    $content .= __('Status', 'mobile-dj-manager') . ': ' . $event_stati[get_post_status($this->event->ID)] . '<br />' . "\n";
                    $content .= __('Client', 'mobile-dj-manager') . ': {CLIENT_FULLNAME}<br />' . "\n";
                    $content .= __('Value', 'mobile-dj-manager') . ': {TOTAL_COST}<br />' . "\n";
                    $deposit = get_post_meta($this->event->ID, '_mdjm_event_deposit');
                    $deposit_status = get_post_meta($this->event->ID, '_mdjm_event_deposit_status');
                    if (!empty($deposit) && $deposit != '0.00') {
                        $content .= __('Deposit', 'mobile-dj-manager') . ': {DEPOSIT} ({DEPOSIT_STATUS})<br />' . "\n";
                    }
                    $content .= __('Balance Due', 'mobile-dj-manager') . ': {BALANCE}</p>' . "\n";
                    $content .= '<p>' . sprintf(__('%sView Event%s', 'mobile-dj-manager'), '<a href="=' . get_edit_post_link($this->event->ID) . '">', '</a>') . '</p>' . "\n";
                    $content .= '</body>' . "\n" . '</html>' . "\n";
                    $mdjm->send_email(array('content' => $mdjm->filter_content(get_post_meta($this->event->ID, '_mdjm_event_client', true), $this->event->ID, $content), 'to' => $mdjm_settings['email']['system_email'], 'subject' => __('Event Contract Signed', 'mobile-dj-manager'), 'journal' => false, 'event_id' => $this->event->ID, 'cc_dj' => false, 'cc_admin' => false, 'filter' => false, 'log_comm' => false));
                } else {
                    if (MDJM_DEBUG == true) {
                        MDJM()->debug->log_it('Skipping admin notification');
                    }
                }
                ?>
					<script type="text/javascript">
                    window.location.replace("<?php 
                echo mdjm_get_formatted_url(MDJM_CONTRACT_PAGE) . 'event_id=' . $this->event->ID . '&message=3&class=2';
                ?>
");
                    </script>
                    <?php 
                exit;
            }
        }
Example #13
0
function jr_check_expired_cron()
{
    global $wpdb;
    $action = get_option('jr_expired_action');
    // Get list of expired posts that are published
    $postids = $wpdb->get_col($wpdb->prepare("\n\t\tSELECT      postmeta.post_id\n\t\tFROM        {$wpdb->postmeta} postmeta\n\t\tLEFT JOIN\t{$wpdb->posts} posts ON postmeta.post_id = posts.ID\n\t\tWHERE       postmeta.meta_key = '_expires' \n\t\t            AND postmeta.meta_value < '%s'\n\t\t            AND post_status = 'publish'\n\t\t            AND post_type = 'job_listing'\n\t", strtotime('NOW')));
    if ($action == 'hide') {
        if ($postids) {
            foreach ($postids as $id) {
                // Captains log supplemental, we have detected a job which is out of date
                // Activate Cloak
                $post = get_post($id);
                if (empty($post)) {
                    return;
                }
                if ('private' == $post->post_status) {
                    return;
                }
                $old_status = $post->post_status;
                $job_post = array();
                $job_post['ID'] = $id;
                $job_post['post_status'] = 'private';
                wp_update_post($job_post);
                $post->post_status = 'private';
                wp_transition_post_status('private', $old_status, $post);
                // Update counts for the post's terms.
                foreach ((array) get_object_taxonomies('job_listing') as $taxonomy) {
                    $tt_ids = wp_get_object_terms($id, $taxonomy, array('fields' => 'tt_ids'));
                    wp_update_term_count($tt_ids, $taxonomy);
                }
                do_action('edit_post', $id, $post);
                do_action('save_post', $id, $post);
                do_action('wp_insert_post', $id, $post);
            }
        }
    }
    if (get_option('jr_expired_job_email_owner') == 'yes') {
        $notify_ids = array();
        // Get list of expiring posts that are published
        $postids = $wpdb->get_col($wpdb->prepare("\n\t\t\tSELECT      DISTINCT postmeta.post_id\n\t\t\tFROM        {$wpdb->postmeta} postmeta\n\t\t\tLEFT JOIN\t{$wpdb->posts} posts ON postmeta.post_id = posts.ID\n\t\t\tWHERE       postmeta.meta_key = '_expires' \n\t\t\t            AND postmeta.meta_value > '%s'\n\t\t\t            AND postmeta.meta_value < '%s'\n\t\t\t            AND post_status = 'publish'\n\t\t\t            AND post_type = 'job_listing'\n\t\t", strtotime('NOW'), strtotime('+5 day')));
        if (sizeof($postids) > 0) {
            // of those, get ids of posts that have already been notified
            $jobs_notified = $wpdb->get_col($wpdb->prepare("\n\t\t\t\tSELECT      postmeta.post_id\n\t\t\t\tFROM        {$wpdb->postmeta} postmeta\n\t\t\t\tWHERE       postmeta.meta_key = 'reminder_email_sent' \n\t\t\t\t            AND postmeta.meta_value IN ('5','1')\n\t\t\t"));
            // Now only send to those who need sending to
            $notify_ids = array_diff($postids, $jobs_notified);
            if ($notify_ids && sizeof($notify_ids) > 0) {
                foreach ($notify_ids as $id) {
                    update_post_meta($id, 'reminder_email_sent', '5');
                    jr_owner_job_expiring_soon($id, 5);
                }
            }
        }
        // Get list of expiring posts (1 day left) that are published
        $postids = $wpdb->get_col($wpdb->prepare("\n\t\t\tSELECT      postmeta.post_id\n\t\t\tFROM        {$wpdb->postmeta} postmeta\n\t\t\tLEFT JOIN\t{$wpdb->posts} posts ON postmeta.post_id = posts.ID\n\t\t\tWHERE       postmeta.meta_key = '_expires' \n\t\t\t            AND postmeta.meta_value > '%s'\n\t\t\t            AND postmeta.meta_value < '%s'\n\t\t\t            AND post_status = 'publish'\n\t\t\t            AND post_type = 'job_listing'\n\t\t", strtotime('NOW'), strtotime('+1 day')));
        if (sizeof($postids) > 0) {
            // of those, get ids of posts that have already been notified
            $jobs_notified = $wpdb->get_col($wpdb->prepare("\n\t\t\t\tSELECT      postmeta.post_id\n\t\t\t\tFROM        {$wpdb->postmeta} postmeta\n\t\t\t\tWHERE       postmeta.meta_key = 'reminder_email_sent' \n\t\t\t\t            AND postmeta.meta_value IN ('1')\n\t\t\t", implode(',', $postids)));
            // Now only send to those who need sending to
            $notify_ids_2 = array_diff($postids, $jobs_notified, $notify_ids);
            if ($notify_ids_2 && sizeof($notify_ids_2) > 0) {
                foreach ($notify_ids_2 as $id) {
                    update_post_meta($id, 'reminder_email_sent', '1');
                    jr_owner_job_expiring_soon($id, 1);
                }
            }
        }
    }
}
Example #14
0
 static function admin_init()
 {
     // WordPress 3.5+ compat: the WP devs are in the midst of removing Links from the WordPress core. Eventually we'll have to deal
     // with the possible disappearance of the wp_links table as a whole; but in the meantime, we just need to turn on the interface
     // element to avoid problems with user capabilities that presume the presence of the Links Manager in the admin UI.
     if (!intval(get_option('link_manager_enabled', false))) {
         update_option('link_manager_enabled', true);
     }
     if (defined('FEEDWORDPRESS_PREPARE_TO_ZAP') and FEEDWORDPRESS_PREPARE_TO_ZAP) {
         $post_id = FEEDWORDPRESS_PREPARE_TO_ZAP;
         $sendback = wp_get_referer();
         if (!$sendback or strpos($sendback, 'post.php') !== false or strpos($sendback, 'post-new.php') !== false) {
             if ('attachment' == $post_type) {
                 $sendback = admin_url('upload.php');
             } else {
                 $sendback = admin_url('edit.php');
                 $sendback .= !empty($post_type) ? '?post_type=' . $post_type : '';
             }
         } else {
             $sendback = esc_url(remove_query_arg(array('trashed', 'untrashed', 'deleted', 'zapped', 'unzapped', 'ids'), $sendback));
         }
         // Make sure we have a post corresponding to this ID.
         $post = $post_type = $post_type_object = null;
         if ($post_id) {
             $post = get_post($post_id);
         }
         if ($post) {
             $post_type = $post->post_type;
         }
         $p = get_post($post_id);
         if (!$post) {
             wp_die(__('The item you are trying to zap no longer exists.'));
         }
         if (!current_user_can('delete_post', $post_id)) {
             wp_die(__('You are not allowed to zap this item.'));
         }
         if ($user_id = wp_check_post_lock($post_id)) {
             $user = get_userdata($user_id);
             wp_die(sprintf(__('You cannot retire this item. %s is currently editing.'), $user->display_name));
         }
         if (MyPHP::request('fwp_post_delete') == 'zap') {
             FeedWordPress::diagnostic('syndicated_posts', 'Zapping existing post # ' . $p->ID . ' "' . $p->post_title . '" due to user request.');
             $old_status = $post->post_status;
             set_post_field('post_status', 'fwpzapped', $post_id);
             wp_transition_post_status('fwpzapped', $old_status, $post);
             # Set up the post to have its content blanked on
             # next update if you do not undo the zapping.
             add_post_meta($post_id, '_feedwordpress_zapped_blank_me', 1, true);
             add_post_meta($post_id, '_feedwordpress_zapped_blank_old_status', $old_status, true);
             wp_redirect(esc_url_raw(add_query_arg(array('zapped' => 1, 'ids' => $post_id), $sendback)));
         } else {
             $old_status = get_post_meta($post_id, '_feedwordpress_zapped_blank_old_status', true);
             set_post_field('post_status', $old_status, $post_id);
             wp_transition_post_status($old_status, 'fwpzapped', $post);
             # O.K., make sure this post does not get blanked
             delete_post_meta($post_id, '_feedwordpress_zapped_blank_me');
             delete_post_meta($post_id, '_feedwordpress_zapped_blank_old_status');
             wp_redirect(esc_url_raw(add_query_arg(array('unzapped' => 1, 'ids' => $post_id), $sendback)));
         }
         // Intercept, don't pass on.
         exit;
     }
 }
/**
 * Update the status of a post.
 *
 * @param int $post_id The post ID
 * @param string $status The new status
 */
function wl_update_post_status($post_id, $status)
{
    wl_write_log("wl_update_post_status [ post ID :: {$post_id} ][ status :: {$status} ]");
    global $wpdb;
    if (!($post = get_post($post_id))) {
        return;
    }
    if ($status === $post->post_status) {
        return;
    }
    $wpdb->update($wpdb->posts, array('post_status' => $status), array('ID' => $post->ID));
    clean_post_cache($post->ID);
    $old_status = $post->post_status;
    $post->post_status = $status;
    wp_transition_post_status($status, $old_status, $post);
    /** This action is documented in wp-includes/post.php */
    do_action('edit_post', $post->ID, $post);
    /** This action is documented in wp-includes/post.php */
    do_action("save_post_{$post->post_type}", $post->ID, $post, true);
    /** This action is documented in wp-includes/post.php */
    do_action('wl_linked_data_save_post', $post->ID);
    /** This action is documented in wp-includes/post.php */
    do_action('wp_insert_post', $post->ID, $post, true);
}
Example #16
0
 public function wpTransitionPostStatus($new_status, $old_status, $post)
 {
     wp_transition_post_status($new_status, $old_status, $post);
 }
Example #17
0
function wp_publish_post($post_id)
{
    global $wpdb;
    $post = get_post($post_id);
    if (empty($post)) {
        return;
    }
    if ('publish' == $post->post_status) {
        return;
    }
    $wpdb->query("UPDATE {$wpdb->posts} SET post_status = 'publish' WHERE ID = '{$post_id}'");
    $old_status = $post->post_status;
    $post->post_status = 'publish';
    wp_transition_post_status('publish', $old_status, $post);
    do_action('edit_post', $post_id, $post);
    do_action('save_post', $post_id, $post);
    do_action('wp_insert_post', $post_id, $post);
}
Example #18
0
 public function import_deindex_post($post_ids)
 {
     // sets a post's status to draft so that it no longer appears in searches
     // TODO: need to find a better status to hide it from searches,
     // but not invalidate incoming links or remove comments
     global $wpdb;
     foreach ((array) $post_ids as $post_id) {
         $post_id = absint($post_id);
         if (!$post_id) {
             continue;
         }
         // set the post to draft (TODO: use a WP function instead of writing to DB)
         $wpdb->get_results("UPDATE {$wpdb->posts} SET post_status = 'draft' WHERE ID = {$post_id}");
         // clear the post/page cache
         clean_page_cache($post_id);
         clean_post_cache($post_id);
         // do the post transition
         wp_transition_post_status('draft', 'publish', $post_id);
     }
 }
	function process_retirements ($delta) {
		global $post;

		$q = new WP_Query(array(
		'fields' => '_synfrom',
		'post_status__not' => 'fwpretired',
		'ignore_sticky_posts' => true,
		'meta_key' => '_feedwordpress_retire_me_'.$this->id,
		'meta_value' => '1',
		));
		if ($q->have_posts()) :
			foreach ($q->posts as $p) :
				$old_status = $p->post_status;
				FeedWordPress::diagnostic('syndicated_posts', 'Retiring existing post # '.$p->ID.' "'.$p->post_title.'" due to absence from a non-incremental feed.');
				set_post_field('post_status', 'fwpretired', $p->ID);
				wp_transition_post_status('fwpretired', $old_status, $p);
				delete_post_meta($p->ID, '_feedwordpress_retire_me_'.$this->id);
			endforeach;
		endif;
		return $delta;
	}
Example #20
0
 /**
  * Handles saving updates from the product editor
  *
  * Saves all product related information which includes core product data
  * and supporting elements such as images, digital downloads, tags,
  * assigned categories, specs and pricing variations.
  *
  * @author Jonathan Davis
  * @since 1.0
  *
  * @param Product $Product
  * @return void
  **/
 public function save(ShoppProduct $Product)
 {
     check_admin_referer('shopp-save-product');
     if (!current_user_can('shopp_products')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     ShoppSettings()->saveform();
     // Save workflow setting
     $status = $Product->status;
     // Set publish date
     if ('publish' == $_POST['status']) {
         $publishing = isset($_POST['publish']) ? $_POST['publish'] : array();
         $fields = array('month' => '', 'date' => '', 'year' => '', 'hour' => '', 'minute' => '', 'meridiem' => '');
         $publishdate = join('', array_merge($fields, $publishing));
         if (!empty($publishdate)) {
             $publish =& $_POST['publish'];
             if ($publish['meridiem'] == "PM" && $publish['hour'] < 12) {
                 $publish['hour'] += 12;
             }
             $publish = mktime($publish['hour'], $publish['minute'], 0, $publish['month'], $publish['date'], $publish['year']);
             $Product->status = 'future';
             unset($_POST['status']);
         } else {
             unset($_POST['publish']);
             // Auto set the publish date if not set (or more accurately, if set to an irrelevant timestamp)
             if ($Product->publish <= 86400) {
                 $Product->publish = null;
             }
         }
     } else {
         unset($_POST['publish']);
         $Product->publish = 0;
     }
     // Set a unique product slug
     if (empty($Product->slug)) {
         $Product->slug = sanitize_title($_POST['name']);
     }
     $Product->slug = wp_unique_post_slug($Product->slug, $Product->id, $Product->status, ShoppProduct::posttype(), 0);
     $Product->featured = 'off';
     if (isset($_POST['content'])) {
         $_POST['description'] = $_POST['content'];
     }
     $Product->updates($_POST, array('meta', 'categories', 'prices', 'tags'));
     do_action('shopp_pre_product_save');
     $Product->save();
     // Remove deleted images
     if (!empty($_POST['deleteImages'])) {
         $deletes = array();
         if (strpos($_POST['deleteImages'], ",") !== false) {
             $deletes = explode(',', $_POST['deleteImages']);
         } else {
             $deletes = array($_POST['deleteImages']);
         }
         $Product->delete_images($deletes);
     }
     // Update image data
     if (!empty($_POST['images']) && is_array($_POST['images'])) {
         $Product->link_images($_POST['images']);
         $Product->save_imageorder($_POST['images']);
         if (!empty($_POST['imagedetails'])) {
             $Product->update_images($_POST['imagedetails']);
         }
     }
     // Update Prices
     if (!empty($_POST['price']) && is_array($_POST['price'])) {
         // Delete prices that were marked for removal
         if (!empty($_POST['deletePrices'])) {
             $deletes = array();
             if (strpos($_POST['deletePrices'], ",")) {
                 $deletes = explode(',', $_POST['deletePrices']);
             } else {
                 $deletes = array($_POST['deletePrices']);
             }
             foreach ($deletes as $option) {
                 $Price = new ShoppPrice($option);
                 $Price->delete();
             }
         }
         $Product->resum();
         // Save prices that there are updates for
         foreach ($_POST['price'] as $i => $priceline) {
             if (empty($priceline['id'])) {
                 $Price = new ShoppPrice();
                 $priceline['product'] = $Product->id;
             } else {
                 $Price = new ShoppPrice($priceline['id']);
             }
             $priceline['sortorder'] = array_search($i, $_POST['sortorder']) + 1;
             $priceline['shipfee'] = Shopp::floatval($priceline['shipfee']);
             if (isset($priceline['recurring']['trialprice'])) {
                 $priceline['recurring']['trialprice'] = Shopp::floatval($priceline['recurring']['trialprice']);
             }
             if ($Price->stock != $priceline['stocked']) {
                 $priceline['stock'] = (int) $priceline['stocked'];
                 do_action('shopp_stock_product', $priceline['stock'], $Price, $Price->stock, $Price->stocklevel);
             } else {
                 unset($priceline['stocked']);
             }
             $Price->updates($priceline);
             $Price->save();
             // Save 'price' meta records after saving the price record
             if (isset($priceline['dimensions']) && is_array($priceline['dimensions'])) {
                 $priceline['dimensions'] = array_map(array('Shopp', 'floatval'), $priceline['dimensions']);
             }
             $settings = array('donation', 'recurring', 'membership', 'dimensions');
             $priceline['settings'] = array();
             foreach ($settings as $setting) {
                 if (!isset($priceline[$setting])) {
                     continue;
                 }
                 $priceline['settings'][$setting] = $priceline[$setting];
             }
             if (!empty($priceline['settings'])) {
                 shopp_set_meta($Price->id, 'price', 'settings', $priceline['settings']);
             }
             if (!empty($priceline['options'])) {
                 shopp_set_meta($Price->id, 'price', 'options', $priceline['options']);
             }
             $Product->sumprice($Price);
             if (!empty($priceline['download'])) {
                 $Price->attach_download($priceline['download']);
             }
             if (!empty($priceline['downloadpath'])) {
                 // Attach file specified by URI/path
                 if (!empty($Price->download->id) || empty($Price->download) && $Price->load_download()) {
                     $File = $Price->download;
                 } else {
                     $File = new ProductDownload();
                 }
                 $stored = false;
                 $tmpfile = sanitize_path($priceline['downloadpath']);
                 $File->storage = false;
                 $Engine = $File->engine();
                 // Set engine from storage settings
                 $File->parent = $Price->id;
                 $File->context = "price";
                 $File->type = "download";
                 $File->name = !empty($priceline['downloadfile']) ? $priceline['downloadfile'] : basename($tmpfile);
                 $File->filename = $File->name;
                 if ($File->found($tmpfile)) {
                     $File->uri = $tmpfile;
                     $stored = true;
                 } else {
                     $stored = $File->store($tmpfile, 'file');
                 }
                 if ($stored) {
                     $File->readmeta();
                     $File->save();
                 }
             }
             // END attach file by path/uri
         }
         // END foreach()
         unset($Price);
     }
     // END if (!empty($_POST['price']))
     $Product->load_sold($Product->id);
     // Refresh accurate product sales stats
     $Product->sumup();
     // Update taxonomies after pricing summary is generated
     // Summary table entry is needed for ProductTaxonomy::recount() to
     // count properly based on aggregate product inventory, see #2968
     foreach (get_object_taxonomies(Product::$posttype) as $taxonomy) {
         $tags = '';
         $taxonomy_obj = get_taxonomy($taxonomy);
         if (isset($_POST['tax_input']) && isset($_POST['tax_input'][$taxonomy])) {
             $tags = $_POST['tax_input'][$taxonomy];
             if (is_array($tags)) {
                 // array = hierarchical, string = non-hierarchical.
                 $tags = array_filter($tags);
             }
         }
         if (current_user_can($taxonomy_obj->cap->assign_terms)) {
             wp_set_post_terms($Product->id, $tags, $taxonomy);
         }
     }
     // Ensure taxonomy counts are updated on status changes, see #2968
     if ($status != $_POST['status']) {
         $Post = new StdClass();
         $Post->ID = $Product->id;
         $Post->post_type = ShoppProduct::$posttype;
         wp_transition_post_status($_POST['status'], $Product->status, $Post);
     }
     if (!empty($_POST['meta']['options'])) {
         $_POST['meta']['options'] = stripslashes_deep($_POST['meta']['options']);
     } else {
         $_POST['meta']['options'] = false;
     }
     // No variation options at all, delete all variation-pricelines
     if (!empty($Product->prices) && is_array($Product->prices) && (empty($_POST['meta']['options']['v']) || empty($_POST['meta']['options']['a']))) {
         foreach ($Product->prices as $priceline) {
             // Skip if not tied to variation options
             if ($priceline->optionkey == 0) {
                 continue;
             }
             if (empty($_POST['meta']['options']['v']) && $priceline->context == "variation" || empty($_POST['meta']['options']['a']) && $priceline->context == "addon") {
                 $Price = new ShoppPrice($priceline->id);
                 $Price->delete();
             }
         }
     }
     // Handle product spec/detail data
     if (!empty($_POST['details']) || !empty($_POST['deletedSpecs'])) {
         // Delete specs queued for removal
         $ids = array();
         $deletes = array();
         if (!empty($_POST['deletedSpecs'])) {
             if (strpos($_POST['deleteImages'], ",") !== false) {
                 $deletes = explode(',', $_POST['deleteImages']);
             } else {
                 $deletes = array($_POST['deletedSpecs']);
             }
             $ids = db::escape($_POST['deletedSpecs']);
             $Spec = new Spec();
             db::query("DELETE FROM {$Spec->_table} WHERE id IN ({$ids})");
         }
         if (is_array($_POST['details'])) {
             foreach ($_POST['details'] as $i => $spec) {
                 if (in_array($spec['id'], $deletes)) {
                     continue;
                 }
                 if (isset($spec['new'])) {
                     $Spec = new Spec();
                     $spec['id'] = '';
                     $spec['parent'] = $Product->id;
                 } else {
                     $Spec = new Spec($spec['id']);
                 }
                 $spec['sortorder'] = array_search($i, $_POST['details-sortorder']) + 1;
                 $Spec->updates($spec);
                 $Spec->save();
             }
         }
     }
     // Save any meta data
     if (isset($_POST['meta']) && is_array($_POST['meta'])) {
         foreach ($_POST['meta'] as $name => $value) {
             if (isset($Product->meta[$name])) {
                 $Meta = $Product->meta[$name];
                 if (is_array($Meta)) {
                     $Meta = reset($Product->meta[$name]);
                 }
             } else {
                 $Meta = new ShoppMetaObject(array('parent' => $Product->id, 'context' => 'product', 'type' => 'meta', 'name' => $name));
             }
             $Meta->parent = $Product->id;
             $Meta->name = $name;
             $Meta->value = $value;
             $Meta->save();
         }
     }
     $Product->load_data();
     // Reload data so everything is fresh for shopp_product_saved
     do_action_ref_array('shopp_product_saved', array(&$Product));
     unset($Product);
 }
Example #21
0
 public function sync_profile_data($result)
 {
     $user = get_user_by('id', $result);
     $ae_users = AE_Users::get_instance();
     $user_data = $ae_users->convert($user);
     $profile = get_post($user_data->user_profile_id);
     if (ae_user_role($result) == FREELANCER && !empty($profile) && $profile->post_type == "profile") {
         //sync profile title
         $args = array('ID' => $user_data->user_profile_id, 'post_title' => $user->display_name);
         wp_update_post($args);
         //sync profile post_status
         global $wpdb;
         if (!($profile = get_post($profile))) {
             return;
         }
         $new_status = isset($user_data->user_available) && $user_data->user_available == "on" ? "publish" : "hide";
         if ($new_status == $profile->post_status) {
             return;
         }
         $wpdb->update($wpdb->posts, array('post_status' => $new_status), array('ID' => $profile->ID));
         clean_post_cache($profile->ID);
         $old_status = $profile->post_status;
         $profile->post_status = $new_status;
         wp_transition_post_status($new_status, $old_status, $profile);
     }
 }
Example #22
0
 public function reject_event($event_id, $user = '', $reason = '')
 {
     global $mdjm, $current_user;
     /* -- Validation -- */
     if (empty($event_id)) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('ERROR: Cannot reject an event without an Event ID in ' . __METHOD__, true);
         }
         return false;
     }
     $event = get_post($event_id);
     $user = !empty($user) ? $user : $current_user->ID;
     $reason = !empty($reason) ? stripslashes($reason) : __('Unavailable');
     $meta_update = array('_mdjm_event_last_updated_by' => $user, '_mdjm_event_rejected' => date('Y-m-d H:i:s'), '_mdjm_event_rejected_by' => $user);
     /* -- Prevent loops whilst updating -- */
     remove_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
     /* -- Initiate actions for status change -- */
     wp_transition_post_status('mdjm-rejected', $event->post_status, $event);
     /* -- Update the post status -- */
     if (wp_update_post(array('ID' => $event_id, 'post_status' => 'mdjm-rejected'))) {
         $result = true;
     } else {
         $result = false;
     }
     /* -- Update the post meta -- */
     foreach ($meta_update as $event_meta_key => $event_meta_value) {
         update_post_meta($event->ID, $event_meta_key, $event_meta_value);
     }
     /* -- Update Journal with event updates -- */
     if (MDJM_JOURNAL == true) {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('	-- Adding journal entry');
         }
         $this->add_journal(array('user' => $user, 'event' => $event->ID, 'comment_content' => 'Event rejected', 'comment_type' => 'mdjm-journal'), array('type' => 'reject-event', 'visibility' => '0'));
     } else {
         if (MDJM_DEBUG == true) {
             MDJM()->debug->log_it('	-- Journalling is disabled');
         }
     }
     add_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
     return $result;
 }
 public function change_status($post, $new_status, $silent = false)
 {
     if (!$post) {
         return false;
     }
     if ($post->post_status == $new_status) {
         return false;
     }
     $old_status = $post->post_status;
     global $wpdb;
     if ($wpdb->update($wpdb->posts, array('post_status' => $new_status), array('ID' => $post->ID))) {
         if (!$silent) {
             wp_transition_post_status($new_status, $old_status, $post);
         }
         return true;
     }
     return false;
 }
Example #24
0
    function edcal_changedate()
    {
        if (!$this->edcal_checknonce()) {
            die;
        }
        header("Content-Type: application/json");
        $this->edcal_addNoCacheHeaders();
        $edcal_postid = isset($_GET['postid']) ? $_GET['postid'] : null;
        $edcal_newDate = isset($_GET['newdate']) ? $_GET['newdate'] : null;
        $edcal_oldDate = isset($_GET['olddate']) ? $_GET['olddate'] : null;
        $edcal_postStatus = isset($_GET['postStatus']) ? $_GET['postStatus'] : null;
        $move_to_drawer = $edcal_newDate == '0000-00-00';
        $move_from_drawer = $edcal_oldDate == '00000000';
        global $post;
        $args = array('posts_id' => $edcal_postid);
        $post = get_post($edcal_postid);
        setup_postdata($post);
        /*
         * Posts in WordPress have more than one date.  There is the GMT date,
         * the date in the local time zone, the modified date in GMT and the
         * modified date in the local time zone.  We update all of them.
         */
        if ($move_from_drawer) {
            /* 
             * Set the date to 'unscheduled' [ie. 0]. We use this date 
             * further down in the concurrency check, and this will make the dates
             * technically off by 10 hours, but it's still the same day. We only do 
             * this for posts that were created as drafts.  Works for now, but
             * we would have to revamp this if we use an actual timestamp check.
             */
            $post->post_date = '0000-00-00 ' . date('H:i:s', strtotime($post->post_date));
        } else {
            if ($move_to_drawer) {
                // echo ( "\r\npost->post_date_gmt=".$post->post_date_gmt);
                $post->post_date_gmt = $post->post_date;
            } else {
                // set the scheduled time as our original time
                $post->post_date_gmt = $post->post_date;
            }
        }
        // echo ( "\r\npost->post_date_gmt = $post->post_date_gmt \r\npost->post_date = $post->post_date");
        /*
         * Error-checking:
         */
        $error = false;
        if (!current_user_can('edit_post', $edcal_postid)) {
            /*
             * This is just a sanity check to make sure that the current
             * user has permission to edit posts.  Most of the time this
             * will never be run because you can't see the calendar unless
             * you are at least an editor.
             */
            $error = EDCAL_PERMISSION_ERROR;
        } else {
            if (date('Y-m-d', strtotime($post->post_date)) != date('Y-m-d', strtotime($edcal_oldDate))) {
                /*
                 * We are doing optimistic concurrency checking on the dates.  If
                 * the user tries to move a post we want to make sure nobody else
                 * has moved that post since the page was last updated.  If the 
                 * old date in the database doesn't match the old date from the
                 * browser then we return an error to the browser along with the
                 * updated post data.
                 */
                $error = EDCAL_CONCURRENCY_ERROR;
            }
        }
        if ($error) {
            // die('error= '.$error);
            ?>
            {
                "error": <?php 
            echo $error;
            ?>
,
                "post" :
            <?php 
            $this->edcal_postJSON($post, false, true);
            ?>
 }
            
            <?php 
            die;
        }
        /*
         * No errors, so let's go create our new post parameters to update
         */
        $updated_post = array();
        $updated_post['ID'] = $edcal_postid;
        if (!$move_to_drawer) {
            $updated_post['post_date'] = $edcal_newDate . substr($post->post_date, strlen($edcal_newDate));
        }
        /*
         * When a user creates a draft and never sets a date or publishes it 
         * then the GMT date will have a timestamp of 00:00:00 to indicate 
         * that the date hasn't been set.  In that case we need to specify
         * an edit date or the wp_update_post function will strip our new
         * date out and leave the post as publish immediately.
         */
        $needsEditDate = preg_match('/^0000/', $post->post_date_gmt);
        if ($needsEditDate) {
            // echo "\r\nneeds edit date\r\n";
            $updated_post['edit_date'] = $edcal_newDate . substr($post->post_date, strlen($edcal_newDate));
        }
        if ($move_to_drawer) {
            $updated_post['post_date_gmt'] = "0000-00-00 00:00:00";
            $updated_post['edit_date'] = $post->post_date;
        } else {
            if ($move_from_drawer) {
                $updated_post['post_date_gmt'] = get_gmt_from_date($post->post_date);
                $updated_post['post_modified_gmt'] = get_gmt_from_date($post->post_date);
            }
        }
        /*
         * We need to make sure to use the GMT formatting for the date.
         */
        if (!$move_to_drawer) {
            $updated_post['post_date_gmt'] = get_gmt_from_date($updated_post['post_date']);
            $updated_post['post_modified'] = $edcal_newDate . substr($post->post_modified, strlen($edcal_newDate));
            $updated_post['post_modified_gmt'] = get_gmt_from_date($updated_post['post_date']);
        }
        if ($edcal_postStatus != $post->post_status) {
            /*
             * We only want to update the post status if it has changed.
             * If the post status has changed that takes a few more steps
             */
            wp_transition_post_status($edcal_postStatus, $post->post_status, $post);
            $updated_post['post_status'] = $edcal_postStatus;
            // Update counts for the post's terms.
            foreach ((array) get_object_taxonomies('post') as $taxonomy) {
                $tt_ids = wp_get_object_terms($post_id, $taxonomy, 'fields=tt_ids');
                wp_update_term_count($tt_ids, $taxonomy);
            }
            do_action('edit_post', $edcal_postid, $post);
            do_action('save_post', $edcal_postid, $post);
            do_action('wp_insert_post', $edcal_postid, $post);
        }
        // die(var_dump($updated_post).'success!');
        /*
         * Now we finally update the post into the database
         */
        wp_update_post($updated_post);
        /*
         * We finish by returning the latest data for the post in the JSON
         */
        global $post;
        $args = array('posts_id' => $edcal_postid);
        $post = get_post($edcal_postid);
        ?>
{
            "post" :
            
        <?php 
        $this->edcal_postJSON($post, false, true);
        ?>
}
        <?php 
        die;
    }
 function store()
 {
     global $wpdb;
     if ($this->filtered()) {
         // This should never happen.
         FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
     }
     $freshness = $this->freshness();
     if ($this->has_fresh_content()) {
         # -- Look up, or create, numeric ID for author
         $this->post['post_author'] = $this->author_id($this->link->setting('unfamiliar author', 'unfamiliar_author', 'create'));
         if (is_null($this->post['post_author'])) {
             FeedWordPress::diagnostic('feed_items:rejected', 'Filtered out item [' . $this->guid() . '] without syndication: no author available');
             $this->post = NULL;
         }
     }
     // We have to check again in case post has been filtered during
     // the author_id lookup
     if ($this->has_fresh_content()) {
         $consider = array('category' => array('abbr' => 'cats', 'domain' => array('category', 'post_tag')), 'post_tag' => array('abbr' => 'tags', 'domain' => array('post_tag')));
         $termSet = array();
         $valid = null;
         foreach ($consider as $what => $taxes) {
             if (!is_null($this->post)) {
                 // Not filtered out yet
                 # -- Look up, or create, numeric ID for categories
                 $taxonomies = $this->link->setting("match/" . $taxes['abbr'], 'match_' . $taxes['abbr'], $taxes['domain']);
                 // Eliminate dummy variables
                 $taxonomies = array_filter($taxonomies, 'remove_dummy_zero');
                 $terms = $this->category_ids($this->feed_terms[$what], $this->link->setting("unfamiliar {$what}", "unfamiliar_{$what}", 'create:' . $what), $taxonomies, array('singleton' => false, 'filters' => true));
                 if (is_null($terms) or is_null($termSet)) {
                     // filtered out -- no matches
                 } else {
                     $valid = true;
                     // filter mode off, or at least one match
                     foreach ($terms as $tax => $term_ids) {
                         if (!isset($termSet[$tax])) {
                             $termSet[$tax] = array();
                         }
                         $termSet[$tax] = array_merge($termSet[$tax], $term_ids);
                     }
                 }
             }
         }
         if (is_null($valid)) {
             // Plonked
             $this->post = NULL;
         } else {
             // We can proceed
             $this->post['tax_input'] = array();
             foreach ($termSet as $tax => $term_ids) {
                 if (!isset($this->post['tax_input'][$tax])) {
                     $this->post['tax_input'][$tax] = array();
                 }
                 $this->post['tax_input'][$tax] = array_merge($this->post['tax_input'][$tax], $term_ids);
             }
             // Now let's add on the feed and global presets
             foreach ($this->preset_terms as $tax => $term_ids) {
                 if (!isset($this->post['tax_input'][$tax])) {
                     $this->post['tax_input'][$tax] = array();
                 }
                 $this->post['tax_input'][$tax] = array_merge($this->post['tax_input'][$tax], $this->category_ids($term_ids, 'create:' . $tax, array($tax), array('singleton' => true)));
             }
         }
     }
     // We have to check again in case the post has been filtered
     // during the category/tags/taxonomy terms lookup
     if ($this->has_fresh_content()) {
         // Filter some individual fields
         // If there already is a post slug (from syndication or by manual
         // editing) don't cause WP to overwrite it by sending in a NULL
         // post_name. Props Chris Fritz 2012-11-28.
         $post_name = is_null($this->_wp_post) ? NULL : $this->_wp_post->post_name;
         // Allow filters to set post slug. Props niska.
         $post_name = apply_filters('syndicated_post_slug', $post_name, $this);
         if (!empty($post_name)) {
             $this->post['post_name'] = $post_name;
         }
         $this->post = apply_filters('syndicated_post', $this->post, $this);
         // Allow for feed-specific syndicated_post filters.
         $this->post = apply_filters("syndicated_post_" . $this->link->uri(), $this->post, $this);
     }
     // Hook in early to make sure these get inserted if at all possible
     add_action('transition_post_status', array($this, 'add_rss_meta'), -10000, 3);
     $ret = false;
     if ($this->has_fresh_content()) {
         $diag = $this->fresh_storage_diagnostic();
         if (!is_null($diag)) {
             FeedWordPress::diagnostic('syndicated_posts', $diag);
         }
         $this->insert_post($this->fresh_content_is_update(), $this->freshness());
         $hook = $this->fresh_storage_hook();
         if (!is_null($hook)) {
             do_action($hook, $this->wp_id(), $this);
         }
         $ret = $this->freshness('status');
     }
     // If this is a legit, non-filtered post, tag it as found on the
     // feed regardless of fresh or stale status
     if (!$this->filtered()) {
         $key = '_feedwordpress_retire_me_' . $this->link->id;
         delete_post_meta($this->wp_id(), $key);
         $status = get_post_field('post_status', $this->wp_id());
         if ('fwpretired' == $status and $this->link->is_non_incremental()) {
             FeedWordPress::diagnostic('syndicated_posts', "Un-retiring previously retired post # " . $this->wp_id() . " due to re-appearance on non-incremental feed.");
             set_post_field('post_status', $this->post['post_status'], $this->wp_id());
             wp_transition_post_status($this->post['post_status'], $status, $this->post);
         } elseif ('fwpzapped' == $status) {
             // Set this new revision up to be
             // blanked on the next update.
             add_post_meta($this->wp_id(), '_feedwordpress_zapped_blank_me', 2, true);
         }
     }
     // Remove add_rss_meta hook
     remove_action('transition_post_status', array($this, 'add_rss_meta'), -10000, 3);
     return $ret;
 }
Example #26
0
 function update_order_status($order_id, $new_status)
 {
     global $wpdb;
     $statuses = array('received' => 'order_received', 'paid' => 'order_paid', 'shipped' => 'order_shipped', 'closed' => 'order_closed');
     if (!array_key_exists($new_status, $statuses)) {
         return false;
     }
     //get the order
     $order = $this->get_order($order_id);
     if (!$order) {
         return false;
     }
     switch ($new_status) {
         case 'paid':
             //update paid time, can't be adjusted as we don't want to loose gateway info
             if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
                 update_post_meta($order->ID, 'mp_paid_time', time());
                 do_action('mp_order_paid', $order);
             }
             break;
         case 'shipped':
             //update paid time if paid step was skipped
             if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
                 update_post_meta($order->ID, 'mp_paid_time', time());
                 do_action('mp_order_paid', $order);
             }
             //update shipped time, can be adjusted
             update_post_meta($order->ID, 'mp_shipped_time', time());
             do_action('mp_order_shipped', $order);
             //send email
             $this->order_shipped_notification($order->ID);
             break;
         case 'closed':
             //update paid time if paid step was skipped
             if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
                 update_post_meta($order->ID, 'mp_paid_time', time());
                 do_action('mp_order_paid', $order);
             }
             //update shipped time if shipped step was skipped
             if (!get_post_meta($order->ID, 'mp_shipped_time', true)) {
                 update_post_meta($order->ID, 'mp_shipped_time', time());
                 do_action('mp_order_shipped', $order);
             }
             //update closed
             update_post_meta($order->ID, 'mp_closed_time', time());
             do_action('mp_order_closed', $order);
             break;
     }
     if ($statuses[$new_status] == $order->post_status) {
         return;
     }
     $wpdb->update($wpdb->posts, array('post_status' => $statuses[$new_status]), array('ID' => $order->ID));
     $old_status = $order->post_status;
     $order->post_status = $statuses[$new_status];
     wp_transition_post_status($statuses[$new_status], $old_status, $order);
 }
Example #27
0
/**
 * Publish a post by transitioning the post status.
 *
 * @since 2.1.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|WP_Post $post Post ID or post object.
 */
function wp_publish_post($post)
{
    global $wpdb;
    if (!($post = get_post($post))) {
        return;
    }
    if ('publish' == $post->post_status) {
        return;
    }
    $wpdb->update($wpdb->posts, array('post_status' => 'publish'), array('ID' => $post->ID));
    clean_post_cache($post->ID);
    $old_status = $post->post_status;
    $post->post_status = 'publish';
    wp_transition_post_status('publish', $old_status, $post);
    /** This action is documented in wp-includes/post.php */
    do_action('edit_post', $post->ID, $post);
    /** This action is documented in wp-includes/post.php */
    do_action("save_post_{$post->post_type}", $post->ID, $post, true);
    /** This action is documented in wp-includes/post.php */
    do_action('save_post', $post->ID, $post, true);
    /** This action is documented in wp-includes/post.php */
    do_action('wp_insert_post', $post->ID, $post, true);
}
Example #28
0
/**
 * Insert a post.
 *
 * If the $postarr parameter has 'ID' set to a value, then post will be updated.
 *
 * You can set the post date manually, but setting the values for 'post_date'
 * and 'post_date_gmt' keys. You can close the comments or open the comments by
 * setting the value for 'comment_status' key.
 *
 * The defaults for the parameter $postarr are:
 *     'post_status'   - Default is 'draft'.
 *     'post_type'     - Default is 'post'.
 *     'post_author'   - Default is current user ID ($user_ID). The ID of the user who added the post.
 *     'ping_status'   - Default is the value in 'default_ping_status' option.
 *                       Whether the attachment can accept pings.
 *     'post_parent'   - Default is 0. Set this for the post it belongs to, if any.
 *     'menu_order'    - Default is 0. The order it is displayed.
 *     'to_ping'       - Whether to ping.
 *     'pinged'        - Default is empty string.
 *     'post_password' - Default is empty string. The password to access the attachment.
 *     'guid'          - Global Unique ID for referencing the attachment.
 *     'post_content_filtered' - Post content filtered.
 *     'post_excerpt'  - Post excerpt.
 *
 * @since 1.0.0
 * @uses $wpdb
 * @uses $user_ID
 * @uses do_action() Calls 'pre_post_update' on post ID if this is an update.
 * @uses do_action() Calls 'edit_post' action on post ID and post data if this is an update.
 * @uses do_action() Calls 'save_post' and 'wp_insert_post' on post id and post data just before returning.
 * @uses apply_filters() Calls 'wp_insert_post_data' passing $data, $postarr prior to database update or insert.
 * @uses wp_transition_post_status()
 *
 * @param array $postarr Elements that make up post to insert.
 * @param bool $wp_error Optional. Allow return of WP_Error on failure.
 * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success.
 */
function wp_insert_post($postarr, $wp_error = false)
{
    global $wpdb, $user_ID;
    $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID, 'ping_status' => get_option('default_ping_status'), 'post_parent' => 0, 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'post_content' => '', 'post_title' => '');
    $postarr = wp_parse_args($postarr, $defaults);
    unset($postarr['filter']);
    $postarr = sanitize_post($postarr, 'db');
    // export array as variables
    extract($postarr, EXTR_SKIP);
    // Are we updating or creating?
    $update = false;
    if (!empty($ID)) {
        $update = true;
        $previous_status = get_post_field('post_status', $ID);
    } else {
        $previous_status = 'new';
    }
    $maybe_empty = !$post_content && !$post_title && !$post_excerpt && post_type_supports($post_type, 'editor') && post_type_supports($post_type, 'title') && post_type_supports($post_type, 'excerpt');
    if (apply_filters('wp_insert_post_empty_content', $maybe_empty, $postarr)) {
        if ($wp_error) {
            return new WP_Error('empty_content', __('Content, title, and excerpt are empty.'));
        } else {
            return 0;
        }
    }
    if (empty($post_type)) {
        $post_type = 'post';
    }
    if (empty($post_status)) {
        $post_status = 'draft';
    }
    if (!empty($post_category)) {
        $post_category = array_filter($post_category);
    }
    // Filter out empty terms
    // Make sure we set a valid category.
    if (empty($post_category) || 0 == count($post_category) || !is_array($post_category)) {
        // 'post' requires at least one category.
        if ('post' == $post_type && 'auto-draft' != $post_status) {
            $post_category = array(get_option('default_category'));
        } else {
            $post_category = array();
        }
    }
    if (empty($post_author)) {
        $post_author = $user_ID;
    }
    $post_ID = 0;
    // Get the post ID and GUID
    if ($update) {
        $post_ID = (int) $ID;
        $guid = get_post_field('guid', $post_ID);
        $post_before = get_post($post_ID);
    }
    // Don't allow contributors to set the post slug for pending review posts
    if ('pending' == $post_status && !current_user_can('publish_posts')) {
        $post_name = '';
    }
    // Create a valid post name. Drafts and pending posts are allowed to have an empty
    // post name.
    if (empty($post_name)) {
        if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) {
            $post_name = sanitize_title($post_title);
        } else {
            $post_name = '';
        }
    } else {
        // On updates, we need to check to see if it's using the old, fixed sanitization context.
        $check_name = sanitize_title($post_name, '', 'old-save');
        if ($update && strtolower(urlencode($post_name)) == $check_name && get_post_field('post_name', $ID) == $check_name) {
            $post_name = $check_name;
        } else {
            // new post, or slug has changed.
            $post_name = sanitize_title($post_name);
        }
    }
    // If the post date is empty (due to having been new or a draft) and status is not 'draft' or 'pending', set date to now
    if (empty($post_date) || '0000-00-00 00:00:00' == $post_date) {
        $post_date = current_time('mysql');
    }
    // validate the date
    $mm = substr($post_date, 5, 2);
    $jj = substr($post_date, 8, 2);
    $aa = substr($post_date, 0, 4);
    $valid_date = wp_checkdate($mm, $jj, $aa, $post_date);
    if (!$valid_date) {
        if ($wp_error) {
            return new WP_Error('invalid_date', __('Whoops, the provided date is invalid.'));
        } else {
            return 0;
        }
    }
    if (empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt) {
        if (!in_array($post_status, array('draft', 'pending', 'auto-draft'))) {
            $post_date_gmt = get_gmt_from_date($post_date);
        } else {
            $post_date_gmt = '0000-00-00 00:00:00';
        }
    }
    if ($update || '0000-00-00 00:00:00' == $post_date) {
        $post_modified = current_time('mysql');
        $post_modified_gmt = current_time('mysql', 1);
    } else {
        $post_modified = $post_date;
        $post_modified_gmt = $post_date_gmt;
    }
    if ('publish' == $post_status) {
        $now = gmdate('Y-m-d H:i:59');
        if (mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false)) {
            $post_status = 'future';
        }
    } elseif ('future' == $post_status) {
        $now = gmdate('Y-m-d H:i:59');
        if (mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false)) {
            $post_status = 'publish';
        }
    }
    if (empty($comment_status)) {
        if ($update) {
            $comment_status = 'closed';
        } else {
            $comment_status = get_option('default_comment_status');
        }
    }
    if (empty($ping_status)) {
        $ping_status = get_option('default_ping_status');
    }
    if (isset($to_ping)) {
        $to_ping = sanitize_trackback_urls($to_ping);
    } else {
        $to_ping = '';
    }
    if (!isset($pinged)) {
        $pinged = '';
    }
    if (isset($post_parent)) {
        $post_parent = (int) $post_parent;
    } else {
        $post_parent = 0;
    }
    // Check the post_parent to see if it will cause a hierarchy loop
    $post_parent = apply_filters('wp_insert_post_parent', $post_parent, $post_ID, compact(array_keys($postarr)), $postarr);
    if (isset($menu_order)) {
        $menu_order = (int) $menu_order;
    } else {
        $menu_order = 0;
    }
    if (!isset($post_password) || 'private' == $post_status) {
        $post_password = '';
    }
    $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);
    // expected_slashed (everything!)
    $data = compact(array('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid'));
    $data = apply_filters('wp_insert_post_data', $data, $postarr);
    $data = stripslashes_deep($data);
    $where = array('ID' => $post_ID);
    if ($update) {
        do_action('pre_post_update', $post_ID);
        if (false === $wpdb->update($wpdb->posts, $data, $where)) {
            if ($wp_error) {
                return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error);
            } else {
                return 0;
            }
        }
    } else {
        if (isset($post_mime_type)) {
            $data['post_mime_type'] = stripslashes($post_mime_type);
        }
        // This isn't in the update
        // If there is a suggested ID, use it if not already present
        if (!empty($import_id)) {
            $import_id = (int) $import_id;
            if (!$wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE ID = %d", $import_id))) {
                $data['ID'] = $import_id;
            }
        }
        if (false === $wpdb->insert($wpdb->posts, $data)) {
            if ($wp_error) {
                return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error);
            } else {
                return 0;
            }
        }
        $post_ID = (int) $wpdb->insert_id;
        // use the newly generated $post_ID
        $where = array('ID' => $post_ID);
    }
    if (empty($data['post_name']) && !in_array($data['post_status'], array('draft', 'pending', 'auto-draft'))) {
        $data['post_name'] = sanitize_title($data['post_title'], $post_ID);
        $wpdb->update($wpdb->posts, array('post_name' => $data['post_name']), $where);
    }
    if (is_object_in_taxonomy($post_type, 'category')) {
        wp_set_post_categories($post_ID, $post_category);
    }
    if (isset($tags_input) && is_object_in_taxonomy($post_type, 'post_tag')) {
        wp_set_post_tags($post_ID, $tags_input);
    }
    // new-style support for all custom taxonomies
    if (!empty($tax_input)) {
        foreach ($tax_input as $taxonomy => $tags) {
            $taxonomy_obj = get_taxonomy($taxonomy);
            if (is_array($tags)) {
                // array = hierarchical, string = non-hierarchical.
                $tags = array_filter($tags);
            }
            if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                wp_set_post_terms($post_ID, $tags, $taxonomy);
            }
        }
    }
    $current_guid = get_post_field('guid', $post_ID);
    // Set GUID
    if (!$update && '' == $current_guid) {
        $wpdb->update($wpdb->posts, array('guid' => get_permalink($post_ID)), $where);
    }
    clean_post_cache($post_ID);
    $post = get_post($post_ID);
    if (!empty($page_template) && 'page' == $data['post_type']) {
        $post->page_template = $page_template;
        $page_templates = wp_get_theme()->get_page_templates();
        if ('default' != $page_template && !isset($page_templates[$page_template])) {
            if ($wp_error) {
                return new WP_Error('invalid_page_template', __('The page template is invalid.'));
            } else {
                return 0;
            }
        }
        update_post_meta($post_ID, '_wp_page_template', $page_template);
    }
    wp_transition_post_status($data['post_status'], $previous_status, $post);
    if ($update) {
        do_action('edit_post', $post_ID, $post);
        $post_after = get_post($post_ID);
        do_action('post_updated', $post_ID, $post_after, $post_before);
    }
    do_action('save_post', $post_ID, $post);
    do_action('wp_insert_post', $post_ID, $post);
    return $post_ID;
}
Example #29
0
/**
 * Publish a post by transitioning the post status.
 *
 * @since 2.1.0
 * @uses $wpdb
 * @uses do_action() Calls 'edit_post', 'save_post', and 'wp_insert_post' on post_id and post data.
 *
 * @param int $post_id Post ID.
 * @return null
 */
function wp_publish_post($post_id)
{
    global $wpdb;
    $post = get_post($post_id);
    if (empty($post)) {
        return;
    }
    if ('publish' == $post->post_status) {
        return;
    }
    $wpdb->update($wpdb->posts, array('post_status' => 'publish'), array('ID' => $post_id));
    $old_status = $post->post_status;
    $post->post_status = 'publish';
    wp_transition_post_status('publish', $old_status, $post);
    // Update counts for the post's terms.
    foreach ((array) get_object_taxonomies('post') as $taxonomy) {
        $tt_ids = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'tt_ids'));
        wp_update_term_count($tt_ids, $taxonomy);
    }
    do_action('edit_post', $post_id, $post);
    do_action('save_post', $post_id, $post);
    do_action('wp_insert_post', $post_id, $post);
}
Example #30
0
function edcal_changedate()
{
    if (!edcal_checknonce()) {
        die;
    }
    header("Content-Type: application/json");
    edcal_addNoCacheHeaders();
    global $edcal_startDate, $edcal_endDate;
    $edcal_postid = isset($_GET['postid']) ? $_GET['postid'] : null;
    $edcal_newDate = isset($_GET['newdate']) ? $_GET['newdate'] : null;
    $edcal_oldDate = isset($_GET['olddate']) ? $_GET['olddate'] : null;
    $edcal_postStatus = isset($_GET['postStatus']) ? $_GET['postStatus'] : null;
    if (!current_user_can('edit_post', $edcal_postid)) {
        global $EDCAL_PERMISSION_ERROR;
        /*
         * This is just a sanity check to make sure that the current
         * user has permission to edit posts.  Most of the time this
         * will never be run because you can't see the calendar unless
         * you are at least an editor
         */
        ?>
        {
            "error": <?php 
        echo $EDCAL_PERMISSION_ERROR;
        ?>
,
        <?php 
        global $post;
        $args = array('posts_id' => $edcal_postid);
        $post = get_post($edcal_postid);
        ?>
            "post" :
        <?php 
        edcal_postJSON($post, false, true);
        ?>
 }
        
        <?php 
        die;
    }
    $post = get_post($edcal_postid, ARRAY_A);
    setup_postdata($post);
    /*
     * We are doing optimistic concurrency checking on the dates.  If
     * the user tries to move a post we want to make sure nobody else
     * has moved that post since the page was last updated.  If the 
     * old date in the database doesn't match the old date from the
     * browser then we return an error to the browser along with the
     * updated post data.
     */
    if (date('Y-m-d', strtotime($post['post_date'])) != date('Y-m-d', strtotime($edcal_oldDate))) {
        global $EDCAL_CONCURRENCY_ERROR;
        ?>
 {
            "error": <?php 
        echo $EDCAL_CONCURRENCY_ERROR;
        ?>
,
        <?php 
        global $post;
        $args = array('posts_id' => $edcal_postid);
        $post = get_post($edcal_postid);
        ?>
            "post" :
        <?php 
        edcal_postJSON($post, false, true);
        ?>
 }
        
        <?php 
        die;
    }
    /*
     * Posts in WordPress have more than one date.  There is the GMT date,
     * the date in the local time zone, the modified date in GMT and the
     * modified date in the local time zone.  We update all of them.
     */
    $post['post_date_gmt'] = $post['post_date'];
    /*
     * When a user creates a draft and never sets a date or publishes it 
     * then the GMT date will have a timestamp of 00:00:00 to indicate 
     * that the date hasn't been set.  In that case we need to specify
     * an edit date or the wp_update_post function will strip our new
     * date out and leave the post as publish immediately.
     */
    $needsEditDate = strpos($post['post_date_gmt'], "0000-00-00 00:00:00") === 0;
    $updated_post = array();
    $updated_post['ID'] = $edcal_postid;
    $updated_post['post_date'] = $edcal_newDate . substr($post['post_date'], strlen($edcal_newDate));
    if ($needsEditDate != -1) {
        $updated_post['edit_date'] = $edcal_newDate . substr($post['post_date'], strlen($edcal_newDate));
    }
    /*
     * We need to make sure to use the GMT formatting for the date.
     */
    $updated_post['post_date_gmt'] = get_gmt_from_date($updated_post['post_date']);
    $updated_post['post_modified'] = $edcal_newDate . substr($post['post_modified'], strlen($edcal_newDate));
    $updated_post['post_modified_gmt'] = get_gmt_from_date($updated_post['post_date']);
    if ($edcal_postStatus != $post['post_status']) {
        /*
         * We only want to update the post status if it has changed.
         * If the post status has changed that takes a few more steps
         */
        wp_transition_post_status($edcal_postStatus, $post['post_status'], $post);
        $updated_post['post_status'] = $edcal_postStatus;
        // Update counts for the post's terms.
        foreach ((array) get_object_taxonomies('post') as $taxonomy) {
            $tt_ids = wp_get_object_terms($post_id, $taxonomy, 'fields=tt_ids');
            wp_update_term_count($tt_ids, $taxonomy);
        }
        do_action('edit_post', $edcal_postid, $post);
        do_action('save_post', $edcal_postid, $post);
        do_action('wp_insert_post', $edcal_postid, $post);
    }
    /*
     * Now we finally update the post into the database
     */
    wp_update_post($updated_post);
    /*
     * We finish by returning the latest data for the post in the JSON
     */
    global $post;
    $args = array('posts_id' => $edcal_postid);
    $post = get_post($edcal_postid);
    ?>
{
        "post" :
        
    <?php 
    edcal_postJSON($post, false, true);
    ?>
}
    <?php 
    die;
}