Completed
Pull Request — dev/6.0.0 (#307)
by Rajan
12:39 queued 08:52
created

get_success_message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\Posts\Modules;
4
5
use BulkWP\BulkDelete\Core\Posts\PostsModule;
6
7
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
8
9
/**
10
 * Delete Posts by Sticky Post
11
 *
12
 * @since 6.0.0
13
 */
14
class DeletePostsByStickyPostModule extends PostsModule {
15
	/**
16
	 * Base parameters setup.
17
	 */
18
	protected function initialize() {
19
		$this->item_type     = 'posts';
20
		$this->field_slug    = 'sticky_post';
21
		$this->meta_box_slug = 'bd_by_sticky_post';
22
		$this->action        = 'delete_posts_by_sticky_post';
23
		$this->messages      = array(
24
			'box_label'  => __( 'By Sticky Post', 'bulk-delete' ),
25
		);
26
	}
27
28
	/**
29
	 * Render Delete posts by tag box.
30
	 */
31
	public function render() {
32
		if ( ! $this->are_sticky_post_present() ) : ?>
33
			<h4>
34
				<?php _e( 'There are no sticky post present in this WordPress installation.', 'bulk-delete' ); ?>
35
			</h4>
36
			<?php return; ?>
37
		<?php endif; ?>
0 ignored issues
show
Unused Code introduced by
InlineHTMLNode is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
38
39
		<h4><?php _e( 'Select the sticky post from which you want to delete', 'bulk-delete' ); ?></h4>
40
41
		<!-- Tags start-->
42
		<fieldset class="options">
43
			<table class="optiontable">
44
				<tr>
45
					<td scope="row" colspan="2">
46
						<?php $this->render_sticky_post_dropdown(); ?>
47
					</td>
48
				</tr>
49
			</table>
50
51
			<table class="optiontable">
52
				<?php
53
				$this->render_filtering_table_header();
54
				$this->render_sticky_settings();
55
				$this->render_delete_settings();
56
				?>
57
			</table>
58
		</fieldset>
59
<?php
60
		$this->render_submit_button();
61
	}
62
63
	/**
64
	 * Process delete posts user inputs by sticky_post.
65
	 *
66
	 * @param array $request Request array.
67
	 * @param array $options Options for deleting posts.
68
	 *
69
	 * @return array $options  Inputs from user for posts that were need to delete
70
	 */
71
	protected function convert_user_input_to_options( $request, $options ) {
72
		$options['selected_posts'] = bd_array_get( $request, 'smbd_sticky_post' );
73
74
		$options['sticky_option'] = bd_array_get( $request, 'smbd_sticky_post_sticky_option' );
75
76
		return $options;
77
	}
78
79
	protected function build_query( $options ) {
80
		$query = array();
81
82
		if( $options['sticky_option'] == "hide" ){
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal hide does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
83
			foreach( $options['selected_posts'] as $post ){
84
				unstick_post($post);
85
			}
86
		}else{
87
88
			if ( in_array( 'all', $options['selected_posts'], true ) ) {
89
				$query['post__in'] = get_option( 'sticky_posts' );
90
			} else {
91
				$query['post__in'] = $options['selected_posts'];
92
			}
93
94
			return $query;
95
		}
96
	}
97
98
	/**
99
	 * Response message for deleting posts.
100
	 *
101
	 * @param int $items_deleted count of items deleted.
102
	 *
103
	 * @return string Response message
104
	 */
105
	protected function get_success_message( $items_deleted ) {
106
		/* translators: 1 Number of posts deleted */
107
		return _n( 'Deleted %d sticky post', 'Deleted %d sticky posts', $items_deleted, 'bulk-delete' );
108
	}
109
}
110