Giter Club home page Giter Club logo

wpdev's People

Contributors

josh-gaslamp avatar joshmoreno avatar

Stargazers

 avatar  avatar

Watchers

 avatar

wpdev's Issues

Add __get method to Post model that call underlying methods

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.

Add an easy way to extend the Post model and use these new subclasses

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);

Add a way to get the main template data in other templates

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.

Make wpdev work with php 5.6

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.

Plugin order bug

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);

PluginTemplate::includeTemplate() not compatible with parent signature

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;
}

Html attributes aren't escaped

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);
}

PluginTemplate includeTemplate needs return type

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;
    }

getController can't return null

ControllerLoader.php

-public function getController(): ControllerInterface
+public function getController(): ?ControllerInterface

Add a global controller that runs on all pages

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.

Controllers for page templates don't work out of the box

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;
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.