ta( array() ); return $this->response->to_array(); } $this->response->set_code( '200' ) ->set_message( 'OK' ) ->set_data( array() ); return $this->response->to_array(); } /** * API method called to add VK via app. * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically. * * @since 8.6.1 * @access private * * @param array $data Vk accounts data. * * @return array */ private function add_account_vk( $data ) { $services = array(); $active_accounts = array(); $vk_service = new Rop_Vk_Service(); $model = new Rop_Services_Model(); $db = new Rop_Db_Upgrade(); $vk_service->add_account_with_app( $data ); $services[ $vk_service->get_service_id() ] = $vk_service->get_service(); $active_accounts = array_merge( $active_accounts, $vk_service->get_service_active_accounts() ); if ( ! empty( $services ) ) { $model->add_authenticated_service( $services ); } if ( ! empty( $active_accounts ) ) { $db->migrate_schedule( $active_accounts ); $db->migrate_post_formats( $active_accounts ); } else { $this->response->set_code( '500' ) ->set_data( array() ); return $this->response->to_array(); } $this->response->set_code( '200' ) ->set_message( 'OK' ) ->set_data( array() ); return $this->response->to_array(); } /** * API method to call the license processor. * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically. * * @since 9.1.0 * * @param array $data Data passed from the AJAX call. * * @return array */ private function set_license( $data ) { if ( ! current_user_can( 'manage_options' ) ) { $this->response ->set_code( '403' ) ->set_message( 'Forbidden' ) ->set_data( array( 'success' => false, 'message' => Rop_I18n::get_labels( 'general.no_permission' ) ) ); return $this->response->to_array(); } // NOTE: The license processor requires the license key, even if we want to deactivate the license. if ( empty( $data['license_key'] ) ) { $general_settings = new Rop_Global_Settings; $license_data = $general_settings->get_license_data(); if ( ! empty( $license_data ) && isset( $license_data->key ) ) { $data['license_key'] = $license_data->key; } } $response = apply_filters( 'themeisle_sdk_license_process_rop', $data['license_key'], $data['action'] ); if ( is_wp_error( $response ) ) { return $this->response ->set_data( array( 'success' => false, 'message' => 'activate' === $data['action'] ? Rop_I18n::get_labels( 'general.validation_failed' ) : Rop_I18n::get_labels( 'general.could_not_change_license' ) ) ) ->to_array(); } return $this->response ->set_code( '200' ) ->set_data( array( 'success' => true ) ) ->to_array(); } /** * API method called to add Webhook account. * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically. * * @since 9.1.0 * @access private * * @param array $data Webhook account data. * * @return array */ private function add_account_webhook( $data ) { $services = array(); $webhook_service = new Rop_Webhook_Service(); $model = new Rop_Services_Model(); $db = new Rop_Db_Upgrade(); if ( ! $webhook_service->add_webhook( $data ) ) { $this->response->set_code( '422' ) ->set_data( array() ); return $this->response->to_array(); } $services[ $webhook_service->get_service_id() ] = $webhook_service->get_service(); $active_accounts = $webhook_service->get_service_active_accounts(); if ( ! empty( $services ) ) { $model->add_authenticated_service( $services ); } if ( ! empty( $active_accounts ) ) { $db->migrate_schedule( $active_accounts ); $db->migrate_post_formats( $active_accounts ); } else { $this->response->set_code( '500' ) ->set_data( array() ); return $this->response->to_array(); } $this->response->set_code( '200' ) ->set_message( 'OK' ) ->set_data( array() ); return $this->response->to_array(); } /** * API method called to edit Webhook account. * * @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically. * * @since 9.1.0 * @access private * * @param array $data Webhook account data. * * @return array */ private function edit_account_webhook( $data ) { $webhook_service = new Rop_Webhook_Service(); $model = new Rop_Services_Model(); if ( ! $webhook_service->add_webhook( $data ) ) { $this->response->set_code( '422' ) ->set_data( array() ); return $this->response->to_array(); } $service_id = ! empty( $data['service_id'] ) ? $data['service_id'] : ''; $authenticated_services = $model->get_authenticated_services(); if ( ! isset( $authenticated_services[ $service_id ] ) ) { $this->response->set_code( '422' ) ->set_data( array() ); return $this->response->to_array(); } $authenticated_services[ $service_id ] = array_merge( $authenticated_services[ $service_id ], $webhook_service->get_service() ); $model->update_authenticated_services( $authenticated_services ); if ( ! empty( $data['active'] ) && ! empty( $data['full_id'] ) ) { $model->add_active_accounts( array( $data['full_id'] ) ); } $this->response->set_code( '200' ) ->set_message( 'OK' ) ->set_data( array() ); return $this->response->to_array(); } }