Robin North
Forum Replies Created
-
Forum: Plugins
In reply to: [Menu Section Titles] Plugin adding extra doctype, html and body tagsHey Zach,
Not a problem, I’m happy to be able to help out — thanks for developing the plugin in the first place!
Forum: Plugins
In reply to: [Menu Section Titles] Plugin adding extra doctype, html and body tagsHi Zach,
In addition to the above, the reason you haven’t seen this happening on your local test install is likely because it seems from your screenshots that you’re examining the generated source of the page with your browser’s developer tools. As the additional DTD, head and body tags that are output by the plugin are invalid HTML in the context in which they appear (nested inside another
body
element), your browser will disregard them and thus they do not appear in the generated source.If you view the original source of the page that is output by WordPress, I imagine you will see this invalid markup for yourself.
Forum: Plugins
In reply to: [Menu Section Titles] Plugin adding extra doctype, html and body tagsI noticed I was experiencing this issue today on two WordPress installs running 4.4.2 on PHP 5.4.17 and 5.6.10 respectively.
DOMDocument::loadHTML
would appear to add DTD, head and body tags if they’re missing from the HTML string you attempt to load. There’s a variety of suggestions of how to work around this to just return the desired HTML fragment when usingDOMDocument::saveHTML
— see https://php.net/manual/en/domdocument.savehtml.php#85165 and https://stackoverflow.com/questions/11216726/php-domdocument-without-the-dtd-head-and-body-tags.I’ve implemented the simplest solution that is compatible with PHP < 5.3.6 and submitted a pull request on GitHub for you: https://github.com/zachwills/wp-menu-section-titles/pull/1
Forum: Plugins
In reply to: [Category Sticky Post] Sticky Reset?Unfortunately, I’m still having this issue with 1.2.1. I can’t see from the plugin code how you’ve tried to work around the issue, am I missing something obvious?
I’ve patched my copy with the refactored code I posted previously, which I can confirm as working with 1.2.1.
Forum: Plugins
In reply to: [Category Sticky Post] Sticky Reset?Refactored my refactored code to only prevent disabling of the category the current post is stickied in, and to be a bit more concise:
/** * Renders the select box that allows users to choose the category into which to stick the * specified post. * * @param $post The post to be marked as sticky for the specified category. */ function category_sticky_post_display( $post ) { // Set the nonce for security wp_nonce_field( plugin_basename( __FILE__ ), 'category_sticky_post_nonce' ); // First, read all the categories $categories = get_categories(); // Get the current sticky category for the post, if any $post_sticky_category = get_post_meta( $post->ID, 'category_sticky_post', true ); // Build the HTML that will display the select box $html = '<select id="category_sticky_post" name="category_sticky_post">'; $html .= '<option value="0">' . __( 'Select a category...', 'category-sticky-post' ) . '</option>'; foreach( $categories as $category ) { $html .= '<option value="' . $category->cat_ID . '" ' . selected( $post_sticky_category, $category->cat_ID, false ) . ( ( $this->category_has_sticky_post( $category->cat_ID ) && $post_sticky_category !== $category->cat_ID ) ? ' disabled ' : '' ) . '>'; $html .= $category->cat_name; $html .= '</option>'; } // end foreach $html .= '</select>'; echo $html; } // end category_sticky_post_display
Forum: Plugins
In reply to: [Category Sticky Post] Sticky Reset?Have debugged this and found that because the plugin enforces a single sticky post per category by means of adding the
disabled
attribute to the currently-assigned sticky category in the Sticky Category select menu, updating a post with a sticky category assigned will result in the sticky category custom post meta data being cleared, as disabled select option values are not added to the $_POST array when a form is POSTed in PHP.To solve this, I’ve refactored
category_sticky_post_display
to only add thedisabled
attribute when a category currently has a sticky post and that post is not the one currently being edited.Here’s the code:
/** * Renders the select box that allows users to choose the category into which to stick the * specified post. * * @param $post The post to be marked as sticky for the specified category. */ function category_sticky_post_display( $post ) { // Set the nonce for security wp_nonce_field( plugin_basename( __FILE__ ), 'category_sticky_post_nonce' ); // First, read all the categories $categories = get_categories(); // Build the HTML that will display the select box $html = '<select id="category_sticky_post" name="category_sticky_post">'; $html .= '<option value="0">' . __( 'Select a category...', 'category-sticky-post' ) . '</option>'; foreach( $categories as $category ) { $html .= '<option value="' . $category->cat_ID . '" ' . selected( get_post_meta( $post->ID, 'category_sticky_post', true ), $category->cat_ID, false ) . ( ( $this->category_has_sticky_post( $category->cat_ID ) && ! get_post_meta( $post->ID, 'category_sticky_post', true ) ) ? ' disabled ' : '' ) . '>'; $html .= $category->cat_name; $html .= '</option>'; } // end foreach $html .= '</select>'; echo $html; } // end category_sticky_post_display
Additionally, the
delete_post_meta
call can be removed fromsave_category_sticky_post_data
, asupdate_post_meta
will not add extra rows to the wp_postmeta table if the post already has a post meta object with the same key.Forum: Plugins
In reply to: [Category Sticky Post] Sticky Reset?I’m also experiencing this issue and would also like to see what can be done about it, cheers!