| @@ -2,11 +2,11 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: PatternsWP |
| 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 | - * Author: PatternsWP | |
| 6 | + * Author: PatternsWP Team | |
| 7 | 7 | * Author URI: https://thepatternswp.com |
| 8 | - * Version: 1.0.5 | |
| 8 | + * Version: 1.0.0 | |
| 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 |
| @@ -12,135 +12,15 @@ | ||
| 12 | 12 | * Domain Path: /languages |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | // If this file is called directly, abort. |
| 16 | -if (!defined('WPINC')) { | |
| 17 | - die; | |
| 16 | +if ( ! defined( 'WPINC' ) ) { | |
| 17 | + die; | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | -// Define plugin constants. | |
| 21 | -define('PWP_PLUGIN_DIR', plugin_dir_path(__FILE__)); | |
| 22 | -define('PWP_PLUGIN_URL', plugin_dir_url(__FILE__)); | |
| 23 | -define('PWP_P_VERSION', '1.0.5'); | |
| 24 | -define('PWP_PLUGIN_FILE', __FILE__); | |
| 25 | -define('PWP_ABSPATH', dirname(__FILE__) . '/'); | |
| 26 | -define('PWP_VERSION', get_file_data(__FILE__, ['Version'])[0]); | |
| 27 | - | |
| 28 | -define('PATTERSWP_PLUGIN_API_URL', 'https://api.lemonsqueezy.com/v1/licenses'); | |
| 29 | - | |
| 30 | -// Include necessary files. | |
| 31 | -require_once PWP_PLUGIN_DIR . 'includes/class-patternswp-admin.php'; | |
| 32 | -require_once PWP_PLUGIN_DIR . 'includes/class-patternswp-api.php'; | |
| 33 | -require_once PWP_PLUGIN_DIR . 'includes/lib/class-patterns-license.php'; | |
| 34 | - | |
| 35 | 20 | /** |
| 36 | - * Enqueue assets for Block Editor. | |
| 21 | + * The core plugin class. | |
| 37 | 22 | */ |
| 38 | -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; | |
| 23 | +require plugin_dir_path( __FILE__ ) . 'inc/register-block-patterns.php'; | |
| 24 | +require plugin_dir_path( __FILE__ ) . 'inc/register-block-categories.php'; | |
| 41 | 25 | |
| 42 | - $script_asset = patternswp_get_asset_file('build/patternswp-editor'); | |
| 43 | - 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'], | |
| 48 | - true | |
| 49 | - ); | |
| 50 | 26 | |
| 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 | - ]; | |
| 57 | - | |
| 58 | - wp_localize_script('patternswp-editor-scripts', 'patternsWpData', $localize_data); | |
| 59 | - | |
| 60 | - $style_asset = patternswp_get_asset_file('build/block-pattern-inserter-editor-styles'); | |
| 61 | - wp_enqueue_style('patternswp-editor-styles', PWP_PLUGIN_URL . 'build/style-patternswp-editor-styles.css', [], $style_asset['version']); | |
| 62 | -} | |
| 63 | -add_action('enqueue_block_editor_assets', 'patternswp_enqueue_editor_assets'); | |
| 64 | - | |
| 65 | -/** | |
| 66 | - * Get asset file data. | |
| 67 | - */ | |
| 68 | -function patternswp_get_asset_file($filepath) { | |
| 69 | - $asset_path = PWP_ABSPATH . $filepath . '.asset.php'; | |
| 70 | - return file_exists($asset_path) ? require_once $asset_path : ['dependencies' => [], 'version' => PWP_VERSION]; | |
| 71 | -} | |
| 72 | - | |
| 73 | -// Plugin activation hook. | |
| 74 | -register_activation_hook(__FILE__, function() {}); | |
| 75 | - | |
| 76 | -// Plugin deactivation hook. | |
| 77 | -register_deactivation_hook(__FILE__, function() {}); | |
| 78 | - | |
| 79 | -/** | |
| 80 | - * AJAX handler to fetch patterns. | |
| 81 | - */ | |
| 82 | -function fetch_patterns_handler() { | |
| 83 | - if (!isset($_POST['page']) || !isset($_POST['patternsPerPage'])) { | |
| 84 | - wp_send_json_error('Missing parameters'); | |
| 85 | - wp_die(); | |
| 86 | - } | |
| 87 | - | |
| 88 | - $page = intval($_POST['page']); | |
| 89 | - $patterns_per_page = intval($_POST['patternsPerPage']); | |
| 90 | - $search = sanitize_text_field(wp_unslash($_POST['search'] ?? '')); | |
| 91 | - $category = sanitize_text_field(wp_unslash($_POST['category'] ?? '')); | |
| 92 | - | |
| 93 | - $cache_key = 'patternswp_' . md5("$page-$patterns_per_page-$search-$category"); | |
| 94 | - $cached_data = get_transient($cache_key); | |
| 95 | - | |
| 96 | - if ($cached_data !== false) { | |
| 97 | - wp_send_json_success($cached_data); | |
| 98 | - wp_die(); | |
| 99 | - } | |
| 100 | - | |
| 101 | - $patternswp_api_section = new PatternsWP_API_Section(); | |
| 102 | - $localize_data_ajax = $patternswp_api_section->get_patternswp_pattern($page, $patterns_per_page, $search, $category); | |
| 103 | - | |
| 104 | - if (is_array($localize_data_ajax)) { | |
| 105 | - set_transient($cache_key, $localize_data_ajax, 3600); | |
| 106 | - wp_send_json_success($localize_data_ajax); | |
| 107 | - } else { | |
| 108 | - wp_send_json_error('Failed to fetch patterns'); | |
| 109 | - } | |
| 110 | - | |
| 111 | - wp_die(); | |
| 112 | -} | |
| 113 | -add_action('wp_ajax_fetch_patterns', 'fetch_patterns_handler'); | |
| 114 | -add_action('wp_ajax_nopriv_fetch_patterns', 'fetch_patterns_handler'); | |
| 115 | - | |
| 116 | -/** | |
| 117 | - * Add plugin action links. | |
| 118 | - */ | |
| 119 | -function patternswp_plugin_action_links($links, $file) { | |
| 120 | - if ($file === plugin_basename(__FILE__)) { | |
| 121 | - $get_license_data = get_option('patternswp_plugin_license_data'); | |
| 122 | - $is_active = isset($get_license_data['activated']) ? $get_license_data['activated'] : false; | |
| 123 | - | |
| 124 | - $support_link = '<a href="https://thepatternswp.com/contact/" target="_blank">Support</a>'; | |
| 125 | - array_unshift($links, $support_link); | |
| 126 | - | |
| 127 | - if (!$is_active) { | |
| 128 | - $upgrade_link = '<a href="https://thepatternswp.com/pricing/" target="_blank">Upgrade to Pro</a>'; | |
| 129 | - array_unshift($links, $upgrade_link); | |
| 130 | - } | |
| 131 | - } | |
| 132 | - return $links; | |
| 133 | -} | |
| 134 | -add_filter('plugin_action_links', 'patternswp_plugin_action_links', 10, 2); | |
| 135 | - | |
| 136 | -/** | |
| 137 | - * Add custom plugin meta links. | |
| 138 | - */ | |
| 139 | -function patternswp_add_plugin_meta_links($links, $file) { | |
| 140 | - if ($file === plugin_basename(__FILE__)) { | |
| 141 | - $links[] = '<a href="https://thepatternswp.com/suggest-feature" target="_blank">Suggest a Feature</a>'; | |
| 142 | - $links[] = '<a href="https://wordpress.org/support/plugin/patternswp/reviews/?filter=5" target="_blank">Rate Us</a>'; | |
| 143 | - } | |
| 144 | - return $links; | |
| 145 | -} | |
| 146 | -add_filter('plugin_row_meta', 'patternswp_add_plugin_meta_links', 10, 2); | |