Passed
Push — 217-feature/delete-posts-by-po... ( 407d9c...55fb71 )
by Rajan
06:17
created

PostsMetabox::delete_sticky_posts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace BulkWP\BulkDelete\Core\Posts;
3
4
use BulkWP\BulkDelete\Core\Base\BaseMetabox;
5
6 1
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
7
8
/**
9
 * Metabox for deleting posts.
10
 *
11
 * @since 6.0.0
12
 */
13
abstract class PostsMetabox extends BaseMetabox {
14
	public function filter_js_array( $js_array ) {
15
		$js_array['msg']['deletePostsWarning'] = __( 'Are you sure you want to delete all the posts based on the selected option?', 'bulk-delete' );
16
		$js_array['msg']['selectPostOption']   = __( 'Please select posts from at least one option', 'bulk-delete' );
17
18
		$js_array['validators']['delete_posts_by_category'] = 'validateSelect2';
19
		$js_array['error_msg']['delete_posts_by_category']  = 'selectCategory';
20
		$js_array['msg']['selectCategory']                  = __( 'Please select at least one category', 'bulk-delete' );
21
22
		$js_array['validators']['delete_posts_by_tag']     = 'validateSelect2';
23
		$js_array['error_msg']['delete_posts_by_category'] = 'selectTag';
24
		$js_array['msg']['selectTag']                      = __( 'Please select at least one tag', 'bulk-delete' );
25
26
		$js_array['validators']['delete_posts_by_url'] = 'validateUrl';
27
		$js_array['error_msg']['delete_posts_by_url']  = 'enterUrl';
28
		$js_array['msg']['enterUrl']                   = __( 'Please enter at least one post url', 'bulk-delete' );
29
30
		$js_array['dt_iterators'][] = '_cats';
31
		$js_array['dt_iterators'][] = '_tags';
32
		$js_array['dt_iterators'][] = '_taxs';
33
		$js_array['dt_iterators'][] = '_types';
34
		$js_array['dt_iterators'][] = '_post_status';
35
36
		return $js_array;
37
	}
38
39
	/**
40
	 * Delete sticky posts.
41
	 *
42
	 * @param bool $force_delete Whether to bypass trash and force deletion.
43
	 *
44
	 * @return the deteted post count.
0 ignored issues
show
Bug introduced by
The type BulkWP\BulkDelete\Core\Posts\the was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
	 */
46
	public function delete_sticky_posts( $force_delete ) {
47
		$sticky_post_ids = get_option( 'sticky_posts' );
48
49
		foreach ( $sticky_post_ids as $sticky_post_id ) {
50
			wp_delete_post( $sticky_post_id, $force_delete );
51
		}
52
53
		return count( $sticky_post_ids );
54
	}
55
56
	/**
57
	 * Get the list of post statuses.
58
	 *
59
	 * This includes all custom post status, but excludes built-in private posts.
60
	 *
61
	 * @return array List of post status objects.
62
	 */
63
	public function get_post_statuses(){
64
		return bd_get_post_statuses();
65
	}
66
}
67