PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.4.2
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.4.2
2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 2.7.1 All 27 releases
insert-php / migrations / 020302.php

020302.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.4.2, at migrations/020302.php

79 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php #comp-page builds: premium
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * Adds new columns
10 */
11 class WINPUpdate020302 extends Wbcr_Factory450_Update {
12
13 public function install() {
14 if ( is_multisite() && $this->plugin->isNetworkActive() ) {
15 global $wpdb;
16
17 $blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
18
19 if ( ! empty( $blogs ) ) {
20 foreach ( $blogs as $id ) {
21
22 switch_to_blog( $id );
23
24 $this->new_migration();
25
26 restore_current_blog();
27 }
28 }
29
30 WINP_Helper::flush_page_cache();
31
32 return;
33 }
34
35 $this->new_migration();
36 WINP_Helper::flush_page_cache();
37 }
38
39 /**
40 * @author Artem Prihodko <webtemyk@yandex.ru>
41 * @since 2.3.2
42 */
43 public function new_migration() {
44 wp_raise_memory_limit();
45
46 global $wpdb;
47
48 $snippets = $wpdb->get_results( "
49 SELECT p.ID
50 FROM {$wpdb->posts} p
51 INNER JOIN {$wpdb->postmeta} m ON ( p.ID = m.post_id )
52 WHERE m.meta_key LIKE '" . WINP_Plugin::app()->getPrefix() . "snippet_type'
53 AND p.post_type = '" . WINP_SNIPPETS_POST_TYPE . "'" );
54
55 if ( ! empty( $snippets ) ) {
56 $i = 10;
57 foreach ( (array) $snippets as $snippet ) {
58 $is_snippet_priority = WINP_Helper::getMetaOption( $snippet->ID, 'snippet_priority' );
59
60 if ( ! $is_snippet_priority ) {
61 $snippet_priority = WINP_Helper::updateMetaOption( $snippet->ID, 'snippet_priority', $i );
62
63 if ( $snippet_priority === false ) {
64 $wpdb->insert( $wpdb->postmeta, [
65 'post_id' => $snippet->ID,
66 'meta_key' => WINP_Plugin::app()->getPrefix() . 'snippet_priority',
67 'meta_value' => $i,
68 ], [ '%d', '%s', '%s' ] );
69 }
70
71 unset( $snippet_priority );
72 $i = $i + 10;
73 }
74 }
75 }
76
77 unset( $snippets );
78 }
79 }