Changeset 3209381
- Timestamp:
- 12/17/2024 04:55:55 PM (14 months ago)
- Location:
- outbrain-feed
- Files:
-
- 5 edited
-
tags/1.0.1/includes/Frontend.php (modified) (1 diff)
-
trunk/includes/DB.php (modified) (3 diffs)
-
trunk/includes/Frontend.php (modified) (1 diff)
-
trunk/outbrain-feed.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
outbrain-feed/tags/1.0.1/includes/Frontend.php
r3209068 r3209381 23 23 if ($snippet === false) { 24 24 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared 25 $snippet = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$table_name}` LIMIT 1"));25 $snippet = $wpdb->get_row($wpdb->prepare("SELECT * FROM %s LIMIT 1", $table_name)); 26 26 if ($snippet) { 27 27 wp_cache_set($cache_key, $snippet); -
outbrain-feed/trunk/includes/DB.php
r3209068 r3209381 8 8 global $wpdb; 9 9 $this->wpdb = $wpdb; 10 $this->create_tables();11 10 } 12 11 13 12 public static function create_tables() { 14 13 global $wpdb; 14 $charset_collate = $wpdb->get_charset_collate(); 15 16 // Create the obfeed_snippets table 15 17 $table_name = $wpdb->prefix . 'obfeed_snippets'; 16 $charset_collate = $wpdb->get_charset_collate(); 17 $cache_key = 'obfeed_snippets_db_exists'; 18 $table_exists_1 = wp_cache_get( $cache_key ); 19 20 if ( false === $table_exists_1 ) { 21 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery 22 $table_exists_1 = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name)) === $table_name; 23 wp_cache_set( $cache_key, $table_exists_1 ); 24 } 25 26 if ( $table_exists_1 ) { 27 $sql = "CREATE TABLE $table_name ( 18 $sql = "CREATE TABLE $table_name ( 28 19 id INT NOT NULL AUTO_INCREMENT, 29 20 widget_id VARCHAR(50) NOT NULL, … … 32 23 PRIMARY KEY (id) 33 24 ) $charset_collate;"; 34 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );35 dbDelta( $sql );36 }37 25 38 // Insert default data using prepared statements 39 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery 26 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 27 dbDelta($sql); 28 40 29 $wpdb->insert( 41 30 $table_name, … … 54 43 public static function cleanup() { 55 44 global $wpdb; 56 $table_name = $wpdb->prefix . 'obfeed_snippets'; 57 $table_name = esc_sql($table_name); // Sanitize the table name properly 58 59 // Construct the SQL query safely 60 $sql = 'DROP TABLE IF EXISTS `' . $table_name . '`'; 61 62 // Suppress the warnings for direct database calls, no caching, and schema changes 63 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared 64 $wpdb->query($sql); 65 45 $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}obfeed_snippets"); 66 46 delete_option('obfeed_plugin_mode'); 67 47 delete_option('obfeed_plugin_status'); -
outbrain-feed/trunk/includes/Frontend.php
r3209068 r3209381 17 17 $table_name = $wpdb->prefix . 'obfeed_snippets'; 18 18 19 // Use caching to avoid repeated database queries 20 $cache_key = 'obfeed_snippet'; 21 $snippet = wp_cache_get($cache_key); 22 23 if ($snippet === false) { 24 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared 25 $snippet = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$table_name}` LIMIT 1")); 26 if ($snippet) { 27 wp_cache_set($cache_key, $snippet); 28 } 29 } 19 $snippet = $wpdb->get_row("SELECT * FROM `{$table_name}` LIMIT 1"); 30 20 31 21 if ($snippet) { -
outbrain-feed/trunk/outbrain-feed.php
r3209068 r3209381 4 4 * Plugin URI: https://developer.outbrain.com/outbrain-wordpress-implementation-guide/ 5 5 * Description: Dynamically inserts Outbrain feed widgets into articles, with flexible configuration. 6 * Version: 1.0. 16 * Version: 1.0.2 7 7 * Author: Outbrain Dev Team 8 8 * Author URI: … … 19 19 define('OBFEED_PLUGIN_URL', plugin_dir_url(__FILE__)); 20 20 21 21 22 // Include necessary files 22 23 require_once OBFEED_PLUGIN_DIR . 'includes/Loader.php'; … … 30 31 add_action('plugins_loaded', 'obfeed_initialize_plugin'); 31 32 33 function obfeed_admin_styles() { 34 wp_enqueue_style('obfeed_admin_styles', plugin_dir_url(__FILE__) . 'assets/css/admin-styles.css'); 35 } 36 add_action('admin_enqueue_scripts', 'obfeed_admin_styles'); 37 32 38 // Activation and Uninstall hooks 33 //register_activation_hook(__FILE__, ['OBFEED\DB', 'create_tables']);39 register_activation_hook(__FILE__, ['OBFEED\DB', 'create_tables']); 34 40 register_uninstall_hook(__FILE__, ['OBFEED\DB', 'cleanup']); -
outbrain-feed/trunk/readme.txt
r3209068 r3209381 4 4 Requires at least: 6.1 5 5 Tested up to: 6.7 6 Stable tag: 1.0. 16 Stable tag: 1.0.2 7 7 Requires PHP: 7.1 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.