← All changes
|
includes/template-library/sources/local.php
+20
-4
4.2.0-beta2
→
4.0.0-dev3
View file →
| @@ -14,8 +14,9 @@ | ||
| 14 | 14 | use Elementor\Utils; |
| 15 | 15 | use Elementor\User; |
| 16 | 16 | use Elementor\Core\Isolation\Wordpress_Adapter; |
| 17 | 17 | use Elementor\Core\Isolation\Wordpress_Adapter_Interface; |
| 18 | +use Elementor\Core\Isolation\Elementor_Adapter; | |
| 18 | 19 | use Elementor\Core\Isolation\Elementor_Adapter_Interface; |
| 19 | 20 | use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; |
| 20 | 21 | use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Editor_One_Saved_Templates_Menu; |
| 21 | 22 | use Elementor\Includes\TemplateLibrary\Sources\AdminMenuItems\Editor_One_Templates_Menu; |
| @@ -1996,18 +1997,33 @@ | ||
| 1996 | 1997 | if ( null === $this->wordpress_adapter ) { |
| 1997 | 1998 | $this->set_wordpress_adapter( new WordPress_Adapter() ); |
| 1998 | 1999 | } |
| 1999 | 2000 | |
| 2001 | + if ( ! $this->should_check_permissions( $args ) ) { | |
| 2002 | + return true; | |
| 2003 | + } | |
| 2004 | + | |
| 2000 | 2005 | $post_id = intval( $args['template_id'] ); |
| 2001 | 2006 | $post_status = $this->wordpress_adapter->get_post_status( $post_id ); |
| 2007 | + $is_private_or_non_published = ( 'private' === $post_status && ! $this->wordpress_adapter->current_user_can( 'read_private_posts', $post_id ) ) || ( 'publish' !== $post_status ); | |
| 2002 | 2008 | |
| 2003 | - if ( 'publish' === $post_status && ! post_password_required( $post_id ) ) { | |
| 2004 | - return true; | |
| 2009 | + $can_read_template = ! $is_private_or_non_published || $this->wordpress_adapter->current_user_can( 'edit_post', $post_id ); | |
| 2010 | + | |
| 2011 | + return apply_filters( 'elementor/template-library/is_allowed_to_read_template', $can_read_template, $args ); | |
| 2012 | + } | |
| 2013 | + | |
| 2014 | + private function should_check_permissions( array $args ): bool { | |
| 2015 | + if ( null === $this->elementor_adapter ) { | |
| 2016 | + $this->set_elementor_adapter( new Elementor_Adapter() ); | |
| 2005 | 2017 | } |
| 2006 | 2018 | |
| 2007 | - $can_read_template = $this->wordpress_adapter->current_user_can( 'edit_post', $post_id ); | |
| 2019 | + $check_permissions = isset( $args['check_permissions'] ) && false === $args['check_permissions']; | |
| 2008 | 2020 | |
| 2009 | - return apply_filters( 'elementor/template-library/is_allowed_to_read_template', $can_read_template, $args ); | |
| 2021 | + if ( $check_permissions ) { | |
| 2022 | + return false; | |
| 2023 | + } | |
| 2024 | + | |
| 2025 | + return true; | |
| 2010 | 2026 | } |
| 2011 | 2027 | |
| 2012 | 2028 | public function set_wordpress_adapter( Wordpress_Adapter_Interface $wordpress_adapter ) { |
| 2013 | 2029 | $this->wordpress_adapter = $wordpress_adapter; |