PluginProbe ʕ •ᴥ•ʔ
Essential Addons for Elementor – Popular Elementor Templates & Widgets / 6.6.9
Essential Addons for Elementor – Popular Elementor Templates & Widgets v6.6.9
6.6.9 6.6.8 6.6.7 6.6.6 6.6.5 6.6.4 6.6.3 5.7.3 5.7.4 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.15 5.8.16 5.8.18 5.8.2 5.8.3 5.8.4 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.10 5.9.11 5.9.12 5.9.13 5.9.14 5.9.15 5.9.16 5.9.17 5.9.18 5.9.19 5.9.2 5.9.20 5.9.21 5.9.22 5.9.23 5.9.24 5.9.25 5.9.26 5.9.27 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 6.0.1 6.0.10 6.0.11 6.0.12 6.0.13 6.0.14 6.0.15 6.0.2 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.0.8 6.0.9 6.1.0 6.1.1 6.1.10 6.1.11 trunk 6.1.12 1.0.0 6.1.13 1.0.1 6.1.14 1.1.0 6.1.15 2.0 6.1.17 2.1 6.1.18 2.10.0 6.1.19 2.10.1 6.1.2 2.10.2 6.1.20 2.10.3 6.1.3 2.10.4 6.1.4 2.10.5 6.1.5 2.2.0 6.1.6 2.2.1 6.1.7 2.2.2 6.1.8 2.2.3 6.1.9 2.2.4 6.2.0 2.2.5 6.2.1 2.3.0 6.2.2 2.3.1 6.2.3 2.4.0 6.2.4 2.4.1 6.3.0 2.4.2 6.3.1 2.4.3 6.3.2 2.5.0 6.3.3 2.6.0 6.4.0 2.7.0 6.5.0 2.7.1 6.5.1 2.7.10 6.5.10 2.7.11 6.5.11 2.7.2 6.5.12 2.7.3 6.5.13 2.7.4 6.5.2 2.7.5 6.5.3 2.7.6 6.5.4 2.7.7 6.5.5 2.7.8 6.5.6 2.7.9 6.5.7 2.8.0 6.5.8 2.8.1 6.5.9 2.8.2 6.6.0 2.8.3 6.6.1 2.8.4 6.6.2 2.8.5 2.8.6 2.8.7 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.4.1 3.1.5 3.2.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.5.0 3.5.1 3.5.2 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 5.0.0 5.0.1 5.0.10 5.0.11 5.0.12 5.0.13 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.4.6 5.5.5 5.6.5 5.7.2
essential-addons-for-elementor-lite / includes / Extensions / Post_Duplicator.php
essential-addons-for-elementor-lite / includes / Extensions Last commit date
Custom_JS.php 1 year ago Hover_Effect.php 1 year ago Image_Masking.php 2 months ago Liquid_Glass_Effect.php 5 months ago Post_Duplicator.php 2 months ago Promotion.php 9 months ago Reading_Progress.php 5 months ago Scroll_to_Top.php 5 months ago Table_of_Content.php 2 weeks ago Vertical_Text_Orientation.php 7 months ago Wrapper_Link.php 2 months ago index.php 3 years ago
Post_Duplicator.php
187 lines
1 <?php
2
3 namespace Essential_Addons_Elementor\Extensions;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 class Post_Duplicator {
10 public function __construct() {
11
12 add_filter( 'admin_action_eae_duplicate', array( $this, 'duplicate' ) );
13 add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 10000 );
14 add_filter( 'post_row_actions', array( $this, 'row_actions' ), 10, 2 );
15 add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 );
16
17 }
18
19 public function admin_bar_menu( $wp_admin_bar ) {
20
21 global $pagenow;
22 global $post;
23
24 $enabled_on = get_option( 'eael_save_post_duplicator_post_type', 'all' );
25
26 if ( ! is_admin() || $pagenow !== 'post.php' || ( $enabled_on != 'all' || $post->post_type != $enabled_on ) ) {
27 return;
28 }
29
30 $duplicate_url = admin_url( 'admin.php?action=eae_duplicate&post=' . $post->ID );
31 $duplicate_url = wp_nonce_url( $duplicate_url, 'ea_duplicator' );
32 $wp_admin_bar->add_menu(
33 array(
34 'id' => 'eae-duplicator',
35 'title' => __( 'EA Duplicator', 'essential-addons-for-elementor-lite' ),
36 'href' => $duplicate_url
37 )
38 );
39 }
40
41 /**
42 * EA Duplicator Button added in table row
43 *
44 * @param array $actions
45 * @param WP_Post $post
46 *
47 * @return array
48 */
49 public function row_actions( $actions, $post ) {
50
51 $enabled_on = get_option( 'eael_save_post_duplicator_post_type', 'all' );
52
53 if ( current_user_can( 'edit_posts' ) && ( $enabled_on == 'all' || $post->post_type == $enabled_on ) ) {
54 $duplicate_url = admin_url( 'admin.php?action=eae_duplicate&post=' . $post->ID );
55 $duplicate_url = wp_nonce_url( $duplicate_url, 'ea_duplicator' );
56 $actions['eae_duplicate'] = sprintf(
57 '<a href="%s" title="%s">%s</a>',
58 esc_url( $duplicate_url ),
59 sprintf(
60 /* translators: %s: Post title being duplicated. */
61 __( 'Duplicate %s', 'essential-addons-for-elementor-lite' ),
62 esc_html( $post->post_title )
63 ),
64 __( 'EA Duplicator', 'essential-addons-for-elementor-lite' )
65 );
66 }
67
68 return $actions;
69 }
70
71 /**
72 * Duplicate a post
73 * @return void
74 */
75 public function duplicate() {
76
77 $nonce = isset( $_REQUEST['_wpnonce'] ) && ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : null;
78 $post_id = isset( $_REQUEST['post'] ) && ! empty( $_REQUEST['post'] ) ? intval( $_REQUEST['post'] ) : null;
79 $action = isset( $_REQUEST['action'] ) && ! empty( $_REQUEST['action'] ) ? trim( sanitize_text_field( wp_unslash( $_REQUEST['action']) ) ) : null;
80
81 if ( is_null( $nonce ) || is_null( $post_id ) || $action !== 'eae_duplicate' ) {
82 return; // Return if action is not eae_duplicate
83 }
84
85 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $nonce ) ), 'ea_duplicator' ) ) {
86 return; // Return if nonce is not valid
87 }
88
89 if ( ! current_user_can( 'edit_post', $post_id ) ) {
90 wp_die( esc_html__( 'You do not have sufficient permissions to edit this post.', 'essential-addons-for-elementor-lite' ) );
91 }
92
93 $post = sanitize_post( get_post( $post_id ), 'db' );
94
95 if ( is_null( $post ) ) {
96 return; // Return if post is not there.
97 }
98
99 $current_user = wp_get_current_user();
100 $allowed_roles = array('editor', 'administrator', 'author');
101 $redirect_url = admin_url( 'edit.php?post_type=' . $post->post_type );
102
103 if ( ! array_intersect( $allowed_roles, $current_user->roles ) ) {
104 switch ( $post->post_type ) {
105 case 'post':
106 $can_edit_others_posts = current_user_can('edit_others_posts');
107 break;
108 case 'page':
109 $can_edit_others_posts = current_user_can('edit_others_pages');
110 break;
111 default :
112 $can_edit_others_posts = current_user_can('edit_others_posts');
113 break;
114 }
115
116 if ( $current_user->ID !== $post->post_author && ! $can_edit_others_posts ){
117 wp_safe_redirect( $redirect_url );
118 return;
119 }
120 }
121
122 $duplicate_post_args = array(
123 'post_author' => $current_user->ID,
124 'post_title' => $post->post_title . ' - Copy',
125 'post_content' => $post->post_content,
126 'post_excerpt' => $post->post_excerpt,
127 'post_parent' => $post->post_parent,
128 'post_status' => 'draft',
129 'ping_status' => $post->ping_status,
130 'comment_status' => $post->comment_status,
131 'post_password' => $post->post_password,
132 'post_type' => $post->post_type,
133 'to_ping' => $post->to_ping,
134 'menu_order' => $post->menu_order,
135 );
136 $duplicated_id = wp_insert_post( $duplicate_post_args );
137
138 if ( ! is_wp_error( $duplicated_id ) ) {
139 $taxonomies = get_object_taxonomies( $post->post_type );
140 if ( ! empty( $taxonomies ) && is_array( $taxonomies ) ) {
141 foreach ( $taxonomies as $taxonomy ) {
142 $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
143 wp_set_object_terms( $duplicated_id, $post_terms, $taxonomy, false );
144 }
145 }
146
147 global $wpdb;
148
149 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
150 $post_meta = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = %d", $post_id ) );
151
152 if ( ! empty( $post_meta ) && is_array( $post_meta ) ) {
153
154 $duplicate_insert_query = "INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ";
155 $insert = '';
156
157 foreach ( $post_meta as $meta_info ) {
158
159 $meta_key = sanitize_text_field( $meta_info->meta_key );
160 $meta_value = $meta_info->meta_value;
161
162 $exclude_meta_keys = [ '_wc_average_rating', '_wc_review_count', '_wc_rating_count', '_elementor_css' ];
163
164 if( in_array($meta_key, $exclude_meta_keys) ){
165 continue;
166 }
167
168 if ( $meta_key === '_elementor_template_type' ) {
169 delete_post_meta( $duplicated_id, '_elementor_template_type' );
170 }
171
172 if ( ! empty( $insert ) ) {
173 $insert .= ', ';
174 }
175
176 $insert .= $wpdb->prepare( '(%d, %s, %s)', $duplicated_id, $meta_key, $meta_value );
177 }
178
179 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter
180 $wpdb->query( $duplicate_insert_query . $insert );
181 }
182 }
183
184 wp_safe_redirect( $redirect_url );
185 }
186 }
187