5 if ( ! defined(
'GRAVITYVIEW_DIR' ) ) {
19 if ( ! has_action(
'gravityview/template/before', array( __CLASS__,
'maybe_print_notices' ) ) ) {
20 add_action(
'gravityview/template/before', array( __CLASS__,
'maybe_print_notices' ) );
40 self::disable_show_only_approved_entries( $gravityview );
42 self::maybe_print_reserved_slugs_notice( $gravityview );
44 self::maybe_print_configuration_notice( $gravityview );
46 self::maybe_print_entry_approval_notice( $gravityview );
61 if ( ! isset( $_GET[
'disable_setting'] ) || ! wp_verify_nonce( $_GET[
'gv-setting'],
'setting' ) ) {
65 $settings = $gravityview->view->settings->all();
69 $updated = update_post_meta( $gravityview->view->ID,
'_gravityview_template_settings',
$settings );
72 gravityview()->log->error(
'Could not update View settings => Show only approved' );
76 $redirect_url = home_url( remove_query_arg( array(
'disable_setting',
'gv-setting' ) ) );
78 if ( wp_safe_redirect( $redirect_url ) ) {
94 if ( $gravityview->entries && $gravityview->entries->count() ) {
98 if ( $gravityview->request->is_search() ) {
103 if ( ! $gravityview->view->settings->get(
'show_only_approved', 0 ) ) {
108 if ( $gravityview->view->settings->get(
'admin_show_all_statuses', 0 ) ) {
113 if ( $gravityview->view->settings->get(
'hide_until_searched', 0 ) ) {
117 $current_user = wp_get_current_user();
119 $user_meta_key =
'_gv_dismissed_entry_approval_notice_' . $gravityview->view->ID;
121 $dismiss_nonce_name =
'gv-dismiss';
122 $dismiss_nonce_action =
'gv-dismiss-no-entries-' . $gravityview->view->ID;
124 if ( isset( $_GET[ $dismiss_nonce_name ] ) && wp_verify_nonce( $_GET[ $dismiss_nonce_name ], $dismiss_nonce_action ) ) {
125 add_user_meta( $current_user->ID, $user_meta_key, 1 );
130 if ( get_user_meta( $current_user->ID, $user_meta_key,
true ) ) {
135 if ( empty( $gravityview->view->form ) ) {
139 $count = \GFAPI::count_entries( $gravityview->view->form->ID, array(
140 'status' =>
'active',
141 'field_filters' => array(
143 'key' =>
'is_approved',
144 'operator' =>
'isnot',
151 if ( empty( $count ) ) {
155 $message_template = <<<EOD
157 #{dom_id}-hide-notice { 167 border-
bottom: 1px solid #ddd;
170 #{dom_id} .gv-notice-message { 176 #{dom_id} span.gv-notice-description { 181 #{dom_id} .gv-notice-admin-message { 192 #{dom_id} .dashicons-no-alt { 197 #{dom_id} .dashicons-external { 205 <h3>{notice_title}<span
id=
"{dom_id}-hide-notice"><a href=
"{hide_notice_link}" role=
"button">{hide_notice} <span
class=
"dashicons dashicons-no-alt"></span></span></a></h3>
207 <p
class=
"gv-notice-message">{screenshot} {message} <a href=
"{learn_more_link}" rel=
"external" target=
"_blank">{learn_more} <span
class=
"dashicons dashicons-external" title=
"{title_new_window}"></span></a></p>
211 <div><a href=
"{disable_setting_link}">{disable_setting}</a> <span
class=
"gv-notice-description">{disable_setting_description}</span></div>
212 <div><a href=
"{approve_entries_link}">{approve_entries}</a> <span
class=
"gv-notice-description">{approve_entries_description}</span></div>
214 <p
class=
"gv-notice-admin-message"><em>{admin_message}</em></p>
219 esc_html__(
'There is an unapproved entry that is not being shown.',
'gk-gravityview' ),
220 sprintf( esc_html__(
'There are %s unapproved entries that are not being shown.',
'gk-gravityview' ), number_format_i18n( $count ) ),
224 $float_dir = is_rtl() ?
'left' :
'right';
226 $dismiss_notice_link = wp_nonce_url( add_query_arg( array() ), $dismiss_nonce_action, $dismiss_nonce_name );
228 $disable_setting_link = wp_nonce_url( add_query_arg( array(
229 'disable_setting' =>
'show_only_approved_' . $gravityview->view->ID
230 ) ),
'setting',
'gv-setting' );
232 $placeholders = array(
233 '{dom_id}' => sprintf(
'gv-notice-approve-entries-%d', $gravityview->view->ID ),
234 '{float_dir}' => $float_dir,
235 '{notice_title}' => esc_html( $notice_title ),
236 '{title_new_window}' => esc_attr__(
'This link opens in a new window.',
'gk-gravityview' ),
237 '{hide_notice}' => esc_html__(
'Hide this notice',
'gk-gravityview' ),
238 '{hide_notice_link}' => esc_url( $dismiss_notice_link ),
239 '{message}' => esc_html( wptexturize( __(
'The "Show only approved entries" setting is enabled, so only entries that have been approved are displayed.',
'gk-gravityview' ) ) ),
240 '{learn_more}' => esc_html__(
'Learn about entry approval.',
'gk-gravityview' ),
241 '{learn_more_link}' =>
'https://docs.gravityview.co/article/490-entry-approval-gravity-forms',
242 '{disable_setting}' => esc_html( wptexturize( __(
'Disable the "Show only approved entries" setting for this View',
'gk-gravityview' ) ) ),
243 '{disable_setting_description}' => esc_html( wptexturize( __(
'Click to immediately disable the "Show only approved entries" setting. All entry statuses will be shown.',
'gk-gravityview' ) ) ),
244 '{disable_setting_link}' => esc_url( $disable_setting_link ),
245 '{approve_entries}' => esc_html__(
'Manage entry approval',
'gk-gravityview' ),
246 '{approve_entries_description}' => esc_html__(
'Go to the Gravity Forms entries screen to moderate entry approval.',
'gk-gravityview' ),
247 '{approve_entries_link}' => esc_url( admin_url(
'admin.php?page=gf_entries&id=' . $gravityview->view->form->ID ) ),
248 '{screenshot}' => sprintf(
'<img alt="%s" src="%s" />', esc_attr__(
'Show only approved entries',
'gk-gravityview' ), esc_url( plugins_url(
'assets/images/screenshots/entry-approval.png',
GRAVITYVIEW_FILE ) ) ),
249 '{admin_message}' => sprintf( esc_html__(
'Note: %s',
'gk-gravityview' ), esc_html__(
'You can only see this message because you are able to edit this View.',
'gk-gravityview' ) ),
252 $notice = strtr( $message_template, $placeholders );
255 wp_print_styles(
'dashicons' );
257 echo \GVCommon::generate_notice( $notice,
'warning',
'edit_gravityview', $gravityview->view->ID );
272 case ( $gravityview->request->is_edit_entry() ):
273 $tab = esc_html__(
'Edit Entry',
'gk-gravityview' );
276 case ( $gravityview->request->is_entry( $gravityview->view->form ? $gravityview->view->form->ID : 0 ) ):
277 $tab = esc_html__(
'Single Entry',
'gk-gravityview' );
281 $tab = esc_html__(
'Multiple Entries',
'gk-gravityview' );
282 $context =
'directory';
286 $cls = $gravityview->template;
287 $slug = property_exists( $cls,
'_configuration_slug' ) ? $cls::$_configuration_slug : $cls::$slug;
290 if ( $gravityview->fields->by_position( sprintf(
'%s_%s-*', $context, $slug ) )->by_visible( $gravityview->view )->count() ) {
294 $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',
'gk-gravityview' ), $tab );
295 $edit_link = admin_url( sprintf(
'post.php?post=%d&action=edit#%s-view', $gravityview->view->ID, $context ) );
296 $action_text = sprintf( esc_html__(
'Add fields to %s',
'gk-gravityview' ), $tab );
297 $message = esc_html__(
'You can only see this message because you are able to edit this View.',
'gk-gravityview' );
299 $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 ) ) );
300 $output = sprintf(
'<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>',
$title, esc_url( $edit_link ), $action_text, $message );
302 echo \GVCommon::generate_notice(
$output .
$image,
'gv-warning warning',
'edit_gravityview', $gravityview->view->ID );
318 $reserved_slugs = array(
319 $wp_rewrite->search_base,
320 apply_filters(
'gravityview_directory_endpoint',
'entry' ),
323 $post_types = get_post_types();
325 foreach( $post_types as $post_type ) {
326 $post_type_rewrite = get_post_type_object( $post_type )->rewrite;
328 if ( $slug = \
GV\Utils::get( $post_type_rewrite,
'slug' ) ) {
329 $reserved_slugs[] = $slug;
333 unset( $post_types, $post_type_rewrite );
341 $reserved_slugs = apply_filters(
'gravityview/rewrite/reserved_slugs', $reserved_slugs, $gravityview );
343 $reserved_slugs = array_map(
'strtolower', $reserved_slugs );
345 if ( ! in_array( strtolower( $wp->request ), $reserved_slugs,
true ) ) {
349 gravityview()->log->error(
'{slug} page URL is reserved.', array(
'slug' => $wp->request ) );
351 $title = esc_html__(
'GravityView will not work correctly on this page because of the URL Slug.',
'gk-gravityview' );
352 $message = __(
'Please <a href="%s">read this article</a> for more information.',
'gk-gravityview' );
353 $message .=
' ' . esc_html__(
'You can only see this message because you are able to edit this View.',
'gk-gravityview' );
355 $output = sprintf(
'<h3>%s</h3><p>%s</p>',
$title, sprintf( $message,
'https://docs.gravityview.co/article/659-reserved-urls' ) );
357 echo \GVCommon::generate_notice(
$output,
'gv-error error',
'edit_gravityview', $gravityview->view->ID );
372 return function() use ( $view, $path ) {
gravityview_get_view_id()
Get the current View ID being rendered.
static maybe_print_reserved_slugs_notice( $gravityview)
Print reserved slug warnings, if they exist.
static disable_show_only_approved_entries( $gravityview)
Disable the "Show only approved entries" setting, hence displaying all entries on the View...
legacy_template_warning( $view, $path)
Warn about legacy template being used.
If this file is called directly, abort.
If this file is called directly, abort.
static maybe_print_notices( $gravityview=null)
Print unconfigured notices to admins.
static maybe_print_entry_approval_notice( $gravityview)
Print notice warning admins that "Show only approved" is enabled.
__construct()
Initialization.
const GRAVITYVIEW_FILE
Full path to the GravityView file "GRAVITYVIEW_FILE" "./gravityview.php".
static maybe_print_configuration_notice( $gravityview)
Check empty configuration.
gravityview()
The main GravityView wrapper function.
static getInstance()
Get the one true instantiated self.