Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Tikhomirov committed Apr 16, 2023
1 parent 6b1b1f6 commit 5ff681a
Show file tree
Hide file tree
Showing 97 changed files with 17,960 additions and 976 deletions.
475 changes: 52 additions & 423 deletions AdminWP.php

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions functions/LogSlowActions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/*
Plugin Name: WP Trace slow action
Version: 1.0
Description: A simple plugin to show slow action
Author: Aleksey T
*/


class LogSlowActions
{
public static $trace;
public static $prev_action;

public function add_action()
{
self::$prev_action = !empty(self::$prev_action) ? self::$prev_action : microtime(true);
add_action('mu_plugin_loaded', [$this, 'logger'], 99, 1);
add_action('shutdown', [$this, 'logger'], 99, 1);
}

/**
* Logger
* @return void
*/
public function logger()
{
global $wp_filter;

foreach ($wp_filter as $hook_name => $filter) {
$timer = self::get_stop() - self::$prev_action;
if (!empty(self::$prev_action) && $timer >= 0.02 ) {
self::$trace[$hook_name] = [
'timer' => $timer,
'stats' => self::get_stats(),
];
}
self::$prev_action = self::get_stop();
}

if(self::$trace) {
$this->write_log(self::$trace);
}
}

/**
* Get stop time
* @return float
*/
private function get_stop()
{
global $timestart, $timeend;
$timeend = microtime(true);
$timetotal = ($timeend - $timestart) * 1000;
return $timetotal;
}

/**
* To float
*
* @param $number
* @return float
*/
private function to_float($number)
{
return floatval(preg_replace('/[^\d.]/', '', number_format($number)));
}

private static function get_stats(){
return sprintf(
__('SQL: %d за %s sec. %.2f MB ', 'wp-addon'),
get_num_queries(),
timer_stop(),
(memory_get_peak_usage() / 1024 / 1024)
);
}

public function write_log($data){
error_log(var_export($data, true));
}
}

function trace_slow_actions()
{
(new LogSlowActions())->add_action();
}
73 changes: 40 additions & 33 deletions functions/TinyMCE/bootstrap-shortcodes.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<?php
/**
*
* @year: 2019-04-23
* @see assets js "mce button"
*/



function add_bootstrap_3()
{
class TinyBootstrapExtends
{

public $name;

public function __construct()
{
$this->name = 'bootstrap';

add_action('admin_head', [$this, 'show']);
add_filter('mce_css', [$this, 'add_mce_css']);
add_action('admin_footer', [$this, 'get_shortcodes']);
Expand All @@ -25,38 +20,36 @@ public function __construct()
public function show()
{
// check user permissions
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' )) {
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}

if ('true' === get_user_option( 'rich_editing' )) { // check if WYSIWYG is enabled
add_filter( 'mce_external_plugins', [$this, 'add_js_mce'], 10, 1 );
add_filter( 'mce_buttons', [$this, 'register_mce_button'] );
add_filter( 'mce_external_plugins', [$this, 'add_js_mce'], 20, 1 );
add_filter( 'mce_buttons_3', [$this, 'register_mce_button'] );
}

}

/**
* Add JS
* @param $plugin_array
*
* @return mixed
* @param $plugin_array
* @return array
*/
public function add_js_mce($plugin_array)
public function add_js_mce($plugin_array): array
{
$arr['bootstrap'] = RW_PLUGIN_URL . 'assets/js/tinymce/bootstrap.js';

//RW_PLUGIN_URL . 'assets/js/tinymce/mce-button.js';
return $plugin_array + $arr;
}

/**
* Register new button in the editor
*
* @param $buttons array
*
* @return array
*/
public function register_mce_button($buttons): array
public function register_mce_button(array $buttons): array
{
$buttons[] = $this->name;
return $buttons;
Expand All @@ -68,39 +61,53 @@ public function register_mce_button($buttons): array
*/
public function get_shortcodes()
{
global $shortcode_tags;
echo '<script type="text/javascript">var shortcodes_button = new Array();';
$count = 0;
foreach ($shortcode_tags as $tag => $code) {
echo "shortcodes_button[{$count}] = '{$tag}';";
$count++;
}
echo '</script>';
global $shortcode_tags; ?>
<script type="text/javascript">
let shortcodes_button = [];
<?php $count = 0;
foreach ($shortcode_tags as $tag => $code) {
echo "shortcodes_button[{$count}] = '{$tag}';";
$count++;
} ?>
</script>
<?php
}

/**
* Add custom scripts to Editor
*
* @param $mce_css
*
* @return string
*/
public function add_mce_css($mce_css): string
{
$ver = '01';
if ( ! empty( $mce_css )) {
$mce_css .= ',';
}
$mce_css .= 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css';
$mce_css .= ',';
$mce_css .= '//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css';
$mce_css .= ',';
$mce_css .= RW_PLUGIN_URL . 'assets/css/min/tiny.min.css';

$file_path = get_theme_file_path('assets/css/plugins/bootstrap3.min.css');
$file_url = get_theme_file_uri('assets/css/plugins/bootstrap3.min.css');

if(file_exists($file_path)){
$ver = filemtime( $file_path );
$mce_css .= $file_url . '?' . $ver . ',';
$mce_css .= get_theme_file_uri('assets/css/theme.min.css') . '?' . $ver . ',';
$mce_css .= get_theme_file_uri('assets/css/fonts.min.css') . '?' . $ver . ',';

} else {
$mce_css .= 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css?' . $ver;
$mce_css .= ',';
$mce_css .= 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css';
$mce_css .= ',';
}

$mce_css .= RW_PLUGIN_URL . 'assets/css/min/tiny.min.css?' . $ver;
$mce_css .= ',';

return $mce_css;
}

}

new TinyBootstrapExtends();

}
Loading

0 comments on commit 5ff681a

Please sign in to comment.