Skip to content

Commit

Permalink
refactoring and added _ to accepted chars of post type
Browse files Browse the repository at this point in the history
  • Loading branch information
caspahouzer committed Mar 21, 2023
1 parent f53f80e commit 422924c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 26 deletions.
11 changes: 4 additions & 7 deletions core.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()
return esc_html($postType);
}, get_option('cpt_tables:tables_enabled', [])),
'tables_enabled' => 'cpt_tables:tables_enabled',
'prefix' => $wpdb->prefix . get_option('cpt_tables:tables_prefix', 'cpt_'),
'prefix' => $wpdb->prefix . 'cpt_',
'plugin_slug' => 'wp-cpt-tables',
'default_post_table' => $wpdb->prefix . 'posts',
'default_meta_table' => $wpdb->prefix . 'postmeta',
Expand All @@ -47,11 +47,8 @@ public function load()
{
$self = new self();

// $self->db = new Db;
// $self->config = require(__DIR__ . '/config.php');

add_filter('plugin_action_links_' . WPCPTTABLES_BASENAME, [$this, 'add_action_links'], 10, 2);
add_filter('network_admin_plugin_action_links_' . WPCPTTABLES_BASENAME, [$this, 'add_action_links_network'], 10, 2);
add_filter('plugin_action_links_' . plugin_basename(__FILE__), [$this, 'add_action_links'], 10, 2);
add_filter('network_admin_plugin_action_links_' . plugin_basename(__FILE__), [$this, 'add_action_links_network'], 10, 2);

$self->setupAdminFilters();
$self->setupQueryFilters();
Expand Down Expand Up @@ -129,7 +126,7 @@ public function add_action_links($links, $file)
$settings = '<a href="' . admin_url('options-general.php?page=' . $this->config['plugin_slug']) . '">' . __('Settings') . '</a>';
array_unshift($links, $settings);

$premium = '<a href="' . admin_url('options-general.php?page=' . $this->config['plugin_slug']) . '" style="font-weight:bold">' . __('Go pro', $this->config['plugin_slug']) . '</a>';
// $premium = '<a href="' . admin_url('options-general.php?page=' . $this->config['plugin_slug']) . '" style="font-weight:bold">' . __('Go pro', $this->config['plugin_slug']) . '</a>';
// array_unshift($links, $premium);

return $links;
Expand Down
13 changes: 2 additions & 11 deletions lib/QueryFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class QueryFilters
*/
private $config;

private $post_types = [];

private $custom_table = [];

/**
Expand All @@ -24,13 +22,9 @@ class QueryFilters
*/
public function __construct(Db $db, array $config)
{
global $wpdb;

$this->db = $db;
$this->config = $config;

$this->post_types = get_option($this->config['tables_enabled'], []);

$migrateRunning = get_option('cpt_tables:migrate_running', false);

if ($migrateRunning) {
Expand All @@ -49,8 +43,6 @@ public function __construct(Db $db, array $config)
*/
public function updateQueryTables(string $query): string
{
global $wpdb;

$table = $this->determineTable($query);
$this->custom_table = $table;

Expand Down Expand Up @@ -92,7 +84,7 @@ private function determineTable(string $query)

public function getPostTypeFromRequest(string $query)
{
preg_match("/`?post_type`?\s*=\s*'([a-zA-Z]*)'/", $query, $postType);
preg_match("/`?post_type`?\s*=\s*'([a-zA-Z_]*)'/", $query, $postType);

if ($postType = array_pop($postType)) {
if (isset($_GET['post_type']) && $_GET['post_type'] == $postType) {
Expand All @@ -109,7 +101,7 @@ public function getPostTypeFromRequest(string $query)
*/
public function getPostTypeFromQuery(string $query)
{
preg_match("/`?post_type`?\s*=\s*'([a-zA-Z]*)'/", $query, $postType);
preg_match("/`?post_type`?\s*=\s*'([a-zA-Z_]*)'/", $query, $postType);

if ($postType = array_pop($postType)) {
return $postType;
Expand Down Expand Up @@ -172,7 +164,6 @@ public function getPostIdsFromQuery(string $query): ?string
*/
public function getPostTypeById($ids): ?string
{
global $wpdb;
$key = __METHOD__ . $ids;

if (!$cached = wp_cache_get($key)) {
Expand Down
6 changes: 0 additions & 6 deletions lib/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ class Table
*/
private $config;

/**
* @var string
*/
private $table;

/**
* The notices class
* @var Notices
Expand Down Expand Up @@ -55,7 +50,6 @@ public function getTableName(string $table)
*/
public function create(string $table)
{
global $wpdb;
$table = $this->config['prefix'] . str_replace('-', '_', $table);

$this->createTables($table);
Expand Down
2 changes: 0 additions & 2 deletions lib/Triggers.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ private function insertPostTrigger(array $tables)
*/
private function insertMetaTrigger(array $tables)
{
global $wpdb;

if (!$tables) {
return;
}
Expand Down
6 changes: 6 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ Developed with ♥ by [Sebastian](https://lightapps.de).
This plugin was initially created for own usage to get a big database cleaner.

Check out the [GitHub repository](https://github.com/caspahouzer/wp-cpt-tables) and submit pull requests or open issues

== Changelog ==

=== 1.0.1 ===

* Added _ to accepted chars of post type

0 comments on commit 422924c

Please sign in to comment.