Skip to content

Commit

Permalink
Merge pull request #219 from RRZE-Webteam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rvdforst authored Dec 12, 2024
2 parents d45a570 + e294be8 commit 7e20ade
Show file tree
Hide file tree
Showing 57 changed files with 459 additions and 748 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"require": {
"php": "^8.2.0",
"rrze/wp": "^2.0",
"johngrogg/ics-parser": "^3.4.0",
"rlanvin/php-rrule": "^2.5.0",
"cmb2/cmb2": "^2.11.0"
Expand Down
11 changes: 7 additions & 4 deletions includes/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

class Main
{
/**
* __construct
*/
public function __construct()
public function loaded()
{
// Register the 'CalendarEvent' and 'CalendarFeed' custom post types.
add_action('init', fn() => [
CalendarEvent::registerPostType(),
CalendarFeed::registerPostType(),
]);

add_filter('plugin_action_links_' . plugin()->getBaseName(), [$this, 'settingsLink']);

add_action('admin_enqueue_scripts', [$this, 'adminEnqueueScripts']);
Expand Down
88 changes: 49 additions & 39 deletions vendor/rrze/wp/src/Plugin/Plugin.php → includes/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Plugin;
namespace RRZE\Calendar;

defined('ABSPATH') || exit;

Expand Down Expand Up @@ -31,18 +31,19 @@ class Plugin
protected $url;

/**
* The version of the plugin.
* @var string
* The data of the plugin.
* @var array
*/
protected $version;
protected $data;

/**
* __construct method
* Constructor.
* @param string $pluginFile The full path and filename of the plugin.
*/
public function __construct(string $pluginFile)
{
$this->pluginFile = $pluginFile;
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

/**
Expand All @@ -53,11 +54,10 @@ public function loaded()
$this->setBasename()
->setDirectory()
->setUrl()
->setVersion();
->setData();
}

/**
* getFile method
* Get the full path and filename of the plugin.
* @return string The full path and filename.
*/
Expand All @@ -67,7 +67,6 @@ public function getFile(): string
}

/**
* getBasename method
* Get the basename of the plugin.
* @return string The basename.
*/
Expand All @@ -77,7 +76,6 @@ public function getBasename(): string
}

/**
* setBasename method
* Set the basename of the plugin.
* @return object This Plugin object.
*/
Expand All @@ -88,7 +86,6 @@ public function setBasename(): object
}

/**
* getDirectory method
* Get the filesystem directory path (with trailing slash) for the plugin.
* @return string The filesystem directory path.
*/
Expand All @@ -98,7 +95,6 @@ public function getDirectory(): string
}

/**
* setDirectory method
* Set the filesystem directory path (with trailing slash) for the plugin.
* @return object This Plugin object.
*/
Expand All @@ -109,7 +105,6 @@ public function setDirectory(): object
}

/**
* getPath method
* Get the filesystem directory path (with trailing slash) for the plugin.
* @param string $path The path name.
* @return string The filesystem directory path.
Expand All @@ -120,7 +115,6 @@ public function getPath(string $path = ''): string
}

/**
* getUrl method
* Get the URL directory path (with trailing slash) for the plugin.
* @param string $path The path name.
* @return string The URL directory path.
Expand All @@ -131,7 +125,6 @@ public function getUrl(string $path = ''): string
}

/**
* setUrl method
* Set the URL directory path (with trailing slash) for the plugin.
* @return object This Plugin object.
*/
Expand All @@ -142,7 +135,6 @@ public function setUrl(): object
}

/**
* getSlug method
* Get the slug of the plugin.
* @return string The slug.
*/
Expand All @@ -152,31 +144,58 @@ public function getSlug(): string
}

/**
* getVersion method
* Set the data of the plugin.
* @return object This Plugin object.
*/
public function setData(): object
{
$this->data = get_plugin_data($this->pluginFile, false);
return $this;
}

/**
* Get the data of the plugin.
* @return array The data.
*/
public function getData(): array
{
return $this->data;
}

/**
* Get the name of the plugin.
* @return string The name.
*/
public function getName(): string
{
return $this->data['Name'];
}

/**
* Get the version of the plugin.
* @return string The version.
*/
public function getVersion(): string
{
if (defined('WP_DEBUG') && WP_DEBUG) {
return bin2hex(random_bytes(4));
}
return $this->version;
return $this->data['Version'];
}

/**
* getVersion method
* Set the version of the plugin.
* @return object This Plugin object.
* Get the required WordPress version of the plugin.
* @return string The required WordPress version.
*/
public function setVersion(): object
public function getRequiresWP(): string
{
$headers = ['Version' => 'Version'];
$fileData = get_file_data($this->pluginFile, $headers, 'plugin');
if (isset($fileData['Version'])) {
$this->version = $fileData['Version'];
};
return $this;
return $this->data['RequiresWP'];
}

/**
* Get the required PHP version of the plugin.
* @return string The required PHP version.
*/
public function getRequiresPHP(): string
{
return $this->data['RequiresPHP'];
}

/**
Expand All @@ -187,15 +206,6 @@ public function __call(string $name, array $arguments)
{
if (!method_exists($this, $name)) {
$message = sprintf('Call to undefined method %1$s::%2$s', __CLASS__, $name);
do_action(
'rrze.log.error',
$message,
[
'class' => __CLASS__,
'method' => $name,
'arguments' => $arguments
]
);
if (defined('WP_DEBUG') && WP_DEBUG) {
throw new \Exception($message);
}
Expand Down
32 changes: 6 additions & 26 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

defined('ABSPATH') || exit;

use RRZE\WP\Settings\Settings as OptionsSettings;
use RRZE\Calendar\CPT\CalendarEvent;
use RRZE\Calendar\Settings\Settings as OptionsSettings;

class Settings
{
Expand All @@ -14,7 +15,7 @@ class Settings

public function __construct()
{
add_action('rrze_wp_settings_after_update_option', [$this, 'flushRewriteRules']);
add_action('rrze_calendar_settings_after_update_option', [$this, 'flushRewriteRules']);
}

public function loaded()
Expand Down Expand Up @@ -67,7 +68,9 @@ public function loaded()
public function flushRewriteRules($optionName)
{
if ($optionName === self::OPTION_NAME) {
flush_rewrite_rules(false);
// Register the 'CalendarEvent' CPT again and flush rewrite rules.
CalendarEvent::registerPostType();
flush_rewrite_rules();
}
}

Expand All @@ -88,27 +91,4 @@ public function getOptions()
{
return $this->settings->getOptions();
}

/**
* __call method
* Method overloading.
*/
public function __call(string $name, array $arguments)
{
if (!method_exists($this, $name)) {
$message = sprintf('Call to undefined method %1$s::%2$s', __CLASS__, $name);
do_action(
'rrze.log.error',
$message,
[
'class' => __CLASS__,
'method' => $name,
'arguments' => $arguments
]
);
if (defined('WP_DEBUG') && WP_DEBUG) {
throw new \Exception($message);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Settings;
namespace RRZE\Calendar\Settings;

defined('ABSPATH') || exit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Settings;
namespace RRZE\Calendar\Settings;

defined('ABSPATH') || exit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Settings;
namespace RRZE\Calendar\Settings;

defined('ABSPATH') || exit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Settings;
namespace RRZE\Calendar\Settings;

defined('ABSPATH') || exit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace RRZE\WP\Settings;
namespace RRZE\Calendar\Settings;

defined('ABSPATH') || exit;

use RRZE\WP\Settings\Options\{
use RRZE\Calendar\Settings\Options\{
Checkbox,
CheckboxMultiple,
Password,
Expand Down Expand Up @@ -43,7 +43,7 @@ public function __construct(Section $section, string $type, array $args = [])
$this->type = $type;
$this->args = $args;

$typeMap = apply_filters('rrze_wp_settings_option_type_map', [
$typeMap = apply_filters('rrze_calendar_settings_option_type_map', [
'checkbox' => Checkbox::class,
'checkbox-multiple' => CheckboxMultiple::class,
'password' => Password::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Settings\Options;
namespace RRZE\Calendar\Settings\Options;

defined('ABSPATH') || exit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Settings\Options;
namespace RRZE\Calendar\Settings\Options;

defined('ABSPATH') || exit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace RRZE\WP\Settings\Options;
namespace RRZE\Calendar\Settings\Options;

defined('ABSPATH') || exit;

use RRZE\WP\Settings\Encryption;
use RRZE\Calendar\Settings\Encryption;

class Password extends Type
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Settings\Options;
namespace RRZE\Calendar\Settings\Options;

defined('ABSPATH') || exit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Settings\Options;
namespace RRZE\Calendar\Settings\Options;

defined('ABSPATH') || exit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Settings\Options;
namespace RRZE\Calendar\Settings\Options;

defined('ABSPATH') || exit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RRZE\WP\Settings\Options;
namespace RRZE\Calendar\Settings\Options;

defined('ABSPATH') || exit;

Expand Down
Loading

0 comments on commit 7e20ade

Please sign in to comment.