| @@ -17,13 +17,13 @@ | ||
| 17 | 17 | public $query = 'dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }'; |
| 18 | 18 | |
| 19 | 19 | public function permission_check( WP_REST_Request $request ) { |
| 20 | 20 | $this->request = $request; |
| 21 | - // $_route = $request->get_route(); | |
| 21 | + $_route = $request->get_route(); | |
| 22 | 22 | |
| 23 | - // if( $_route === '/templately/v1/dependencies/install' && ! Helper::current_user_can( 'install_plugins' ) ) { | |
| 24 | - // return Helper::error('invalid_permission', __( 'Sorry, you do not have permission to install a plugin.', 'templately' ), 'dependencies/install', 403 ); | |
| 25 | - // } | |
| 23 | + if( $_route === '/templately/v1/dependencies/install' && ! current_user_can( 'install_plugins' ) ) { | |
| 24 | + return $this->error('invalid_permission', __( 'Sorry, you do not have permission to install a plugin.', 'templately' ), 'dependencies/install', 403 ); | |
| 25 | + } | |
| 26 | 26 | |
| 27 | 27 | return true; |
| 28 | 28 | } |
| 29 | 29 | |
| @@ -28,10 +28,8 @@ | ||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public function register_routes() { |
| 31 | 31 | $this->get( $this->endpoint, [ $this, 'get_dependencies' ] ); |
| 32 | - $this->get( $this->endpoint . '/plugins', [ $this, 'get_plugins' ] ); | |
| 33 | - $this->get( $this->endpoint . '/themes', [ $this, 'get_themes' ] ); | |
| 34 | 32 | $this->post( $this->endpoint . '/check', [$this, 'check_dependencies'] ); |
| 35 | 33 | $this->post( $this->endpoint . '/install', [$this, 'install_dependencies'] ); |
| 36 | 34 | } |
| 37 | 35 | |
| @@ -78,15 +76,14 @@ | ||
| 78 | 76 | |
| 79 | 77 | $_inactive_plugins = []; |
| 80 | 78 | $_plugins = Helper::get_plugins(); |
| 81 | 79 | |
| 82 | - if( $platform === 'elementor' ) { | |
| 80 | + if( ! Helper::is_plugin_active( 'elementor/elementor.php' ) && $platform === 'elementor' ) { | |
| 83 | 81 | $elementor_plugin = new stdClass(); |
| 84 | 82 | $elementor_plugin->name = __( 'Elementor', 'templately' ); |
| 85 | 83 | $elementor_plugin->plugin_file = 'elementor/elementor.php'; |
| 86 | 84 | $elementor_plugin->slug = 'elementor'; |
| 87 | 85 | $elementor_plugin->is_pro = false; |
| 88 | - $elementor_plugin->is_active = Helper::is_plugin_active( 'elementor/elementor.php' ); | |
| 89 | 86 | |
| 90 | 87 | $_inactive_plugins[] = $elementor_plugin; |
| 91 | 88 | } |
| 92 | 89 | |
| @@ -96,14 +93,12 @@ | ||
| 96 | 93 | continue; |
| 97 | 94 | } |
| 98 | 95 | |
| 99 | 96 | $dependency = ( object ) $dependency; |
| 100 | - if ( is_null( $dependency->plugin_file ) ) { | |
| 97 | + if ( is_null( $dependency->plugin_file ) || Helper::is_plugin_active( $dependency->plugin_file ) ) { | |
| 101 | 98 | continue; |
| 102 | 99 | } |
| 103 | 100 | |
| 104 | - $dependency->is_active = Helper::is_plugin_active( $dependency->plugin_file ); | |
| 105 | - | |
| 106 | 101 | if( isset( $dependency->plugin_original_slug ) ) { |
| 107 | 102 | $dependency->slug = $dependency->plugin_original_slug; |
| 108 | 103 | unset( $dependency->plugin_original_slug ); |
| 109 | 104 | } |
| @@ -132,111 +127,7 @@ | ||
| 132 | 127 | '/install', |
| 133 | 128 | 400 |
| 134 | 129 | ); |
| 135 | 130 | } |
| 136 | - $installed = Installer::get_instance()->install( $requirements ); | |
| 137 | - if(empty($installed['success'])){ | |
| 138 | - return $this->error($installed['code'], $installed['message'], 'dependencies/install', 403 ); | |
| 139 | - } | |
| 140 | - return $installed; | |
| 131 | + return Installer::get_instance()->install( $requirements ); | |
| 141 | 132 | } |
| 142 | - | |
| 143 | - public function get_plugins() { | |
| 144 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 145 | - | |
| 146 | - $plugins = array(); | |
| 147 | - | |
| 148 | - foreach ( get_plugins() as $file => $data ) { | |
| 149 | - // if ( is_wp_error( $this->check_read_permission( $file ) ) ) { | |
| 150 | - // continue; | |
| 151 | - // } | |
| 152 | - | |
| 153 | - $data = array( | |
| 154 | - 'plugin' => substr( $file, 0, - 4 ), | |
| 155 | - 'status' => $this->get_plugin_status( $file ), | |
| 156 | - 'name' => $data['Name'], | |
| 157 | - 'plugin_uri' => $data['PluginURI'], | |
| 158 | - 'author' => $data['Author'], | |
| 159 | - 'author_uri' => $data['AuthorURI'], | |
| 160 | - 'description' => array( | |
| 161 | - 'raw' => $data['Description'], | |
| 162 | - 'rendered' => $data['Description'], | |
| 163 | - ), | |
| 164 | - 'version' => $data['Version'], | |
| 165 | - 'network_only' => $data['Network'], | |
| 166 | - 'requires_wp' => $data['RequiresWP'], | |
| 167 | - 'requires_php' => $data['RequiresPHP'], | |
| 168 | - 'textdomain' => $data['TextDomain'], | |
| 169 | - ); | |
| 170 | - | |
| 171 | - $plugins[] = $data; | |
| 172 | - } | |
| 173 | - | |
| 174 | - return new \WP_REST_Response( $plugins ); | |
| 175 | - } | |
| 176 | - | |
| 177 | - public function get_themes() { | |
| 178 | - $themes = array(); | |
| 179 | - | |
| 180 | - $active_themes = wp_get_themes(); | |
| 181 | - $current_theme = wp_get_theme(); | |
| 182 | - | |
| 183 | - foreach ( $active_themes as $theme_name => $theme ) { | |
| 184 | - $data = array( | |
| 185 | - 'status' => $theme->get_stylesheet() === $current_theme->get_stylesheet() ? 'active' : 'inactive', | |
| 186 | - 'template' => $theme->get_template(), | |
| 187 | - 'stylesheet' => $theme->get_stylesheet(), | |
| 188 | - ); | |
| 189 | - | |
| 190 | - | |
| 191 | - $plain_field_mappings = array( | |
| 192 | - 'requires_php' => 'RequiresPHP', | |
| 193 | - 'requires_wp' => 'RequiresWP', | |
| 194 | - 'textdomain' => 'TextDomain', | |
| 195 | - 'version' => 'Version', | |
| 196 | - ); | |
| 197 | - | |
| 198 | - foreach ( $plain_field_mappings as $field => $header ) { | |
| 199 | - $data[ $field ] = $theme->get( $header ); | |
| 200 | - } | |
| 201 | - | |
| 202 | - $rich_field_mappings = array( | |
| 203 | - 'author' => 'Author', | |
| 204 | - 'author_uri' => 'AuthorURI', | |
| 205 | - 'description' => 'Description', | |
| 206 | - 'name' => 'Name', | |
| 207 | - 'tags' => 'Tags', | |
| 208 | - 'theme_uri' => 'ThemeURI', | |
| 209 | - ); | |
| 210 | - | |
| 211 | - foreach ( $rich_field_mappings as $field => $header ) { | |
| 212 | - $data[ $field ]['raw'] = $theme->display( $header, false, true ); | |
| 213 | - $data[ $field ]['rendered'] = $theme->display( $header ); | |
| 214 | - } | |
| 215 | - | |
| 216 | - $themes[] = $data; | |
| 217 | - } | |
| 218 | - | |
| 219 | - return new \WP_REST_Response( $themes ); | |
| 220 | - } | |
| 221 | - | |
| 222 | - /** | |
| 223 | - * Get's the activation status for a plugin. | |
| 224 | - * | |
| 225 | - * @since 5.5.0 | |
| 226 | - * | |
| 227 | - * @param string $plugin The plugin file to check. | |
| 228 | - * @return string Either 'active' or 'inactive'. | |
| 229 | - */ | |
| 230 | - protected function get_plugin_status( $plugin ) { | |
| 231 | - if ( is_plugin_active_for_network( $plugin ) ) { | |
| 232 | - return 'active'; | |
| 233 | - } | |
| 234 | - | |
| 235 | - if ( is_plugin_active( $plugin ) ) { | |
| 236 | - return 'active'; | |
| 237 | - } | |
| 238 | - | |
| 239 | - return 'inactive'; | |
| 240 | - } | |
| 241 | - | |
| 242 | 133 | } |