PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.0.1
JetFormBuilder — Dynamic Blocks Form Builder v2.0.1
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / admin / single-pages / base-single-page.php
jetformbuilder / includes / admin / single-pages Last commit date
actions 4 years ago meta-boxes 4 years ago meta-containers 4 years ago base-single-page.php 4 years ago
base-single-page.php
120 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Admin\Single_Pages;
5
6 use Jet_Form_Builder\Admin\Admin_Page_Interface;
7 use Jet_Form_Builder\Admin\Admin_Page_Trait;
8 use Jet_Form_Builder\Admin\Exceptions\Not_Found_Page_Exception;
9 use Jet_Form_Builder\Admin\Pages\Base_Page;
10 use Jet_Form_Builder\Admin\Pages\Pages_Manager;
11 use Jet_Form_Builder\Admin\Single_Pages\Meta_Containers\Base_Meta_Container;
12 use Jet_Form_Builder\Classes\Repository\Repository_Item_Instance_Trait;
13 use Jet_Form_Builder\Classes\Theme\With_Theme_Info;
14
15 abstract class Base_Single_Page implements Admin_Page_Interface, Repository_Item_Instance_Trait {
16
17 use Admin_Page_Trait;
18 use With_Theme_Info;
19
20 protected $id;
21
22 abstract public function parent_slug(): string;
23
24 public function rep_item_id() {
25 return $this->parent_slug();
26 }
27
28 /**
29 * @return Base_Single_Page
30 * @throws Not_Found_Page_Exception
31 */
32 public function make(): Base_Single_Page {
33 $id = $this->query_id();
34
35 $this->set_id( $id )->query_config();
36
37 return $this;
38 }
39
40 public function query_id(): int {
41 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
42 return absint( $_GET['item_id'] ?? 0 );
43 }
44
45
46 /**
47 * @param int $id
48 *
49 * @return Base_Single_Page
50 * @throws Not_Found_Page_Exception
51 */
52 public function set_id( int $id ): Base_Single_Page {
53 if ( ! $id ) {
54 throw new Not_Found_Page_Exception( 'Item id is empty: ' . $id . ' in ' . static::class );
55 }
56 $this->id = $id;
57
58 return $this;
59 }
60
61 /**
62 * @return Base_Meta_Container[]
63 */
64 public function meta_containers(): array {
65 return array();
66 }
67
68 /**
69 * @return array
70 */
71 public function page_config(): array {
72 return array(
73 'containers' => $this->get_prepared_containers(),
74 'title' => $this->title(),
75 );
76 }
77
78 final public function get_prepared_containers(): array {
79 $prepared = array();
80
81 /** @var Base_Meta_Container[] $containers */
82 $containers = apply_filters( "jet-form-builder/page-containers/{$this->slug()}", $this->meta_containers() );
83
84 foreach ( $containers as $index => $container ) {
85 $prepared[] = $container->set_index( $index )->to_array();
86 }
87
88 return $prepared;
89 }
90
91 public function slug(): string {
92 return $this->parent_slug() . '-single';
93 }
94
95 /**
96 * Returns current page url
97 *
98 * @param array $query_args
99 *
100 * @return string
101 */
102 public function get_url( $query_args = array() ): string {
103 return $this->get_parent()->get_url(
104 array_merge(
105 array( 'item_id' => $this->id ),
106 $query_args
107 )
108 );
109 }
110
111 public function get_parent(): Base_Page {
112 return Pages_Manager::instance()->stable()->rep_get_item_or_die( $this->parent_slug() );
113 }
114
115 public function get_id(): int {
116 return $this->id;
117 }
118
119 }
120