-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
99 lines (86 loc) · 3.07 KB
/
Copy pathplugin.php
File metadata and controls
99 lines (86 loc) · 3.07 KB
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
<?php
/**
* Plugin Name: Geniem WP Project Bells & Whistles
* Plugin URI: https://github.com/devgeniem/wp-plugin-boilerplate
* Description: A collection of various configurations and fixes for Geniem WordPress projects.
* Version: 1.7.1
* Author: Geniem Oy
* Author URI: https://geniem.com
* License: GPL3
*/
namespace Geniem;
use Geniem\Project;
// Check if Composer has been initialized in this directory.
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
}
// Add your production feature classes here.
$classes = [
Project\Add404Headers::class,
Project\DisableAdminEmailVerification::class,
Project\DisableBigImageSizeTreshold::class,
Project\DisableGutenbergAutoFullscreen::class,
Project\DisableGutenbergBlockPatterns::class,
Project\DisableGutenbergDevicePreviewOptions::class,
Project\DisableSiteHealthChecks::class,
Project\FixStreamDateFormat::class,
Project\RemoveSiteHealthWidget::class,
];
// If GENIEM_BELLS_AND_WHISTLES_FLOC_OPTIN constant has been set true,
// send HTTP Header: Permissions-Policy: interest-cohort=()
if ( defined( 'GENIEM_BELLS_AND_WHISTLES_FLOC_OPTIN' ) && GENIEM_BELLS_AND_WHISTLES_FLOC_OPTIN === true ) {
$classes[] = Project\DisableFloc::class;
}
// Add your development feature classes here.
if ( defined( 'WP_ENV' ) && WP_ENV === 'development' ) {
$development_classes = [
Project\CheckTasksCronFile::class,
];
}
// Run constructors for all defined feature classes.
array_walk( $classes, function ( $class_name ) {
if ( class_exists( $class_name ) && ! is_disabled_class( $class_name ) ) {
new $class_name();
}
} );
if ( defined( 'WP_ENV' ) && WP_ENV === 'development' ) {
array_walk( $development_classes, function ( $class_name ) {
if ( class_exists( $class_name ) && ! is_disabled_class( $class_name ) ) {
new $class_name();
}
} );
}
/**
* Check if a class should not be executed.
*
* @param string $class_name The class name without the namespace.
*
* @return boolean
*/
function is_disabled_class( $class_name ) {
// Get the class short name.
try {
$short_name = ( new \ReflectionClass( $class_name ) )->getShortName();
}
catch ( \ReflectionException $e ) {
// No class found.
error_log( $e->getMessage() ); // phpcs:ignore
return true;
}
$disable = defined( 'GENIEM_DISABLE_BELLS_AND_WHISTLES' ) ? GENIEM_DISABLE_BELLS_AND_WHISTLES : [];
$disabled = in_array( $short_name, $disable, true );
return $disabled;
}
/**
* Common notice function so all notices made by this plugin looks the same.
*
* @param string $type Error type. Usually 'error' or 'notice'.
* @param string $message The message that is shown to the admin user.
*
* @return void
*/
function admin_notice( string $type = 'error', string $message = 'No message provided.' ) {
add_action( 'admin_notices', function () use ( $type, $message ) {
echo sprintf( '<div class=\'notice notice-%s\'><p>%s</p></div>', $type, $message ); // phpcs:ignore
} );
}