Ticket #12792: 12792.3.diff

File 12792.3.diff, 4.0 KB (added by scribu, 3 years ago)

Conditionally display "Insert into Post" button

Line 
1Index: wp-admin/includes/post.php
2===================================================================
3--- wp-admin/includes/post.php  (revision 14041)
4+++ wp-admin/includes/post.php  (working copy)
5@@ -1144,7 +1144,7 @@
6 function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
7        global $content_width, $_wp_additional_image_sizes;
8 
9-       $set_thumbnail_link = '<p class="hide-if-no-js"><a href="' . get_upload_iframe_src('image') . '" id="set-post-thumbnail" class="thickbox">%s</a></p>';
10+       $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' ) . '" href="' . get_upload_iframe_src('image') . '" id="set-post-thumbnail" class="thickbox">%s</a></p>';
11        $content = sprintf($set_thumbnail_link, esc_html__( 'Set featured image' ));
12 
13        if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
14Index: wp-admin/includes/media.php
15===================================================================
16--- wp-admin/includes/media.php (revision 14041)
17+++ wp-admin/includes/media.php (working copy)
18@@ -1160,7 +1160,7 @@
19        else
20                $thumb_url = false;
21 
22-       $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true );
23+       $default_args = array( 'errors' => null, 'send' => post_type_supports(get_post_type($_GET['post_id']), 'editor'), 'delete' => true, 'toggle' => true, 'show_title' => true );
24        $args = wp_parse_args( $args, $default_args );
25        extract( $args, EXTR_SKIP );
26 
27@@ -1991,7 +1991,6 @@
28  * @return unknown
29  */
30 function type_url_form_image() {
31-
32        if ( !apply_filters( 'disable_captions', '' ) ) {
33                $caption = '
34                <tr>
35@@ -2060,13 +2059,7 @@
36                        <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
37                        <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
38                </tr>
39-
40-               <tr>
41-                       <td></td>
42-                       <td>
43-                               <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
44-                       </td>
45-               </tr>
46+       ' . _insert_into_post_button('image') . '
47        </tbody></table>
48 ';
49 
50@@ -2097,12 +2090,7 @@
51                        <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
52                </tr>
53                <tr><td></td><td class="help">' . __('Link text, e.g. &#8220;Still Alive by Jonathan Coulton&#8221;') . '</td></tr>
54-               <tr>
55-                       <td></td>
56-                       <td>
57-                               <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
58-                       </td>
59-               </tr>
60+       ' . _insert_into_post_button('audio') . '
61        </tbody></table>
62 ';
63 }
64@@ -2132,12 +2120,7 @@
65                        <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
66                </tr>
67                <tr><td></td><td class="help">' . __('Link text, e.g. &#8220;Lucy on YouTube&#8220;') . '</td></tr>
68-               <tr>
69-                       <td></td>
70-                       <td>
71-                               <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
72-                       </td>
73-               </tr>
74+       ' . _insert_into_post_button('video') . '
75        </tbody></table>
76 ';
77 }
78@@ -2167,14 +2150,34 @@
79                        <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
80                </tr>
81                <tr><td></td><td class="help">' . __('Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;') . '</td></tr>
82+       ' . _insert_into_post_button('file') . '
83+       </tbody></table>
84+';
85+}
86+
87+
88+function _insert_into_post_button($type) {
89+       if ( !post_type_supports(get_post_type($_GET['post_id']), 'editor') )
90+               return '';
91+       
92+       if ( 'image' == $type )
93+       return '
94                <tr>
95                        <td></td>
96                        <td>
97+                               <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
98+                       </td>
99+               </tr>           
100+       ';
101+
102+       return '
103+               <tr>
104+                       <td></td>
105+                       <td>
106                                <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
107                        </td>
108                </tr>
109-       </tbody></table>
110-';
111+       ';
112 }
113 
114 /**