Skip to content

Commit a07727e

Browse files
timiwahalahtiAntti Kuosmanen
authored andcommitted
Get rid of the public form pages for non-admin users while preserving preview
1 parent 99f80db commit a07727e

4 files changed

Lines changed: 192 additions & 83 deletions

File tree

classes/class-cpt-wplf-form.php

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ private function __construct() {
2323
add_action( 'init', array( $this, 'register_cpt' ) );
2424

2525
// post.php / post-new.php view
26+
add_filter( 'get_sample_permalink_html', array( $this, 'modify_permalink_html' ), 10, 2 );
2627
add_action( 'save_post', array( $this, 'save_cpt' ) );
2728
add_filter( 'content_save_pre' , array( $this, 'strip_form_tags' ), 10, 1 );
2829
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes_cpt' ) );
2930
add_action( 'admin_enqueue_scripts', array( $this, 'admin_post_scripts_cpt' ), 10, 1 );
3031

3132
// edit.php view
33+
add_filter( 'post_row_actions', array( $this, 'remove_row_actions' ), 10, 2 );
3234
add_filter( 'manage_edit-wplf-form_columns' , array( $this, 'custom_columns_cpt' ), 100, 1 );
3335
add_action( 'manage_posts_custom_column' , array( $this, 'custom_columns_display_cpt' ), 10, 2 );
3436

@@ -37,6 +39,7 @@ private function __construct() {
3739

3840
// front end
3941
add_shortcode( 'libre-form', array( $this, 'shortcode' ) );
42+
add_action( 'wp', array( $this, 'maybe_set_404_for_single_form' ) );
4043
add_filter( 'the_content', array( $this, 'use_shortcode_for_preview' ) );
4144
add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue_frontend_script' ) );
4245

@@ -92,6 +95,18 @@ public static function register_cpt() {
9295
register_post_type( 'wplf-form', $args );
9396
}
9497

98+
/**
99+
* Modify post.php permalink html to show notice if form isn't publicly visible.
100+
*/
101+
function modify_permalink_html( $html, $post_id ) {
102+
$publicly_visible = $this->get_publicly_visible_state( $post_id );
103+
104+
if( get_post_type( $post_id ) === 'wplf-form' && !$publicly_visible ) {
105+
$html .= '<span>'.__( 'Form is not publicly visible', 'wp-libre-form' ).__( ', permalink will not work for visitors.', 'wp-libre-form' ).'</span>';
106+
}
107+
108+
return $html;
109+
}
95110

96111
/**
97112
* Disable TinyMCE editor for forms, which are simple HTML things
@@ -164,6 +179,17 @@ function default_content_cpt( $content ) {
164179
return $content;
165180
}
166181

182+
/**
183+
* Remove view action in edit.php for forms
184+
*/
185+
function remove_row_actions( $actions, $post ) {
186+
$publicly_visible = $this->get_publicly_visible_state( $post->ID );
187+
188+
if( $post->post_type === 'wplf-form' && !$publicly_visible )
189+
unset( $actions['view'] );
190+
191+
return $actions;
192+
}
167193

168194
/**
169195
* Custom columns in edit.php for Forms
@@ -336,7 +362,6 @@ function meta_box_title_format( $post ) {
336362
<?php
337363
}
338364

339-
340365
/**
341366
* Handles saving our post meta
342367
*/
@@ -454,6 +479,17 @@ function wplf_form( $id , $content = '', $xclass = '' ) {
454479
ob_start();
455480
?>
456481
<form class="libre-form libre-form-<?php echo $id . ' ' . $xclass; ?>" <?php echo $multipart; ?>>
482+
<?php if( is_singular( 'wplf-form' ) && current_user_can( 'edit_post', $id ) ) {
483+
$publicly_visible = $this->get_publicly_visible_state( $id );
484+
if( !$publicly_visible ) {
485+
?>
486+
<p style="background:#f5f5f5;border-left:4px solid #dc3232;padding:6px 12px;">
487+
<b style="color:#dc3232;"><?php _e( 'Form is not publicly visible', 'wp-libre-form' ) ?>.</b><br />
488+
<?php _e( 'Subscriber or visitor will see a 404 error page instead of form.', 'wp-libre-form' ) ?>
489+
</p>
490+
<?php
491+
}
492+
} ?>
457493
<?php echo apply_filters( 'wplf_form', $content ); ?>
458494
<input type="hidden" name="referrer" value="<?php the_permalink(); ?>">
459495
<input type="hidden" name="_referrer_id" value="<?php esc_attr_e( get_the_id() ) ?>">
@@ -509,6 +545,33 @@ function use_shortcode_for_preview( $content ) {
509545
}
510546
return $content;
511547
}
548+
549+
/**
550+
* Set and show 404 page for visitors trying to see single form.
551+
* And yes, it is a global $post. That's right.
552+
*/
553+
function maybe_set_404_for_single_form() {
554+
global $post;
555+
556+
if( !is_singular( 'wplf-form' ) )
557+
return;
558+
559+
$publicly_visible = $this->get_publicly_visible_state( $post->ID );
560+
if( $publicly_visible )
561+
return;
562+
563+
if( !current_user_can( 'edit_post', $post->ID ) ) {
564+
global $wp_query;
565+
$wp_query->set_404();
566+
}
567+
}
568+
569+
/**
570+
* Wrapper function to check if form is publicly visible.
571+
*/
572+
function get_publicly_visible_state( $id ) {
573+
return apply_filters( 'wplf-form-publicly-visible', false, $id );
574+
}
512575
}
513576

514577
endif;

lang/wp-libre-form-fi.mo

547 Bytes
Binary file not shown.

lang/wp-libre-form-fi.po

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
msgid ""
22
msgstr ""
33
"Project-Id-Version: WP Libre Form\n"
4-
"POT-Creation-Date: 2016-02-21 23:16+0100\n"
5-
"PO-Revision-Date: 2016-02-21 23:16+0100\n"
6-
"Last-Translator: Antti Kuosmanen <antti@seravo.fi>\n"
4+
"POT-Creation-Date: 2016-10-26 01:25+0300\n"
5+
"PO-Revision-Date: 2016-10-26 01:28+0300\n"
6+
"Last-Translator: Timi Wahalahti <timi@dude.fi>\n"
77
"Language-Team: Antti Kuosmanen <antti@seravo.fi>\n"
88
"Language: fi\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
1212
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
13-
"X-Generator: Poedit 1.8.6\n"
13+
"X-Generator: Poedit 1.8.11\n"
1414
"X-Poedit-Basepath: ..\n"
1515
"X-Poedit-WPHeader: wp-libre-form.php\n"
1616
"X-Poedit-SourceCharset: UTF-8\n"
@@ -20,151 +20,171 @@ msgstr ""
2020
"X-Poedit-SearchPath-0: .\n"
2121
"X-Poedit-SearchPathExcluded-0: *.js\n"
2222

23-
#: classes/class-cpt-wplf-form.php:53
23+
#: classes/class-cpt-wplf-form.php:56
2424
msgctxt "post type general name"
2525
msgid "Forms"
2626
msgstr "Lomakkeet"
2727

28-
#: classes/class-cpt-wplf-form.php:54
28+
#: classes/class-cpt-wplf-form.php:57
2929
msgctxt "post type singular name"
3030
msgid "Form"
3131
msgstr "Lomake"
3232

33-
#: classes/class-cpt-wplf-form.php:55
33+
#: classes/class-cpt-wplf-form.php:58
3434
msgctxt "admin menu"
3535
msgid "Forms"
3636
msgstr "Lomakkeet"
3737

38-
#: classes/class-cpt-wplf-form.php:56
38+
#: classes/class-cpt-wplf-form.php:59
3939
msgctxt "add new on admin bar"
4040
msgid "Form"
4141
msgstr "Lomake"
4242

43-
#: classes/class-cpt-wplf-form.php:57
43+
#: classes/class-cpt-wplf-form.php:60
4444
msgctxt "form"
4545
msgid "New Form"
4646
msgstr "Uusi lomake"
4747

48-
#: classes/class-cpt-wplf-form.php:58
48+
#: classes/class-cpt-wplf-form.php:61
4949
msgid "Add New Form"
5050
msgstr "Luo uusi lomake"
5151

52-
#: classes/class-cpt-wplf-form.php:59
52+
#: classes/class-cpt-wplf-form.php:62
5353
msgid "New Form"
5454
msgstr "Uusi lomake"
5555

56-
#: classes/class-cpt-wplf-form.php:60
56+
#: classes/class-cpt-wplf-form.php:63
5757
msgid "Edit Form"
5858
msgstr "Muokkaa lomaketta"
5959

60-
#: classes/class-cpt-wplf-form.php:61
60+
#: classes/class-cpt-wplf-form.php:64
6161
msgid "View Form"
6262
msgstr "Näytä lomake"
6363

64-
#: classes/class-cpt-wplf-form.php:62 classes/class-cpt-wplf-submission.php:121
64+
#: classes/class-cpt-wplf-form.php:65 classes/class-cpt-wplf-submission.php:135
6565
msgid "All Forms"
6666
msgstr "Kaikki lomakkeet"
6767

68-
#: classes/class-cpt-wplf-form.php:63
68+
#: classes/class-cpt-wplf-form.php:66
6969
msgid "Search Forms"
7070
msgstr "Etsi lomakkeita"
7171

72-
#: classes/class-cpt-wplf-form.php:64
72+
#: classes/class-cpt-wplf-form.php:67
7373
msgid "No forms found."
7474
msgstr "Lomakkeita ei löytynt."
7575

76-
#: classes/class-cpt-wplf-form.php:65
76+
#: classes/class-cpt-wplf-form.php:68
7777
msgid "No forms found in Trash."
7878
msgstr "Roskakorissa ei ole lomakkeita."
7979

80-
#: classes/class-cpt-wplf-form.php:148
80+
#: classes/class-cpt-wplf-form.php:105 classes/class-cpt-wplf-form.php:518
81+
msgid "Form is not publicly visible"
82+
msgstr "Lomake ei näy julkisesti"
83+
84+
#: classes/class-cpt-wplf-form.php:105
85+
msgid ", permalink will not work for visitors."
86+
msgstr ", eikä kestolinkki toimi käyttäjillä."
87+
88+
#: classes/class-cpt-wplf-form.php:163
8189
msgid "Please enter your name"
8290
msgstr "Kirjoita nimesi"
8391

84-
#: classes/class-cpt-wplf-form.php:149
92+
#: classes/class-cpt-wplf-form.php:164
8593
msgctxt "Default placeholder name"
8694
msgid "John Doe"
8795
msgstr "Matti Meikäläinen"
8896

89-
#: classes/class-cpt-wplf-form.php:151
97+
#: classes/class-cpt-wplf-form.php:166
9098
msgid "Please enter your email address"
9199
msgstr "Kirjoita sähköpostiosoitteesi"
92100

93-
#: classes/class-cpt-wplf-form.php:151 classes/class-cpt-wplf-form.php:154
101+
#: classes/class-cpt-wplf-form.php:166 classes/class-cpt-wplf-form.php:169
94102
msgid "(required)"
95103
msgstr "(pakollinen)"
96104

97-
#: classes/class-cpt-wplf-form.php:152
105+
#: classes/class-cpt-wplf-form.php:167
98106
msgctxt "Default placeholder email"
99107
msgid "example@email.com"
100108
msgstr "esimerkki@esimerkki.fi"
101109

102-
#: classes/class-cpt-wplf-form.php:154
110+
#: classes/class-cpt-wplf-form.php:169
103111
msgid "Write your message below"
104112
msgstr "Kirjoita viestisi alle"
105113

106-
#: classes/class-cpt-wplf-form.php:155
114+
#: classes/class-cpt-wplf-form.php:170
107115
msgctxt "Default placeholder message"
108116
msgid "I wanted to ask about..."
109117
msgstr "Halusin kysyä..."
110118

111-
#: classes/class-cpt-wplf-form.php:157
119+
#: classes/class-cpt-wplf-form.php:172
112120
msgid "Submit"
113121
msgstr "Lähetä"
114122

115-
#: classes/class-cpt-wplf-form.php:159
123+
#: classes/class-cpt-wplf-form.php:174
116124
msgctxt "The HTML comment at the end of the example form"
117125
msgid "Any valid HTML form can be used here!"
118126
msgstr "Tässä toimii mikä tahansa HTML-lomake!"
119127

120-
#: classes/class-cpt-wplf-form.php:175 classes/class-cpt-wplf-form.php:212
128+
#: classes/class-cpt-wplf-form.php:201 classes/class-cpt-wplf-form.php:240
121129
msgid "Shortcode"
122130
msgstr "Lyhytkoodi"
123131

124-
#: classes/class-cpt-wplf-form.php:176 classes/class-cpt-wplf-submission.php:46
132+
#: classes/class-cpt-wplf-form.php:202 classes/class-cpt-wplf-submission.php:46
125133
msgid "Submissions"
126134
msgstr "Vastaukset"
127135

128-
#: classes/class-cpt-wplf-form.php:222
136+
#: classes/class-cpt-wplf-form.php:250
129137
msgid "Success Message"
130138
msgstr "Onnistumisviesti"
131139

132-
#: classes/class-cpt-wplf-form.php:232
140+
#: classes/class-cpt-wplf-form.php:260
133141
msgid "Form Fields Detected"
134142
msgstr "Lomakekentät"
135143

136-
#: classes/class-cpt-wplf-form.php:241
144+
#: classes/class-cpt-wplf-form.php:269
137145
msgid "Emails"
138146
msgstr "Sähköpostit"
139147

140-
#: classes/class-cpt-wplf-form.php:250
148+
#: classes/class-cpt-wplf-form.php:278
141149
msgid "Submission Title Format"
142150
msgstr "Nimi lähetetylle lomakkeelle"
143151

144-
#: classes/class-cpt-wplf-form.php:273
152+
#: classes/class-cpt-wplf-form.php:287
153+
msgid "Visibility"
154+
msgstr "Näkyvyys"
155+
156+
#: classes/class-cpt-wplf-form.php:310
145157
msgctxt "Default success message"
146158
msgid "Thank you! :)"
147159
msgstr "Kiitos! :)"
148160

149-
#: classes/class-cpt-wplf-form.php:294
161+
#: classes/class-cpt-wplf-form.php:331
150162
msgid "Fields marked with * are required"
151163
msgstr "Tähdelliset * kentät on pakollisia"
152164

153-
#: classes/class-cpt-wplf-form.php:315
165+
#: classes/class-cpt-wplf-form.php:352
154166
msgid "Send an email copy when a form is submitted?"
155167
msgstr "Lähetä kopio sähköpostiin kun lomake lähetetään?"
156168

157-
#: classes/class-cpt-wplf-form.php:331
169+
#: classes/class-cpt-wplf-form.php:368
158170
msgid "Submissions from this form will use this formatting in their title."
159171
msgstr ""
160172
"Tähän lomakkeeseen lähetetyt vastaukset nimetään allaolevan kaavan "
161173
"mukaisesti."
162174

163-
#: classes/class-cpt-wplf-form.php:332
175+
#: classes/class-cpt-wplf-form.php:369
164176
msgid "You may use any field values enclosed in \"%\" markers."
165177
msgstr ""
166178
"Voit käyttää otsikossa mitä tahansa kenttiä arvoja \"%\"-merkkien sisällä."
167179

180+
#: classes/class-cpt-wplf-form.php:385
181+
msgid "Make this form publicly visible with permalink?"
182+
msgstr "Näytä lomake julkisesti kestolinkillä?"
183+
184+
#: classes/class-cpt-wplf-form.php:519
185+
msgid "Subscriber or visitor will see a 404 error page instead of form."
186+
msgstr "Tilaaja tai käyttäjä näkee lomakkeen sijaan 404-virhesivun."
187+
168188
#: classes/class-cpt-wplf-submission.php:37
169189
msgctxt "post type general name"
170190
msgid "Submissions"
@@ -226,15 +246,15 @@ msgstr "Lähde"
226246
msgid "Form"
227247
msgstr "Lomake"
228248

229-
#: classes/class-cpt-wplf-submission.php:158
249+
#: classes/class-cpt-wplf-submission.php:172
230250
msgid "Submission"
231251
msgstr "Vastaus"
232252

233-
#: classes/class-cpt-wplf-submission.php:178
253+
#: classes/class-cpt-wplf-submission.php:193
234254
msgid "Field"
235255
msgstr "Kenttä"
236256

237-
#: classes/class-cpt-wplf-submission.php:179
257+
#: classes/class-cpt-wplf-submission.php:194
238258
msgid "Value"
239259
msgstr "Arvo"
240260

@@ -266,8 +286,8 @@ msgid "https://github.com/anttiviljami/wp-libre-form"
266286
msgstr "https://github.com/anttiviljami/wp-libre-form"
267287

268288
#. Description of the plugin/theme
269-
msgid "HTML form builder for WordPress"
270-
msgstr "HTML form builder for WordPress"
289+
msgid "A minimal HTML form builder for WordPress; made for developers"
290+
msgstr "Minimalistinen HTML lomakerakentaja WordPressille; tehty kehittäjille."
271291

272292
#. Author of the plugin/theme
273293
msgid "@anttiviljami"
@@ -277,6 +297,12 @@ msgstr "@anttiviljami"
277297
msgid "https://github.com/anttiviljami/"
278298
msgstr "https://github.com/anttiviljami/"
279299

300+
#~ msgid "Make this form publicly visible with direct link?"
301+
#~ msgstr "Näytä lomake julkisesti suoralla linkillä?"
302+
303+
#~ msgid "HTML form builder for WordPress"
304+
#~ msgstr "HTML form builder for WordPress"
305+
280306
#~ msgid "referrer"
281307
#~ msgstr "lähde"
282308

0 commit comments

Comments
 (0)