| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace PXLBSAdminify\Inc\Modules\PostDuplicator; | |
| 3 | +namespace WPAdminify\Inc\Modules\PostDuplicator; | |
| 4 | 4 | |
| 5 | -use PXLBSAdminify\Inc\Admin\AdminSettings; | |
| 5 | +use WPAdminify\Inc\Admin\AdminSettings; | |
| 6 | 6 | // no direct access allowed |
| 7 | 7 | if (!defined('ABSPATH')) { |
| 8 | 8 | exit; |
| 9 | 9 | } |
| @@ -28,22 +28,19 @@ | ||
| 28 | 28 | public $options = []; |
| 29 | 29 | |
| 30 | 30 | public function __construct() |
| 31 | 31 | { |
| 32 | - $this->clone_title = AdminSettings::get_instance()->get('pxlbsadminify_wl_plugin_menu_label'); | |
| 32 | + $this->clone_title = AdminSettings::get_instance()->get('jltwp_adminify_wl_plugin_menu_label'); | |
| 33 | 33 | |
| 34 | 34 | $this->options = (array) AdminSettings::get_instance()->get(); |
| 35 | 35 | |
| 36 | - // Taxonomy duplicator (reads post_duplicator.taxonomies) is a | |
| 37 | - // Pro-only feature. Pro/Classes/Filters.php registers the | |
| 38 | - // admin_action and *_row_actions filters when the Pro plugin | |
| 39 | - // is active. | |
| 36 | + new TaxonomyDuplicator(); | |
| 40 | 37 | |
| 41 | 38 | // Check Access for User roles |
| 42 | - add_action('admin_init', [$this, 'post_duplicator_init']); | |
| 39 | + add_action('admin_init', [$this, 'adminify_post_duplicator_init']); | |
| 43 | 40 | } |
| 44 | 41 | |
| 45 | - public function post_duplicator_init() | |
| 42 | + public function adminify_post_duplicator_init() | |
| 46 | 43 | { |
| 47 | 44 | $post_types = []; |
| 48 | 45 | if (!empty($this->options['post_duplicator']['post_types'])) { |
| 49 | 46 | $post_types = $this->options['post_duplicator']['post_types']; |
| @@ -53,16 +50,16 @@ | ||
| 53 | 50 | if (empty($post_types) || empty(array_intersect($all_post_types, $post_types))) { |
| 54 | 51 | return; |
| 55 | 52 | } |
| 56 | 53 | |
| 57 | - add_action('admin_action_adminify_duplicate', [$this, 'duplicate_post_as_draft']); | |
| 58 | - add_filter('post_row_actions', [$this, 'duplicator_row_actions'], 10, 2); | |
| 59 | - add_filter('page_row_actions', [$this, 'duplicator_row_actions'], 10, 2); | |
| 54 | + add_action('admin_action_adminify_duplicate', [$this, 'adminify_duplicate_post_as_draft']); | |
| 55 | + add_filter('post_row_actions', [$this, 'jltwp_adminify_duplicator_row_actions'], 10, 2); | |
| 56 | + add_filter('page_row_actions', [$this, 'jltwp_adminify_duplicator_row_actions'], 10, 2); | |
| 60 | 57 | |
| 61 | 58 | |
| 62 | 59 | // foreach ($post_types as $key => $post_type) { |
| 63 | 60 | // if (in_array($post_type, $all_post_types)) { |
| 64 | - // add_filter($post_type . '_row_actions', [$this, 'duplicator_row_actions'], 10, 2); | |
| 61 | + // add_filter($post_type . '_row_actions', [$this, 'jltwp_adminify_duplicator_row_actions'], 10, 2); | |
| 65 | 62 | // } |
| 66 | 63 | // } |
| 67 | 64 | } |
| 68 | 65 | |
| @@ -96,9 +93,9 @@ | ||
| 96 | 93 | |
| 97 | 94 | /* |
| 98 | 95 | * Add the duplicate link to action list for post_row_actions |
| 99 | 96 | */ |
| 100 | - public function duplicator_row_actions($actions, $post) | |
| 97 | + public function jltwp_adminify_duplicator_row_actions($actions, $post) | |
| 101 | 98 | { |
| 102 | 99 | $post_type = $post->post_type; |
| 103 | 100 | $allowed_post_types = $post_types = $this->options['post_duplicator']['post_types']; |
| 104 | 101 | if( !in_array($post_type, $allowed_post_types)){ |
| @@ -108,14 +105,13 @@ | ||
| 108 | 105 | return $actions; |
| 109 | 106 | } |
| 110 | 107 | |
| 111 | 108 | $adminify_duplicate_link = admin_url('admin.php?action=adminify_duplicate&post=' . $post->ID); |
| 112 | - $adminify_duplicate_link = wp_nonce_url($adminify_duplicate_link, 'pxlbsadminify_post_duplicator_nonce'); | |
| 109 | + $adminify_duplicate_link = wp_nonce_url($adminify_duplicate_link, 'jltwp_adminify_post_duplicator_nonce'); | |
| 113 | 110 | |
| 114 | 111 | $clone_title = !empty($this->clone_title) ? $this->clone_title : 'Adminify'; |
| 115 | 112 | $clone_title = preg_replace('/wp/i', '', $clone_title) . ' Clone'; |
| 116 | 113 | $duplicate_title = 'Duplicate this item ' . $post->post_title; |
| 117 | - /* translators: 1: Duplicate post URL, 2: Link title attribute, 3: Link text */ | |
| 118 | 114 | $actions['adminify_duplicate'] = sprintf(__('<a href="%1$s" title="%2$s" rel="permalink">%3$s</a>', 'adminify'), $adminify_duplicate_link, $duplicate_title, $clone_title); |
| 119 | 115 | return $actions; |
| 120 | 116 | } |
| 121 | 117 | |
| @@ -122,9 +118,9 @@ | ||
| 122 | 118 | |
| 123 | 119 | /* |
| 124 | 120 | * Function creates post duplicate as a draft and redirects then to the edit post screen |
| 125 | 121 | */ |
| 126 | - public function duplicate_post_as_draft() | |
| 122 | + public function adminify_duplicate_post_as_draft() | |
| 127 | 123 | { |
| 128 | 124 | global $wpdb; |
| 129 | 125 | |
| 130 | 126 | if (!(isset($_GET['post']) || isset($_POST['post']) || (isset($_REQUEST['action']) && 'adminify_duplicate' == $_REQUEST['action']))) { |
| @@ -134,9 +130,9 @@ | ||
| 134 | 130 | /* |
| 135 | 131 | * Nonce verification |
| 136 | 132 | * Return if nonce is not valid |
| 137 | 133 | */ |
| 138 | - if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_wpnonce'])), 'pxlbsadminify_post_duplicator_nonce')) { | |
| 134 | + if (!wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_wpnonce'])), 'jltwp_adminify_post_duplicator_nonce')) { | |
| 139 | 135 | return; |
| 140 | 136 | } |
| 141 | 137 | |
| 142 | 138 | /* |
| @@ -146,13 +142,13 @@ | ||
| 146 | 142 | /* |
| 147 | 143 | * and all the original post data then |
| 148 | 144 | */ |
| 149 | 145 | $post = get_post($post_id); |
| 150 | - if( isset( $_SERVER['HTTP_REFERER']) && str_contains( esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ), 'action=adminify_duplicate' )) { | |
| 146 | + if( isset( $_SERVER['HTTP_REFERER']) && str_contains( $_SERVER['HTTP_REFERER'], 'action=adminify_duplicate' )) { | |
| 151 | 147 | $redirect_url = admin_url('edit.php?post_type=' . $post->post_type); |
| 152 | 148 | wp_safe_redirect($redirect_url); |
| 153 | 149 | |
| 154 | - // exit; | |
| 150 | + exit; | |
| 155 | 151 | } |
| 156 | 152 | |
| 157 | 153 | if (!$this->user_can_clone($post)) { |
| 158 | 154 | return; |
| @@ -198,10 +194,9 @@ | ||
| 198 | 194 | |
| 199 | 195 | /* |
| 200 | 196 | * duplicate all post meta just in two SQL queries |
| 201 | 197 | */ |
| 202 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query required for copying all post meta rows; not cached intentionally. | |
| 203 | - $post_meta_infos = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=%d", $post_id)); | |
| 198 | + $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"); | |
| 204 | 199 | if (count($post_meta_infos) != 0) { |
| 205 | 200 | $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) "; |
| 206 | 201 | foreach ($post_meta_infos as $meta_info) { |
| 207 | 202 | $meta_key = $meta_info->meta_key; |
| @@ -222,9 +217,8 @@ | ||
| 222 | 217 | $meta_value = $meta_info->meta_value; |
| 223 | 218 | $sql_query_sel[] = $wpdb->prepare('SELECT %d, %s, %s', $new_post_id, $meta_key, $meta_value); |
| 224 | 219 | } |
| 225 | 220 | $sql_query .= implode(' UNION ALL ', $sql_query_sel); |
| 226 | - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,PluginCheck.Security.DirectDB.UnescapedDBParameter -- $sql_query is built from $wpdb->prepare() fragments above; direct query required for bulk meta insert, not cached intentionally. | |
| 227 | 221 | $wpdb->query($sql_query); |
| 228 | 222 | } |
| 229 | 223 | |
| 230 | 224 | /* |