Skip to content

Commit

Permalink
finetune codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Oct 4, 2022
1 parent e4ef309 commit 43b5e54
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<a name="1.0.0"></a>
# [1.0.0](https://github.com/wp-extends/api-explorer) (2022-xx-xx)
# [1.0.0](https://github.com/Awilum/wp-api-explorer) (2022-10-04)
* Initial release
28 changes: 13 additions & 15 deletions api-explorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,40 @@

/**
* Plugin Name: API Explorer
* Plugin URI: https://github.com/Awilum
* Description: API Explorer
* Plugin URI: https://github.com/Awilum/wp-api-explorer
* Description: WordPress plugins adds API Explorer link for pages, posts, tags, categories and comments
* Author: Sergey Romanenko
* Version: 1.0.0
* Author URI: https://github.com/Awilum
* Author URI: https://awilum.github.io/
*/

use Glowy\View\View;
require_once __DIR__ . '/includes/vars.php';

! is_file($autoload = __DIR__ . '/vendor/autoload.php') and exit('Please run: <i>composer install</i>');
Vars::$storage['views_directory'] = __DIR__ . '/views/';
Vars::$storage['views_extension'] = 'php';

$loader = require_once $autoload;

View::setDirectory(__DIR__ . '/views/');
View::setExtension('php');
require_once __DIR__ . '/includes/view.php';

add_filter('comment_row_actions', function($actions, $data) {
return array_merge($actions, [view('link_row')->with(['data' => $data])->render()]);
return array_merge($actions, [view('link_row', ['data' => $data])]);
}, 100, 2);

add_filter('tag_row_actions', function($actions, $data) {
return array_merge($actions, [view('link_row')->with(['data' => $data])->render()]);
return array_merge($actions, [view('link_row', ['data' => $data])]);
}, 100, 2);

add_filter('page_row_actions', function($actions, $data) {
return array_merge($actions, [view('link_row')->with(['data' => $data])->render()]);
return array_merge($actions, [view('link_row', ['data' => $data])]);
}, 100, 2);

add_filter('post_row_actions', function($actions, $data) {
return array_merge($actions, [view('link_row')->with(['data' => $data])->render()]);
return array_merge($actions, [view('link_row', ['data' => $data])]);
}, 100, 2);

add_action('admin_footer', function() {
view('explorer')->display();
echo view('explorer');
});

add_action('admin_print_footer_scripts', function() {
view('js')->display();
echo view('js');
});
30 changes: 0 additions & 30 deletions composer.json

This file was deleted.

5 changes: 5 additions & 0 deletions includes/vars.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

class Vars { static $storage = []; }
34 changes: 34 additions & 0 deletions includes/view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

function view(string $view, array $data = [], $callback = null)
{
$viewFile = Vars::$storage['views_directory'] . $view . '.' . Vars::$storage['views_extension'];

if (! file_exists($viewFile)) {
return '';
}

// Extract variables as references
$viewVars = array_merge($data);

extract($viewVars, EXTR_REFS);

// Turn on output buffering
ob_start();

// Include view file
include $viewFile;

// Write content.
$content = ob_get_clean() ?: '';

// Filter content
if ($callback !== null) {
$content = call_user_func($callback, $content);
}

// Return rendered content
return $content;
}
2 changes: 1 addition & 1 deletion views/link_row.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$id = $data->comment_ID;
break;
default:
# code...

break;
}
?>
Expand Down

0 comments on commit 43b5e54

Please sign in to comment.