PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.17
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.17
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / updates / update-1.8.7.php

update-1.8.7.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.17, at includes/updates/update-1.8.7.php

114 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Update to 1.8.7
4 *
5 * Cleans up duplicate/orphan template posts created by the old migration system.
6 * Plugin and theme templates are now detected dynamically from the filesystem
7 * and no longer stored in the database.
8 *
9 * @author Paul Kilmurray <paul@kilbot.com>
10 *
11 * @see http://wcpos.com
12 * @package WCPOS\WooCommercePOS
13 */
14
15 namespace WCPOS\WooCommercePOS;
16
17 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
18 // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
19 // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Update script with file-scoped variables.
20 // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited -- Using $post_id as loop variable, not overriding WP global.
21
22 global $wpdb;
23
24 // Delete all templates with _template_plugin = 1 (these are now virtual).
25 $plugin_templates = get_posts(
26 array(
27 'post_type' => 'wcpos_template',
28 'post_status' => 'any',
29 'posts_per_page' => -1,
30 'meta_query' => array(
31 array(
32 'key' => '_template_plugin',
33 'value' => '1',
34 ),
35 ),
36 'fields' => 'ids',
37 )
38 );
39
40 foreach ( $plugin_templates as $post_id ) {
41 wp_delete_post( $post_id, true );
42 }
43
44 // Delete all templates with _template_theme = 1 (these are now virtual).
45 $theme_templates = get_posts(
46 array(
47 'post_type' => 'wcpos_template',
48 'post_status' => 'any',
49 'posts_per_page' => -1,
50 'meta_query' => array(
51 array(
52 'key' => '_template_theme',
53 'value' => '1',
54 ),
55 ),
56 'fields' => 'ids',
57 )
58 );
59
60 foreach ( $theme_templates as $post_id ) {
61 wp_delete_post( $post_id, true );
62 }
63
64 // Migrate active template from post meta to option (if still using old system).
65 $active_receipt = get_posts(
66 array(
67 'post_type' => 'wcpos_template',
68 'post_status' => 'publish',
69 'posts_per_page' => 1,
70 'meta_query' => array(
71 array(
72 'key' => '_template_active',
73 'value' => '1',
74 ),
75 ),
76 'tax_query' => array(
77 array(
78 'taxonomy' => 'wcpos_template_type',
79 'field' => 'slug',
80 'terms' => 'receipt',
81 ),
82 ),
83 'fields' => 'ids',
84 )
85 );
86
87 // If there's an active custom template, set it in the option.
88 if ( ! empty( $active_receipt ) ) {
89 update_option( 'wcpos_active_template_receipt', $active_receipt[0] );
90 }
91
92 // Clean up all _template_active meta (no longer used).
93 $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_template_active' ) );
94
95 // Fix templates missing taxonomy - assign 'receipt' as default.
96 $templates_without_type = get_posts(
97 array(
98 'post_type' => 'wcpos_template',
99 'post_status' => 'any',
100 'posts_per_page' => -1,
101 'fields' => 'ids',
102 'tax_query' => array(
103 array(
104 'taxonomy' => 'wcpos_template_type',
105 'operator' => 'NOT EXISTS',
106 ),
107 ),
108 )
109 );
110
111 foreach ( $templates_without_type as $post_id ) {
112 wp_set_object_terms( $post_id, 'receipt', 'wcpos_template_type' );
113 }
114