Skip to content

Commit 7b8f054

Browse files
committed
Add post type supports
1 parent 312c2a0 commit 7b8f054

File tree

5 files changed

+97
-59
lines changed

5 files changed

+97
-59
lines changed

README.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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.5.0
8+
Stable tag: 0.6.0
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1111

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

4747
== Changelog ==
4848

49-
= 0.5.0 =
49+
= 0.6.0 =
5050
* The first version

admin/includes/settings.php

Lines changed: 92 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,54 @@ public function admin_init() {
6666
add_option( $this->plugin_slug, $this->default_settings() );
6767
} // end if
6868

69-
add_settings_section(
70-
'general',
71-
__( 'General', $this->plugin_slug ),
72-
'',
73-
$this->plugin_slug
74-
);
75-
76-
add_settings_field(
77-
'title',
78-
__( 'Title Text', $this->plugin_slug ),
79-
array( $this, 'title_callback' ),
80-
$this->plugin_slug,
81-
'general'
82-
);
83-
84-
add_settings_field(
85-
'instruction',
86-
__( 'Instruction', $this->plugin_slug ),
87-
array( $this, 'instruction_callback' ),
88-
$this->plugin_slug,
89-
'general'
90-
);
91-
92-
add_settings_field(
93-
'link_text',
94-
__( 'Link Text', $this->plugin_slug ),
95-
array( $this, 'link_text_callback' ),
96-
$this->plugin_slug,
97-
'general'
98-
);
99-
100-
add_settings_field(
101-
'button_text',
102-
__( 'Button Text', $this->plugin_slug ),
103-
array( $this, 'button_text_callback' ),
104-
$this->plugin_slug,
105-
'general'
106-
);
69+
$post_types = $this->supported_post_types();
70+
71+
foreach ( $post_types as $pt ) {
72+
$post_object = get_post_type_object( $pt );
73+
74+
add_settings_section(
75+
$pt,
76+
sprintf( __( 'Featured Image Metabox in %s', $this->plugin_slug ), $post_object->labels->name ),
77+
'',
78+
$this->plugin_slug
79+
);
80+
81+
add_settings_field(
82+
'title',
83+
__( 'Title Text', $this->plugin_slug ),
84+
array( $this, 'title_callback' ),
85+
$this->plugin_slug,
86+
$pt,
87+
array( $pt )
88+
);
89+
90+
add_settings_field(
91+
'instruction',
92+
__( 'Instruction', $this->plugin_slug ),
93+
array( $this, 'instruction_callback' ),
94+
$this->plugin_slug,
95+
$pt,
96+
array( $pt )
97+
);
98+
99+
add_settings_field(
100+
'link_text',
101+
__( 'Link Text', $this->plugin_slug ),
102+
array( $this, 'link_text_callback' ),
103+
$this->plugin_slug,
104+
$pt,
105+
array( $pt )
106+
);
107+
108+
add_settings_field(
109+
'button_text',
110+
__( 'Button Text', $this->plugin_slug ),
111+
array( $this, 'button_text_callback' ),
112+
$this->plugin_slug,
113+
$pt,
114+
array( $pt )
115+
);
116+
}
107117

108118
register_setting(
109119
$this->plugin_slug,
@@ -119,59 +129,87 @@ public function admin_init() {
119129
*/
120130
public function default_settings() {
121131

122-
$defaults = array(
123-
'title' => 'Post Featured Image',
124-
'instruction' => '',
125-
'link_text' => '',
126-
'button_text' => '',
127-
);
132+
$post_types = $this->supported_post_types();
133+
$keys = array(
134+
'title' => '',
135+
'instruction' => '',
136+
'link_text' => '',
137+
'button_text' => '',
138+
);
139+
$defaults = array();
140+
141+
foreach ( $post_types as $pt ) {
142+
$defaults[$pt] = $keys;
143+
}
128144

129-
return apply_filters( 'default_settings', $defaults );
145+
return apply_filters( 'cfim_default_settings', $defaults );
130146

131147
} // end default_settings
132148

133-
public function title_callback() {
149+
/**
150+
* Get post types with thumbnail support
151+
*
152+
* @return array supported post types
153+
*
154+
* @since 0.6.0
155+
*/
156+
public function supported_post_types() {
157+
158+
$post_types = get_post_types();
159+
$results = array();
160+
161+
foreach ( $post_types as $pt ) {
162+
if ( post_type_supports( $pt, 'thumbnail' ) ) {
163+
$results[] = $pt;
164+
}
165+
}
166+
167+
return $results;
168+
169+
} // end supported_post_types
170+
171+
public function title_callback( $args ) {
134172

135173
$options = get_option( $this->plugin_slug );
136174
$value = isset( $options['title'] ) ? $options['title'] : '';
137175

138-
$html = '<input type"text" id="title" name="' . $this->plugin_slug . '[title]" value="' . $value . '" class="regular-text" />';
176+
$html = '<input type"text" id="title" name="' . $this->plugin_slug . '[' . $args[0] . '][title]" value="' . $value . '" class="regular-text" />';
139177
$html .= '<p class="description">' . __( 'Enter your custom title for Featured Image Metabox.', $this->plugin_slug ) . '</p>';
140178

141179
echo $html;
142180

143181
} // end title_callback
144182

145-
public function instruction_callback() {
183+
public function instruction_callback( $args ) {
146184

147185
$options = get_option( $this->plugin_slug );
148186
$value = isset( $options['instruction'] ) ? $options['instruction'] : '';
149187

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

153191
echo $html;
154192

155193
} // end instruction_callback
156194

157-
public function link_text_callback() {
195+
public function link_text_callback( $args ) {
158196

159197
$options = get_option( $this->plugin_slug );
160198
$value = isset( $options['link_text'] ) ? $options['link_text'] : '';
161199

162-
$html = '<input type"text" id="link_text" name="' . $this->plugin_slug . '[link_text]" value="' . $value . '" class="regular-text" />';
200+
$html = '<input type"text" id="link_text" name="' . $this->plugin_slug . '[' . $args[0] . '][link_text]" value="' . $value . '" class="regular-text" />';
163201
$html .= '<p class="description">' . sprintf( __( 'Enter the custom link text to replace the "%s".', $this->plugin_slug ), __( 'Set featured image' ) ) . '</p>';
164202

165203
echo $html;
166204

167205
} // end link_text_callback
168206

169-
public function button_text_callback() {
207+
public function button_text_callback( $args ) {
170208

171209
$options = get_option( $this->plugin_slug );
172210
$value = isset( $options['button_text'] ) ? $options['button_text'] : '';
173211

174-
$html = '<input type"text" id="button_text" name="' . $this->plugin_slug . '[button_text]" value="' . $value . '" class="regular-text" />';
212+
$html = '<input type"text" id="button_text" name="' . $this->plugin_slug . '[' . $args[0] . '][button_text]" value="' . $value . '" class="regular-text" />';
175213
$html .= '<p class="description">' . sprintf( __( 'Enter the custom button text to replace the "%s".', $this->plugin_slug ), __( 'Set featured image' ) ) . '</p>';
176214

177215
echo $html;

admin/views/admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="wrap">
1818

1919
<div id="icon-themes" class="icon32"></div>
20-
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
20+
<h2><?php echo esc_html( get_admin_page_title() ) . ' Settings'; ?></h2>
2121
<?php // settings_errors(); ?>
2222

2323
<form method="post" action="options.php">

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.5.0
17+
* Version: 0.6.0
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.5.0';
31+
const VERSION = '0.6.0';
3232

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

0 commit comments

Comments
 (0)