PluginProbe
PatternsWP – Gutenberg Block Patterns & Page Templates Library / 1.0.4
PatternsWP – Gutenberg Block Patterns & Page Templates Library v1.0.4
trunk 1.0.0 1.0.1 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
← All changes | patternswp.php +43 -118 1.0.81.0.4 View file →
@@ -4,9 +4,9 @@
4 4 * Plugin URI: https://thepatternswp.com
5 5 * Description: A growing library of ready-made block patterns can help you build websites faster in no time.
6 6 * Author: PatternsWP
7 7 * Author URI: https://thepatternswp.com
8 - * Version: 1.0.8
8 + * Version: 1.0.4
9 9 * License: GPL-2.0+
10 10 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11 11 * Text Domain: patternswp
12 12 * Domain Path: /languages
@@ -19,156 +19,81 @@
19 19
20 20 // Define plugin constants.
21 21 define('PWP_PLUGIN_DIR', plugin_dir_path(__FILE__));
22 22 define('PWP_PLUGIN_URL', plugin_dir_url(__FILE__));
23 -define('PWP_P_VERSION', '1.0.8');
24 23 define('PWP_PLUGIN_FILE', __FILE__);
25 24 define('PWP_ABSPATH', dirname(__FILE__) . '/');
26 25 define('PWP_VERSION', get_file_data(__FILE__, ['Version'])[0]);
27 26
28 -define('PATTERSWP_PLUGIN_API_URL', 'https://api.lemonsqueezy.com/v1/licenses');
29 -
30 27 // Include necessary files.
31 -require_once PWP_PLUGIN_DIR . 'includes/class-patternswp-admin.php';
32 28 require_once PWP_PLUGIN_DIR . 'includes/class-patternswp-api.php';
33 -require_once PWP_PLUGIN_DIR . 'includes/lib/class-patterns-license.php';
34 29
35 30 /**
36 31 * Enqueue assets for Block Editor.
37 32 */
38 33 function patternswp_enqueue_editor_assets() {
39 - $get_license_data = get_option('patternswp_plugin_license_data');
40 - $is_active = isset($get_license_data['activated']) ? $get_license_data['activated'] : false;
41 34
35 + // Scripts.
42 36 $script_asset = patternswp_get_asset_file('build/patternswp-editor');
43 37 wp_enqueue_script(
44 - 'patternswp-editor-scripts',
45 - PWP_PLUGIN_URL . 'build/patternswp-editor.js',
46 - array_merge($script_asset['dependencies'], ['wp-api']),
47 - $script_asset['version'],
38 + 'patternswp-editor-scripts',
39 + PWP_PLUGIN_URL . 'build/patternswp-editor.js',
40 + array_merge($script_asset['dependencies'], ['wp-api']),
41 + $script_asset['version'],
48 42 true
49 43 );
50 44
51 - $patternswp_api_section = new PatternsWP_API_Section();
52 - $localize_data = [
53 - 'isLicenseActive' => $is_active,
54 - 'externalPatterns' => [],
55 - 'patternCategories' => $patternswp_api_section->get_patternswp_category_type(),
56 - 'patternsNonce' => wp_create_nonce('patternswp_nonce'),
57 - ];
58 -
59 - wp_localize_script('patternswp-editor-scripts', 'patternsWpData', $localize_data);
60 -
45 + // Styles.
61 46 $style_asset = patternswp_get_asset_file('build/block-pattern-inserter-editor-styles');
62 - wp_enqueue_style('patternswp-editor-styles', PWP_PLUGIN_URL . 'build/style-patternswp-editor-styles.css', [], $style_asset['version']);
47 + wp_enqueue_style(
48 + 'patternswp-editor-styles',
49 + PWP_PLUGIN_URL . 'build/style-patternswp-editor-styles.css',
50 + array(),
51 + $style_asset['version']
52 + );
63 53 }
64 54 add_action('enqueue_block_editor_assets', 'patternswp_enqueue_editor_assets');
65 55
66 56 /**
67 57 * Get asset file data.
58 + *
59 + * @param string $filepath The file path.
60 + * @return array Asset data.
68 61 */
69 62 function patternswp_get_asset_file($filepath) {
70 63 $asset_path = PWP_ABSPATH . $filepath . '.asset.php';
71 - return file_exists($asset_path) ? require_once $asset_path : ['dependencies' => [], 'version' => PWP_VERSION];
64 + return file_exists($asset_path)
65 + ? require_once $asset_path
66 + : [
67 + 'dependencies' => [],
68 + 'version' => PWP_VERSION,
69 + ];
72 70 }
73 71
74 72 // Plugin activation hook.
75 -register_activation_hook(__FILE__, 'patternswp_schedule_hourly_cron');
73 +register_activation_hook(__FILE__, 'patternswp_plugin_activate');
74 +function patternswp_plugin_activate() {
75 + global $wpdb;
76 + $table_name = $wpdb->prefix . 'patternswp_patterns';
76 77
77 -function patternswp_schedule_hourly_cron() {
78 - if ( !wp_next_scheduled( 'patternswp_hourly_transient_load' ) ) {
79 - wp_schedule_event( time(), 'hourly', 'patternswp_hourly_transient_load' );
78 + // Check if the table already exists.
79 + if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
80 + // Table does not exist, so create it.
81 + $charset_collate = $wpdb->get_charset_collate();
82 + $sql = "CREATE TABLE $table_name (
83 + id INT NOT NULL AUTO_INCREMENT,
84 + title VARCHAR(255),
85 + categories VARCHAR(100),
86 + content LONGTEXT,
87 + PRIMARY KEY (id)
88 + ) $charset_collate;";
89 +
90 + require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
91 + dbDelta($sql);
80 92 }
81 93 }
82 94
83 95 // Plugin deactivation hook.
84 -register_deactivation_hook(__FILE__, 'patternswp_remove_hourly_cron');
85 -
86 -function patternswp_remove_hourly_cron() {
87 - $timestamp = wp_next_scheduled( 'patternswp_hourly_transient_load' );
88 - if ( $timestamp ) {
89 - wp_unschedule_event( $timestamp, 'patternswp_hourly_transient_load' );
90 - }
96 +register_deactivation_hook(__FILE__, 'patternswp_plugin_deactivate');
97 +function patternswp_plugin_deactivate() {
98 + // Deactivation tasks if any.
91 99 }
92 -
93 -/**
94 - * AJAX handler to fetch patterns.
95 - */
96 -function fetch_patterns_handler() {
97 -
98 - // Verify nonce
99 - if (!isset($_POST['nonce'])) {
100 - wp_send_json_error('Missing nonce');
101 - wp_die();
102 - }
103 -
104 - $nonce = sanitize_text_field(wp_unslash($_POST['nonce']));
105 -
106 - if (!wp_verify_nonce($nonce, 'patternswp_nonce')) {
107 - wp_send_json_error('Invalid nonce');
108 - wp_die();
109 - }
110 -
111 - if (!isset($_POST['page']) || !isset($_POST['patternsPerPage'])) {
112 - wp_send_json_error('Missing parameters');
113 - wp_die();
114 - }
115 -
116 - $page = intval($_POST['page']);
117 - $patterns_per_page = intval($_POST['patternsPerPage']);
118 - $search = sanitize_text_field(wp_unslash($_POST['search'] ?? ''));
119 - $category = sanitize_text_field(wp_unslash($_POST['category'] ?? ''));
120 -
121 - $cache_key = 'patternswp_' . md5("$page-$patterns_per_page-$search-$category");
122 - $cached_data = get_transient($cache_key);
123 -
124 - if ($cached_data !== false) {
125 - wp_send_json_success($cached_data);
126 - wp_die();
127 - }
128 -
129 - $patternswp_api_section = new PatternsWP_API_Section();
130 - $localize_data_ajax = $patternswp_api_section->get_patternswp_pattern($page, $patterns_per_page, $search, $category);
131 -
132 - if (is_array($localize_data_ajax)) {
133 - set_transient($cache_key, $localize_data_ajax, 3600);
134 - wp_send_json_success($localize_data_ajax);
135 - } else {
136 - wp_send_json_error('Failed to fetch patterns');
137 - }
138 -
139 - wp_die();
140 -}
141 -add_action('wp_ajax_fetch_patterns', 'fetch_patterns_handler');
142 -add_action('wp_ajax_nopriv_fetch_patterns', 'fetch_patterns_handler');
143 -
144 -/**
145 - * Add plugin action links.
146 - */
147 -function patternswp_plugin_action_links($links, $file) {
148 - if ($file === plugin_basename(__FILE__)) {
149 - $get_license_data = get_option('patternswp_plugin_license_data');
150 - $is_active = isset($get_license_data['activated']) ? $get_license_data['activated'] : false;
151 -
152 - $support_link = '<a href="https://thepatternswp.com/contact/" target="_blank">Support</a>';
153 - array_unshift($links, $support_link);
154 -
155 - if (!$is_active) {
156 - $upgrade_link = '<a href="https://thepatternswp.com/pricing/" target="_blank">Upgrade to Pro</a>';
157 - array_unshift($links, $upgrade_link);
158 - }
159 - }
160 - return $links;
161 -}
162 -add_filter('plugin_action_links', 'patternswp_plugin_action_links', 10, 2);
163 -
164 -/**
165 - * Add custom plugin meta links.
166 - */
167 -function patternswp_add_plugin_meta_links($links, $file) {
168 - if ($file === plugin_basename(__FILE__)) {
169 - $links[] = '<a href="https://thepatternswp.com/suggest-feature" target="_blank">Suggest a Feature</a>';
170 - $links[] = '<a href="https://wordpress.org/support/plugin/patternswp/reviews/?filter=5" target="_blank">Rate Us</a>';
171 - }
172 - return $links;
173 -}
174 -add_filter('plugin_row_meta', 'patternswp_add_plugin_meta_links', 10, 2);