Example #1
0
/**
 * Save post action, process fields
 */
function update_post_gallery_so_14445904($post_id, $post_object)
{
    // Doing revision, exit earlier **can be removed**
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    // Doing revision, exit earlier
    if ('revision' == $post_object->post_type) {
        return;
    }
    //    // Verify authenticity
    //    if ( !wp_verify_nonce( $_POST['noncename_so_14445904'], plugin_basename( __FILE__ ) ) )
    //        return;
    // Correct post type
    if ('w_dalil_posttype' != $_POST['post_type']) {
        return;
    }
    add_filter('upload_dir', 'dalil_dir');
    if (isset($_POST['hide_logo']) && ($_POST['hide_logo'] = 'hide')) {
        update_post_meta($post_id, 'dalil_item_hidden', true);
    }
    if (isset($_POST['unhide_logo']) && ($_POST['unhide_logo'] = 'hide')) {
        update_post_meta($post_id, 'dalil_item_hidden', false);
    }
    if (isset($_POST['remove_logo']) && ($_POST['remove_logo'] = 'remove')) {
        $dalil_information = get_post_meta($post_id, 'dalil_information', true);
        if ($_POST['dalil-address']) {
            $dalil_data['dalil-address'] = $_POST['dalil-address'];
        }
        if ($_POST['dalil-phone']) {
            $dalil_data['dalil-phone'] = $_POST['dalil-phone'];
        }
        if ($_POST['dalil-email']) {
            $dalil_data['dalil-email'] = $_POST['dalil-email'];
        }
        if ($_POST['dalil-website']) {
            $dalil_data['dalil-website'] = $_POST['dalil-website'];
        }
        /* delete old logo */
        if (isset($dalil_information['dalil-logo'])) {
            $file_name = substr($dalil_information['dalil-logo'], strpos($dalil_information['dalil-logo'], 'dalil_files') + 12);
            rename(wp_upload_dir()['path'] . '/' . $file_name, wp_upload_dir()['path'] . '/removed_' . $file_name);
        }
        if (isset($dalil_information['dalil-logo-orginal'])) {
            $file_name = substr($dalil_information['dalil-logo-orginal'], strpos($dalil_information['dalil-logo-orginal'], 'dalil_files') + 12);
            rename(wp_upload_dir()['path'] . '/' . $file_name, wp_upload_dir()['path'] . '/removed_' . $file_name);
        }
        //        unlink( wp_upload_dir()['path'].'/'.$file_name ) ;
        update_post_meta($post_id, 'dalil_information', $dalil_data);
        return;
    }
    if (isset($_FILES['dalil-logo']) && $_FILES['dalil-logo']['name'] != '') {
        $dalil_information = get_post_meta($post_id, 'dalil_information', true);
        $uploadedfile = $_FILES['dalil-logo'];
        $upload_overrides = array('test_form' => false, 'unique_filename_callback' => 'dalil_logo_filename');
        add_filter('upload_mimes', 'dalil_mimes');
        $movefile = wp_handle_upload($uploadedfile, $upload_overrides);
        remove_filter('upload_mimes', 'dalil_mimes');
        if ($movefile && !isset($movefile['error'])) {
            $get_ext = wg_get_ext($movefile['type']);
            $generated_for_small = 'sm_' . rand(100000, 999999) . $get_ext;
            $image1 = wp_get_image_editor($movefile['file']);
            $image1->resize(270, NULL, true);
            $sm_dir = wp_upload_dir()['basedir'] . '/dalil_files/' . $generated_for_small;
            $sm_url = wp_upload_dir()['baseurl'] . '/dalil_files/' . $generated_for_small;
            $result = $image1->save($sm_dir);
            $dalil_information = get_post_meta($post_id, 'dalil_information', true);
            if (isset($dalil_information['dalil-logo'])) {
                /* delete old logo */
                $file_name = substr($dalil_information['dalil-logo-orginal'], strpos($dalil_information['dalil-logo-orginal'], 'dalil_files') + 12);
                rename(wp_upload_dir()['path'] . '/' . $file_name, wp_upload_dir()['path'] . '/removed_' . $file_name);
                //              unlink( wp_upload_dir()['path'].'/'.$file_name ) ;
            }
            $dalil_data['dalil-logo-orginal'] = $movefile['url'];
            $dalil_data['dalil-logo'] = $sm_url;
        }
    } else {
        $dalil_information = get_post_meta($post_id, 'dalil_information', true);
        if ($dalil_information['dalil-logo'] != '') {
            $dalil_data['dalil-logo'] = $dalil_information['dalil-logo'];
        }
    }
    remove_filter('upload_dir', 'dalil_dir');
    if ($_POST['dalil-address']) {
        $dalil_data['dalil-address'] = $_POST['dalil-address'];
    }
    if ($_POST['dalil-phone']) {
        $dalil_data['dalil-phone'] = $_POST['dalil-phone'];
    }
    if ($_POST['dalil-email']) {
        $dalil_data['dalil-email'] = $_POST['dalil-email'];
    }
    if ($_POST['dalil-website']) {
        $dalil_data['dalil-website'] = $_POST['dalil-website'];
    }
    if ($dalil_data) {
        update_post_meta($post_id, 'dalil_information', $dalil_data);
    } else {
        delete_post_meta($post_id, 'dalil_information');
    }
}
Example #2
0
function w_dalilhandle_addnew()
{
    session_start();
    if (isset($_FILES['dalil_logo']) && $_FILES['dalil_logo']['name'] != '') {
        $uploadedfile = $_FILES['dalil_logo'];
        $upload_overrides = array('test_form' => false, 'unique_filename_callback' => 'dalil_logo_filename');
        add_filter('upload_mimes', 'dalil_mimes');
        add_filter('upload_dir', 'dalil_dir');
        $movefile = wp_handle_upload($uploadedfile, $upload_overrides);
        remove_filter('upload_dir', 'dalil_dir');
        remove_filter('upload_mimes', 'dalil_mimes');
        if ($movefile && !isset($movefile['error'])) {
            $get_ext = wg_get_ext($movefile['type']);
            $generated_for_small = 'sm_' . rand(100000, 999999) . $get_ext;
            $image1 = wp_get_image_editor($movefile['file']);
            $image1->resize(270, NULL, true);
            $sm_dir = wp_upload_dir()['basedir'] . '/dalil_files/' . $generated_for_small;
            $sm_url = wp_upload_dir()['baseurl'] . '/dalil_files/' . $generated_for_small;
            $result = $image1->save($sm_dir);
            $dalil_data['dalil-logo-orginal'] = $movefile['url'];
            $dalil_data['dalil-logo'] = $sm_url;
        } else {
            $_SESSION['dalil_message'] = __('Logo File Not allowed', 'w_dalil');
            session_write_close();
            wp_redirect($_SERVER["REQUEST_URI"]);
            exit;
        }
    }
    if (wp_verify_nonce($_POST['w-dalil-addnew'], 'w-dalil-nonce') && isset($_POST['dalil_newsubmit'])) {
        $daliltitle = mysql_real_escape_string($_POST['dalil_newtitle']);
        $dalil_data['dalil-address'] = mysql_real_escape_string($_POST['dalil_newaddress']);
        $dalil_data['dalil-phone'] = mysql_real_escape_string($_POST['dalil_newphone']);
        $dalil_data['dalil-activity'] = mysql_real_escape_string($_POST['dalil_newactivity']);
        if (isset($_POST['dalil_newemail'])) {
            $dalil_data['dalil-email'] = mysql_real_escape_string($_POST['dalil_newemail']);
        }
        if (isset($_POST['dalil_newwebsite'])) {
            $dalil_data['dalil-website'] = mysql_real_escape_string($_POST['dalil_newwebsite']);
        }
        $my_post = array('post_title' => $daliltitle, 'post_type' => 'w_dalil_posttype');
        $post_id = wp_insert_post($my_post, $wp_error);
        if (!$wp_error) {
            update_post_meta($post_id, 'dalil_information', $dalil_data);
            $_SESSION['dalil_message'] = __('Thanks For adding', 'w_dalil');
            session_write_close();
            wp_redirect($_SERVER["REQUEST_URI"]);
            exit;
        }
    }
}