Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('wcfm_vendor_groups_actions', function($actions, $wcfm_groups_single) {
- $actions .= '<a class="wcfm_group_duplicate wcfm-action-icon" href="#" data-groupid="' . $wcfm_groups_single->ID . '"><span class="wcfmfa fa-copy text_tip" data-tip="' . esc_attr__( 'Duplicate', 'wc-frontend-manager' ) . '"></span></a>';
- return $actions;
- }, 10, 2);
- add_action('after_wcfm_groups', function() {
- ?>
- <script>
- jQuery(function($) {
- $('#wcfm-groups').on('click', '.wcfm_group_duplicate', function(){
- $('#wcfm-groups_wrapper').block({
- message: null,
- overlayCSS: {
- background: '#fff',
- opacity: 0.6
- }
- });
- var data = {
- action : 'wcfmgs_duplicate_group',
- groupid : $(this).data('groupid'),
- wcfm_ajax_nonce: wcfm_params.wcfm_ajax_nonce
- }
- $.ajax({
- type: 'POST',
- url: wcfm_params.ajax_url,
- data: data,
- success: function(response) {
- if(response) {
- $response_json = $.parseJSON(response);
- if($response_json.status) {
- if( $response_json.redirect ) window.location = $response_json.redirect;
- }
- }
- }
- });
- $('#wcfm-groups_wrapper').unblock();
- return false;
- });
- });
- </script>
- <?php
- });
- add_action('wp_ajax_wcfmgs_duplicate_group', function() {
- global $wpdb;
- if ( ! check_ajax_referer( 'wcfm_ajax_nonce', 'wcfm_ajax_nonce', false ) ) {
- wp_send_json_error( __( 'Invalid nonce! Refresh your page and try again.', 'wc-frontend-manager' ) );
- wp_die();
- }
- if ( empty( $_POST['groupid'] ) ) {
- echo '{"status": false, "message": "' . __( 'No group to copy' ) . '"}';
- }
- $group_id = isset( $_POST['groupid'] ) ? absint( $_POST['groupid'] ) : '';
- $post = get_post( $group_id );
- if (isset( $post ) && $post != null) {
- $args = array(
- 'comment_status' => $post->comment_status,
- 'ping_status' => $post->ping_status,
- 'post_author' => $post->post_author,
- 'post_content' => $post->post_content,
- 'post_excerpt' => $post->post_excerpt,
- 'post_name' => $post->post_name,
- 'post_parent' => $post->post_parent,
- 'post_password' => $post->post_password,
- 'post_status' => 'draft',
- 'post_title' => $post->post_title . " (Copy)",
- 'post_type' => $post->post_type,
- 'to_ping' => $post->to_ping,
- 'menu_order' => $post->menu_order
- );
- $new_post_id = wp_insert_post( $args );
- $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$group_id");
- if (count($post_meta_infos)!=0) {
- $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
- foreach ($post_meta_infos as $meta_info) {
- $meta_key = $meta_info->meta_key;
- if( $meta_key == '_wp_old_slug' ) continue;
- $meta_value = addslashes($meta_info->meta_value);
- $sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'";
- }
- $sql_query.= implode(" UNION ALL ", $sql_query_sel);
- $wpdb->query($sql_query);
- }
- echo '{"status": true, "redirect": "' . get_wcfm_groups_manage_url( $new_post_id ) . '", "id": "' . $new_post_id . '"}';
- }
- die;
- });
Add Comment
Please, Sign In to add comment