1
|
|
|
<?php |
2
|
|
|
namespace GV; |
3
|
|
|
|
4
|
|
|
/** If this file is called directly, abort. */ |
5
|
|
|
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
6
|
|
|
die(); |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* The \GV\Renderer class. |
11
|
|
|
* |
12
|
|
|
* The base for all renderers. |
13
|
|
|
*/ |
14
|
|
|
class Renderer { |
15
|
|
|
/** |
16
|
|
|
* Initialization. |
17
|
|
|
*/ |
18
|
102 |
|
public function __construct() { |
19
|
102 |
|
if ( ! has_action( 'gravityview/template/before', array( __CLASS__, 'maybe_print_notices' ) ) ) { |
20
|
31 |
|
add_action( 'gravityview/template/before', array( __CLASS__, 'maybe_print_notices' ) ); |
21
|
|
|
} |
22
|
102 |
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Print unconfigured notices to admins. |
26
|
|
|
* Print reserved slug warnings. |
27
|
|
|
* |
28
|
|
|
* @param \GV\Template_Context $gravityview The $gravityview template object. |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
35 |
|
public static function maybe_print_notices( $gravityview = null ) { |
33
|
35 |
|
if ( ! $gravityview instanceof \GV\Template_Context ) { |
34
|
|
|
/** Call the legacy code. */ |
35
|
|
|
\GravityView_frontend::getInstance()->context_not_configured_warning( gravityview_get_view_id() ); |
36
|
|
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Check reserved slugs. |
41
|
|
|
*/ |
42
|
35 |
|
global $wp; |
43
|
35 |
|
global $wp_rewrite; |
44
|
|
|
|
45
|
|
|
$reserved_slugs = array( |
46
|
35 |
|
$wp_rewrite->search_base, |
47
|
35 |
|
apply_filters( 'gravityview_directory_endpoint', 'entry' ), |
48
|
|
|
); |
49
|
|
|
|
50
|
35 |
|
$post_types = get_post_types(); |
51
|
|
|
|
52
|
35 |
|
foreach( $post_types as $post_type ) { |
53
|
35 |
|
$post_type_rewrite = get_post_type_object( $post_type )->rewrite; |
54
|
|
|
|
55
|
35 |
|
if ( $slug = \GV\Utils::get( $post_type_rewrite, 'slug' ) ) { |
56
|
35 |
|
$reserved_slugs[] = $slug; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
35 |
|
unset( $post_types, $post_type_rewrite ); |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @filter `gravityview/rewrite/reserved_slugs` Modify the reserved embed slugs that trigger a warning. |
64
|
|
|
* @since 2.5 |
65
|
|
|
* @param[in,out] array $reserved_slugs An array of strings, reserved slugs. |
66
|
|
|
* @param \GV\Template_Context $gravityview The context. |
67
|
|
|
*/ |
68
|
35 |
|
$reserved_slugs = apply_filters( 'gravityview/rewrite/reserved_slugs', $reserved_slugs, $gravityview ); |
69
|
|
|
|
70
|
35 |
|
$reserved_slugs = array_map( 'strtolower', $reserved_slugs ); |
71
|
|
|
|
72
|
35 |
|
if ( in_array( strtolower( $wp->request ), $reserved_slugs, true ) ) { |
73
|
1 |
|
gravityview()->log->error( '{slug} page URL is reserved.', array( 'slug' => $wp->request ) ); |
74
|
|
|
|
75
|
1 |
|
$title = esc_html__( 'GravityView will not work correctly on this page because of the URL Slug.', 'gravityview' ); |
76
|
1 |
|
$message = __( 'Please <a href="%s">read this article</a> for more information.', 'gravityview' ); |
77
|
1 |
|
$message .= ' ' . esc_html__( 'You can only see this message because you are able to edit this View.', 'gravityview' ); |
78
|
|
|
|
79
|
1 |
|
$output = sprintf( '<h3>%s</h3><p>%s</p>', $title, sprintf( $message, 'https://docs.gravityview.co/article/659-reserved-urls' ) ); |
80
|
|
|
|
81
|
1 |
|
echo \GVCommon::generate_notice( $output, 'gv-error error', 'edit_gravityview', $gravityview->view->ID ); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Check empty configuration. |
86
|
|
|
*/ |
87
|
|
|
switch ( true ) { |
88
|
35 |
|
case ( $gravityview->request->is_edit_entry() ): |
89
|
|
|
$tab = __( 'Edit Entry', 'gravityview' ); |
90
|
|
|
$context = 'edit'; |
91
|
|
|
break; |
92
|
35 |
|
case ( $gravityview->request->is_entry( $gravityview->view->form ? $gravityview->view->form->ID : 0 ) ): |
93
|
10 |
|
$tab = __( 'Single Entry', 'gravityview' ); |
94
|
10 |
|
$context = 'single'; |
95
|
10 |
|
break; |
96
|
|
|
default: |
97
|
27 |
|
$tab = __( 'Multiple Entries', 'gravityview' ); |
98
|
27 |
|
$context = 'directory'; |
99
|
27 |
|
break; |
100
|
|
|
} |
101
|
|
|
|
102
|
35 |
|
$cls = $gravityview->template; |
103
|
35 |
|
$slug = property_exists( $cls, '_configuration_slug' ) ? $cls::$_configuration_slug : $cls::$slug; |
104
|
35 |
|
if ( $gravityview->fields->by_position( sprintf( '%s_%s-*', $context, $slug ) )->by_visible( $gravityview->view )->count() ) { |
105
|
28 |
|
return; |
106
|
|
|
} |
107
|
|
|
|
108
|
7 |
|
$title = sprintf( esc_html_x( 'The %s layout has not been configured.', 'Displayed when a View is not configured. %s is replaced by the tab label', 'gravityview' ), $tab ); |
109
|
7 |
|
$edit_link = admin_url( sprintf( 'post.php?post=%d&action=edit#%s-view', $gravityview->view->ID, $context ) ); |
|
|
|
|
110
|
7 |
|
$action_text = sprintf( esc_html__( 'Add fields to %s', 'gravityview' ), $tab ); |
111
|
7 |
|
$message = esc_html__( 'You can only see this message because you are able to edit this View.', 'gravityview' ); |
112
|
|
|
|
113
|
7 |
|
$image = sprintf( '<img alt="%s" src="%s" style="margin-top: 10px;" />', $tab, esc_url( plugins_url( sprintf( 'assets/images/tab-%s.png', $context ), GRAVITYVIEW_FILE ) ) ); |
114
|
7 |
|
$output = sprintf( '<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url( $edit_link ), $action_text, $message ); |
115
|
|
|
|
116
|
7 |
|
echo \GVCommon::generate_notice( $output . $image, 'gv-error error', 'edit_gravityview', $gravityview->view->ID ); |
|
|
|
|
117
|
7 |
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Warn about legacy template being used. |
121
|
|
|
* |
122
|
|
|
* Generate a callback that shows which legacy template was at fault. |
123
|
|
|
* Used in gravityview_before. |
124
|
|
|
* |
125
|
|
|
* @param \GV\View $view The view we're looking at. |
126
|
|
|
* @param string $path The path of the offending template. |
127
|
|
|
* |
128
|
|
|
* @return \Callable A closure used in the filter. |
129
|
|
|
*/ |
130
|
|
|
public function legacy_template_warning( $view, $path ) { |
131
|
|
|
return function() use ( $view, $path ) { |
132
|
|
|
// Do not panic for now... |
133
|
|
|
}; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.