-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feature/settings page (#34) * refactor: functions location * upgrade: dependencies * add: setting page * add: assets and styles for settings page * Feature/check type options (#35) * change: error vs warning * add: warning on heading, error on image * change: build update * change: functions relating to options * add: clean build folder * add: blocks and functions in array * add: block check values in php and js * change: build files * change: heading checks * fix: error vs warning for invalidations * change: updated error component * change: image check and global block check * add: button check * Feature/cleanup (#36) * add: php docs * add: singleton for block config * add: js docs to block checks * add: js docs to block mods * finish: adding code docs * change: update readme.txt * Feature/styles (#37) * change: editor error and warning styles * finish: styles * upgrade: package lock * Fix/plugin check (#38) * fix: version mismatch * fix: error in plugin check * change: description * change: removed button check for now (#39) * change: version tags to 1.0.0
- Loading branch information
1 parent
348d886
commit 1027d26
Showing
44 changed files
with
2,103 additions
and
1,818 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace BlockAccessibility; | ||
|
||
class BlockConfig | ||
{ | ||
/** | ||
* Holds the singleton instance of BlockConfig. | ||
* | ||
* @var BlockConfig|null | ||
*/ | ||
private static $instance = null; | ||
|
||
/** | ||
* Holds the block configuration array. | ||
* | ||
* @var array|null | ||
*/ | ||
private $blockConfig = null; | ||
|
||
/** | ||
* Private constructor to prevent multiple instances. | ||
*/ | ||
private function __construct() | ||
{ | ||
// Initialize the block configuration once | ||
$this->blockConfig = [ | ||
[ | ||
'function_name' => 'renderCoreHeadingOptions', | ||
'option_name' => 'coreHeadingBlockCheck', | ||
'block_label' => esc_html__('Heading', 'block-accessibility-checks'), | ||
], | ||
[ | ||
'function_name' => 'renderCoreImageOptions', | ||
'option_name' => 'coreImageBlockCheck', | ||
'block_label' => esc_html__('Image', 'block-accessibility-checks'), | ||
], | ||
[ | ||
'function_name' => 'renderCoreTableOptions', | ||
'option_name' => 'coreTableBlockCheck', | ||
'block_label' => esc_html__('Table', 'block-accessibility-checks'), | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Retrieves the singleton instance of the BlockConfig class. | ||
* | ||
* @return BlockConfig The singleton instance. | ||
*/ | ||
public static function getInstance() | ||
{ | ||
if (self::$instance === null) { | ||
self::$instance = new self(); | ||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
/** | ||
* Retrieves the block configuration. | ||
* | ||
* This method returns the cached block configuration array. | ||
* | ||
* @return array The block configuration. | ||
*/ | ||
public function getBlockConfig() | ||
{ | ||
return $this->blockConfig; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?php | ||
|
||
/** | ||
* | ||
* The ScriptsStyles class is responsible for enqueueing block assets and admin assets. | ||
* | ||
* @package BlockAccessibility | ||
*/ | ||
|
||
namespace BlockAccessibility; | ||
|
||
class ScriptsStyles | ||
{ | ||
private $pluginFile; | ||
private $translations; | ||
|
||
/** | ||
* Constructs a new instance of the ScriptsStyles class. | ||
* | ||
* @param string $pluginFile The path to the plugin file. | ||
* @param Translations $translations The translations object. | ||
*/ | ||
public function __construct($pluginFile, Translations $translations) | ||
{ | ||
$this->pluginFile = $pluginFile; | ||
$this->translations = $translations; | ||
} | ||
|
||
/** | ||
* Enqueues the assets for the block. | ||
* | ||
* This method is responsible for enqueueing the necessary scripts and styles for the block. | ||
* It sets up script translations and then calls the methods to enqueue the block scripts and styles. | ||
* | ||
* @return void | ||
*/ | ||
public function enqueueBlockAssets() | ||
{ | ||
$script_handle = 'block-accessibility-script'; | ||
$this->translations->setupScriptTranslations($script_handle); | ||
|
||
$this->enqueueBlockScripts(); | ||
$this->enqueueBlockStyles(); | ||
} | ||
|
||
/** | ||
* Enqueues the admin assets. | ||
* | ||
* This method is responsible for enqueueing the necessary scripts and styles for the admin area. | ||
* It sets up script translations and enqueues admin styles. | ||
* | ||
* @return void | ||
*/ | ||
public function enqueueAdminAssets() | ||
{ | ||
$script_handle = 'block-accessibility-script'; | ||
$this->translations->setupScriptTranslations($script_handle); | ||
|
||
$this->enqueueAdminStyles(); | ||
} | ||
|
||
/** | ||
* Enqueues the block scripts for the plugin. | ||
* | ||
* This function is responsible for enqueueing the necessary JavaScript scripts for the plugin's blocks. | ||
* It registers the script handle, script path, dependencies, version, and localization data. | ||
* | ||
* @access private | ||
* @return void | ||
*/ | ||
private function enqueueBlockScripts() | ||
{ | ||
$script_path = 'build/block-checks.js'; | ||
$script_handle = 'block-accessibility-script'; | ||
|
||
wp_enqueue_script( | ||
$script_handle, | ||
plugins_url($script_path, $this->pluginFile), | ||
['wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor'], | ||
BLOCK_ACCESSIBILITY_VERSION, // Use the constant here | ||
true | ||
); | ||
|
||
/** | ||
* Retrieves the block checks options from the database. | ||
* | ||
* @return array The block checks options. | ||
*/ | ||
$block_checks_options = get_option('block_checks_options', []); | ||
|
||
wp_localize_script( | ||
$script_handle, | ||
'BlockAccessibilityChecks', | ||
array( | ||
'blockChecksOptions' => $block_checks_options, | ||
'blocks' => BlockConfig::getInstance()->getBlockConfig(), | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Enqueues the block styles. | ||
* | ||
* This function is responsible for enqueueing the block styles for the plugin. | ||
* It uses the `wp_enqueue_style` function to enqueue the styles. | ||
* | ||
* @access private | ||
* @return void | ||
*/ | ||
private function enqueueBlockStyles() | ||
{ | ||
$style_path = 'build/block-checks.css'; | ||
wp_enqueue_style( | ||
'block-checks-style', | ||
plugins_url($style_path, $this->pluginFile), | ||
[], | ||
BLOCK_ACCESSIBILITY_VERSION | ||
); | ||
} | ||
|
||
/** | ||
* Enqueues the admin styles for the block accessibility checks. | ||
* | ||
* This function is responsible for enqueueing the admin styles for the block accessibility checks. | ||
* It uses the `wp_enqueue_style` function to enqueue the 'block-checks-admin' style. | ||
* | ||
* @access private | ||
*/ | ||
private function enqueueAdminStyles() | ||
{ | ||
$style_path = 'build/block-admin.css'; | ||
wp_enqueue_style( | ||
'block-checks-admin', | ||
plugins_url($style_path, $this->pluginFile), | ||
[], | ||
BLOCK_ACCESSIBILITY_VERSION | ||
); | ||
} | ||
} |
Oops, something went wrong.