Skip to content

Commit

Permalink
Adds small tweaks based on Scrutinizer CI feedback. Fixes the nonce v…
Browse files Browse the repository at this point in the history
…alues.
  • Loading branch information
mattyza committed Dec 14, 2014
1 parent a16fa95 commit faa73fc
Showing 1 changed file with 40 additions and 46 deletions.
86 changes: 40 additions & 46 deletions classes/class-starter-plugin-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ public function register_post_type () {
'all_items' => sprintf( __( 'All %s', 'starter-plugin' ), $this->plural ),
'view_item' => sprintf( __( 'View %s', 'starter-plugin' ), $this->singular ),
'search_items' => sprintf( __( 'Search %a', 'starter-plugin' ), $this->plural ),
'not_found' => sprintf( __( 'No %s Found', 'starter-plugin' ), $this->plural ),
'not_found' => sprintf( __( 'No %s Found', 'starter-plugin' ), $this->plural ),
'not_found_in_trash' => sprintf( __( 'No %s Found In Trash', 'starter-plugin' ), $this->plural ),
'parent_item_colon' => '',
'menu_name' => $this->plural

'menu_name' => $this->plural;
);

$single_slug = apply_filters( 'starter_plugin_single_slug', _x( sanitize_title_with_dashes( $this->singular ), 'single post url slug', 'starter-plugin' ) );
Expand All @@ -128,7 +127,7 @@ public function register_post_type () {
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'page-attributes' ),
'menu_position' => 5,
'menu_icon' => 'dashicons-smiley'
'menu_icon' => 'dashicons-smiley',
);

$args = wp_parse_args( $this->args, $defaults );
Expand All @@ -137,7 +136,7 @@ public function register_post_type () {
} // End register_post_type()

/**
* Register the "feature-category" taxonomy.
* Register the "thing-category" taxonomy.
* @access public
* @since 1.3.0
* @return void
Expand All @@ -157,23 +156,18 @@ public function register_taxonomy () {
* @return void
*/
public function register_custom_columns ( $column_name, $id ) {
global $wpdb, $post;
global $post;

$meta = get_post_custom( $id );
// Uncomment this line to use metadata in the switches below.
// $meta = get_post_custom( $id );

switch ( $column_name ) {

case 'image':
$value = '';

$value = $this->get_image( $id, 40 );

echo $value;
echo $this->get_image( $id, 40 );
break;

default:
break;

}
} // End register_custom_columns()

Expand All @@ -188,7 +182,7 @@ public function register_custom_columns ( $column_name, $id ) {
public function register_custom_column_headings ( $defaults ) {
$new_columns = array( 'image' => __( 'Image', 'starter-plugin' ) );

$last_item = '';
$last_item = array();

if ( isset( $defaults['date'] ) ) { unset( $defaults['date'] ); }

Expand All @@ -199,7 +193,7 @@ public function register_custom_column_headings ( $defaults ) {
}
$defaults = array_merge( $defaults, $new_columns );

if ( $last_item != '' ) {
if ( is_array( $last_item ) && 0 < count( $last_item ) ) {
foreach ( $last_item as $k => $v ) {
$defaults[$k] = $v;
break;
Expand All @@ -216,33 +210,33 @@ public function register_custom_column_headings ( $defaults ) {
* @return array Modified array.
*/
public function updated_messages ( $messages ) {
global $post, $post_ID;

$messages[$this->post_type] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __( '%3$s updated. %sView %4$s%s', 'starter-plugin' ), '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', '</a>', $this->singular, strtolower( $this->singular ) ),
2 => __( 'Custom field updated.', 'starter-plugin' ),
3 => __( 'Custom field deleted.', 'starter-plugin' ),
4 => sprintf( __( '%s updated.', 'starter-plugin' ), $this->singular ),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision']) ? sprintf( __( '%s restored to revision from %s', 'starter-plugin' ), $this->singular, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __( '%s published. %sView feature%s', 'starter-plugin' ), $this->singular, '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', '</a>' ),
7 => sprintf( __( '%s saved.', 'starter-plugin' ), $this->singular ),
8 => sprintf( __( '%s submitted. %sPreview %s%s', 'starter-plugin' ), $this->singular, strtolower( $this->singular ), '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', '</a>' ),
9 => sprintf( __( '%s scheduled for: %1$s. %2$sPreview %s%3$s', 'starter-plugin' ), $this->singular, strtolower( $this->singular ),
// translators: Publish box date format, see http://php.net/date
'<strong>' . date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) . '</strong>', '<a target="_blank" href="' . esc_url( get_permalink($post_ID) ) . '">', '</a>' ),
10 => sprintf( __( '%s draft updated. %sPreview %s%s', 'starter-plugin' ), $this->singular, strtolower( $this->singular ), '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', '</a>' ),
);

return $messages;
global $post, $post_ID;

$messages[$this->post_type] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __( '%3$s updated. %sView %4$s%s', 'starter-plugin' ), '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', '</a>', $this->singular, strtolower( $this->singular ) ),
2 => __( 'Custom field updated.', 'starter-plugin' ),
3 => __( 'Custom field deleted.', 'starter-plugin' ),
4 => sprintf( __( '%s updated.', 'starter-plugin' ), $this->singular ),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision']) ? sprintf( __( '%s restored to revision from %s', 'starter-plugin' ), $this->singular, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __( '%s published. %sView feature%s', 'starter-plugin' ), $this->singular, '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', '</a>' ),
7 => sprintf( __( '%s saved.', 'starter-plugin' ), $this->singular ),
8 => sprintf( __( '%s submitted. %sPreview %s%s', 'starter-plugin' ), $this->singular, strtolower( $this->singular ), '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', '</a>' ),
9 => sprintf( __( '%s scheduled for: %1$s. %2$sPreview %s%3$s', 'starter-plugin' ), $this->singular, strtolower( $this->singular ),
// translators: Publish box date format, see http://php.net/date
'<strong>' . date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) . '</strong>', '<a target="_blank" href="' . esc_url( get_permalink($post_ID) ) . '">', '</a>' ),
10 => sprintf( __( '%s draft updated. %sPreview %s%s', 'starter-plugin' ), $this->singular, strtolower( $this->singular ), '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', '</a>' ),
);

return $messages;
} // End updated_messages()

/**
* Setup the meta box.
*
* @access public
* @since 1.1.0
* @since 1.0.0
* @return void
*/
public function meta_box_setup () {
Expand All @@ -253,7 +247,7 @@ public function meta_box_setup () {
* The contents of our meta box.
*
* @access public
* @since 1.1.0
* @since 1.0.0
* @return void
*/
public function meta_box_content () {
Expand All @@ -263,7 +257,7 @@ public function meta_box_content () {

$html = '';

$html .= '<input type="hidden" name="starter_plugin_' . $this->post_type . '_noonce" id="starter_plugin_' . $this->post_type . '_noonce" value="' . wp_create_nonce( plugin_basename( $this->dir ) ) . '" />';
$html .= '<input type="hidden" name="starter_plugin_' . $this->post_type . '_noonce" id="starter_plugin_' . $this->post_type . '_noonce" value="' . wp_create_nonce( plugin_basename( dirname( Starter_Plugin()->plugin_path ) ) ) . '" />';

if ( 0 < count( $field_data ) ) {
$html .= '<table class="form-table">' . "\n";
Expand Down Expand Up @@ -291,19 +285,19 @@ public function meta_box_content () {
* Save meta box fields.
*
* @access public
* @since 1.1.0
* @since 1.0.0
* @param int $post_id
* @return void
*/
public function meta_box_save ( $post_id ) {
global $post, $messages;

// Verify
if ( ( get_post_type() != $this->post_type ) || ! wp_verify_nonce( $_POST['starter_plugin_' . $this->post_type . '_noonce'], plugin_basename( $this->dir ) ) ) {
if ( ( get_post_type() != $this->post_type ) || ! wp_verify_nonce( $_POST['starter_plugin_' . $this->post_type . '_noonce'], plugin_basename( dirname( Starter_Plugin()->plugin_path ) ) ) ) {
return $post_id;
}

if ( 'page' == $_POST['post_type'] ) {
if ( isset( $_POST['post_type'] ) && 'page' == esc_attr( $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return $post_id;
}
Expand Down Expand Up @@ -352,7 +346,7 @@ public function enter_title_here ( $title ) {

/**
* Get the settings for the custom fields.
* @since 1.1.0
* @since 1.0.0
* @return array
*/
public function get_custom_fields_settings () {
Expand All @@ -372,7 +366,7 @@ public function get_custom_fields_settings () {
/**
* Get the image for the given ID.
* @param int $id Post ID.
* @param string/array/int $size Image dimension. (default: "feature-thumbnail")
* @param mixed $size Image dimension. (default: "thing-thumbnail")
* @since 1.0.0
* @return string <img> tag.
*/
Expand Down Expand Up @@ -416,7 +410,7 @@ public function activation () {
/**
* Flush the rewrite rules
* @access public
* @since 1.3.1
* @since 1.0.0
* @return void
*/
private function flush_rewrite_rules () {
Expand All @@ -426,7 +420,7 @@ private function flush_rewrite_rules () {

/**
* Ensure that "post-thumbnails" support is available for those themes that don't register it.
* @since 1.0.1
* @since 1.0.0
* @return void
*/
public function ensure_post_thumbnails_support () {
Expand Down

0 comments on commit faa73fc

Please sign in to comment.