Select a Private or Public page to use as your post type archive page.
13 |
View the archive and you will see the page content instead of the archive content.
14 |
Use page templates on your pages for flexibility.
15 |
16 |
17 | ## Note
18 |
19 | Your post types need to have `has_archive` set to true.
20 |
21 | Installation
22 | ---------------------
23 | Go to Settings->Reading. At the bottom you will see a place to map your post types.
24 |
25 | DEVS
26 | ---------------------
27 |
28 | 1. Clone the repo to any location you choose.
29 | 2. Run ```npm install``` inside the folder.
30 | 3. Run ```npm run build``` inside the folder.
31 | 4. Set up a symlink to your WordPress installation using the folder as the base.
32 | 5. Run ```npm run watch``` to make changes and then ```npm run build``` when you're done.
33 |
34 | 1. To edit the block, they are in ```/blocks/load.js``` and ```/blocks/edit.js```.
35 | 2. The REST API is created and passed in ```/blocks.init.php```.
36 | 3. The attributes and output are in ```/blocks/class-post-type-select-posts.php```.
37 |
38 | Credit
39 | -------------
40 | Chris Logan for coming up with the idea.
41 |
42 | # Security Policy
43 |
44 | ## Reporting Security Bugs Please report security bugs found in the Custom Query Blocks plugin's source code through the [Patchstack Vulnerability Disclosure Program](https://patchstack.com/database/report-preview/fe816fb9-144f-4dd1-998a-a465439d87e0?pin=IFOiN16e7SpHRdJF). The Patchstack team will assist you with verification, CVE assignment, and notify the developers of this plugin.
--------------------------------------------------------------------------------
/src/block/components/TermListControl.js:
--------------------------------------------------------------------------------
1 | import { useState, useEffect } from 'react';
2 | import { __ } from '@wordpress/i18n';
3 | import { useForm, Controller, useWatch } from 'react-hook-form';
4 | import { CheckboxControl } from '@wordpress/components';
5 |
6 | const TermListControl = ( props ) => {
7 |
8 | const { terms, onChange, hasSelectAll = false } = props;
9 |
10 | const getDefaultValues = () => {
11 | return {
12 | terms: terms,
13 | };
14 | };
15 |
16 | const { control, setValue, getValues } = useForm( {
17 | defaultValues: getDefaultValues(),
18 | } );
19 |
20 | const formValues = useWatch( { control } );
21 |
22 | if ( ! formValues.terms ) {
23 | return null;
24 | }
25 |
26 | const isDisabled = ( term_id ) => {
27 | if ( ! hasSelectAll || 0 === term_id ) {
28 | return false;
29 | } else {
30 | // Check if term ID 0 is selected.
31 | const termZero = formValues.terms.find( ( term ) => term.id === 0 );
32 | return termZero.selected;
33 | }
34 | }
35 |
36 | return (
37 |
Map your post type archives to a page for customization of the post type archive page.
24 |
Map your category archives to a page for customization of the term archive page.
25 |
Map your 404 template to a page and easily customize your 404 page.
26 |
27 |
28 | View Documentation and Overview
29 |
30 | The plugin currently has three blocks:
31 |
32 | * Custom Post Types Block
33 | * Term (Category) Grid Block
34 | * Featured Posts by Category Block
35 |
36 | === Post Type Archive Mapping ===
37 |
38 | This plugin allows you to map your custom post type archive pages. Just create a page and go to Settings->Reading to set the page for your archive.
39 |
40 | Ensure your post types have has_archive set to true.
41 |
42 |
43 |
Select a Public page to use as your post type archive page.
44 |
View the archive and you will see the page content instead of the archive content.
45 |
Use page templates on your pages for flexibility.
46 |
Custom Gutenberg block for showing your posts.
47 |
48 |
49 | === Term Archive Mapping ===
50 |
51 | This plugin also allows you to map your term archives to a page. Just create a page and go edit your term to set the archive page.
52 |
53 |
54 |
Create a public page to use as your term archive.
55 |
Visit the edit term page and select the page.
56 |
View the term and you will see your selected page.
57 |
Use Gutenberg on your public page to customize the archive.
58 |
59 |
60 | === 404 Page Mapping ===
61 |
62 | This plugin allows you to map a page to your 404 template, so you can customize a 404 page as needed.
63 |
64 | === Development is on GitHub ===
65 |
66 | Development is on GitHub
67 |
68 | === Archive Pages Pro ===
69 |
70 | Archive Pages Pro has all the mapping feature of this plugin and more. You can map post types, terms, authors, and more to pages. Learn more about Archive Pages Pro
71 |
72 | == Installation ==
73 |
74 | 1. Just unzip and upload the "post-type-archive-mapping" folder to your '/wp-content/plugins/' directory
75 | 2. Activate the plugin through the 'Plugins' menu in WordPress
76 |
77 | Post Type Archive Mapping
78 |
79 | 1. Create a custom post type that has an archive
80 | 2. Create a page with a custom template. Use the Gutenberg block to show off posts in that Custom Post Type.
81 | 3. Go to Settings->Reading and assign the page to the custom post type archive
82 | 4. Go to the post type archive and observe the page content is now the archive
83 |
84 | Term Archive Mapping
85 |
86 | 1. Create a public page to use as your term archive.
87 | 2. Visit the edit term page and select the page.
88 | 3. View the term and you will see your selected page.
89 | 4. Use Gutenberg on your public page to customize the archive.
90 |
91 | 404 Template Mapping
92 |
93 | 1. Visit Settings->Reading and map your 404 template to a page.
94 | 2. Customize the new 404 page.
95 | 3. Navigate to a broken URL to preview the 404 page.
96 |
97 | == Frequently Asked Questions ==
98 |
99 | = I don't see the post types. What's wrong? =
100 |
101 | Make sure your post type has has_archive set to true and show_in_rest set to true.
102 |
103 | = Can you do posts instead of pages? =
104 |
105 | This plugin will only allow mapping to pages.
106 |
107 | = Does this plugin work with term (e.g., category) archives? =
108 |
109 | Yes. Edit a term and you can map it to any page.
110 |
111 | = I need help. Can you help me? =
112 |
113 | Yes, just post in the support forums here and I'll do my best to address your issue.
114 |
115 | == Screenshots ==
116 |
117 | 1. Setting up the custom post types block.
118 | 2. Styling the block.
119 | 3. New Term Grid Block.
120 | 4. Settings->Reading option.
121 | 5. Term archive option.
122 |
123 | == Changelog ==
124 |
125 | = 5.4.0 =
126 | * Released 2025-11-15
127 | * Resolving XSS vulnerability with title tag as reported via Patchstack. Ensuring compatibility with WP 6.9.
128 |
129 | = 5.3.1 =
130 | * Released 2024-08-27
131 | * Fixing some deprecation notices in blocks.
132 | * Adding information about new plugin Archive Pages Pro.
133 | * Misc. copy updates.
134 |
135 | = 5.3.0 =
136 | * Released 2024-07-10
137 | * Hardening REST APIs based on security report from the WordPress security team.
138 | * This is a security release and we recommend updating as soon as possible.
139 |
140 | = 5.2.0 =
141 | * Released 2024-03-17
142 | * Fixing a bug in the Term Grid block where the SearchListControl in Woo Components was throwing an error, so the component was reworked.
143 |
144 | = 5.1.6 =
145 | * Released 2023-03-17
146 | * Fixing a bug where the term grid didn't show on the frontend.
147 |
148 | = 5.1.5 =
149 | * Released 2022-10-02
150 | * Fixing a bug where a term would not save in the custom post types block.
151 |
152 | = 5.1.4 =
153 | * Released 2022-10-01
154 | * Updated build scripts.
155 | * Fixing schema errors when it comes to registering attributes.
156 |
157 | = 5.1.2 =
158 | * Released 2021-07-28
159 | * Fixing block categories for WP 5.8.
160 |
161 | = 5.1.0 =
162 | * Released 2021-03-25
163 | * Seeking volunteer devs if you want to learn blocks and help lower the build size.
164 | * Feature: Can disable post type mapping via the settings page.
165 | * Feature: Can disable the blocks via the settings page.
166 | * Feature: Can disable the columns on the pages screen.
167 | * Feature: Can disable the created image sizes.
168 | * Feature: New admin options to enable/disable settings.
169 | * Bug fix: Selecting individual terms in the term block would not reflect on the front-end.
170 | * Misc: Removing block icon from the Add Blocks screen.
171 | * Misc: Updating block icons and color scheme.
172 | * Bug fix: Tweaking word-break in the terms block.
173 |
174 | = 5.0.6 =
175 | * Released 2021-03-09
176 | * Fixing term saving causing archives to fail.
177 |
178 | = 5.0.5 =
179 | * Released 2021-02-12
180 | * Mapping to pages now shows a hierachy to more easily select pages.
181 | * New branding. Hopefully less spammy.
182 | * Making readme more descriptive of what the plugin does.
183 |
184 | = 5.0.1 =
185 | * Released 2021-02-12
186 | * Fixed the Term block with the block erroring out when modifying the query parameters.
187 | * Testing with WordPress 5.7.
188 |
189 | = 5.0.0 =
190 | * Released 2020-09-07
191 | * Added ability to map 404 to a page.
192 | * Fixed Gutenberg bugs in the Custom Post Types block and Featured Posts block.
193 |
194 | = 4.5.5 =
195 | * Released 2020-08-23
196 | * Minimium supported version is now WordPress 5.5
197 | * Fixed pagination for WP 5.5.
198 | * Fixed REST API errors for WP 5.5.
199 | * Miscellaneous block fixes and updates.
200 |
201 | = 4.5.3 =
202 | * Released 2020-05-17
203 | * Added Polylang support when mapping posts. Added WPML support for the main Custom Post Types block.
204 |
205 | = 4.5.2 =
206 | * Released 2020-05-01
207 | * Removing the term redirect as some pages would get "stuck."
208 |
209 | = 4.5.1 =
210 | * Released 2020-04-29
211 | * Added pagination to the Featured Posts by Category Block.
212 |
213 | = 4.5.0 =
214 | * Released 2020-04-20
215 | * Added featured posts by category block.
216 | * Added block previews.
217 | * New plugin name: Custom Query Blocks
218 |
219 | = 4.0.5 -
220 | * Released 2020-04-16
221 | * Added compatibility for Yoast SEO.
222 |
223 | = 4.0.1 =
224 | * Released 2020-04-12
225 | * New block: Term (Category) Grid Block.
226 | * HOT FIX: Term Grid wasn't loading.
227 |
228 | = 3.3.5 =
229 | * Released 2020-04-07
230 | * Updated plugin architecture.
231 | * Show mapped pages and its own column.
232 | * Mapped term pages now redirect to the correct term.
233 | * Added new contributor: Paal Joachim.
234 |
235 | = 3.3.1 =
236 | * Released 2020-04-01
237 | * Fixing PHP notice saying invalid argument for foreach statement.
238 |
239 | = 3.3.0 =
240 |
241 | * Released 2020-03-11
242 | * New full post mode for showing off the full post.
243 | * Option to remove the link from the title.
244 |
245 | = 3.2.2 =
246 | * Released 2020-02-10
247 | * Plugin was having conflicts with other admin screens when saving terms, resulting in a 403 error.
248 |
249 | = 3.2.1 =
250 | * Released 2020-02-03
251 | * Added support for translations.
252 | * Revised loading screen to make it easier on translators.
253 |
254 | = 3.2.0 =
255 | * Released 2020-02-03
256 | * Added ability to map term archives to pages.
257 |
258 | = 3.1.1 =
259 | * Released 2020-02-01
260 | * Added several order and orderby parameters.
261 |
262 | = 3.1.0 =
263 | * Released 2020-01-26
264 | * Removing custom field placeholder if a custom field isn't present.
265 | * Removing continue reading link and post link if custom post type isn't publicly queryable.
266 | * Wrapping excerpt in paragraph tag.
267 | * Add class to readmore paragraph tag for styling.
268 | * Hiding styles options if override styles is present.
269 | * Changing verbiage of remove styles to Override styles.
270 | * Added support for Adobe fonts through https://wordpress.org/plugins/custom-typekit-fonts/
271 |
272 | = 3.0.9 =
273 |
274 | * Released 2019-12-08
275 | * Added the ability to set a fallback image for the featured image.
276 |
277 | = 3.0.7 =
278 |
279 | * Released 2019-12-05
280 | * Fixing pagination when a page with the Gutenberg block is set as the front page.
281 |
282 | = 3.0.6 =
283 |
284 | * Released 2019-12-05
285 | * Moving featured image to its own panel in Gutenberg settings.
286 | * Moving title to its own panel in Gutenberg settings.
287 | * Cleaning up editor styles for headings.
288 | * Adding ability to change the heading HTML tag.
289 |
290 | = 3.0.5 =
291 | * Released 2019-12-05
292 | * Adding ability to remove styles so that you can style your own layout.
293 |
294 | = 3.0.0 =
295 | * Released 2019-12-03
296 | * Adding custom field support.
297 | * Updating REST API for faster loading.
298 |
299 | = 2.2.2 =
300 | * Released 2019-12-02
301 | * Added ability to remove title from displaying.
302 | * Added new branded loading animation.
303 |
304 | = 2.2.1 =
305 | * Released 2019-10-29
306 | * Testing up to WordPress 5.3.
307 | * Fixing JS error when jQuery is not defined as a $ variable.
308 |
309 | = 2.2.0 =
310 | * Released 2019-08-23
311 | * Bug fix when in grid mode and image is placed below the title.
312 | * Bug fix: skipping taxonomies when there are none.
313 | * Bug fix: fixing capitalization error.
314 | * Enhancement: You can now select fonts for your content areas.
315 |
316 | = 2.1.2 =
317 | * Released 2019-06-11
318 | * Fixing pagination
319 |
320 | = 2.1.1 =
321 | * Released 2019-05-26
322 | * Some users were seeing featured images twice in the back-end.
323 |
324 | = 2.1.0 =
325 | * Released 2019-05-25
326 | * Fixed Gravatar sizing not saving.
327 | * Changing the way excerpts are shown in Gutenberg.
328 | * Added the ability to change taxonomy location.
329 | * Content can now be centered in the Grid view.
330 | * Added border, padding, and background style options in Gutenberg block.
331 | * Added color options for text in Gutenberg block.
332 |
333 | = 2.0.7 =
334 | * Released 2019-05-24
335 | * Added the ability to trim the excerpt length.
336 | * Reduce the file size of the Gutenberg block script using a new build technique.
337 |
338 | = 2.0.5 =
339 | * Released 2019-04-21
340 | * Conditional term filtering
341 |
342 | = 2.0.4 =
343 | * Released 2019-04-18
344 | * Adding support for six columns
345 | * Fixing undefined index error
346 |
347 | = 2.0.3 =
348 | * Released 2019-03-29
349 | * Fixed term not being saved when displaying posts
350 |
351 | = 2.0.1 =
352 | * Released 2019-01-17
353 | * Fixed pagination when using a page with just the block
354 |
355 | = 2.0.1 =
356 | * Released 2019-01-17
357 | * Fixing bug where arguments weren't an array when switching reading types in Settings->Reading.
358 |
359 | = 2.0.0 =
360 | * Released 2019-01-06
361 | * Numerous enhancements to the Gutenberg block including showing taxonomies, setting the image type (Avatar vs Regular), setting where the featured image is displayed, selecting the image size, and much more.
362 |
363 | = 1.0.1 =
364 | * Released 2018-11-07
365 | * WordPress 5.0 compatibility
366 |
367 | = 1.0.0 =
368 | * Released 2018-09-24
369 | * Initial release.
370 |
371 | == Upgrade Notice ==
372 |
373 | = 5.4.0 =
374 | Resolving XSS vulnerability with title tag as reported via Patchstack. Ensuring compatibility with WP 6.9.
--------------------------------------------------------------------------------
/dist/blockstyles.css:
--------------------------------------------------------------------------------
1 | @font-face{font-family:"PTAM";src:url("../fonts/ptam.eot");src:url("../fonts/ptam.eot?#iefix") format("embedded-opentype"),url("../fonts/ptam.woff2") format("woff2"),url("../fonts/ptam.woff") format("woff"),url("../fonts/ptam.ttf") format("truetype"),url("../fonts/ptam.svg#svgFontName") format("svg")}@media only screen and (min-width: 600px){div[class*=wp-block-atomic].ptam-font-size-14.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-14.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-14.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-14.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-14.ptam-block-cta p{font-size:14px}div[class*=wp-block-atomic].ptam-font-size-15.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-15.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-15.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-15.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-15.ptam-block-cta p{font-size:15px}div[class*=wp-block-atomic].ptam-font-size-16.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-16.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-16.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-16.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-16.ptam-block-cta p{font-size:16px}div[class*=wp-block-atomic].ptam-font-size-17.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-17.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-17.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-17.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-17.ptam-block-cta p{font-size:17px}div[class*=wp-block-atomic].ptam-font-size-18.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-18.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-18.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-18.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-18.ptam-block-cta p{font-size:18px}div[class*=wp-block-atomic].ptam-font-size-19.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-19.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-19.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-19.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-19.ptam-block-cta p{font-size:19px}div[class*=wp-block-atomic].ptam-font-size-20.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-20.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-20.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-20.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-20.ptam-block-cta p{font-size:20px}div[class*=wp-block-atomic].ptam-font-size-21.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-21.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-21.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-21.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-21.ptam-block-cta p{font-size:21px}div[class*=wp-block-atomic].ptam-font-size-22.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-22.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-22.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-22.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-22.ptam-block-cta p{font-size:22px}div[class*=wp-block-atomic].ptam-font-size-23.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-23.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-23.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-23.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-23.ptam-block-cta p{font-size:23px}div[class*=wp-block-atomic].ptam-font-size-24.ptam-block-testimonial p,div[class*=wp-block-atomic].ptam-font-size-24.ptam-block-notice p,div[class*=wp-block-atomic].ptam-font-size-24.ptam-block-profile p,div[class*=wp-block-atomic].ptam-font-size-24.ptam-block-accordion p,div[class*=wp-block-atomic].ptam-font-size-24.ptam-block-cta p{font-size:24px}}.center{text-align:center}.left{text-align:left}.right{text-align:right}@media only screen and (min-width: 600px){.wp-block-columns .layout-column-1,.wp-block-columns .layout-column-2{margin-right:5%}}.wp-block-image{margin-bottom:1.2em}.ptam-text-link{color:inherit;box-shadow:0 -1px 0 inset;text-decoration:none;transition:.3s ease}.ptam-text-link:hover{color:inherit;box-shadow:0 -2px 0 inset;color:#5a3fd6}.entry-content .ptam-block-post-grid-title{margin-top:0;margin-bottom:15px;font-size:28px;line-height:1.2;clear:none}.entry-content .ptam-block-post-grid-title:before{display:none}.entry-content .ptam-block-post-grid-title:after{display:none}.entry-content .ptam-block-post-grid-title a{color:#000;box-shadow:none;transition:.3s ease}.ptam-block-post-grid{margin:0 0 1.2em 0;position:relative}.ptam-block-post-grid .is-grid{display:grid;grid-template-columns:1fr 1fr;grid-template-rows:1fr;grid-gap:0 2em;column-gap:2em;line-height:1.1}.ptam-block-post-grid .is-grid article{margin-bottom:2.5em}.ptam-block-post-grid .is-grid.columns-1{grid-template-columns:1fr}.ptam-block-post-grid .is-grid.columns-2{grid-template-columns:1fr 1fr}@media only screen and (max-width: 600px){.ptam-block-post-grid .is-grid.columns-2{grid-template-columns:1fr}}.ptam-block-post-grid .is-grid.columns-3{grid-template-columns:1fr 1fr 1fr}@media only screen and (max-width: 600px){.ptam-block-post-grid .is-grid.columns-3{grid-template-columns:1fr 1fr}}.ptam-block-post-grid .is-grid.columns-4{grid-template-columns:1fr 1fr 1fr 1fr}@media only screen and (max-width: 800px){.ptam-block-post-grid .is-grid.columns-4{grid-template-columns:1fr 1fr 1fr}}.ptam-block-post-grid .is-grid.columns-5{grid-template-columns:1fr 1fr 1fr 1fr 1fr}@media only screen and (max-width: 1000px){.ptam-block-post-grid .is-grid.columns-5{grid-template-columns:1fr 1fr 1fr 1fr}}@media only screen and (max-width: 800px){.ptam-block-post-grid .is-grid.columns-5{grid-template-columns:1fr 1fr 1fr}}.ptam-block-post-grid .is-grid.columns-6{grid-template-columns:1fr 1fr 1fr 1fr 1fr 1fr}@media only screen and (max-width: 1000px){.ptam-block-post-grid .is-grid.columns-6{grid-template-columns:1fr 1fr 1fr 1fr}}@media only screen and (max-width: 800px){.ptam-block-post-grid .is-grid.columns-6{grid-template-columns:1fr 1fr 1fr}}@media only screen and (max-width: 600px){.ptam-block-post-grid div[class*=columns].is-grid{grid-template-columns:1fr}}.ptam-block-post-grid .ptam-block-post-grid-image{margin:10px 0}.ptam-block-post-grid .ptam-block-post-grid-image img{display:inline-block}.ptam-block-post-grid .is-list .ptam-block-post-grid-image{margin-top:0}.ptam-block-post-grid .ptam-block-post-grid-text{text-align:left}.ptam-block-post-grid .ptam-block-post-grid-image .avatar{height:auto;width:inherit;border-radius:0}.ptam-block-post-grid .ptam-block-post-grid-title{margin-top:0;margin-bottom:15px;font-size:28px;line-height:1.2;clear:none}.ptam-block-post-grid .ptam-block-post-grid-title:before{display:none}.ptam-block-post-grid .ptam-block-post-grid-title:after{display:none}.ptam-block-post-grid .ptam-block-post-grid-title a{color:#000;box-shadow:none;transition:.3s ease}.ptam-block-post-grid .ptam-block-post-grid-byline{text-transform:uppercase;font-size:13px;letter-spacing:1px;color:#626e81;margin-bottom:15px}.ptam-block-post-grid .ptam-text-lower-case{text-transform:none}.ptam-block-post-grid .ptam-block-post-grid-author,.ptam-block-post-grid .ptam-block-post-grid-date{display:inline-block}.ptam-block-post-grid .ptam-block-post-grid-author:not(:last-child):after,.ptam-block-post-grid .ptam-block-post-grid-date:not(:last-child):after{content:"·";vertical-align:middle;margin:0 5px;line-height:1}.ptam-block-post-grid .ptam-block-post-grid-author a{box-shadow:unset}.ptam-block-post-grid .ptam-block-post-grid-author a:hover{color:inherit;text-decoration:none;box-shadow:unset}.ptam-block-post-grid .ptam-block-post-grid-text p{margin:0 0 15px 0;line-height:1.5;font-size:18px}@media only screen and (max-width: 600px){.ptam-block-post-grid .ptam-block-post-grid-text p{font-size:16px}}.ptam-block-post-grid .ptam-block-post-grid-text p:last-of-type{margin-bottom:0}.ptam-block-post-grid .ptam-block-post-grid-link{display:inline-block;box-shadow:none;transition:.3s ease;font-weight:bold;color:#000}.ptam-block-post-grid .ptam-block-post-grid-link:hover{box-shadow:0 -2px 0 inset}.ptam-block-post-grid .ptam-block-post-grid-excerpt div+p{margin-top:15px}.ptam-block-post-grid .is-list article{display:grid;grid-template-columns:30% 1fr;grid-template-rows:1fr;grid-gap:0 2em}.ptam-block-post-grid .is-list article:not(:last-child){margin-bottom:5%;padding-bottom:5%}@media only screen and (min-width: 600px){.ptam-block-post-grid .is-list article:not(:last-child){border-bottom:solid 1px #eee}}@media only screen and (max-width: 600px){.ptam-block-post-grid .is-list article{grid-template-columns:1fr}}.ptam-block-post-grid .is-list.is-custom article{display:block;grid-template-columns:100% 1fr;grid-template-rows:1fr;grid-gap:0 2em}.ptam-block-post-grid .is-list .ptam-block-post-grid-image{margin-bottom:0}@media only screen and (max-width: 600px){.ptam-block-post-grid .is-list .ptam-block-post-grid-image{margin-bottom:5%}}.ptam-block-post-grid .is-list h1.ptam-block-post-grid-title{margin-top:10px 0}@media only screen and (min-width: 600px){.ptam-block-post-grid .is-list h1.ptam-block-post-grid-title{font-size:38px}}.ptam-block-post-grid .is-list h2.ptam-block-post-grid-title{margin-top:10px 0}@media only screen and (min-width: 600px){.ptam-block-post-grid .is-list h2.ptam-block-post-grid-title{font-size:34px}}.ptam-block-post-grid .is-list h3.ptam-block-post-grid-title{margin-top:10px 0}@media only screen and (min-width: 600px){.ptam-block-post-grid .is-list h3.ptam-block-post-grid-title{font-size:34px}}.ptam-block-post-grid .is-list h4.ptam-block-post-grid-title{margin-top:10px 0}@media only screen and (min-width: 600px){.ptam-block-post-grid .is-list h4.ptam-block-post-grid-title{font-size:28px}}.ptam-block-post-grid .is-list h5.ptam-block-post-grid-title{margin-top:10px 0}@media only screen and (min-width: 600px){.ptam-block-post-grid .is-list h5.ptam-block-post-grid-title{font-size:22px}}.ptam-block-post-grid .is-list h6.ptam-block-post-grid-title{margin-top:10px 0}@media only screen and (min-width: 600px){.ptam-block-post-grid .is-list h6.ptam-block-post-grid-title{font-size:18px}}.ptam-block-post-grid .is-list .no-thumb .ptam-block-post-grid-text{grid-column:span 1}button.ptam-media-alt-upload.components-button{margin-bottom:20px}button.ptam-media-alt-reset.components-button{margin:15px 0}.ptam-term-select .woocommerce-search-list__selected-header button,.ptam-term-exclude .woocommerce-search-list__selected-header button{display:block;margin:1em 0}.ptam-term-select .woocommerce-search-list__selected,.ptam-term-exclude .woocommerce-search-list__selected{margin-bottom:15px}.ptam-term-select .woocommerce-tag.has-remove,.ptam-term-exclude .woocommerce-tag.has-remove{display:flex;align-items:center;justify-content:space-between;background:#fff;padding:10px 20px;border:1px solid #eee;color:#000}.ptam-term-select .woocommerce-tag.has-remove .woocommerce-tag__remove,.ptam-term-exclude .woocommerce-tag.has-remove .woocommerce-tag__remove{display:block;align-self:flex-end}.ptam-term-grid-loading{display:flex;flex-wrap:wrap;justify-content:center;align-items:center;text-align:center;width:100%}.ptam-term-grid-loading h1{width:100%;text-align:center}.ptam-term-grid{position:relative;display:flex;flex-wrap:wrap;display:grid;grid-template-columns:repeat(auto-fill, minmax(200px, 1fr));grid-auto-rows:minmax(150px, auto);grid-gap:1em;justify-items:center}.ptam-term-grid.columns-1{grid-template-columns:1fr}.ptam-term-grid.columns-2{grid-template-columns:1fr 1fr}@media only screen and (max-width: 500px){.ptam-term-grid.columns-2{grid-template-columns:1fr}}.ptam-term-grid.columns-3{grid-template-columns:1fr 1fr 1fr}@media only screen and (max-width: 600px){.ptam-term-grid.columns-3{grid-template-columns:1fr 1fr}}@media only screen and (max-width: 500px){.ptam-term-grid.columns-3{grid-template-columns:1fr}}.ptam-term-grid.columns-4{grid-template-columns:1fr 1fr 1fr 1fr}@media only screen and (max-width: 800px){.ptam-term-grid.columns-4{grid-template-columns:1fr 1fr 1fr}}@media only screen and (max-width: 600px){.ptam-term-grid.columns-4{grid-template-columns:1fr 1fr}}@media only screen and (max-width: 500px){.ptam-term-grid.columns-4{grid-template-columns:1fr}}.ptam-term-grid .ptam-term-grid-anchor-full{position:absolute;z-index:3;display:block;width:100%;height:100%}.ptam-term-grid .ptam-term-grid-item{position:relative;display:flex;flex-wrap:wrap;align-items:center;justify-content:center;min-height:300px;width:100%;background:#24292d;color:#fff;background-size:cover;background-repeat:no-repeat;background-position:center center;text-align:center;padding:20px;overflow:hidden;transition:background-color .5s ease;word-break:break-all;box-sizing:border-box;margin-left:5px;margin-right:5px;flex:1 1 300px}.ptam-term-grid .ptam-term-grid-item .ptam-term-grid-item-content{position:relative;z-index:2}.ptam-term-grid .ptam-term-grid-item .ptam-term-grid-button{display:inline-block;background-color:#32373c;color:#fff;border:none;border-radius:28px;font-weight:500;box-shadow:none;cursor:pointer;display:inline-block;font-size:18px;margin:0;margin-top:1em;padding:12px 24px;text-align:center;text-decoration:none;overflow-wrap:break-word;transition:background-color .5s ease}.ptam-term-grid .ptam-term-grid-item h2{color:#fff;font-size:2.2em}.ptam-term-grid .ptam-term-grid-item .ptam-term-grid-item-description{font-size:1.4em;line-height:1.5em}.ptam-fp-wrapper .ptam-fp-term{margin-bottom:20px}.ptam-fp-wrapper .ptam-fp-term span{display:inline-block}.ptam-fp-wrapper .ptam-featured-post-item{padding-bottom:1.3em;border-bottom:1px solid #ddd}.ptam-fp-wrapper .ptam-featured-post-item:last-child{border-bottom:0}.ptam-fp-wrapper .ptam-featured-post-meta .entry-title{font-weight:700;line-height:1.4em;margin:1em 0}.ptam-fp-wrapper .ptam-featured-post-meta .entry-title a{color:#000;text-decoration:none}.ptam-fp-wrapper .ptam-featured-post-meta .entry-title a:hover{color:#000;text-decoration:none}.ptam-fp-wrapper .ptam-featured-post-meta .entry-meta{display:flex;flex-wrap:wrap;justify-content:space-between;margin-bottom:1em;font-size:12px}.ptam-fp-wrapper .ptam-featured-post-meta .entry-meta .author-name a{font-weight:700;color:#6c6c6c;text-decoration:none}.ptam-fp-wrapper .ptam-featured-post-meta .entry-meta .author-name a:hover{color:#333;text-decoration:none}.ptam-fp-wrapper .ptam-featured-post-meta .entry-meta .author-name a:before{font-family:"PTAM";content:"";display:inline-block;margin-right:2px}.ptam-fp-wrapper .ptam-featured-post-meta .entry-meta .post-date{color:#6c6c6c}.ptam-fp-wrapper .ptam-featured-post-meta .entry-meta .post-date:before{font-family:"PTAM";content:"";display:inline-block;margin-right:2px}.ptam-fp-wrapper .ptam-featured-post-meta .entry-meta .post-comments{color:#000}.ptam-fp-wrapper .ptam-featured-post-meta .entry-meta .post-comments:before{font-family:"PTAM";content:"";display:inline-block;margin-right:2px}.ptam-fp-wrapper .ptam-featured-post-content{line-height:1.2em;margin:1em 0}.ptam-fp-wrapper .ptam-featured-post-button a{display:inline-block;padding:10px 20px;text-decoration:none}.ptam-fp-wrapper .ptam-featured-post-button a :hover{text-decoration:none}.ptam-pagination>ul,body.has-blocks .fl-post-content .ptam-pagination>ul{list-style-type:none;margin:0;padding:0}.ptam-pagination li,body.has-blocks .fl-post-content .ptam-pagination li{display:inline-block}.ptam-pagination li>span,.ptam-pagination li>a,body.has-blocks .fl-post-content .ptam-pagination li>span,body.has-blocks .fl-post-content .ptam-pagination li>a{display:inline-block;padding:5px 10px;margin:0 4px 0 0;border:1px solid #eee;line-height:1;text-decoration:none;border-radius:2px;font-weight:600}.ptam-pagination li>span:hover,.ptam-pagination li>a:hover,body.has-blocks .fl-post-content .ptam-pagination li>span:hover,body.has-blocks .fl-post-content .ptam-pagination li>a:hover{background:#f9f9f9}.ptam-pagination li>span.current,body.has-blocks .fl-post-content .ptam-pagination li>span.current{background:#f9f9f9}.ptam-apply{margin-top:15px;margin-bottom:20px}.ptam-term-select .woocommerce-search-list__selected,.ptam-term-exclude .woocommerce-search-list__selected{display:none}.ptam-term-select .components-base-control__field,.ptam-term-exclude .components-base-control__field{display:none}
2 |
--------------------------------------------------------------------------------
/includes/class-functions.php:
--------------------------------------------------------------------------------
1 | 1 ) {
110 | $opacity = 1.0;
111 | }
112 | $output = 'rgba(' . implode( ',', $rgb ) . ',' . $opacity . ')';
113 | } else {
114 | $output = 'rgb(' . implode( ',', $rgb ) . ')';
115 | }
116 |
117 | // Return rgb(a) color string.
118 | return $output;
119 | }
120 |
121 | /**
122 | * Return an image URL.
123 | *
124 | * @param int $attachment_id The attachment ID.
125 | * @param string $size The image size to retrieve.
126 | *
127 | * @return string Image URL or empty string if not found.
128 | */
129 | public static function get_image( $attachment_id = 0, $size = 'large' ) {
130 | $maybe_image = wp_get_attachment_image_src( $attachment_id, $size );
131 | if ( ! $maybe_image ) {
132 | return '';
133 | }
134 | if ( isset( $maybe_image[0] ) ) {
135 | return esc_url( $maybe_image[0] );
136 | }
137 | return '';
138 | }
139 |
140 | /**
141 | * Get an image from term meta.
142 | *
143 | * @param string $size The image size.
144 | * @param string $meta_field The meta field to query.
145 | * @param string $type The type of meta to retrieve (meta, acf, pods).
146 | * @param string $taxonomy The taxonomy slug to retrieve images for.
147 | * @param int $term_id The term to retrieve data for.
148 | *
149 | * @return string Image URL or blank if not found.
150 | */
151 | public static function get_term_image( $size = 'large', $meta_field = '', $type = 'meta', $taxonomy = 'category', $term_id = 0 ) {
152 | if ( 'none' === $type ) {
153 | return '';
154 | }
155 | if ( 'acf' === $type && function_exists( 'get_field' ) ) {
156 | $acf_term_id = $taxonomy . '_' . $term_id;
157 | $acf_term_value = get_field( $meta_field, $acf_term_id );
158 | if ( ! $acf_term_value ) {
159 | return '';
160 | }
161 | if ( is_numeric( $acf_term_value ) ) {
162 | $image = self::get_image( $acf_term_value, $size );
163 | return $image;
164 | } elseif ( is_array( $acf_term_value ) && isset( $acf_term_value['url'] ) ) {
165 | return esc_url( $acf_term_value['url'] );
166 | } elseif ( is_string( $acf_term_value ) ) {
167 | return esc_url( $acf_term_value );
168 | } else {
169 | return '';
170 | }
171 | }
172 | if ( 'meta' === $type ) {
173 | $term_value = get_term_meta( $term_id, $meta_field, true );
174 | if ( is_numeric( $term_value ) ) {
175 | $image = self::get_image( $term_value, $size );
176 | return $image;
177 | } elseif ( is_array( $term_value ) && isset( $term_value['url'] ) ) {
178 | return esc_url( $term_value['url'] );
179 | } elseif ( is_string( $term_value ) ) {
180 | return esc_url( $term_value );
181 | } else {
182 | return '';
183 | }
184 | }
185 | if ( 'pods' === $type ) {
186 | $term_value = get_term_meta( $term_id, $meta_field, true );
187 | if ( is_numeric( $term_value ) ) {
188 | $image = self::get_image( $term_value, $size );
189 | return $image;
190 | } elseif ( is_array( $term_value ) && isset( $term_value['ID'] ) ) {
191 | return self::get_image( $term_value['ID'], $size );
192 | } elseif ( is_string( $term_value ) ) {
193 | return esc_url( $term_value );
194 | } else {
195 | return '';
196 | }
197 | }
198 | return '';
199 | }
200 |
201 | /**
202 | * Get web safe fonts
203 | *
204 | * @return array $fonts Fonts to Use
205 | */
206 | public static function get_fonts() {
207 | /**
208 | * Filter the fonts that are available.
209 | *
210 | * @since 3.5.0
211 | *
212 | * @param array associative array of key/value pairs of fonts.
213 | */
214 | $fonts = apply_filters(
215 | 'ptam_fonts',
216 | array(
217 | 'inherit' => 'Default',
218 | 'arial' => 'Arial',
219 | 'helvetica' => 'Helvetica',
220 | 'times new roman' => 'Times New Roman',
221 | 'times' => 'Times',
222 | 'courier new' => 'Courier New',
223 | 'courier' => 'Courier',
224 | 'verdana' => 'Verdana',
225 | 'georgia' => 'Georgia',
226 | 'palatino' => 'Palatino',
227 | 'garamond' => 'Garamond',
228 | 'bookman' => 'Bookman',
229 | 'trebuchet ms' => 'Trebuchet MS',
230 | 'arial black' => 'Arial Black',
231 | 'impact' => 'Impact',
232 | )
233 | );
234 | $pro_fonts = array();
235 | // Add Typekit Fonts.
236 | if ( defined( 'CUSTOM_TYPEKIT_FONTS_FILE' ) ) {
237 | $adobe_fonts = get_option( 'custom-typekit-fonts', array() );
238 | if ( isset( $adobe_fonts['custom-typekit-font-details'] ) ) {
239 | foreach ( $adobe_fonts['custom-typekit-font-details'] as $font_name => $font_details ) {
240 | $pro_fonts[ $font_details['slug'] ] = $font_details['family'];
241 | }
242 | }
243 | }
244 | $fonts = array_merge( $fonts, $pro_fonts );
245 | return $fonts;
246 | }
247 |
248 | /**
249 | * Return the URL to the admin screen
250 | *
251 | * @param string $tab Tab path to load.
252 | * @param string $sub_tab Subtab path to load.
253 | *
254 | * @return string URL to admin screen. Output is not escaped.
255 | */
256 | public static function get_settings_url( $tab = '', $sub_tab = '' ) {
257 | $options_url = admin_url( 'options-general.php?page=custom-query-blocks' );
258 | if ( ! empty( $tab ) ) {
259 | $options_url = add_query_arg( array( 'tab' => sanitize_title( $tab ) ), $options_url );
260 | if ( ! empty( $sub_tab ) ) {
261 | $options_url = add_query_arg( array( 'subtab' => sanitize_title( $sub_tab ) ), $options_url );
262 | }
263 | }
264 | return $options_url;
265 | }
266 |
267 | /**
268 | * Get the current admin tab.
269 | *
270 | * @return null|string Current admin tab.
271 | */
272 | public static function get_admin_tab() {
273 | $tab = filter_input( INPUT_GET, 'tab', FILTER_DEFAULT );
274 | if ( $tab && is_string( $tab ) ) {
275 | return sanitize_text_field( sanitize_title( $tab ) );
276 | }
277 | return null;
278 | }
279 |
280 | /**
281 | * Get the current admin sub-tab.
282 | *
283 | * @return null|string Current admin sub-tab.
284 | */
285 | public static function get_admin_sub_tab() {
286 | $tab = filter_input( INPUT_GET, 'tab', FILTER_DEFAULT );
287 | if ( $tab && is_string( $tab ) ) {
288 | $subtab = filter_input( INPUT_GET, 'subtab', FILTER_DEFAULT );
289 | if ( $subtab && is_string( $subtab ) ) {
290 | return sanitize_text_field( sanitize_title( $subtab ) );
291 | }
292 | }
293 | return null;
294 | }
295 |
296 | /**
297 | * Return the plugin slug.
298 | *
299 | * @return string plugin slug.
300 | */
301 | public static function get_plugin_slug() {
302 | return dirname( plugin_basename( PTAM_FILE ) );
303 | }
304 |
305 | /**
306 | * Return the plugin path.
307 | *
308 | * @return string plugin path.
309 | */
310 | public static function get_plugin_path() {
311 | return plugin_basename( PTAM_FILE );
312 | }
313 |
314 | /**
315 | * Return the basefile for the plugin.
316 | *
317 | * @return string base file for the plugin.
318 | */
319 | public static function get_plugin_file() {
320 | return plugin_basename( PTAM_FILE );
321 | }
322 |
323 | /**
324 | * Return the version for the plugin.
325 | *
326 | * @return float version for the plugin.
327 | */
328 | public static function get_plugin_version() {
329 | return PTAM_VERSION;
330 | }
331 |
332 | /**
333 | * Get the Plugin Logo.
334 | */
335 | public static function get_plugin_logo() {
336 | /**
337 | * Filer the output of the plugin logo.
338 | *
339 | * Potentially change branding of the plugin.
340 | *
341 | * @since 5.1.0
342 | *
343 | * @param string URL to the plugin logo.
344 | */
345 | return apply_filters( 'ptam_plugin_logo_full', self::get_plugin_url( '/img/logo.png' ) );
346 | }
347 |
348 | /**
349 | * Get the plugin author name.
350 | */
351 | public static function get_plugin_author() {
352 | /**
353 | * Filer the output of the plugin Author.
354 | *
355 | * Potentially change branding of the plugin.
356 | *
357 | * @since 5.1.0
358 | *
359 | * @param string Plugin Author name.
360 | */
361 | $plugin_author = apply_filters( 'ptam_plugin_author', 'MediaRon LLC' );
362 | return $plugin_author;
363 | }
364 |
365 | /**
366 | * Return the Plugin author URI.
367 | */
368 | public static function get_plugin_author_uri() {
369 | /**
370 | * Filer the output of the plugin Author URI.
371 | *
372 | * Potentially change branding of the plugin.
373 | *
374 | * @since 5.1.0
375 | *
376 | * @param string Plugin Author URI.
377 | */
378 | $plugin_author = apply_filters( 'ptam_plugin_author_uri', 'https://mediaron.com' );
379 | return $plugin_author;
380 | }
381 |
382 | /**
383 | * Get the Plugin Icon.
384 | */
385 | public static function get_plugin_icon() {
386 | /**
387 | * Filer the output of the plugin icon.
388 | *
389 | * Potentially change branding of the plugin.
390 | *
391 | * @since 5.1.0
392 | *
393 | * @param string URL to the plugin icon.
394 | */
395 | return apply_filters( 'ptam_plugin_icon', self::get_plugin_url( '/img/logo.png' ) );
396 | }
397 |
398 | /**
399 | * Return the plugin name for the plugin.
400 | *
401 | * @return string Plugin name.
402 | */
403 | public static function get_plugin_name() {
404 | /**
405 | * Filer the output of the plugin name.
406 | *
407 | * Potentially change branding of the plugin.
408 | *
409 | * @since 5.1.0
410 | *
411 | * @param string Plugin name.
412 | */
413 | return apply_filters( 'ptam_plugin_name', __( 'Custom Query Blocks', 'post-type-archive-mapping' ) );
414 | }
415 |
416 | /**
417 | * Return the plugin description for the plugin.
418 | *
419 | * @return string plugin description.
420 | */
421 | public static function get_plugin_description() {
422 | /**
423 | * Filer the output of the plugin name.
424 | *
425 | * Potentially change branding of the plugin.
426 | *
427 | * @since 5.1.0
428 | *
429 | * @param string Plugin description.
430 | */
431 | return apply_filters( 'ptam_plugin_description', __( 'Map your post type and term archives to a page and use our Gutenberg blocks to show posts or terms.', 'post-type-archive-mapping' ) );
432 | }
433 |
434 | /**
435 | * Retrieve the plugin URI.
436 | */
437 | public static function get_plugin_uri() {
438 | /**
439 | * Filer the output of the plugin URI.
440 | *
441 | * Potentially change branding of the plugin.
442 | *
443 | * @since 5.1.0
444 | *
445 | * @param string Plugin URI.
446 | */
447 | return apply_filters( 'ptam_plugin_uri', 'https://mediaron.com/custom-query-blocks/' );
448 | }
449 |
450 | /**
451 | * Retrieve the plugin Menu Name.
452 | */
453 | public static function get_plugin_menu_name() {
454 | /**
455 | * Filer the output of the plugin menu name.
456 | *
457 | * Potentially change branding of the plugin.
458 | *
459 | * @since 5.1.0
460 | *
461 | * @param string Plugin Menu Name.
462 | */
463 | return apply_filters( 'ptam_plugin_menu_name', __( 'Custom Query Blocks', 'post-type-archive-mapping' ) );
464 | }
465 |
466 | /**
467 | * Retrieve the plugin title.
468 | */
469 | public static function get_plugin_title() {
470 | /**
471 | * Filer the output of the plugin title.
472 | *
473 | * Potentially change branding of the plugin.
474 | *
475 | * @since 5.1.0
476 | *
477 | * @param string Plugin Menu Name.
478 | */
479 | return apply_filters( 'ptam_plugin_menu_title', self::get_plugin_name() );
480 | }
481 |
482 | /**
483 | * Returns appropriate html for KSES.
484 | *
485 | * @param bool $svg Whether to add SVG data to KSES.
486 | */
487 | public static function get_kses_allowed_html( $svg = true ) {
488 | $allowed_tags = wp_kses_allowed_html();
489 |
490 | $allowed_tags['nav'] = array(
491 | 'class' => array(),
492 | );
493 | $allowed_tags['a']['class'] = array();
494 |
495 | if ( ! $svg ) {
496 | return $allowed_tags;
497 | }
498 | $allowed_tags['svg'] = array(
499 | 'xmlns' => array(),
500 | 'fill' => array(),
501 | 'viewbox' => array(),
502 | 'role' => array(),
503 | 'aria-hidden' => array(),
504 | 'focusable' => array(),
505 | 'class' => array(),
506 | );
507 |
508 | $allowed_tags['path'] = array(
509 | 'd' => array(),
510 | 'fill' => array(),
511 | 'opacity' => array(),
512 | );
513 |
514 | $allowed_tags['g'] = array();
515 |
516 | $allowed_tags['use'] = array(
517 | 'xlink:href' => array(),
518 | );
519 |
520 | $allowed_tags['symbol'] = array(
521 | 'aria-hidden' => array(),
522 | 'viewBox' => array(),
523 | 'id' => array(),
524 | 'xmls' => array(),
525 | );
526 |
527 | return $allowed_tags;
528 | }
529 |
530 | /**
531 | * Get the plugin directory for a path.
532 | *
533 | * @param string $path The path to the file.
534 | *
535 | * @return string The new path.
536 | */
537 | public static function get_plugin_dir( $path = '' ) {
538 | $dir = rtrim( plugin_dir_path( PTAM_FILE ), '/' );
539 | if ( ! empty( $path ) && is_string( $path ) ) {
540 | $dir .= '/' . ltrim( $path, '/' );
541 | }
542 | return $dir;
543 | }
544 |
545 | /**
546 | * Return a plugin URL path.
547 | *
548 | * @param string $path Path to the file.
549 | *
550 | * @return string URL to to the file.
551 | */
552 | public static function get_plugin_url( $path = '' ) {
553 | $dir = rtrim( plugin_dir_url( PTAM_FILE ), '/' );
554 | if ( ! empty( $path ) && is_string( $path ) ) {
555 | $dir .= '/' . ltrim( $path, '/' );
556 | }
557 | return $dir;
558 | }
559 |
560 | /**
561 | * Gets the highest priority for a filter.
562 | *
563 | * @param int $subtract The amount to subtract from the high priority.
564 | *
565 | * @return int priority.
566 | */
567 | public static function get_highest_priority( $subtract = 0 ) {
568 | $highest_priority = PHP_INT_MAX;
569 | $subtract = absint( $subtract );
570 | if ( 0 === $subtract ) {
571 | --$highest_priority;
572 | } else {
573 | $highest_priority = absint( $highest_priority - $subtract );
574 | }
575 | return $highest_priority;
576 | }
577 | }
578 |
--------------------------------------------------------------------------------
/post-type-archive-mapping.php:
--------------------------------------------------------------------------------
1 | enqueue = new PTAM\Includes\Enqueue();
84 | $this->enqueue->run();
85 |
86 | // Run if blocks are enabled.
87 | if ( false === Options::is_blocks_disabled() ) {
88 | // Register REST for the plugin.
89 | $this->rest = new PTAM\Includes\Rest\Rest();
90 | $this->rest->run();
91 |
92 | // Register Custom Post Type Block.
93 | $this->cpt_block_one = new PTAM\Includes\Blocks\Custom_Post_Types\Custom_Post_Types();
94 | $this->cpt_block_one->run();
95 |
96 | // Register Term Grid Block.
97 | $this->term_grid = new PTAM\Includes\Blocks\Term_Grid\Terms();
98 | $this->term_grid->run();
99 |
100 | // Register Featured Post Block.
101 | $this->featured_posts = new PTAM\Includes\Blocks\Featured_Posts\Posts();
102 | $this->featured_posts->run();
103 |
104 | // Gutenberg Helper which sets the block categories.
105 | $this->gutenberg = new PTAM\Includes\Admin\Gutenberg();
106 | $this->gutenberg->run();
107 | }
108 |
109 | /**
110 | * Filter to disable archive mapping.
111 | * This is useful if you want to use the blocks but not the archive mapping.
112 | *
113 | * @since 5.1.8
114 | */
115 | $ptam_disabled = apply_filters( 'ptam_archive_mapping_disabled', false );
116 |
117 | // Run if page columns are enabled.
118 | if ( false === Options::is_page_columns_disabled() && false === Options::is_archive_mapping_disabled() && ! $ptam_disabled ) {
119 | // Page columns.
120 | $this->page_columns = new PTAM\Includes\Admin\Page_Columns();
121 | $this->page_columns->run();
122 | }
123 |
124 | if ( ! $ptam_disabled ) {
125 | // Yoast Compatibility.
126 | $this->yoast = new PTAM\Includes\Yoast();
127 | $this->yoast->run();
128 | }
129 |
130 | // Admin settings.
131 | $this->admin_settings = new PTAM\Includes\Admin\Admin_Settings();
132 | } //end constructor
133 |
134 | /**
135 | * Main plugin initialization
136 | *
137 | * Initialize admin menus, options,and scripts
138 | *
139 | * @since 1.0.0
140 | * @access public
141 | *
142 | * @see __construct
143 | */
144 | public function init() {
145 |
146 | /**
147 | * Filter to disable archive mapping.
148 | * This is useful if you want to use the blocks but not the archive mapping.
149 | *
150 | * @since 5.1.8
151 | */
152 | $ptam_disabled = apply_filters( 'ptam_archive_mapping_disabled', false );
153 |
154 | // Check if archive mapping is disabled.
155 | if ( false === Options::is_archive_mapping_disabled() && ! $ptam_disabled ) {
156 | // Archive mapping settings.
157 | add_action( 'admin_init', array( $this, 'init_admin_settings' ) );
158 | add_action( 'pre_get_posts', array( $this, 'maybe_override_archive' ) );
159 |
160 | // Output admin notices once when saving archive mapping.
161 | add_action( 'admin_notices', array( $this, 'admin_notices' ) );
162 |
163 | // 404 page detection.
164 | add_filter( 'template_include', array( $this, 'maybe_force_404_template' ), 1 );
165 | }
166 | } //end init
167 |
168 | /**
169 | * This is a catch-all. Any 404 error not caught will be directed here.
170 | * If a 404 error is caught, will load the page template instead.
171 | *
172 | * @param string $template The regular template.
173 | *
174 | * @return string $template The updated template.
175 | */
176 | public function maybe_force_404_template( $template ) {
177 | if ( is_404() ) {
178 | $page_id_404 = absint( get_option( 'post-type-archive-mapping-404', 0 ) );
179 | if ( $page_id_404 > 0 ) {
180 | $args = array(
181 | 'post_type' => 'page',
182 | 'page_id' => $page_id_404,
183 | 'post_status' => 'publish',
184 | 'posts_per_page' => 1,
185 | );
186 | /* I wise woman once told me to never use query_posts. Like NEVER. I had no choice here. */
187 | query_posts( // phpcs:ignore
188 | $args
189 | );
190 | return get_page_template();
191 | }
192 | }
193 | return $template;
194 | }
195 |
196 | /**
197 | * Add admin notices when things go wrong.
198 | *
199 | * @since 3.3.5
200 | */
201 | public function admin_notices() {
202 | // Check for any term errors.
203 | if ( get_option( 'ptam_error_message', '' ) ) {
204 | printf(
205 | '