Нет описания

copy-delete-posts.php 44KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. <?php
  2. /**
  3. * Plugin Name: Copy & Delete Posts
  4. * Plugin URI: https://copy-delete-posts.com
  5. * Description: The best solution to easily make duplicates of your posts & pages, and delete them in one go.
  6. * Version: 1.2.1
  7. * Author: Copy Delete Posts
  8. * Author URI: https://copy-delete-posts.com/
  9. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10. // Exit if accessed directly.
  11. if (!defined('ABSPATH'))
  12. exit;
  13. /** –– **\
  14. * Opt-in.
  15. * @since 1.1.2
  16. */
  17. require_once 'analyst/main.php';
  18. analyst_init(array(
  19. 'client-id' => 'ovgxe3xq075ladbp',
  20. 'client-secret' => 'b4de5ed2ba7be687e233d152ec1e8fd116052ab0',
  21. 'base-dir' => __FILE__
  22. ));
  23. /** –– * */
  24. /** –– **\
  25. * Global variables and constants.
  26. * @since 1.0.0
  27. */
  28. // Plugin constants
  29. define('CDP_VERSION', '1.2.1');
  30. define('CDP_WP_VERSION', get_bloginfo('version'));
  31. define('CDP_SCRIPT_DEBUG', false);
  32. define('CDP_ROOT_DIR', __DIR__);
  33. define('CDP_ROOT_FILE', __FILE__);
  34. $cdp_plug_url = plugins_url('', __FILE__);
  35. load_plugin_textdomain('copy-delete-posts', null, dirname(plugin_basename(__FILE__)) . '/languages');
  36. // Other only admin stuff
  37. if (is_admin()) {
  38. // Set constant variables for this file
  39. $cdp_dir = dirname(__FILE__);
  40. $cdp_globals = get_option('_cdp_globals');
  41. $cdp_premium = 'copy-delete-posts-premium/copy-delete-posts-premium.php';
  42. // Try to show error while debugging
  43. if (CDP_SCRIPT_DEBUG === true) {
  44. error_reporting(E_ALL);
  45. ini_set('display_errors', 1);
  46. }
  47. }
  48. /** –– * */
  49. /** –– **\
  50. * Fired on plugin activation.
  51. * @since 1.0.0
  52. */
  53. register_activation_hook(__FILE__, function () {
  54. if (function_exists('activate_plugin')) {
  55. add_option('_cdp_redirect', true);
  56. $cdp_premium_path = WP_PLUGIN_DIR . '/copy-delete-posts-premium';
  57. $plugin = 'copy-delete-posts-premium/copy-delete-posts-premium.php';
  58. if (!is_plugin_active($plugin) && is_dir($cdp_premium_path))
  59. activate_plugin($plugin);
  60. }
  61. if (get_option('_cdp_review', false) == false) {
  62. $review = array(
  63. 'installed' => time(),
  64. 'users' => array()
  65. );
  66. update_option('_cdp_review', $review);
  67. }
  68. do_action('cdp_plugin_setup');
  69. });
  70. /** –– * */
  71. /** –– **\
  72. * Fired on plugin deactivation.
  73. * @since 1.0.0
  74. */
  75. register_deactivation_hook(__FILE__, function () {
  76. if (function_exists('deactivate_plugins')) {
  77. $plugin = 'copy-delete-posts-premium/copy-delete-posts-premium.php';
  78. if (is_plugin_active($plugin))
  79. add_action('update_option_active_plugins', function () {
  80. $plugin = 'copy-delete-posts-premium/copy-delete-posts-premium.php';
  81. deactivate_plugins($plugin);
  82. });
  83. }
  84. });
  85. /** –– * */
  86. /** –– **\
  87. * Fired on plugin load and check permissions.
  88. * @since 1.0.0
  89. */
  90. add_action('plugins_loaded', function () {
  91. do_action('cdp_loaded');
  92. });
  93. /** –– * */
  94. /** –– **\
  95. * Fired on any plugin upgrade (in case if it's ours)
  96. * @since 1.0.6
  97. */
  98. add_action('upgrader_process_complete', function () {
  99. if (get_option('_cdp_review', false) == false) {
  100. $review = array(
  101. 'installed' => time(),
  102. 'users' => array()
  103. );
  104. update_option('_cdp_review', $review);
  105. }
  106. });
  107. /** –– * */
  108. /** –– **\
  109. * Include all menus.
  110. * @since 1.0.0
  111. */
  112. add_action('cdp_loaded', function () {
  113. // Include footer banner
  114. include_once trailingslashit(__DIR__) . '/banner/misc.php';
  115. // Others
  116. if (cdp_check_permissions(wp_get_current_user()) == false) return;
  117. require_once plugin_dir_path(__FILE__) . 'menu/configuration.php';
  118. require_once plugin_dir_path(__FILE__) . 'menu/tooltips.php';
  119. require_once plugin_dir_path(__FILE__) . 'menu/variables.php';
  120. require_once plugin_dir_path(__FILE__) . 'menu/modal.php';
  121. require_once plugin_dir_path(__FILE__) . 'menu/notifications.php';
  122. require_once plugin_dir_path(__FILE__) . 'post/handler.php';
  123. // Review banner
  124. if (!is_dir(WP_PLUGIN_DIR . '/copy-delete-posts-premium')) {
  125. if (!(class_exists('Inisev\Subs\Inisev_Review') || class_exists('Inisev_Review'))) require_once CDP_ROOT_DIR . '/modules/review/review.php';
  126. $review_banner = new \Inisev\Subs\Inisev_Review(CDP_ROOT_FILE, CDP_ROOT_DIR, 'copy-delete-posts', 'Copy & Delete Posts', 'https://bit.ly/2VeAf2E', 'copy-delete-posts');
  127. }
  128. });
  129. /** –– **/
  130. /** –– **\
  131. * Admin Init
  132. * @since 1.0.0
  133. */
  134. add_action('admin_init', function () {
  135. if (cdp_check_permissions(wp_get_current_user()) == false)
  136. return;
  137. if (get_option('_cdp_redirect', false)) {
  138. delete_option('_cdp_redirect', false);
  139. wp_redirect(admin_url('admin.php?page=copy-delete-posts'));
  140. }
  141. global $cdp_premium;
  142. $cdp_premium_path = WP_PLUGIN_DIR . '/copy-delete-posts-premium';
  143. $cdp_premium_ver_path = WP_PLUGIN_DIR . '/copy-delete-posts-premium/version.txt';
  144. if (defined('CDP_PREMIUM_VERSION') && version_compare(CDP_PREMIUM_VERSION, CDP_VERSION, '!=')) {
  145. update_option('_cdp_mishmash', true);
  146. } else {
  147. if (is_dir($cdp_premium_path) && file_exists($cdp_premium_ver_path)) {
  148. $cdp_prem_ver_file = fopen($cdp_premium_ver_path, 'r') or false;
  149. $cdp_prem_ver = fgets($cdp_prem_ver_file);
  150. fclose($cdp_prem_ver_file);
  151. if ((trim($cdp_prem_ver) == CDP_VERSION) && !is_plugin_active($cdp_premium)) {
  152. activate_plugin($cdp_premium, '', false, true);
  153. // add_option('_cdp_redirect', false);
  154. }
  155. if (trim($cdp_prem_ver) == CDP_VERSION)
  156. update_option('_cdp_mishmash', false);
  157. }
  158. }
  159. if (is_plugin_active($cdp_premium) && !file_exists($cdp_premium_ver_path)) {
  160. if (is_plugin_active($cdp_premium))
  161. deactivate_plugins($cdp_premium, true);
  162. }
  163. });
  164. /** –– * */
  165. /** –– **\
  166. * Setup assets.
  167. * @since 1.0.0
  168. */
  169. add_action('admin_enqueue_scripts', function () {
  170. if (cdp_check_permissions(wp_get_current_user()) == false)
  171. return;
  172. if (function_exists('wp_doing_ajax') && wp_doing_ajax())
  173. return;
  174. global $cdp_plug_url;
  175. global $pagenow, $post;
  176. $screen = get_current_screen();
  177. $min = defined('CDP_SCRIPT_DEBUG') && CDP_SCRIPT_DEBUG ? '' : '.min';
  178. $allowed = ['post', 'edit-post', 'toplevel_page_copy-delete-posts', 'edit-page', 'page'];
  179. $at = ($screen->id != 'attachment');
  180. $g = get_option('_cdp_globals', array());
  181. if (array_key_exists('others', $g))
  182. $g = $g['others'];
  183. else
  184. $g = cdp_default_global_options();
  185. if (is_object($post))
  186. $type = $post->post_type;
  187. else
  188. $type = false;
  189. if (isset($g['cdp-menu-in-settings']) && $g['cdp-menu-in-settings'] == 'true') {
  190. ?>
  191. <style media="screen">
  192. #toplevel_page_copy-delete-posts { display: none; visibility: hidden; }
  193. </style>
  194. <?php
  195. }
  196. $ver = preg_replace('#[^\pL\pN/-]+#', '', CDP_VERSION);
  197. wp_enqueue_style('cdp-css-global', "{$cdp_plug_url}/assets/css/cdp-global{$min}.css", '', $ver);
  198. wp_enqueue_script('cdp-js-global', "{$cdp_plug_url}/assets/js/cdp-global{$min}.js", ['jquery'], $ver, true);
  199. cdp_load_localize_global_js();
  200. wp_enqueue_style('cdp-css-select', "{$cdp_plug_url}/assets/css/cdp-select{$min}.css", '', $ver);
  201. wp_enqueue_script('cdp-js-select', "{$cdp_plug_url}/assets/js/cdp-select{$min}.js", '', $ver, true);
  202. wp_enqueue_style('cdp-tooltips-css', "{$cdp_plug_url}/assets/css/cdp.tooltip{$min}.css", '', $ver);
  203. wp_enqueue_script('cdp-tooltips', "{$cdp_plug_url}/assets/js/cdp.tooltip{$min}.js", '', $ver, true);
  204. if (method_exists($screen, 'is_block_editor')) {
  205. if (!$screen->is_block_editor() && $pagenow == 'post.php' && $at) {
  206. if (isset($g['cdp-display-edit']) && $g['cdp-display-edit'] == 'true') {
  207. $a = ($type == 'post' && $g['cdp-content-posts'] == 'true');
  208. $b = ($type == 'page' && $g['cdp-content-pages'] == 'true');
  209. $c = ($type != 'post' && $type != 'page' && $g['cdp-content-custom'] == 'true');
  210. if (($a || $b || $c) && $pagenow != 'post-new.php')
  211. wp_enqueue_style('cdp-editor', "{$cdp_plug_url}/assets/css/cdp-editor{$min}.css", '', $ver);
  212. }
  213. }
  214. }
  215. $ver = preg_replace('#[^\pL\pN/-]+#', '', CDP_VERSION);
  216. if ((!$screen || !in_array($screen->id, $allowed)) && !($pagenow == 'edit.php' || $pagenow == 'post.php'))
  217. return;
  218. wp_enqueue_style('cdp-css', "{$cdp_plug_url}/assets/css/cdp{$min}.css", '', $ver);
  219. wp_enqueue_style('cdp-css-user', "{$cdp_plug_url}/assets/css/cdp-user{$min}.css", '', $ver);
  220. wp_enqueue_script('cdp-icPagination', "{$cdp_plug_url}/assets/js/cdp-icPagination{$min}.js", '', $ver);
  221. wp_enqueue_script('cdp', "{$cdp_plug_url}/assets/js/cdp{$min}.js", '', $ver, true);
  222. $cdpJSArgs = [
  223. 'strNoItems' => __('No items to show, try with other filters!', 'copy-delete-posts'),
  224. 'strIntroSaveIssue' => __('Something went wrong and we couldn\'t save intro settings!', 'copy-delete-posts'),
  225. 'strIntroSaveIssue2' => __('Something went wrong and we couldn\'t save intro settings.', 'copy-delete-posts'),
  226. 'strIntroUpdateIssue' => __('Something went wrong and we couldn\'t update intro settings – try again!', 'copy-delete-posts'),
  227. 'strIntroUpdateIssue2' => __('Something went wrong and we couldn\'t update intro settings. – Please check console for more info.', 'copy-delete-posts'),
  228. 'strSettingsSaved' => __('All your settings were saved!', 'copy-delete-posts'),
  229. 'strSettingsSaveIssue' => __('Something went wrong and we couldn\'t save your settings.', 'copy-delete-posts'),
  230. 'strSettingsSaveIssue2' => __('Something went wrong and we couldn\'t save your settings. – Please check console for more info.', 'copy-delete-posts'),
  231. 'strTogglableName' => __('(Name of original)', 'copy-delete-posts'),
  232. 'strCopyNumIssue' => __('You need to insert positive number for copies.', 'copy-delete-posts'),
  233. 'strCopyPostIssue' => __('Something went wrong and we couldn\'t copy this post – please try again!', 'copy-delete-posts'),
  234. 'strCopyPostIssueConsInfo' => __('Something went wrong and we couldn\'t copy this post. – See dev console for more info.', 'copy-delete-posts'),
  235. 'strTooltipBtnIssue' => __('Couldn\'t recognize that button, please try again.', 'copy-delete-posts'),
  236. 'strSelectedProfIssue' => __('Unable to recognize selected profile, please try again.', 'copy-delete-posts'),
  237. 'strSelectedProfGetIssue' => __('Something went wrong and we couldn\'t get profile settings. – Check console for more details', 'copy-delete-posts'),
  238. 'strConsLogErr' => __('Copy & Delete Post – Error', 'copy-delete-posts'),
  239. 'strSelectedProfGetIssue2' => __('Something went wrong and we couldn\'t get profile settings – please try again!', 'copy-delete-posts'),
  240. 'strCopyInProgress' => __('Copy in progress...', 'copy-delete-posts'),
  241. 'strServerDataIssue' => __('There was an error while getting data from server, please try again.', 'copy-delete-posts'),
  242. 'strPostListIssue' => __('Something went wrong and we couldn\'t get post list. – Please check console for more info.', 'copy-delete-posts'),
  243. 'strCheckDuplicatesSearch' => __('Please, check for: which duplicates you are looking for', 'copy-delete-posts'),
  244. 'strServerConnectIssue' => __('Cannot connect to the server, premium filters will not be applied.', 'copy-delete-posts'),
  245. 'strFilterNotSelected' => __('You did not select any filter.<br>Click <a href="#" class="cdp-show-the-copies">here</a> to show all copies (of the selected post type) made by this plugin.', 'copy-delete-posts'),
  246. 'strNoDataForFilter' => __('No posts/pages meeting the current filter conditions.', 'copy-delete-posts'),
  247. 'strCheckSteps' => __('Please check that you completed all steps, before this task!', 'copy-delete-posts'),
  248. 'strSelectPostToDel' => __('Nothing to do here, please select at least one post to delete.', 'copy-delete-posts'),
  249. 'strFieldWrongCount' => __('You have wrong count in throttling field, please fix.', 'copy-delete-posts'),
  250. 'strDeletionProcessStarted' => __('Deletion process started, you can close this page now and wait till the process ends!', 'copy-delete-posts'),
  251. 'strDeletionTaskStart' => __('Something went wrong and we couldn\'t setup the deletion task.', 'copy-delete-posts'),
  252. 'strDeletionTaskEnd' => __('– Please try without throttling.', 'copy-delete-posts'),
  253. 'strDeletionTaskConsInfo' => __('Something went wrong and we couldn\'t setup the deletion task. – Please check console for more info.', 'copy-delete-posts'),
  254. 'strLicenseKeyEmpty' => __('Please enter license key, currently it is empty.', 'copy-delete-posts'),
  255. 'strLicenseActiveReloading' => __('License is already active, let us reload the page!', 'copy-delete-posts'),
  256. 'strLicenseValidPressBtn' => __('License is valid, press the button again to activate!', 'copy-delete-posts'),
  257. 'strUnknownRespRefreshPage' => __('Unknown response, please try refresh the page!', 'copy-delete-posts'),
  258. 'strSendRequestIssue' => __('Something went wrong and we couldn\'t send request, please try refresh page and try again.', 'copy-delete-posts'),
  259. 'strSendRequestIssue2' => __('Something went wrong and we couldn\'t send request, are you connected to the internet?', 'copy-delete-posts'),
  260. 'strIncludingHtml' => __('<b>including</b> empty', 'copy-delete-posts'),
  261. 'strIncludingHtml2' => __('only if <u><b>not</b></u> empty', 'copy-delete-posts'),
  262. 'strTogglableNameChange' => __('Change it to (Name of original)', 'copy-delete-posts'),
  263. 'strTogglableNameChangeBlank' => __('Change it to blank', 'copy-delete-posts'),
  264. 'strDeletingPosts' => __('Deleting Posts', 'copy-delete-posts'),
  265. 'strAutoCleanPosts' => __('Auto Cleaning-up', 'copy-delete-posts'),
  266. 'strKill' => __('Kill', 'copy-delete-posts'),
  267. 'strDeletedPosts' => __('Deleted Posts', 'copy-delete-posts'),
  268. 'strAutoCleanedPosts' => __('Auto Cleaned-up', 'copy-delete-posts'),
  269. 'strHide' => __('Hide', 'copy-delete-posts'),
  270. 'strDefCopySettingsStart' => __('Define your copy settings', 'copy-delete-posts'),
  271. 'strDefCopySettingsLink' => __('here', 'copy-delete-posts'),
  272. 'strCopyToOtherSiteHtml' => __('If you’re on a multisite you can copy it to other sites with the Premium Plugin. <a href="https://sellcodes.com/CylMIdJD" target="_blank">Order it now!</a>', 'copy-delete-posts'),
  273. 'strPremFeatureHtml' => __('This is a Premium Feature.<br><a href="https://sellcodes.com/CylMIdJD" target="_blank">Check it out and upgrade today</a>,<br>we made it <b>really affordable!</b>', 'copy-delete-posts'),
  274. 'strPreOrderHtml' => __('You can copy it to other sites with the Premium Plugin.<br><a href="https://sellcodes.com/CylMIdJD" target="_blank">Pre-order it now</a>', 'copy-delete-posts'),
  275. 'strMultisiteCanCopy' => __('If you’re on a multisite you can copy it to other sites.', 'copy-delete-posts'),
  276. 'strChangeTypeOfCopy' => __('Change the type of this copy <span class="cdp-premium-icon cdp-big-icon"></span>', 'copy-delete-posts'),
  277. 'strPostDuplicateOf' => __('This post is a duplicate of', 'copy-delete-posts'),
  278. 'strAreYouSure' => __('Are you REALLY sure?', 'copy-delete-posts'),
  279. 'strYouAreCrazy' => __('You\'re crazy! – Here is the output:', 'copy-delete-posts'),
  280. 'strDebugOutputEnd' => __('–––––––––––––- END OF THE DEBUG OUTPUT –––––––––––––- ', 'copy-delete-posts'),
  281. 'copySuccessfull' => __('Copy to clipboard was successfull.', 'copy-delete-posts'),
  282. 'copyFailed' => __('Copy to clipboard failed, your browser does not support this function.', 'copy-delete-posts'),
  283. ];
  284. wp_localize_script('cdp', 'cdpJS', $cdpJSArgs);
  285. wp_enqueue_script('cdp-modal', "{$cdp_plug_url}/assets/js/cdp-modal{$min}.js", '', $ver, true);
  286. $cdpModalJSArgs = [
  287. 'strRowCopyIssue' => __('Please select at least one row to copy.', 'copy-delete-posts'),
  288. 'strRowCopyTryAgain' => __('Please select at least one row to copy and try again.', 'copy-delete-posts'),
  289. 'strSettCopyIssue' => __('Please select basic settings for this copy.', 'copy-delete-posts'),
  290. 'strPostCopyIssue' => __('Something went wrong and we couldn\'t copy this post – please try again!', 'copy-delete-posts'),
  291. 'strPostCopyIssueConsoleInfo' => __('Something went wrong and we couldn\'t copy this post. – See dev console for more info.', 'copy-delete-posts'),
  292. 'strRecogBtnIssue' => __('Couldn\'t recognize that button, please try again.', 'copy-delete-posts'),
  293. 'strCopyInProgress' => __('Copy in progress...', 'copy-delete-posts'),
  294. ];
  295. wp_localize_script('cdp-modal', 'cdpModalJS', $cdpModalJSArgs);
  296. wp_enqueue_script('cdp-bulk', "{$cdp_plug_url}/assets/js/cdp-bulk{$min}.js", '', $ver, true);
  297. $cdpBulkJSArgs = ['strOptCopy' => __('Copy', 'copy-delete-posts')];
  298. wp_localize_script('cdp-bulk', 'cdpBulkJS', $cdpBulkJSArgs);
  299. });
  300. /** –– * */
  301. /** –– **\
  302. * Setup assets (not admin).
  303. * @since 1.0.0
  304. */
  305. add_action('wp_enqueue_scripts', function () {
  306. if (cdp_check_permissions(wp_get_current_user()) == false)
  307. return;
  308. if ((function_exists('wp_doing_ajax') && wp_doing_ajax()) || (!(is_single() || is_page())))
  309. return;
  310. global $cdp_plug_url;
  311. $ver = preg_replace('#[^\pL\pN/-]+#', '', CDP_VERSION);
  312. $min = defined('CDP_SCRIPT_DEBUG') && CDP_SCRIPT_DEBUG ? '' : '.min';
  313. wp_enqueue_script('jquery-ui-draggable');
  314. wp_enqueue_script('jquery-ui-droppable');
  315. wp_enqueue_script('jquery-ui-sortable');
  316. wp_enqueue_style('cdp-css-global', "{$cdp_plug_url}/assets/css/cdp-global{$min}.css", '', $ver);
  317. wp_enqueue_script('cdp-js-global', "{$cdp_plug_url}/assets/js/cdp-global{$min}.js", ['jquery'], $ver, true);
  318. cdp_load_localize_global_js();
  319. wp_enqueue_style('cdp-css', "{$cdp_plug_url}/assets/css/cdp{$min}.css", '', $ver);
  320. wp_enqueue_style('cdp-css-user', "{$cdp_plug_url}/assets/css/cdp-user{$min}.css", '', $ver);
  321. wp_enqueue_script('cdp', "{$cdp_plug_url}/assets/js/cdp{$min}.js", ['jquery'], $ver, true);
  322. wp_enqueue_script('cdp-tooltips', "{$cdp_plug_url}/assets/js/cdp.tooltip{$min}.js", '', $ver, true);
  323. wp_enqueue_style('cdp-tooltips-css', "{$cdp_plug_url}/assets/css/cdp.tooltip{$min}.css", '', $ver);
  324. wp_enqueue_script('cdp-modal', "{$cdp_plug_url}/assets/js/cdp-modal{$min}.js", ['jquery'], $ver, true);
  325. wp_enqueue_script('cdp-js-user', "{$cdp_plug_url}/assets/js/cdp-user{$min}.js", '', $ver, true);
  326. wp_enqueue_style('cdp-css-select', "{$cdp_plug_url}/assets/css/cdp-select{$min}.css", '', $ver);
  327. wp_enqueue_script('cdp-js-select', "{$cdp_plug_url}/assets/js/cdp-select{$min}.js", '', $ver, true);
  328. });
  329. /** –– * */
  330. /** –– **\
  331. * Setup assets (for gutenberg).
  332. * @since 1.0.0
  333. */
  334. add_action('enqueue_block_editor_assets', function () {
  335. if (cdp_check_permissions(wp_get_current_user()) == false)
  336. return;
  337. global $post;
  338. global $cdp_plug_url;
  339. $min = defined('CDP_SCRIPT_DEBUG') && CDP_SCRIPT_DEBUG ? '' : '.min';
  340. $g = get_option('_cdp_globals', array());
  341. if (array_key_exists('others', $g))
  342. $g = $g['others'];
  343. else
  344. $g = cdp_default_global_options();
  345. $ver = preg_replace('#[^\pL\pN/-]+#', '', CDP_VERSION);
  346. if (is_object($post))
  347. $type = $post->post_type;
  348. else
  349. $type = false;
  350. $a = ($type == 'post' && $g['cdp-content-posts'] == 'true');
  351. $b = ($type == 'page' && $g['cdp-content-pages'] == 'true');
  352. $c = ($type != 'post' && $type != 'page' && $g['cdp-content-custom'] == 'true');
  353. if ((isset($g['cdp-display-gutenberg']) && $g['cdp-display-gutenberg'] == 'true') && ($a || $b || $c)) {
  354. wp_enqueue_style('cdp-gutenberg', "{$cdp_plug_url}/assets/css/cdp-gutenberg{$min}.css", '', $ver);
  355. wp_enqueue_script('cdp-js-gutenberg', "{$cdp_plug_url}/assets/js/cdp-gutenberg{$min}.js", ['jquery'], $ver, true);
  356. $cdpGutenbergJSArgs = ['cdpCopy' => __('Copy this', 'copy-delete-posts')];
  357. wp_localize_script('cdp-js-gutenberg', 'cdpGutenbergJS', $cdpGutenbergJSArgs);
  358. }
  359. });
  360. /** –– * */
  361. /** –– **\
  362. * Settings and menu initializer.
  363. * @since 1.0.0
  364. */
  365. add_action('admin_menu', function () {
  366. if (cdp_check_permissions(wp_get_current_user()) == false)
  367. return;
  368. // Menu icon
  369. $icon_url = plugin_dir_url(__FILE__) . 'assets/imgs/icon.png';
  370. // Main menu slug
  371. $parentSlug = 'copy-delete-posts';
  372. // Globals
  373. $g = get_option('_cdp_globals', array());
  374. if (array_key_exists('others', $g))
  375. $g = $g['others'];
  376. else
  377. $g = cdp_default_global_options();
  378. // Main menu hook
  379. add_menu_page(__('Copy & Delete Posts', 'copy-delete-posts'), __('<span id="cdp-menu">Copy & Delete Posts</span>', 'copy-delete-posts'), 'read', $parentSlug, 'cdp_configuration', $icon_url, $position = 98);
  380. if (isset($g['cdp-menu-in-settings']) && $g['cdp-menu-in-settings'] == 'true') {
  381. add_submenu_page('tools.php', __('Copy & Delete Posts Menu', 'copy-delete-posts'), __('<span id="cdp-menu">Copy & Delete Posts</span>', 'copy-delete-posts'), 'read', 'copy-delete-posts', 'cdp_configuration', 3);
  382. }
  383. // Remove default submenu by menu
  384. remove_submenu_page($parentSlug, $parentSlug);
  385. });
  386. /** –– * */
  387. /** –– **\
  388. * Add copy option to Quick Actions of Posts.
  389. * @since 1.0.0
  390. */
  391. add_filter('post_row_actions', function ($actions, $post) {
  392. if (cdp_check_permissions(wp_get_current_user()) == false)
  393. return $actions;
  394. // Get global options and post type
  395. $g = get_option('_cdp_globals', array());
  396. if (array_key_exists('others', $g))
  397. $g = $g['others'];
  398. else
  399. $g = cdp_default_global_options();
  400. $type = $post->post_type;
  401. // If user want to see the copy buton here pass
  402. if (isset($g['cdp-display-posts']) && $g['cdp-display-posts'] == 'true')
  403. if (($type == 'post' && $g['cdp-content-posts'] == 'true') || ($type != 'post' && $g['cdp-content-custom'] == 'true'))
  404. $actions['cdp_copy'] = "<a href='#'><span class='cdp-copy-button cdp-tooltip-copy' x='" . $type . "' title='" . __('test', 'copy-delete-posts') . "' data-cdp-id='{$post->ID}'>" . __('Copy', 'copy-delete-posts') . "</span></a>";
  405. return $actions;
  406. }, 10, 2);
  407. /** –– * */
  408. /** –– **\
  409. * Add copy option to Quick Actions of Pages.
  410. * @since 1.0.0
  411. */
  412. add_filter('page_row_actions', function ($actions, $page) {
  413. if (cdp_check_permissions(wp_get_current_user()) == false)
  414. return;
  415. // Get global options and post type
  416. $g = get_option('_cdp_globals', array());
  417. if (array_key_exists('others', $g))
  418. $g = $g['others'];
  419. else
  420. $g = cdp_default_global_options();
  421. $type = $page->post_type;
  422. // If user want to see the copy buton here pass
  423. if (isset($g['cdp-display-posts']) && $g['cdp-display-posts'] == 'true')
  424. if (($type == 'page' && $g['cdp-content-pages'] == 'true') || ($type != 'page' && $g['cdp-content-custom'] == 'true'))
  425. $actions['cdp_copy'] = "<a href='#'><span class='cdp-copy-button cdp-tooltip-copy' title='" . __('test', 'copy-delete-posts') . "' data-cdp-id='{$page->ID}'>" . __('Copy', 'copy-delete-posts') . "</span></a>";
  426. return $actions;
  427. }, 10, 2);
  428. /** –– * */
  429. /** –– **\
  430. * Add copy option to Bulk Actions of Posts.
  431. * @since 1.0.0
  432. */
  433. add_filter('bulk_actions-edit-post', function ($bulk_actions) {
  434. if (cdp_check_permissions(wp_get_current_user()) == false)
  435. return;
  436. $g = get_option('_cdp_globals', array());
  437. if (array_key_exists('others', $g))
  438. $g = $g['others'];
  439. else
  440. $g = cdp_default_global_options();
  441. if (isset($g['cdp-display-bulk']) && $g['cdp-display-bulk'] == 'true')
  442. $bulk_actions['cdp_bulk_copy'] = __('Copy', 'copy-delete-posts');
  443. return $bulk_actions;
  444. });
  445. /** –– * */
  446. /** –– **\
  447. * Add copy option to Bulk Actions of Pages.
  448. * @since 1.0.0
  449. */
  450. add_filter('bulk_actions-edit-page', function ($bulk_actions) {
  451. if (cdp_check_permissions(wp_get_current_user()) == false)
  452. return;
  453. $g = get_option('_cdp_globals', array());
  454. if (array_key_exists('others', $g))
  455. $g = $g['others'];
  456. else
  457. $g = cdp_default_global_options();
  458. if (isset($g['cdp-display-bulk']) && $g['cdp-display-bulk'] == 'true')
  459. $bulk_actions['cdp_bulk_copy'] = __('Copy', 'copy-delete-posts');
  460. return $bulk_actions;
  461. });
  462. /** –– * */
  463. /** –– **\
  464. * Add copy option to admin bar inside preview.
  465. * @since 1.0.0
  466. */
  467. add_action('admin_bar_menu', function ($admin_bar) {
  468. if (cdp_check_permissions(wp_get_current_user()) == false)
  469. return;
  470. $screen = ((function_exists('get_current_screen') ? get_current_screen() : false));
  471. $screens = ['post', 'page'];
  472. if (!(is_single() || is_page() || (isset($screen) && ($screen != false && in_array($screen->id, $screens)))))
  473. return;
  474. $g = get_option('_cdp_globals', array());
  475. if (array_key_exists('others', $g))
  476. $g = $g['others'];
  477. else
  478. $g = cdp_default_global_options();
  479. global $post;
  480. if (is_object($post))
  481. $type = $post->post_type;
  482. else
  483. $type = false;
  484. $a = ($type == 'post' && $g['cdp-content-posts'] == 'true');
  485. $b = ($type == 'page' && $g['cdp-content-pages'] == 'true');
  486. $c = ($type != 'post' && $type != 'page' && $g['cdp-content-custom'] == 'true');
  487. if (isset($g['cdp-display-admin']) && $g['cdp-display-admin'] == 'false')
  488. return;
  489. global $cdp_plug_url;
  490. if ($a || $b || $c) {
  491. $icon = '<span class="cdp-admin-bar-icon" data-plug-path="' . $cdp_plug_url . '" data-this-id="' . get_the_ID() . '"></span>';
  492. $admin_bar->add_menu(array(
  493. 'id' => '#cdp-copy-bar-x',
  494. 'parent' => null,
  495. 'group' => null,
  496. 'title' => $icon . __('Copy this', 'copy-delete-posts'),
  497. 'href' => '#',
  498. 'meta' => array('class' => 'cdp-admin-bar-copy', 'target' => '_self')
  499. ));
  500. }
  501. }, 80);
  502. /** –– * */
  503. /** –– **\
  504. * Add notification to admin bar.
  505. * @since 1.0.0
  506. */
  507. add_action('admin_bar_menu', function ($admin_bar) {
  508. if (cdp_check_permissions(wp_get_current_user()) == false)
  509. return;
  510. if (!is_admin())
  511. return;
  512. if (!function_exists('cdp_notifications_menu'))
  513. require_once plugin_dir_path(__FILE__) . 'menu/notifications.php';
  514. if (function_exists('cdp_notifications_menu')) {
  515. $data = cdp_notifications_menu();
  516. $admin_bar->add_menu(array(
  517. 'id' => 'wp-admin-copy-and-delete-posts',
  518. 'parent' => null,
  519. 'group' => null,
  520. 'title' => $data['html'],
  521. 'href' => '#',
  522. 'meta' => array(
  523. 'class' => 'cdp-admin-bar-noti menupop' . (($data['in_list'] == 0) ? ' cdp-noti-hide' : ''),
  524. 'target' => '_self'
  525. )
  526. ));
  527. }
  528. }, 80);
  529. /** –– * */
  530. /** –– **\
  531. * This function adds version info.
  532. * @since 1.0.0
  533. */
  534. add_action('wp_head', function () {
  535. echo '<meta name="cdp-version" content="' . CDP_VERSION . '" />';
  536. });
  537. /** –– * */
  538. /** –– **\
  539. * This function adds thickbox modal to preview and view pages.
  540. * @since 1.0.0
  541. */
  542. add_action('wp_footer', function () {
  543. if (cdp_check_permissions(wp_get_current_user()) == false)
  544. return;
  545. $g = get_option('_cdp_globals', array());
  546. if (array_key_exists('others', $g))
  547. $g = $g['others'];
  548. else
  549. $g = cdp_default_global_options();
  550. if (isset($g['cdp-display-admin']) && $g['cdp-display-admin'] == 'false')
  551. return;
  552. global $cdp_plug_url, $post;
  553. $post_id = false;
  554. if (isset($post->ID))
  555. $post_id = $post->ID;
  556. $screen = ((function_exists('get_current_screen')) ? get_current_screen() : false);
  557. $profiles = get_option('_cdp_profiles');
  558. if (is_single() || is_page()) {
  559. $hx = false;
  560. if ($g['cdp-premium-hide-tooltip'] == 'true')
  561. $hx = true;
  562. cdp_vars($hx, $cdp_plug_url, $post_id);
  563. cdp_modal($screen, $profiles);
  564. }
  565. });
  566. /** –– * */
  567. /** –– **\
  568. * Add prepared HTML for tooltips and other info.
  569. * @since 1.0.0
  570. */
  571. add_action('admin_notices', function () {
  572. if (cdp_check_permissions(wp_get_current_user()) == false)
  573. return;
  574. global $post, $cdp_plug_url, $cdp_globals, $pagenow;
  575. $post_id = false;
  576. $hasParent = false;
  577. $screen = get_current_screen();
  578. $profiles = get_option('_cdp_profiles');
  579. $deny = ['edit-page', 'edit-post'];
  580. $hx = false;
  581. if (!in_array($screen->id, $deny)) {
  582. if (isset($post->ID)) {
  583. $post_id = $post->ID;
  584. $meta = get_post_meta($post->ID, '_cdp_origin');
  585. $site = get_post_meta($post->ID, '_cdp_origin_site');
  586. if ($cdp_globals && array_key_exists('others', $cdp_globals) && array_key_exists('cdp-references-post', $cdp_globals['others'])) {
  587. if ($cdp_globals['others']['cdp-references-edit'] == 'true') {
  588. if (function_exists('switch_to_blog') && $site)
  589. switch_to_blog($site);
  590. if (array_key_exists(0, $meta) && get_post_status($meta[0])) {
  591. $parentTitle = get_the_title($meta[0]);
  592. $link = get_post_permalink($meta[0]);
  593. $hasParent = array(
  594. 'title' => $parentTitle,
  595. 'link' => $link
  596. );
  597. }
  598. if (function_exists('restore_current_blog') && $site)
  599. restore_current_blog();
  600. }
  601. }
  602. }
  603. }
  604. if ($cdp_globals && array_key_exists('others', $cdp_globals) && array_key_exists('cdp-premium-hide-tooltip', $cdp_globals['others']) && $cdp_globals['others']['cdp-premium-hide-tooltip'] == 'true') {
  605. $hx = true;
  606. }
  607. if (get_option('_cdp_show_copy', false)) {
  608. echo '<span style="display: none; visibility: hidden;" id="cdp-show-copy-banner" data-value="true"></span>';
  609. delete_option('_cdp_show_copy');
  610. }
  611. if ($pagenow == 'edit.php')
  612. $post_id = false;
  613. cdp_vars($hx, $cdp_plug_url, $post_id, $hasParent, true);
  614. cdp_tooltip_content($profiles);
  615. cdp_modal($screen, $profiles);
  616. });
  617. /** –– * */
  618. /** –– **\
  619. * Add button in standard editor.
  620. * @since 1.0.0
  621. */
  622. add_action('post_submitbox_start', function () {
  623. if (cdp_check_permissions(wp_get_current_user()) == false)
  624. return;
  625. $g = get_option('_cdp_globals', array());
  626. if (array_key_exists('others', $g))
  627. $g = $g['others'];
  628. else
  629. $g = cdp_default_global_options();
  630. if (isset($g['cdp-display-edit']) && $g['cdp-display-edit'] == 'false')
  631. return;
  632. global $post, $pagenow;
  633. if (is_object($post))
  634. $type = $post->post_type;
  635. else
  636. $type = false;
  637. $a = ($type == 'post' && $g['cdp-content-posts'] == 'true');
  638. $b = ($type == 'page' && $g['cdp-content-pages'] == 'true');
  639. $c = ($type != 'post' && $type != 'page' && $g['cdp-content-custom'] == 'true');
  640. if (($a || $b || $c) && $pagenow != 'post-new.php')
  641. echo '<div id="cdp-copy-btn"><a class="cdp-copy-btn-editor" href="#">' . __('Copy this post', 'copy-delete-posts') . '</a></div>';
  642. });
  643. /** –– * */
  644. /** –– **\
  645. * Add hook for cron (deletion).
  646. * @since 1.0.0
  647. */
  648. add_action('cdp_cron_delete', function ($args = false) {
  649. $ids = $args['ids'];
  650. $trash = $args['trash'];
  651. $site = (array_key_exists('site', $args)) ? $args['site'] : '-1';
  652. $tok = $args['token']['token'];
  653. $tsk = $args['token']['tsk'];
  654. if ($args == false)
  655. return;
  656. $cdp_cron = get_option('_cdp_crons');
  657. if (!isset($cdp_cron[$tok]) || !$cdp_cron[$tok])
  658. return;
  659. $auit = $cdp_cron[$tok]['auit'];
  660. $auitd = $cdp_cron[$tok]['auitd'];
  661. $areWePro = areWePro(true, '/handler/crons.php', true);
  662. if ($auit == true && $areWePro && function_exists('cdpp_make_redirect'))
  663. cdpp_make_redirect($ids, $auitd);
  664. if ($trash == true && $areWePro && function_exists('cdpp_crons_trash_post'))
  665. cdpp_crons_trash_post($ids);
  666. else
  667. foreach ($ids as $i => $id)
  668. wp_delete_post($id, true);
  669. $cdp_cron[$tok]['tasks'][$tsk] = current_time('timestamp');
  670. $falsed = false;
  671. $last = false;
  672. $i = 0;
  673. $size = sizeof($cdp_cron[$tok]['tasks']);
  674. foreach ($cdp_cron[$tok]['tasks'] as $otsk => $val) {
  675. if ($val == false)
  676. $falsed = true;
  677. $i++;
  678. if ($i == ($size - 1))
  679. $last = $otsk;
  680. }
  681. if ($tsk == '-0' || $last == $tsk || $falsed == false || $cdp_cron[$tok]['tasks'][$last] != false) {
  682. $cdp_cron[$tok]['done'] = current_time('timestamp');
  683. $cdp_cron[$tok]['data'] = array('formated-date' => date('d M Y, H:i:s'));
  684. if (array_key_exists('del_size', $cdp_cron[$tok])) {
  685. $cdp_cron[$tok]['data']['amount'] = $cdp_cron[$tok]['del_size'];
  686. $cdp_cron[$tok]['data']['text'] = __('Manual Cleanup removed ', 'copy-delete-posts') . $cdp_cron[$tok]['del_size'] . ' post(s).';
  687. }
  688. $cdp_cron[$tok]['shown'] = false;
  689. }
  690. update_option('_cdp_crons', $cdp_cron);
  691. });
  692. /** –– * */
  693. /** –– **\
  694. * Check if user is permmited to use this plugin.
  695. * @since 1.0.0
  696. * @param $user = current_user = object
  697. *
  698. * @return boolean
  699. */
  700. function cdp_check_permissions($user = array()) {
  701. if (!isset($user) || empty($user))
  702. return false;
  703. $access = false;
  704. $access_roles = get_option('_cdp_globals');
  705. if (!isset($access_roles['roles']))
  706. $access_roles = array();
  707. foreach ($user->roles as $role => $name) {
  708. if ($name == 'administrator' || (isset($access_roles['roles'][$name]) && $access_roles['roles'][$name] == 'true')) {
  709. $access = true;
  710. break;
  711. }
  712. }
  713. return $access;
  714. }
  715. /** –– * */
  716. /** –– **\
  717. * First run of the plugin setup default options for Default profile
  718. * @since 1.0.0
  719. */
  720. add_action('cdp_plugin_setup', 'cdp_setup_default_profile');
  721. function cdp_setup_default_profile() {
  722. $current = get_option('_cdp_globals');
  723. $isSetup = get_option('_cdp_default_setup');
  724. if (($current != false && array_key_exists('default', $current)) || $isSetup)
  725. return;
  726. $already = array();
  727. $globals = array();
  728. $already['default'] = cdp_default_options();
  729. $globals['others'] = cdp_default_global_options();
  730. $s1 = update_option('_cdp_globals', $globals);
  731. $s2 = update_option('_cdp_profiles', $already);
  732. if ($s1 || $s2)
  733. update_option('_cdp_default_setup', true);
  734. }
  735. /** –– * */
  736. function cdp_load_localize_global_js() {
  737. $cdpGlobalJSArgs = [
  738. 'strDissmisIssue' => __('There was an issue while dismissing banner, please do it next time again.', 'copy-delete-posts'),
  739. 'strDissmisRequestIssue' => __('Cannot send dismiss request. Are you connected to the internet?', 'copy-delete-posts'),
  740. 'strReviewReview' => __('Thank you very much for the review, this banner will not appear again!', 'copy-delete-posts'),
  741. 'strReviewAlready' => __('Thank you very much for the review, this banner will not appear again!', 'copy-delete-posts'),
  742. 'strReviewLater' => __('Alright! We will ask you again in 14 days!', 'copy-delete-posts'),
  743. 'strReviewDefault' => __('This banner will not appear again, if any feature is missing you can ask for it on our support forum!', 'copy-delete-posts'),
  744. 'strTasksCleared' => __('Tasks cleared!', 'copy-delete-posts'),
  745. 'strTasksUpdateIssue' => __('We couldn\'t update task list, please try again later or kill tasks individualy.', 'copy-delete-posts'),
  746. 'strTasksUpdateIssue2' => __('We couldn\'t update task list, please try again later or kill tasks individualy.', 'copy-delete-posts'),
  747. 'strTaskHide' => __('The task has been hidden', 'copy-delete-posts'),
  748. 'strTaskHideIssue' => __('There was an error and we couldn\'t hide the task.', 'copy-delete-posts'),
  749. 'strTaskHideIssue2' => __('There was an error and we couldn\'t hide the task.', 'copy-delete-posts'),
  750. 'strTaskKill' => __('The task has been killed', 'copy-delete-posts'),
  751. 'strTaskKillIssue' => __('There was an error and we couldn\'t kill the task.', 'copy-delete-posts'),
  752. 'strTaskKillIssue2' => __('There was an error and we couldn\'t kill the task.', 'copy-delete-posts'),
  753. 'strCDPInstallSuccess' => __('Plugin has been installed successfully, feel free to check those awesome features!', 'copy-delete-posts'),
  754. 'strCDPInfo' => __('Copy & Delete Posts', 'copy-delete-posts'),
  755. 'strCDPInfoPremium' => __('Premium', 'copy-delete-posts'),
  756. 'strHideBannerNow' => __('It will hide this banner just for now.', 'copy-delete-posts'),
  757. 'strErrWithNotif' => __('There was an error with this notification.', 'copy-delete-posts'),
  758. 'strCDPInfo2' => __('Copy & Delete Posts', 'copy-delete-posts'),
  759. ];
  760. wp_localize_script('cdp-js-global', 'cdpGlobalJS', $cdpGlobalJSArgs);
  761. }
  762. /** –– **\
  763. * Default settings for unset profiles
  764. * @since 1.0.0
  765. */
  766. function cdp_default_options() {
  767. return array(
  768. 'title' => 'true',
  769. 'date' => 'false',
  770. 'status' => 'false',
  771. 'slug' => 'true',
  772. 'excerpt' => 'true',
  773. 'content' => 'true',
  774. 'f_image' => 'true',
  775. 'template' => 'true',
  776. 'format' => 'true',
  777. 'author' => 'true',
  778. 'password' => 'true',
  779. 'attachments' => 'false',
  780. 'children' => 'false',
  781. 'comments' => 'false',
  782. 'menu_order' => 'true',
  783. 'category' => 'true',
  784. 'post_tag' => 'true',
  785. 'taxonomy' => 'true',
  786. 'nav_menu' => 'true',
  787. 'link_category' => 'true',
  788. 'all_metadata' => 'false',
  789. 'names' => array(
  790. 'prefix' => '',
  791. 'suffix' => '#[Counter]',
  792. 'format' => '1',
  793. 'custom' => 'm/d/Y',
  794. 'display' => 'Default'
  795. ),
  796. 'usmplugin' => 'false',
  797. 'yoast' => 'false',
  798. 'woo' => 'false'
  799. );
  800. }
  801. function cdp_default_global_options() {
  802. return array(
  803. 'cdp-content-pages' => 'true',
  804. 'cdp-content-posts' => 'true',
  805. 'cdp-content-custom' => 'true',
  806. 'cdp-display-posts' => 'true',
  807. 'cdp-display-edit' => 'true',
  808. 'cdp-display-admin' => 'true',
  809. 'cdp-display-bulk' => 'true',
  810. 'cdp-display-gutenberg' => 'true',
  811. 'cdp-references-post' => 'false',
  812. 'cdp-references-edit' => 'false',
  813. 'cdp-premium-import' => 'false',
  814. 'cdp-premium-hide-tooltip' => 'false',
  815. 'cdp-menu-in-settings' => 'false',
  816. );
  817. }
  818. /** –– * */
  819. /** –– **\
  820. * Add state info if user want it (the reference to original)
  821. * @since 1.0.0
  822. */
  823. if (is_admin()) {
  824. if ($cdp_globals && array_key_exists('others', $cdp_globals) && array_key_exists('cdp-references-post', $cdp_globals['others'])) {
  825. if ($cdp_globals['others']['cdp-references-post'] == 'true')
  826. add_filter('display_post_states', 'cdp_state_post_add', 1, 10);
  827. }
  828. }
  829. function cdp_state_post_add($post_states, $post) {
  830. if (cdp_check_permissions(wp_get_current_user()) == false)
  831. return $post_states;
  832. $meta = get_post_meta($post->ID, '_cdp_origin');
  833. $site = get_post_meta($post->ID, '_cdp_origin_site');
  834. if (function_exists('switch_to_blog') && $site)
  835. switch_to_blog($site);
  836. for ($i = sizeof($meta); $i >= 0; --$i) {
  837. if (array_key_exists(($i - 1), $meta) && get_post_status($meta[$i - 1])) {
  838. $link = get_post_permalink($meta[$i - 1]);
  839. $title = get_the_title($meta[$i - 1]) . " – " . "ID: " . $meta[$i - 1];
  840. $post_states['_cdp'] = __('Copy of', 'copy-delete-posts') . " <a class='cdp-tooltip-top' title='$title' href='$link' target='_blank'>" . __('this', 'copy-delete-posts') . "</a> " . __('post', 'copy-delete-posts');
  841. break;
  842. }
  843. }
  844. if (function_exists('restore_current_blog') && $site)
  845. restore_current_blog();
  846. return $post_states;
  847. }
  848. /** –– * */
  849. /** –– **\
  850. * Check the premium status and correction
  851. * @since 1.0.0
  852. */
  853. function areWePro($include = true, $file = '/content/premium.php', $ignore_perms = false) {
  854. if (!$ignore_perms && cdp_check_permissions(wp_get_current_user()) == false)
  855. return false;
  856. // Get WP-Plugin path
  857. $premium_plugin = 'copy-delete-posts-premium/copy-delete-posts-premium.php';
  858. $premium_dir = WP_PLUGIN_DIR . '/' . 'copy-delete-posts-premium';
  859. $pplugin_path = $premium_dir . $file;
  860. $squirrel = 'cdpp_squirrelicense';
  861. $core = '/includes/core.php';
  862. $areWePro = false;
  863. // Load premium content if the plugin is here
  864. if (is_dir($premium_dir) && ((function_exists('is_plugin_active') && is_plugin_active($premium_plugin)) || (!function_exists('is_plugin_active')))) {
  865. // Include cool features
  866. if ($include && file_exists($pplugin_path))
  867. require_once($pplugin_path);
  868. // Is premium function
  869. if (file_exists($pplugin_path))
  870. $areWePro = true;
  871. // Has special functions
  872. if (file_exists($pplugin_path) && file_exists($premium_dir . $core)) {
  873. require_once($premium_dir . $core);
  874. if (function_exists($squirrel))
  875. $areWePro = $squirrel()['p'];
  876. else
  877. $areWePro = false;
  878. } else
  879. $areWePro = false;
  880. }
  881. // Return answer
  882. return $areWePro;
  883. }
  884. /** –– * */
  885. /** –– **\
  886. * It adds button on plugin list below plugin
  887. * @since 1.0.0
  888. */
  889. add_filter('plugin_action_links_' . plugin_basename(__FILE__), function ($links) {
  890. $links['cdp-settings-link'] = '<a href="' . admin_url('/admin.php?page=copy-delete-posts') . '">' . __('Settings', 'copy-delete-posts') . '</a>';
  891. return $links;
  892. });
  893. /** –– * */
  894. /** –– **\
  895. * This function fixes Wordpress wp_upload_dir function
  896. * @since 1.0.0
  897. */
  898. function cdp_fix_upload_paths($data) {
  899. // Check if the base URL matches the format
  900. $needs_fixing = preg_match("/wp-content\/blogs\.dir\/(\d+)\/files/", $data['baseurl'], $uri_part);
  901. if ($needs_fixing) {
  902. $data['url'] = str_replace($uri_part[0], 'files', $data['url']);
  903. $data['baseurl'] = str_replace($uri_part[0], 'files', $data['baseurl']);
  904. }
  905. return $data;
  906. }
  907. /** –– * */
  908. /** –– **\
  909. * This function will sanitize whole array with sanitize_text_field – by RECURSION
  910. * @since 1.0.0
  911. */
  912. function cdp_sanitize_array($data = null) {
  913. $array = array();
  914. if (is_array($data) || is_object($data))
  915. foreach ($data as $key => $value) {
  916. $key = ((is_numeric($key)) ? intval($key) : sanitize_text_field($key));
  917. if (is_array($value) || is_object($value))
  918. $array[$key] = cdp_sanitize_array($value);
  919. else
  920. $array[$key] = sanitize_text_field($value);
  921. }
  922. else if (is_string($data))
  923. return sanitize_text_field($data);
  924. else if (is_bool($data))
  925. return $data;
  926. else if (is_null($data))
  927. return 'false';
  928. else {
  929. error_log('Copy & Delete Posts[copy-delete-posts.php:707]: Unknown AJaX datatype – ' . gettype($data));
  930. echo 'error – invalid data';
  931. wp_die();
  932. }
  933. return $array;
  934. }
  935. /** –– **/