Skip to content

Commit 1fa245d

Browse files
committed
Bug fix: get_current_screen not working in AJAX mode
1 parent 54a29a4 commit 1fa245d

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

README.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ Donate link: http://1fix.io/
55
Tags: featured image, metabox
66
Requires at least: 3.5
77
Tested up to: 3.9.1
8-
Stable tag: 0.9.1
8+
Stable tag: 0.9.5
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1111

12-
Custom the title, content and link / button text in the Featured Image metabox.
12+
Custom the title, content and set / remove link text in the Featured Image metabox.
1313

1414
== Description ==
1515

16-
Custom the title, content and link / button text in the Featured Image metabox.
16+
With this plugin, you can custom the Featured Image metabox by:
17+
* Set the tilte text instead of the default "Featured Image".
18+
* Add instructions for the image, like the image dimenstions.
19+
* Set a custom set / remove link text, instead of the default "Set / Remove featured image".
20+
* Custom the metabox by post types. Each post type has its own custom settings.
1721

1822
== Installation ==
1923

@@ -46,5 +50,5 @@ Custom the title, content and link / button text in the Featured Image metabox.
4650

4751
== Changelog ==
4852

49-
= 0.9.1 =
53+
= 0.9.5 =
5054
* The first version

admin/class-custom-featured-image-metabox-admin.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,28 @@ public function add_action_links( $links ) {
149149

150150
}
151151

152+
/**
153+
* Get post type
154+
*
155+
* @return string Post type
156+
*
157+
* @since 0.9.5
158+
*/
159+
public function get_post_type() {
160+
161+
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
162+
if ( isset( $_REQUEST['post_id'] ) ) {
163+
$post = get_post( $_REQUEST['post_id'] );
164+
return $post->post_type;
165+
}
166+
}
167+
168+
$screen = get_current_screen();
169+
170+
return $screen->post_type;
171+
172+
} // end get_post_type
173+
152174
/**
153175
* Change the title of Featured Image Metabox
154176
*
@@ -158,8 +180,7 @@ public function add_action_links( $links ) {
158180
*/
159181
public function change_metabox_title() {
160182

161-
$screen = get_current_screen();
162-
$post_type = $screen->id;
183+
$post_type = $this->get_post_type();
163184
$options = get_option( $this->plugin_slug . '_' . $post_type );
164185

165186
if ( isset( $options['title'] ) && ! empty( $options['title'] ) ) {
@@ -182,8 +203,7 @@ public function change_metabox_title() {
182203
*/
183204
public function change_metabox_content( $content ) {
184205

185-
$screen = get_current_screen();
186-
$post_type = $screen->id;
206+
$post_type = $this->get_post_type();
187207
$options = get_option( $this->plugin_slug . '_' . $post_type );
188208

189209
if ( isset( $options['instruction'] ) && ! empty( $options['instruction'] ) ) {

admin/includes/settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function instruction_callback( $args ) {
151151
$value = isset( $args[1]['instruction'] ) ? $args[1]['instruction'] : '';
152152

153153
$html = '<input type"text" id="instruction" name="' . $args[0] . '[instruction]" value="' . $value . '" class="regular-text" />';
154-
$html .= '<p class="description">' . __( 'Enter the instruction for Featured Image, like image dimensions.', $this->plugin_slug ) . '</p>';
154+
$html .= '<p class="description">' . __( 'Enter the instructions for Featured Image, like image dimensions.', $this->plugin_slug ) . '</p>';
155155

156156
echo $html;
157157

custom-featured-image-metabox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Plugin Name: Custom Featured Image Metabox
1515
* Plugin URI: http://1fix.io
1616
* Description: Custom the title, content and link / button text in the Featured Image metabox.
17-
* Version: 0.9.1
17+
* Version: 0.9.5
1818
* Author: 1fixdotio
1919
* Author URI: http://1fix.io
2020
* Text Domain: cfim

public/class-custom-featured-image-metabox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Custom_Featured_Image_Metabox {
2828
*
2929
* @var string
3030
*/
31-
const VERSION = '0.9.1';
31+
const VERSION = '0.9.5';
3232

3333
/**
3434
* Unique identifier for your plugin.

0 commit comments

Comments
 (0)