Content.php
1 year ago
LoginForm.php
1 year ago
LoginRedirect.php
1 year ago
PostList.php
1 year ago
PostList.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * AAM shortcode strategy for post list |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @version 6.9.35 |
| 15 | */ |
| 16 | class AAM_Service_Shortcode_Handler_PostList |
| 17 | { |
| 18 | |
| 19 | /** |
| 20 | * Shortcode arguments |
| 21 | * |
| 22 | * @var array |
| 23 | * |
| 24 | * @access protected |
| 25 | * @version 6.9.35 |
| 26 | */ |
| 27 | protected $args; |
| 28 | |
| 29 | /** |
| 30 | * Initialize shortcode decorator |
| 31 | * |
| 32 | * Expecting attributes in $args are the list of arguments that WP_Query receives |
| 33 | * |
| 34 | * @param array $args |
| 35 | * |
| 36 | * @return void |
| 37 | * |
| 38 | * @access public |
| 39 | * @version 6.9.35 |
| 40 | */ |
| 41 | public function __construct($args, $content = null) |
| 42 | { |
| 43 | // Determine correct default status & post type |
| 44 | $post_type = isset($args['post_type']) ? $args['post_type'] : 'post'; |
| 45 | $status = $post_type === 'attachment' ? 'inherit' : 'publish'; |
| 46 | |
| 47 | $this->args = array_merge( |
| 48 | [ |
| 49 | 'post_type' => 'post', |
| 50 | 'nopaging' => true, |
| 51 | 'post_status' => $status, |
| 52 | 'template' => 'template-parts/content' |
| 53 | ], |
| 54 | is_array($args) ? $args : [] |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Process the shortcode |
| 60 | * |
| 61 | * @return string |
| 62 | * |
| 63 | * @access public |
| 64 | * @version 6.9.35 |
| 65 | */ |
| 66 | public function run() |
| 67 | { |
| 68 | // Making sure that post type is public |
| 69 | $post_type = get_post_type_object($this->args['post_type']); |
| 70 | |
| 71 | if (is_a($post_type, 'WP_Post_Type') && $post_type->public) { |
| 72 | $result = AAM_Backend_View::loadPartial('post-list', array_merge( |
| 73 | $this->args, |
| 74 | array('id' => uniqid()) |
| 75 | )); |
| 76 | } else { |
| 77 | $result = null; |
| 78 | } |
| 79 | |
| 80 | return $result; |
| 81 | } |
| 82 | |
| 83 | } |