Skip to content

Commit

Permalink
Merge pull request #1488 from podlove/feat/onboarding-settings
Browse files Browse the repository at this point in the history
feat(onboarding) - Set default settings
  • Loading branch information
dnkbln authored Aug 9, 2024
2 parents c17767b + 0c5d3b0 commit 42cc020
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/modules/onboarding/onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Podlove\Modules\Onboarding;

use Podlove\Modules\Onboarding\Settings\OnboardingPage;
use Podlove\Api\Admin\WP_REST_PodloveOnboarding_Controller;
use Podlove\Modules\Onboarding\WP_REST_PodloveOnboarding_Controller;

class Onboarding extends \Podlove\Modules\Base
{
Expand Down
55 changes: 55 additions & 0 deletions lib/modules/onboarding/rest_api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Podlove\Modules\Onboarding;

use Podlove\Modules\WordpressFileUpload\Wordpress_File_Upload;
use WP_REST_Controller;

class WP_REST_PodloveOnboarding_Controller extends WP_REST_Controller
{
/**
* Constructor.
*/
public function __construct()
{
$this->namespace = 'podlove/v2';
$this->rest_base = 'onboarding';
}

/**
* Register the component routes.
*/
public function register_routes()
{
register_rest_route($this->namespace, $this->rest_base."/setup", [
[
'methods' => \WP_REST_SERVER::EDITABLE,
'callback' => [$this, 'update_items'],
'permission_callback' => [$this, 'update_permissions_check']
]
]);
}

public function update_items($request)
{
// activate File-Upload-Module and set default settings
if (!\Podlove\Modules\Base::is_active('wordpress_file_upload')) {
\Podlove\Modules\Base::activate('wordpress_file_upload');
}
$upload_modul = Wordpress_File_Upload::instance();
$upload_modul->update_module_option('upload_subdir', 'podlove-media');
// set upload loaction to emty
$settings = get_option('podlove_podcast');
$settings["media_file_base_uri"] = "";
update_option('podlove_podcast', $settings);
}

public function update_permissions_check($request)
{
if (!current_user_can('edit_posts')) {
return new \Podlove\Api\Error\ForbiddenAccess();
}

return true;
}
}

0 comments on commit 42cc020

Please sign in to comment.