| 1 |
<?php |
| 2 |
/** |
| 3 |
* Loop Builder admin screen. |
| 4 |
* |
| 5 |
* Included from King_Addons\Loop_Builder::render_admin_page(), which has |
| 6 |
* already checked the current user's capability. |
| 7 |
* |
| 8 |
* @package King_Addons |
| 9 |
*/ |
| 10 |
|
| 11 |
use King_Addons\Loop_Builder; |
| 12 |
use King_Addons\Loop_Builder\Document as Loop_Document; |
| 13 |
use King_Addons\Loop_Builder\Renderer as Loop_Renderer; |
| 14 |
|
| 15 |
if (!defined('ABSPATH')) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
require_once KING_ADDONS_PATH . 'includes/admin/shared/page-shell.php'; |
| 20 |
|
| 21 |
$ka_loop_templates = Loop_Renderer::get_templates(); |
| 22 |
$ka_loop_sources = Loop_Builder::get_source_post_types(); |
| 23 |
|
| 24 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 25 |
$ka_loop_error = isset($_GET['ka_error']) ? sanitize_key(wp_unslash($_GET['ka_error'])) : ''; |
| 26 |
|
| 27 |
$ka_notices = []; |
| 28 |
|
| 29 |
if ('create' === $ka_loop_error) { |
| 30 |
$ka_notices[] = ['type' => 'error', 'text' => esc_html__('The template could not be created.', 'king-addons')]; |
| 31 |
} |
| 32 |
|
| 33 |
ka_admin_page_open([ |
| 34 |
'title' => esc_html__('Loop Builder', 'king-addons'), |
| 35 |
'subtitle' => esc_html__('Design one card in Elementor, then repeat it for every entry a query returns with the Loop Grid widget.', 'king-addons'), |
| 36 |
'icon' => 'dashicons-screenoptions', |
| 37 |
'icon_color' => 'pink', |
| 38 |
'notices' => $ka_notices, |
| 39 |
]); |
| 40 |
?> |
| 41 |
|
| 42 |
<?php ka_admin_card_open(esc_html__('New loop item', 'king-addons'), 'dashicons-plus-alt'); ?> |
| 43 |
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>"> |
| 44 |
<input type="hidden" name="action" value="king_addons_create_loop_template"> |
| 45 |
<?php wp_nonce_field('king_addons_create_loop_template'); ?> |
| 46 |
|
| 47 |
<?php ka_admin_row_open(esc_html__('Name', 'king-addons'), 'ka-loop-title'); ?> |
| 48 |
<input type="text" id="ka-loop-title" name="loop_title" |
| 49 |
placeholder="<?php esc_attr_e('Post card', 'king-addons'); ?>"> |
| 50 |
<?php ka_admin_row_close(); ?> |
| 51 |
|
| 52 |
<?php ka_admin_row_open(esc_html__('Designed for', 'king-addons'), 'ka-loop-source'); ?> |
| 53 |
<select name="loop_source" id="ka-loop-source"> |
| 54 |
<?php foreach ($ka_loop_sources as $ka_slug => $ka_label) : ?> |
| 55 |
<option value="<?php echo esc_attr($ka_slug); ?>"<?php selected('post', $ka_slug); ?>> |
| 56 |
<?php echo esc_html($ka_label); ?> |
| 57 |
</option> |
| 58 |
<?php endforeach; ?> |
| 59 |
</select> |
| 60 |
<?php ka_admin_row_close(esc_html__('Only decides which entry the editor previews the card with.', 'king-addons')); ?> |
| 61 |
|
| 62 |
<p class="ka-submit"> |
| 63 |
<button type="submit" class="ka-btn ka-btn-primary"> |
| 64 |
<span class="dashicons dashicons-edit"></span> |
| 65 |
<?php esc_html_e('Create and edit', 'king-addons'); ?> |
| 66 |
</button> |
| 67 |
</p> |
| 68 |
</form> |
| 69 |
<?php ka_admin_card_close(); ?> |
| 70 |
|
| 71 |
<?php ka_admin_card_open(esc_html__('Loop items', 'king-addons'), 'dashicons-screenoptions'); ?> |
| 72 |
<?php if (empty($ka_loop_templates)) : ?> |
| 73 |
<div class="ka-empty"> |
| 74 |
<p><?php esc_html_e('No loop items yet. Create one above, design the card in Elementor, then drop a Loop Grid widget on any page and pick it.', 'king-addons'); ?></p> |
| 75 |
</div> |
| 76 |
<?php else : ?> |
| 77 |
<table class="ka-table"> |
| 78 |
<thead> |
| 79 |
<tr> |
| 80 |
<th><?php esc_html_e('Name', 'king-addons'); ?></th> |
| 81 |
<th><?php esc_html_e('Designed for', 'king-addons'); ?></th> |
| 82 |
<th><?php esc_html_e('ID', 'king-addons'); ?></th> |
| 83 |
<th class="ka-table-actions"><?php esc_html_e('Actions', 'king-addons'); ?></th> |
| 84 |
</tr> |
| 85 |
</thead> |
| 86 |
<tbody> |
| 87 |
<?php foreach ($ka_loop_templates as $ka_id => $ka_title) : ?> |
| 88 |
<?php |
| 89 |
$ka_source = (string) get_post_meta($ka_id, Loop_Document::META_SOURCE, true); |
| 90 |
$ka_source_label = $ka_loop_sources[$ka_source] ?? $ka_source; |
| 91 |
?> |
| 92 |
<tr> |
| 93 |
<td><strong><?php echo esc_html($ka_title); ?></strong></td> |
| 94 |
<td><?php echo esc_html('' !== $ka_source_label ? $ka_source_label : '—'); ?></td> |
| 95 |
<td><code><?php echo (int) $ka_id; ?></code></td> |
| 96 |
<td class="ka-table-actions"> |
| 97 |
<a class="ka-btn ka-btn-secondary ka-btn-sm" href="<?php echo esc_url(add_query_arg(['post' => $ka_id, 'action' => 'elementor'], admin_url('post.php'))); ?>"> |
| 98 |
<span class="dashicons dashicons-edit"></span> |
| 99 |
<?php esc_html_e('Edit', 'king-addons'); ?> |
| 100 |
</a> |
| 101 |
<a class="ka-btn ka-btn-secondary ka-btn-sm" href="<?php echo esc_url(get_delete_post_link($ka_id)); ?>" |
| 102 |
onclick="return window.confirm(<?php echo esc_attr(wp_json_encode(esc_html__('Move this loop item to the trash? Any grid using it will show nothing.', 'king-addons'))); ?>);"> |
| 103 |
<span class="dashicons dashicons-trash"></span> |
| 104 |
<?php esc_html_e('Trash', 'king-addons'); ?> |
| 105 |
</a> |
| 106 |
</td> |
| 107 |
</tr> |
| 108 |
<?php endforeach; ?> |
| 109 |
</tbody> |
| 110 |
</table> |
| 111 |
<?php endif; ?> |
| 112 |
<?php ka_admin_card_close(); ?> |
| 113 |
|
| 114 |
<?php ka_admin_page_close(); ?> |
| 115 |
|