function __construct() { if (!pl_can_use_tools()) { return false; } add_action('wp_before_admin_bar_render', array($this, 'admin_bar_init')); if (pl_is_workarea_iframe()) { add_filter('show_admin_bar', '__return_false'); } if (pl_tools_active()) { add_action('admin_bar_menu', array($this, 'admin_bar_save'), 3); } add_action('admin_bar_menu', array($this, 'admin_bar_tools'), 220); }
function save_hook() { /** Incoming post data */ $postdata = $_POST; if (isset($postdata['nonce'])) { pl_verify_ajax($postdata['nonce']); } else { die('No Nonce set!'); } /** If doing an upload. */ if (isset($_FILES)) { $postdata['files'] = $_FILES; } /** Start response variable, sent back at end of request. */ $response = array(); /** Send back the data we recieved */ $response['post'] = $postdata; /** The saving hook */ $hook = $postdata['hook']; /** The specific thing to run ( not used? )*/ // $run = $postdata['run']; /** Page information TODO used? */ // $pageID = $postdata['pageID']; // $typeID = $postdata['typeID']; /** Debug information */ $response['dataAmount'] = isset($_SERVER['CONTENT_LENGTH']) ? (int) $_SERVER['CONTENT_LENGTH'] : 'No Value'; /** * Trigger hook, send the functions the data and response for update * If user is logged out then only do nopriv options */ if (pl_can_use_tools()) { $response = apply_filters('pl_server_' . $hook, $response, $postdata); $response = apply_filters('pl_server_nopriv_' . $hook, $response, $postdata); } else { $response = apply_filters('pl_server_nopriv_' . $hook, $response, $postdata); } /** JSON response for output and UI actions */ header('Content-Type: application/json'); echo json_encode(pl_convert_arrays_to_objects($response)); die; // don't forget this, always returns 0 w/o }
/** * Update post meta */ function handle_meta_settings_form($post_id) { if (!isset($_POST['pl_platform_settings']) || !isset($_POST['pl_platform_settings_nonce']) || !wp_verify_nonce($_POST['pl_platform_settings_nonce'], $this->form_action)) { return; } if ('page' == $_POST['post_type'] && !pl_can_use_tools('edit_page', $post_id)) { return; } elseif (!pl_can_use_tools('edit_post', $post_id)) { return; } $postsettings = $_POST['pl_platform_settings']; $postsettings = $this->sanitize_post_options($postsettings); foreach ($postsettings as $key => $val) { update_post_meta($post_id, $key, $val); } }
/** * Create an admin notice */ function pl_create_notice($args) { // Only show notices to users with update_core role, thats single site admins and multisite network admins. if (!pl_can_use_tools('update_core')) { return false; } $args = wp_parse_args($args, array('title' => __('Notice', 'pl-platform'), 'msg' => false, 'action' => false, 'alink' => '#', 'atext' => false, 'id' => 'none', 'exp' => 30 * DAY_IN_SECONDS, 'class' => '', 'icon' => 'cog')); $hide = false; $id = 'pl_notice_' . $args['id']; /** Special URL parameter for testing. Deletes transients if present... */ if (isset($_GET['pl_clear_transients'])) { delete_transient($id); } if ('pl_notice_none' != $id) { $args['class'] .= ' pl-is-dismissible'; $hide = get_transient($id); $hide_btn = sprintf('<span class="pl-notice-dismiss button button-secondary"><i class="pl-icon pl-icon-remove"></i> Hide</span>'); } else { $hide_btn = ''; } $icon = sprintf('<div class="pl-notice-icon"><i class="pl-icon pl-icon-%s"></i></div>', $args['icon']); if ($args['action']) { $action = sprintf('<span class="act">%s</span>', $args['action']); } elseif ($args['atext']) { $action = sprintf('<span class="act"><a class="button button-primary" href="%s"><i class="pl-icon pl-icon-%s"></i> %s <i class="pl-icon pl-icon-angle-right"></i></a></span>', $args['alink'], $args['icon'], $args['atext']); } if (false === $hide) { printf('<div id="message" class="updated pl-notice %s" data-id="%s" data-exp="%s">%s <div class="pl-notice-content">%s<span class="ttl">%s</span> <span class="msg">%s</span>%s</div></div>', $args['class'], $id, $args['exp'], $icon, $hide_btn, $args['title'], $args['msg'], $args['action']); } }
/** * Display a message if section has no output. */ function blank_template($name = '') { if (pl_can_use_tools()) { return sprintf('<div class="blank-section-template pl-editor-only"><strong>%s</strong> %a.</div>', $name, __('is hidden or returned no output', 'pl-platform')); } else { return ''; } }