page-template-example icon indicating copy to clipboard operation
page-template-example copied to clipboard

No working with WordPress v4.7

Open WPDevHQ opened this issue 8 years ago • 5 comments

Hello Tom,

Unfortunatelly this approach will no longer work with the upcoming WordPress v4.7

Any ideas on how we can make it work so that we can continue using the code?

Many thanks, Zulf

WPDevHQ avatar Nov 06 '16 17:11 WPDevHQ

Thanks for the heads up on this. I'll try and take a look at it as soon as I get a chance (before the release of 4.7).

tommcfarlin avatar Nov 09 '16 21:11 tommcfarlin

Hey guys, After doing some research with the changes in templates for 4.7, if you change lines 81 -> 82 like below...

    if ( version_compare( floatval($GLOBALS['wp_version']), '4.7', '

Then add the simple function to use for version 4.7 up...

    /**
     * Adds our template to the page dropdown for v4.7+
     *
     **/
    public function add_new_template( $posts_templates ) {
        $posts_templates = array_merge( $posts_templates, $this->templates );
        return $posts_templates;
    }

It works for me, here's the page I referenced for some more info on the changes https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/ It probably could use some more testing but it works for my purposes.

leeb003 avatar Nov 16 '16 00:11 leeb003

This works for me as well.

michaeltorbert avatar Dec 07 '16 21:12 michaeltorbert

I'm looking to have this plugin re-written hopefully sooner rather than later so it will include support for 4.7 and will be much better organized from an OOP standpoint.

Thanks for the comments thus far :).

tommcfarlin avatar Dec 14 '16 05:12 tommcfarlin

The solution suggested by @leeb003 works perfectly for me. Thank you! I'd be very interested in an updated version of this plugin.

maurobringolf avatar Dec 14 '16 10:12 maurobringolf