joshmoreno / wpdev Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://getwpdev.com
Home Page: https://getwpdev.com
It would be nice if you didn't have to call methods but instead just access properties that called the methods. $Post->title()
could simply be $Post->title
. It would make the code more forgiving which generally equates to less bugs, which is always a win.
I come across cases where this would be extremely useful.
For example, maybe you have an event
custom post type and you want to encapsulate functionality for events. Maybe our app could benefit from an Event::formattedStartDate()
method or an Event::guestSpeakers()
method.
Extending the Post
model can be done already (basic oop - extend the class). So really, we just need a way to hook in and tell wpdev to return a different model under certain conditions.
Maybe something along these lines:
add_filter('wpdev.postModelClass', function($class, WP_Query $query){
if ($query->is_singular('event')) {
return \MyEventPlugin\Models\Event::class;
}
return $class;
}, 10, 2);
There are times where we don't call templates ourselves, maybe it's coming from a plugin, but we could still benefit from having access to the data passed to the initial template.
Maybe an app service container that would be the main entry point for getting stuff regardless of where you are in the app.
Currently tightenco/collect requires 7.1.3
.
Would need to drop to the 5.4.33 release to get the php dependency down to 5.6.4
.
Maybe two branches? Master for php 7.1.3
and another branch for 5.6.4
.
I'd also need to make sure the existing wpdev code is compatible with 5.6.4
.
For some reason reordering on the activated_plugin
hook wasn't reliable.
Refactoring to use pre_update_option_active_plugins
is working and probably a better choice as we're altering the value before it's saved rather than after.
bootstrap.php
-function on_plugin_activation()
-{
- // should end up evaluating to 'wpdev/wpdev.php'
- $path = basename(dirname(__DIR__)).'/wpdev.php';
- $plugins = get_option('active_plugins', []);
- $key = array_search($path, $plugins);
-
- if ($key !== false) {
- array_splice($plugins, $key, 1);
- array_unshift($plugins, $path);
- update_option('active_plugins', $plugins);
- }
-}
-add_action('activated_plugin', __NAMESPACE__.'\\on_plugin_activation');
+function on_pre_update_option_active_plugins($value, $old_value, $option)
+{
+ // should end up evaluating to 'wpdev/wpdev.php'
+ $path = basename(dirname(__DIR__)).'/wpdev.php';
+ $key = array_search($path, $value);
+
+ if ($key !== false) {
+ array_splice($value, $key, 1);
+ array_unshift($value, $path);
+ }
+
+ return $value;
+}
+add_filter('pre_update_option_active_plugins', +__NAMESPACE__.'\\on_pre_update_option_active_plugins', 10, 3);
Fatal error: Declaration of WPDev\Template\PluginTemplate::includeTemplate() must be compatible with WPDev\Template\Template::includeTemplate(): bool in /Users/home/Projects/WordPress/abcsd/public/wp-content/plugins/wpdev/inc/Template/PluginTemplate.php on line 37
Change it to
public function includeTemplate()
{
if (!$template = $this->getTemplate()) {
return;
}
$data = $this->data;
extract($data, EXTR_OVERWRITE);
include $template;
}
https://github.com/JoshMoreno/wpdev/blob/master/inc/Controller/ControllerLoader.php#L36
It can also return null
protected function buildAttributesString()
{
// concatenate key and value to make joining easier
$attribute_strings = [];
foreach ($this->attributes as $key => $value) {
if (is_null($value)) {
$attribute_strings[] = $key;
} else {
$attribute_strings[] = "$key=\"$value\"";
}
}
return join(' ', $attribute_strings);
}
should be
protected function buildAttributesString()
{
// concatenate key and value to make joining easier
$attribute_strings = [];
foreach ($this->attributes as $key => $value) {
if (is_null($value)) {
$attribute_strings[] = $key;
} else {
+ $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false);
$attribute_strings[] = "$key=\"$value\"";
}
}
return join(' ', $attribute_strings);
}
public function includeTemplate(): bool
{
if (!parent::includeTemplate() && is_readable($this->filePath)) {
$data = $this->data;
extract($data, EXTR_OVERWRITE);
include $this->filePath;
return true;
}
return false;
}
Looks like Whoops is causing this.
ControllerLoader.php
-public function getController(): ControllerInterface
+public function getController(): ?ControllerInterface
Add a way to disable whoops.
Use case would be for any data that shows in the header and footer. It will likely show on all pages.
Usually you can just create a custom widget, but I can see this being useful at times.
Something like this
public function isPostType($postType)
{
return $this->postType() === $postType;
}
// and/or an alias
public function isA($postType)
{
return $this->isPostType($postType);
}
Controllers for page templates get missed by the file finder.
Here's a fix, but this should be working out of the box. Note that your page template controllers have to be in the your-theme/controllers/page-templates/
directory for now.
/*
|--------------------------------------------------------------------------
| Fix page template controllers. They weren't getting found
|--------------------------------------------------------------------------
*/
add_filter('wpdev.controllers', function($controller_files) {
$result = [];
foreach ($controller_files as $name => $controllerFile) {
$parts = explode('/', $controllerFile[0]);
if (in_array('page-templates', $parts)) {
$result["page-templates/{$name}"] = $controllerFile;
} else {
// don't do anything
$result[$name] = $controllerFile;
}
}
return $result;
});
$Post = Post::create(get_option('page_for_posts', true));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.