| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Easy Quotes |
| 4 |
* Description: Adds a new Post Type 'Quotes' and a customizable Gutenberg Block 'Easy Quotes' to your wordpress site. Collect and show your favorite Quotes (random, daily or specific). |
| 5 |
* Requires at least: 6.7 |
| 6 |
* Requires PHP: 7.4 |
| 7 |
* Version: 1.3.2 |
| 8 |
* Author: Jürgen Müller |
| 9 |
* Author URI: https://www.layart.org |
| 10 |
* License: GPL-2.0-or-later |
| 11 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 12 |
* Text Domain: easy-quotes |
| 13 |
* |
| 14 |
* @package LayArt |
| 15 |
*/ |
| 16 |
|
| 17 |
// Exit if accessed directly. |
| 18 |
if ( ! defined( 'ABSPATH' ) ) { |
| 19 |
exit; |
| 20 |
} |
| 21 |
|
| 22 |
define('EASY_QUOTES_VERSION', '1.3.2'); |
| 23 |
define('EASY_QUOTES_PLUGIN_URL', plugin_dir_url(__FILE__)); |
| 24 |
define('EASY_QUOTES_PLUGIN_DIR', plugin_dir_path(__FILE__)); |
| 25 |
|
| 26 |
class Easy_Quotes |
| 27 |
{ |
| 28 |
function __construct() { |
| 29 |
add_action( 'init', [$this, 'register_blocks'] ); |
| 30 |
add_action( 'wp_enqueue_scripts', [$this, 'enqueue_scripts'] ); |
| 31 |
register_activation_hook( __FILE__, [$this, 'activation'] ); |
| 32 |
|
| 33 |
$this->load_dependencies(); |
| 34 |
$this->init_classes(); |
| 35 |
} |
| 36 |
|
| 37 |
function load_dependencies() |
| 38 |
{ |
| 39 |
require_once EASY_QUOTES_PLUGIN_DIR . 'includes/data.php'; |
| 40 |
require_once EASY_QUOTES_PLUGIN_DIR . 'includes/stars.php'; |
| 41 |
require_once EASY_QUOTES_PLUGIN_DIR . 'includes/post-type.php'; |
| 42 |
require_once EASY_QUOTES_PLUGIN_DIR . 'includes/font.php'; |
| 43 |
require_once EASY_QUOTES_PLUGIN_DIR . 'includes/fonts-database.php'; |
| 44 |
} |
| 45 |
|
| 46 |
function init_classes() { |
| 47 |
new Easy_Quotes_Data(); |
| 48 |
new Easy_Quotes_Stars(); |
| 49 |
new Easy_Quotes_Post_Type(); |
| 50 |
|
| 51 |
// Clean up the old database silently |
| 52 |
$fontsDb = new Easy_Quotes_Fonts_Database(); |
| 53 |
if ($fontsDb->legacyTablesExist()) { |
| 54 |
$fontsDb->dropTables(); |
| 55 |
error_log('Easy Quotes: Legacy font tables cleaned up successfully'); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
function register_blocks() { |
| 60 |
if ( function_exists( 'wp_register_block_types_from_metadata_collection' ) ) { |
| 61 |
wp_register_block_types_from_metadata_collection( __DIR__ . '/build', __DIR__ . '/build/blocks-manifest.php' ); |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
if ( function_exists( 'wp_register_block_metadata_collection' ) ) { |
| 66 |
wp_register_block_metadata_collection( __DIR__ . '/build', __DIR__ . '/build/blocks-manifest.php' ); |
| 67 |
} |
| 68 |
|
| 69 |
$manifest_data = require __DIR__ . '/build/blocks-manifest.php'; |
| 70 |
foreach ( array_keys( $manifest_data ) as $block_type ) { |
| 71 |
register_block_type( __DIR__ . "/build/{$block_type}" ); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Enqueue javascript helper functions in header |
| 77 |
* |
| 78 |
* @return void |
| 79 |
*/ |
| 80 |
function enqueue_scripts() { |
| 81 |
wp_enqueue_script( |
| 82 |
'easy-quotes-script', |
| 83 |
EASY_QUOTES_PLUGIN_URL . 'public/js/easy-quotes.js', |
| 84 |
[], |
| 85 |
EASY_QUOTES_VERSION, |
| 86 |
false |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
function activation() { |
| 91 |
register_uninstall_hook(__FILE__, array('Easy_Quotes', 'uninstall')); |
| 92 |
} |
| 93 |
|
| 94 |
public static function uninstall() |
| 95 |
{ |
| 96 |
// nothing to do. |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
new Easy_Quotes(); |
| 101 |
|