function page_save_postdata($post_id) { global $page_postmetas; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (isset($_POST['pp_meta_form']) && !wp_verify_nonce($_POST['pp_meta_form'], plugin_basename(__FILE__))) { return $post_id; } // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Check permissions if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } // OK, we're authenticated if ($parent_id = wp_is_post_revision($post_id)) { $post_id = $parent_id; } if (isset($_POST['pp_meta_form'])) { //If import page content builder if (is_admin() && isset($_POST['ppb_import_current']) && !empty($_POST['ppb_import_current'])) { //If upload import builder file if (isset($_FILES['ppb_import_current_file']['name']) && !empty($_FILES['ppb_import_current_file']['name'])) { //Check if zip file $import_filename = $_FILES['ppb_import_current_file']['name']; $import_type = $_FILES['ppb_import_current_file']['type']; $is_zip = FALSE; $new_filename = basename($import_filename, '_.zip'); $accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/s-compressed'); foreach ($accepted_types as $mime_type) { if ($mime_type == $import_type) { $is_zip = TRUE; break; } } } else { if (isset($_POST['ppb_import_demo_file']) && !empty($_POST['ppb_import_demo_file'])) { $is_zip = FALSE; } } if ($is_zip) { WP_Filesystem(); $upload_dir = wp_upload_dir(); $cache_dir = ''; if (isset($upload_dir['basedir'])) { $cache_dir = $upload_dir['basedir'] . '/meteors'; } move_uploaded_file($_FILES["ppb_import_current_file"]["tmp_name"], $cache_dir . '/' . $import_filename); //$unzipfile = unzip_file( $cache_dir.'/'.$import_filename, $cache_dir); $zip = new ZipArchive(); $x = $zip->open($cache_dir . '/' . $import_filename); for ($i = 0; $i < $zip->numFiles; $i++) { $new_filename = $zip->getNameIndex($i); break; } if ($x === true) { $zip->extractTo($cache_dir); $zip->close(); } $import_options_json = file_get_contents($cache_dir . '/' . $new_filename); unlink($cache_dir . '/' . $import_filename); unlink($cache_dir . '/' . $new_filename); } else { if (isset($_POST['ppb_import_demo_file']) && !empty($_POST['ppb_import_demo_file'])) { $import_options_json = file_get_contents(get_template_directory() . '/cache/demos/pages/' . $_POST['ppb_import_demo_file']); } else { //If .json file then import $import_options_json = file_get_contents($_FILES["ppb_import_current_file"]["tmp_name"]); } } $import_options_arr = json_decode($import_options_json, true); if (isset($import_options_arr['ppb_form_data_order'][0]) && !empty($import_options_arr['ppb_form_data_order'][0])) { page_update_custom_meta($post_id, $import_options_arr['ppb_form_data_order'][0], 'ppb_form_data_order'); } $ppb_item_arr = explode(',', $import_options_arr['ppb_form_data_order'][0]); if (is_array($ppb_item_arr) && !empty($ppb_item_arr)) { foreach ($ppb_item_arr as $key => $ppb_item_arr) { if (isset($import_options_arr[$ppb_item_arr . '_data'][0]) && !empty($import_options_arr[$ppb_item_arr . '_data'][0])) { page_update_custom_meta($post_id, $import_options_arr[$ppb_item_arr . '_data'][0], $ppb_item_arr . '_data'); } if (isset($import_options_arr[$ppb_item_arr . '_size'][0]) && !empty($import_options_arr[$ppb_item_arr . '_size'][0])) { page_update_custom_meta($post_id, $import_options_arr[$ppb_item_arr . '_size'][0], $ppb_item_arr . '_size'); } } } header("Location: " . $_SERVER['HTTP_REFERER']); exit; } //If export page content builder if (is_admin() && isset($_POST['ppb_export_current']) && !empty($_POST['ppb_export_current'])) { $page_title = get_the_title($post_id); $json_file_name = strtolower(sanitize_title(THEMENAME)) . 'page' . strtolower(sanitize_title($page_title)) . '_export_' . date('m-d-Y_hia'); header('Content-disposition: attachment; filename=' . $json_file_name . '.json'); header('Content-type: application/json'); //Get current content builder data $ppb_form_data_order = get_post_meta($post_id, 'ppb_form_data_order'); $export_options_arr = array(); if (!empty($ppb_form_data_order)) { $export_options_arr['ppb_form_data_order'] = $ppb_form_data_order; //Get each builder module data $ppb_form_item_arr = explode(',', $ppb_form_data_order[0]); foreach ($ppb_form_item_arr as $key => $ppb_form_item) { $ppb_form_item_data = get_post_meta($post_id, $ppb_form_item . '_data'); $export_options_arr[$ppb_form_item . '_data'] = $ppb_form_item_data; $ppb_form_item_size = get_post_meta($post_id, $ppb_form_item . '_size'); $export_options_arr[$ppb_form_item . '_size'] = $ppb_form_item_size; } } echo json_encode($export_options_arr); exit; } foreach ($page_postmetas as $postmeta) { if (isset($_POST[$postmeta['id']]) && $_POST[$postmeta['id']]) { page_update_custom_meta($post_id, $_POST[$postmeta['id']], $postmeta['id']); } if (isset($_POST[$postmeta['id']]) && $_POST[$postmeta['id']] == "") { delete_post_meta($post_id, $postmeta['id']); } if (!isset($_POST[$postmeta['id']])) { delete_post_meta($post_id, $postmeta['id']); } } // Saving Page Builder Data if (isset($_POST['ppb_enable']) && !empty($_POST['ppb_enable'])) { page_update_custom_meta($post_id, $_POST['ppb_enable'], 'ppb_enable'); } else { delete_post_meta($post_id, 'ppb_enable'); } if (isset($_POST['ppb_form_data_order']) && !empty($_POST['ppb_form_data_order'])) { page_update_custom_meta($post_id, $_POST['ppb_form_data_order'], 'ppb_form_data_order'); $ppb_item_arr = explode(',', $_POST['ppb_form_data_order']); if (is_array($ppb_item_arr) && !empty($ppb_item_arr)) { foreach ($ppb_item_arr as $key => $ppb_item_arr) { if (isset($_POST[$ppb_item_arr . '_data']) && !empty($_POST[$ppb_item_arr . '_data'])) { page_update_custom_meta($post_id, $_POST[$ppb_item_arr . '_data'], $ppb_item_arr . '_data'); } if (isset($_POST[$ppb_item_arr . '_size']) && !empty($_POST[$ppb_item_arr . '_size'])) { page_update_custom_meta($post_id, $_POST[$ppb_item_arr . '_size'], $ppb_item_arr . '_size'); } } } } else { page_update_custom_meta($post_id, '', 'ppb_form_data_order'); } } //If enable Content Builder then also copy its content to standard page content if (isset($_POST['ppb_enable']) && !empty($_POST['ppb_enable']) && !wp_is_post_revision($post_id)) { //unhook this function so it doesn't loop infinitely remove_action('save_post', 'page_save_postdata'); //update the post, which calls save_post again $ppb_page_content = tg_apply_builder($post_id, 'page', FALSE); $current_post = array('ID' => $post_id, 'post_content' => $ppb_page_content); wp_update_post($current_post); if (is_wp_error($post_id)) { $errors = $post_id->get_error_messages(); foreach ($errors as $error) { echo esc_html($error); } } //re-hook this function add_action('save_post', 'page_save_postdata'); } }
function page_save_postdata($post_id) { global $page_postmetas; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (isset($_POST['myplugin_noncename']) && !wp_verify_nonce($_POST['myplugin_noncename'], plugin_basename(__FILE__))) { return $post_id; } // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Check permissions if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } // OK, we're authenticated if ($parent_id = wp_is_post_revision($post_id)) { $post_id = $parent_id; } foreach ($page_postmetas as $postmeta) { if ($_POST[$postmeta['id']]) { page_update_custom_meta($post_id, $_POST[$postmeta['id']], $postmeta['id']); } if ($_POST[$postmeta['id']] == "") { delete_post_meta($post_id, $postmeta['id']); } } }
function page_save_postdata($post_id) { global $page_postmetas; if (!is_edit_page('new')) { //Add gallery cats select $gallery_cat_select = retrieve_my_gallerycat(); $page_postmetas[] = array("section" => "Content Type", "id" => "page_gallery_cat", "type" => "select", "title" => "Gallery Category", "description" => "You can select gallery category to display on this page. <strong>(If you select Gallery Archive as page template)</strong>", "items" => $gallery_cat_select); } // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (isset($_POST['pp_meta_form']) && !wp_verify_nonce($_POST['pp_meta_form'], plugin_basename(__FILE__))) { return $post_id; } // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Check permissions if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } // OK, we're authenticated if ($parent_id = wp_is_post_revision($post_id)) { $post_id = $parent_id; } if (isset($_POST['pp_meta_form'])) { foreach ($page_postmetas as $postmeta) { if (isset($_POST[$postmeta['id']]) && $_POST[$postmeta['id']]) { page_update_custom_meta($post_id, $_POST[$postmeta['id']], $postmeta['id']); } if (isset($_POST[$postmeta['id']]) && $_POST[$postmeta['id']] == "") { delete_post_meta($post_id, $postmeta['id']); } if (!isset($_POST[$postmeta['id']])) { delete_post_meta($post_id, $postmeta['id']); } } // Saving Page Builder Data if (isset($_POST['ppb_enable']) && !empty($_POST['ppb_enable'])) { page_update_custom_meta($post_id, $_POST['ppb_enable'], 'ppb_enable'); } else { delete_post_meta($post_id, 'ppb_enable'); } if (isset($_POST['ppb_form_data_order']) && !empty($_POST['ppb_form_data_order'])) { page_update_custom_meta($post_id, $_POST['ppb_form_data_order'], 'ppb_form_data_order'); $ppb_item_arr = explode(',', $_POST['ppb_form_data_order']); if (is_array($ppb_item_arr) && !empty($ppb_item_arr)) { foreach ($ppb_item_arr as $key => $ppb_item_arr) { if (isset($_POST[$ppb_item_arr . '_data']) && !empty($_POST[$ppb_item_arr . '_data'])) { page_update_custom_meta($post_id, $_POST[$ppb_item_arr . '_data'], $ppb_item_arr . '_data'); } if (isset($_POST[$ppb_item_arr . '_size']) && !empty($_POST[$ppb_item_arr . '_size'])) { page_update_custom_meta($post_id, $_POST[$ppb_item_arr . '_size'], $ppb_item_arr . '_size'); } } } } else { page_update_custom_meta($post_id, '', 'ppb_form_data_order'); } } //If enable Content Builder then also copy its content to standard page content if (isset($_POST['ppb_enable']) && !empty($_POST['ppb_enable']) && !wp_is_post_revision($post_id)) { //unhook this function so it doesn't loop infinitely remove_action('save_post', 'page_save_postdata'); //update the post, which calls save_post again $ppb_page_content = tg_apply_builder($post_id, 'page', FALSE); $current_post = array('ID' => $post_id, 'post_content' => $ppb_page_content); wp_update_post($current_post); if (is_wp_error($post_id)) { $errors = $post_id->get_error_messages(); foreach ($errors as $error) { echo $error; } } //re-hook this function add_action('save_post', 'page_save_postdata'); } }
function page_save_postdata($post_id, $page_postmetas) { //global $page_postmetas; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (isset($_POST['myplugin_noncename']) && !wp_verify_nonce($_POST['myplugin_noncename'], plugin_basename(__FILE__))) { return $post_id; } // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } if ('page' != $_POST['post_type'] || !isset($_POST['post_type'])) { return $post_id; } //Fix for quick edit mode. //print "<pre>"; //print_r($page_postmetas); // Check permissions if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } // OK, we're authenticated if ($parent_id = wp_is_post_revision($post_id)) { $post_id = $parent_id; } foreach ($page_postmetas as $postmeta) { if ($_POST[$postmeta['id']]) { page_update_custom_meta($post_id, $_POST[$postmeta['id']], $postmeta['id']); } if ($_POST[$postmeta['id']] == "") { delete_post_meta($post_id, $postmeta['id']); } } // file upload // /* if ($_FILES["upload_kingsize_page_background"]["type"]){ $special_chars = array (' ','`','"','\'','\\','/'," ","#","$","%","^","&","*","!","~","`","\"","'","'","=","?","/","[","]","(",")","|","<",">",";","\\",","); $filename = str_replace($special_chars,'',$_FILES['upload_kingsize_page_background']['name']); //$filename = time() . $filename; $directory = dirname(__FILE__) . "/images/upload/"; $directory = str_replace("lib/","",$directory); @move_uploaded_file($_FILES["upload_kingsize_page_background"]["tmp_name"], $directory . $filename); @chmod($directory . $filename, 0644); $uploaded_image_path = get_option('siteurl'). "/wp-content/themes/". get_option('template')."/images/upload/". $filename; //updating the meta value of background page_update_custom_meta($post_id, $uploaded_image_path, "kingsize_page_background"); } */ /// ennd file upload // }