name = plugin_basename(__FILE__);
$this->pre = strtolower(__CLASS__);
$this->version = '1.0.4.8';
$this->scripts = array(
'admin' => array(
$this->pre . '-interact' => array(
'src' => plugins_url('/js/interact.js', __FILE__),
'dependency' => 'jquery',
),
$this->pre . '-admin-bar' => array(
'src' => plugins_url('/js/admin-bar.js', __FILE__),
'dependency' => array('jquery', $this->pre . '-interact', 'jquery-ui-tooltip'),
),
$this->pre . '-admin' => array(
'src' => plugins_url('/js/admin.js', __FILE__),
'dependency' => array('jquery', $this->pre . '-interact', 'accordion', 'postbox', 'jquery-ui-draggable', 'jquery-ui-sortable', 'jquery-ui-slider', 'jquery-ui-tooltip'),
),
$this->pre . '-menu' => array(
'src' => plugins_url('/js/menu.js', __FILE__),
'dependency' => $this->pre . '-interact',
),
),
$this->pre . '-interact' => array(
'src' => plugins_url('/js/interact.js', __FILE__),
'dependency' => 'jquery',
),
$this->pre . '-admin-bar' => array(
'src' => plugins_url('/js/admin-bar.js', __FILE__),
'dependency' => array('jquery', $this->pre . '-interact', 'jquery-ui-tooltip'),
),
);
$jquery_ui = "http" . (is_ssl() ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css";
$font = "http" . (is_ssl() ? "s" : "") . "://fonts.googleapis.com/css?family=Yanone+Kaffeesatz";
$this->styles = array(
'admin' => array(
'jquery-style-css' => $jquery_ui,
$this->pre . '-admin-css' => array(
'src' => plugins_url('/css/admin.css', __FILE__),
'dependency' => 'jquery-style-css'
),
'Yanone-Kaffeesatz' => $font
),
'jquery-style-css' => $jquery_ui,
$this->pre . '-admin-css' => array(
'src' => plugins_url('/css/admin.css', __FILE__),
'dependency' => 'jquery-style-css'
),
'Yanone-Kaffeesatz' => $font
);
//on - disabled
$this->options = array(
'debugging' => true,
'settings_options' => array(
//welcome message
'welcome_message' => "
Welcome to your simple backend! You can get to editing via the menu in the lower right corner. ",//dashboard admin menu
//dashboard admin menu
'menu' => array(
'0' => array(
'name' => 'Dashboard',
'orig' => 'Dashboard',
'index' => '0',
'link' => 'index.php',
'type' => 'menu',
'submenu' => array(
array(
'show' => '0',
'name' => 'Home',
'link' => 'index.php',
),
array(
'show' => '0',
'name' => 'Updates',
'link' => 'update-core.php',
)
),
'allow' => 'on',
'instructions' => ''
),
'1' => array(
'name' => 'Edit All Pages',
'orig' => 'Pages',
'index' => '1',
'link' => 'edit.php?post_type=page',
'type' => 'menu',
'submenu' => array(
array(
'show' => '0',
'name' => 'All Pages',
'link' => 'edit.php?post_type=page',
),
array(
'show' => '0',
'name' => 'Add New',
'link' => 'post-new.php?post_type=page'
),
),
'allow' => '',
'instructions' => 'Select to edit any page on the frontend. Note some pages will be present that are placeholders for other site functions and pages may also contain [shortcodes] in brackets for special functions.'
)
),
//dashboard widgets
'rss_title' => 'Web Design, Marketing and WordPress…',
'rss_url' => 'https://twitrss.me/twitter_user_to_rss/?user=johnathandotpro',
//toggles
'admin_hidden' => array(
'role' => 'editor',
'password' => 'on'
),
'editor_hidden' => array(
'gallery' => 'on',
'featured_image'=> 'on'
),
/*
* media gallery options
* will sync after saving settings
*/
'image_default_link_type' => 'none',
'image_default_size' => 'medium',
'image_default_align' => 'center',
'sanitized_links' => array(),
'plugins' => array(),
'email' => array(
'from' => array()
)
),
);
$this->menu_pages = array(
'A Simple Backend' => array(
'capability' => 'edit_dashboard',
'position' => '1',
'func' => 'settings',
),
);
$this->actions = array(
'admin_notices' => false,
'admin_init' => false,
'init' => array(
'init' => array(
'priority' => 99999999999
)
),
'welcome_panel' => false,
'admin_head' => 'head',
'wp_head' => 'head',
'admin_bar_menu' => array(
'admin_bar_menu' => array(
'priority' => 99999999999
),
),
'add_meta_boxes' => array(
'add_meta_boxes' => array(
'priority' => 99999999999
)
),
'do_meta_boxes' => array(
'disable_collapse' => array(
'priority' => 1,
'params' => 3
),
'remove_widgets' => array(
'priority' => 99999999999
)
),
'wp_dashboard_setup' => 'setup_widgets',
'login_head' => false,
'login_form' => false,
'login_footer' => false,
'admin_footer' => false,
'edit_form_top' => false,
'publish_product' => array(
'publish_product' => array(
'priority' => 99999999999,
'params' => 2
)
),
'edit_form_before_permalink' => false,
'manage_product_posts_custom_column'=> false,
'load-index.php' => 'show_welcome_panel',
'wp_after_admin_bar_render' => 'admin_bar',
'wp_logout' => false,
'wp_login' => false,
'wp_footer' => false,
'wp_ajax_login_logo_upload' => 'login_logo_upload',
'wp_ajax_nopriv_login_logo_upload' => 'login_logo_upload',
'wp_ajax_add_menu' => 'add_menu',
'wp_ajax_nopriv_add_menu' => 'add_menu',
'wp_ajax_add_link' => 'add_link',
'wp_ajax_nopriv_add_link' => 'add_link',
'wp_ajax_add_page' => 'add_page',
'wp_ajax_nopriv_add_page' => 'add_page',
'wp_ajax_add_media' => 'add_media',
'wp_ajax_nopriv_add_media' => 'add_media',
'wp_ajax_basic' => 'wp_logout',
'wp_ajax_nopriv_basic' => 'wp_logout',
);
$this->filters = array(
'login_redirect' => array(
'login_redirect' => array(
'priority' => 1,
'params' => 3
)
),
'screen_options_show_screen' => array(
'remove_screen_options' => array(
'params' => 2
)
),
'contextual_help' => array(
'remove_help' => array(
'params' => 3
)
),
'page_row_actions' => array(
'remove_row_actions' => array(
'priority' => 99999999999,
'params' => 2
)
),
'post_row_actions' => array(
'remove_row_actions' => array(
'priority' => 99999999999,
'params' => 2
)
),
'tag_row_actions' => array(
'remove_row_actions' => array(
'priority' => 99999999999,
'params' => 2
)
),
'manage_posts_columns' => array(
'remove_columns' => array(
'priority' => 99999999999,
'params' => 2
)
),
'manage_pages_columns' => array(
'remove_columns' => array(
'priority' => 99999999999,
'params' => 2
)
),
'plugin_action_links_' . $this->name => 'plugin_action_links',
'user_can_richedit' => false,
'wp_default_editor' => false,
'gettext' => array(
'rename_media_button' => array(
'params' => 2,
'priority' => 99999999999
)
),
'media_view_strings' => array(
'remove_media_strings' => array(
'priority' => 99999999999,
'params' => 2
)
),
'wp_insert_post_data' => array(
'wp_insert_post_data' => array(
'priority' => 99999999999,
'params' => 2
)
),
'wp_mail_from' => array(
'wp_mail_from' => array(
'priority' => 99999999999
)
),
'wp_mail_from_name' => array(
'wp_mail_from_name' => array(
'priority' => 99999999999
)
),
'woocommerce_product_data_tabs' => array(
'woocommerce_product_data_tabs' => array(
'priority' => 99999999999
)
),
'manage_product_posts_columns' => array(
'manage_product_posts_columns' => array(
'priority' => 99999999999
)
),
'the_seo_framework_show_seo_column' => array(
'the_seo_framework_show_seo_column' => array(
'priority' => 99999999999
)
)
);
// list of pages (current_screen ids) affected by metabox toggle
$this->widget_exempt = array('blogging', 'dashboard', 'page', 'post', 'product', 'slideshow', 'wysiwyg-widget', 'hrf_faq', 'bne_testimonials');
//register the plugin and init assets
$this->register_plugin($this->name, __FILE__, true);
if(! is_array($this->options['settings_options']['plugins'])) {
$this->options['settings_options']['plugins'] = array();
}
//get mode status
$this->the_advance();
if($this->options['settings_options']['rss_url'] == 'https://bitly.com/u/johnathanevans.rss' // v1.0.2.3 rss hotfix
|| $this->options['settings_options']['rss_url'] == 'https://queryfeed.net/tw?q=%40evanspress') { // v1.0.3.1 rss hotfix
$this->options['settings_options']['rss_url'] = 'https://twitrss.me/twitter_user_to_rss/?user=johnathandotpro';
$this->update_option('rss_url', 'https://twitrss.me/twitter_user_to_rss/?user=johnathandotpro');
}
// v1.0.2.5 rss title hotfix temp
if($this->options['settings_options']['rss_title'] == 'Tips from Johnathan Evans and Evans Press…') {
$this->options['settings_options']['rss_title'] = 'Web Design, Marketing and WordPress…';
$this->update_option('rss_title', 'Web Design, Marketing and WordPress…');
}
//get Simplified Product
if(empty($this->advance) && class_exists('Simplified')) {
$simplified_product = new Simplified(array());
}
ksort($this->options['settings_options']['menu']);
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
//export
if(! empty($_GET['action']) && $_GET['action'] == 'export' && $this->pre == str_replace('-', '', $_GET['page'])) {
$output = json_encode($this->options['settings_options'], JSON_PRETTY_PRINT);
$filename = "asimplebackend-settings-" . date("m-d-Y") . ".json";
if($output !== false) {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Length: " . strlen($output) . ";");
header("Content-Disposition: attachment; filename=" . $filename);
header("Content-Type: text/plain; ");
header("Content-Transfer-Encoding: binary");
echo $output;
exit;
}
}
}
public function the_seo_framework_show_seo_column($bool) { //remove The SEO Framework Page/Post column
if(empty($this->advance) && empty($this->options['settings_options']['plugins']['theseoframework'])) {
return false;
}
return $bool;
}
public function deactivate() {
if(! empty($_GET['purge'])) {
$this->deactivation_hook();
$this->wp_logout();
}
}
public function admin_bar_menu($wp_admin_bar) {
if(! empty($this->advance)) {
$href = $_SERVER['REQUEST_URI'];
if(empty($_GET)) {
$href .= "?";
} else {
$href .= "&";
}
$href .= "a-simple-backend-mode=basic";
$wp_admin_bar->add_node(array(
'id' => 'backend-basic',
'title' => 'A Simple Backend',
'href' => $href,
));
}
}
public function admin_notices() {
global $current_user, $current_screen;
$dismiss = '';
if(! empty($_GET)) {
$dismiss = http_build_query($_GET);
}
if(! empty($dismiss)) {
$dismiss .= '&simple_backend_notice=0';
} else {
$dismiss = 'simple_backend_notice=0';
}
$data = array(
'link' => admin_url("admin.php?page=a-simple-backend"),
'dismiss' => '?' . $dismiss,
);
if(! get_user_meta($current_user->ID, $this->pre . '-notice') && current_user_can('administrator')) {
$this->render('notice', $data, true, 'admin');
}
}
public function admin_init() {
global $current_user;
//import
if(! empty($_FILES['file']) && $this->pre == str_replace('-', '', $_GET['page'])) {
$success = false;
$upload = wp_handle_upload($_FILES['file'], array('test_form' => false, 'test_type' => false, 'action' => $this->url));
if($upload && ! isset($upload['error'])) {
$content = file_get_contents($upload['file']);
if(! empty($content) && $opts = json_decode($content, true)) {
$this->options['settings_options'] = $opts;
foreach($opts as $name => $value) {
if($name == 'menu' && is_array($value)) {
$value = $this->sanitize_menu($value);
}
$this->update_option($name, $value);
}
$success = true;
}
}
if(! $success) {
$this->render_err('Import failed');
}
//remove file to reduce clutter
unlink($upload['file']);
}
//set notice
if(isset($_GET['simple_backend_notice']) && '0' == $_GET['simple_backend_notice']) {
add_user_meta($current_user->ID, $this->pre . '-notice', 'true', true);
}
}
public function init() {
if(empty($this->advance)) {
if(! empty($_GET['post_type'])) {
if($_GET['post_type'] != 'page' && $_GET['post_type'] != 'post') {
return;
}
} elseif(! empty($_GET['post']) && ! empty($_GET['action']) && $_GET['action'] == 'edit') {
$post = get_post($_GET['post']);
if($post->post_type != 'post' && $post->post_type != 'page') {
return;
}
}
//remove WP QUADS init
//Quads_Meta_Box->save causes nonce failure on quads_config_nonce by quads_config
remove_action('load-post.php', 'quads_load_meta_box');
remove_action('load-post-new.php', 'quads_load_meta_box');
show_admin_bar(false);
}
}
public function the_advance() {
global $current_user;
$this->advance = 0;
if(! empty($_GET['a-simple-backend-mode'])) {
$request = explode("?", $_SERVER['REQUEST_URI'])[0];
$gets = $_GET;
unset($gets['a-simple-backend-mode']);
$gets = array_filter($gets);
switch($_GET['a-simple-backend-mode']) {
case 'basic':
$this->wp_logout();
break;
case 'advance':
setcookie($this->pre . '-mode', 1, 0, '/');
break;
}
if(! empty($gets)) {
$request .= '?' . http_build_query($gets);
}
header('Location:' . $request); //wp_redirect & wp_safe_redirect does not work :(
exit();
}
if(! empty($_COOKIE[$this->pre . '-mode'])) {
$this->advance = 1;
}
}
public function head() {
if(is_user_logged_in()) {
if (empty($this->advance) && is_admin()) {
global $current_screen;
//remove on WooCommerce Product Editor
if(is_object($current_screen) && $current_screen->id == 'product' && empty($this->options['settings_options']['plugins']['woocommerce'])) {
remove_action('media_buttons', 'media_buttons');
}
//remove Gravity Forms Add Form button on Add Post & Page
if(empty($this->options['settings_options']['plugins']['gravity_forms'])) {
//Gravity Forms 1.9.8.5 or earlier
remove_action('media_buttons', array('RGForms', 'add_form_button'), 20);
//Gravity Forms 1.9.19 [May 5 2016]
remove_action('media_buttons', array('GFForms', 'add_form_button'), 20);
}
//remove Insert Slideshow from Add Post & Page
if(empty($this->options['settings_options']['plugins']['slideshow'])) {
remove_action('media_buttons', array('SlideshowPluginShortcode', 'shortcodeInserter'), 11);
}
}
$data = array(
'exempt' => $this->widget_exempt,
'mode' => empty($this->advance) ? 0 : 1,
'flushed' => isset($_GET['cache_flushed']) ? 1 : 0
);
$this->render('head', $data, true, 'admin');
}
}
public function remove_media_strings($strings) {
if(empty($this->advance)) {
$editor = $this->options['settings_options']['editor_hidden'];
if (!empty($editor['featured_image']) && $editor['featured_image'] == "on") {
$strings['setFeaturedImageTitle'] = false;
}
if (!empty($editor['gallery']) && $editor['gallery'] == "on") {
$strings['createGalleryTitle'] = false;
}
}
return $strings;
}
public function login_redirect($redirect_to, $requested_redirect_to, $user) {
if(! is_wp_error($user)) {
//remove Buddpress Login Redirect Hooks
if (empty($this->options['settings_options']['plugins']['buddypress_login_redirect']) && in_array('administrator', $user->roles)) {
remove_filter("login_redirect", "bp_login_redirection", 100);
remove_action('wp_logout', 'blr_logout_redirect');
$redirect_to = admin_url();
}
}
return $redirect_to;
}
public function wp_logout() {
setcookie($this->pre . '-mode', 0, time() - 3600, '/');
}
public function wp_login() {
$this->wp_logout();
}
public function wp_footer() {
global $show_admin_bar;
if(! $show_admin_bar && empty($this->advance)) {
$this->admin_bar();
}
}
public function woocommerce_product_data_tabs($product_data_tabs) {
if(empty($this->advance) && empty($this->options['settings_options']['plugins']['woocommerce'])) {
/*$new_tabs = array();
foreach ($product_data_tabs as $id => $attr) {
if ($id == 'general' || $id == 'attribute') {
$new_tabs[] = $product_data_tabs[$id];
}
}
return $new_tabs; */
if(class_exists('Simplified')) {
$product_data_tabs['variations']['class'][] = 'show_if_simplified_product';
}
}
return $product_data_tabs;
}
public function manage_product_posts_columns($columns) {
//remove woocommerce tag, featured, and type columns on product list
unset($columns['product_tag']);
unset($columns['featured']);
unset($columns['product_type']);
if(empty($this->advance)) {
$columns['actions'] = 'Actions';
}
return $columns;
}
public function edit_form_before_permalink($post) {
global $wp_meta_boxes;
$submitdiv = false;
foreach($wp_meta_boxes[$post->post_type] as $context => $priorities) {
foreach($priorities as $priority => $metaboxes) {
if(isset($metaboxes['submitdiv']) && $metaboxes['submitdiv'] !== false) {
$submitdiv = true;
break 2;
}
}
}
// only render when submitdiv isn't around
if(empty($this->advance) && ! $submitdiv) {
$this->render('titlewrap', array(
'post' => $post
));
}
}
public function manage_product_posts_custom_column($column) {
global $post, $the_product;
if(empty($this->advance) && $column == 'actions') :
?>
advance)) {
$settings['defaultProps'] = array(
'link' => $this->options['settings_options']['image_default_link_type'],
'align' => $this->options['settings_options']['image_default_align'],
'size' => $this->options['settings_options']['image_default_size'],
);
}
return $settings;
}
public function rename_media_button($translation, $text) {
global $current_screen;
if (empty($this->advance)
&& is_admin()) {
$editor = $this->options['settings_options']['editor_hidden'];;
if($text == 'Add Media' && empty($editor['media_name'])) {
return 'Add Photos';
}
}
return $translation;
}
public function user_can_richedit() {
if(empty($this->advance)) {
if (empty($this->options['settings_options']['richeditor'])) {
return true;
}
return false;
}
return true;
}
public function wp_default_editor($editor) {
if(empty($this->advance)) {
if (!empty($this->options['settings_options']['richeditor']) && $this->options['settings_options']['richeditor'] == "on") {
return $editor;
}
return 'tinymce';
}
return $editor;
}
public function plugin_action_links($links) {
$links['settings'] = 'Settings ';
$links['purge'] = str_replace('>Deactivate<', '>Uninstall<', str_replace('action', 'purge=1&action', $links['deactivate']));
return $links;
}
public function admin_bar() {
global $_parent_pages;
if(is_user_logged_in()) {
global $wp_admin_bar, $menu, $submenu, $current_screen, $wp_the_query;
$all_caps = array();
foreach(wp_get_current_user()->allcaps as $cap => $val) {
$all_caps[] = $cap;
}
$capabilities = get_role($this->options['settings_options']['admin_hidden']['role']);
$allow = true;
foreach($capabilities->capabilities as $cap => $val) {
if(! in_array($cap, $all_caps)) {
$allow = false;
break;
}
}
$mode = '';
$hmenu = $this->sanitize_menu($this->options['settings_options']['menu']);
if (!empty($hmenu)) {
global $_sanitized_links;
$_sanitized_links = $this->options['settings_options']['sanitized_links'];
if (empty($_sanitized_links)) {
$_sanitized_links = array();
}
//remove inaccessible items
foreach ($hmenu as $key => $item) {
if (!$allow && empty($item['allow'])) {
unset($hmenu[$key]);
continue;
}
if ($item['type'] == 'menu') {
foreach ($menu as $i) {
if ($i[2] == $item['link']) {
if (current_user_can($i[1])) {
if (!empty($item['submenu'])) {
foreach ($submenu as $parent => $s) {
if ($parent == $item['link']) {
foreach ($item['submenu'] as $index => $sub) {
if (empty($sub['show'])) {
unset($item['submenu'][$index]);
continue;
}
foreach ($s as $subitem) {
if ($subitem[2] == $sub['link'] && !current_user_can($subitem[1])) {
unset($item['submenu'][$index]);
break;
}
}
}
}
}
$hmenu[$key]['submenu'] = array_filter($item['submenu']);
}
} else {
unset($hmenu[$key]);
}
break;
}
}
}
if ($item['type'] == 'toplink') {
foreach ($submenu as $parent => $s) {
$break = false;
foreach ($s as $subitem) {
if ($subitem[2] == $item['link'] && !current_user_can($subitem[1])) {
unset($hmenu[$key]);
$break = true;
break;
}
}
if ($break) {
break;
}
}
}
if (($item['type'] == 'page' && !current_user_can('edit_pages')) || ($item['type'] == 'media' && !current_user_can('edit_posts'))) {
unset($hmenu[$key]);
}
}
//remove empty elements
$hmenu = array_filter($hmenu);
//resolve links
foreach ($hmenu as $key => $item) {
switch ($item['type']) {
case 'menu':
if (!empty($item['submenu'])) {
foreach ($item['submenu'] as $index => $sub) {
if (empty($sub['show'])) {
unset($item['submenu'][$index]);
} else {
$item['submenu'][$index]['link'] = $this->sanitize_link($sub['link'], 'toplink');
}
}
$hmenu[$key]['submenu'] = array_filter($item['submenu']);
}
case 'toplink':
$hmenu[$key]['link'] = $this->sanitize_link($item['link'], $item['type']);
break;
default:
$hmenu[$key]['link'] = $this->sanitize_link($item['link'], $item['type']);
break;
}
//cannot sanitize link
if ($hmenu[$key]['link'] === false) {
unset($hmenu[$key]);
}
}
if (is_admin()) {
//save sanitized links
$this->update_option('sanitized_links', $_sanitized_links);
}
//remove empty elements
$hmenu = array_filter($hmenu);
} else {
$hmenu = array();
}
$link = "";
$label = "";
$post = false;
if ($allow && (current_user_can('edit_pages') || current_user_can('edit_products'))) { //ensure user is allowed to edit pages
if (is_admin()) {
$post = get_post();
} else {
$post = $wp_the_query->get_queried_object();
}
if (!empty($post->ID)) {
$post_type_object = get_post_type_object($post->post_type);
//check if in admin and editing
if ((!empty($current_screen)
&& $current_screen->base == "post"
&& $current_screen->action != "add")
|| !is_admin()
) {
if (is_admin()) {
$link = set_url_scheme(get_permalink($post->ID));
$label = "View";
} else {
$link = admin_url("post.php?post=" . $post->ID . "&action=edit");
$label = "Edit";
}
$label .= " " . ucwords($post->post_type);
} else {
$post = false;
}
} else {
$post = false;
}
}
$mode = $_SERVER['REQUEST_URI'];
$query = explode("?", $mode);
$get = false;
if (!empty($query) && count($query) > 1) {
$query = $query[1];
$get = array_filter(explode("&", $query));
}
if (empty($get)) {
if (substr($mode, -1) != "?") {
$mode .= "?";
}
} else {
$mode .= "&";
}
if (empty($this->advance)) {
$mode .= "a-simple-backend-mode=advance";
} else {
$mode .= "a-simple-backend-mode=basic";
}
$permalink = '';
if(! is_admin()) {
$permalink = get_permalink();
}
$gd = $wpaas = $kinsta = $wpcycle = '';
if(class_exists('GD_System_Plugin_Command_Controller') && ! isset($this->options['settings_options']['plugins']['godaddy'])) {
$gd = home_url() . '?cache_flushed=&GD_COMMAND=FLUSH_CACHE&GD_NONCE=' . wp_create_nonce('GD_FLUSH_CACHE');
}
if(class_exists('WPaaS\\Cache') && ! isset($this->options['settings_options']['plugins']['godaddy'])) {
$wpaas = home_url() . '?cache_flushed=&wpaas_action=flush_cache&wpaas_nonce=' . wp_create_nonce('wpaas_flush_cache');
}
if(class_exists('Kinsta\KinstaCache') && ! isset($this->options['settings_options']['plugins']['kinsta'])) {
$kinsta = wp_nonce_url(admin_url('admin-ajax.php?action=kinsta_clear_cache_all&source=adminbar'), 'kinsta-clear-cache-all', 'kinsta_nonce');
}
if(class_exists('wpcyclengxc_Admin') && ! isset($this->options['settings_options']['plugins']['wpcycle'])) {
$wpcycle = admin_url(sprintf("/admin-ajax.php?action=flushcache&redirect_to=%s&nonce=%s", home_url() . '?cache_flushed', wp_create_nonce("flushcache")));
}
$this->render('admin-bar', array(
'allow' => $allow,
'menu' => $hmenu,
'gd' => $gd,
'wpaas' => $wpaas,
'kinsta' => $kinsta,
'wpcycle' => $wpcycle,
'logout' => wp_logout_url($permalink),
'post' => $post,
'link' => $link,
'label' => $label,
'mode' => $mode
), true, 'admin');
if (empty($this->advance)) {
$this->admin_aesthetics();
}
}
}
public function remove_help($old_help, $screen_id, $screen) {
if (empty($this->advance)) {
$screen->remove_help_tabs();
}
return $old_help;
}
public function remove_row_actions($actions, $post) {
global $current_screen;
if (empty($this->advance) && $current_screen->base != 'edit-tags') {
return array();
}
return $actions;
}
public function remove_columns($columns) {
global $current_screen;
if(empty($this->advance)) {
if($current_screen->id == 'edit-post') {
return array('cb' => '', 'title' => 'Title');
} else {
return array('title' => 'Title');
}
}
return $columns;
}
public function remove_screen_options() {
if (empty($this->advance)) {
return false;
}
return true;
}
public function show_welcome_panel() {
$id = get_current_user_id();
if (!get_user_meta($id, 'show_welcome_panel', true)) {
update_user_meta($id, 'show_welcome_panel', 1);
}
}
public function settings_options($options) {
return $options;
}
public function settings() {
global $wp_roles, $menu, $submenu;
$menu_items = array();
foreach($menu as $key => $item) {
$menu_items[$key] = $item;
$menu_items[$key][0] = preg_replace('/\s*(\)/i', '', $item[0]); //remove notification html tags
$menu_items[$key]['submenu'] = array();
foreach($submenu as $parent => $sub) {
if($item[2] == $parent) {
foreach($sub as $index => $values) {
$sub[$index][0] = preg_replace('/\s*(\)/i', '', $values[0]);
}
$menu_items[$key]['submenu'] = $sub;
break;
}
}
}
//end
//rss
$rss = $this->options['settings_options']['rss_url'];
$default_rss = get_bloginfo('rss2_url');
if(empty($rss)) {
$rss = $default_rss;
}
//end
$query_images = new WP_Query(array(
'post_type' => 'attachment',
'post_mime_type' =>'image',
'post_status' => 'inherit',
'posts_per_page' => 5,
'orderby' => 'rand'
));
$media = $query_images->posts;
foreach($media as $key => $item) {
if(empty($item->post_title)) {
$media[$key]->post_title = basename($item->guid);
}
}
$sitename = strtolower($_SERVER['SERVER_NAME']);
if(substr( $sitename, 0, 4 ) == 'www.') {
$sitename = substr($sitename, 4);
}
$from_email = 'wordpress@' . $sitename;
$this->render('settings', array(
'welcome_message' => $this->options['settings_options']['welcome_message'],
'menu' => $menu_items,
'page' => get_pages(array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'post_type' => 'page',
'post_status' => 'publish'
)),
'media' => $media,
'default_rss' => $default_rss,
'rss' => $rss,
'rss_title' => $this->options['settings_options']['rss_title'],
'admin_hidden' => $this->options['settings_options']['admin_hidden'],
'editor_hidden' => $this->options['settings_options']['editor_hidden'],
'alignment' => $this->options['settings_options']['image_default_align'],
'link' => $this->options['settings_options']['image_default_link_type'],
'size' => $this->options['settings_options']['image_default_size'],
'roles' => $wp_roles->roles,
'show' => $this->options['settings_options']['menu'],
'plugins' => $this->options['settings_options']['plugins'],
'email' => $this->options['settings_options']['email'],
'email_placeholder' => array(
'from' => array(
'address' => apply_filters('wp_mail_from', $from_email),
'name' => apply_filters('wp_mail_from_name', 'Wordpress')
)
),
'active_plugins' => get_option('active_plugins')
), true, 'admin');
}
public function welcome_panel() {
if(empty($this->advance)) {
$this->render('welcome', array(
'pre' => $this->pre,
'welcome_message' => $this->options['settings_options']['welcome_message'],
), true, 'admin');
}
}
public function setup_widgets() {
if(empty($this->options['settings_options']['admin_hidden']['rss'])) {
$this->wp_add_dashboard_widget($this->pre . 'posts-feed', $this->options['settings_options']['rss_title'], 'posts_feed');
}
}
public function add_meta_boxes() {
global $current_screen, $post_type, $post;
if(empty($this->advance)) {
if($current_screen->id == 'product' && empty($this->options['settings_options']['plugins']['product'])) {
//reset metabox positions
delete_user_meta(get_current_user_id(), 'meta-box-order_product');
/** WooCommerce Metaboxes */
remove_meta_box( 'product_catdiv', 'product', 'side' );
$cats = get_categories(array('taxonomy' => 'product_cat', 'hide_empty' => false));
if(! empty($cats)) {
add_meta_box( 'product_catdiv', 'Categories...', 'post_categories_meta_box', 'product', 'side', 'high', array('taxonomy' => 'product_cat') );
}
add_meta_box('woocommerce-instruction-box', __ ('Basic Instructions…'), array($this, 'woocommerce_instruction_box'), 'product', 'normal', 'high');
if(class_exists('WC_Meta_Box_Product_Data')) {
remove_meta_box('woocommerce-product-data', 'product', 'normal');
add_meta_box( 'woocommerce-product-data', __( 'Options...', 'woocommerce' ), 'WC_Meta_Box_Product_Data::output', 'product', 'normal', 'default' );
}
remove_meta_box( 'postimagediv', 'product', 'normal' );
add_meta_box('postimagediv', 'Main Photo...', 'post_thumbnail_meta_box', 'product', 'normal', 'low');
if (class_exists('WC_Meta_Box_Product_Images')) {
remove_meta_box('woocommerce-product-images', 'product', 'normal');
add_meta_box('woocommerce-product-images', __('More Photos...', 'woocommerce'), 'WC_Meta_Box_Product_Images::output', 'product', 'normal', 'low');
}
}
if($current_screen->id == 'slideshow' && empty($this->options['settings_options']['plugins']['slideshow'])) {
//reset metabox positions
delete_user_meta(get_current_user_id(), 'meta-box-order_slideshow');
//vital nonce
add_meta_box('slideshow-hidden-nonce', 'Nonce', array($this, 'add_slideshow_nonce'), 'slideshow', 'normal', 'low');
}
if($current_screen->id == 'post' && empty($this->options['settings_options']['plugins']['blogging'])) {
$post_type_object = get_post_type_object($post_type);
$thumbnail_support = current_theme_supports('post-thumbnails', $post_type) && post_type_supports($post_type, 'thumbnail');
if($thumbnail_support && current_user_can('upload_files')) {
remove_meta_box('postimagediv', 'blogging', 'side');
add_meta_box('postimagediv', esc_html($post_type_object->labels->featured_image), 'post_thumbnail_meta_box', null, 'side', 'low');
}
foreach(get_object_taxonomies($post) as $tax_name) {
$taxonomy = get_taxonomy($tax_name);
if(! $taxonomy->show_ui || false === $taxonomy->meta_box_cb) {
continue;
}
$label = $taxonomy->labels->name;
if(! is_taxonomy_hierarchical($tax_name)) {
$tax_meta_box_id = 'tagsdiv-' . $tax_name;
} else {
$tax_meta_box_id = $tax_name . 'div';
}
remove_meta_box($tax_meta_box_id, 'blogging', 'side');
add_meta_box($tax_meta_box_id, $label, $taxonomy->meta_box_cb, null, 'side', 'low', array('taxonomy' => $tax_name));
}
//replace submitdiv ID with another
$publish_callback_args = null;
if(post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status ) {
$revisions = wp_get_post_revisions($post->ID);
// We should aim to show the revisions meta box only when there are revisions.
if(count($revisions) > 1) {
reset($revisions); // Reset pointer for key()
$publish_callback_args = array('revisions_count' => count($revisions), 'revision_id' => key($revisions));
}
// only appear on published posts
//add_meta_box('submitdiv_blogging', _('Publish'), 'post_submit_meta_box', null, 'side', 'low', $publish_callback_args);
}
}
}
}
public function add_slideshow_nonce() {
wp_nonce_field(SlideshowPluginSlideshowSettingsHandler::$nonceAction, SlideshowPluginSlideshowSettingsHandler::$nonceName);
}
public function disable_collapse($post_type, $context, $post) {
global $wp_meta_boxes;
$screen = get_current_screen();
$page = $screen->id;
if(isset($wp_meta_boxes[ $page ][ $context ])) {
foreach(array('high', 'sorted', 'core', 'default', 'low') as $priority) {
if(isset($wp_meta_boxes[ $page ][ $context ][ $priority ])) {
foreach ((array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box) {
if(false == $box || ! $box['title']) {
continue;
}
$this->add_filter("postbox_classes_{$page}_{$box['id']}", "__return_empty_array");
}
}
}
}
}
public function remove_widgets() {
if (empty($this->advance)) {
global $wp_meta_boxes, $current_screen;
// save to local variable to avoid interference with other usage(s)
$screen_id = $current_screen->id;
if($current_screen->id == 'post' && empty($this->options['settings_options']['plugins']['blogging'])) {
$screen_id = 'blogging';
}
if(! in_array($screen_id, $this->widget_exempt) || array_key_exists($screen_id, $this->options['settings_options']['plugins'])) {
return;
}
foreach ($wp_meta_boxes as $page => $widgets) {
foreach ($widgets as $context => $group) {
foreach ($group as $priority => $meta_boxes) {
foreach ($meta_boxes as $id => $meta_box) {
//don't remove category meta box on page/post when not empty
if($id == 'categorydiv') {
$cats = get_categories(array('taxonomy' => 'category', 'hide_empty' => false));
if ((! empty($cats) && count($cats) > 1) || $screen_id == 'blogging') {
continue;
}
}
//don't remove testimonial category meta box on BNE Testimonials when not empty
if($id == 'bne-testimonials-taxonomydiv') {
$cats = get_categories(array('taxonomy' => 'bne-testimonials-taxonomy', 'hide_empty' => false));
if (! empty($cats) && count($cats) > 1) {
continue;
}
}
if ($id == $this->pre . 'posts-feed'
|| $id == 'wpAutosinventory' //wp-autos plugin (unpublished)
|| $id == 'product_catdiv' //WooCommerce Product Categories Post Box
|| ($id == 'postimagediv' && $current_screen->id == 'product') //WooCommerce Product Image | Featured Image for others
|| ($id == 'postimagediv' && $current_screen->id == 'bne_testimonials') // BNE Testimonials Thumbnail | Featured Image for others
|| $id == 'woocommerce-product-images' //WooCommerce Product Gallery
|| $id == 'woocommerce-product-data' //WooCommerce Product Data
|| $id == 'woocommerce-instruction-box' //WooCommerce custom instruction box
|| $id == 'woocommerce-featured-box' //ASB WC featured checkbox
|| ($id == 'theseoframework-inpost-box' && ! empty($this->options['settings_options']['plugins']['theseoframework'])) //The SEO Framework Post Box
|| $id == 'slides-list' //slideshow slides list
|| $id == 'slideshow-hidden-nonce' //custom slideshow metabox containing nonce
// Blogging
|| ($id == 'submitdiv_blogging' && $screen_id == 'blogging')
|| ($id == 'postimagediv' && $screen_id == 'blogging')
|| ($id == 'tagsdiv-post_tag' && $screen_id == 'blogging')
// Blogging END
) {
continue;
} else {
remove_meta_box($id, $page, $context);
}
}
}
}
}
}
}
public function posts_feed() {
$rss = $this->options['settings_options']['rss_url'];
$count = 0;
$items = array();
if(empty($rss)) {
$rss = get_bloginfo('rss2_url');
}
$feed = fetch_feed($rss);
if(! is_wp_error($feed)) {
$count = $feed->get_item_quantity(10);
$items = $feed->get_items(0, $count);
}
$this->render('feed', array(
'pre' => $this->pre,
'count' => $count,
'items' => $items,
), true, 'admin');
}
//Change login image
public function login_head() {
?>
options['settings_options']['admin_hidden']['password'])) {
$this->render('password');
}
}
public function login_footer() {
?>
id, $this->widget_exempt) && ! array_key_exists($current_screen->id, $this->options['settings_options']['plugins'])):
?>
id == 'post'):
?>
options['settings_options']['plugins']['blogging'])): ?>
options['settings_options']['plugins']['acf_better_search'])):
?>
id == 'hrf_faq' && empty($this->options['settings_options']['plugins']['hrf_faq'])):
?>
id == 'product' && empty($this->options['settings_options']['plugins']['product'])):
?>
id == 'slideshow' && empty($this->options['settings_options']['plugins']['slideshow'])):
?>
base != 'edit-tags' && $current_screen->id != 'edit-product' && $current_screen->id != 'edit-post' && $plugin_page != 'bsk-pdf-manager-pdfs'):
?>
plugins_url('/helpers/', __FILE__),
"upload_dir" => $upload_dir['path'] . '/',
"upload_url" => $upload_dir['url'] . '/',
"mkdir_mode" => 0777,
"delete_type" => 'POST',
"image_versions" => array(
'' => array(
// Automatically rotate images based on EXIF meta data:
'auto_orient' => true
),
'wp-login' => array(
'max_width' => 320,
'max_height' => 260
),
'wp-logo' => array(
'max_width' => 20,
'max_height' => 20
)
),
)
);
die();
}
public function sanitize_link($link, $type) {
// ** temporary **
// save sanitized links in global var
// assume links sanitized on admin side
global $menu, $submenu, $_sanitized_links;
$submenu_items = array();
switch($type) {
case 'menu':
if(is_admin()) {
$submenu_items = $submenu[$link];
if(! empty($submenu_items)) {
$submenu_items = array_values($submenu_items); // Re-index.
$menu_hook = get_plugin_page_hook($submenu_items[0][2], $link);
$menu_file = $submenu_items[0][2];
if (($pos = strpos( $menu_file, '?' )) !== false) {
$menu_file = substr($menu_file, 0, $pos);
}
if (! empty($menu_hook) || (('index.php' != $submenu_items[0][2]) && file_exists(WP_PLUGIN_DIR . "/" . $menu_file) && ! file_exists(ABSPATH . "/wp-admin/" . $menu_file))) {
$_sanitized_links[$link] = 'admin.php?page=' . $submenu_items[0][2];
} else {
$_sanitized_links[$link] = $submenu_items[0][2];
}
} else {
$menu_hook = get_plugin_page_hook($link, 'admin.php');
$menu_file = $link;
if (($pos = strpos($menu_file, '?')) !== false) {
$menu_file = substr($menu_file, 0, $pos);
}
if (! empty($menu_hook) || (('index.php' != $link) && file_exists(WP_PLUGIN_DIR . "/" . $menu_file) && ! file_exists(ABSPATH . "/wp-admin/" . $menu_file))) {
$_sanitized_links[$link] = 'admin.php?page=' . $link;
} else {
$_sanitized_links[$link] = $link;
}
}
$link = admin_url($_sanitized_links[$link]);
} else {
if(empty($_sanitized_links[$link])) {
return false;
} else {
$link = admin_url($_sanitized_links[$link]);
}
}
break;
case 'toplink':
if(is_admin()) {
$admin_is_parent = false;
$menu_hook = null;
$parent = null;
foreach ($submenu as $p => $group) {
foreach ($group as $sub) {
if ($sub[2] == $link) {
$parent = $p;
break;
}
}
}
$menu_hook = get_plugin_page_hook($link, $parent);
$menu_file = $link;
if (($pos = strpos($menu_file, '?')) !== false) {
$menu_file = substr($menu_file, 0, $pos);
}
$parent_menu_hook = get_plugin_page_hook($parent, 'admin.php');
$parent_menu_file = $parent;
if (!empty($parent_menu_hook) || (('index.php' != $parent) && file_exists(WP_PLUGIN_DIR . "/" . $parent_menu_file) && !file_exists(ABSPATH . "/wp-admin/" . $parent_menu_file))) {
$admin_is_parent = true;
}
if (!empty($menu_hook) || (('index.php' != $link) && file_exists(WP_PLUGIN_DIR . "/" . $menu_file) && !file_exists(ABSPATH . "/wp-admin/" . $menu_file))) {
if ((!$admin_is_parent && file_exists(WP_PLUGIN_DIR . "/" . $menu_file) && !is_dir(WP_PLUGIN_DIR . "/" . $parent)) || file_exists($menu_file)) {
$sub_item_url = add_query_arg(array('page' => $link), $parent);
} else {
$sub_item_url = add_query_arg(array('page' => $link), 'admin.php');
}
$_sanitized_links[$link] = esc_url($sub_item_url);
} else {
$_sanitized_links[$link] = $link;
}
$link = admin_url($_sanitized_links[$link]);
} else {
if(empty($_sanitized_links[$link])) {
return false;
} else {
$link = admin_url($_sanitized_links[$link]);
}
}
break;
case 'media':
case 'page':
$link = admin_url('post.php?post=' . $link . '&action=edit');
break;
}
return $link;
}
public function sanitize_menu($old_menu) {
global $menu, $submenu;
$upload_dir = wp_upload_dir();
if(! is_admin()) {
if(empty($menu) && file_exists($upload_dir['basedir'] . '/menu.json')) {
$menu = json_decode(file_get_contents($upload_dir['basedir'] . '/menu.json'));
}
if(empty($submenu) && file_exists($upload_dir['basedir'] . '/submenu.json')) {
$submenu = json_decode(file_get_contents($upload_dir['basedir'] . '/submenu.json'));
}
} else {
file_put_contents($upload_dir['basedir'] . '/menu.json', json_encode($menu));
file_put_contents($upload_dir['basedir'] . '/submenu.json', json_encode($submenu));
}
foreach($old_menu as $m => $i) {
$match = false;
switch($i['type']) {
case 'menu':
foreach ($menu as $item) {
if ($item[2] == $i['link']) {
$match = true;
break;
}
}
break;
case 'toplink':
foreach($submenu as $parent => $sub) {
if($match) {
break;
}
foreach($sub as $item) {
if($item[2] == $i['link']) {
$match = true;
break;
}
}
}
break;
case 'page':
case 'media':
if(get_post_status($i['link']) !== false) {
$match = true;
break;
}
break;
default:
$match = true;
break;
}
//does not exist
//remove from menu
if (!$match) {
unset($old_menu[$m]);
}
}
$new_menu = array_filter($old_menu);
$this->options['settings_options']['menu'] = $new_menu;
return $new_menu;
}
public function add_menu() {
if(! empty($_POST['menu'])) {
foreach($_POST['menu'] as $m) {
if(! empty($m['toplink'])) {//redirect to toplink
$this->toplink(array('name' => $m['name'], 'orig' => $m['orig'], 'index' => $m['index'], 'link' => $m['link']));
} else {
$s = unserialize(urldecode($m['submenu']));
$submenu = array();
foreach ($s as $index => $sub) {
if (!$index && strpos($m['link'], '.php') === false) {
continue;
}
$submenu[] = array(
'name' => stripslashes($sub[0]),
'link' => $sub[2],
'show' => 0,
);
}
$this->menu(array('name' => $m['name'], 'orig' => $m['orig'], 'index' => $m['index'], 'link' => $m['link'], 'submenu' => $submenu));
}
}
}
exit;
}
public function menu($data) {
$this->render('menu', $data, true, 'admin');
}
public function toplink($data) {
$this->render('toplink', $data, true, 'admin');
}
public function add_link() {
$this->link(array('name' => stripslashes($_POST['name']), 'link' => $_POST['link'], 'target' => $_POST['target'], 'index' => $_POST['index']));
exit;
}
public function link($data) {
$this->render('link', $data, true, 'admin');
}
public function add_page() {
if(! empty($_POST['page'])) {
foreach($_POST['page'] as $p) {
$this->page(array('name' => stripslashes($p['name']), 'orig' => $p['orig'], 'index' => $p['index'], 'link' => $p['link']));
}
}
exit;
}
public function page($data) {
$this->render('page', $data, true, 'admin');
}
public function add_media() {
if(! empty($_POST['media'])) {
foreach($_POST['media'] as $m) {
$this->media(array('name' => stripslashes($m['name']), 'orig' => $m['orig'], 'index' => $m['index'], 'link' => $m['link']));
}
}
exit;
}
public function media($data) {
$this->render('media', $data, true, 'admin');
}
public function admin_footer() {
if(empty($this->advance)) {
$this->render('footer', false, true, 'admin');
}
}
public function publish_product($ID, $post) {
if(empty($this->advance)) {
//add missing post meta to display at woocommerce shop
add_post_meta($ID, '_visibility', 'visible', true);
}
}
public function edit_form_top($post) {
if(empty($this->advance)) {
$plugins = get_option('active_plugins');
?>
advance)) {
$data['comment_status'] = 'open';
$data['ping_status'] = 'open';
if(! empty($_POST['asimplebackend-post-draft'])) {
$data['post_status'] = 'draft';
}
}
return $data;
}
public function wp_mail_from($address) {
if(isset($this->options['settings_options']['email']['from']['address'])) {
$trimmed = trim($this->options['settings_options']['email']['from']['address']);
if(! empty($trimmed)) {
return $trimmed;
}
}
return $address;
}
public function wp_mail_from_name($name) {
if(isset($this->options['settings_options']['email']['from']['name'])) {
$trimmed = trim($this->options['settings_options']['email']['from']['name']);
if(! empty($trimmed)) {
return $trimmed;
}
}
return $name;
}
public function woocommerce_instruction_box($post) {
?>
Choose “Simple Product” to add items with just a price and leave other options blank. Use “Variable Product” for products with options: input a regular price, select “Attributes”, select “Add” next to “Custom Product Attribute”, input options per instructions, check “Visible on the Product Page”, check “Used for Variations”, select “Save Attributes”, select “Variations”, select “Go” next to “Add Variation”, expand the variation that is created, input a price into the regular price field, leave rest blank and select Save Changes for the variation.
NOTE: You must select “Save Changes” once more at the top to save a product!