Skip to content

Commit

Permalink
fixes a fatal crash on plugin activation
Browse files Browse the repository at this point in the history
  • Loading branch information
fatihbalsoy committed Dec 30, 2023
1 parent 912d6ec commit d6daddd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: material-board-nightly-${{ steps.date.outputs.date }}
path: build/_bundle/material-board
path: build/material-board

# - name: Upload Nightly Build w/o Date
# uses: actions/upload-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: material-board-release-${{ steps.date.outputs.date }}
path: build/_bundle/material-board
path: build/material-board

# - name: Upload Release Build w/o Date
# uses: actions/upload-artifact@v3
Expand All @@ -73,6 +73,6 @@ jobs:
env:
REPO: self
BRANCH: release-deployed
FOLDER: build/_bundle/material-board
FOLDER: build/material-board
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

3 changes: 3 additions & 0 deletions src/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.3.8:
- Hotfix: There was a fatal crash on plugin activation.

0.3.7:
- Added a new option to disable content padding
- Material Icons for BuddIcons (bbPress)
Expand Down
74 changes: 46 additions & 28 deletions src/material-board.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin URI: https://github.com/fatihbalsoy/material-board
* Description: The Material Board plugin for WordPress updates the appearance of your site's dashboard to a sleeker, more contemporary design based on Google's Material Design Guidelines. This plugin preserves your existing dashboard layout, avoids making any significant alterations, and doesn't include any branding or promotional content. It's straightforward to use and comes at no cost.
* Author: Fatih Balsoy
* Version: 0.3.7
* Version: 0.3.8
* Text Domain: material-board
* Domain Path: /languages
* Author URI: https://fatih.bal.soy
Expand Down Expand Up @@ -34,7 +34,8 @@
$fbwpmdp_bundle = "material-board";
$fbwpmdp_settings_title = $fbwpmdp_name;

class MaterialBoardPlugin {
class MaterialBoardPlugin
{

public string $settings_slug;
private array $options = array(
Expand Down Expand Up @@ -67,13 +68,15 @@ class MaterialBoardPlugin {
'fbwpmdp_negative_space' => 'on'
);

function __construct() {
$this->settings_slug = $GLOBALS['fbwpmdp_bundle'];
function __construct()
{
// TODO: setting this to $GLOBALS['fbwpmdp_bundle'] causes a fatal crash
$this->settings_slug = 'material-board';
if (is_admin()) {
if(!function_exists('get_plugin_data')){
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if (!function_exists('get_plugin_data')) {
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
}
$plugin_data = get_plugin_data( __FILE__ );
$plugin_data = get_plugin_data(__FILE__);
$GLOBALS["fbwpmdp_version"] = $plugin_data["Version"];
}

Expand All @@ -91,20 +94,23 @@ function __construct() {
}

/** Language Support **/
function setup_languages() {
function setup_languages()
{
// Set the theme's text domain
load_plugin_textdomain($GLOBALS['fbwpmdp_bundle'], false, dirname(plugin_basename(__FILE__)) . '/languages/');
}

/** User-facing Admin Theme (Admin Bar) **/
function fbwpmdp_admin_user_theme_style() {
function fbwpmdp_admin_user_theme_style()
{
wp_enqueue_style('fbwpmdp-user-theme', plugins_url('styles/wp.css', __FILE__));

$this->load_plugin_options();
}

/** Admin Dashboard Theme **/
function fbwpmdp_admin_theme_style() {
function fbwpmdp_admin_theme_style()
{
// wp_enqueue_script('theme-script', plugins_url('app.js', __FILE__), array('jquery'));
wp_enqueue_style('fbwpmdp-admin-theme', plugins_url('styles/wp-admin.css', __FILE__));

Expand All @@ -119,41 +125,47 @@ function fbwpmdp_admin_theme_style() {
}

/** Gutenburg Block Editor Theme **/
function fbwpmdp_gutenburg_style() {
if($this->fbwpmdp_is_gutenberg_editor() && !$GLOBALS['fbwpmdp_is_dev']) {
function fbwpmdp_gutenburg_style()
{
if ($this->fbwpmdp_is_gutenberg_editor() && !$GLOBALS['fbwpmdp_is_dev']) {
wp_dequeue_style('fbwpmdp-admin-theme');
}
}

/** Safari and Chrome Browser Theme Color **/
function change_theme_color_meta() {
function change_theme_color_meta()
{
if (is_admin()) {
$primary_color = get_option('fbwpmdp_colors_primary');
echo '<meta name="theme-color" content="' . esc_attr($primary_color) . '">';
}
}

/** Login Theme **/
function fbwpmdp_login_theme_style() {
function fbwpmdp_login_theme_style()
{
wp_enqueue_style('fbwpmdp-login-theme', plugins_url('styles/wp-login.css', __FILE__));
$this->load_plugin_options();
}

/** Plugin Menu **/
function fbwpmdp_plugin_menu() {
function fbwpmdp_plugin_menu()
{
add_theme_page($GLOBALS["fbwpmdp_name"], $GLOBALS["fbwpmdp_name"], 'manage_options', $this->settings_slug, array($this, 'fbwpmdp_plugin_options'));
}

/** Plugin Settings Link **/
function fbwpmdp_settings_link($links) {
function fbwpmdp_settings_link($links)
{
$url = admin_url("themes.php?page=" . $this->settings_slug);
$settings_link = '<a href="' . $url . '">' . esc_html_e('Settings', 'material-board') . '</a>';
$links[] = $settings_link;
return $links;
}

/** Load Plugin Options **/
function load_plugin_options() {
function load_plugin_options()
{
//? -- COLORS -- ?//
$color_stylesheet = $this->fbwpmdp_get_local_file_contents("styles/shared.dynamic.css");
$color_stylesheet_with_primary = str_replace("\"primary-color\"", get_option('fbwpmdp_colors_primary'), $color_stylesheet);
Expand All @@ -163,7 +175,8 @@ function load_plugin_options() {
wp_add_inline_style('fbwpmdp-login-theme', $color_stylesheet_with_primary_and_accent);

//? -- DARK MODE -- ?//
function fbwpmdp_enqueue_dark_theme() {
function fbwpmdp_enqueue_dark_theme()
{
wp_enqueue_style('dark-admin-theme', plugins_url('styles/themes/shared.dark.css', __FILE__));
}

Expand Down Expand Up @@ -231,7 +244,7 @@ function fbwpmdp_enqueue_dark_theme() {
wp_enqueue_style('large_admin_bar_variant', plugins_url('styles/options/large_app_bar_2.css', __FILE__));
// Remove negative space if needed
if ($this->get_option_or_default('fbwpmdp_negative_space') != 'on') {
wp_enqueue_style('large_admin_bar_no_negative_space', plugins_url('styles/options/large_app_bar_2_no_negative_space.css', __FILE__ ));
wp_enqueue_style('large_admin_bar_no_negative_space', plugins_url('styles/options/large_app_bar_2_no_negative_space.css', __FILE__));
}
}
} else {
Expand All @@ -251,39 +264,44 @@ function fbwpmdp_enqueue_dark_theme() {
}

/** Plugin Options **/
function fbwpmdp_plugin_options() {
function fbwpmdp_plugin_options()
{
if (!current_user_can('manage_options')) {
wp_die(esc_html_e('You do not have sufficient permissions to access this page.'));
}
echo $this->fbwpmdp_get_local_file_contents('settings/index.php');
}

function get_option_or_default($option) {
function get_option_or_default($option)
{
return get_option($option, $this->options[$option]);
}

function settings() {
function settings()
{
foreach ($this->options as $key => $value) {
add_option($key, $value);
register_setting('material_dashboard_plugin', $key, array('sanitize_callback' => 'sanitize_text_field', 'default' => $value));
}
}

function fbwpmdp_get_local_file_contents($file_path) {
function fbwpmdp_get_local_file_contents($file_path)
{
ob_start();
include $file_path;
$contents = ob_get_clean();

return $contents;
}

function fbwpmdp_is_gutenberg_editor() {
if( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) {
function fbwpmdp_is_gutenberg_editor()
{
if (function_exists('is_gutenberg_page') && is_gutenberg_page()) {
return true;
}
}

$current_screen = get_current_screen();
if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
if (method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: fatihbalsoy
Donate link: https://paypal.me/fatihbalsoy
Tags: material, design, dashboard
Tested up to: 6.4.2
Stable tag: 0.3.7
Stable tag: 0.3.8
Requires at least: 5.8
Requires PHP: 7.0.0
License: AGPLv3 or later
Expand Down

0 comments on commit d6daddd

Please sign in to comment.