Example #1
0
    function upgrade()
    {
        //Alternate form in case we're upgrading.
        global $nxt_version;
        $nxtw_options = get_option('nxtw_options');
        $test = get_posts('post_type=wiki');
        if ($nxt_version >= 3.0 && empty($test)) {
            $old_wikis = get_pages('meta_key=_wiki_page&meta_value=1');
            foreach ($old_wikis as $wiki) {
                $wiki->post_type = 'wiki';
                $wiki->ID = null;
                if (nxt_insert_post($wiki) != false) {
                    echo "<p>" . __('Wiki page') . " " . $wiki->post_title . " " . __('successfully upgraded to Wiki post type.') . "</p><br />";
                    nxt_delete_post($wiki->ID);
                }
            }
        }
        $this->upgrade_wiki_editor();
        if (!isset($nxtw_options['number_of_revisions']) && get_option('numberOfRevisions') != false) {
            echo '<input type="hidden" name="nxtw_options[number_of_revisions]" value="' . get_option('numberOfRevisions') . '" />';
        } elseif (empty($nxtw_options['number_of_revisions'])) {
            echo '<input type="hidden" name="nxtw_options[number_of_revisions]" value="5" />';
        }
        delete_option('numberOfRevisions');
        if (!isset($nxtw_options['email_admins']) && get_option('wiki_email_admins') != false) {
            echo '<input type="hidden" name="nxtw_options[email_admins]" value="' . get_option('wiki_email_admins') . '" />';
        } elseif (empty($nxtw_options['email_admins'])) {
            echo '<input type="hidden" name="nxtw_options[email_admins]" value="0" />';
        }
        delete_option('wiki_email_admins');
        if (!isset($nxtw_options['show_toc_onfrontpage']) && get_option('wiki_show_toc_onfrontpage') != false) {
            echo '<input type="hidden" name="nxtw_options[show_toc_onfrontpage]" value="' . get_option('wiki_show_toc_onfrontpage') . '" />';
        } elseif (empty($nxtw_options['show_toc_onfrontpage'])) {
            echo '<input type="hidden" name="nxtw_options[show_toc_onfrontpage]" value="0" />';
        }
        delete_option('wiki_show_toc_onfrontpage');
        if (!isset($nxtw_options['cron_email']) && get_option('wiki_cron_email') != false) {
            echo '<input type="hidden" name="nxtw_options[cron_email]" value="' . get_option('wiki_cron_email') . '" />';
        } elseif (empty($nxtw_options['cron_email'])) {
            echo '<input type="hidden" name="nxtw_options[cron_email]" value="0" />';
        }
        delete_option('wiki_cron_email');
        echo '<input type="hidden" name="nxtw_options[nxtw_upgrade]" value="done_gone_and_upgraded" />';
        echo '
		<tr>
			<td><input class="button-primary" type="submit" value="' . __('Finish Upgrade') . '" /></td>
		</tr>
		';
    }
 /**
  * delete_assignment_screen( $vars )
  *
  * Hooks into screen_handler
  * Delete assignment screen
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function delete_assignment_screen($vars)
 {
     global $bp;
     $assignment = $this->is_assignment($this->current_assignment);
     $nonce_name = 'delete_assignment';
     $is_nonce = false;
     if (isset($_GET['_nxtnonce'])) {
         $is_nonce = nxt_verify_nonce($_GET['_nxtnonce'], $nonce_name);
     }
     if (true != $is_nonce) {
         $vars['die'] = __('Nonce Error while deleting the assignment.', 'bpsp');
         return $vars;
     }
     if ($assignment->post_author == $bp->loggedin_user->id || is_super_admin()) {
         nxt_delete_post($assignment->ID);
     } else {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to delete the assignment.', 'bpsp');
         return $vars;
     }
     $vars['message'] = __('Assignment deleted successfully.', 'bpsp');
     return $this->list_assignments_screen($vars);
 }
Example #3
0
function nxtmu_delete_user($id)
{
    global $nxtdb;
    $id = (int) $id;
    do_action('nxtmu_delete_user', $id);
    $blogs = get_blogs_of_user($id);
    if (!empty($blogs)) {
        foreach ($blogs as $blog) {
            switch_to_blog($blog->userblog_id);
            remove_user_from_blog($id, $blog->userblog_id);
            $post_ids = $nxtdb->get_col($nxtdb->prepare("SELECT ID FROM {$nxtdb->posts} WHERE post_author = %d", $id));
            foreach ((array) $post_ids as $post_id) {
                nxt_delete_post($post_id);
            }
            // Clean links
            $link_ids = $nxtdb->get_col($nxtdb->prepare("SELECT link_id FROM {$nxtdb->links} WHERE link_owner = %d", $id));
            if ($link_ids) {
                foreach ($link_ids as $link_id) {
                    nxt_delete_link($link_id);
                }
            }
            restore_current_blog();
        }
    }
    $nxtdb->query($nxtdb->prepare("DELETE FROM {$nxtdb->users} WHERE ID = %d", $id));
    $nxtdb->query($nxtdb->prepare("DELETE FROM {$nxtdb->usermeta} WHERE user_id = %d", $id));
    clean_user_cache($id);
    // allow for commit transaction
    do_action('deleted_user', $id);
    return true;
}
 /**
  * Remove a post.
  *
  * @since 1.5.0
  *
  * @param array $args Method parameters.
  * @return bool True when post is deleted.
  */
 function blogger_deletePost($args)
 {
     $this->escape($args);
     $post_ID = (int) $args[1];
     $username = $args[2];
     $password = $args[3];
     $publish = $args[4];
     if (!($user = $this->login($username, $password))) {
         return $this->error;
     }
     do_action('xmlrpc_call', 'blogger.deletePost');
     $actual_post = nxt_get_single_post($post_ID, ARRAY_A);
     if (!$actual_post || $actual_post['post_type'] != 'post') {
         return new IXR_Error(404, __('Sorry, no such post.'));
     }
     if (!current_user_can('delete_post', $post_ID)) {
         return new IXR_Error(401, __('Sorry, you do not have the right to delete this post.'));
     }
     $result = nxt_delete_post($post_ID);
     if (!$result) {
         return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be deleted.'));
     }
     return true;
 }
Example #5
0
 /**
  * delete_response_screen( $vars )
  *
  * Hooks into screen_handler
  * Delete response screen
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function delete_response_screen($vars)
 {
     if (is_object($this->current_response)) {
         $response = $this->current_response;
     } else {
         $response = $this->is_response($this->current_response);
     }
     $nonce_name = 'response_delete';
     $is_nonce = false;
     if (isset($_GET['_nxtnonce'])) {
         $is_nonce = nxt_verify_nonce($_GET['_nxtnonce'], $nonce_name);
     }
     if (true != $is_nonce) {
         $vars['die'] = __('Nonce Error while deleting the response.', 'bpsp');
         return $vars;
     }
     if ($this->has_response_caps() || is_super_admin()) {
         nxt_delete_post($response->ID);
         delete_post_meta($this->current_assignment->ID, 'responded_author', $response->post_author);
         if (isset($vars['assignment'])) {
             $vars = $this->populate_responses($vars);
         }
     } else {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to delete the response.', 'bpsp');
         return $vars;
     }
     $vars['name'] = 'single_assignment';
     $vars['message'] = __('Response deleted successfully.', 'bpsp');
     return $vars;
 }
Example #6
0
         foreach ($post_fields as $field) {
             $args[$field] = isset($_POST[$field][$_key]) ? $_POST[$field][$_key] : '';
         }
         $menu_item_db_id = nxt_update_nav_menu_item($nav_menu_selected_id, $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key, $args);
         if (is_nxt_error($menu_item_db_id)) {
             $messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>';
         } elseif (isset($menu_items[$menu_item_db_id])) {
             unset($menu_items[$menu_item_db_id]);
         }
     }
 }
 // Remove menu items from the menu that weren't in $_POST
 if (!empty($menu_items)) {
     foreach (array_keys($menu_items) as $menu_item_id) {
         if (is_nav_menu_item($menu_item_id)) {
             nxt_delete_post($menu_item_id);
         }
     }
 }
 // Store 'auto-add' pages.
 $auto_add = !empty($_POST['auto-add-pages']);
 $nav_menu_option = (array) get_option('nav_menu_options');
 if (!isset($nav_menu_option['auto_add'])) {
     $nav_menu_option['auto_add'] = array();
 }
 if ($auto_add) {
     if (!in_array($nav_menu_selected_id, $nav_menu_option['auto_add'])) {
         $nav_menu_option['auto_add'][] = $nav_menu_selected_id;
     }
 } else {
     if (false !== ($key = array_search($nav_menu_selected_id, $nav_menu_option['auto_add']))) {
Example #7
0
/**
 * Deletes orphaned draft menu items
 *
 * @access private
 * @since 3.0.0
 *
 */
function _nxt_delete_orphaned_draft_menu_items()
{
    global $nxtdb;
    $delete_timestamp = time() - 60 * 60 * 24 * EMPTY_TRASH_DAYS;
    // delete orphaned draft menu items
    $menu_items_to_delete = $nxtdb->get_col($nxtdb->prepare("SELECT ID FROM {$nxtdb->posts} AS p LEFT JOIN {$nxtdb->postmeta} AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp));
    foreach ((array) $menu_items_to_delete as $menu_item_id) {
        nxt_delete_post($menu_item_id, true);
    }
}
Example #8
0
/**
 * Remove user and optionally reassign posts and links to another user.
 *
 * If the $reassign parameter is not assigned to an User ID, then all posts will
 * be deleted of that user. The action 'delete_user' that is passed the User ID
 * being deleted will be run after the posts are either reassigned or deleted.
 * The user meta will also be deleted that are for that User ID.
 *
 * @since 2.0.0
 *
 * @param int $id User ID.
 * @param int $reassign Optional. Reassign posts and links to new User ID.
 * @return bool True when finished.
 */
function nxt_delete_user($id, $reassign = 'novalue')
{
    global $nxtdb;
    $id = (int) $id;
    // allow for transaction statement
    do_action('delete_user', $id);
    if ('novalue' === $reassign || null === $reassign) {
        $post_ids = $nxtdb->get_col($nxtdb->prepare("SELECT ID FROM {$nxtdb->posts} WHERE post_author = %d", $id));
        if ($post_ids) {
            foreach ($post_ids as $post_id) {
                nxt_delete_post($post_id);
            }
        }
        // Clean links
        $link_ids = $nxtdb->get_col($nxtdb->prepare("SELECT link_id FROM {$nxtdb->links} WHERE link_owner = %d", $id));
        if ($link_ids) {
            foreach ($link_ids as $link_id) {
                nxt_delete_link($link_id);
            }
        }
    } else {
        $reassign = (int) $reassign;
        $nxtdb->update($nxtdb->posts, array('post_author' => $reassign), array('post_author' => $id));
        $nxtdb->update($nxtdb->links, array('link_owner' => $reassign), array('link_owner' => $id));
    }
    clean_user_cache($id);
    // FINALLY, delete user
    if (!is_multisite()) {
        $nxtdb->query($nxtdb->prepare("DELETE FROM {$nxtdb->usermeta} WHERE user_id = %d", $id));
        $nxtdb->query($nxtdb->prepare("DELETE FROM {$nxtdb->users} WHERE ID = %d", $id));
    } else {
        $level_key = $nxtdb->get_blog_prefix() . 'capabilities';
        // nxtmu site admins don't have user_levels
        $nxtdb->query("DELETE FROM {$nxtdb->usermeta} WHERE user_id = {$id} AND meta_key = '{$level_key}'");
    }
    // allow for commit transaction
    do_action('deleted_user', $id);
    return true;
}
Example #9
0
         $done = nxt_untrash_post($id);
     }
     if ($done) {
         die('1');
     }
     die('0');
     break;
 case 'delete-page':
     check_ajax_referer("{$action}_{$id}");
     if (!current_user_can('delete_page', $id)) {
         die('-1');
     }
     if (!get_page($id)) {
         die('1');
     }
     if (nxt_delete_post($id)) {
         die('1');
     } else {
         die('0');
     }
     break;
 case 'dim-comment':
     // On success, die with time() instead of 1
     if (!($comment = get_comment($id))) {
         $x = new nxt_Ajax_Response(array('what' => 'comment', 'id' => new nxt_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id))));
         $x->send();
     }
     if (!current_user_can('edit_comment', $comment->comment_ID) && !current_user_can('moderate_comments')) {
         die('-1');
     }
     $current = nxt_get_comment_status($comment->comment_ID);
Example #10
0
 /**
  * delete_schedule_screen( $vars )
  *
  * Hooks into screen_handler
  * Delete schedule screen
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function delete_schedule_screen($vars)
 {
     global $bp;
     $schedule = $this->is_schedule($this->current_schedule);
     $nonce_name = 'delete_schedule';
     $is_nonce = false;
     if (isset($_GET['_nxtnonce'])) {
         $is_nonce = nxt_verify_nonce($_GET['_nxtnonce'], $nonce_name);
     }
     if (true != $is_nonce) {
         $vars['error'] = __('BuddyPress Courseware Nonce Error while deleting a schedule.', 'bpsp');
         return $this->list_schedules_screen($vars);
     }
     if ($this->has_schedule_caps($bp->loggedin_user->id) || is_super_admin()) {
         nxt_delete_post($schedule->ID);
     } else {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to delete a schedule.', 'bpsp');
         return $vars;
     }
     $vars['message'] = __('Schedule deleted successfully.', 'bpsp');
     return $this->list_schedules_screen($vars);
 }
 /**
  * Clean up tables and pages on deactivation.
  */
 public function deactivate()
 {
     // Remove all created tables
     global $nxtdb;
     $delete_tables = array($this->tables->videos, $this->tables->video_usage);
     foreach ($delete_tables as $table) {
         $nxtdb->query("DROP TABLE {$table}");
     }
     // Delete the local playlist page
     $page_id = $this->get_option('playlist_page_id');
     if ($page_id) {
         ClassBlogs_NXTClass::switch_to_blog(ClassBlogs_Settings::get_root_blog_id());
         nxt_delete_post($page_id, true);
         $this->update_option('playlist_page_id', null);
         ClassBlogs_NXTClass::restore_current_blog();
     }
 }
Example #12
0
/**
 * Callback for handling a menu item when its original object is deleted.
 *
 * @since 3.0.0
 * @access private
 *
 * @param int $object_id The ID of the original object being trashed.
 *
 */
function _nxt_delete_tax_menu_item($object_id = 0)
{
    $object_id = (int) $object_id;
    $menu_item_ids = nxt_get_associated_nav_menu_items($object_id, 'taxonomy');
    foreach ((array) $menu_item_ids as $menu_item_id) {
        nxt_delete_post($menu_item_id, true);
    }
}
Example #13
0
 /**
  * Remove the container page for the tag list on deactivation.
  *
  * @since 0.4
  */
 public function deactivate()
 {
     $page_id = $this->get_option('tag_page_id');
     if ($page_id) {
         ClassBlogs_NXTClass::switch_to_blog(ClassBlogs_Settings::get_root_blog_id());
         nxt_delete_post($page_id, true);
         $this->update_option('tag_page_id', null);
         ClassBlogs_NXTClass::restore_current_blog();
     }
 }
Example #14
0
/**
 * Deletes a revision.
 *
 * Deletes the row from the posts table corresponding to the specified revision.
 *
 * @package NXTClass
 * @subpackage Post_Revisions
 * @since 2.6.0
 *
 * @uses nxt_get_post_revision()
 * @uses nxt_delete_post()
 *
 * @param int|object $revision_id Revision ID or revision object.
 * @return mixed Null or nxt_Error if error, deleted post if success.
 */
function nxt_delete_post_revision($revision_id)
{
    if (!($revision = nxt_get_post_revision($revision_id))) {
        return $revision;
    }
    $delete = nxt_delete_post($revision->ID);
    if (is_nxt_error($delete)) {
        return $delete;
    }
    if ($delete) {
        do_action('nxt_delete_post_revision', $revision->ID, $revision);
    }
    return $delete;
}
Example #15
0
/**
 * Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS.
 *
 * @since 2.9.0
 */
function nxt_scheduled_delete()
{
    global $nxtdb;
    $delete_timestamp = time() - 60 * 60 * 24 * EMPTY_TRASH_DAYS;
    $posts_to_delete = $nxtdb->get_results($nxtdb->prepare("SELECT post_id FROM {$nxtdb->postmeta} WHERE meta_key = '_nxt_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);
    foreach ((array) $posts_to_delete as $post) {
        $post_id = (int) $post['post_id'];
        if (!$post_id) {
            continue;
        }
        $del_post = get_post($post_id);
        if (!$del_post || 'trash' != $del_post->post_status) {
            delete_post_meta($post_id, '_nxt_trash_meta_status');
            delete_post_meta($post_id, '_nxt_trash_meta_time');
        } else {
            nxt_delete_post($post_id);
        }
    }
    $comments_to_delete = $nxtdb->get_results($nxtdb->prepare("SELECT comment_id FROM {$nxtdb->commentmeta} WHERE meta_key = '_nxt_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);
    foreach ((array) $comments_to_delete as $comment) {
        $comment_id = (int) $comment['comment_id'];
        if (!$comment_id) {
            continue;
        }
        $del_comment = get_comment($comment_id);
        if (!$del_comment || 'trash' != $del_comment->comment_approved) {
            delete_comment_meta($comment_id, '_nxt_trash_meta_time');
            delete_comment_meta($comment_id, '_nxt_trash_meta_status');
        } else {
            nxt_delete_comment($comment_id);
        }
    }
}
Example #16
0
     }
     $sendback = add_query_arg('untrashed', $untrashed, $sendback);
     break;
 case 'delete':
     $deleted = 0;
     foreach ((array) $post_ids as $post_id) {
         $post_del =& get_post($post_id);
         if (!current_user_can($post_type_object->cap->delete_post, $post_id)) {
             nxt_die(__('You are not allowed to delete this item.'));
         }
         if ($post_del->post_type == 'attachment') {
             if (!nxt_delete_attachment($post_id)) {
                 nxt_die(__('Error in deleting...'));
             }
         } else {
             if (!nxt_delete_post($post_id)) {
                 nxt_die(__('Error in deleting...'));
             }
         }
         $deleted++;
     }
     $sendback = add_query_arg('deleted', $deleted, $sendback);
     break;
 case 'edit':
     if (isset($_REQUEST['bulk_edit'])) {
         $done = bulk_edit_posts($_REQUEST);
         if (is_array($done)) {
             $done['updated'] = count($done['updated']);
             $done['skipped'] = count($done['skipped']);
             $done['locked'] = count($done['locked']);
             $sendback = add_query_arg($done, $sendback);
Example #17
0
     nxt_redirect(add_query_arg('untrashed', 1, $sendback));
     exit;
     break;
 case 'delete':
     check_admin_referer('delete-' . $post_type . '_' . $post_id);
     if (!current_user_can($post_type_object->cap->delete_post, $post_id)) {
         nxt_die(__('You are not allowed to delete this item.'));
     }
     $force = !EMPTY_TRASH_DAYS;
     if ($post->post_type == 'attachment') {
         $force = $force || !MEDIA_TRASH;
         if (!nxt_delete_attachment($post_id, $force)) {
             nxt_die(__('Error in deleting.'));
         }
     } else {
         if (!nxt_delete_post($post_id, $force)) {
             nxt_die(__('Error in deleting.'));
         }
     }
     nxt_redirect(add_query_arg('deleted', 1, $sendback));
     exit;
     break;
 case 'preview':
     check_admin_referer('autosave', 'autosavenonce');
     $url = post_preview();
     nxt_redirect($url);
     exit;
     break;
 default:
     nxt_redirect(admin_url('edit.php'));
     exit;
 function step_pages_save()
 {
     global $nxtdb;
     if (isset($_POST['submit']) && isset($_POST['bp_pages'])) {
         check_admin_referer('bpwizard_pages');
         // Make sure that the pages are created on the bp_get_root_blog_id(), no matter which Dashboard the setup is being run on
         if (!empty($nxtdb->blogid) && $nxtdb->blogid != bp_get_root_blog_id() && !defined('BP_ENABLE_MULTIBLOG')) {
             switch_to_blog(bp_get_root_blog_id());
         }
         // Delete any existing pages
         $existing_pages = bp_core_update_get_page_meta('bp-pages');
         foreach ((array) $existing_pages as $page_id) {
             nxt_delete_post($page_id, true);
         }
         $blog_pages = $this->setup_pages((array) $_POST['bp_pages']);
         bp_update_option('bp-pages', $blog_pages);
         if (!empty($nxtdb->blogid) && $nxtdb->blogid != bp_get_root_blog_id() && !defined('BP_ENABLE_MULTIBLOG')) {
             restore_current_blog();
         }
         return true;
     }
     return false;
 }
Example #19
0
/**
 * Default post information to use when populating the "Write Post" form.
 *
 * @since 2.0.0
 *
 * @param string $post_type A post type string, defaults to 'post'.
 * @return object stdClass object containing all the default post data as attributes
 */
function get_default_post_to_edit($post_type = 'post', $create_in_db = false)
{
    global $nxtdb;
    $post_title = '';
    if (!empty($_REQUEST['post_title'])) {
        $post_title = esc_html(stripslashes($_REQUEST['post_title']));
    }
    $post_content = '';
    if (!empty($_REQUEST['content'])) {
        $post_content = esc_html(stripslashes($_REQUEST['content']));
    }
    $post_excerpt = '';
    if (!empty($_REQUEST['excerpt'])) {
        $post_excerpt = esc_html(stripslashes($_REQUEST['excerpt']));
    }
    if ($create_in_db) {
        // Cleanup old auto-drafts more than 7 days old
        $old_posts = $nxtdb->get_col("SELECT ID FROM {$nxtdb->posts} WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date");
        foreach ((array) $old_posts as $delete) {
            nxt_delete_post($delete, true);
        }
        // Force delete
        $post_id = nxt_insert_post(array('post_title' => __('Auto Draft'), 'post_type' => $post_type, 'post_status' => 'auto-draft'));
        $post = get_post($post_id);
        if (current_theme_supports('post-formats') && post_type_supports($post->post_type, 'post-formats') && get_option('default_post_format')) {
            set_post_format($post, get_option('default_post_format'));
        }
    } else {
        $post = new stdClass();
        $post->ID = 0;
        $post->post_author = '';
        $post->post_date = '';
        $post->post_date_gmt = '';
        $post->post_password = '';
        $post->post_type = $post_type;
        $post->post_status = 'draft';
        $post->to_ping = '';
        $post->pinged = '';
        $post->comment_status = get_option('default_comment_status');
        $post->ping_status = get_option('default_ping_status');
        $post->post_pingback = get_option('default_pingback_flag');
        $post->post_category = get_option('default_category');
        $post->page_template = 'default';
        $post->post_parent = 0;
        $post->menu_order = 0;
    }
    $post->post_content = apply_filters('default_content', $post_content, $post);
    $post->post_title = apply_filters('default_title', $post_title, $post);
    $post->post_excerpt = apply_filters('default_excerpt', $post_excerpt, $post);
    $post->post_name = '';
    return $post;
}