LIB-> //-------------------------------- // INIT private $initiated = false; private $is__wp_register_scripts__admin = false; private $LIB; function init() { if ($this->initiated) {return;} $this->initiated = true; if (!current_user_can('administrator')) {return;} // load base $this->load_LIB(); $this->LIB->is_api_get = false; $this->LIB->process__SERVER(); $this->LIB->process__GET(); $this->LIB->load_VARS__base(); $this->LIB->load_LANG(); $this->wp_register_scripts__admin(); if ($this->LIB->process__POST()!==true) {return;} if ($this->LIB->access_check__PAGE()!==true) {return;} // load next $this->LIB->load_VARS__other(); $this->LIB->load_SETTINGS(); $this->LIB->load_PREMIUM(); $this->LIB->detect_page(); // echo("\n
".__METHOD__."::".__LINE__."\n".'WP debug error_get_last'."\n");print_r(error_get_last(),true);echo("
\n\n");wp_die(); } private function load_LIB($registry=false) { // WP $lib = 'libs/lib'; $lib_class = 'LibAIGenProTools1764792494705'; $path_base = realpath(dirname(__FILE__) . '/..'); $lib_file = ($path_base.'/'.str_replace('\\', '/', strtolower($lib)).'.php'); require_once($lib_file); $lib_load = $lib_class; $this->LIB = new $lib_load(); } //-------------------------------- // WP register scripts function wp_register_scripts__admin() { if ($this->is__wp_register_scripts__admin) {return;} $this->is__wp_register_scripts__admin = true; // admin plugin settings add_action( 'admin_init', function($admin_bar) { // as one field (json, base64) // @codingStandardsIgnoreStart register_setting($this->LIB->VARS['name']['_code-'].'settings-group', $this->LIB->VARS['name']['_code-'].'settings', array( 'type' => 'string', 'sanitize_callback' => array($this->LIB, 'wp_register_setting__sanitize_text_field'), 'default' => NULL, )); // @codingStandardsIgnoreEnd }); // admin menu add_action( 'admin_menu', function($admin_bar) { // top // admin_bar_menu $this->LIB->VARS['adminbar_btn_main'] = []; add_action('admin_bar_menu', function($admin_bar){ $admin_bar->add_node([ 'id' => $this->LIB->VARS['name']['_code'], 'title' => $this->LIB->get_tpl6('navs/'.'nav__adminbar_btn_main'), ]); }, 999); // side add_menu_page($this->LIB->VARS['name']['title'], $this->LIB->VARS['name']['title'], 'manage_options', $this->LIB->VARS['name']['code'].'-settings', array( $this->LIB, 'page__admin_settings' ), 'data:image/svg+xml;base64,' . base64_encode($this->LIB->get_lang('icon-module_logo-w'))); }); // plugins page add_filter( "plugin_action_links_".$this->LIB->VARS['path']['plugin_basename'], function($links) { // $links = array_reverse($links); array_push($links, 'Settings'); array_push($links, 'Get started'); if ( !$this->LIB->is_active($this->LIB->VARS['name']['code-premium-route']) ) { array_push($links, 'Get Premium'); } // $links = array_reverse($links); return $links; }); // ajax // xhr $arr = [ 'api', ]; foreach ($arr as $k_ => $l_) { add_action('wp_ajax_'.$this->LIB->VARS['name']['code_'].$l_, array($this, $l_)); } // cssjs $arr = []; $arr[$this->LIB->VARS['cssjs']['path']."AWIT_Core7/AWIT.Core7".$this->LIB->VARS['cssjs']['is_min_str_addon'].".css"] = 'css'; $arr[$this->LIB->VARS['cssjs']['path']."AWIT_Core7/AWIT.Core7".$this->LIB->VARS['cssjs']['is_min_str_addon'].".js"] = 'js'; $arr[$this->LIB->VARS['cssjs']['path']."fonts".$this->LIB->VARS['cssjs']['is_min_str_addon'].".css"] = 'css'; $arr[$this->LIB->VARS['cssjs']['path']."inject".$this->LIB->VARS['cssjs']['is_min_str_addon'].".css"] = 'css'; $arr[$this->LIB->VARS['cssjs']['path']."inject".$this->LIB->VARS['cssjs']['is_min_str_addon'].".js"] = 'js'; $this->LIB->add__cssjs($arr); } function wp_register_setting__sanitize_text_field($input) { return sanitize_text_field($input); } //-------------------------------- // PAGES // ACTIONS function api($p=[]) { if (!$this->initiated) {return;} $f = $this->LIB->process__func_name(__FUNCTION__); // $f['name'] //--- $this->LIB->is_api_get = true; if ($this->LIB->process__POST()!==true) {wp_die(__METHOD__.':'.__FUNCTION__.':'.__LINE__);} if ( empty($p) ) { $p = $this->LIB->request->post; } else { $p = func_get_args(); } $p = $this->LIB->process__func_params([ // 'is_post_check' => true, 'is_set_time_limit' => 7200, 'is_ignore_user_abort' => false, 'is_stream_start' => true, 'is_process__AC' => true, 'is_process__data' => true, 'is_return' => true, 'action_type' => '', ], $p); // $p['___'] //--- $res = []; $data = false; //--- // type filter by key if ( !in_array($p['action_type'],$this->LIB->VARS['xhr_get__access_arr']['base']) ) { $this->LIB->throw_new_log([ 'on_off' => 1, 'type' => 'critical_error', 'tags' => [ ($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''), __LINE__, '!access', ], 'is_noty' => true, 'click_close' => true, 'timeout' => 180000, 'title' => $this->LIB->get_lang('error-code-0'), 'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'', ]); } if ( $this->LIB->VARS['tmp'][$f['name']]['tmp_fname'] = $tmp_fname = $this->LIB->is_fname([$p['action_type']], $this) ) { if ($p['is_ignore_user_abort']) { ignore_user_abort(true); } if ($p['is_set_time_limit']!==false) { // @codingStandardsIgnoreStart set_time_limit($p['is_set_time_limit']); // @codingStandardsIgnoreEnd } if ($p['is_stream_start']) { $this->xhr_stream_start(); } $data = $this->LIB->$tmp_fname(); } else { $this->LIB->throw_new_log([ 'on_off' => 1, 'type' => 'critical_error', 'tags' => [ ($this->LIB->SETTINGS__get_item(['main','base','list','IS_DEV_MODE',])?$f['name']:''), __LINE__, '!access_f', ], 'is_noty' => true, 'click_close' => true, 'timeout' => 180000, 'title' => $this->LIB->get_lang('error-code-0'), 'id' => $this->LIB->VARS['name']['code-'].'log-'.$f['name'].'', ]); } //--- // res AC data key if ($p['is_process__data']) { if (is_string($data) || !isset($data['data'])) {$res['data'] = $data;} } // AC addon if ($p['is_process__AC']) { $res = array_merge($res, $this->LIB->process__AC()); } //--- // result // output if ($p['is_return']) { $this->LIB->output__xhr_get($res); } } private function xhr_stream_start() { // stream init @header('Content-Encoding: none'); // Disable gzip compression ob_end_flush(); // Stop buffer ob_implicit_flush(1); // Implicit flush at each output command // this is to make the buffer achieve the minimum size in order to flush data echo esc_html(str_repeat(' ',1024*64)); } }