/**
  * Process the request for deleting users by meta.
  *
  * @since 5.5
  */
 public function process()
 {
     $delete_options = array();
     $delete_options['meta_key'] = array_get($_POST, 'smbd_u_meta_key');
     $delete_options['meta_compare'] = array_get($_POST, 'smbd_u_meta_compare', '=');
     $delete_options['meta_value'] = array_get($_POST, 'smbd_u_meta_value');
     $delete_options['login_restrict'] = array_get_bool($_POST, "smbd_{$this->field_slug}_login_restrict", false);
     $delete_options['login_days'] = absint(array_get($_POST, "smbd_{$this->field_slug}_login_days", 0));
     $delete_options['no_posts'] = array_get_bool($_POST, "smbd_{$this->field_slug}_no_posts", false);
     $delete_options['limit_to'] = absint(array_get($_POST, "smbd_{$this->field_slug}_limit_to", 0));
     $this->process_delete($delete_options);
 }
Exemple #2
0
 /**
  * Gets a boolean value from the COOKIE data.
  *
  * \param $key
  *   The name of the boolean.
  *
  * \param $default
  *   The default value to return if no valid boolean was found. If you omit
  *   this parameter, null is used.
  *
  * \return
  *   A string or the default value.
  *
  * \see array_get_bool
  */
 public static function cookie_bool($key, $default = null)
 {
     return array_get_bool($_COOKIE, $key, $default);
 }
 /**
  * Controller for deleting comment meta fields.
  *
  * @static
  * @since  5.4
  */
 public static function do_delete_comment_meta()
 {
     $delete_options = array();
     $delete_options['post_type'] = esc_sql(array_get($_POST, 'smbd_cm_post_type', 'post'));
     $delete_options['use_value'] = array_get_bool($_POST, 'smbd_cm_use_value', false);
     $delete_options['meta_key'] = esc_sql(array_get($_POST, 'smbd_cm_key', ''));
     $delete_options['limit_to'] = absint(array_get($_POST, 'smbd_cm_limit_to', 0));
     $delete_options['restrict'] = array_get_bool($_POST, 'smbd_cm_restrict', false);
     $delete_options['op'] = esc_sql(array_get($_POST, 'smbd_cm_op', 'before'));
     $delete_options['days'] = absint(array_get($_POST, 'smbd_cm_days', 0));
     /**
      * Delete comment-meta delete options filter.
      * This filter is for processing filtering options for deleting comment meta
      *
      * @since 5.4
      */
     $delete_options = apply_filters('bd_delete_comment_meta_options', $delete_options, $_POST);
     if ('true' == array_get($_POST, 'smbd_cm_cron', 'false')) {
         $freq = $_POST['smbd_cm_cron_freq'];
         $time = strtotime($_POST['smbd_cm_cron_start']) - get_option('gmt_offset') * 60 * 60;
         if ($freq == -1) {
             wp_schedule_single_event($time, self::CRON_HOOK, array($delete_options));
         } else {
             wp_schedule_event($time, $freq, self::CRON_HOOK, array($delete_options));
         }
         $msg = __('Comment meta fields from the comments with the selected criteria are scheduled for deletion.', 'bulk-delete') . ' ' . sprintf(__('See the full list of <a href = "%s">scheduled tasks</a>', 'bulk-delete'), get_bloginfo('wpurl') . '/wp-admin/admin.php?page=' . Bulk_Delete::CRON_PAGE_SLUG);
     } else {
         $deleted_count = self::delete_comment_meta($delete_options);
         $msg = sprintf(_n('Deleted comment meta field from %d comment', 'Deleted comment meta field from %d comments', $deleted_count, 'bulk-delete'), $deleted_count);
     }
     add_settings_error(Bulk_Delete_Meta::META_PAGE_SLUG, 'deleted-comments', $msg, 'updated');
 }
 /**
  * Process the request for deleting users by role.
  *
  * @since 5.5
  */
 public function process()
 {
     $delete_options = array();
     $delete_options['selected_roles'] = array_get($_POST, 'smbd_u_roles');
     $delete_options['no_posts'] = array_get_bool($_POST, "smbd_{$this->field_slug}_no_posts", false);
     $delete_options['login_restrict'] = array_get_bool($_POST, "smbd_{$this->field_slug}_login_restrict", false);
     $delete_options['login_days'] = absint(array_get($_POST, "smbd_{$this->field_slug}_login_days", 0));
     $delete_options['limit_to'] = absint(array_get($_POST, "smbd_{$this->field_slug}_limit_to", 0));
     $this->process_delete($delete_options);
 }
 /**
  * Helper function for processing deletion.
  * Setups up cron and invokes the actual delete method.
  *
  * @since 5.5
  */
 protected function process_delete($delete_options)
 {
     if (array_get_bool($_POST, 'smbd_' . $this->field_slug . '_cron', false)) {
         $freq = $_POST['smbd_' . $this->field_slug . '_cron_freq'];
         $time = strtotime($_POST['smbd_' . $this->field_slug . '_cron_start']) - get_option('gmt_offset') * 60 * 60;
         if (-1 == $freq) {
             wp_schedule_single_event($time, $this->cron_hook, array($delete_options));
         } else {
             wp_schedule_event($time, $freq, $this->cron_hook, array($delete_options));
         }
         $msg = $this->messages['scheduled'] . ' ' . sprintf(__('See the full list of <a href = "%s">scheduled tasks</a>', 'bulk-delete'), get_bloginfo('wpurl') . '/wp-admin/admin.php?page=' . Bulk_Delete::CRON_PAGE_SLUG);
     } else {
         $deleted_count = $this->delete($delete_options);
         $msg = sprintf(_n($this->messages['deleted_single'], $this->messages['deleted_plural'], $deleted_count, 'bulk-delete'), $deleted_count);
     }
     add_settings_error($this->page_slug, 'deleted-' . $this->item_type, $msg, 'updated');
 }
 /**
  * Delete posts by url
  *
  * @static
  * @since 5.0
  */
 public static function do_delete_posts_by_url()
 {
     $force_delete = array_get_bool($_POST, 'smbd_specific_force_delete', false);
     $urls = preg_split('/\\r\\n|\\r|\\n/', array_get($_POST, 'smdb_specific_pages_urls'));
     foreach ($urls as $url) {
         $checkedurl = $url;
         if (substr($checkedurl, 0, 1) == '/') {
             $checkedurl = get_site_url() . $checkedurl;
         }
         $postid = url_to_postid($checkedurl);
         wp_delete_post($postid, $force_delete);
     }
     $deleted_count = count($urls);
     $msg = sprintf(_n('Deleted %d post with the specified urls', 'Deleted %d posts with the specified urls', $deleted_count, 'bulk-delete'), $deleted_count);
     add_settings_error(Bulk_Delete::POSTS_PAGE_SLUG, 'deleted-posts', $msg, 'updated');
 }
 /**
  * Request handler for deleting pages by status
  *
  * @since 5.0
  */
 public static function do_delete_pages_by_status()
 {
     $delete_options = array();
     $delete_options['restrict'] = array_get_bool($_POST, 'smbd_pages_restrict', false);
     $delete_options['limit_to'] = absint(array_get($_POST, 'smbd_pages_limit_to', 0));
     $delete_options['force_delete'] = array_get_bool($_POST, 'smbd_pages_force_delete', false);
     $delete_options['date_op'] = array_get($_POST, 'smbd_pages_op');
     $delete_options['days'] = absint(array_get($_POST, 'smbd_pages_days'));
     $delete_options['publish'] = array_get($_POST, 'smbd_published_pages');
     $delete_options['drafts'] = array_get($_POST, 'smbd_draft_pages');
     $delete_options['pending'] = array_get($_POST, 'smbd_pending_pages');
     $delete_options['future'] = array_get($_POST, 'smbd_future_pages');
     $delete_options['private'] = array_get($_POST, 'smbd_private_pages');
     if ('true' == array_get($_POST, 'smbd_pages_cron', 'false')) {
         $freq = $_POST['smbd_pages_cron_freq'];
         $time = strtotime($_POST['smbd_pages_cron_start']) - get_option('gmt_offset') * 60 * 60;
         if ($freq == -1) {
             wp_schedule_single_event($time, Bulk_Delete::CRON_HOOK_PAGES_STATUS, array($delete_options));
         } else {
             wp_schedule_event($time, $freq, Bulk_Delete::CRON_HOOK_PAGES_STATUS, array($delete_options));
         }
         $msg = __('The selected pages are scheduled for deletion.', 'bulk-delete') . ' ' . sprintf(__('See the full list of <a href = "%s">scheduled tasks</a>', 'bulk-delete'), get_bloginfo('wpurl') . '/wp-admin/admin.php?page=' . Bulk_Delete::CRON_PAGE_SLUG);
     } else {
         $deleted_count = self::delete_pages_by_status($delete_options);
         $msg = sprintf(_n('Deleted %d page', 'Deleted %d pages', $deleted_count, 'bulk-delete'), $deleted_count);
     }
     add_settings_error(Bulk_Delete::PAGES_PAGE_SLUG, 'deleted-cron', $msg, 'updated');
 }
Exemple #8
0
 /**
  * Setup a new database connection.
  *
  * This stores the connection configuration in the database pool.
  * See the AnewtDatabaseConnection (and subclasses) documentation for the
  * description of the settings array.
  *
  * \param $settings
  *   An associative array with connection settings. At least the \c type
  *   key must be provided to specify the database connection type. See
  *   AnewtDatabaseConnection for the possible values.
  * \param $id
  *   The connection id to use for this connection (optional, defaults to
  *   <code>default</code>)
  *
  * \see AnewtDatabaseConnection
  */
 public static function setup_connection($settings, $id = 'default')
 {
     assert('is_assoc_array($settings)');
     assert('array_has_key($settings, "type"); // "type" key must be present in database settings array');
     assert('is_string($id)');
     /* A connection can be setup only once */
     if (array_key_exists($id, AnewtDatabase::$connections)) {
         throw new AnewtDatabaseException('Connection "%s" has been setup already.', $id);
     }
     /* Create an AnewtDatabaseConnection instance */
     $connection_type = $settings['type'];
     switch ($connection_type) {
         case 'sqlite':
             anewt_include('database/backend-sqlite');
             $connection = new AnewtDatabaseConnectionSQLite($settings);
             break;
         case 'mysql':
             anewt_include('database/backend-mysql');
             $connection = new AnewtDatabaseConnectionMySQL($settings);
             break;
         case 'mysql-old':
             anewt_include('database/backend-mysql-old');
             $connection = new AnewtDatabaseConnectionMySQLOld($settings);
             break;
         case 'postgresql':
             anewt_include('database/backend-postgresql');
             $connection = new AnewtDatabaseConnectionPostgreSQL($settings);
             break;
         case 'memcache':
             anewt_include('database/backend-memcache');
             $connection = new AnewtDatabaseConnectionMemcache($settings);
             break;
         default:
             throw new AnewtDatabaseException('Database type "%s" is not supported', $connection_type);
             break;
     }
     /* Connect by default, unless instructed not to */
     if (array_get_bool($settings, 'autoconnect', true)) {
         $connection->connect();
     }
     /* Store the connection instance */
     AnewtDatabase::$connections[$id] = $connection;
 }