Completed
Push — master ( 5073b9...52a8b9 )
by David
01:04
created
src/modules/food-kg/includes/admin/Main_Ingredient_List_Table.php 2 patches
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -3,43 +3,43 @@  discard block
 block discarded – undo
3 3
 namespace Wordlift\Modules\Food_Kg\Admin;
4 4
 
5 5
 if ( ! class_exists( 'WP_List_Table' ) ) {
6
-	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
+    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
7 7
 }
8 8
 
9 9
 use WP_List_Table;
10 10
 
11 11
 class Main_Ingredient_List_Table extends WP_List_Table {
12 12
 
13
-	public function prepare_items() {
14
-		global $wpdb; // This is used only if making any database queries
15
-
16
-		/**
17
-		 * REQUIRED. Now we need to define our column headers. This includes a complete
18
-		 * array of columns to be displayed (slugs & titles), a list of columns
19
-		 * to keep hidden, and a list of columns that are sortable. Each of these
20
-		 * can be defined in another method (as we've done here) before being
21
-		 * used to build the value for our _column_headers property.
22
-		 */
23
-		$columns  = $this->get_columns();
24
-		$hidden   = array();
25
-		$sortable = $this->get_sortable_columns();
26
-
27
-		/**
28
-		 * REQUIRED. Finally, we build an array to be used by the class for column
29
-		 * headers. The $this->_column_headers property takes an array which contains
30
-		 * 3 other arrays. One for all columns, one for hidden columns, and one
31
-		 * for sortable columns.
32
-		 */
33
-		$this->_column_headers = array( $columns, $hidden, $sortable );
34
-
35
-		// Pagination.
36
-		$per_page     = 20;
37
-		$current_page = $this->get_pagenum();
38
-		$total_items  = $this->count();
39
-
40
-		$this->items = $wpdb->get_results(
41
-			$wpdb->prepare(
42
-				"SELECT p1.ID AS recipe_ID,
13
+    public function prepare_items() {
14
+        global $wpdb; // This is used only if making any database queries
15
+
16
+        /**
17
+         * REQUIRED. Now we need to define our column headers. This includes a complete
18
+         * array of columns to be displayed (slugs & titles), a list of columns
19
+         * to keep hidden, and a list of columns that are sortable. Each of these
20
+         * can be defined in another method (as we've done here) before being
21
+         * used to build the value for our _column_headers property.
22
+         */
23
+        $columns  = $this->get_columns();
24
+        $hidden   = array();
25
+        $sortable = $this->get_sortable_columns();
26
+
27
+        /**
28
+         * REQUIRED. Finally, we build an array to be used by the class for column
29
+         * headers. The $this->_column_headers property takes an array which contains
30
+         * 3 other arrays. One for all columns, one for hidden columns, and one
31
+         * for sortable columns.
32
+         */
33
+        $this->_column_headers = array( $columns, $hidden, $sortable );
34
+
35
+        // Pagination.
36
+        $per_page     = 20;
37
+        $current_page = $this->get_pagenum();
38
+        $total_items  = $this->count();
39
+
40
+        $this->items = $wpdb->get_results(
41
+            $wpdb->prepare(
42
+                "SELECT p1.ID AS recipe_ID,
43 43
 					    p1.post_title AS recipe_name,
44 44
 					    p2.ID AS post_ID,
45 45
 					    p2.post_title
@@ -49,99 +49,99 @@  discard block
 block discarded – undo
49 49
 							INNER JOIN $wpdb->postmeta pm2
50 50
 								ON pm2.post_ID = pm1.post_ID AND pm2.meta_key = 'wprm_parent_post_id'
51 51
 						    INNER JOIN $wpdb->posts p2"
52
-				// The following ignore rule is used against the `LIKE CONCAT`. We only have const values.
53
-				// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.LikeWildcardsInQuery
54
-				. " ON p2.post_status = 'publish' AND p2.ID = pm2.post_ID
52
+                // The following ignore rule is used against the `LIKE CONCAT`. We only have const values.
53
+                // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.LikeWildcardsInQuery
54
+                . " ON p2.post_status = 'publish' AND p2.ID = pm2.post_ID
55 55
 							WHERE pm1.meta_key = '_wl_main_ingredient_jsonld'
56 56
 					LIMIT %d
57 57
 					OFFSET %d",
58
-				$per_page,
59
-				( $current_page - 1 ) * $per_page
60
-			)
61
-		);
58
+                $per_page,
59
+                ( $current_page - 1 ) * $per_page
60
+            )
61
+        );
62 62
 
63
-		$this->set_pagination_args(
64
-			array(
65
-				'total_items' => $total_items,
66
-				'per_page'    => $per_page,
67
-				'total_pages' => ceil( $total_items / $per_page ),
68
-			)
69
-		);
70
-	}
63
+        $this->set_pagination_args(
64
+            array(
65
+                'total_items' => $total_items,
66
+                'per_page'    => $per_page,
67
+                'total_pages' => ceil( $total_items / $per_page ),
68
+            )
69
+        );
70
+    }
71 71
 
72
-	private function count() {
73
-		global $wpdb;
72
+    private function count() {
73
+        global $wpdb;
74 74
 
75
-		$count = get_transient( '_wl_main_ingredient_list_table__count' );
75
+        $count = get_transient( '_wl_main_ingredient_list_table__count' );
76 76
 
77
-		if ( ! $count ) {
77
+        if ( ! $count ) {
78 78
 
79
-			$count = $wpdb->get_var(
80
-				"SELECT COUNT(1)
79
+            $count = $wpdb->get_var(
80
+                "SELECT COUNT(1)
81 81
 						FROM $wpdb->postmeta pm1
82 82
 						    INNER JOIN $wpdb->posts p1
83 83
 						        ON p1.ID = pm1.post_ID AND p1.post_type = 'wprm_recipe'
84 84
 							INNER JOIN $wpdb->postmeta pm2
85 85
 								ON pm2.post_ID = pm1.post_ID AND pm2.meta_key = 'wprm_parent_post_id'
86 86
 						    INNER JOIN $wpdb->posts p2"
87
-				// The following ignore rule is used against the `LIKE CONCAT`. We only have const values.
88
-				// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.LikeWildcardsInQuery
89
-				. " ON p2.post_status = 'publish' AND p2.ID = pm2.post_ID
87
+                // The following ignore rule is used against the `LIKE CONCAT`. We only have const values.
88
+                // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.LikeWildcardsInQuery
89
+                . " ON p2.post_status = 'publish' AND p2.ID = pm2.post_ID
90 90
 							WHERE pm1.meta_key = '_wl_main_ingredient_jsonld'"
91
-			);
92
-
93
-			set_transient( '_wl_main_ingredient_list_table__count', $count, 60 );
94
-		}
95
-
96
-		return $count;
97
-	}
98
-
99
-	public function no_items() {
100
-		esc_html_e( 'No main ingredients found.', 'wordlift' );
101
-	}
102
-
103
-	public function get_columns() {
104
-		return array(
105
-			'ingredient_name' => __( 'Ingredient Name', 'wordlift' ),
106
-			'recipe_name'     => __( 'Recipe Name', 'wordlift' ),
107
-			'post_title'      => __( 'Post Title', 'wordlift' ),
108
-			'url'             => __( 'Post URL', 'wordlift' ),
109
-			'actions'         => '',
110
-		);
111
-	}
112
-
113
-	public function column_ingredient_name( $item ) {
114
-		$recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
115
-		$recipe         = json_decode( $recipe_json_ld, true );
116
-
117
-		return $recipe ? $recipe['name'] : 'null';
118
-	}
119
-
120
-	public function column_recipe_name( $item ) {
121
-		return $item->recipe_name;
122
-	}
123
-
124
-	public function column_post_title( $item ) {
125
-		return sprintf( '<a href="%s">%s</a>', get_edit_post_link( $item->post_ID ), $item->post_title );
126
-	}
127
-
128
-	public function column_url( $item ) {
129
-		return get_permalink( $item->post_ID );
130
-	}
131
-
132
-	public function column_actions( $item ) {
133
-
134
-		$url = admin_url(
135
-			sprintf( 'admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->recipe_ID )  // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
136
-		);
137
-
138
-		return sprintf(
139
-			'<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>',
140
-			$url,
141
-			esc_attr( $item->post_title ),
142
-			esc_html__( 'JSON-LD', 'wordlift' )
143
-		);
144
-	}
91
+            );
92
+
93
+            set_transient( '_wl_main_ingredient_list_table__count', $count, 60 );
94
+        }
95
+
96
+        return $count;
97
+    }
98
+
99
+    public function no_items() {
100
+        esc_html_e( 'No main ingredients found.', 'wordlift' );
101
+    }
102
+
103
+    public function get_columns() {
104
+        return array(
105
+            'ingredient_name' => __( 'Ingredient Name', 'wordlift' ),
106
+            'recipe_name'     => __( 'Recipe Name', 'wordlift' ),
107
+            'post_title'      => __( 'Post Title', 'wordlift' ),
108
+            'url'             => __( 'Post URL', 'wordlift' ),
109
+            'actions'         => '',
110
+        );
111
+    }
112
+
113
+    public function column_ingredient_name( $item ) {
114
+        $recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
115
+        $recipe         = json_decode( $recipe_json_ld, true );
116
+
117
+        return $recipe ? $recipe['name'] : 'null';
118
+    }
119
+
120
+    public function column_recipe_name( $item ) {
121
+        return $item->recipe_name;
122
+    }
123
+
124
+    public function column_post_title( $item ) {
125
+        return sprintf( '<a href="%s">%s</a>', get_edit_post_link( $item->post_ID ), $item->post_title );
126
+    }
127
+
128
+    public function column_url( $item ) {
129
+        return get_permalink( $item->post_ID );
130
+    }
131
+
132
+    public function column_actions( $item ) {
133
+
134
+        $url = admin_url(
135
+            sprintf( 'admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->recipe_ID )  // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
136
+        );
137
+
138
+        return sprintf(
139
+            '<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>',
140
+            $url,
141
+            esc_attr( $item->post_title ),
142
+            esc_html__( 'JSON-LD', 'wordlift' )
143
+        );
144
+    }
145 145
 
146 146
 }
147 147
 
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace Wordlift\Modules\Food_Kg\Admin;
4 4
 
5
-if ( ! class_exists( 'WP_List_Table' ) ) {
6
-	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
+if ( ! class_exists('WP_List_Table')) {
6
+	require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php';
7 7
 }
8 8
 
9 9
 use WP_List_Table;
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 		 * 3 other arrays. One for all columns, one for hidden columns, and one
31 31
 		 * for sortable columns.
32 32
 		 */
33
-		$this->_column_headers = array( $columns, $hidden, $sortable );
33
+		$this->_column_headers = array($columns, $hidden, $sortable);
34 34
 
35 35
 		// Pagination.
36 36
 		$per_page     = 20;
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 					LIMIT %d
57 57
 					OFFSET %d",
58 58
 				$per_page,
59
-				( $current_page - 1 ) * $per_page
59
+				($current_page - 1) * $per_page
60 60
 			)
61 61
 		);
62 62
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 			array(
65 65
 				'total_items' => $total_items,
66 66
 				'per_page'    => $per_page,
67
-				'total_pages' => ceil( $total_items / $per_page ),
67
+				'total_pages' => ceil($total_items / $per_page),
68 68
 			)
69 69
 		);
70 70
 	}
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
 	private function count() {
73 73
 		global $wpdb;
74 74
 
75
-		$count = get_transient( '_wl_main_ingredient_list_table__count' );
75
+		$count = get_transient('_wl_main_ingredient_list_table__count');
76 76
 
77
-		if ( ! $count ) {
77
+		if ( ! $count) {
78 78
 
79 79
 			$count = $wpdb->get_var(
80 80
 				"SELECT COUNT(1)
@@ -90,56 +90,56 @@  discard block
 block discarded – undo
90 90
 							WHERE pm1.meta_key = '_wl_main_ingredient_jsonld'"
91 91
 			);
92 92
 
93
-			set_transient( '_wl_main_ingredient_list_table__count', $count, 60 );
93
+			set_transient('_wl_main_ingredient_list_table__count', $count, 60);
94 94
 		}
95 95
 
96 96
 		return $count;
97 97
 	}
98 98
 
99 99
 	public function no_items() {
100
-		esc_html_e( 'No main ingredients found.', 'wordlift' );
100
+		esc_html_e('No main ingredients found.', 'wordlift');
101 101
 	}
102 102
 
103 103
 	public function get_columns() {
104 104
 		return array(
105
-			'ingredient_name' => __( 'Ingredient Name', 'wordlift' ),
106
-			'recipe_name'     => __( 'Recipe Name', 'wordlift' ),
107
-			'post_title'      => __( 'Post Title', 'wordlift' ),
108
-			'url'             => __( 'Post URL', 'wordlift' ),
105
+			'ingredient_name' => __('Ingredient Name', 'wordlift'),
106
+			'recipe_name'     => __('Recipe Name', 'wordlift'),
107
+			'post_title'      => __('Post Title', 'wordlift'),
108
+			'url'             => __('Post URL', 'wordlift'),
109 109
 			'actions'         => '',
110 110
 		);
111 111
 	}
112 112
 
113
-	public function column_ingredient_name( $item ) {
114
-		$recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
115
-		$recipe         = json_decode( $recipe_json_ld, true );
113
+	public function column_ingredient_name($item) {
114
+		$recipe_json_ld = get_post_meta($item->recipe_ID, '_wl_main_ingredient_jsonld', true); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
115
+		$recipe         = json_decode($recipe_json_ld, true);
116 116
 
117 117
 		return $recipe ? $recipe['name'] : 'null';
118 118
 	}
119 119
 
120
-	public function column_recipe_name( $item ) {
120
+	public function column_recipe_name($item) {
121 121
 		return $item->recipe_name;
122 122
 	}
123 123
 
124
-	public function column_post_title( $item ) {
125
-		return sprintf( '<a href="%s">%s</a>', get_edit_post_link( $item->post_ID ), $item->post_title );
124
+	public function column_post_title($item) {
125
+		return sprintf('<a href="%s">%s</a>', get_edit_post_link($item->post_ID), $item->post_title);
126 126
 	}
127 127
 
128
-	public function column_url( $item ) {
129
-		return get_permalink( $item->post_ID );
128
+	public function column_url($item) {
129
+		return get_permalink($item->post_ID);
130 130
 	}
131 131
 
132
-	public function column_actions( $item ) {
132
+	public function column_actions($item) {
133 133
 
134 134
 		$url = admin_url(
135
-			sprintf( 'admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->recipe_ID )  // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
135
+			sprintf('admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->recipe_ID)  // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
136 136
 		);
137 137
 
138 138
 		return sprintf(
139 139
 			'<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>',
140 140
 			$url,
141
-			esc_attr( $item->post_title ),
142
-			esc_html__( 'JSON-LD', 'wordlift' )
141
+			esc_attr($item->post_title),
142
+			esc_html__('JSON-LD', 'wordlift')
143 143
 		);
144 144
 	}
145 145
 
Please login to merge, or discard this patch.
src/modules/food-kg/includes/admin/Download_Ingredients_Data.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -4,22 +4,22 @@  discard block
 block discarded – undo
4 4
 
5 5
 class Download_Ingredients_Data {
6 6
 
7
-	public function register_hooks() {
8
-		add_action( 'wp_ajax_wl_download_ingredients_data', array( $this, 'wl_download_ingredients_data' ) );
9
-	}
7
+    public function register_hooks() {
8
+        add_action( 'wp_ajax_wl_download_ingredients_data', array( $this, 'wl_download_ingredients_data' ) );
9
+    }
10 10
 
11
-	public function wl_download_ingredients_data() {
11
+    public function wl_download_ingredients_data() {
12 12
 
13
-		check_ajax_referer( 'wl-dl-ingredients-data-nonce' );
13
+        check_ajax_referer( 'wl-dl-ingredients-data-nonce' );
14 14
 
15
-		if ( ! current_user_can( 'manage_options' ) ) {
16
-			wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wordlift' ) );
17
-		}
15
+        if ( ! current_user_can( 'manage_options' ) ) {
16
+            wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wordlift' ) );
17
+        }
18 18
 
19
-		global $wpdb;
19
+        global $wpdb;
20 20
 
21
-		$items = $wpdb->get_results(
22
-			"SELECT p1.ID AS recipe_ID,
21
+        $items = $wpdb->get_results(
22
+            "SELECT p1.ID AS recipe_ID,
23 23
 					    p1.post_title AS recipe_name,
24 24
 					    p2.ID AS post_ID,
25 25
 					    p2.post_title
@@ -29,62 +29,62 @@  discard block
 block discarded – undo
29 29
 							INNER JOIN $wpdb->postmeta pm2
30 30
 								ON pm2.post_ID = pm1.post_ID AND pm2.meta_key = 'wprm_parent_post_id'
31 31
 						    INNER JOIN $wpdb->posts p2"
32
-			// The following ignore rule is used against the `LIKE CONCAT`. We only have const values.
33
-			// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.LikeWildcardsInQuery
34
-			. " ON p2.post_status = 'publish' AND p2.ID = pm2.post_ID
32
+            // The following ignore rule is used against the `LIKE CONCAT`. We only have const values.
33
+            // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.LikeWildcardsInQuery
34
+            . " ON p2.post_status = 'publish' AND p2.ID = pm2.post_ID
35 35
 							WHERE pm1.meta_key = '_wl_main_ingredient_jsonld'"
36
-		);
37
-
38
-		if ( ! $items ) {
39
-			wp_send_json_error( __( 'No main ingredients found.', 'wordlift' ) );
40
-		}
41
-
42
-		// Generate unique filename using current timestamp.
43
-		$filename = 'wl-main-ingredients-data-' . gmdate( 'Y-m-d-H-i-s' ) . '.tsv';
44
-
45
-		header( 'Content-Disposition: attachment; filename=' . $filename );
46
-		header( 'Content-Type: text/text/tab-separated-values; charset=' . get_bloginfo( 'charset' ) );
47
-
48
-		// Do not cache the file.
49
-		header( 'Pragma: no-cache' );
50
-		header( 'Expires: 0' );
51
-
52
-		$output = fopen( 'php://output', 'w' );
53
-
54
-		// Insert Header.
55
-		fputcsv(
56
-			$output,
57
-			array(
58
-				__( 'Ingredient Name', 'wordlift' ),
59
-				__( 'Recipe Name', 'wordlift' ),
60
-				__( 'Recipe ID', 'wordlift' ),
61
-				__( 'Post Name', 'wordlift' ),
62
-				__( 'Post ID', 'wordlift' ),
63
-				__( 'Post URL', 'wordlift' ),
64
-			),
65
-			"\t"
66
-		);
67
-
68
-		// Insert Data.
69
-		foreach ( $items as $item ) {
70
-			$recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
71
-			$recipe         = json_decode( $recipe_json_ld, true );
72
-			fputcsv(
73
-				$output,
74
-				array(
75
-					$recipe ? $recipe['name'] : 'null',
76
-					$item->recipe_name,
77
-					$item->recipe_ID,
78
-					// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
79
-					$item->post_title,
80
-					$item->post_ID,
81
-					esc_url( get_the_permalink( $item->post_ID ) ),
82
-				),
83
-				"\t"
84
-			);
85
-			ob_flush();
86
-		}
87
-
88
-		wp_die();
89
-	}
36
+        );
37
+
38
+        if ( ! $items ) {
39
+            wp_send_json_error( __( 'No main ingredients found.', 'wordlift' ) );
40
+        }
41
+
42
+        // Generate unique filename using current timestamp.
43
+        $filename = 'wl-main-ingredients-data-' . gmdate( 'Y-m-d-H-i-s' ) . '.tsv';
44
+
45
+        header( 'Content-Disposition: attachment; filename=' . $filename );
46
+        header( 'Content-Type: text/text/tab-separated-values; charset=' . get_bloginfo( 'charset' ) );
47
+
48
+        // Do not cache the file.
49
+        header( 'Pragma: no-cache' );
50
+        header( 'Expires: 0' );
51
+
52
+        $output = fopen( 'php://output', 'w' );
53
+
54
+        // Insert Header.
55
+        fputcsv(
56
+            $output,
57
+            array(
58
+                __( 'Ingredient Name', 'wordlift' ),
59
+                __( 'Recipe Name', 'wordlift' ),
60
+                __( 'Recipe ID', 'wordlift' ),
61
+                __( 'Post Name', 'wordlift' ),
62
+                __( 'Post ID', 'wordlift' ),
63
+                __( 'Post URL', 'wordlift' ),
64
+            ),
65
+            "\t"
66
+        );
67
+
68
+        // Insert Data.
69
+        foreach ( $items as $item ) {
70
+            $recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
71
+            $recipe         = json_decode( $recipe_json_ld, true );
72
+            fputcsv(
73
+                $output,
74
+                array(
75
+                    $recipe ? $recipe['name'] : 'null',
76
+                    $item->recipe_name,
77
+                    $item->recipe_ID,
78
+                    // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
79
+                    $item->post_title,
80
+                    $item->post_ID,
81
+                    esc_url( get_the_permalink( $item->post_ID ) ),
82
+                ),
83
+                "\t"
84
+            );
85
+            ob_flush();
86
+        }
87
+
88
+        wp_die();
89
+    }
90 90
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -5,15 +5,15 @@  discard block
 block discarded – undo
5 5
 class Download_Ingredients_Data {
6 6
 
7 7
 	public function register_hooks() {
8
-		add_action( 'wp_ajax_wl_download_ingredients_data', array( $this, 'wl_download_ingredients_data' ) );
8
+		add_action('wp_ajax_wl_download_ingredients_data', array($this, 'wl_download_ingredients_data'));
9 9
 	}
10 10
 
11 11
 	public function wl_download_ingredients_data() {
12 12
 
13
-		check_ajax_referer( 'wl-dl-ingredients-data-nonce' );
13
+		check_ajax_referer('wl-dl-ingredients-data-nonce');
14 14
 
15
-		if ( ! current_user_can( 'manage_options' ) ) {
16
-			wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wordlift' ) );
15
+		if ( ! current_user_can('manage_options')) {
16
+			wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'wordlift'));
17 17
 		}
18 18
 
19 19
 		global $wpdb;
@@ -35,40 +35,40 @@  discard block
 block discarded – undo
35 35
 							WHERE pm1.meta_key = '_wl_main_ingredient_jsonld'"
36 36
 		);
37 37
 
38
-		if ( ! $items ) {
39
-			wp_send_json_error( __( 'No main ingredients found.', 'wordlift' ) );
38
+		if ( ! $items) {
39
+			wp_send_json_error(__('No main ingredients found.', 'wordlift'));
40 40
 		}
41 41
 
42 42
 		// Generate unique filename using current timestamp.
43
-		$filename = 'wl-main-ingredients-data-' . gmdate( 'Y-m-d-H-i-s' ) . '.tsv';
43
+		$filename = 'wl-main-ingredients-data-'.gmdate('Y-m-d-H-i-s').'.tsv';
44 44
 
45
-		header( 'Content-Disposition: attachment; filename=' . $filename );
46
-		header( 'Content-Type: text/text/tab-separated-values; charset=' . get_bloginfo( 'charset' ) );
45
+		header('Content-Disposition: attachment; filename='.$filename);
46
+		header('Content-Type: text/text/tab-separated-values; charset='.get_bloginfo('charset'));
47 47
 
48 48
 		// Do not cache the file.
49
-		header( 'Pragma: no-cache' );
50
-		header( 'Expires: 0' );
49
+		header('Pragma: no-cache');
50
+		header('Expires: 0');
51 51
 
52
-		$output = fopen( 'php://output', 'w' );
52
+		$output = fopen('php://output', 'w');
53 53
 
54 54
 		// Insert Header.
55 55
 		fputcsv(
56 56
 			$output,
57 57
 			array(
58
-				__( 'Ingredient Name', 'wordlift' ),
59
-				__( 'Recipe Name', 'wordlift' ),
60
-				__( 'Recipe ID', 'wordlift' ),
61
-				__( 'Post Name', 'wordlift' ),
62
-				__( 'Post ID', 'wordlift' ),
63
-				__( 'Post URL', 'wordlift' ),
58
+				__('Ingredient Name', 'wordlift'),
59
+				__('Recipe Name', 'wordlift'),
60
+				__('Recipe ID', 'wordlift'),
61
+				__('Post Name', 'wordlift'),
62
+				__('Post ID', 'wordlift'),
63
+				__('Post URL', 'wordlift'),
64 64
 			),
65 65
 			"\t"
66 66
 		);
67 67
 
68 68
 		// Insert Data.
69
-		foreach ( $items as $item ) {
70
-			$recipe_json_ld = get_post_meta( $item->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
71
-			$recipe         = json_decode( $recipe_json_ld, true );
69
+		foreach ($items as $item) {
70
+			$recipe_json_ld = get_post_meta($item->recipe_ID, '_wl_main_ingredient_jsonld', true); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
71
+			$recipe         = json_decode($recipe_json_ld, true);
72 72
 			fputcsv(
73 73
 				$output,
74 74
 				array(
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 					// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
79 79
 					$item->post_title,
80 80
 					$item->post_ID,
81
-					esc_url( get_the_permalink( $item->post_ID ) ),
81
+					esc_url(get_the_permalink($item->post_ID)),
82 82
 				),
83 83
 				"\t"
84 84
 			);
Please login to merge, or discard this patch.