| @@ -7,8 +7,12 @@ | ||
| 7 | 7 | * |
| 8 | 8 | * @package automattic/jetpack |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit( 0 ); | |
| 13 | +} | |
| 14 | + | |
| 11 | 15 | add_shortcode( 'archives', 'archives_shortcode' ); |
| 12 | 16 | |
| 13 | 17 | /** |
| 14 | 18 | * Display Archives shortcode. |
| @@ -47,9 +51,36 @@ | ||
| 47 | 51 | if ( empty( $limit ) ) { |
| 48 | 52 | $limit = ''; |
| 49 | 53 | } |
| 50 | 54 | |
| 51 | - $showcount = ( false !== $attr['showcount'] && 'false' !== $attr['showcount'] ) ? true : false; | |
| 55 | + /* | |
| 56 | + * The `postbypost` type (also the default) lists one entry per published | |
| 57 | + * post. Left unbounded, wp_get_archives() materializes the entire post table | |
| 58 | + * in a single request, which can exhaust PHP memory and fatal on large sites. | |
| 59 | + * Apply a sane, filterable default cap when no explicit limit was supplied. | |
| 60 | + */ | |
| 61 | + if ( 'postbypost' === $attr['type'] && '' === $limit ) { | |
| 62 | + /** | |
| 63 | + * Filter the default number of entries listed by the [archives] shortcode | |
| 64 | + * when using the unbounded `postbypost` type with no explicit `limit`. | |
| 65 | + * | |
| 66 | + * Set to 0 to restore the previous (unlimited) behavior, though this is | |
| 67 | + * not recommended on sites with a large number of posts. | |
| 68 | + * | |
| 69 | + * @module shortcodes | |
| 70 | + * | |
| 71 | + * @since 16.0 | |
| 72 | + * | |
| 73 | + * @param int $limit Default maximum number of posts to list. Default 100. | |
| 74 | + */ | |
| 75 | + $default_limit = (int) apply_filters( 'jetpack_archives_shortcode_default_limit', 100 ); | |
| 76 | + | |
| 77 | + if ( $default_limit > 0 ) { | |
| 78 | + $limit = $default_limit; | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + $showcount = false !== $attr['showcount'] && 'false' !== $attr['showcount']; | |
| 52 | 83 | $before = wp_kses( $attr['before'], $allowedposttags ); |
| 53 | 84 | $after = wp_kses( $attr['after'], $allowedposttags ); |
| 54 | 85 | |
| 55 | 86 | // Get the archives. |