-
Notifications
You must be signed in to change notification settings - Fork 8
/
fontsampler.php
executable file
·108 lines (94 loc) · 5.49 KB
/
fontsampler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/*
Plugin Name: Fontsampler
Plugin URI: http://fontsampler.johannesneumeier.com
Description: Create interactive webfont previews via shortcodes. Create and edit previews from the ¶ Fontsampler sidebar menu or click "Settings" on the left.
Version: 0.4.14
Author: Underscore
Author URI: https://underscoretype.com
Copyright: Copyright 2016-2021 Johannes Neumeier
Text Domain: fontsampler
*/
defined( 'ABSPATH' ) or die( 'Access denied.' );
error_reporting(E_ALL);
// PHP version check first and foremost
function displayPhpError() {
echo '<section id="fontsampler-admin">';
echo '<div class="notice error"><strong>Your server is running an outdated PHP version ' . PHP_VERSION
. '</strong>, <br>Fontsampler requires at least PHP version 7.0.0 or higher to run.<br><br>'
. 'The recommended PHP version for Wordpress itself is 7.0.0</a> or greater.<br><br>'
. 'While legacy Wordpress support extends to 5.6.20+, <strong>Fontsampler requires a minimum '
. 'of PHP 7.0.0.</strong> Please <a href="https://wordpress.org/about/requirements/">follow the instractions for requirements</a> '
. 'and be in touch with your webserver provider about upgrading or enabling '
. 'a more modern version of PHP.<br><br>'
. 'As a last resort you can also try <a href="https://wordpress.org/plugins/fontsampler/advanced/">manually download a zip archive</a> of an older, but outdated, '
. 'version of Fontsampler (try 0.4.4) to run with your server’s PHP version.';
echo '</section>';
exit();
}
function addMenuWithWarning() {
add_menu_page( 'Fontsampler plugin page', 'Fontsampler', 'manage_options', 'fontsampler', 'displayPhpError', 'dashicons-editor-paragraph' );
wp_enqueue_style( 'fontsampler_admin_css', plugin_dir_url( __FILE__ ) . '/admin/css/fontsampler-admin.css', false, '1.0.0' );
}
if ( version_compare( PHP_VERSION, "7.0.0" ) < 0 ) {
add_action( 'admin_menu', 'addMenuWithWarning' );
} else {
global $wpdb;
// PHP version is good, let's go all bells and whistles...
require_once( 'FontsamplerPlugin.php' );
// Convenience subclasses instantiated within the FontsamplerPlugin class
require_once( 'FontsamplerDatabase.php' );
require_once( 'FontsamplerFormhandler.php' );
require_once( 'FontsamplerLayout.php' );
require_once( 'FontsamplerHelpers.php' );
require_once( 'FontsamplerPagination.php' );
require_once( 'FontsamplerMessages.php' );
require_once( 'FontsamplerNotifications.php' );
require_once( 'FontsamplerTwigExtension.php' );
// require_once( 'vendor/oyejorge/less.php/lessc.inc.php' );
require_once( 'vendor/autoload.php' );
// hook all plugin classes init to when Wordpress is ready
// $loader = new Twig_Loader_Filesystem( __DIR__ . '/includes' );
$loader = new \Twig\Loader\FilesystemLoader( __DIR__ . '/includes' );
$twig = new \Twig\Environment( $loader );
$twig->addExtension(new Fontsampler_Twig_Extension());
$fontsampler = new FontsamplerPlugin( $wpdb, $twig );
// load translations, then kick off actual Fontsampler setup and hooks
add_action( 'plugins_loaded', array( $fontsampler, 'fontsampler_load_text_domain' ) );
add_action( 'init', "fontsampler_init" );
if (get_option($fontsampler::FONTSAMPLER_OPTION_PROXY_URLS) && !empty(get_option( 'permalink_structure' ))) {
add_action('template_redirect', array($fontsampler, 'fontsampler_template_redirect'));
add_filter('query_vars', array($fontsampler, 'fontsampler_query_vars'));
}
register_activation_hook( __FILE__, array( $fontsampler, 'fontsampler_activate' ) );
}
function fontsampler_init() {
global $wpdb, $fontsampler;
// It's not entirely clear why $fontsampler is not available form the previous init above,
// but using the wp CLI not re-initializing the instance causes nasty errors
// hook all plugin classes init to when Wordpress is ready
$loader = new \Twig\Loader\FilesystemLoader( __DIR__ . '/includes' );
$twig = new \Twig\Environment( $loader );
$twig->addExtension(new Fontsampler_Twig_Extension());
$fontsampler = new FontsamplerPlugin( $wpdb, $twig );
$fontsampler->init();
// register the shortcode hook
add_shortcode( 'fontsampler', array( $fontsampler, 'fontsampler_shortcode' ) );
if (get_option($fontsampler::FONTSAMPLER_OPTION_PROXY_URLS) && !empty(get_option( 'permalink_structure' ))) {
// register an endpoint for custom webfont URLs, if enabled
add_rewrite_rule('^' . $fontsampler::FONTSAMPLER_PROXY_URL . '/(\d+)', 'index.php?' . $fontsampler::FONTSAMPLER_PROXY_QUERY_VAR . '=$matches[1]', 'top');
}
// register front end styles and scripts, but don't load them yet
wp_register_script( 'fontsampler-js', plugin_dir_url( __FILE__ ) . 'js/fontsampler.js', array('jquery'), false, false );
// register hook to check if a shortcode is present and attempt to enqueue styles
// then; scripts can be enqueued in the shortcode itself, since they are okay to
// be in the footer
add_action( 'wp', array( $fontsampler, 'check_shortcodes_enqueue_styles' ));
// backend
add_action( 'admin_menu', array( $fontsampler, 'fontsampler_plugin_setup_menu' ) );
add_action( 'admin_enqueue_scripts', array( $fontsampler, 'fontsampler_admin_enqueues' ) );
add_action( 'wp_ajax_get_mock_fontsampler', array( $fontsampler, 'ajax_get_mock_fontsampler' ) );
add_filter( 'upload_mimes', array( $fontsampler, 'allow_font_upload_types' ) );
add_filter( 'wp_check_filetype_and_ext', array( $fontsampler, 'check_upload_extension' ), 10, 4 );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $fontsampler, 'add_action_links' ) );
}