Git Product home page Git Product logo

oik-lib's Introduction

oik-lib

banner

Description

Shared library management for WordPress plugins.

Background

In June 2015, other than extension plugins, very few WordPress plugins shared common logic. Hardly any implemented plugin dependency logic.

Plugins that used the same code had two choices:

  1. Make the code subtly different; by function name, namespace or classes
  2. Carefully manage the duplicated functions

Conversely, many developers were using Composer to satisfy requirements for libraries used by "plugins". Show evidence...

The oik-lib plugin is intended to support an API whereby plugins can request library functions without worrying too much about the source of the functions, or even the implementation.

The plugin is intended to be easy to install and maintain and does not require SSH access to be used.

Requirements

  • Ability to request a library
  • Notification actions when dependencies satisfied
  • Plugin dependency checking
  • Shared delivery of library functions
  • Applicable to plugins and themes
  • Fallback support for standalone plugins
  • Version checking
  • Support Composer packages

See oik-lib - requirements summary

Implementation

There are some library functions that are so crucial that these need to be available all the time.

While they are not part of WordPress core, these functions will need to be implemented in such a way that they can be available for use by any plugin or theme at all times.

This plugin achieves this by becoming a MU plugin.

It provides the basic set of APIs to allow each plugin to get involved with sharing.

The APIs are provided in library files which can be bundled in standalone plugins.

Multiple plugins may deliver the library functions, but only one of them will be used.

The logic will attempt to take into account a variety of ways of indicating the presence of library functions. Advanced logic, dynamically loadable on demand, will be used to attempt to resolve issues with inactive code or incompatible versions.

Installation

  1. Upload the contents of the oik-lib plugin to the `/wp-content/plugins/oik-lib' directory
  2. Activate the oik-lib plugin through the 'Plugins' menu in WordPress

Frequently Asked Questions

Where are the FAQs

See the official plugin documentation at oik-plugins

Screenshots

  1. oik-lib in action

Upgrade Notice

0.2.1

Tested PHP 8.1 and PHP 8.2.

0.2.0

Synchronized with oik v4.1.2's improved autoload. Tested with PHP 8.0

0.1.1

Synchronized with oik v3.2.1

0.1.0

Synchronized with oik v3.2.0-RC1

0.0.8

Synchronized with oik v3.1.1, oik-bwtrace v2.1.0 etc

0.0.7

Synchronized with oik v3.0.1, oik-bwtrace v2.0.12 etc

0.0.6

Synchronized with oik v3.0.0, oik-bwtrace v2.0.11 etc

0.0.5

Updated trace levels to reduce noise.

0.0.4

Synchronized with oik-bwtrace v2.0.7. Please also upgrade the oik base plugin and oik-bwtrace.

0.0.3

Upgrade for support for Composer packages. See oik-fum sample plugin. Please also upgrade oik and oik-bwtrace.

0.0.2

Upgrade to get better support for plugins performing dependency checking

0.0.1

First version for WordPress PHP library management

Changelog

0.2.1

  • Changed: Add PHPUnit tests to load .php files with PHP 8.2 #8
  • Tested: With WordPress 6.2-beta2
  • Tested: With PHP 8.0, 8.1 and 8.2
  • Tested: With PHPUnt 9.6

0.2.0

  • Fixed: Pass array not object to bw_tablerow.,https://github.com/bobbingwide/oik-libs/issues/#7
  • Changed: Reconcile PHP 8 updates
  • Changed: Reconcile libs/class-oik-update.php
  • Changed: Synchronized with oik v4.1.2
  • Tested: With WordPress 5.8
  • Tested: With PHP 8.0

0.1.1

  • Changed: Synchronized with oik v3.2.1

0.1.0

0.0.8

  • Changed: Synchronized with oik v3.1.1 and oik-bwtrace v2.1.0
  • Tested with WordPress 4.7.1 and WordPress Multisite

0.0.7

  • Tested: With WordPress 4.5.2 and WordPress MultiSite
  • Changed: Synchronized with oik v3.0.1 and oik-bwtrace v2.0.12

0.0.6

  • Tested: With WordPress 4.5

0.0.5

  • Changed: update trace levels
  • Tested: With WordPress 4.5-RC1

0.0.4

  • Changed: Synchronized with oik-bwtrace v2.0.7
  • Changed: Synchronized with oik v3.0.0-alpha.0917

0.0.3

  • Added: Add screenshot of the oik-lib admin page
  • Added: oik-admin, bobbforms and bobbfunc for admin page
  • Added: oik_require_file() API uses OIK_libs::require_file() method
  • Added: support for Composer libraries with multiple files
  • Changed: Delivers and loads oik-admin shared library
  • Changed: Don't display the "error" column
  • Changed: set oik-depends library to v3.0.0
  • Changed: some comment changes

0.0.2

  • Fixed: Corrected logic around plugin dependency checking
  • Changed: libs/bwtrace.php now at 2.0.1
  • Changed: libs/oik-lib.php now at 0.0.2
  • Changed: libs/oik_boot.php now at 3.0.0
  • Changed: Now dependent upon bobbfunc:3.0.0 - for bw_as_array()
  • Changed: Implements hook for admin_notices earlier; now priority 8, was 9.
  • Changed: Corrected names of the default libraries in the comments
  • Changed: Now dependent upon bobbfunc v3.0.0
  • Fixed: oik_lib_init() uses load_plugin_textdomain() instead of bw_load_plugin_textdomain()
  • Changed: Defers admin checks until "wp_loaded". Now tests for WP_errors in the response
  • Changed: Implements "oik_query_libs" with a lower priority than oik

0.0.1

  • Added: New plugin

Further reading

If you want to read more about the oik plugins then please visit the oik plugin "the oik plugin - for often included key-information"

oik-lib's People

Contributors

bobbingwide avatar

Stargazers

 avatar

Watchers

 avatar  avatar

oik-lib's Issues

Provide autoloading for shared libraries

oik-lib should be able to support autoloading of classes from the correct library file.
Suppose there are two plugins A and B which use the shared library L.
If the library L that we've already loaded is from plugin A then any classes that are referred to from the library should also be loaded from plugin A.

There should be an easy to use API to indicate that autoloading should be managed by oik-lib.
The solution should co-exist peacefully with Composer autoload logic.

Improve version checking in oik_require_lib()

The text below was copied from bobbingwide/oik#9 (comment)

When I first installed oik v3.2.0-RC1 on oik-plugins.co.uk I got the following Fatal Error
Fatal error: Uncaught Error: Call to undefined function oik_l10n_enable_jti() in oik/admin/oik-admin.inc:28
when attempting to visit wp-admin.

Explanation

  • This was because the oik-l10n library had not been loaded.
  • v0.0.8 of the oik-lib plugin was activated at the time.
  • It didn't matter what the value of the Enable as Must Use plugin? was.
  • oik_require_lib_wrapper( 'oik-l10n' ) had failed since the shared library was not registered.
  • and v0.0.8 did not yet implement fallback logic. #3

Workaround

  • When oik-lib was deactivated it worked.
  • Upgrading to v0.1.0 also resolved the issue.

Proposed solution

  • oik should register the 'oik-i10n' shared library

This resolves the Fatal Error problem but oik v0.0.8 will still not work fully as there are incompatible versions of shared libraries in play.
oik-lib calls oik_require_lib( "bobbfunc", "3.0.0" ) which returns

bobbfunc? WP_Error Object
(
    [errors] => Array
        (
            [incompatible] => Array
                (
                    [0] => Incompatible library already loaded
                )

        )

    [error_data] => Array
        (
            [incompatible] => OIK_lib Object
                (
                    [library] => bobbfunc
                    [path] => 
                    [src] => C:\apache\htdocs\oikcom/wp-content/plugins/oik/libs/bobbfunc.php
                    [deps] => Array
                        (
                        )

                    [version] => 
                    [args] => Array
                        (
                            [library] => bobbfunc
                            [src] => C:\apache\htdocs\oikcom/wp-content/plugins/oik/libs/bobbfunc.php
                            [deps] => 
                        )

                    [error] => 
                )

        )

)

As a result oik-lib does not add an action hook for 'admin_menu' so the oik-lib admin page is not enabled.

Requirements for oik-lib

  • Something is needed to make it easier to debug this version incompatibility logic.

Incorrect dependency checking when oik-lib Must-Use enabled

The oik-lib plugin provides a function which enables the plugin to be enabled as a Must-Use plugin.

One reason for doing this is to reduce the number of messages associated with unsatisfied plugin dependencies. e.g. cookie-cat and oik-nivo-slider are both dependent upon oik. If oik is not activated each dependent plugin will attempt to report a problem.
The new logic in the oik/oik-lib dependency libraries is designed to reduce the number of messages.

At present, this is not working. The dependency checking is reporting that oik is not activated even though it is.

Workaround

Do not select the Enable as Must Use plugin checkbox.

Fatal error: count(): Argument #1 ($var) must be of type Countable|array, OIK_lib given

Stack trace: 
#0 C:\apache\htdocs\oikcom\wp-content\plugins\oik-lib\admin\oik-lib.php(92): bw_tablerow(Object(OIK_lib)) 
#1 C:\apache\htdocs\wordpress\wp-content\plugins\oik\libs\class-BW-.php(97): oik_lib_display_libraries() 
#2 C:\apache\htdocs\oikcom\wp-content\plugins\oik-lib\admin\oik-lib.php(38): BW_::oik_box(NULL, 'oik_lib_display...', 'Registered libr...', 'oik_lib_display...') 
#3 C:\apache\htdocs\oikcom\wp-includes\class-wp-hook.php(303): oik_lib_options_do_page('')
#4 C:\apache\htdocs\oikcom\wp-includes\class-wp-hook.php(327): WP_Hook->apply_filters('', Array) 
#5 C:\apache\htdocs\oikcom\wp-includes\plugin.php(470): WP_Hook->do_action(Array) 
#6 C:\apache\htdocs\oikcom\wp-admin\admin.php(259): do_action('settings_page_o...') 
#7 C:\apache\htdocs\oikcom\wp-admin\options-general.php(10): require_once('C:\\apache\\htdoc...') 
#8 {main} thrown in C:\apache\htdocs\wordpress\wp-content\plugins\oik\libs\bobbforms.php on line 270

oik-lib should follow the fallback route if a registered library is not found

Problem statement

In one of my development environments ( qw/wp44 ), when testing the plugin update logic in oik-weight-zone-shipping-pro, I had deactivated all plugins except for oik-weight-zone-shipping-pro and the mu_plugins, which included oik-lib. When oik-lib used the require_lib() method to load the 'class-bobbcomp' library, since oik-weight-zone-shipping-pro had not registered the libraries that it has included in the libs folder, the library file was not 'found' so it wasn't loaded. The directory had however been identified using oik_lib_fallback().

Proposed solution

oik-lib should attempt to locate a library file using the fallback method. This is the technique that a plugin such as oik-weight-zone-shipping-pro, which does not have a dependency on oik, expects to be used.

Workaround

Deactivate the mu-plugins as well. One method is to rename the folder.

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.