Completed
Push — develop ( 027051...c8e87b )
by David
03:56 queued 13s
created
src/wordlift/images-licenses/tasks/class-remove-all-images-task.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -7,108 +7,108 @@
 block discarded – undo
7 7
 
8 8
 class Remove_All_Images_Task implements Task {
9 9
 
10
-	const MENU_SLUG = 'wl_remove_all_images_task';
10
+    const MENU_SLUG = 'wl_remove_all_images_task';
11 11
 
12
-	/**
13
-	 * @var Image_License_Service
14
-	 */
15
-	private $image_license_service;
12
+    /**
13
+     * @var Image_License_Service
14
+     */
15
+    private $image_license_service;
16 16
 
17
-	/**
18
-	 * Remove_All_Images_Task constructor.
19
-	 *
20
-	 * @param Image_License_Service $image_license_service
21
-	 */
22
-	public function __construct( $image_license_service ) {
17
+    /**
18
+     * Remove_All_Images_Task constructor.
19
+     *
20
+     * @param Image_License_Service $image_license_service
21
+     */
22
+    public function __construct( $image_license_service ) {
23 23
 
24
-		$this->image_license_service = $image_license_service;
24
+        $this->image_license_service = $image_license_service;
25 25
 
26 26
 
27
-		add_action( 'wp_ajax_' . $this->get_id() . '__single', array( $this, 'ajax', ) );
27
+        add_action( 'wp_ajax_' . $this->get_id() . '__single', array( $this, 'ajax', ) );
28 28
 
29
-	}
29
+    }
30 30
 
31
-	public function ajax() {
31
+    public function ajax() {
32 32
 
33
-		check_ajax_referer( $this->get_id() );
33
+        check_ajax_referer( $this->get_id() );
34 34
 
35
-		$this->process_item( $_POST );
35
+        $this->process_item( $_POST );
36 36
 
37
-		wp_send_json_success();
37
+        wp_send_json_success();
38 38
 
39
-	}
39
+    }
40 40
 
41
-	/**
42
-	 * @inheritDoc
43
-	 */
44
-	function get_id() {
41
+    /**
42
+     * @inheritDoc
43
+     */
44
+    function get_id() {
45 45
 
46
-		return self::MENU_SLUG;
47
-	}
46
+        return self::MENU_SLUG;
47
+    }
48 48
 
49
-	function get_label() {
49
+    function get_label() {
50 50
 
51
-		return __( 'Remove all images', 'wordlift' );
52
-	}
51
+        return __( 'Remove all images', 'wordlift' );
52
+    }
53 53
 
54
-	/**
55
-	 * @inheritDoc
56
-	 */
57
-	function list_items( $limit = 10, $offset = 0 ) {
54
+    /**
55
+     * @inheritDoc
56
+     */
57
+    function list_items( $limit = 10, $offset = 0 ) {
58 58
 
59
-		$data = $this->image_license_service->get_non_public_domain_images();
59
+        $data = $this->image_license_service->get_non_public_domain_images();
60 60
 
61
-		return array_slice( $data, $offset, $limit );
62
-	}
61
+        return array_slice( $data, $offset, $limit );
62
+    }
63 63
 
64
-	/**
65
-	 * @inheritDoc
66
-	 */
67
-	function count_items() {
64
+    /**
65
+     * @inheritDoc
66
+     */
67
+    function count_items() {
68 68
 
69
-		$data = $this->image_license_service->get_non_public_domain_images();
69
+        $data = $this->image_license_service->get_non_public_domain_images();
70 70
 
71
-		return count( $data );
72
-	}
71
+        return count( $data );
72
+    }
73 73
 
74
-	/**
75
-	 * @inheritDoc
76
-	 */
77
-	function process_item( $item ) {
74
+    /**
75
+     * @inheritDoc
76
+     */
77
+    function process_item( $item ) {
78 78
 
79
-		// Avoid deleting images that have been marked as fixed.
80
-		$fixed = get_post_meta( $item['attachment_id'], '_wl_image_license_fixed', true );
81
-		if ( ! empty( $fixed ) ) {
82
-			return;
83
-		}
79
+        // Avoid deleting images that have been marked as fixed.
80
+        $fixed = get_post_meta( $item['attachment_id'], '_wl_image_license_fixed', true );
81
+        if ( ! empty( $fixed ) ) {
82
+            return;
83
+        }
84 84
 
85
-		if ( isset( $item['posts_ids_as_embed'] ) ) {
86
-			foreach ( $item['posts_ids_as_embed'] as $post_id ) {
85
+        if ( isset( $item['posts_ids_as_embed'] ) ) {
86
+            foreach ( $item['posts_ids_as_embed'] as $post_id ) {
87 87
 
88
-				$pathinfo         = pathinfo( $item['filename'] );
89
-				$filename         = $pathinfo['filename'];
90
-				$extension        = $pathinfo['extension'];
91
-				$filename_quote   = preg_quote( $filename, '@' );
92
-				$filename_pattern = $filename_quote . '(?:-\d+x\d+).' . $extension;
88
+                $pathinfo         = pathinfo( $item['filename'] );
89
+                $filename         = $pathinfo['filename'];
90
+                $extension        = $pathinfo['extension'];
91
+                $filename_quote   = preg_quote( $filename, '@' );
92
+                $filename_pattern = $filename_quote . '(?:-\d+x\d+).' . $extension;
93 93
 
94
-				$post         = get_post( $post_id );
95
-				$search       = array(
96
-					'@<a[^>]*href="[^"]+wl/[^"]+' . $filename_pattern . '"[^>]*>(.+?)</a>@',
97
-					'@<img[^>]*src="[^"]+wl/[^"]+' . $filename_pattern . '"[^>]*>@',
98
-				);
99
-				$replace      = array( '$1', '', );
100
-				$post_content = preg_replace( $search, $replace, $post->post_content );
94
+                $post         = get_post( $post_id );
95
+                $search       = array(
96
+                    '@<a[^>]*href="[^"]+wl/[^"]+' . $filename_pattern . '"[^>]*>(.+?)</a>@',
97
+                    '@<img[^>]*src="[^"]+wl/[^"]+' . $filename_pattern . '"[^>]*>@',
98
+                );
99
+                $replace      = array( '$1', '', );
100
+                $post_content = preg_replace( $search, $replace, $post->post_content );
101 101
 
102
-				wp_update_post( array(
103
-					'ID'           => $post_id,
104
-					'post_content' => $post_content,
105
-				) );
102
+                wp_update_post( array(
103
+                    'ID'           => $post_id,
104
+                    'post_content' => $post_content,
105
+                ) );
106 106
 
107
-			}
108
-		}
107
+            }
108
+        }
109 109
 
110
-		wp_delete_attachment( $item['attachment_id'], true );
110
+        wp_delete_attachment( $item['attachment_id'], true );
111 111
 
112
-	}
112
+    }
113 113
 
114 114
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -19,20 +19,20 @@  discard block
 block discarded – undo
19 19
 	 *
20 20
 	 * @param Image_License_Service $image_license_service
21 21
 	 */
22
-	public function __construct( $image_license_service ) {
22
+	public function __construct($image_license_service) {
23 23
 
24 24
 		$this->image_license_service = $image_license_service;
25 25
 
26 26
 
27
-		add_action( 'wp_ajax_' . $this->get_id() . '__single', array( $this, 'ajax', ) );
27
+		add_action('wp_ajax_'.$this->get_id().'__single', array($this, 'ajax',));
28 28
 
29 29
 	}
30 30
 
31 31
 	public function ajax() {
32 32
 
33
-		check_ajax_referer( $this->get_id() );
33
+		check_ajax_referer($this->get_id());
34 34
 
35
-		$this->process_item( $_POST );
35
+		$this->process_item($_POST);
36 36
 
37 37
 		wp_send_json_success();
38 38
 
@@ -48,17 +48,17 @@  discard block
 block discarded – undo
48 48
 
49 49
 	function get_label() {
50 50
 
51
-		return __( 'Remove all images', 'wordlift' );
51
+		return __('Remove all images', 'wordlift');
52 52
 	}
53 53
 
54 54
 	/**
55 55
 	 * @inheritDoc
56 56
 	 */
57
-	function list_items( $limit = 10, $offset = 0 ) {
57
+	function list_items($limit = 10, $offset = 0) {
58 58
 
59 59
 		$data = $this->image_license_service->get_non_public_domain_images();
60 60
 
61
-		return array_slice( $data, $offset, $limit );
61
+		return array_slice($data, $offset, $limit);
62 62
 	}
63 63
 
64 64
 	/**
@@ -68,46 +68,46 @@  discard block
 block discarded – undo
68 68
 
69 69
 		$data = $this->image_license_service->get_non_public_domain_images();
70 70
 
71
-		return count( $data );
71
+		return count($data);
72 72
 	}
73 73
 
74 74
 	/**
75 75
 	 * @inheritDoc
76 76
 	 */
77
-	function process_item( $item ) {
77
+	function process_item($item) {
78 78
 
79 79
 		// Avoid deleting images that have been marked as fixed.
80
-		$fixed = get_post_meta( $item['attachment_id'], '_wl_image_license_fixed', true );
81
-		if ( ! empty( $fixed ) ) {
80
+		$fixed = get_post_meta($item['attachment_id'], '_wl_image_license_fixed', true);
81
+		if ( ! empty($fixed)) {
82 82
 			return;
83 83
 		}
84 84
 
85
-		if ( isset( $item['posts_ids_as_embed'] ) ) {
86
-			foreach ( $item['posts_ids_as_embed'] as $post_id ) {
85
+		if (isset($item['posts_ids_as_embed'])) {
86
+			foreach ($item['posts_ids_as_embed'] as $post_id) {
87 87
 
88
-				$pathinfo         = pathinfo( $item['filename'] );
88
+				$pathinfo         = pathinfo($item['filename']);
89 89
 				$filename         = $pathinfo['filename'];
90 90
 				$extension        = $pathinfo['extension'];
91
-				$filename_quote   = preg_quote( $filename, '@' );
92
-				$filename_pattern = $filename_quote . '(?:-\d+x\d+).' . $extension;
91
+				$filename_quote   = preg_quote($filename, '@');
92
+				$filename_pattern = $filename_quote.'(?:-\d+x\d+).'.$extension;
93 93
 
94
-				$post         = get_post( $post_id );
94
+				$post         = get_post($post_id);
95 95
 				$search       = array(
96
-					'@<a[^>]*href="[^"]+wl/[^"]+' . $filename_pattern . '"[^>]*>(.+?)</a>@',
97
-					'@<img[^>]*src="[^"]+wl/[^"]+' . $filename_pattern . '"[^>]*>@',
96
+					'@<a[^>]*href="[^"]+wl/[^"]+'.$filename_pattern.'"[^>]*>(.+?)</a>@',
97
+					'@<img[^>]*src="[^"]+wl/[^"]+'.$filename_pattern.'"[^>]*>@',
98 98
 				);
99
-				$replace      = array( '$1', '', );
100
-				$post_content = preg_replace( $search, $replace, $post->post_content );
99
+				$replace      = array('$1', '',);
100
+				$post_content = preg_replace($search, $replace, $post->post_content);
101 101
 
102
-				wp_update_post( array(
102
+				wp_update_post(array(
103 103
 					'ID'           => $post_id,
104 104
 					'post_content' => $post_content,
105
-				) );
105
+				));
106 106
 
107 107
 			}
108 108
 		}
109 109
 
110
-		wp_delete_attachment( $item['attachment_id'], true );
110
+		wp_delete_attachment($item['attachment_id'], true);
111 111
 
112 112
 	}
113 113
 
Please login to merge, or discard this patch.
wordlift/images-licenses/tasks/class-add-license-caption-or-remove-task.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -7,116 +7,116 @@
 block discarded – undo
7 7
 
8 8
 class Add_License_Caption_Or_Remove_Task extends Remove_All_Images_Task {
9 9
 
10
-	const MENU_SLUG = 'wl_add_license_caption_or_remove';
10
+    const MENU_SLUG = 'wl_add_license_caption_or_remove';
11 11
 
12
-	/**
13
-	 * @var Image_License_Service
14
-	 */
15
-	private $image_license_service;
12
+    /**
13
+     * @var Image_License_Service
14
+     */
15
+    private $image_license_service;
16 16
 
17
-	/**
18
-	 * Remove_All_Images_Task constructor.
19
-	 *
20
-	 * @param Image_License_Service $image_license_service
21
-	 */
22
-	public function __construct( $image_license_service ) {
23
-		parent::__construct( $image_license_service );
17
+    /**
18
+     * Remove_All_Images_Task constructor.
19
+     *
20
+     * @param Image_License_Service $image_license_service
21
+     */
22
+    public function __construct( $image_license_service ) {
23
+        parent::__construct( $image_license_service );
24 24
 
25
-		$this->image_license_service = $image_license_service;
25
+        $this->image_license_service = $image_license_service;
26 26
 
27
-		add_action( 'wp_ajax_' . $this->get_id() . '__single', array( $this, 'ajax', ) );
27
+        add_action( 'wp_ajax_' . $this->get_id() . '__single', array( $this, 'ajax', ) );
28 28
 
29
-	}
29
+    }
30 30
 
31
-	public function ajax() {
31
+    public function ajax() {
32 32
 
33
-		check_ajax_referer( $this->get_id() );
33
+        check_ajax_referer( $this->get_id() );
34 34
 
35
-		$this->process_item( $_POST );
35
+        $this->process_item( $_POST );
36 36
 
37
-		wp_send_json_success();
37
+        wp_send_json_success();
38 38
 
39
-	}
39
+    }
40 40
 
41
-	/**
42
-	 * @inheritDoc
43
-	 */
44
-	function get_id() {
41
+    /**
42
+     * @inheritDoc
43
+     */
44
+    function get_id() {
45 45
 
46
-		return self::MENU_SLUG;
47
-	}
46
+        return self::MENU_SLUG;
47
+    }
48 48
 
49
-	function get_label() {
49
+    function get_label() {
50 50
 
51
-		return __( 'Add license caption to images and remove those with unknown license', 'wordlift' );
52
-	}
51
+        return __( 'Add license caption to images and remove those with unknown license', 'wordlift' );
52
+    }
53 53
 
54
-	/**
55
-	 * @inheritDoc
56
-	 */
57
-	function process_item( $item ) {
54
+    /**
55
+     * @inheritDoc
56
+     */
57
+    function process_item( $item ) {
58 58
 
59
-		$is_unknown_license = '#N/A' === $item['license'];
59
+        $is_unknown_license = '#N/A' === $item['license'];
60 60
 
61
-		// If the license is unknown, delete the attachment.
62
-		if ( $is_unknown_license ) {
63
-			parent::process_item( $item );
61
+        // If the license is unknown, delete the attachment.
62
+        if ( $is_unknown_license ) {
63
+            parent::process_item( $item );
64 64
 
65
-			return;
66
-		}
65
+            return;
66
+        }
67 67
 
68
-		$caption_builder = new Caption_Builder( $item );
69
-		$caption         = $caption_builder->build();
68
+        $caption_builder = new Caption_Builder( $item );
69
+        $caption         = $caption_builder->build();
70 70
 
71
-		wp_update_post( array(
72
-			'ID'           => $item['attachment_id'],
73
-			'post_excerpt' => $caption
74
-		) );
71
+        wp_update_post( array(
72
+            'ID'           => $item['attachment_id'],
73
+            'post_excerpt' => $caption
74
+        ) );
75 75
 
76
-		// Avoid running the regex on post content more than once.
77
-		$fixed = get_post_meta( $item['attachment_id'], '_wl_image_license_fixed', true );
78
-		if ( ! empty( $fixed ) ) {
79
-			return;
80
-		}
76
+        // Avoid running the regex on post content more than once.
77
+        $fixed = get_post_meta( $item['attachment_id'], '_wl_image_license_fixed', true );
78
+        if ( ! empty( $fixed ) ) {
79
+            return;
80
+        }
81 81
 
82
-		if ( isset( $item['posts_ids_as_embed'] ) ) {
83
-			foreach ( $item['posts_ids_as_embed'] as $post_id ) {
82
+        if ( isset( $item['posts_ids_as_embed'] ) ) {
83
+            foreach ( $item['posts_ids_as_embed'] as $post_id ) {
84 84
 
85
-				$figure = sprintf(
86
-					'
85
+                $figure = sprintf(
86
+                    '
87 87
 				<figure>
88 88
 					$0
89 89
 					<figcaption>%s</figcaption>
90 90
 				</figure>
91 91
 				', $caption );
92 92
 
93
-				/**
94
-				 * <figure>
95
-				 * <img src="/media/examples/elephant-660-480.jpg"
96
-				 * alt="Elephant at sunset">
97
-				 * <figcaption>An elephant at sunset</figcaption>
98
-				 * </figure>
99
-				 */
100
-
101
-				$pathinfo       = pathinfo( $item['filename'] );
102
-				$filename       = $pathinfo['filename'];
103
-				$extension      = $pathinfo['extension'];
104
-				$filename_quote = preg_quote( $filename, '@' );
105
-				$post           = get_post( $post_id );
106
-				$pattern        = '@<img[^>]*src="[^"]+wl/[^"]+' . $filename_quote . '(?:-\d+x\d+).' . $extension . '"[^>]*>@';
107
-				$post_content   = preg_replace( $pattern, $figure, $post->post_content );
108
-
109
-				wp_update_post( array(
110
-					'ID'           => $post_id,
111
-					'post_content' => $post_content,
112
-				) );
113
-
114
-			}
115
-		}
116
-
117
-		// Set the attachment as fixed.
118
-		update_post_meta( $item['attachment_id'], '_wl_image_license_fixed', time() );
119
-
120
-	}
93
+                /**
94
+                 * <figure>
95
+                 * <img src="/media/examples/elephant-660-480.jpg"
96
+                 * alt="Elephant at sunset">
97
+                 * <figcaption>An elephant at sunset</figcaption>
98
+                 * </figure>
99
+                 */
100
+
101
+                $pathinfo       = pathinfo( $item['filename'] );
102
+                $filename       = $pathinfo['filename'];
103
+                $extension      = $pathinfo['extension'];
104
+                $filename_quote = preg_quote( $filename, '@' );
105
+                $post           = get_post( $post_id );
106
+                $pattern        = '@<img[^>]*src="[^"]+wl/[^"]+' . $filename_quote . '(?:-\d+x\d+).' . $extension . '"[^>]*>@';
107
+                $post_content   = preg_replace( $pattern, $figure, $post->post_content );
108
+
109
+                wp_update_post( array(
110
+                    'ID'           => $post_id,
111
+                    'post_content' => $post_content,
112
+                ) );
113
+
114
+            }
115
+        }
116
+
117
+        // Set the attachment as fixed.
118
+        update_post_meta( $item['attachment_id'], '_wl_image_license_fixed', time() );
119
+
120
+    }
121 121
 
122 122
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -19,20 +19,20 @@  discard block
 block discarded – undo
19 19
 	 *
20 20
 	 * @param Image_License_Service $image_license_service
21 21
 	 */
22
-	public function __construct( $image_license_service ) {
23
-		parent::__construct( $image_license_service );
22
+	public function __construct($image_license_service) {
23
+		parent::__construct($image_license_service);
24 24
 
25 25
 		$this->image_license_service = $image_license_service;
26 26
 
27
-		add_action( 'wp_ajax_' . $this->get_id() . '__single', array( $this, 'ajax', ) );
27
+		add_action('wp_ajax_'.$this->get_id().'__single', array($this, 'ajax',));
28 28
 
29 29
 	}
30 30
 
31 31
 	public function ajax() {
32 32
 
33
-		check_ajax_referer( $this->get_id() );
33
+		check_ajax_referer($this->get_id());
34 34
 
35
-		$this->process_item( $_POST );
35
+		$this->process_item($_POST);
36 36
 
37 37
 		wp_send_json_success();
38 38
 
@@ -48,39 +48,39 @@  discard block
 block discarded – undo
48 48
 
49 49
 	function get_label() {
50 50
 
51
-		return __( 'Add license caption to images and remove those with unknown license', 'wordlift' );
51
+		return __('Add license caption to images and remove those with unknown license', 'wordlift');
52 52
 	}
53 53
 
54 54
 	/**
55 55
 	 * @inheritDoc
56 56
 	 */
57
-	function process_item( $item ) {
57
+	function process_item($item) {
58 58
 
59 59
 		$is_unknown_license = '#N/A' === $item['license'];
60 60
 
61 61
 		// If the license is unknown, delete the attachment.
62
-		if ( $is_unknown_license ) {
63
-			parent::process_item( $item );
62
+		if ($is_unknown_license) {
63
+			parent::process_item($item);
64 64
 
65 65
 			return;
66 66
 		}
67 67
 
68
-		$caption_builder = new Caption_Builder( $item );
68
+		$caption_builder = new Caption_Builder($item);
69 69
 		$caption         = $caption_builder->build();
70 70
 
71
-		wp_update_post( array(
71
+		wp_update_post(array(
72 72
 			'ID'           => $item['attachment_id'],
73 73
 			'post_excerpt' => $caption
74
-		) );
74
+		));
75 75
 
76 76
 		// Avoid running the regex on post content more than once.
77
-		$fixed = get_post_meta( $item['attachment_id'], '_wl_image_license_fixed', true );
78
-		if ( ! empty( $fixed ) ) {
77
+		$fixed = get_post_meta($item['attachment_id'], '_wl_image_license_fixed', true);
78
+		if ( ! empty($fixed)) {
79 79
 			return;
80 80
 		}
81 81
 
82
-		if ( isset( $item['posts_ids_as_embed'] ) ) {
83
-			foreach ( $item['posts_ids_as_embed'] as $post_id ) {
82
+		if (isset($item['posts_ids_as_embed'])) {
83
+			foreach ($item['posts_ids_as_embed'] as $post_id) {
84 84
 
85 85
 				$figure = sprintf(
86 86
 					'
@@ -98,24 +98,24 @@  discard block
 block discarded – undo
98 98
 				 * </figure>
99 99
 				 */
100 100
 
101
-				$pathinfo       = pathinfo( $item['filename'] );
101
+				$pathinfo       = pathinfo($item['filename']);
102 102
 				$filename       = $pathinfo['filename'];
103 103
 				$extension      = $pathinfo['extension'];
104
-				$filename_quote = preg_quote( $filename, '@' );
105
-				$post           = get_post( $post_id );
106
-				$pattern        = '@<img[^>]*src="[^"]+wl/[^"]+' . $filename_quote . '(?:-\d+x\d+).' . $extension . '"[^>]*>@';
107
-				$post_content   = preg_replace( $pattern, $figure, $post->post_content );
104
+				$filename_quote = preg_quote($filename, '@');
105
+				$post           = get_post($post_id);
106
+				$pattern        = '@<img[^>]*src="[^"]+wl/[^"]+'.$filename_quote.'(?:-\d+x\d+).'.$extension.'"[^>]*>@';
107
+				$post_content   = preg_replace($pattern, $figure, $post->post_content);
108 108
 
109
-				wp_update_post( array(
109
+				wp_update_post(array(
110 110
 					'ID'           => $post_id,
111 111
 					'post_content' => $post_content,
112
-				) );
112
+				));
113 113
 
114 114
 			}
115 115
 		}
116 116
 
117 117
 		// Set the attachment as fixed.
118
-		update_post_meta( $item['attachment_id'], '_wl_image_license_fixed', time() );
118
+		update_post_meta($item['attachment_id'], '_wl_image_license_fixed', time());
119 119
 
120 120
 	}
121 121
 
Please login to merge, or discard this patch.