Commit realizado el 12:13:52 08-04-2024

This commit is contained in:
Pagina Web Monito
2024-04-08 12:13:55 -04:00
commit 0c33094de9
7815 changed files with 1365694 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
workflows:
version: 2
main:
jobs:
- php72-build
- php73-build
- php74-build
- php80-build
version: 2
job-references:
mysql_image: &mysql_image
cimg/mysql:5.7
setup_environment: &setup_environment
name: "Setup Environment Variables"
command: |
echo "export PATH=$HOME/.composer/vendor/bin:$PATH" >> $BASH_ENV
source /home/circleci/.bashrc
install_dependencies: &install_dependencies
name: "Install Dependencies"
command: |
sudo apt-get update && sudo apt-get install mysql-client subversion
php_job: &php_job
environment:
- WP_TESTS_DIR: "/tmp/wordpress-tests-lib"
- WP_CORE_DIR: "/tmp/wordpress/"
steps:
- checkout
- run: php --version
- run: composer --version
- run: *setup_environment
- run: *install_dependencies
- run:
name: "Run Tests"
command: |
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
make test-unit
WP_MULTISITE=1 make test-unit
make test-style
jobs:
php56-build:
<<: *php_job
docker:
- image: cimg/php:5.6
- image: *mysql_image
php70-build:
<<: *php_job
docker:
- image: cimg/php:7.0
- image: *mysql_image
php71-build:
<<: *php_job
docker:
- image: cimg/php:7.1
- image: *mysql_image
php72-build:
<<: *php_job
docker:
- image: cimg/php:7.2
- image: *mysql_image
php73-build:
<<: *php_job
docker:
- image: cimg/php:7.3
- image: *mysql_image
php74-build:
<<: *php_job
docker:
- image: cimg/php:7.4
- image: *mysql_image
php80-build:
<<: *php_job
docker:
- image: cimg/php:8.0
- image: *mysql_image
php81-build:
<<: *php_job
docker:
- image: cimg/php:8.1
- image: *mysql_image

View File

@@ -0,0 +1,65 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards based custom ruleset for your plugin">
<description>Generally-applicable sniffs for WordPress plugins.</description>
<!-- What to scan -->
<file>.</file>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/node_modules/</exclude-pattern>
<exclude-pattern>/tests/*</exclude-pattern>
<!-- How to scan -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<arg value="sp"/> <!-- Show sniff and progress -->
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->
<!-- Rules: Check PHP version compatibility -->
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="5.6-"/>
<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<rule ref="PHPCompatibilityWP"/>
<!-- Rules: WordPress Coding Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<config name="minimum_supported_wp_version" value="4.6"/>
<rule ref="WordPress">
<!-- Unable to fix -->
<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound"/>
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound"/>
<exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching"/>
<!-- TODO: Maybe fix -->
<exclude name="WordPress.WP.CronInterval.ChangeDetected"/>
<exclude name="WordPress.DB.DirectDatabaseQuery.DirectQuery"/>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
<property name="prefixes" type="array" value="wpbp"/>
</properties>
<!-- TODO: Maybe fix -->
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound"/>
</rule>
<rule ref="WordPress.WP.I18n">
<properties>
<!-- Value: replace the text domain used. -->
<property name="text_domain" type="array" value="wp-background-processing"/>
</properties>
<!-- TODO: Should fix -->
<exclude name="WordPress.WP.I18n.MissingArgDomain"/>
<exclude name="WordPress.WP.I18n.MissingTranslatorsComment"/>
</rule>
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
<properties>
<property name="blank_line_check" value="true"/>
</properties>
</rule>
</ruleset>

View File

@@ -0,0 +1,18 @@
.PHONY: test
test: test-unit test-style
.PHONY: test-unit
test-unit: vendor
vendor/bin/phpunit
.PHONY: test-style
test-style: vendor
vendor/bin/phpcs
vendor: composer.json
composer install --ignore-platform-reqs
.PHONY: clean
clean:
rm -rf vendor
rm -f tests/.phpunit.result.cache

View File

@@ -0,0 +1,202 @@
<?php
/**
* WP Async Request
*
* @package WP-Background-Processing
*/
/**
* Abstract WP_Async_Request class.
*
* @abstract
*/
abstract class WP_Async_Request {
/**
* Prefix
*
* (default value: 'wp')
*
* @var string
* @access protected
*/
protected $prefix = 'wp';
/**
* Action
*
* (default value: 'async_request')
*
* @var string
* @access protected
*/
protected $action = 'async_request';
/**
* Identifier
*
* @var mixed
* @access protected
*/
protected $identifier;
/**
* Data
*
* (default value: array())
*
* @var array
* @access protected
*/
protected $data = array();
/**
* Initiate new async request.
*/
public function __construct() {
$this->identifier = $this->prefix . '_' . $this->action;
add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
}
/**
* Set data used during the request.
*
* @param array $data Data.
*
* @return $this
*/
public function data( $data ) {
$this->data = $data;
return $this;
}
/**
* Dispatch the async request.
*
* @return array|WP_Error|false HTTP Response array, WP_Error on failure, or false if not attempted.
*/
public function dispatch() {
$url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
$args = $this->get_post_args();
return wp_remote_post( esc_url_raw( $url ), $args );
}
/**
* Get query args.
*
* @return array
*/
protected function get_query_args() {
if ( property_exists( $this, 'query_args' ) ) {
return $this->query_args;
}
$args = array(
'action' => $this->identifier,
'nonce' => wp_create_nonce( $this->identifier ),
);
/**
* Filters the post arguments used during an async request.
*
* @param array $url
*/
return apply_filters( $this->identifier . '_query_args', $args );
}
/**
* Get query URL.
*
* @return string
*/
protected function get_query_url() {
if ( property_exists( $this, 'query_url' ) ) {
return $this->query_url;
}
$url = admin_url( 'admin-ajax.php' );
/**
* Filters the post arguments used during an async request.
*
* @param string $url
*/
return apply_filters( $this->identifier . '_query_url', $url );
}
/**
* Get post args.
*
* @return array
*/
protected function get_post_args() {
if ( property_exists( $this, 'post_args' ) ) {
return $this->post_args;
}
$args = array(
'timeout' => 5,
'blocking' => false,
'body' => $this->data,
'cookies' => $_COOKIE, // Passing cookies ensures request is performed as initiating user.
'sslverify' => apply_filters( 'https_local_ssl_verify', false ), // Local requests, fine to pass false.
);
/**
* Filters the post arguments used during an async request.
*
* @param array $args
*/
return apply_filters( $this->identifier . '_post_args', $args );
}
/**
* Maybe handle a dispatched request.
*
* Check for correct nonce and pass to handler.
*
* @return void|mixed
*/
public function maybe_handle() {
// Don't lock up other requests while processing.
session_write_close();
check_ajax_referer( $this->identifier, 'nonce' );
$this->handle();
return $this->maybe_wp_die();
}
/**
* Should the process exit with wp_die?
*
* @param mixed $return What to return if filter says don't die, default is null.
*
* @return void|mixed
*/
protected function maybe_wp_die( $return = null ) {
/**
* Should wp_die be used?
*
* @return bool
*/
if ( apply_filters( $this->identifier . '_wp_die', true ) ) {
wp_die();
}
return $return;
}
/**
* Handle a dispatched request.
*
* Override this method to perform any actions required
* during the async request.
*/
abstract protected function handle();
}

View File

@@ -0,0 +1,786 @@
<?php
/**
* WP Background Process
*
* @package WP-Background-Processing
*/
/**
* Abstract WP_Background_Process class.
*
* @abstract
* @extends WP_Async_Request
*/
abstract class WP_Background_Process extends WP_Async_Request {
/**
* Action
*
* (default value: 'background_process')
*
* @var string
* @access protected
*/
protected $action = 'background_process';
/**
* Start time of current process.
*
* (default value: 0)
*
* @var int
* @access protected
*/
protected $start_time = 0;
/**
* Cron_hook_identifier
*
* @var string
* @access protected
*/
protected $cron_hook_identifier;
/**
* Cron_interval_identifier
*
* @var string
* @access protected
*/
protected $cron_interval_identifier;
/**
* Restrict object instantiation when using unserialize.
*
* @var bool|array
*/
protected $allowed_batch_data_classes = true;
/**
* The status set when process is cancelling.
*
* @var int
*/
const STATUS_CANCELLED = 1;
/**
* The status set when process is paused or pausing.
*
* @var int;
*/
const STATUS_PAUSED = 2;
/**
* Initiate new background process.
*
* @param bool|array $allowed_batch_data_classes Optional. Array of class names that can be unserialized. Default true (any class).
*/
public function __construct( $allowed_batch_data_classes = true ) {
parent::__construct();
if ( empty( $allowed_batch_data_classes ) && false !== $allowed_batch_data_classes ) {
$allowed_batch_data_classes = true;
}
if ( ! is_bool( $allowed_batch_data_classes ) && ! is_array( $allowed_batch_data_classes ) ) {
$allowed_batch_data_classes = true;
}
// If allowed_batch_data_classes property set in subclass,
// only apply override if not allowing any class.
if ( true === $this->allowed_batch_data_classes || true !== $allowed_batch_data_classes ) {
$this->allowed_batch_data_classes = $allowed_batch_data_classes;
}
$this->cron_hook_identifier = $this->identifier . '_cron';
$this->cron_interval_identifier = $this->identifier . '_cron_interval';
add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
}
/**
* Schedule the cron healthcheck and dispatch an async request to start processing the queue.
*
* @access public
* @return array|WP_Error|false HTTP Response array, WP_Error on failure, or false if not attempted.
*/
public function dispatch() {
if ( $this->is_processing() ) {
// Process already running.
return false;
}
// Schedule the cron healthcheck.
$this->schedule_event();
// Perform remote post.
return parent::dispatch();
}
/**
* Push to the queue.
*
* Note, save must be called in order to persist queued items to a batch for processing.
*
* @param mixed $data Data.
*
* @return $this
*/
public function push_to_queue( $data ) {
$this->data[] = $data;
return $this;
}
/**
* Save the queued items for future processing.
*
* @return $this
*/
public function save() {
$key = $this->generate_key();
if ( ! empty( $this->data ) ) {
update_site_option( $key, $this->data );
}
// Clean out data so that new data isn't prepended with closed session's data.
$this->data = array();
return $this;
}
/**
* Update a batch's queued items.
*
* @param string $key Key.
* @param array $data Data.
*
* @return $this
*/
public function update( $key, $data ) {
if ( ! empty( $data ) ) {
update_site_option( $key, $data );
}
return $this;
}
/**
* Delete a batch of queued items.
*
* @param string $key Key.
*
* @return $this
*/
public function delete( $key ) {
delete_site_option( $key );
return $this;
}
/**
* Delete entire job queue.
*/
public function delete_all() {
$batches = $this->get_batches();
foreach ( $batches as $batch ) {
$this->delete( $batch->key );
}
delete_site_option( $this->get_status_key() );
$this->cancelled();
}
/**
* Cancel job on next batch.
*/
public function cancel() {
update_site_option( $this->get_status_key(), self::STATUS_CANCELLED );
// Just in case the job was paused at the time.
$this->dispatch();
}
/**
* Has the process been cancelled?
*
* @return bool
*/
public function is_cancelled() {
$status = get_site_option( $this->get_status_key(), 0 );
return absint( $status ) === self::STATUS_CANCELLED;
}
/**
* Called when background process has been cancelled.
*/
protected function cancelled() {
do_action( $this->identifier . '_cancelled' );
}
/**
* Pause job on next batch.
*/
public function pause() {
update_site_option( $this->get_status_key(), self::STATUS_PAUSED );
}
/**
* Is the job paused?
*
* @return bool
*/
public function is_paused() {
$status = get_site_option( $this->get_status_key(), 0 );
return absint( $status ) === self::STATUS_PAUSED;
}
/**
* Called when background process has been paused.
*/
protected function paused() {
do_action( $this->identifier . '_paused' );
}
/**
* Resume job.
*/
public function resume() {
delete_site_option( $this->get_status_key() );
$this->schedule_event();
$this->dispatch();
$this->resumed();
}
/**
* Called when background process has been resumed.
*/
protected function resumed() {
do_action( $this->identifier . '_resumed' );
}
/**
* Is queued?
*
* @return bool
*/
public function is_queued() {
return ! $this->is_queue_empty();
}
/**
* Is the tool currently active, e.g. starting, working, paused or cleaning up?
*
* @return bool
*/
public function is_active() {
return $this->is_queued() || $this->is_processing() || $this->is_paused() || $this->is_cancelled();
}
/**
* Generate key for a batch.
*
* Generates a unique key based on microtime. Queue items are
* given a unique key so that they can be merged upon save.
*
* @param int $length Optional max length to trim key to, defaults to 64 characters.
* @param string $key Optional string to append to identifier before hash, defaults to "batch".
*
* @return string
*/
protected function generate_key( $length = 64, $key = 'batch' ) {
$unique = md5( microtime() . wp_rand() );
$prepend = $this->identifier . '_' . $key . '_';
return substr( $prepend . $unique, 0, $length );
}
/**
* Get the status key.
*
* @return string
*/
protected function get_status_key() {
return $this->identifier . '_status';
}
/**
* Maybe process a batch of queued items.
*
* Checks whether data exists within the queue and that
* the process is not already running.
*/
public function maybe_handle() {
// Don't lock up other requests while processing.
session_write_close();
if ( $this->is_processing() ) {
// Background process already running.
return $this->maybe_wp_die();
}
if ( $this->is_cancelled() ) {
$this->clear_scheduled_event();
$this->delete_all();
return $this->maybe_wp_die();
}
if ( $this->is_paused() ) {
$this->clear_scheduled_event();
$this->paused();
return $this->maybe_wp_die();
}
if ( $this->is_queue_empty() ) {
// No data to process.
return $this->maybe_wp_die();
}
check_ajax_referer( $this->identifier, 'nonce' );
$this->handle();
return $this->maybe_wp_die();
}
/**
* Is queue empty?
*
* @return bool
*/
protected function is_queue_empty() {
return empty( $this->get_batch() );
}
/**
* Is process running?
*
* Check whether the current process is already running
* in a background process.
*
* @return bool
*
* @deprecated 1.1.0 Superseded.
* @see is_processing()
*/
protected function is_process_running() {
return $this->is_processing();
}
/**
* Is the background process currently running?
*
* @return bool
*/
public function is_processing() {
if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
// Process already running.
return true;
}
return false;
}
/**
* Lock process.
*
* Lock the process so that multiple instances can't run simultaneously.
* Override if applicable, but the duration should be greater than that
* defined in the time_exceeded() method.
*/
protected function lock_process() {
$this->start_time = time(); // Set start time of current process.
$lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
$lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
}
/**
* Unlock process.
*
* Unlock the process so that other instances can spawn.
*
* @return $this
*/
protected function unlock_process() {
delete_site_transient( $this->identifier . '_process_lock' );
return $this;
}
/**
* Get batch.
*
* @return stdClass Return the first batch of queued items.
*/
protected function get_batch() {
return array_reduce(
$this->get_batches( 1 ),
static function ( $carry, $batch ) {
return $batch;
},
array()
);
}
/**
* Get batches.
*
* @param int $limit Number of batches to return, defaults to all.
*
* @return array of stdClass
*/
public function get_batches( $limit = 0 ) {
global $wpdb;
if ( empty( $limit ) || ! is_int( $limit ) ) {
$limit = 0;
}
$table = $wpdb->options;
$column = 'option_name';
$key_column = 'option_id';
$value_column = 'option_value';
if ( is_multisite() ) {
$table = $wpdb->sitemeta;
$column = 'meta_key';
$key_column = 'meta_id';
$value_column = 'meta_value';
}
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
$sql = '
SELECT *
FROM ' . $table . '
WHERE ' . $column . ' LIKE %s
ORDER BY ' . $key_column . ' ASC
';
$args = array( $key );
if ( ! empty( $limit ) ) {
$sql .= ' LIMIT %d';
$args[] = $limit;
}
$items = $wpdb->get_results( $wpdb->prepare( $sql, $args ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$batches = array();
if ( ! empty( $items ) ) {
$allowed_classes = $this->allowed_batch_data_classes;
$batches = array_map(
static function ( $item ) use ( $column, $value_column, $allowed_classes ) {
$batch = new stdClass();
$batch->key = $item->{$column};
$batch->data = static::maybe_unserialize( $item->{$value_column}, $allowed_classes );
return $batch;
},
$items
);
}
return $batches;
}
/**
* Handle a dispatched request.
*
* Pass each queue item to the task handler, while remaining
* within server memory and time limit constraints.
*/
protected function handle() {
$this->lock_process();
/**
* Number of seconds to sleep between batches. Defaults to 0 seconds, minimum 0.
*
* @param int $seconds
*/
$throttle_seconds = max(
0,
apply_filters(
$this->identifier . '_seconds_between_batches',
apply_filters(
$this->prefix . '_seconds_between_batches',
0
)
)
);
do {
$batch = $this->get_batch();
foreach ( $batch->data as $key => $value ) {
$task = $this->task( $value );
if ( false !== $task ) {
$batch->data[ $key ] = $task;
} else {
unset( $batch->data[ $key ] );
}
// Keep the batch up to date while processing it.
if ( ! empty( $batch->data ) ) {
$this->update( $batch->key, $batch->data );
}
// Let the server breathe a little.
sleep( $throttle_seconds );
// Batch limits reached, or pause or cancel request.
if ( $this->time_exceeded() || $this->memory_exceeded() || $this->is_paused() || $this->is_cancelled() ) {
break;
}
}
// Delete current batch if fully processed.
if ( empty( $batch->data ) ) {
$this->delete( $batch->key );
}
} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() && ! $this->is_paused() && ! $this->is_cancelled() );
$this->unlock_process();
// Start next batch or complete process.
if ( ! $this->is_queue_empty() ) {
$this->dispatch();
} else {
$this->complete();
}
return $this->maybe_wp_die();
}
/**
* Memory exceeded?
*
* Ensures the batch process never exceeds 90%
* of the maximum WordPress memory.
*
* @return bool
*/
protected function memory_exceeded() {
$memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory
$current_memory = memory_get_usage( true );
$return = false;
if ( $current_memory >= $memory_limit ) {
$return = true;
}
return apply_filters( $this->identifier . '_memory_exceeded', $return );
}
/**
* Get memory limit in bytes.
*
* @return int
*/
protected function get_memory_limit() {
if ( function_exists( 'ini_get' ) ) {
$memory_limit = ini_get( 'memory_limit' );
} else {
// Sensible default.
$memory_limit = '128M';
}
if ( ! $memory_limit || -1 === intval( $memory_limit ) ) {
// Unlimited, set to 32GB.
$memory_limit = '32000M';
}
return wp_convert_hr_to_bytes( $memory_limit );
}
/**
* Time limit exceeded?
*
* Ensures the batch never exceeds a sensible time limit.
* A timeout limit of 30s is common on shared hosting.
*
* @return bool
*/
protected function time_exceeded() {
$finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
$return = false;
if ( time() >= $finish ) {
$return = true;
}
return apply_filters( $this->identifier . '_time_exceeded', $return );
}
/**
* Complete processing.
*
* Override if applicable, but ensure that the below actions are
* performed, or, call parent::complete().
*/
protected function complete() {
delete_site_option( $this->get_status_key() );
// Remove the cron healthcheck job from the cron schedule.
$this->clear_scheduled_event();
$this->completed();
}
/**
* Called when background process has completed.
*/
protected function completed() {
do_action( $this->identifier . '_completed' );
}
/**
* Get the cron healthcheck interval in minutes.
*
* Default is 5 minutes, minimum is 1 minute.
*
* @return int
*/
public function get_cron_interval() {
$interval = 5;
if ( property_exists( $this, 'cron_interval' ) ) {
$interval = $this->cron_interval;
}
$interval = apply_filters( $this->cron_interval_identifier, $interval );
return is_int( $interval ) && 0 < $interval ? $interval : 5;
}
/**
* Schedule the cron healthcheck job.
*
* @access public
*
* @param mixed $schedules Schedules.
*
* @return mixed
*/
public function schedule_cron_healthcheck( $schedules ) {
$interval = $this->get_cron_interval();
if ( 1 === $interval ) {
$display = __( 'Every Minute' );
} else {
$display = sprintf( __( 'Every %d Minutes' ), $interval );
}
// Adds an "Every NNN Minute(s)" schedule to the existing cron schedules.
$schedules[ $this->cron_interval_identifier ] = array(
'interval' => MINUTE_IN_SECONDS * $interval,
'display' => $display,
);
return $schedules;
}
/**
* Handle cron healthcheck event.
*
* Restart the background process if not already running
* and data exists in the queue.
*/
public function handle_cron_healthcheck() {
if ( $this->is_processing() ) {
// Background process already running.
exit;
}
if ( $this->is_queue_empty() ) {
// No data to process.
$this->clear_scheduled_event();
exit;
}
$this->dispatch();
}
/**
* Schedule the cron healthcheck event.
*/
protected function schedule_event() {
if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
wp_schedule_event( time() + ( $this->get_cron_interval() * MINUTE_IN_SECONDS ), $this->cron_interval_identifier, $this->cron_hook_identifier );
}
}
/**
* Clear scheduled cron healthcheck event.
*/
protected function clear_scheduled_event() {
$timestamp = wp_next_scheduled( $this->cron_hook_identifier );
if ( $timestamp ) {
wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
}
}
/**
* Cancel the background process.
*
* Stop processing queue items, clear cron job and delete batch.
*
* @deprecated 1.1.0 Superseded.
* @see cancel()
*/
public function cancel_process() {
$this->cancel();
}
/**
* Perform task with queued item.
*
* Override this method to perform any actions required on each
* queue item. Return the modified item for further processing
* in the next pass through. Or, return false to remove the
* item from the queue.
*
* @param mixed $item Queue item to iterate over.
*
* @return mixed
*/
abstract protected function task( $item );
/**
* Maybe unserialize data, but not if an object.
*
* @param mixed $data Data to be unserialized.
* @param bool|array $allowed_classes Array of class names that can be unserialized.
*
* @return mixed
*/
protected static function maybe_unserialize( $data, $allowed_classes ) {
if ( is_serialized( $data ) ) {
$options = array();
if ( is_bool( $allowed_classes ) || is_array( $allowed_classes ) ) {
$options['allowed_classes'] = $allowed_classes;
}
return @unserialize( $data, $options ); // @phpcs:ignore
}
return $data;
}
}

View File

@@ -0,0 +1,280 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS

View File

@@ -0,0 +1,24 @@
<?php
/**
* WP-Background Processing
*
* @package WP-Background-Processing
*/
/**
* Plugin Name: WP Background Processing
* Plugin URI: https://github.com/deliciousbrains/wp-background-processing
* Description: Asynchronous requests and background processing in WordPress.
* Author: Delicious Brains Inc.
* Version: 1.0
* Author URI: https://deliciousbrains.com/
* GitHub Plugin URI: https://github.com/deliciousbrains/wp-background-processing
* GitHub Branch: master
*/
if ( ! class_exists( 'WP_Async_Request' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'classes/wp-async-request.php';
}
if ( ! class_exists( 'WP_Background_Process' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'classes/wp-background-process.php';
}

View File

@@ -0,0 +1,25 @@
<?php
// autoload.php @generated by Composer
if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
}
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInite0bd047aa5058f04568aa38dfc5ac000::getLoader();

View File

@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@@ -0,0 +1,84 @@
<?php
/**
* Bootstraps the CMB2 process
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2
* @license GPL-2.0+
* @link https://cmb2.io
*/
/**
* Function to encapsulate the CMB2 bootstrap process.
*
* @since 2.2.0
* @return void
*/
function cmb2_bootstrap() {
if ( is_admin() ) {
/**
* Fires on the admin side when CMB2 is included/loaded.
*
* In most cases, this should be used to add metaboxes. See example-functions.php
*/
do_action( 'cmb2_admin_init' );
}
/**
* Fires when CMB2 is included/loaded
*
* Can be used to add metaboxes if needed on the front-end or WP-API (or the front and backend).
*/
do_action( 'cmb2_init' );
/**
* For back-compat. Does the dirty-work of instantiating all the
* CMB2 instances for the cmb2_meta_boxes filter
*
* @since 2.0.2
*/
$cmb_config_arrays = apply_filters( 'cmb2_meta_boxes', array() );
foreach ( (array) $cmb_config_arrays as $cmb_config ) {
new CMB2( $cmb_config );
}
/**
* Fires after all CMB2 instances are created
*/
do_action( 'cmb2_init_before_hookup' );
/**
* Get all created metaboxes, and instantiate CMB2_Hookup
* on metaboxes which require it.
*
* @since 2.0.2
*/
foreach ( CMB2_Boxes::get_all() as $cmb ) {
/**
* Initiates the box "hookup" into WordPress.
*
* Unless the 'hookup' box property is `false`, the box will be hooked in as
* a post/user/comment/option/term box.
*
* And if the 'show_in_rest' box property is set, the box will be hooked
* into the CMB2 REST API.
*
* The dynamic portion of the hook name, $cmb->cmb_id, is the box id.
*
* @since 2.2.6
*
* @param array $cmb The CMB2 object to hookup.
*/
do_action( "cmb2_init_hookup_{$cmb->cmb_id}", $cmb );
}
/**
* Fires after CMB2 initiation process has been completed
*/
do_action( 'cmb2_after_init' );
}
/* End. That's it, folks! */

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,323 @@
<?php
/**
* CMB2 ajax methods
* (i.e. a lot of work to get oEmbeds to work with non-post objects)
*
* @since 0.9.5
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
*/
class CMB2_Ajax {
// Whether to hijack the oembed cache system.
protected $hijack = false;
protected $object_id = 0;
protected $embed_args = array();
protected $object_type = 'post';
protected $ajax_update = false;
/**
* Instance of this class.
*
* @since 2.2.2
* @var object
*/
protected static $instance;
/**
* Get the singleton instance of this class.
*
* @since 2.2.2
* @return CMB2_Ajax
*/
public static function get_instance() {
if ( ! ( self::$instance instanceof self ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*
* @since 2.2.0
*/
protected function __construct() {
add_action( 'wp_ajax_cmb2_oembed_handler', array( $this, 'oembed_handler' ) );
add_action( 'wp_ajax_nopriv_cmb2_oembed_handler', array( $this, 'oembed_handler' ) );
// Need to occasionally clean stale oembed cache data from the option value.
add_action( 'cmb2_save_options-page_fields', array( __CLASS__, 'clean_stale_options_page_oembeds' ) );
}
/**
* Handles our oEmbed ajax request
*
* @since 0.9.5
* @return mixed oEmbed embed code | fallback | error message
*/
public function oembed_handler() {
// Verify our nonce.
if ( ! ( isset( $_REQUEST['cmb2_ajax_nonce'], $_REQUEST['oembed_url'] ) && wp_verify_nonce( $_REQUEST['cmb2_ajax_nonce'], 'ajax_nonce' ) ) ) {
die();
}
// Sanitize our search string.
$oembed_string = sanitize_text_field( $_REQUEST['oembed_url'] );
// Send back error if empty.
if ( empty( $oembed_string ) ) {
wp_send_json_error( '<p class="ui-state-error-text">' . esc_html__( 'Please Try Again', 'cmb2' ) . '</p>' );
}
// Set width of embed.
$embed_width = isset( $_REQUEST['oembed_width'] ) && intval( $_REQUEST['oembed_width'] ) < 640 ? intval( $_REQUEST['oembed_width'] ) : '640';
// Set url.
$oembed_url = esc_url( $oembed_string );
// Set args.
$embed_args = array(
'width' => $embed_width,
);
$this->ajax_update = true;
// Get embed code (or fallback link).
$html = $this->get_oembed( array(
'url' => $oembed_url,
'object_id' => $_REQUEST['object_id'],
'object_type' => isset( $_REQUEST['object_type'] ) ? $_REQUEST['object_type'] : 'post',
'oembed_args' => $embed_args,
'field_id' => $_REQUEST['field_id'],
) );
wp_send_json_success( $html );
}
/**
* Retrieves oEmbed from url/object ID
*
* @since 0.9.5
* @param array $args Arguments for method.
* @return mixed HTML markup with embed or fallback.
*/
public function get_oembed_no_edit( $args ) {
global $wp_embed;
$oembed_url = esc_url( $args['url'] );
// Sanitize object_id.
$this->object_id = is_numeric( $args['object_id'] ) ? absint( $args['object_id'] ) : sanitize_text_field( $args['object_id'] );
$args = wp_parse_args( $args, array(
'object_type' => 'post',
'oembed_args' => array(),
'field_id' => false,
'wp_error' => false,
) );
$this->embed_args =& $args;
/*
* Set the post_ID so oEmbed won't fail
* wp-includes/class-wp-embed.php, WP_Embed::shortcode()
*/
$wp_embed->post_ID = $this->object_id;
// Special scenario if NOT a post object.
if ( isset( $args['object_type'] ) && 'post' != $args['object_type'] ) {
if ( 'options-page' == $args['object_type'] ) {
// Bogus id to pass some numeric checks. Issue with a VERY large WP install?
$wp_embed->post_ID = 1987645321;
}
// Ok, we need to hijack the oembed cache system.
$this->hijack = true;
$this->object_type = $args['object_type'];
// Gets ombed cache from our object's meta (vs postmeta).
add_filter( 'get_post_metadata', array( $this, 'hijack_oembed_cache_get' ), 10, 3 );
// Sets ombed cache in our object's meta (vs postmeta).
add_filter( 'update_post_metadata', array( $this, 'hijack_oembed_cache_set' ), 10, 4 );
}
$embed_args = '';
foreach ( $args['oembed_args'] as $key => $val ) {
$embed_args .= " $key=\"$val\"";
}
// Ping WordPress for an embed.
$embed = $wp_embed->run_shortcode( '[embed' . $embed_args . ']' . $oembed_url . '[/embed]' );
// Fallback that WordPress creates when no oEmbed was found.
$fallback = $wp_embed->maybe_make_link( $oembed_url );
return compact( 'embed', 'fallback', 'args' );
}
/**
* Retrieves oEmbed from url/object ID
*
* @since 0.9.5
* @param array $args Arguments for method.
* @return string HTML markup with embed or fallback.
*/
public function get_oembed( $args ) {
$oembed = $this->get_oembed_no_edit( $args );
// Send back our embed.
if ( $oembed['embed'] && $oembed['embed'] != $oembed['fallback'] ) {
return '<div class="cmb2-oembed embed-status">' . $oembed['embed'] . '<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button" rel="' . $oembed['args']['field_id'] . '">' . esc_html__( 'Remove Embed', 'cmb2' ) . '</a></p></div>';
}
// Otherwise, send back error info that no oEmbeds were found.
return sprintf(
'<p class="ui-state-error-text">%s</p>',
sprintf(
/* translators: 1: results for. 2: link to codex.wordpress.org/Embeds */
esc_html__( 'No oEmbed Results Found for %1$s. View more info at %2$s.', 'cmb2' ),
$oembed['fallback'],
'<a href="https://wordpress.org/support/article/embeds/" target="_blank">codex.wordpress.org/Embeds</a>'
)
);
}
/**
* Hijacks retrieving of cached oEmbed.
* Returns cached data from relevant object metadata (vs postmeta)
*
* @since 0.9.5
* @param boolean $check Whether to retrieve postmeta or override.
* @param int $object_id Object ID.
* @param string $meta_key Object metakey.
* @return mixed Object's oEmbed cached data.
*/
public function hijack_oembed_cache_get( $check, $object_id, $meta_key ) {
if ( ! $this->hijack || ( $this->object_id != $object_id && 1987645321 !== $object_id ) ) {
return $check;
}
if ( $this->ajax_update ) {
return false;
}
return $this->cache_action( $meta_key );
}
/**
* Hijacks saving of cached oEmbed.
* Saves cached data to relevant object metadata (vs postmeta)
*
* @since 0.9.5
* @param boolean $check Whether to continue setting postmeta.
* @param int $object_id Object ID to get postmeta from.
* @param string $meta_key Postmeta's key.
* @param mixed $meta_value Value of the postmeta to be saved.
* @return boolean Whether to continue setting.
*/
public function hijack_oembed_cache_set( $check, $object_id, $meta_key, $meta_value ) {
if (
! $this->hijack
|| ( $this->object_id != $object_id && 1987645321 !== $object_id )
// Only want to hijack oembed meta values.
|| 0 !== strpos( $meta_key, '_oembed_' )
) {
return $check;
}
$this->cache_action( $meta_key, $meta_value );
// Anything other than `null` to cancel saving to postmeta.
return true;
}
/**
* Gets/updates the cached oEmbed value from/to relevant object metadata (vs postmeta).
*
* @since 1.3.0
*
* @param string $meta_key Postmeta's key.
* @return mixed
*/
protected function cache_action( $meta_key ) {
$func_args = func_get_args();
$action = isset( $func_args[1] ) ? 'update' : 'get';
if ( 'options-page' === $this->object_type ) {
$args = array( $meta_key );
if ( 'update' === $action ) {
$args[] = $func_args[1];
$args[] = true;
}
// Cache the result to our options.
$status = call_user_func_array( array( cmb2_options( $this->object_id ), $action ), $args );
} else {
$args = array( $this->object_type, $this->object_id, $meta_key );
$args[] = 'update' === $action ? $func_args[1] : true;
// Cache the result to our metadata.
$status = call_user_func_array( $action . '_metadata', $args );
}
return $status;
}
/**
* Hooks in when options-page data is saved to clean stale
* oembed cache data from the option value.
*
* @since 2.2.0
* @param string $option_key The options-page option key.
* @return void
*/
public static function clean_stale_options_page_oembeds( $option_key ) {
$options = cmb2_options( $option_key )->get_options();
$modified = false;
if ( is_array( $options ) ) {
$ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, '', array(), 0 );
$now = time();
foreach ( $options as $key => $value ) {
// Check for cached oembed data.
if ( 0 === strpos( $key, '_oembed_time_' ) ) {
$cached_recently = ( $now - $value ) < $ttl;
if ( ! $cached_recently ) {
$modified = true;
// Remove the the cached ttl expiration, and the cached oembed value.
unset( $options[ $key ] );
unset( $options[ str_replace( '_oembed_time_', '_oembed_', $key ) ] );
}
} // End if.
// Remove the cached unknown values.
elseif ( '{{unknown}}' === $value ) {
$modified = true;
unset( $options[ $key ] );
}
}
}
// Update the option and remove stale cache data.
if ( $modified ) {
$updated = cmb2_options( $option_key )->set( $options );
}
}
}

View File

@@ -0,0 +1,534 @@
<?php
/**
* CMB2 Base - Base object functionality.
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*
* @property-read $args The objects array of properties/arguments.
* @property-read $meta_box The objects array of properties/arguments.
* @property-read $properties The objects array of properties/arguments.
* @property-read $cmb_id Current CMB2 instance ID
* @property-read $object_id Object ID
* @property-read $object_type Type of object being handled. (e.g., post, user, comment, or term)
*/
abstract class CMB2_Base {
/**
* Current CMB2 instance ID
*
* @var string
* @since 2.2.3
*/
protected $cmb_id = '';
/**
* The object properties name.
*
* @var string
* @since 2.2.3
*/
protected $properties_name = 'meta_box';
/**
* Object ID
*
* @var mixed
* @since 2.2.3
*/
protected $object_id = 0;
/**
* Type of object being handled. (e.g., post, user, comment, or term)
*
* @var string
* @since 2.2.3
*/
protected $object_type = '';
/**
* Array of key => value data for saving. Likely $_POST data.
*
* @var array
* @since 2.2.3
*/
public $data_to_save = array();
/**
* Array of field param callback results
*
* @var array
* @since 2.0.0
*/
protected $callback_results = array();
/**
* The deprecated_param method deprecated param message signature.
*/
const DEPRECATED_PARAM = 1;
/**
* The deprecated_param method deprecated callback param message signature.
*/
const DEPRECATED_CB_PARAM = 2;
/**
* Get started
*
* @since 2.2.3
* @param array $args Object properties array.
*/
public function __construct( $args = array() ) {
if ( ! empty( $args ) ) {
foreach ( array(
'cmb_id',
'properties_name',
'object_id',
'object_type',
'data_to_save',
) as $object_prop ) {
if ( isset( $args[ $object_prop ] ) ) {
$this->{$object_prop} = $args[ $object_prop ];
}
}
}
}
/**
* Returns the object ID
*
* @since 2.2.3
* @param integer $object_id Object ID.
* @return integer Object ID
*/
public function object_id( $object_id = 0 ) {
if ( $object_id ) {
$this->object_id = $object_id;
}
return $this->object_id;
}
/**
* Returns the object type
*
* @since 2.2.3
* @param string $object_type Object Type.
* @return string Object type
*/
public function object_type( $object_type = '' ) {
if ( $object_type ) {
$this->object_type = $object_type;
}
return $this->object_type;
}
/**
* Get the object type for the current page, based on the $pagenow global.
*
* @since 2.2.2
* @return string Page object type name.
*/
public function current_object_type() {
global $pagenow;
$type = 'post';
if ( in_array( $pagenow, array( 'user-edit.php', 'profile.php', 'user-new.php' ), true ) ) {
$type = 'user';
}
if ( in_array( $pagenow, array( 'edit-comments.php', 'comment.php' ), true ) ) {
$type = 'comment';
}
if ( in_array( $pagenow, array( 'edit-tags.php', 'term.php' ), true ) ) {
$type = 'term';
}
return $type;
}
/**
* Set object property.
*
* @since 2.2.2
* @param string $property Metabox config property to retrieve.
* @param mixed $value Value to set if no value found.
* @return mixed Metabox config property value or false.
*/
public function set_prop( $property, $value ) {
$this->{$this->properties_name}[ $property ] = $value;
return $this->prop( $property );
}
/**
* Get object property and optionally set a fallback
*
* @since 2.0.0
* @param string $property Metabox config property to retrieve.
* @param mixed $fallback Fallback value to set if no value found.
* @return mixed Metabox config property value or false
*/
public function prop( $property, $fallback = null ) {
if ( array_key_exists( $property, $this->{$this->properties_name} ) ) {
return $this->{$this->properties_name}[ $property ];
} elseif ( $fallback ) {
return $this->{$this->properties_name}[ $property ] = $fallback;
}
}
/**
* Get default field arguments specific to this CMB2 object.
*
* @since 2.2.0
* @param array $field_args Metabox field config array.
* @param CMB2_Field $field_group (optional) CMB2_Field object (group parent).
* @return array Array of field arguments.
*/
protected function get_default_args( $field_args, $field_group = null ) {
if ( $field_group ) {
$args = array(
'field_args' => $field_args,
'group_field' => $field_group,
);
} else {
$args = array(
'field_args' => $field_args,
'object_type' => $this->object_type(),
'object_id' => $this->object_id(),
'cmb_id' => $this->cmb_id,
);
}
return $args;
}
/**
* Get a new field object specific to this CMB2 object.
*
* @since 2.2.0
* @param array $field_args Metabox field config array.
* @param CMB2_Field $field_group (optional) CMB2_Field object (group parent).
* @return CMB2_Field CMB2_Field object
*/
protected function get_new_field( $field_args, $field_group = null ) {
return new CMB2_Field( $this->get_default_args( $field_args, $field_group ) );
}
/**
* Determine whether this cmb object should show, based on the 'show_on_cb' callback.
*
* @since 2.0.9
*
* @return bool Whether this cmb should be shown.
*/
public function should_show() {
// Default to showing this cmb
$show = true;
// Use the callback to determine showing the cmb, if it exists.
if ( is_callable( $this->prop( 'show_on_cb' ) ) ) {
$show = (bool) call_user_func( $this->prop( 'show_on_cb' ), $this );
}
return $show;
}
/**
* Displays the results of the param callbacks.
*
* @since 2.0.0
* @param string $param Field parameter.
*/
public function peform_param_callback( $param ) {
echo $this->get_param_callback_result( $param );
}
/**
* Store results of the param callbacks for continual access
*
* @since 2.0.0
* @param string $param Field parameter.
* @return mixed Results of param/param callback
*/
public function get_param_callback_result( $param ) {
// If we've already retrieved this param's value.
if ( array_key_exists( $param, $this->callback_results ) ) {
// Send it back.
return $this->callback_results[ $param ];
}
// Check if parameter has registered a callback.
if ( $cb = $this->maybe_callback( $param ) ) {
// Ok, callback is good, let's run it and store the result.
ob_start();
$returned = $this->do_callback( $cb );
// Grab the result from the output buffer and store it.
$echoed = ob_get_clean();
// This checks if the user returned or echoed their callback.
// Defaults to using the echoed value.
$this->callback_results[ $param ] = $echoed ? $echoed : $returned;
} else {
// Otherwise just get whatever is there.
$this->callback_results[ $param ] = isset( $this->{$this->properties_name}[ $param ] ) ? $this->{$this->properties_name}[ $param ] : false;
}
return $this->callback_results[ $param ];
}
/**
* Unset the cached results of the param callback.
*
* @since 2.2.6
* @param string $param Field parameter.
* @return CMB2_Base
*/
public function unset_param_callback_cache( $param ) {
if ( isset( $this->callback_results[ $param ] ) ) {
unset( $this->callback_results[ $param ] );
}
return $this;
}
/**
* Handles the parameter callbacks, and passes this object as parameter.
*
* @since 2.2.3
* @param callable $cb The callback method/function/closure.
* @param mixed $additional_params Any additoinal parameters which should be passed to the callback.
* @return mixed Return of the callback function.
*/
protected function do_callback( $cb, $additional_params = null ) {
return call_user_func( $cb, $this->{$this->properties_name}, $this, $additional_params );
}
/**
* Checks if field has a callback value
*
* @since 1.0.1
* @param string $cb Callback string.
* @return mixed NULL, false for NO validation, or $cb string if it exists.
*/
public function maybe_callback( $cb ) {
$args = $this->{$this->properties_name};
if ( ! isset( $args[ $cb ] ) ) {
return null;
}
// Check if requesting explicitly false.
$cb = false !== $args[ $cb ] && 'false' !== $args[ $cb ] ? $args[ $cb ] : false;
// If requesting NO validation, return false.
if ( ! $cb ) {
return false;
}
if ( is_callable( $cb ) ) {
return $cb;
}
return null;
}
/**
* Checks if this object has parameter corresponding to the given filter
* which is callable. If so, it registers the callback, and if not,
* converts the maybe-modified $val to a boolean for return.
*
* The registered handlers will have a parameter name which matches the filter, except:
* - The 'cmb2_api' prefix will be removed
* - A '_cb' suffix will be added (to stay inline with other '*_cb' parameters).
*
* @since 2.2.3
*
* @param string $hook_name The hook name.
* @param bool $val The default value.
* @param string $hook_function The hook function. Default: 'add_filter'.
*
* @return null|bool Null if hook is registered, or bool for value.
*/
public function maybe_hook_parameter( $hook_name, $val = null, $hook_function = 'add_filter' ) {
// Remove filter prefix, add param suffix.
$parameter = substr( $hook_name, strlen( 'cmb2_api_' ) ) . '_cb';
return self::maybe_hook(
$this->prop( $parameter, $val ),
$hook_name,
$hook_function
);
}
/**
* Checks if given value is callable, and registers the callback.
* If is non-callable, converts the $val to a boolean for return.
*
* @since 2.2.3
*
* @param bool $val The default value.
* @param string $hook_name The hook name.
* @param string $hook_function The hook function.
*
* @return null|bool Null if hook is registered, or bool for value.
*/
public static function maybe_hook( $val, $hook_name, $hook_function ) {
if ( is_callable( $val ) ) {
call_user_func( $hook_function, $hook_name, $val, 10, 2 );
return null;
}
// Cast to bool.
return ! ! $val;
}
/**
* Mark a param as deprecated and inform when it has been used.
*
* There is a default WordPress hook deprecated_argument_run that will be called
* that can be used to get the backtrace up to what file and function used the
* deprecated argument.
*
* The current behavior is to trigger a user error if WP_DEBUG is true.
*
* @since 2.2.3
*
* @param string $function The function that was called.
* @param string $version The version of CMB2 that deprecated the argument used.
* @param string $message Optional. A message regarding the change, or numeric
* key to generate message from additional arguments.
* Default null.
*/
protected function deprecated_param( $function, $version, $message = null ) {
$args = func_get_args();
if ( is_numeric( $message ) ) {
switch ( $message ) {
case self::DEPRECATED_PARAM:
$message = sprintf( __( 'The "%1$s" field parameter has been deprecated in favor of the "%2$s" parameter.', 'cmb2' ), $args[3], $args[4] );
break;
case self::DEPRECATED_CB_PARAM:
$message = sprintf( __( 'Using the "%1$s" field parameter as a callback has been deprecated in favor of the "%2$s" parameter.', 'cmb2' ), $args[3], $args[4] );
break;
default:
$message = null;
break;
}
}
/**
* Fires when a deprecated argument is called. This is a WP core action.
*
* @since 2.2.3
*
* @param string $function The function that was called.
* @param string $message A message regarding the change.
* @param string $version The version of CMB2 that deprecated the argument used.
*/
do_action( 'deprecated_argument_run', $function, $message, $version );
/**
* Filters whether to trigger an error for deprecated arguments. This is a WP core filter.
*
* @since 2.2.3
*
* @param bool $trigger Whether to trigger the error for deprecated arguments. Default true.
*/
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
if ( ! is_null( $message ) ) {
trigger_error( sprintf( __( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s! %3$s', 'cmb2' ), $function, $version, $message ) );
} else {
trigger_error( sprintf( __( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s with no alternative available.', 'cmb2' ), $function, $version ) );
}
} else {
if ( ! is_null( $message ) ) {
trigger_error( sprintf( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
} else {
trigger_error( sprintf( '%1$s was called with a parameter that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
}
}
}
}
/**
* Magic getter for our object.
*
* @param string $field Requested property.
* @throws Exception Throws an exception if the field is invalid.
* @return mixed
*/
public function __get( $field ) {
switch ( $field ) {
case 'args':
case 'meta_box':
if ( $field === $this->properties_name ) {
return $this->{$this->properties_name};
}
case 'properties':
return $this->{$this->properties_name};
case 'cmb_id':
case 'object_id':
case 'object_type':
return $this->{$field};
default:
throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) );
}
}
/**
* Allows overloading the object with methods... Whooaaa oooh it's magic, y'knoooow.
*
* @since 1.0.0
* @throws Exception Invalid method exception.
*
* @param string $method Non-existent method.
* @param array $args All arguments passed to the method.
* @return mixed
*/
public function __call( $method, $args ) {
$object_class = strtolower( get_class( $this ) );
if ( ! has_filter( "{$object_class}_inherit_{$method}" ) ) {
throw new Exception( sprintf( esc_html__( 'Invalid %1$s method: %2$s', 'cmb2' ), get_class( $this ), $method ) );
}
array_unshift( $args, $this );
/**
* Allows overloading the object (CMB2 or CMB2_Field) with additional capabilities
* by registering hook callbacks.
*
* The first dynamic portion of the hook name, $object_class, refers to the object class,
* either cmb2 or cmb2_field.
*
* The second dynamic portion of the hook name, $method, is the non-existent method being
* called on the object. To avoid possible future methods encroaching on your hooks,
* use a unique method (aka, $cmb->prefix_my_method()).
*
* When registering your callback, you will need to ensure that you register the correct
* number of `$accepted_args`, accounting for this object instance being the first argument.
*
* @param array $args The arguments to be passed to the hook.
* The first argument will always be this object instance.
*/
return apply_filters_ref_array( "{$object_class}_inherit_{$method}", $args );
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* A CMB2 object instance registry for storing every CMB2 instance.
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Boxes {
/**
* Array of all metabox objects.
*
* @since 2.0.0
* @var array
*/
protected static $cmb2_instances = array();
/**
* Add a CMB2 instance object to the registry.
*
* @since 1.X.X
*
* @param CMB2 $cmb_instance CMB2 instance.
*/
public static function add( CMB2 $cmb_instance ) {
self::$cmb2_instances[ $cmb_instance->cmb_id ] = $cmb_instance;
}
/**
* Remove a CMB2 instance object from the registry.
*
* @since 1.X.X
*
* @param string $cmb_id A CMB2 instance id.
*/
public static function remove( $cmb_id ) {
if ( array_key_exists( $cmb_id, self::$cmb2_instances ) ) {
unset( self::$cmb2_instances[ $cmb_id ] );
}
}
/**
* Retrieve a CMB2 instance by cmb id.
*
* @since 1.X.X
*
* @param string $cmb_id A CMB2 instance id.
*
* @return CMB2|bool False or CMB2 object instance.
*/
public static function get( $cmb_id ) {
if ( empty( self::$cmb2_instances ) || empty( self::$cmb2_instances[ $cmb_id ] ) ) {
return false;
}
return self::$cmb2_instances[ $cmb_id ];
}
/**
* Retrieve all CMB2 instances registered.
*
* @since 1.X.X
* @return CMB2[] Array of all registered cmb2 instances.
*/
public static function get_all() {
return self::$cmb2_instances;
}
/**
* Retrieve all CMB2 instances that have the specified property set.
*
* @since 2.4.0
* @param string $property Property name.
* @param mixed $compare (Optional) The value to compare.
* @return CMB2[] Array of matching cmb2 instances.
*/
public static function get_by( $property, $compare = 'nocompare' ) {
$boxes = array();
foreach ( self::$cmb2_instances as $cmb_id => $cmb ) {
$prop = $cmb->prop( $property );
if ( 'nocompare' === $compare ) {
if ( ! empty( $prop ) ) {
$boxes[ $cmb_id ] = $cmb;
}
continue;
}
if ( $compare === $prop ) {
$boxes[ $cmb_id ] = $cmb;
}
}
return $boxes;
}
/**
* Retrieve all CMB2 instances as long as they do not include the ignored property.
*
* @since 2.4.0
* @param string $property Property name.
* @param mixed $to_ignore The value to ignore.
* @return CMB2[] Array of matching cmb2 instances.
*/
public static function filter_by( $property, $to_ignore = null ) {
$boxes = array();
foreach ( self::$cmb2_instances as $cmb_id => $cmb ) {
if ( $to_ignore === $cmb->prop( $property ) ) {
continue;
}
$boxes[ $cmb_id ] = $cmb;
}
return $boxes;
}
/**
* Deprecated and left for back-compatibility. The original `get_by_property`
* method was misnamed and never actually used by CMB2 core.
*
* @since 2.2.3
*
* @param string $property Property name.
* @param mixed $to_ignore The value to ignore.
* @return CMB2[] Array of matching cmb2 instances.
*/
public static function get_by_property( $property, $to_ignore = null ) {
_deprecated_function( __METHOD__, '2.4.0', 'CMB2_Boxes::filter_by()' );
return self::filter_by( $property );
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,505 @@
<?php
/**
* CMB2 field display base.
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Field_Display {
/**
* A CMB field object
*
* @var CMB2_Field object
* @since 2.2.2
*/
public $field;
/**
* The CMB field object's value.
*
* @var mixed
* @since 2.2.2
*/
public $value;
/**
* Get the corresponding display class for the field type.
*
* @since 2.2.2
* @param CMB2_Field $field Requested field type.
* @return CMB2_Field_Display
*/
public static function get( CMB2_Field $field ) {
$fieldtype = $field->type();
$display_class_name = $field->args( 'display_class' );
if ( empty( $display_class_name ) ) {
switch ( $fieldtype ) {
case 'text_url':
$display_class_name = 'CMB2_Display_Text_Url';
break;
case 'text_money':
$display_class_name = 'CMB2_Display_Text_Money';
break;
case 'colorpicker':
$display_class_name = 'CMB2_Display_Colorpicker';
break;
case 'checkbox':
$display_class_name = 'CMB2_Display_Checkbox';
break;
case 'wysiwyg':
case 'textarea_small':
$display_class_name = 'CMB2_Display_Textarea';
break;
case 'textarea_code':
$display_class_name = 'CMB2_Display_Textarea_Code';
break;
case 'text_time':
$display_class_name = 'CMB2_Display_Text_Time';
break;
case 'text_date':
case 'text_date_timestamp':
case 'text_datetime_timestamp':
$display_class_name = 'CMB2_Display_Text_Date';
break;
case 'text_datetime_timestamp_timezone':
$display_class_name = 'CMB2_Display_Text_Date_Timezone';
break;
case 'select':
case 'radio':
case 'radio_inline':
$display_class_name = 'CMB2_Display_Select';
break;
case 'multicheck':
case 'multicheck_inline':
$display_class_name = 'CMB2_Display_Multicheck';
break;
case 'taxonomy_radio':
case 'taxonomy_radio_inline':
case 'taxonomy_select':
case 'taxonomy_select_hierarchical':
case 'taxonomy_radio_hierarchical':
$display_class_name = 'CMB2_Display_Taxonomy_Radio';
break;
case 'taxonomy_multicheck':
case 'taxonomy_multicheck_inline':
case 'taxonomy_multicheck_hierarchical':
$display_class_name = 'CMB2_Display_Taxonomy_Multicheck';
break;
case 'file':
$display_class_name = 'CMB2_Display_File';
break;
case 'file_list':
$display_class_name = 'CMB2_Display_File_List';
break;
case 'oembed':
$display_class_name = 'CMB2_Display_oEmbed';
break;
default:
$display_class_name = __CLASS__;
break;
}// End switch.
}
if ( has_action( "cmb2_display_class_{$fieldtype}" ) ) {
/**
* Filters the custom field display class used for displaying the field. Class is required to extend CMB2_Type_Base.
*
* The dynamic portion of the hook name, $fieldtype, refers to the (custom) field type.
*
* @since 2.2.4
*
* @param string $display_class_name The custom field display class to use.
* @param object $field The `CMB2_Field` object.
*/
$display_class_name = apply_filters( "cmb2_display_class_{$fieldtype}", $display_class_name, $field );
}
return new $display_class_name( $field );
}
/**
* Setup our class vars
*
* @since 2.2.2
* @param CMB2_Field $field A CMB2 field object.
*/
public function __construct( CMB2_Field $field ) {
$this->field = $field;
$this->value = $this->field->value;
}
/**
* Catchall method if field's 'display_cb' is NOT defined, or field type does
* not have a corresponding display method
*
* @since 2.2.2
*/
public function display() {
// If repeatable.
if ( $this->field->args( 'repeatable' ) ) {
// And has a repeatable value.
if ( is_array( $this->field->value ) ) {
// Then loop and output.
echo '<ul class="cmb2-' . esc_attr( sanitize_html_class( str_replace( '_', '-', $this->field->type() ) ) ) . '">';
foreach ( $this->field->value as $val ) {
$this->value = $val;
echo '<li>', $this->_display(), '</li>';
;
}
echo '</ul>';
}
} else {
$this->_display();
}
}
/**
* Default fallback display method.
*
* @since 2.2.2
*/
protected function _display() {
print_r( $this->value );
}
}
class CMB2_Display_Text_Url extends CMB2_Field_Display {
/**
* Display url value.
*
* @since 2.2.2
*/
protected function _display() {
echo make_clickable( esc_url( $this->value ) );
}
}
class CMB2_Display_Text_Money extends CMB2_Field_Display {
/**
* Display text_money value.
*
* @since 2.2.2
*/
protected function _display() {
$this->value = $this->value ? $this->value : '0';
echo ( ! $this->field->get_param_callback_result( 'before_field' ) ? '$' : ' ' ), $this->value;
}
}
class CMB2_Display_Colorpicker extends CMB2_Field_Display {
/**
* Display color picker value.
*
* @since 2.2.2
*/
protected function _display() {
echo '<span class="cmb2-colorpicker-swatch"><span style="background-color:', esc_attr( $this->value ), '"></span> ', esc_html( $this->value ), '</span>';
}
}
class CMB2_Display_Checkbox extends CMB2_Field_Display {
/**
* Display multicheck value.
*
* @since 2.2.2
*/
protected function _display() {
echo $this->value === 'on' ? 'on' : 'off';
}
}
class CMB2_Display_Select extends CMB2_Field_Display {
/**
* Display select value.
*
* @since 2.2.2
*/
protected function _display() {
$options = $this->field->options();
$fallback = $this->field->args( 'show_option_none' );
if ( ! $fallback && isset( $options[''] ) ) {
$fallback = $options[''];
}
if ( ! $this->value && $fallback ) {
echo $fallback;
} elseif ( isset( $options[ $this->value ] ) ) {
echo $options[ $this->value ];
} else {
echo esc_attr( $this->value );
}
}
}
class CMB2_Display_Multicheck extends CMB2_Field_Display {
/**
* Display multicheck value.
*
* @since 2.2.2
*/
protected function _display() {
if ( empty( $this->value ) || ! is_array( $this->value ) ) {
return;
}
$options = $this->field->options();
$output = array();
foreach ( $this->value as $val ) {
if ( isset( $options[ $val ] ) ) {
$output[] = $options[ $val ];
} else {
$output[] = esc_attr( $val );
}
}
echo implode( ', ', $output );
}
}
class CMB2_Display_Textarea extends CMB2_Field_Display {
/**
* Display textarea value.
*
* @since 2.2.2
*/
protected function _display() {
echo wpautop( wp_kses_post( $this->value ) );
}
}
class CMB2_Display_Textarea_Code extends CMB2_Field_Display {
/**
* Display textarea_code value.
*
* @since 2.2.2
*/
protected function _display() {
echo '<xmp class="cmb2-code">' . print_r( $this->value, true ) . '</xmp>';
}
}
class CMB2_Display_Text_Time extends CMB2_Field_Display {
/**
* Display text_time value.
*
* @since 2.2.2
*/
protected function _display() {
echo $this->field->get_timestamp_format( 'time_format', $this->value );
}
}
class CMB2_Display_Text_Date extends CMB2_Field_Display {
/**
* Display text_date value.
*
* @since 2.2.2
*/
protected function _display() {
echo $this->field->get_timestamp_format( 'date_format', $this->value );
}
}
class CMB2_Display_Text_Date_Timezone extends CMB2_Field_Display {
/**
* Display text_datetime_timestamp_timezone value.
*
* @since 2.2.2
*/
protected function _display() {
$field = $this->field;
if ( empty( $this->value ) ) {
return;
}
$datetime = maybe_unserialize( $this->value );
$this->value = $tzstring = '';
if ( $datetime && $datetime instanceof DateTime ) {
$tz = $datetime->getTimezone();
$tzstring = $tz->getName();
$this->value = $datetime->getTimestamp();
}
$date = $this->field->get_timestamp_format( 'date_format', $this->value );
$time = $this->field->get_timestamp_format( 'time_format', $this->value );
echo $date, ( $time ? ' ' . $time : '' ), ( $tzstring ? ', ' . $tzstring : '' );
}
}
class CMB2_Display_Taxonomy_Radio extends CMB2_Field_Display {
/**
* Display single taxonomy value.
*
* @since 2.2.2
*/
protected function _display() {
$taxonomy = $this->field->args( 'taxonomy' );
$types = new CMB2_Types( $this->field );
$type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_Taxonomy_Radio' );
$terms = $type->get_object_terms();
$term = false;
if ( is_wp_error( $terms ) || empty( $terms ) && ( $default = $this->field->get_default() ) ) {
$term = get_term_by( 'slug', $default, $taxonomy );
} elseif ( ! empty( $terms ) ) {
$term = $terms[ key( $terms ) ];
}
if ( $term ) {
$link = get_edit_term_link( $term->term_id, $taxonomy );
echo '<a href="', esc_url( $link ), '">', esc_html( $term->name ), '</a>';
}
}
}
class CMB2_Display_Taxonomy_Multicheck extends CMB2_Field_Display {
/**
* Display taxonomy values.
*
* @since 2.2.2
*/
protected function _display() {
$taxonomy = $this->field->args( 'taxonomy' );
$types = new CMB2_Types( $this->field );
$type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_Taxonomy_Multicheck' );
$terms = $type->get_object_terms();
if ( is_wp_error( $terms ) || empty( $terms ) && ( $default = $this->field->get_default() ) ) {
$terms = array();
if ( is_array( $default ) ) {
foreach ( $default as $slug ) {
$terms[] = get_term_by( 'slug', $slug, $taxonomy );
}
} else {
$terms[] = get_term_by( 'slug', $default, $taxonomy );
}
}
if ( is_array( $terms ) ) {
$links = array();
foreach ( $terms as $term ) {
$link = get_edit_term_link( $term->term_id, $taxonomy );
$links[] = '<a href="' . esc_url( $link ) . '">' . esc_html( $term->name ) . '</a>';
}
// Then loop and output.
echo '<div class="cmb2-taxonomy-terms-', esc_attr( sanitize_html_class( $taxonomy ) ), '">';
echo implode( ', ', $links );
echo '</div>';
}
}
}
class CMB2_Display_File extends CMB2_Field_Display {
/**
* Display file value.
*
* @since 2.2.2
*/
protected function _display() {
if ( empty( $this->value ) ) {
return;
}
$this->value = esc_url_raw( $this->value );
$types = new CMB2_Types( $this->field );
$type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_File_Base' );
$id = $this->field->get_field_clone( array(
'id' => $this->field->_id( '', false ) . '_id',
) )->escaped_value( 'absint' );
$this->file_output( $this->value, $id, $type );
}
protected function file_output( $url_value, $id, CMB2_Type_File_Base $field_type ) {
// If there is no ID saved yet, try to get it from the url.
if ( $url_value && ! $id ) {
$id = CMB2_Utils::image_id_from_url( esc_url_raw( $url_value ) );
}
if ( $field_type->is_valid_img_ext( $url_value ) ) {
$img_size = $this->field->args( 'preview_size' );
if ( $id ) {
$image = wp_get_attachment_image( $id, $img_size, null, array(
'class' => 'cmb-image-display',
) );
} else {
$size = is_array( $img_size ) ? $img_size[0] : 200;
$image = '<img class="cmb-image-display" style="max-width: ' . absint( $size ) . 'px; width: 100%; height: auto;" src="' . esc_url( $url_value ) . '" alt="" />';
}
echo $image;
} else {
printf( '<div class="file-status"><span>%1$s <strong><a href="%2$s">%3$s</a></strong></span></div>',
esc_html( $field_type->_text( 'file_text', __( 'File:', 'cmb2' ) ) ),
esc_url( $url_value ),
esc_html( CMB2_Utils::get_file_name_from_path( $url_value ) )
);
}
}
}
class CMB2_Display_File_List extends CMB2_Display_File {
/**
* Display file_list value.
*
* @since 2.2.2
*/
protected function _display() {
if ( empty( $this->value ) || ! is_array( $this->value ) ) {
return;
}
$types = new CMB2_Types( $this->field );
$type = $types->get_new_render_type( $this->field->type(), 'CMB2_Type_File_Base' );
echo '<ul class="cmb2-display-file-list">';
foreach ( $this->value as $id => $fullurl ) {
echo '<li>', $this->file_output( esc_url_raw( $fullurl ), $id, $type ), '</li>';
}
echo '</ul>';
}
}
class CMB2_Display_oEmbed extends CMB2_Field_Display {
/**
* Display oembed value.
*
* @since 2.2.2
*/
protected function _display() {
if ( ! $this->value ) {
return;
}
cmb2_do_oembed( array(
'url' => $this->value,
'object_id' => $this->field->object_id,
'object_type' => $this->field->object_type,
'oembed_args' => array(
'width' => '300',
),
'field_id' => $this->field->id(),
) );
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,105 @@
<?php
/**
* Base class for hooking CMB2 into WordPress.
*
* @since 2.2.0
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*
* @property-read string $object_type
* @property-read CMB2 $cmb
*/
abstract class CMB2_Hookup_Base {
/**
* CMB2 object.
*
* @var CMB2 object
* @since 2.0.2
*/
protected $cmb;
/**
* The object type we are performing the hookup for
*
* @var string
* @since 2.0.9
*/
protected $object_type = 'post';
/**
* A functionalized constructor, used for the hookup action callbacks.
*
* @since 2.2.6
*
* @throws Exception Failed implementation.
*
* @param CMB2 $cmb The CMB2 object to hookup.
*/
public static function maybe_init_and_hookup( CMB2 $cmb ) {
throw new Exception( sprintf( esc_html__( '%1$s should be implemented by the extended class.', 'cmb2' ), __FUNCTION__ ) );
}
/**
* Constructor
*
* @since 2.0.0
* @param CMB2 $cmb The CMB2 object to hookup.
*/
public function __construct( CMB2 $cmb ) {
$this->cmb = $cmb;
$this->object_type = $this->cmb->mb_object_type();
}
abstract public function universal_hooks();
/**
* Ensures WordPress hook only gets fired once per object.
*
* @since 2.0.0
* @param string $action The name of the filter to hook the $hook callback to.
* @param callback $hook The callback to be run when the filter is applied.
* @param integer $priority Order the functions are executed.
* @param int $accepted_args The number of arguments the function accepts.
*/
public function once( $action, $hook, $priority = 10, $accepted_args = 1 ) {
static $hooks_completed = array();
$args = func_get_args();
// Get object hash.. This bypasses issues with serializing closures.
if ( is_object( $hook ) ) {
$args[1] = spl_object_hash( $args[1] );
} elseif ( is_array( $hook ) && is_object( $hook[0] ) ) {
$args[1][0] = spl_object_hash( $hook[0] );
}
$key = md5( serialize( $args ) );
if ( ! isset( $hooks_completed[ $key ] ) ) {
$hooks_completed[ $key ] = 1;
add_filter( $action, $hook, $priority, $accepted_args );
}
}
/**
* Magic getter for our object.
*
* @param string $field Property to return.
* @throws Exception Throws an exception if the field is invalid.
* @return mixed
*/
public function __get( $field ) {
switch ( $field ) {
case 'object_type':
case 'cmb':
return $this->{$field};
default:
throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) );
}
}
}

View File

@@ -0,0 +1,257 @@
<?php
/**
* Handles the dependencies and enqueueing of the CMB2 JS scripts
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_JS {
/**
* The CMB2 JS handle
*
* @var string
* @since 2.0.7
*/
protected static $handle = 'cmb2-scripts';
/**
* The CMB2 JS variable name
*
* @var string
* @since 2.0.7
*/
protected static $js_variable = 'cmb2_l10';
/**
* Array of CMB2 JS dependencies
*
* @var array
* @since 2.0.7
*/
protected static $dependencies = array(
'jquery' => 'jquery',
);
/**
* Array of CMB2 fields model data for JS.
*
* @var array
* @since 2.4.0
*/
protected static $fields = array();
/**
* Add a dependency to the array of CMB2 JS dependencies
*
* @since 2.0.7
* @param array|string $dependencies Array (or string) of dependencies to add.
*/
public static function add_dependencies( $dependencies ) {
foreach ( (array) $dependencies as $dependency ) {
self::$dependencies[ $dependency ] = $dependency;
}
}
/**
* Add field model data to the array for JS.
*
* @since 2.4.0
*
* @param CMB2_Field $field Field object.
*/
public static function add_field_data( CMB2_Field $field ) {
$hash = $field->hash_id();
if ( ! isset( self::$fields[ $hash ] ) ) {
self::$fields[ $hash ] = $field->js_data();
}
}
/**
* Enqueue the CMB2 JS
*
* @since 2.0.7
*/
public static function enqueue() {
// Filter required script dependencies.
$dependencies = self::$dependencies = apply_filters( 'cmb2_script_dependencies', self::$dependencies );
// Only use minified files if SCRIPT_DEBUG is off.
$debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
$min = $debug ? '' : '.min';
// if colorpicker.
if ( isset( $dependencies['wp-color-picker'] ) ) {
if ( ! is_admin() ) {
self::colorpicker_frontend();
}
// Enqueue colorpicker
if ( ! wp_script_is( 'wp-color-picker', 'enqueued' ) ) {
wp_enqueue_script( 'wp-color-picker' );
}
if ( isset( $dependencies['wp-color-picker-alpha'] ) ) {
self::register_colorpicker_alpha();
}
}
// if file/file_list.
if ( isset( $dependencies['media-editor'] ) ) {
wp_enqueue_media();
CMB2_Type_File_Base::output_js_underscore_templates();
}
// if timepicker.
if ( isset( $dependencies['jquery-ui-datetimepicker'] ) ) {
self::register_datetimepicker();
}
// if cmb2-wysiwyg.
$enqueue_wysiwyg = isset( $dependencies['cmb2-wysiwyg'] ) && $debug;
unset( $dependencies['cmb2-wysiwyg'] );
// if cmb2-char-counter.
$enqueue_char_counter = isset( $dependencies['cmb2-char-counter'] ) && $debug;
unset( $dependencies['cmb2-char-counter'] );
// Enqueue cmb JS.
wp_enqueue_script( self::$handle, CMB2_Utils::url( "js/cmb2{$min}.js" ), array_values( $dependencies ), CMB2_VERSION, true );
// if SCRIPT_DEBUG, we need to enqueue separately.
if ( $enqueue_wysiwyg ) {
wp_enqueue_script( 'cmb2-wysiwyg', CMB2_Utils::url( 'js/cmb2-wysiwyg.js' ), array( 'jquery', 'wp-util' ), CMB2_VERSION );
}
if ( $enqueue_char_counter ) {
wp_enqueue_script( 'cmb2-char-counter', CMB2_Utils::url( 'js/cmb2-char-counter.js' ), array( 'jquery', 'wp-util' ), CMB2_VERSION );
}
self::localize( $debug );
do_action( 'cmb2_footer_enqueue' );
}
/**
* Register or enqueue the wp-color-picker-alpha script.
*
* @since 2.2.7
*
* @param boolean $enqueue Whether or not to enqueue.
*
* @return void
*/
public static function register_colorpicker_alpha( $enqueue = false ) {
// Only use minified files if SCRIPT_DEBUG is off.
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$func = $enqueue ? 'wp_enqueue_script' : 'wp_register_script';
$func( 'wp-color-picker-alpha', CMB2_Utils::url( "js/wp-color-picker-alpha{$min}.js" ), array( 'wp-color-picker' ), '2.1.3' );
}
/**
* Register or enqueue the jquery-ui-datetimepicker script.
*
* @since 2.2.7
*
* @param boolean $enqueue Whether or not to enqueue.
*
* @return void
*/
public static function register_datetimepicker( $enqueue = false ) {
$func = $enqueue ? 'wp_enqueue_script' : 'wp_register_script';
$func( 'jquery-ui-datetimepicker', CMB2_Utils::url( 'js/jquery-ui-timepicker-addon.min.js' ), array( 'jquery-ui-slider' ), '1.5.0' );
}
/**
* We need to register colorpicker on the front-end
*
* @since 2.0.7
*/
protected static function colorpicker_frontend() {
wp_register_script( 'iris', admin_url( 'js/iris.min.js' ), array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), CMB2_VERSION );
wp_register_script( 'wp-color-picker', admin_url( 'js/color-picker.min.js' ), array( 'iris' ), CMB2_VERSION );
wp_localize_script( 'wp-color-picker', 'wpColorPickerL10n', array(
'clear' => esc_html__( 'Clear', 'cmb2' ),
'defaultString' => esc_html__( 'Default', 'cmb2' ),
'pick' => esc_html__( 'Select Color', 'cmb2' ),
'current' => esc_html__( 'Current Color', 'cmb2' ),
) );
}
/**
* Localize the php variables for CMB2 JS
*
* @since 2.0.7
*
* @param mixed $debug Whether or not we are debugging.
*/
protected static function localize( $debug ) {
static $localized = false;
if ( $localized ) {
return;
}
$localized = true;
$l10n = array(
'fields' => self::$fields,
'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ),
'ajaxurl' => admin_url( '/admin-ajax.php' ),
'script_debug' => $debug,
'up_arrow_class' => 'dashicons dashicons-arrow-up-alt2',
'down_arrow_class' => 'dashicons dashicons-arrow-down-alt2',
'user_can_richedit' => user_can_richedit(),
'defaults' => array(
'code_editor' => false,
'color_picker' => false,
'date_picker' => array(
'changeMonth' => true,
'changeYear' => true,
'dateFormat' => _x( 'mm/dd/yy', 'Valid formatDate string for jquery-ui datepicker', 'cmb2' ),
'dayNames' => explode( ',', esc_html__( 'Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday', 'cmb2' ) ),
'dayNamesMin' => explode( ',', esc_html__( 'Su, Mo, Tu, We, Th, Fr, Sa', 'cmb2' ) ),
'dayNamesShort' => explode( ',', esc_html__( 'Sun, Mon, Tue, Wed, Thu, Fri, Sat', 'cmb2' ) ),
'monthNames' => explode( ',', esc_html__( 'January, February, March, April, May, June, July, August, September, October, November, December', 'cmb2' ) ),
'monthNamesShort' => explode( ',', esc_html__( 'Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec', 'cmb2' ) ),
'nextText' => esc_html__( 'Next', 'cmb2' ),
'prevText' => esc_html__( 'Prev', 'cmb2' ),
'currentText' => esc_html__( 'Today', 'cmb2' ),
'closeText' => esc_html__( 'Done', 'cmb2' ),
'clearText' => esc_html__( 'Clear', 'cmb2' ),
),
'time_picker' => array(
'timeOnlyTitle' => esc_html__( 'Choose Time', 'cmb2' ),
'timeText' => esc_html__( 'Time', 'cmb2' ),
'hourText' => esc_html__( 'Hour', 'cmb2' ),
'minuteText' => esc_html__( 'Minute', 'cmb2' ),
'secondText' => esc_html__( 'Second', 'cmb2' ),
'currentText' => esc_html__( 'Now', 'cmb2' ),
'closeText' => esc_html__( 'Done', 'cmb2' ),
'timeFormat' => _x( 'hh:mm TT', 'Valid formatting string, as per http://trentrichardson.com/examples/timepicker/', 'cmb2' ),
'controlType' => 'select',
'stepMinute' => 5,
),
),
'strings' => array(
'upload_file' => esc_html__( 'Use this file', 'cmb2' ),
'upload_files' => esc_html__( 'Use these files', 'cmb2' ),
'remove_image' => esc_html__( 'Remove Image', 'cmb2' ),
'remove_file' => esc_html__( 'Remove', 'cmb2' ),
'file' => esc_html__( 'File:', 'cmb2' ),
'download' => esc_html__( 'Download', 'cmb2' ),
'check_toggle' => esc_html__( 'Select / Deselect All', 'cmb2' ),
),
);
if ( isset( self::$dependencies['code-editor'] ) && function_exists( 'wp_enqueue_code_editor' ) ) {
$l10n['defaults']['code_editor'] = wp_enqueue_code_editor( array(
'type' => 'text/html',
) );
}
wp_localize_script( self::$handle, self::$js_variable, apply_filters( 'cmb2_localized_data', $l10n ) );
}
}

View File

@@ -0,0 +1,250 @@
<?php
/**
* CMB2 Utility classes for handling multi-dimensional array data for options
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
/**
* Retrieves an instance of CMB2_Option based on the option key
*
* @package CMB2
* @author CMB2 team
*/
class CMB2_Options {
/**
* Array of all CMB2_Option instances
*
* @var array
* @since 1.0.0
*/
protected static $option_sets = array();
public static function get( $option_key ) {
if ( empty( self::$option_sets ) || empty( self::$option_sets[ $option_key ] ) ) {
self::$option_sets[ $option_key ] = new CMB2_Option( $option_key );
}
return self::$option_sets[ $option_key ];
}
}
/**
* Handles getting/setting of values to an option array
* for a specific option key
*
* @package CMB2
* @author CMB2 team
*/
class CMB2_Option {
/**
* Options array
*
* @var array
*/
protected $options = array();
/**
* Current option key
*
* @var string
*/
protected $key = '';
/**
* Initiate option object
*
* @param string $option_key Option key where data will be saved.
* Leave empty for temporary data store.
* @since 2.0.0
*/
public function __construct( $option_key = '' ) {
$this->key = ! empty( $option_key ) ? $option_key : '';
}
/**
* Delete the option from the db
*
* @since 2.0.0
* @return mixed Delete success or failure
*/
public function delete_option() {
$deleted = $this->key ? delete_option( $this->key ) : true;
$this->options = $deleted ? array() : $this->options;
return $this->options;
}
/**
* Removes an option from an option array
*
* @since 1.0.1
* @param string $field_id Option array field key.
* @param bool $resave Whether or not to resave.
* @return array Modified options
*/
public function remove( $field_id, $resave = false ) {
$this->get_options();
if ( isset( $this->options[ $field_id ] ) ) {
unset( $this->options[ $field_id ] );
}
if ( $resave ) {
$this->set();
}
return $this->options;
}
/**
* Retrieves an option from an option array
*
* @since 1.0.1
* @param string $field_id Option array field key.
* @param mixed $default Fallback value for the option.
* @return array Requested field or default
*/
public function get( $field_id, $default = false ) {
$opts = $this->get_options();
if ( 'all' == $field_id ) {
return $opts;
} elseif ( array_key_exists( $field_id, $opts ) ) {
return false !== $opts[ $field_id ] ? $opts[ $field_id ] : $default;
}
return $default;
}
/**
* Updates Option data
*
* @since 1.0.1
* @param string $field_id Option array field key.
* @param mixed $value Value to update data with.
* @param bool $resave Whether to re-save the data.
* @param bool $single Whether data should not be an array.
* @return boolean Return status of update.
*/
public function update( $field_id, $value = '', $resave = false, $single = true ) {
$this->get_options();
if ( true !== $field_id ) {
if ( ! $single ) {
// If multiple, add to array.
$this->options[ $field_id ][] = $value;
} else {
$this->options[ $field_id ] = $value;
}
}
if ( $resave || true === $field_id ) {
return $this->set();
}
return true;
}
/**
* Saves the option array
* Needs to be run after finished using remove/update_option
*
* @uses apply_filters() Calls 'cmb2_override_option_save_{$this->key}' hook
* to allow overwriting the option value to be stored.
*
* @since 1.0.1
* @param array $options Optional options to override.
* @return bool Success/Failure
*/
public function set( $options = array() ) {
if ( ! empty( $options ) || empty( $options ) && empty( $this->key ) ) {
$this->options = $options;
}
$this->options = wp_unslash( $this->options ); // get rid of those evil magic quotes.
if ( empty( $this->key ) ) {
return false;
}
$test_save = apply_filters( "cmb2_override_option_save_{$this->key}", 'cmb2_no_override_option_save', $this->options, $this );
if ( 'cmb2_no_override_option_save' !== $test_save ) {
// If override, do not proceed to update the option, just return result.
return $test_save;
}
/**
* Whether to auto-load the option when WordPress starts up.
*
* The dynamic portion of the hook name, $this->key, refers to the option key.
*
* @since 2.4.0
*
* @param bool $autoload Whether to load the option when WordPress starts up.
* @param CMB2_Option $cmb_option This object.
*/
$autoload = apply_filters( "cmb2_should_autoload_{$this->key}", true, $this );
return update_option(
$this->key,
$this->options,
! $autoload || 'no' === $autoload ? false : true
);
}
/**
* Retrieve option value based on name of option.
*
* @uses apply_filters() Calls 'cmb2_override_option_get_{$this->key}' hook to allow
* overwriting the option value to be retrieved.
*
* @since 1.0.1
* @param mixed $default Optional. Default value to return if the option does not exist.
* @return mixed Value set for the option.
*/
public function get_options( $default = null ) {
if ( empty( $this->options ) && ! empty( $this->key ) ) {
$test_get = apply_filters( "cmb2_override_option_get_{$this->key}", 'cmb2_no_override_option_get', $default, $this );
if ( 'cmb2_no_override_option_get' !== $test_get ) {
$this->options = $test_get;
} else {
// If no override, get the option.
$this->options = get_option( $this->key, $default );
}
}
$this->options = (array) $this->options;
return $this->options;
}
/**
* Magic getter for our object.
*
* @since 2.6.0
*
* @param string $field Requested property.
* @throws Exception Throws an exception if the field is invalid.
* @return mixed
*/
public function __get( $field ) {
switch ( $field ) {
case 'options':
case 'key':
return $this->{$field};
default:
throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) );
}
}
}

View File

@@ -0,0 +1,372 @@
<?php
/**
* Handles hooking CMB2 forms/metaboxes into the post/attachement/user screens
* and handles hooking in and saving those fields.
*
* @since 2.0.0
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Options_Hookup extends CMB2_Hookup {
/**
* The object type we are performing the hookup for
*
* @var string
* @since 2.0.9
*/
protected $object_type = 'options-page';
/**
* Options page key.
*
* @var string
* @since 2.2.5
*/
protected $option_key = '';
/**
* Constructor
*
* @since 2.0.0
* @param CMB2 $cmb The CMB2 object to hookup.
* @param string $option_key Option key to use.
*/
public function __construct( CMB2 $cmb, $option_key ) {
$this->cmb = $cmb;
$this->option_key = $option_key;
}
public function hooks() {
if ( empty( $this->option_key ) ) {
return;
}
if ( ! $this->cmb->prop( 'autoload', true ) ) {
// Disable option autoload if requested.
add_filter( "cmb2_should_autoload_{$this->option_key}", '__return_false' );
}
/**
* For WP < 4.7. Ensure the register_setting function exists.
*/
if ( ! CMB2_Utils::wp_at_least( '4.7' ) && ! function_exists( 'register_setting' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Register setting to cmb2 group.
register_setting( 'cmb2', $this->option_key );
// Handle saving the data.
add_action( 'admin_post_' . $this->option_key, array( $this, 'save_options' ) );
// Optionally network_admin_menu.
$hook = $this->cmb->prop( 'admin_menu_hook' );
// Hook in to add our menu.
add_action( $hook, array( $this, 'options_page_menu_hooks' ), $this->get_priority() );
// If in the network admin, need to use get/update_site_option.
if ( 'network_admin_menu' === $hook ) {
// Override CMB's getter.
add_filter( "cmb2_override_option_get_{$this->option_key}", array( $this, 'network_get_override' ), 10, 2 );
// Override CMB's setter.
add_filter( "cmb2_override_option_save_{$this->option_key}", array( $this, 'network_update_override' ), 10, 2 );
}
}
/**
* Hook up our admin menu item and admin page.
*
* @since 2.2.5
*
* @return void
*/
public function options_page_menu_hooks() {
$parent_slug = $this->cmb->prop( 'parent_slug' );
$title = $this->cmb->prop( 'title' );
$menu_title = $this->cmb->prop( 'menu_title', $title );
$capability = $this->cmb->prop( 'capability' );
$callback = array( $this, 'options_page_output' );
if ( $parent_slug ) {
$page_hook = add_submenu_page(
$parent_slug,
$title,
$menu_title,
$capability,
$this->option_key,
$callback
);
} else {
$page_hook = add_menu_page(
$title,
$menu_title,
$capability,
$this->option_key,
$callback,
$this->cmb->prop( 'icon_url' ),
$this->cmb->prop( 'position' )
);
}
if ( $this->cmb->prop( 'cmb_styles' ) ) {
// Include CMB CSS in the head to avoid FOUC.
add_action( "admin_print_styles-{$page_hook}", array( 'CMB2_Hookup', 'enqueue_cmb_css' ) );
}
$this->maybe_register_message();
}
/**
* If there is a message callback, let it determine how to register the message,
* else add a settings message if on this settings page.
*
* @since 2.2.6
*
* @return void
*/
public function maybe_register_message() {
$is_options_page = self::is_page( $this->option_key );
$should_notify = ! $this->cmb->prop( 'disable_settings_errors' ) && isset( $_GET['settings-updated'] ) && $is_options_page;
$is_updated = $should_notify && 'true' === $_GET['settings-updated'];
$setting = "{$this->option_key}-notices";
$code = '';
$message = __( 'Nothing to update.', 'cmb2' );
$type = 'notice-warning';
if ( $is_updated ) {
$message = __( 'Settings updated.', 'cmb2' );
$type = 'updated';
}
// Check if parameter has registered a callback.
if ( $cb = $this->cmb->maybe_callback( 'message_cb' ) ) {
/**
* The 'message_cb' callback will receive the following parameters.
* Unless there are other reasons for notifications, the callback should only
* `add_settings_error()` if `$args['should_notify']` is truthy.
*
* @param CMB2 $cmb The CMB2 object.
* @param array $args {
* An array of message arguments
*
* @type bool $is_options_page Whether current page is this options page.
* @type bool $should_notify Whether options were saved and we should be notified.
* @type bool $is_updated Whether options were updated with save (or stayed the same).
* @type string $setting For add_settings_error(), Slug title of the setting to which
* this error applies.
* @type string $code For add_settings_error(), Slug-name to identify the error.
* Used as part of 'id' attribute in HTML output.
* @type string $message For add_settings_error(), The formatted message text to display
* to the user (will be shown inside styled `<div>` and `<p>` tags).
* Will be 'Settings updated.' if $is_updated is true, else 'Nothing to update.'
* @type string $type For add_settings_error(), Message type, controls HTML class.
* Accepts 'error', 'updated', '', 'notice-warning', etc.
* Will be 'updated' if $is_updated is true, else 'notice-warning'.
* }
*/
$args = compact( 'is_options_page', 'should_notify', 'is_updated', 'setting', 'code', 'message', 'type' );
$this->cmb->do_callback( $cb, $args );
} elseif ( $should_notify ) {
add_settings_error( $setting, $code, $message, $type );
}
}
/**
* Display options-page output. To override, set 'display_cb' box property.
*
* @since 2.2.5
*/
public function options_page_output() {
$this->maybe_output_settings_notices();
$callback = $this->cmb->prop( 'display_cb' );
if ( is_callable( $callback ) ) {
return call_user_func( $callback, $this );
}
?>
<div class="wrap cmb2-options-page option-<?php echo esc_attr( sanitize_html_class( $this->option_key ) ); ?>">
<?php if ( $this->cmb->prop( 'title' ) ) : ?>
<h2><?php echo wp_kses_post( $this->cmb->prop( 'title' ) ); ?></h2>
<?php endif; ?>
<?php $this->options_page_tab_nav_output(); ?>
<form class="cmb-form" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="POST" id="<?php echo $this->cmb->cmb_id; ?>" enctype="multipart/form-data" encoding="multipart/form-data">
<input type="hidden" name="action" value="<?php echo esc_attr( $this->option_key ); ?>">
<?php $this->options_page_metabox(); ?>
<?php submit_button( esc_attr( $this->cmb->prop( 'save_button' ) ), 'primary', 'submit-cmb' ); ?>
</form>
</div>
<?php
}
/**
* Display options-page Tab Navigation output.
*
* @since 2.9.0
*/
public function options_page_tab_nav_output() {
$tabs = $this->get_tab_group_tabs();
if ( empty( $tabs ) ) {
return;
}
?>
<h2 class="nav-tab-wrapper">
<?php foreach ( $tabs as $option_key => $tab_title ) : ?>
<a class="nav-tab<?php if ( self::is_page( $option_key ) ) : ?> nav-tab-active<?php endif; ?>" href="<?php menu_page_url( $option_key ); ?>"><?php echo wp_kses_post( $tab_title ); ?></a>
<?php endforeach; ?>
</h2>
<?php
}
/**
* Outputs the settings notices if a) not a sub-page of 'options-general.php'
* (because settings_errors() already called in wp-admin/options-head.php),
* and b) the 'disable_settings_errors' prop is not set or truthy.
*
* @since 2.2.5
* @return void
*/
public function maybe_output_settings_notices() {
global $parent_file;
// The settings sub-pages will already have settings_errors() called in wp-admin/options-head.php.
if ( 'options-general.php' !== $parent_file ) {
settings_errors( "{$this->option_key}-notices" );
}
}
/**
* Gets navigation tabs array for CMB2 options pages which share the
* same tab_group property.
*
* @since 2.4.0
* @return array Array of tab information ($option_key => $tab_title)
*/
public function get_tab_group_tabs() {
$tab_group = $this->cmb->prop( 'tab_group' );
$tabs = array();
if ( $tab_group ) {
$boxes = CMB2_Boxes::get_by( 'tab_group', $tab_group );
foreach ( $boxes as $cmb_id => $cmb ) {
$option_key = $cmb->options_page_keys();
// Must have an option key, must be an options page box.
if ( ! isset( $option_key[0] ) || 'options-page' !== $cmb->mb_object_type() ) {
continue;
}
$tabs[ $option_key[0] ] = $cmb->prop( 'tab_title', $cmb->prop( 'title' ) );
}
}
return apply_filters( 'cmb2_tab_group_tabs', $tabs, $tab_group );
}
/**
* Display metaboxes for an options-page object.
*
* @since 2.2.5
*/
public function options_page_metabox() {
$this->show_form_for_type( 'options-page' );
}
/**
* Save data from options page, then redirects back.
*
* @since 2.2.5
* @return void
*/
public function save_options() {
$url = wp_get_referer();
if ( ! $url ) {
$url = admin_url();
}
if (
$this->can_save( 'options-page' )
// check params.
&& isset( $_POST['submit-cmb'], $_POST['action'] )
&& $this->option_key === $_POST['action']
) {
$updated = $this->cmb
->save_fields( $this->option_key, $this->cmb->object_type(), $_POST )
->was_updated(); // Will be false if no values were changed/updated.
$url = add_query_arg( 'settings-updated', $updated ? 'true' : 'false', $url );
}
wp_safe_redirect( esc_url_raw( $url ), 303 /* WP_Http::SEE_OTHER */ );
exit;
}
/**
* Replaces get_option with get_site_option.
*
* @since 2.2.5
*
* @param mixed $test Not used.
* @param mixed $default Default value to use.
* @return mixed Value set for the network option.
*/
public function network_get_override( $test, $default = false ) {
return get_site_option( $this->option_key, $default );
}
/**
* Replaces update_option with update_site_option.
*
* @since 2.2.5
*
* @param mixed $test Not used.
* @param mixed $option_value Value to use.
* @return bool Success/Failure
*/
public function network_update_override( $test, $option_value ) {
return update_site_option( $this->option_key, $option_value );
}
/**
* Determines if given page slug matches the 'page' GET query variable.
*
* @since 2.4.0
*
* @param string $page Page slug.
* @return boolean
*/
public static function is_page( $page ) {
return isset( $_GET['page'] ) && $page === $_GET['page'];
}
/**
* Magic getter for our object.
*
* @param string $field Property to retrieve.
*
* @throws Exception Throws an exception if the field is invalid.
* @return mixed
*/
public function __get( $field ) {
switch ( $field ) {
case 'object_type':
case 'option_key':
case 'cmb':
return $this->{$field};
default:
throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) );
}
}
}

View File

@@ -0,0 +1,665 @@
<?php
/**
* CMB2 field sanitization
*
* @since 0.0.4
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*
* @method string _id()
*/
class CMB2_Sanitize {
/**
* A CMB field object
*
* @var CMB2_Field object
*/
public $field;
/**
* Field's value
*
* @var mixed
*/
public $value;
/**
* Setup our class vars
*
* @since 1.1.0
* @param CMB2_Field $field A CMB2 field object.
* @param mixed $value Field value.
*/
public function __construct( CMB2_Field $field, $value ) {
$this->field = $field;
$this->value = $value;
}
/**
* Catchall method if field's 'sanitization_cb' is NOT defined,
* or field type does not have a corresponding validation method.
*
* @since 1.0.0
*
* @param string $name Non-existent method name.
* @param array $arguments All arguments passed to the method.
* @return mixed
*/
public function __call( $name, $arguments ) {
return $this->default_sanitization();
}
/**
* Default fallback sanitization method. Applies filters.
*
* @since 1.0.2
*/
public function default_sanitization() {
$field_type = $this->field->type();
/**
* This exists for back-compatibility, but validation
* is not what happens here.
*
* @deprecated See documentation for "cmb2_sanitize_{$field_type}".
*/
if ( function_exists( 'apply_filters_deprecated' ) ) {
$override_value = apply_filters_deprecated( "cmb2_validate_{$field_type}", array( null, $this->value, $this->field->object_id, $this->field->args(), $this ), '2.0.0', "cmb2_sanitize_{$field_type}" );
} else {
$override_value = apply_filters( "cmb2_validate_{$field_type}", null, $this->value, $this->field->object_id, $this->field->args(), $this );
}
if ( null !== $override_value ) {
return $override_value;
}
$sanitized_value = '';
switch ( $field_type ) {
case 'wysiwyg':
case 'textarea_small':
case 'oembed':
$sanitized_value = $this->textarea();
break;
case 'taxonomy_select':
case 'taxonomy_select_hierarchical':
case 'taxonomy_radio':
case 'taxonomy_radio_inline':
case 'taxonomy_radio_hierarchical':
case 'taxonomy_multicheck':
case 'taxonomy_multicheck_hierarchical':
case 'taxonomy_multicheck_inline':
$sanitized_value = $this->taxonomy();
break;
case 'multicheck':
case 'multicheck_inline':
case 'file_list':
case 'group':
// no filtering
$sanitized_value = $this->value;
break;
default:
// Handle repeatable fields array
// We'll fallback to 'sanitize_text_field'
$sanitized_value = $this->_default_sanitization();
break;
}
return $this->_is_empty_array( $sanitized_value ) ? '' : $sanitized_value;
}
/**
* Default sanitization method, sanitize_text_field. Checks if value is array.
*
* @since 2.2.4
* @return mixed Sanitized value.
*/
protected function _default_sanitization() {
// Handle repeatable fields array.
return is_array( $this->value ) ? array_map( 'sanitize_text_field', $this->value ) : sanitize_text_field( $this->value );
}
/**
* Sets the object terms to the object (if not options-page) and optionally returns the sanitized term values.
*
* @since 2.2.4
* @return mixed Blank value, or sanitized term values if "cmb2_return_taxonomy_values_{$cmb_id}" is true.
*/
public function taxonomy() {
$sanitized_value = '';
if ( ! $this->field->args( 'taxonomy' ) ) {
CMB2_Utils::log_if_debug( __METHOD__, __LINE__, "{$this->field->type()} {$this->field->_id( '', false )} is missing the 'taxonomy' parameter." );
} else {
if ( in_array( $this->field->object_type, array( 'options-page', 'term' ), true ) ) {
$return_values = true;
} else {
wp_set_object_terms( $this->field->object_id, $this->value, $this->field->args( 'taxonomy' ) );
$return_values = false;
}
$cmb_id = $this->field->cmb_id;
/**
* Filter whether 'taxonomy_*' fields should return their value when being sanitized.
*
* By default, these fields do not return a value as we do not want them stored to meta
* (as they are stored as terms). This allows overriding that and is used by CMB2::get_sanitized_values().
*
* The dynamic portion of the hook, $cmb_id, refers to the this field's CMB2 box id.
*
* @since 2.2.4
*
* @param bool $return_values By default, this is only true for 'options-page' boxes. To enable:
* `add_filter( "cmb2_return_taxonomy_values_{$cmb_id}", '__return_true' );`
* @param CMB2_Sanitize $sanitizer This object.
*/
if ( apply_filters( "cmb2_return_taxonomy_values_{$cmb_id}", $return_values, $this ) ) {
$sanitized_value = $this->_default_sanitization();
}
}
return $sanitized_value;
}
/**
* Simple checkbox validation
*
* @since 1.0.1
* @return string|false 'on' or false
*/
public function checkbox() {
return $this->value === 'on' ? 'on' : false;
}
/**
* Validate url in a meta value.
*
* @since 1.0.1
* @return string Empty string or escaped url
*/
public function text_url() {
$protocols = $this->field->args( 'protocols' );
$default = $this->field->get_default();
// for repeatable.
if ( is_array( $this->value ) ) {
foreach ( $this->value as $key => $val ) {
$this->value[ $key ] = self::sanitize_and_secure_url( $val, $protocols, $default );
}
} else {
$this->value = self::sanitize_and_secure_url( $this->value, $protocols, $default );
}
return $this->value;
}
public function colorpicker() {
// for repeatable.
if ( is_array( $this->value ) ) {
$check = $this->value;
$this->value = array();
foreach ( $check as $key => $val ) {
if ( $val && '#' != $val ) {
$this->value[ $key ] = esc_attr( $val );
}
}
} else {
$this->value = ! $this->value || '#' == $this->value ? '' : esc_attr( $this->value );
}
return $this->value;
}
/**
* Validate email in a meta value
*
* @since 1.0.1
* @return string Empty string or sanitized email
*/
public function text_email() {
// for repeatable.
if ( is_array( $this->value ) ) {
foreach ( $this->value as $key => $val ) {
$val = trim( $val );
$this->value[ $key ] = is_email( $val ) ? $val : '';
}
} else {
$this->value = trim( $this->value );
$this->value = is_email( $this->value ) ? $this->value : '';
}
return $this->value;
}
/**
* Validate money in a meta value
*
* @since 1.0.1
* @return string Empty string or sanitized money value
*/
public function text_money() {
if ( ! $this->value ) {
return '';
}
global $wp_locale;
$search = array( $wp_locale->number_format['thousands_sep'], $wp_locale->number_format['decimal_point'] );
$replace = array( '', '.' );
// Strip slashes. Example: 2\'180.00.
// See https://github.com/CMB2/CMB2/issues/1014.
$this->value = wp_unslash( $this->value );
// for repeatable.
if ( is_array( $this->value ) ) {
foreach ( $this->value as $key => $val ) {
if ( $val ) {
$this->value[ $key ] = number_format_i18n( (float) str_ireplace( $search, $replace, $val ), 2 );
}
}
} else {
$this->value = number_format_i18n( (float) str_ireplace( $search, $replace, $this->value ), 2 );
}
return $this->value;
}
/**
* Converts text date to timestamp
*
* @since 1.0.2
* @return string Timestring
*/
public function text_date_timestamp() {
// date_create_from_format if there is a slash in the value.
$this->value = wp_unslash( $this->value );
return is_array( $this->value )
? array_map( array( $this->field, 'get_timestamp_from_value' ), $this->value )
: $this->field->get_timestamp_from_value( $this->value );
}
/**
* Datetime to timestamp
*
* @since 1.0.1
*
* @param bool $repeat Whether or not to repeat.
* @return string|array Timestring
*/
public function text_datetime_timestamp( $repeat = false ) {
// date_create_from_format if there is a slash in the value.
$this->value = wp_unslash( $this->value );
if ( $this->is_empty_value() ) {
return '';
}
$repeat_value = $this->_check_repeat( __FUNCTION__, $repeat );
if ( false !== $repeat_value ) {
return $repeat_value;
}
// Account for timestamp values passed through REST API.
if ( $this->is_valid_date_value() ) {
$this->value = CMB2_Utils::make_valid_time_stamp( $this->value );
} elseif ( isset( $this->value['date'], $this->value['time'] ) ) {
$this->value = $this->field->get_timestamp_from_value( $this->value['date'] . ' ' . $this->value['time'] );
}
if ( $tz_offset = $this->field->field_timezone_offset() ) {
$this->value += (int) $tz_offset;
}
return $this->value;
}
/**
* Datetime to timestamp with timezone
*
* @since 1.0.1
*
* @param bool $repeat Whether or not to repeat.
* @return string Timestring
*/
public function text_datetime_timestamp_timezone( $repeat = false ) {
static $utc_values = array();
if ( $this->is_empty_value() ) {
return '';
}
// date_create_from_format if there is a slash in the value.
$this->value = wp_unslash( $this->value );
$utc_key = $this->field->_id( '', false ) . '_utc';
$repeat_value = $this->_check_repeat( __FUNCTION__, $repeat );
if ( false !== $repeat_value ) {
if ( ! empty( $utc_values[ $utc_key ] ) ) {
$this->_save_utc_value( $utc_key, $utc_values[ $utc_key ] );
unset( $utc_values[ $utc_key ] );
}
return $repeat_value;
}
$tzstring = null;
if ( is_array( $this->value ) && array_key_exists( 'timezone', $this->value ) ) {
$tzstring = $this->value['timezone'];
}
if ( empty( $tzstring ) ) {
$tzstring = CMB2_Utils::timezone_string();
}
$offset = CMB2_Utils::timezone_offset( $tzstring );
if ( 'UTC' === substr( $tzstring, 0, 3 ) ) {
$tzstring = timezone_name_from_abbr( '', $offset, 0 );
/**
* The timezone_name_from_abbr() returns false if not found based on offset.
* Since there are currently some invalid timezones in wp_timezone_dropdown(),
* fallback to an offset of 0 (UTC+0)
* https://core.trac.wordpress.org/ticket/29205
*/
$tzstring = false !== $tzstring ? $tzstring : timezone_name_from_abbr( '', 0, 0 );
}
$full_format = $this->field->args['date_format'] . ' ' . $this->field->args['time_format'];
try {
$datetime = null;
if ( is_array( $this->value ) ) {
$full_date = $this->value['date'] . ' ' . $this->value['time'];
$datetime = date_create_from_format( $full_format, $full_date );
} elseif ( $this->is_valid_date_value() ) {
$timestamp = CMB2_Utils::make_valid_time_stamp( $this->value );
if ( $timestamp ) {
$datetime = new DateTime();
$datetime->setTimestamp( $timestamp );
}
}
if ( ! is_object( $datetime ) ) {
$this->value = $utc_stamp = '';
} else {
$datetime->setTimezone( new DateTimeZone( $tzstring ) );
$utc_stamp = date_timestamp_get( $datetime ) - $offset;
$this->value = serialize( $datetime );
}
if ( $this->field->group ) {
$this->value = array(
'supporting_field_value' => $utc_stamp,
'supporting_field_id' => $utc_key,
'value' => $this->value,
);
} else {
// Save the utc timestamp supporting field.
if ( $repeat ) {
$utc_values[ $utc_key ][] = $utc_stamp;
} else {
$this->_save_utc_value( $utc_key, $utc_stamp );
}
}
} catch ( Exception $e ) {
$this->value = '';
CMB2_Utils::log_if_debug( __METHOD__, __LINE__, $e->getMessage() );
}
return $this->value;
}
/**
* Sanitize textareas and wysiwyg fields
*
* @since 1.0.1
* @return string Sanitized data
*/
public function textarea() {
return is_array( $this->value ) ? array_map( 'wp_kses_post', $this->value ) : wp_kses_post( $this->value );
}
/**
* Sanitize code textareas
*
* @since 1.0.2
*
* @param bool $repeat Whether or not to repeat.
* @return string Sanitized data
*/
public function textarea_code( $repeat = false ) {
$repeat_value = $this->_check_repeat( __FUNCTION__, $repeat );
if ( false !== $repeat_value ) {
return $repeat_value;
}
return htmlspecialchars_decode( stripslashes( $this->value ) );
}
/**
* Handles saving of attachment post ID and sanitizing file url
*
* @since 1.1.0
* @return string Sanitized url
*/
public function file() {
$file_id_key = $this->field->_id( '', false ) . '_id';
if ( $this->field->group ) {
// Return an array with url/id if saving a group field.
$this->value = $this->_get_group_file_value_array( $file_id_key );
} else {
$this->_save_file_id_value( $file_id_key );
$this->text_url();
}
return $this->value;
}
/**
* Gets the values for the `file` field type from the data being saved.
*
* @since 2.2.0
*
* @param mixed $id_key ID key to use.
* @return array
*/
public function _get_group_file_value_array( $id_key ) {
$alldata = $this->field->group->data_to_save;
$base_id = $this->field->group->_id( '', false );
$i = $this->field->group->index;
// Check group $alldata data.
$id_val = isset( $alldata[ $base_id ][ $i ][ $id_key ] )
? absint( $alldata[ $base_id ][ $i ][ $id_key ] )
: '';
// We don't want to save 0 to the DB for file fields.
if ( 0 === $id_val ) {
$id_val = '';
}
return array(
'value' => $this->text_url(),
'supporting_field_value' => $id_val,
'supporting_field_id' => $id_key,
);
}
/**
* Peforms saving of `file` attachement's ID
*
* @since 1.1.0
*
* @param mixed $file_id_key ID key to use.
* @return mixed
*/
public function _save_file_id_value( $file_id_key ) {
$id_field = $this->_new_supporting_field( $file_id_key );
// Check standard data_to_save data.
$id_val = isset( $this->field->data_to_save[ $file_id_key ] )
? $this->field->data_to_save[ $file_id_key ]
: null;
// If there is no ID saved yet, try to get it from the url.
if ( $this->value && ! $id_val ) {
$id_val = CMB2_Utils::image_id_from_url( $this->value );
// If there is an ID but user emptied the input value, remove the ID.
} elseif ( ! $this->value && $id_val ) {
$id_val = null;
}
return $id_field->save_field( $id_val );
}
/**
* Peforms saving of `text_datetime_timestamp_timezone` utc timestamp
*
* @since 2.2.0
*
* @param mixed $utc_key UTC key.
* @param mixed $utc_stamp UTC timestamp.
* @return mixed
*/
public function _save_utc_value( $utc_key, $utc_stamp ) {
return $this->_new_supporting_field( $utc_key )->save_field( $utc_stamp );
}
/**
* Returns a new, supporting, CMB2_Field object based on a new field id.
*
* @since 2.2.0
*
* @param mixed $new_field_id New field ID.
* @return CMB2_Field
*/
public function _new_supporting_field( $new_field_id ) {
return $this->field->get_field_clone( array(
'id' => $new_field_id,
'sanitization_cb' => false,
) );
}
/**
* If repeating, loop through and re-apply sanitization method
*
* @since 1.1.0
* @param string $method Class method.
* @param bool $repeat Whether repeating or not.
* @return mixed Sanitized value
*/
public function _check_repeat( $method, $repeat ) {
if ( $repeat || ! $this->field->args( 'repeatable' ) ) {
return false;
}
$values_array = $this->value;
$new_value = array();
foreach ( $values_array as $iterator => $this->value ) {
if ( $this->value ) {
$val = $this->$method( true );
if ( ! empty( $val ) ) {
$new_value[] = $val;
}
}
}
$this->value = $new_value;
return empty( $this->value ) ? null : $this->value;
}
/**
* Determine if passed value is an empty array
*
* @since 2.0.6
* @param mixed $to_check Value to check.
* @return boolean Whether value is an array that's empty
*/
public function _is_empty_array( $to_check ) {
if ( is_array( $to_check ) ) {
$cleaned_up = array_filter( $to_check );
return empty( $cleaned_up );
}
return false;
}
/**
* Sanitize a URL. Make the default scheme HTTPS.
*
* @since 2.10.0
* @param string $value Unescaped URL.
* @param array $protocols Allowed protocols for URL.
* @param string $default Default value if no URL found.
* @return string escaped URL.
*/
public static function sanitize_and_secure_url( $url, $protocols = null, $default = null ) {
if ( empty( $url ) ) {
return $default;
}
$orig_scheme = parse_url( $url, PHP_URL_SCHEME );
$url = esc_url_raw( $url, $protocols );
// If original url has no scheme...
if ( null === $orig_scheme ) {
// Let's make sure the added scheme is https.
$url = set_url_scheme( $url, 'https' );
}
return $url;
}
/**
* Check if the current field's value is empty.
*
* @since 2.9.1
*
* @return boolean Wether value is empty.
*/
public function is_empty_value() {
if ( empty( $this->value ) ) {
return true;
}
if ( is_array( $this->value ) ) {
$test = array_filter( $this->value );
if ( empty( $test ) ) {
return true;
}
}
return false;
}
/**
* Check if the current field's value is a valid date value.
*
* @since 2.9.1
*
* @return boolean Wether value is a valid date value.
*/
public function is_valid_date_value() {
return is_scalar( $this->value ) && CMB2_Utils::is_valid_date( $this->value );
}
}

View File

@@ -0,0 +1,179 @@
<?php
/**
* Show On Filters
* Use the 'cmb2_show_on' filter to further refine the conditions
* under which a metabox is displayed.
* Below you can limit it by ID and page template
*
* All methods in this class are automatically filtered
*
* @since 1.0.0
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Show_Filters {
/**
* Get Show_on key. backwards compatible w/ 'key' indexes
*
* @since 2.0.0
*
* @param array $meta_box_args Metabox config array.
*
* @return mixed show_on key or false
*/
private static function get_show_on_key( $meta_box_args ) {
$show_on = isset( $meta_box_args['show_on'] ) ? (array) $meta_box_args['show_on'] : false;
if ( $show_on && is_array( $show_on ) ) {
if ( array_key_exists( 'key', $show_on ) ) {
return $show_on['key'];
}
$keys = array_keys( $show_on );
return $keys[0];
}
return false;
}
/**
* Get Show_on value. backwards compatible w/ 'value' indexes
*
* @since 2.0.0
*
* @param array $meta_box_args Metabox config array.
*
* @return mixed show_on value or false
*/
private static function get_show_on_value( $meta_box_args ) {
$show_on = isset( $meta_box_args['show_on'] ) ? (array) $meta_box_args['show_on'] : false;
if ( $show_on && is_array( $show_on ) ) {
if ( array_key_exists( 'value', $show_on ) ) {
return $show_on['value'];
}
$keys = array_keys( $show_on );
return $show_on[ $keys[0] ];
}
return array();
}
/**
* Add metaboxes for an specific ID
*
* @since 1.0.0
* @param bool $display To display or not.
* @param array $meta_box_args Metabox config array.
* @param CMB2 $cmb The CMB2 instance.
* @return bool Whether to display this metabox on the current page.
*/
public static function check_id( $display, $meta_box_args, $cmb ) {
$key = self::get_show_on_key( $meta_box_args );
if ( ! $key || 'id' !== $key ) {
return $display;
}
$object_id = is_admin() ? $cmb->object_id() : get_the_ID();
if ( ! $object_id ) {
return false;
}
// If current page id is in the included array, display the metabox.
return in_array( $object_id, (array) self::get_show_on_value( $meta_box_args ) );
}
/**
* Add metaboxes for an specific Page Template
*
* @since 1.0.0
* @param bool $display To display or not.
* @param array $meta_box_args Metabox config array.
* @param CMB2 $cmb CMB2 object.
* @return bool Whether to display this metabox on the current page.
*/
public static function check_page_template( $display, $meta_box_args, $cmb ) {
$key = self::get_show_on_key( $meta_box_args );
if ( ! $key || 'page-template' !== $key ) {
return $display;
}
$object_id = $cmb->object_id();
if ( ! $object_id || 'post' !== $cmb->object_type() ) {
return false;
}
// Get current template.
$current_template = get_post_meta( $object_id, '_wp_page_template', true );
// See if there's a match.
if ( $current_template && in_array( $current_template, (array) self::get_show_on_value( $meta_box_args ) ) ) {
return true;
}
return false;
}
/**
* Only show options-page metaboxes on their options page (but only enforce on the admin side)
*
* @since 1.0.0
* @param bool $display To display or not.
* @param array $meta_box_args Metabox config array.
* @return bool Whether to display this metabox on the current page.
*/
public static function check_admin_page( $display, $meta_box_args ) {
$key = self::get_show_on_key( $meta_box_args );
// check if this is a 'options-page' metabox.
if ( ! $key || 'options-page' !== $key ) {
return $display;
}
// Enforce 'show_on' filter in the admin.
if ( is_admin() ) {
// If there is no 'page' query var, our filter isn't applicable.
if ( ! isset( $_GET['page'] ) ) {
return $display;
}
$show_on = self::get_show_on_value( $meta_box_args );
if ( empty( $show_on ) ) {
return false;
}
if ( is_array( $show_on ) ) {
foreach ( $show_on as $page ) {
if ( $_GET['page'] == $page ) {
return true;
}
}
} else {
if ( $_GET['page'] == $show_on ) {
return true;
}
}
return false;
}
// Allow options-page metaboxes to be displayed anywhere on the front-end.
return true;
}
}

View File

@@ -0,0 +1,675 @@
<?php
/**
* CMB field type objects
*
* @since 1.0.0
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Types {
/**
* An iterator value for repeatable fields
*
* @var integer
* @since 1.0.0
*/
public $iterator = 0;
/**
* Current CMB2_Field field object
*
* @var CMB2_Field object
* @since 1.0.0
*/
public $field;
/**
* Current CMB2_Type_Base object
*
* @var CMB2_Type_Base object
* @since 2.2.2
*/
public $type = null;
public function __construct( CMB2_Field $field ) {
$this->field = $field;
}
/**
* Default fallback. Allows rendering fields via "cmb2_render_$fieldtype" hook
*
* @since 1.0.0
* @param string $fieldtype Non-existent field type name
* @param array $arguments All arguments passed to the method
*/
public function __call( $fieldtype, $arguments ) {
// Check for methods to be proxied to the CMB2_Type_Base object.
if ( $exists = $this->maybe_proxy_method( $fieldtype, $arguments ) ) {
return $exists['value'];
}
// Check for custom field type class.
if ( $object = $this->maybe_custom_field_object( $fieldtype, $arguments ) ) {
return $object->render();
}
/**
* Pass non-existent field types through an action.
*
* The dynamic portion of the hook name, $fieldtype, refers to the field type.
*
* @param array $field The passed in `CMB2_Field` object
* @param mixed $escaped_value The value of this field escaped.
* It defaults to `sanitize_text_field`.
* If you need the unescaped value, you can access it
* via `$field->value()`
* @param int $object_id The ID of the current object
* @param string $object_type The type of object you are working with.
* Most commonly, `post` (this applies to all post-types),
* but could also be `comment`, `user` or `options-page`.
* @param object $field_type_object This `CMB2_Types` object
*/
do_action( "cmb2_render_{$fieldtype}", $this->field, $this->field->escaped_value(), $this->field->object_id, $this->field->object_type, $this );
}
/**
* Render a field (and handle repeatable)
*
* @since 1.1.0
*/
public function render() {
if ( $this->field->args( 'repeatable' ) ) {
$this->render_repeatable_field();
} else {
$this->_render();
}
}
/**
* Render a field type
*
* @since 1.1.0
*/
protected function _render() {
$this->field->peform_param_callback( 'before_field' );
echo $this->{$this->field->type()}();
$this->field->peform_param_callback( 'after_field' );
}
/**
* Proxies the method call to the CMB2_Type_Base object, if it exists, otherwise returns a default fallback value.
*
* @since 2.2.2
*
* @param string $method Method to call on the CMB2_Type_Base object.
* @param mixed $default Default fallback value if method is not found.
* @param array $args Optional arguments to pass to proxy method.
*
* @return mixed Results from called method.
*/
protected function proxy_method( $method, $default, $args = array() ) {
if ( ! is_object( $this->type ) ) {
$this->guess_type_object( $method );
}
if ( is_object( $this->type ) && method_exists( $this->type, $method ) ) {
return empty( $args )
? $this->type->$method()
: call_user_func_array( array( $this->type, $method ), $args );
}
return $default;
}
/**
* If no CMB2_Types::$type object is initiated when a proxy method is called, it means
* it's a custom field type (which SHOULD be instantiating a Type), but let's try and
* guess the type object for them and instantiate it.
*
* @since 2.2.3
*
* @param string $method Method attempting to be called on the CMB2_Type_Base object.
* @return bool
*/
protected function guess_type_object( $method ) {
$fieldtype = $this->field->type();
// Try to "guess" the Type object based on the method requested.
switch ( $method ) {
case 'select_option':
case 'list_input':
case 'list_input_checkbox':
case 'concat_items':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_Select' );
break;
case 'is_valid_img_ext':
case 'img_status_output':
case 'file_status_output':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_File_Base' );
break;
case 'parse_picker_options':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_Text_Date' );
break;
case 'get_object_terms':
case 'get_terms':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_Taxonomy_Multicheck' );
break;
case 'date_args':
case 'time_args':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_Text_Datetime_Timestamp' );
break;
case 'parse_args':
$this->get_new_render_type( $fieldtype, 'CMB2_Type_Text' );
break;
}
return null !== $this->type;
}
/**
* Check for methods to be proxied to the CMB2_Type_Base object.
*
* @since 2.2.4
* @param string $method The possible method to proxy.
* @param array $arguments All arguments passed to the method.
* @return bool|array False if not proxied, else array with 'value' key being the return of the method.
*/
public function maybe_proxy_method( $method, $arguments ) {
$exists = false;
$proxied = array(
'get_object_terms' => array(),
'is_valid_img_ext' => false,
'parse_args' => array(),
'concat_items' => '',
'select_option' => '',
'list_input' => '',
'list_input_checkbox' => '',
'img_status_output' => '',
'file_status_output' => '',
'parse_picker_options' => array(),
);
if ( isset( $proxied[ $method ] ) ) {
$exists = array(
// Ok, proxy the method call to the CMB2_Type_Base object.
'value' => $this->proxy_method( $method, $proxied[ $method ], $arguments ),
);
}
return $exists;
}
/**
* Checks for a custom field CMB2_Type_Base class to use for rendering.
*
* @since 2.2.4
*
* @param string $fieldtype Non-existent field type name.
* @param array $args Optional field arguments.
*
* @return bool|CMB2_Type_Base Type object if custom field is an object, false if field was added with
* `cmb2_render_{$field_type}` action.
* @throws Exception if custom field type class does not extend CMB2_Type_Base.
*/
public function maybe_custom_field_object( $fieldtype, $args = array() ) {
if ( $render_class_name = $this->get_render_type_class( $fieldtype ) ) {
$this->type = new $render_class_name( $this, $args );
if ( ! ( $this->type instanceof CMB2_Type_Base ) ) {
throw new Exception( __( 'Custom CMB2 field type classes must extend CMB2_Type_Base.', 'cmb2' ) );
}
return $this->type;
}
return false;
}
/**
* Gets the render type CMB2_Type_Base object to use for rendering the field.
*
* @since 2.2.4
* @param string $fieldtype The type of field being rendered.
* @param string $render_class_name The default field type class to use. Defaults to null.
* @param array $args Optional arguments to pass to type class.
* @param mixed $additional Optional additional argument to pass to type class.
* @return CMB2_Type_Base Type object.
*/
public function get_new_render_type( $fieldtype, $render_class_name = null, $args = array(), $additional = '' ) {
$render_class_name = $this->get_render_type_class( $fieldtype, $render_class_name );
$this->type = new $render_class_name( $this, $args, $additional );
return $this->type;
}
/**
* Checks for the render type class to use for rendering the field.
*
* @since 2.2.4
* @param string $fieldtype The type of field being rendered.
* @param string $render_class_name The default field type class to use. Defaults to null.
* @return string The field type class to use.
*/
public function get_render_type_class( $fieldtype, $render_class_name = null ) {
$render_class_name = $this->field->args( 'render_class' ) ? $this->field->args( 'render_class' ) : $render_class_name;
if ( has_action( "cmb2_render_class_{$fieldtype}" ) ) {
/**
* Filters the custom field type class used for rendering the field. Class is required to extend CMB2_Type_Base.
*
* The dynamic portion of the hook name, $fieldtype, refers to the (custom) field type.
*
* @since 2.2.4
*
* @param string $render_class_name The custom field type class to use. Default null.
* @param object $field_type_object This `CMB2_Types` object.
*/
$render_class_name = apply_filters( "cmb2_render_class_{$fieldtype}", $render_class_name, $this );
}
return $render_class_name && class_exists( $render_class_name ) ? $render_class_name : false;
}
/**
* Retrieve text parameter from field's options array (if it has one), or use fallback text
*
* @since 2.0.0
* @param string $text_key Key in field's options array.
* @param string $fallback Fallback text.
* @return string
*/
public function _text( $text_key, $fallback = '' ) {
return $this->field->get_string( $text_key, $fallback );
}
/**
* Determine a file's extension
*
* @since 1.0.0
* @param string $file File url
* @return string|false File extension or false
*/
public function get_file_ext( $file ) {
return CMB2_Utils::get_file_ext( $file );
}
/**
* Get the file name from a url
*
* @since 2.0.0
* @param string $value File url or path
* @return string File name
*/
public function get_file_name_from_path( $value ) {
return CMB2_Utils::get_file_name_from_path( $value );
}
/**
* Combines attributes into a string for a form element
*
* @since 1.1.0
* @param array $attrs Attributes to concatenate
* @param array $attr_exclude Attributes that should NOT be concatenated
* @return string String of attributes for form element
*/
public function concat_attrs( $attrs, $attr_exclude = array() ) {
return CMB2_Utils::concat_attrs( $attrs, $attr_exclude );
}
/**
* Generates repeatable field table markup
*
* @since 1.0.0
*/
public function render_repeatable_field() {
$table_id = $this->field->id() . '_repeat';
$this->_desc( true, true, true );
?>
<div id="<?php echo $table_id; ?>" class="cmb-repeat-table cmb-nested">
<div class="cmb-tbody cmb-field-list">
<?php $this->repeatable_rows(); ?>
</div>
</div>
<p class="cmb-add-row">
<button type="button" data-selector="<?php echo $table_id; ?>" class="cmb-add-row-button button-secondary"><?php echo esc_html( $this->_text( 'add_row_text', esc_html__( 'Add Row', 'cmb2' ) ) ); ?></button>
</p>
<?php
// reset iterator
$this->iterator = 0;
}
/**
* Generates repeatable field rows
*
* @since 1.1.0
*/
public function repeatable_rows() {
$meta_value = array_filter( (array) $this->field->escaped_value() );
// check for default content
$default = $this->field->get_default();
// check for saved data
if ( ! empty( $meta_value ) ) {
$meta_value = is_array( $meta_value ) ? array_filter( $meta_value ) : $meta_value;
$meta_value = ! empty( $meta_value ) ? $meta_value : $default;
} else {
$meta_value = $default;
}
// Loop value array and add a row
if ( ! empty( $meta_value ) ) {
foreach ( (array) $meta_value as $val ) {
$this->field->escaped_value = $val;
$this->repeat_row();
$this->iterator++;
}
} else {
// If value is empty (including empty array), then clear the value.
$this->field->escaped_value = $this->field->value = null;
// Otherwise add one row
$this->repeat_row();
}
// Then add an empty row
$this->field->escaped_value = $default;
$this->iterator = $this->iterator ? $this->iterator : 1;
$this->repeat_row( 'empty-row hidden' );
}
/**
* Generates a repeatable row's markup
*
* @since 1.1.0
* @param string $classes Repeatable table row's class
*/
protected function repeat_row( $classes = 'cmb-repeat-row' ) {
$classes = explode( ' ', $classes );
$classes = array_map( 'sanitize_html_class', $classes );
?>
<div class="cmb-row <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
<div class="cmb-td">
<?php $this->_render(); ?>
</div>
<div class="cmb-td cmb-remove-row">
<button type="button" class="button-secondary cmb-remove-row-button" title="<?php echo esc_attr( $this->_text( 'remove_row_button_title', esc_html__( 'Remove Row', 'cmb2' ) ) ); ?>"><?php echo esc_html( $this->_text( 'remove_row_text', esc_html__( 'Remove', 'cmb2' ) ) ); ?></button>
</div>
</div>
<?php
}
/**
* Generates description markup.
*
* @since 1.0.0
* @param bool $paragraph Paragraph tag or span.
* @param bool $echo Whether to echo description or only return it.
* @param bool $repeat_group Whether to repeat the group.
* @return string Field's description markup.
*/
public function _desc( $paragraph = false, $echo = false, $repeat_group = false ) {
// Prevent description from printing multiple times for repeatable fields
if ( ! $repeat_group && ( $this->field->args( 'repeatable' ) || $this->iterator > 0 ) ) {
return '';
}
$desc = $this->field->args( 'description' );
if ( ! $desc ) {
return;
}
$tag = $paragraph ? 'p' : 'span';
$desc = sprintf( "\n" . '<%1$s class="cmb2-metabox-description">%2$s</%1$s>' . "\n", $tag, $desc );
if ( $echo ) {
echo $desc;
}
return $desc;
}
/**
* Generate field name attribute
*
* @since 1.1.0
* @param string $suffix For multi-part fields
* @return string Name attribute
*/
public function _name( $suffix = '' ) {
return $this->field->args( '_name' ) . ( $this->field->args( 'repeatable' ) ? '[' . $this->iterator . ']' : '' ) . $suffix;
}
/**
* Generate field id attribute
*
* @since 1.1.0
* @param string $suffix For multi-part fields
* @param bool $append_repeatable_iterator Whether to append the iterator attribue if the field is repeatable.
* @return string Id attribute
*/
public function _id( $suffix = '', $append_repeatable_iterator = true ) {
$id = $this->field->id() . $suffix . ( $this->field->args( 'repeatable' ) ? '_' . $this->iterator : '' );
if ( $append_repeatable_iterator && $this->field->args( 'repeatable' ) ) {
$id .= '" data-iterator="' . $this->iterator;
}
return $id;
}
/**
* Handles outputting an 'input' element
*
* @since 1.1.0
* @param array $args Override arguments
* @param string $type Field type
* @return string Form input element
*/
public function input( $args = array(), $type = __FUNCTION__ ) {
return $this->get_new_render_type( 'text', 'CMB2_Type_Text', $args, $type )->render();
}
/**
* Handles outputting an 'textarea' element
*
* @since 1.1.0
* @param array $args Override arguments
* @return string Form textarea element
*/
public function textarea( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Textarea', $args )->render();
}
/**
* Begin Field Types
*/
public function text() {
return $this->input();
}
public function hidden() {
$args = array(
'type' => 'hidden',
'desc' => '',
'class' => 'cmb2-hidden',
);
if ( $this->field->group ) {
$args['data-groupid'] = $this->field->group->id();
$args['data-iterator'] = $this->iterator;
}
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', $args, 'input' )->render();
}
public function text_small() {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array(
'class' => 'cmb2-text-small',
'desc' => $this->_desc(),
), 'input' )->render();
}
public function text_medium() {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array(
'class' => 'cmb2-text-medium',
'desc' => $this->_desc(),
), 'input' )->render();
}
public function text_email() {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array(
'class' => 'cmb2-text-email cmb2-text-medium',
'type' => 'email',
), 'input' )->render();
}
public function text_url() {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array(
'class' => 'cmb2-text-url cmb2-text-medium regular-text',
'value' => $this->field->escaped_value( 'esc_url' ),
), 'input' )->render();
}
public function text_money() {
$input = $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text', array(
'class' => 'cmb2-text-money',
'desc' => $this->_desc(),
), 'input' )->render();
return ( ! $this->field->get_param_callback_result( 'before_field' ) ? '$ ' : ' ' ) . $input;
}
public function textarea_small() {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Textarea', array(
'class' => 'cmb2-textarea-small',
'rows' => 4,
) )->render();
}
public function textarea_code( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Textarea_Code', $args )->render();
}
public function wysiwyg( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Wysiwyg', $args )->render();
}
public function text_date( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Date', $args )->render();
}
// Alias for text_date
public function text_date_timestamp( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Date', $args )->render();
}
public function text_time( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Time', $args )->render();
}
public function text_datetime_timestamp( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Datetime_Timestamp', $args )->render();
}
public function text_datetime_timestamp_timezone( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Text_Datetime_Timestamp_Timezone', $args )->render();
}
public function select_timezone( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Select_Timezone', $args )->render();
}
public function colorpicker( $args = array(), $meta_value = '' ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Colorpicker', $args, $meta_value )->render();
}
public function title( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Title', $args )->render();
}
public function select( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Select', $args )->render();
}
public function taxonomy_select( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Select', $args )->render();
}
public function taxonomy_select_hierarchical( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Select_Hierarchical', $args )->render();
}
public function radio( $args = array(), $type = __FUNCTION__ ) {
return $this->get_new_render_type( $type, 'CMB2_Type_Radio', $args, $type )->render();
}
public function radio_inline( $args = array() ) {
return $this->radio( $args, __FUNCTION__ );
}
public function multicheck( $type = 'checkbox' ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Multicheck', array(), $type )->render();
}
public function multicheck_inline() {
return $this->multicheck( 'multicheck_inline' );
}
public function checkbox( $args = array(), $is_checked = null ) {
// Avoid get_new_render_type since we need a different default for the 3rd argument than ''.
$render_class_name = $this->get_render_type_class( __FUNCTION__, 'CMB2_Type_Checkbox' );
$this->type = new $render_class_name( $this, $args, $is_checked );
return $this->type->render();
}
public function taxonomy_radio( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Radio', $args )->render();
}
public function taxonomy_radio_hierarchical( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Radio_Hierarchical', $args )->render();
}
public function taxonomy_radio_inline( $args = array() ) {
return $this->taxonomy_radio( $args );
}
public function taxonomy_multicheck( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Multicheck', $args )->render();
}
public function taxonomy_multicheck_hierarchical( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Taxonomy_Multicheck_Hierarchical', $args )->render();
}
public function taxonomy_multicheck_inline( $args = array() ) {
return $this->taxonomy_multicheck( $args );
}
public function oembed( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_Oembed', $args )->render();
}
public function file_list( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_File_List', $args )->render();
}
public function file( $args = array() ) {
return $this->get_new_render_type( __FUNCTION__, 'CMB2_Type_File', $args )->render();
}
}

View File

@@ -0,0 +1,698 @@
<?php
/**
* CMB2 Utilities
*
* @since 1.1.0
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Utils {
/**
* The WordPress ABSPATH constant.
*
* @var string
* @since 2.2.3
*/
protected static $ABSPATH = ABSPATH;
/**
* The url which is used to load local resources.
*
* @var string
* @since 2.0.0
*/
protected static $url = '';
/**
* Utility method that attempts to get an attachment's ID by it's url
*
* @since 1.0.0
* @param string $img_url Attachment url.
* @return int|false Attachment ID or false
*/
public static function image_id_from_url( $img_url ) {
$attachment_id = 0;
$dir = wp_upload_dir();
// Is URL in uploads directory?
if ( false === strpos( $img_url, $dir['baseurl'] . '/' ) ) {
return false;
}
$file = basename( $img_url );
$query_args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'fields' => 'ids',
'meta_query' => array(
array(
'value' => $file,
'compare' => 'LIKE',
'key' => '_wp_attachment_metadata',
),
),
);
$query = new WP_Query( $query_args );
if ( $query->have_posts() ) {
foreach ( $query->posts as $post_id ) {
$meta = wp_get_attachment_metadata( $post_id );
$original_file = basename( $meta['file'] );
$cropped_image_files = isset( $meta['sizes'] ) ? wp_list_pluck( $meta['sizes'], 'file' ) : array();
if ( $original_file === $file || in_array( $file, $cropped_image_files ) ) {
$attachment_id = $post_id;
break;
}
}
}
return 0 === $attachment_id ? false : $attachment_id;
}
/**
* Utility method to get a combined list of default and custom registered image sizes
*
* @since 2.2.4
* @link http://core.trac.wordpress.org/ticket/18947
* @global array $_wp_additional_image_sizes
* @return array The image sizes
*/
public static function get_available_image_sizes() {
global $_wp_additional_image_sizes;
$default_image_sizes = array( 'thumbnail', 'medium', 'large' );
foreach ( $default_image_sizes as $size ) {
$image_sizes[ $size ] = array(
'height' => intval( get_option( "{$size}_size_h" ) ),
'width' => intval( get_option( "{$size}_size_w" ) ),
'crop' => get_option( "{$size}_crop" ) ? get_option( "{$size}_crop" ) : false,
);
}
if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) {
$image_sizes = array_merge( $image_sizes, $_wp_additional_image_sizes );
}
return $image_sizes;
}
/**
* Utility method to return the closest named size from an array of values
*
* Based off of WordPress's image_get_intermediate_size()
* If the size matches an existing size then it will be used. If there is no
* direct match, then the nearest image size larger than the specified size
* will be used. If nothing is found, then the function will return false.
* Uses get_available_image_sizes() to get all available sizes.
*
* @since 2.2.4
* @param array|string $size Image size. Accepts an array of width and height (in that order).
* @return false|string Named image size e.g. 'thumbnail'
*/
public static function get_named_size( $size ) {
$data = array();
// Find the best match when '$size' is an array.
if ( is_array( $size ) ) {
$image_sizes = self::get_available_image_sizes();
$candidates = array();
foreach ( $image_sizes as $_size => $data ) {
// If there's an exact match to an existing image size, short circuit.
if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) {
$candidates[ $data['width'] * $data['height'] ] = array( $_size, $data );
break;
}
// If it's not an exact match, consider larger sizes with the same aspect ratio.
if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) {
/**
* To test for varying crops, we constrain the dimensions of the larger image
* to the dimensions of the smaller image and see if they match.
*/
if ( $data['width'] > $size[0] ) {
$constrained_size = wp_constrain_dimensions( $data['width'], $data['height'], $size[0] );
$expected_size = array( $size[0], $size[1] );
} else {
$constrained_size = wp_constrain_dimensions( $size[0], $size[1], $data['width'] );
$expected_size = array( $data['width'], $data['height'] );
}
// If the image dimensions are within 1px of the expected size, we consider it a match.
$matched = ( abs( $constrained_size[0] - $expected_size[0] ) <= 1 && abs( $constrained_size[1] - $expected_size[1] ) <= 1 );
if ( $matched ) {
$candidates[ $data['width'] * $data['height'] ] = array( $_size, $data );
}
}
}
if ( ! empty( $candidates ) ) {
// Sort the array by size if we have more than one candidate.
if ( 1 < count( $candidates ) ) {
ksort( $candidates );
}
$data = array_shift( $candidates );
$data = $data[0];
} elseif ( ! empty( $image_sizes['thumbnail'] ) && $image_sizes['thumbnail']['width'] >= $size[0] && $image_sizes['thumbnail']['width'] >= $size[1] ) {
/*
* When the size requested is smaller than the thumbnail dimensions, we
* fall back to the thumbnail size.
*/
$data = 'thumbnail';
} else {
return false;
}
} elseif ( ! empty( $image_sizes[ $size ] ) ) {
$data = $size;
}// End if.
// If we still don't have a match at this point, return false.
if ( empty( $data ) ) {
return false;
}
return $data;
}
/**
* Utility method that returns time string offset by timezone
*
* @since 1.0.0
* @param string $tzstring Time string.
* @return string Offset time string
*/
public static function timezone_offset( $tzstring ) {
$tz_offset = 0;
if ( ! empty( $tzstring ) && is_string( $tzstring ) ) {
if ( 'UTC' === substr( $tzstring, 0, 3 ) ) {
$tzstring = str_replace( array( ':15', ':30', ':45' ), array( '.25', '.5', '.75' ), $tzstring );
return intval( floatval( substr( $tzstring, 3 ) ) * HOUR_IN_SECONDS );
}
try {
$date_time_zone_selected = new DateTimeZone( $tzstring );
$tz_offset = timezone_offset_get( $date_time_zone_selected, date_create() );
} catch ( Exception $e ) {
self::log_if_debug( __METHOD__, __LINE__, $e->getMessage() );
}
}
return $tz_offset;
}
/**
* Utility method that returns a timezone string representing the default timezone for the site.
*
* Roughly copied from WordPress, as get_option('timezone_string') will return
* an empty string if no value has been set on the options page.
* A timezone string is required by the wp_timezone_choice() used by the
* select_timezone field.
*
* @since 1.0.0
* @return string Timezone string
*/
public static function timezone_string() {
$current_offset = get_option( 'gmt_offset' );
$tzstring = get_option( 'timezone_string' );
// Remove old Etc mappings. Fallback to gmt_offset.
if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) {
$tzstring = '';
}
if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists.
if ( 0 == $current_offset ) {
$tzstring = 'UTC+0';
} elseif ( $current_offset < 0 ) {
$tzstring = 'UTC' . $current_offset;
} else {
$tzstring = 'UTC+' . $current_offset;
}
}
return $tzstring;
}
/**
* Returns a unix timestamp, first checking if value already is a timestamp.
*
* @since 2.0.0
* @param string|int $string Possible timestamp string.
* @return int Time stamp.
*/
public static function make_valid_time_stamp( $string ) {
if ( ! $string ) {
return 0;
}
$valid = self::is_valid_time_stamp( $string );
if ( $valid ) {
$timestamp = (int) $string;
$length = strlen( (string) $timestamp );
$unixlength = strlen( (string) time() );
$diff = $length - $unixlength;
// If value is larger than a unix timestamp, we need to round to the
// nearest unix timestamp (in seconds).
if ( $diff > 0 ) {
$divider = (int) '1' . str_repeat( '0', $diff );
$timestamp = round( $timestamp / $divider );
}
} else {
$timestamp = @strtotime( (string) $string );
}
return $timestamp;
}
/**
* Determine if a value is a valid date.
*
* @since 2.9.1
* @param mixed $date Value to check.
* @return boolean Whether value is a valid date
*/
public static function is_valid_date( $date ) {
return ( is_string( $date ) && @strtotime( $date ) )
|| self::is_valid_time_stamp( $date );
}
/**
* Determine if a value is a valid timestamp
*
* @since 2.0.0
* @param mixed $timestamp Value to check.
* @return boolean Whether value is a valid timestamp
*/
public static function is_valid_time_stamp( $timestamp ) {
return (string) (int) $timestamp === (string) $timestamp
&& $timestamp <= PHP_INT_MAX
&& $timestamp >= ~PHP_INT_MAX;
}
/**
* Checks if a value is 'empty'. Still accepts 0.
*
* @since 2.0.0
* @param mixed $value Value to check.
* @return bool True or false
*/
public static function isempty( $value ) {
return null === $value || '' === $value || false === $value || array() === $value;
}
/**
* Checks if a value is not 'empty'. 0 doesn't count as empty.
*
* @since 2.2.2
* @param mixed $value Value to check.
* @return bool True or false
*/
public static function notempty( $value ) {
return null !== $value && '' !== $value && false !== $value && array() !== $value;
}
/**
* Filters out empty values (not including 0).
*
* @since 2.2.2
* @param mixed $value Value to check.
* @return array True or false.
*/
public static function filter_empty( $value ) {
return array_filter( $value, array( __CLASS__, 'notempty' ) );
}
/**
* Insert a single array item inside another array at a set position
*
* @since 2.0.2
* @param array $array Array to modify. Is passed by reference, and no return is needed. Passed by reference.
* @param array $new New array to insert.
* @param int $position Position in the main array to insert the new array.
*/
public static function array_insert( &$array, $new, $position ) {
$before = array_slice( $array, 0, $position - 1 );
$after = array_diff_key( $array, $before );
$array = array_merge( $before, $new, $after );
}
/**
* Defines the url which is used to load local resources.
* This may need to be filtered for local Window installations.
* If resources do not load, please check the wiki for details.
*
* @since 1.0.1
*
* @param string $path URL path.
* @return string URL to CMB2 resources
*/
public static function url( $path = '' ) {
if ( self::$url ) {
return self::$url . $path;
}
$cmb2_url = self::get_url_from_dir( cmb2_dir() );
/**
* Filter the CMB location url.
*
* @param string $cmb2_url Currently registered url.
*/
self::$url = trailingslashit( apply_filters( 'cmb2_meta_box_url', $cmb2_url, CMB2_VERSION ) );
return self::$url . $path;
}
/**
* Converts a system path to a URL
*
* @since 2.2.2
* @param string $dir Directory path to convert.
* @return string Converted URL.
*/
public static function get_url_from_dir( $dir ) {
$dir = self::normalize_path( $dir );
// Let's test if We are in the plugins or mu-plugins dir.
$test_dir = trailingslashit( $dir ) . 'unneeded.php';
if (
0 === strpos( $test_dir, self::normalize_path( WPMU_PLUGIN_DIR ) )
|| 0 === strpos( $test_dir, self::normalize_path( WP_PLUGIN_DIR ) )
) {
// Ok, then use plugins_url, as it is more reliable.
return trailingslashit( plugins_url( '', $test_dir ) );
}
// Ok, now let's test if we are in the theme dir.
$theme_root = self::normalize_path( get_theme_root() );
if ( 0 === strpos( $dir, $theme_root ) ) {
// Ok, then use get_theme_root_uri.
return set_url_scheme(
trailingslashit(
str_replace(
untrailingslashit( $theme_root ),
untrailingslashit( get_theme_root_uri() ),
$dir
)
)
);
}
// Check to see if it's anywhere in the root directory.
$site_dir = self::get_normalized_abspath();
$site_url = trailingslashit( is_multisite() ? network_site_url() : site_url() );
$url = str_replace(
array( $site_dir, WP_PLUGIN_DIR ),
array( $site_url, WP_PLUGIN_URL ),
$dir
);
return set_url_scheme( $url );
}
/**
* Get the normalized absolute path defined by WordPress.
*
* @since 2.2.6
*
* @return string Normalized absolute path.
*/
protected static function get_normalized_abspath() {
return self::normalize_path( self::$ABSPATH );
}
/**
* `wp_normalize_path` wrapper for back-compat. Normalize a filesystem path.
*
* On windows systems, replaces backslashes with forward slashes
* and forces upper-case drive letters.
* Allows for two leading slashes for Windows network shares, but
* ensures that all other duplicate slashes are reduced to a single.
*
* @since 2.2.0
*
* @param string $path Path to normalize.
* @return string Normalized path.
*/
protected static function normalize_path( $path ) {
if ( function_exists( 'wp_normalize_path' ) ) {
return wp_normalize_path( $path );
}
// Replace newer WP's version of wp_normalize_path.
$path = str_replace( '\\', '/', $path );
$path = preg_replace( '|(?<=.)/+|', '/', $path );
if ( ':' === substr( $path, 1, 1 ) ) {
$path = ucfirst( $path );
}
return $path;
}
/**
* Get timestamp from text date
*
* @since 2.2.0
* @param string $value Date value.
* @param string $date_format Expected date format.
* @return mixed Unix timestamp representing the date.
*/
public static function get_timestamp_from_value( $value, $date_format ) {
$date_object = date_create_from_format( $date_format, $value );
return $date_object ? $date_object->setTime( 0, 0, 0 )->getTimeStamp() : strtotime( $value );
}
/**
* Takes a php date() format string and returns a string formatted to suit for the date/time pickers
* It will work only with the following subset of date() options:
*
* Formats: d, l, j, z, m, F, n, y, and Y.
*
* A slight effort is made to deal with escaped characters.
*
* Other options are ignored, because they would either bring compatibility problems between PHP and JS, or
* bring even more translation troubles.
*
* @since 2.2.0
* @param string $format PHP date format.
* @return string reformatted string
*/
public static function php_to_js_dateformat( $format ) {
// order is relevant here, since the replacement will be done sequentially.
$supported_options = array(
'd' => 'dd', // Day, leading 0.
'j' => 'd', // Day, no 0.
'z' => 'o', // Day of the year, no leading zeroes.
// 'D' => 'D', // Day name short, not sure how it'll work with translations.
'l ' => 'DD ', // Day name full, idem before.
'l, ' => 'DD, ', // Day name full, idem before.
'm' => 'mm', // Month of the year, leading 0.
'n' => 'm', // Month of the year, no leading 0.
// 'M' => 'M', // Month, Short name.
'F ' => 'MM ', // Month, full name.
'F, ' => 'MM, ', // Month, full name.
'y' => 'y', // Year, two digit.
'Y' => 'yy', // Year, full.
'H' => 'HH', // Hour with leading 0 (24 hour).
'G' => 'H', // Hour with no leading 0 (24 hour).
'h' => 'hh', // Hour with leading 0 (12 hour).
'g' => 'h', // Hour with no leading 0 (12 hour).
'i' => 'mm', // Minute with leading 0.
's' => 'ss', // Second with leading 0.
'a' => 'tt', // am/pm.
'A' => 'TT', // AM/PM.
);
foreach ( $supported_options as $php => $js ) {
// replaces every instance of a supported option, but skips escaped characters.
$format = preg_replace( "~(?<!\\\\)$php~", $js, $format );
}
$supported_options = array(
'l' => 'DD', // Day name full, idem before.
'F' => 'MM', // Month, full name.
);
if ( isset( $supported_options[ $format ] ) ) {
$format = $supported_options[ $format ];
}
$format = preg_replace_callback( '~(?:\\\.)+~', array( __CLASS__, 'wrap_escaped_chars' ), $format );
return $format;
}
/**
* Helper function for CMB_Utils::php_to_js_dateformat().
*
* @since 2.2.0
* @param string $value Value to wrap/escape.
* @return string Modified value
*/
public static function wrap_escaped_chars( $value ) {
return '&#39;' . str_replace( '\\', '', $value[0] ) . '&#39;';
}
/**
* Send to debug.log if WP_DEBUG is defined and true
*
* @since 2.2.0
*
* @param string $function Function name.
* @param int $line Line number.
* @param mixed $msg Message to output.
* @param mixed $debug Variable to print_r.
*/
public static function log_if_debug( $function, $line, $msg, $debug = null ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( "In $function, $line:" . print_r( $msg, true ) . ( $debug ? print_r( $debug, true ) : '' ) );
}
}
/**
* Determine a file's extension
*
* @since 1.0.0
* @param string $file File url.
* @return string|false File extension or false
*/
public static function get_file_ext( $file ) {
$parsed = parse_url( $file, PHP_URL_PATH );
return $parsed ? strtolower( pathinfo( $parsed, PATHINFO_EXTENSION ) ) : false;
}
/**
* Get the file name from a url
*
* @since 2.0.0
* @param string $value File url or path.
* @return string File name
*/
public static function get_file_name_from_path( $value ) {
$parts = explode( '/', $value );
return is_array( $parts ) ? end( $parts ) : $value;
}
/**
* Check if WP version is at least $version.
*
* @since 2.2.2
* @param string $version WP version string to compare.
* @return bool Result of comparison check.
*/
public static function wp_at_least( $version ) {
return version_compare( get_bloginfo( 'version' ), $version, '>=' );
}
/**
* Combines attributes into a string for a form element.
*
* @since 1.1.0
* @param array $attrs Attributes to concatenate.
* @param array $attr_exclude Attributes that should NOT be concatenated.
* @return string String of attributes for form element.
*/
public static function concat_attrs( $attrs, $attr_exclude = array() ) {
$attr_exclude[] = 'rendered';
$attr_exclude[] = 'js_dependencies';
$attributes = '';
foreach ( $attrs as $attr => $val ) {
$excluded = in_array( $attr, (array) $attr_exclude, true );
$empty = false === $val && 'value' !== $attr;
if ( ! $excluded && ! $empty ) {
$val = is_array( $val ) ? implode( ',', $val ) : $val;
// if data attribute, use single quote wraps, else double.
$quotes = self::is_data_attribute( $attr ) ? "'" : '"';
$attributes .= sprintf( ' %1$s=%3$s%2$s%3$s', $attr, $val, $quotes );
}
}
return $attributes;
}
/**
* Check if given attribute is a data attribute.
*
* @since 2.2.5
*
* @param string $att HTML attribute.
* @return boolean
*/
public static function is_data_attribute( $att ) {
return 0 === stripos( $att, 'data-' );
}
/**
* Ensures value is an array.
*
* @since 2.2.3
*
* @param mixed $value Value to ensure is array.
* @param array $default Default array. Defaults to empty array.
*
* @return array The array.
*/
public static function ensure_array( $value, $default = array() ) {
if ( empty( $value ) ) {
return $default;
}
if ( is_array( $value ) || is_object( $value ) ) {
return (array) $value;
}
// Not sure anything would be non-scalar that is not an array or object?
if ( ! is_scalar( $value ) ) {
return $default;
}
return (array) $value;
}
/**
* If number is numeric, normalize it with floatval or intval, depending on if decimal is found.
*
* @since 2.2.6
*
* @param mixed $value Value to normalize (if numeric).
* @return mixed Possibly normalized value.
*/
public static function normalize_if_numeric( $value ) {
if ( is_numeric( $value ) ) {
$value = false !== strpos( $value, '.' ) ? floatval( $value ) : intval( $value );
}
return $value;
}
/**
* Generates a 12 character unique hash from a string.
*
* @since 2.4.0
*
* @param string $string String to create a hash from.
*
* @return string
*/
public static function generate_hash( $string ) {
return substr( base_convert( md5( $string ), 16, 32 ), 0, 12 );
}
}

View File

@@ -0,0 +1,427 @@
<?php
/**
* CMB2 Helper Functions
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
/**
* Helper function to provide directory path to CMB2
*
* @since 2.0.0
* @param string $path Path to append.
* @return string Directory with optional path appended
*/
function cmb2_dir( $path = '' ) {
return CMB2_DIR . $path;
}
/**
* Autoloads files with CMB2 classes when needed
*
* @since 1.0.0
* @param string $class_name Name of the class being requested.
*/
function cmb2_autoload_classes( $class_name ) {
if ( 0 !== strpos( $class_name, 'CMB2' ) ) {
return;
}
$path = 'includes';
if ( 'CMB2_Type' === $class_name || 0 === strpos( $class_name, 'CMB2_Type_' ) ) {
$path .= '/types';
}
if ( 'CMB2_REST' === $class_name || 0 === strpos( $class_name, 'CMB2_REST_' ) ) {
$path .= '/rest-api';
}
include_once( cmb2_dir( "$path/{$class_name}.php" ) );
}
/**
* Get instance of the CMB2_Utils class
*
* @since 2.0.0
* @return CMB2_Utils object CMB2 utilities class
*/
function cmb2_utils() {
static $cmb2_utils;
$cmb2_utils = $cmb2_utils ? $cmb2_utils : new CMB2_Utils();
return $cmb2_utils;
}
/**
* Get instance of the CMB2_Ajax class
*
* @since 2.0.0
* @return CMB2_Ajax object CMB2 ajax class
*/
function cmb2_ajax() {
return CMB2_Ajax::get_instance();
}
/**
* Get instance of the CMB2_Option class for the passed metabox ID
*
* @since 2.0.0
*
* @param string $key Option key to fetch.
* @return CMB2_Option object Options class for setting/getting options for metabox
*/
function cmb2_options( $key ) {
return CMB2_Options::get( $key );
}
/**
* Get a cmb oEmbed. Handles oEmbed getting for non-post objects
*
* @since 2.0.0
* @param array $args Arguments. Accepts:
*
* 'url' - URL to retrieve the oEmbed from,
* 'object_id' - $post_id,
* 'object_type' - 'post',
* 'oembed_args' - $embed_args, // array containing 'width', etc
* 'field_id' - false,
* 'cache_key' - false,
* 'wp_error' - true/false, // To return a wp_error object if no embed found.
*
* @return string oEmbed string
*/
function cmb2_get_oembed( $args = array() ) {
$oembed = cmb2_ajax()->get_oembed_no_edit( $args );
// Send back our embed.
if ( $oembed['embed'] && $oembed['embed'] != $oembed['fallback'] ) {
return '<div class="cmb2-oembed">' . $oembed['embed'] . '</div>';
}
$error = sprintf(
/* translators: 1: results for. 2: link to codex.wordpress.org/Embeds */
esc_html__( 'No oEmbed Results Found for %1$s. View more info at %2$s.', 'cmb2' ),
$oembed['fallback'],
'<a href="https://wordpress.org/support/article/embeds/" target="_blank">codex.wordpress.org/Embeds</a>'
);
if ( isset( $args['wp_error'] ) && $args['wp_error'] ) {
return new WP_Error( 'cmb2_get_oembed_result', $error, compact( 'oembed', 'args' ) );
}
// Otherwise, send back error info that no oEmbeds were found.
return '<p class="ui-state-error-text">' . $error . '</p>';
}
/**
* Outputs the return of cmb2_get_oembed.
*
* @since 2.2.2
* @see cmb2_get_oembed
*
* @param array $args oEmbed args.
*/
function cmb2_do_oembed( $args = array() ) {
echo cmb2_get_oembed( $args );
}
add_action( 'cmb2_do_oembed', 'cmb2_do_oembed' );
/**
* A helper function to get an option from a CMB2 options array
*
* @since 1.0.1
* @param string $option_key Option key.
* @param string $field_id Option array field key.
* @param mixed $default Optional default fallback value.
* @return array Options array or specific field
*/
function cmb2_get_option( $option_key, $field_id = '', $default = false ) {
return cmb2_options( $option_key )->get( $field_id, $default );
}
/**
* A helper function to update an option in a CMB2 options array
*
* @since 2.0.0
* @param string $option_key Option key.
* @param string $field_id Option array field key.
* @param mixed $value Value to update data with.
* @param boolean $single Whether data should not be an array.
* @return boolean Success/Failure
*/
function cmb2_update_option( $option_key, $field_id, $value, $single = true ) {
if ( cmb2_options( $option_key )->update( $field_id, $value, false, $single ) ) {
return cmb2_options( $option_key )->set();
}
return false;
}
/**
* Get a CMB2 field object.
*
* @since 1.1.0
* @param array $meta_box Metabox ID or Metabox config array.
* @param array $field_id Field ID or all field arguments.
* @param int|string $object_id Object ID (string for options-page).
* @param string $object_type Type of object being saved. (e.g., post, user, term, comment, or options-page).
* Defaults to metabox object type.
* @return CMB2_Field|null CMB2_Field object unless metabox config cannot be found
*/
function cmb2_get_field( $meta_box, $field_id, $object_id = 0, $object_type = '' ) {
$object_id = $object_id ? $object_id : get_the_ID();
$cmb = $meta_box instanceof CMB2 ? $meta_box : cmb2_get_metabox( $meta_box, $object_id );
if ( ! $cmb ) {
return;
}
$cmb->object_type( $object_type ? $object_type : $cmb->mb_object_type() );
return $cmb->get_field( $field_id );
}
/**
* Get a field's value.
*
* @since 1.1.0
* @param array $meta_box Metabox ID or Metabox config array.
* @param array $field_id Field ID or all field arguments.
* @param int|string $object_id Object ID (string for options-page).
* @param string $object_type Type of object being saved. (e.g., post, user, term, comment, or options-page).
* Defaults to metabox object type.
* @return mixed Maybe escaped value
*/
function cmb2_get_field_value( $meta_box, $field_id, $object_id = 0, $object_type = '' ) {
$field = cmb2_get_field( $meta_box, $field_id, $object_id, $object_type );
return $field->escaped_value();
}
/**
* Because OOP can be scary
*
* @since 2.0.2
* @param array $meta_box_config Metabox Config array.
* @return CMB2 object Instantiated CMB2 object
*/
function new_cmb2_box( array $meta_box_config ) {
return cmb2_get_metabox( $meta_box_config );
}
/**
* Retrieve a CMB2 instance by the metabox ID
*
* @since 2.0.0
* @param mixed $meta_box Metabox ID or Metabox config array.
* @param int|string $object_id Object ID (string for options-page).
* @param string $object_type Type of object being saved.
* (e.g., post, user, term, comment, or options-page).
* Defaults to metabox object type.
* @return CMB2 object
*/
function cmb2_get_metabox( $meta_box, $object_id = 0, $object_type = '' ) {
if ( $meta_box instanceof CMB2 ) {
return $meta_box;
}
if ( is_string( $meta_box ) ) {
$cmb = CMB2_Boxes::get( $meta_box );
} else {
// See if we already have an instance of this metabox.
$cmb = CMB2_Boxes::get( $meta_box['id'] );
// If not, we'll initate a new metabox.
$cmb = $cmb ? $cmb : new CMB2( $meta_box, $object_id );
}
if ( $cmb && $object_id ) {
$cmb->object_id( $object_id );
}
if ( $cmb && $object_type ) {
$cmb->object_type( $object_type );
}
return $cmb;
}
/**
* Returns array of sanitized field values from a metabox (without saving them)
*
* @since 2.0.3
* @param mixed $meta_box Metabox ID or Metabox config array.
* @param array $data_to_sanitize Array of field_id => value data for sanitizing (likely $_POST data).
* @return mixed Array of sanitized values or false if no CMB2 object found
*/
function cmb2_get_metabox_sanitized_values( $meta_box, array $data_to_sanitize ) {
$cmb = cmb2_get_metabox( $meta_box );
return $cmb ? $cmb->get_sanitized_values( $data_to_sanitize ) : false;
}
/**
* Retrieve a metabox form
*
* @since 2.0.0
* @param mixed $meta_box Metabox config array or Metabox ID.
* @param int|string $object_id Object ID (string for options-page).
* @param array $args Optional arguments array.
* @return string CMB2 html form markup
*/
function cmb2_get_metabox_form( $meta_box, $object_id = 0, $args = array() ) {
$object_id = $object_id ? $object_id : get_the_ID();
$cmb = cmb2_get_metabox( $meta_box, $object_id );
ob_start();
// Get cmb form.
cmb2_print_metabox_form( $cmb, $object_id, $args );
$form = ob_get_clean();
return apply_filters( 'cmb2_get_metabox_form', $form, $object_id, $cmb );
}
/**
* Display a metabox form & save it on submission
*
* @since 1.0.0
* @param mixed $meta_box Metabox config array or Metabox ID.
* @param int|string $object_id Object ID (string for options-page).
* @param array $args Optional arguments array.
*/
function cmb2_print_metabox_form( $meta_box, $object_id = 0, $args = array() ) {
$object_id = $object_id ? $object_id : get_the_ID();
$cmb = cmb2_get_metabox( $meta_box, $object_id );
// if passing a metabox ID, and that ID was not found.
if ( ! $cmb ) {
return;
}
$args = wp_parse_args( $args, array(
'form_format' => '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<input type="submit" name="submit-cmb" value="%4$s" class="button-primary"></form>',
'save_button' => esc_html__( 'Save', 'cmb2' ),
'object_type' => $cmb->mb_object_type(),
'cmb_styles' => $cmb->prop( 'cmb_styles' ),
'enqueue_js' => $cmb->prop( 'enqueue_js' ),
) );
// Set object type explicitly (rather than trying to guess from context).
$cmb->object_type( $args['object_type'] );
// Save the metabox if it's been submitted
// check permissions
// @todo more hardening?
if (
$cmb->prop( 'save_fields' )
// check nonce.
&& isset( $_POST['submit-cmb'], $_POST['object_id'], $_POST[ $cmb->nonce() ] )
&& wp_verify_nonce( $_POST[ $cmb->nonce() ], $cmb->nonce() )
&& $object_id && $_POST['object_id'] == $object_id
) {
$cmb->save_fields( $object_id, $cmb->object_type(), $_POST );
}
// Enqueue JS/CSS.
if ( $args['cmb_styles'] ) {
CMB2_Hookup::enqueue_cmb_css();
}
if ( $args['enqueue_js'] ) {
CMB2_Hookup::enqueue_cmb_js();
}
$form_format = apply_filters( 'cmb2_get_metabox_form_format', $args['form_format'], $object_id, $cmb );
$format_parts = explode( '%3$s', $form_format );
// Show cmb form.
printf( $format_parts[0], esc_attr( $cmb->cmb_id ), esc_attr( $object_id ) );
$cmb->show_form();
if ( isset( $format_parts[1] ) && $format_parts[1] ) {
printf( str_ireplace( '%4$s', '%1$s', $format_parts[1] ), esc_attr( $args['save_button'] ) );
}
}
/**
* Display a metabox form (or optionally return it) & save it on submission.
*
* @since 1.0.0
* @param mixed $meta_box Metabox config array or Metabox ID.
* @param int|string $object_id Object ID (string for options-page).
* @param array $args Optional arguments array.
* @return string
*/
function cmb2_metabox_form( $meta_box, $object_id = 0, $args = array() ) {
if ( ! isset( $args['echo'] ) || $args['echo'] ) {
cmb2_print_metabox_form( $meta_box, $object_id, $args );
} else {
return cmb2_get_metabox_form( $meta_box, $object_id, $args );
}
}
if ( ! function_exists( 'date_create_from_format' ) ) {
/**
* Reimplementation of DateTime::createFromFormat for PHP < 5.3. :(
* Borrowed from http://stackoverflow.com/questions/5399075/php-datetimecreatefromformat-in-5-2
*
* @param string $date_format Date format.
* @param string $date_value Date value.
*
* @return DateTime
*/
function date_create_from_format( $date_format, $date_value ) {
$schedule_format = str_replace(
array( 'M', 'Y', 'm', 'd', 'H', 'i', 'a' ),
array( '%b', '%Y', '%m', '%d', '%H', '%M', '%p' ),
$date_format
);
/*
* %Y, %m and %d correspond to date()'s Y m and d.
* %I corresponds to H, %M to i and %p to a
*/
$parsed_time = strptime( $date_value, $schedule_format );
$ymd = sprintf(
/**
* This is a format string that takes six total decimal
* arguments, then left-pads them with zeros to either
* 4 or 2 characters, as needed
*/
'%04d-%02d-%02d %02d:%02d:%02d',
$parsed_time['tm_year'] + 1900, // This will be "111", so we need to add 1900.
$parsed_time['tm_mon'] + 1, // This will be the month minus one, so we add one.
$parsed_time['tm_mday'],
$parsed_time['tm_hour'],
$parsed_time['tm_min'],
$parsed_time['tm_sec']
);
return new DateTime( $ymd );
}
}// End if.
if ( ! function_exists( 'date_timestamp_get' ) ) {
/**
* Returns the Unix timestamp representing the date.
* Reimplementation of DateTime::getTimestamp for PHP < 5.3. :(
*
* @param DateTime $date DateTime instance.
*
* @return int
*/
function date_timestamp_get( DateTime $date ) {
return $date->format( 'U' );
}
}// End if.

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden

View File

@@ -0,0 +1,865 @@
<?php
/**
* Handles hooking CMB2 objects/fields into the WordPres REST API
* which can allow fields to be read and/or updated.
*
* @since 2.2.3
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*
* @property-read read_fields Array of readable field objects.
* @property-read edit_fields Array of editable field objects.
* @property-read rest_read Whether CMB2 object is readable via the rest api.
* @property-read rest_edit Whether CMB2 object is editable via the rest api.
*/
class CMB2_REST extends CMB2_Hookup_Base {
/**
* The current CMB2 REST endpoint version
*
* @var string
* @since 2.2.3
*/
const VERSION = '1';
/**
* The CMB2 REST base namespace (v should always be followed by $version)
*
* @var string
* @since 2.2.3
*/
const NAME_SPACE = 'cmb2/v1';
/**
* @var CMB2 object
* @since 2.2.3
*/
public $cmb;
/**
* @var CMB2_REST[] objects
* @since 2.2.3
*/
protected static $boxes = array();
/**
* @var array Array of cmb ids for each type.
* @since 2.2.3
*/
protected static $type_boxes = array(
'post' => array(),
'user' => array(),
'comment' => array(),
'term' => array(),
);
/**
* Array of readable field objects.
*
* @var CMB2_Field[]
* @since 2.2.3
*/
protected $read_fields = array();
/**
* Array of editable field objects.
*
* @var CMB2_Field[]
* @since 2.2.3
*/
protected $edit_fields = array();
/**
* Whether CMB2 object is readable via the rest api.
*
* @var boolean
*/
protected $rest_read = false;
/**
* Whether CMB2 object is editable via the rest api.
*
* @var boolean
*/
protected $rest_edit = false;
/**
* A functionalized constructor, used for the hookup action callbacks.
*
* @since 2.2.6
*
* @param CMB2 $cmb The CMB2 object to hookup
*
* @return CMB2_Hookup_Base $hookup The hookup object.
*/
public static function maybe_init_and_hookup( CMB2 $cmb ) {
if ( $cmb->prop( 'show_in_rest' ) && function_exists( 'rest_get_server' ) ) {
$hookup = new self( $cmb );
return $hookup->universal_hooks();
}
return false;
}
/**
* Constructor
*
* @since 2.2.3
*
* @param CMB2 $cmb The CMB2 object to be registered for the API.
*/
public function __construct( CMB2 $cmb ) {
$this->cmb = $cmb;
self::$boxes[ $cmb->cmb_id ] = $this;
$show_value = $this->cmb->prop( 'show_in_rest' );
$this->rest_read = self::is_readable( $show_value );
$this->rest_edit = self::is_editable( $show_value );
}
/**
* Hooks to register on frontend and backend.
*
* @since 2.2.3
*
* @return void
*/
public function universal_hooks() {
// hook up the CMB rest endpoint classes
$this->once( 'rest_api_init', array( __CLASS__, 'init_routes' ), 0 );
if ( function_exists( 'register_rest_field' ) ) {
$this->once( 'rest_api_init', array( __CLASS__, 'register_cmb2_fields' ), 50 );
}
$this->declare_read_edit_fields();
add_filter( 'is_protected_meta', array( $this, 'is_protected_meta' ), 10, 3 );
return $this;
}
/**
* Initiate the CMB2 Boxes and Fields routes
*
* @since 2.2.3
*
* @return void
*/
public static function init_routes() {
$wp_rest_server = rest_get_server();
$boxes_controller = new CMB2_REST_Controller_Boxes( $wp_rest_server );
$boxes_controller->register_routes();
$fields_controller = new CMB2_REST_Controller_Fields( $wp_rest_server );
$fields_controller->register_routes();
}
/**
* Loop through REST boxes and call register_rest_field for each object type.
*
* @since 2.2.3
*
* @return void
*/
public static function register_cmb2_fields() {
$alltypes = $taxonomies = array();
foreach ( self::$boxes as $cmb_id => $rest_box ) {
// Hook box specific filter callbacks.
$callback = $rest_box->cmb->prop( 'register_rest_field_cb' );
if ( is_callable( $callback ) ) {
call_user_func( $callback, $rest_box );
continue;
}
$types = array_flip( $rest_box->cmb->box_types( array( 'post' ) ) );
if ( isset( $types['user'] ) ) {
unset( $types['user'] );
self::$type_boxes['user'][ $cmb_id ] = $cmb_id;
}
if ( isset( $types['comment'] ) ) {
unset( $types['comment'] );
self::$type_boxes['comment'][ $cmb_id ] = $cmb_id;
}
if ( isset( $types['term'] ) ) {
unset( $types['term'] );
$taxonomies = array_merge(
$taxonomies,
CMB2_Utils::ensure_array( $rest_box->cmb->prop( 'taxonomies' ) )
);
self::$type_boxes['term'][ $cmb_id ] = $cmb_id;
}
if ( ! empty( $types ) ) {
$alltypes = array_merge( $alltypes, array_flip( $types ) );
self::$type_boxes['post'][ $cmb_id ] = $cmb_id;
}
}
$alltypes = array_unique( $alltypes );
if ( ! empty( $alltypes ) ) {
self::register_rest_field( $alltypes, 'post' );
}
if ( ! empty( self::$type_boxes['user'] ) ) {
self::register_rest_field( 'user', 'user' );
}
if ( ! empty( self::$type_boxes['comment'] ) ) {
self::register_rest_field( 'comment', 'comment' );
}
if ( ! empty( self::$type_boxes['term'] ) ) {
self::register_rest_field( $taxonomies, 'term' );
}
}
/**
* Wrapper for register_rest_field.
*
* @since 2.2.3
*
* @param string|array $object_types Object(s) the field is being registered
* to, "post"|"term"|"comment" etc.
* @param string $object_types Canonical object type for callbacks.
*
* @return void
*/
protected static function register_rest_field( $object_types, $object_type ) {
register_rest_field( $object_types, 'cmb2', array(
'get_callback' => array( __CLASS__, "get_{$object_type}_rest_values" ),
'update_callback' => array( __CLASS__, "update_{$object_type}_rest_values" ),
'schema' => null, // @todo add schema
) );
}
/**
* Setup readable and editable fields.
*
* @since 2.2.3
*
* @return void
*/
protected function declare_read_edit_fields() {
foreach ( $this->cmb->prop( 'fields' ) as $field ) {
$show_in_rest = isset( $field['show_in_rest'] ) ? $field['show_in_rest'] : null;
if ( false === $show_in_rest ) {
continue;
}
if ( $this->can_read( $show_in_rest ) ) {
$this->read_fields[] = $field['id'];
}
if ( $this->can_edit( $show_in_rest ) ) {
$this->edit_fields[] = $field['id'];
}
}
}
/**
* Determines if a field is readable based on it's show_in_rest value
* and the box's show_in_rest value.
*
* @since 2.2.3
*
* @param bool $show_in_rest Field's show_in_rest value. Default null.
*
* @return bool Whether field is readable.
*/
protected function can_read( $show_in_rest ) {
// if 'null', then use default box value.
if ( null === $show_in_rest ) {
return $this->rest_read;
}
// Else check if the value represents readable.
return self::is_readable( $show_in_rest );
}
/**
* Determines if a field is editable based on it's show_in_rest value
* and the box's show_in_rest value.
*
* @since 2.2.3
*
* @param bool $show_in_rest Field's show_in_rest value. Default null.
*
* @return bool Whether field is editable.
*/
protected function can_edit( $show_in_rest ) {
// if 'null', then use default box value.
if ( null === $show_in_rest ) {
return $this->rest_edit;
}
// Else check if the value represents editable.
return self::is_editable( $show_in_rest );
}
/**
* Handler for getting post custom field data.
*
* @since 2.2.3
*
* @param array $object The object data from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return mixed
*/
public static function get_post_rest_values( $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::get_rest_values( $object, $request, $object_type, 'post' );
}
}
/**
* Handler for getting user custom field data.
*
* @since 2.2.3
*
* @param array $object The object data from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return mixed
*/
public static function get_user_rest_values( $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::get_rest_values( $object, $request, $object_type, 'user' );
}
}
/**
* Handler for getting comment custom field data.
*
* @since 2.2.3
*
* @param array $object The object data from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return mixed
*/
public static function get_comment_rest_values( $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::get_rest_values( $object, $request, $object_type, 'comment' );
}
}
/**
* Handler for getting term custom field data.
*
* @since 2.2.3
*
* @param array $object The object data from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return mixed
*/
public static function get_term_rest_values( $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::get_rest_values( $object, $request, $object_type, 'term' );
}
}
/**
* Handler for getting custom field data.
*
* @since 2.2.3
*
* @param array $object The object data from the response
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
* @param string $main_object_type The cmb main object type
*
* @return mixed
*/
protected static function get_rest_values( $object, $request, $object_type, $main_object_type = 'post' ) {
if ( ! isset( $object['id'] ) ) {
return;
}
$values = array();
if ( ! empty( self::$type_boxes[ $main_object_type ] ) ) {
foreach ( self::$type_boxes[ $main_object_type ] as $cmb_id ) {
$rest_box = self::$boxes[ $cmb_id ];
if ( ! $rest_box->cmb->is_box_type( $object_type ) ) {
continue;
}
$result = self::get_box_rest_values( $rest_box, $object['id'], $main_object_type );
if ( ! empty( $result ) ) {
if ( empty( $values[ $cmb_id ] ) ) {
$values[ $cmb_id ] = $result;
} else {
$values[ $cmb_id ] = array_merge( $values[ $cmb_id ], $result );
}
}
}
}
return $values;
}
/**
* Get box rest values.
*
* @since 2.7.0
*
* @param CMB2_REST $rest_box The CMB2_REST object.
* @param integer $object_id The object ID.
* @param string $main_object_type The object type (post, user, term, etc)
*
* @return array Array of box rest values.
*/
public static function get_box_rest_values( $rest_box, $object_id = 0, $main_object_type = 'post' ) {
$rest_box->cmb->object_id( $object_id );
$rest_box->cmb->object_type( $main_object_type );
$values = array();
foreach ( $rest_box->read_fields as $field_id ) {
$field = $rest_box->cmb->get_field( $field_id );
$field->object_id( $object_id );
$field->object_type( $main_object_type );
$values[ $field->id( true ) ] = $field->get_rest_value();
if ( $field->args( 'has_supporting_data' ) ) {
$field = $field->get_supporting_field();
$values[ $field->id( true ) ] = $field->get_rest_value();
}
}
return $values;
}
/**
* Handler for updating post custom field data.
*
* @since 2.2.3
*
* @param mixed $values The value of the field
* @param object $object The object from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return bool|int
*/
public static function update_post_rest_values( $values, $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::update_rest_values( $values, $object, $request, $object_type, 'post' );
}
}
/**
* Handler for updating user custom field data.
*
* @since 2.2.3
*
* @param mixed $values The value of the field
* @param object $object The object from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return bool|int
*/
public static function update_user_rest_values( $values, $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::update_rest_values( $values, $object, $request, $object_type, 'user' );
}
}
/**
* Handler for updating comment custom field data.
*
* @since 2.2.3
*
* @param mixed $values The value of the field
* @param object $object The object from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return bool|int
*/
public static function update_comment_rest_values( $values, $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::update_rest_values( $values, $object, $request, $object_type, 'comment' );
}
}
/**
* Handler for updating term custom field data.
*
* @since 2.2.3
*
* @param mixed $values The value of the field
* @param object $object The object from the response
* @param string $field_name Name of field
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
*
* @return bool|int
*/
public static function update_term_rest_values( $values, $object, $field_name, $request, $object_type ) {
if ( 'cmb2' === $field_name ) {
return self::update_rest_values( $values, $object, $request, $object_type, 'term' );
}
}
/**
* Handler for updating custom field data.
*
* @since 2.2.3
*
* @param mixed $values The value of the field
* @param object $object The object from the response
* @param WP_REST_Request $request Current request
* @param string $object_type The request object type
* @param string $main_object_type The cmb main object type
*
* @return bool|int
*/
protected static function update_rest_values( $values, $object, $request, $object_type, $main_object_type = 'post' ) {
if ( empty( $values ) || ! is_array( $values ) ) {
return;
}
$object_id = self::get_object_id( $object, $main_object_type );
if ( ! $object_id ) {
return;
}
$updated = array();
if ( ! empty( self::$type_boxes[ $main_object_type ] ) ) {
foreach ( self::$type_boxes[ $main_object_type ] as $cmb_id ) {
$result = self::santize_box_rest_values( $values, self::$boxes[ $cmb_id ], $object_id, $main_object_type );
if ( ! empty( $result ) ) {
$updated[ $cmb_id ] = $result;
}
}
}
return $updated;
}
/**
* Updates box rest values.
*
* @since 2.7.0
*
* @param array $values Array of values.
* @param CMB2_REST $rest_box The CMB2_REST object.
* @param integer $object_id The object ID.
* @param string $main_object_type The object type (post, user, term, etc)
*
* @return mixed|bool Array of updated statuses if successful.
*/
public static function santize_box_rest_values( $values, $rest_box, $object_id = 0, $main_object_type = 'post' ) {
if ( ! array_key_exists( $rest_box->cmb->cmb_id, $values ) ) {
return false;
}
$rest_box->cmb->object_id( $object_id );
$rest_box->cmb->object_type( $main_object_type );
return $rest_box->sanitize_box_values( $values );
}
/**
* Loop through box fields and sanitize the values.
*
* @since 2.2.o
*
* @param array $values Array of values being provided.
* @return array Array of updated/sanitized values.
*/
public function sanitize_box_values( array $values ) {
$updated = array();
$this->cmb->pre_process();
foreach ( $this->edit_fields as $field_id ) {
$updated[ $field_id ] = $this->sanitize_field_value( $values, $field_id );
}
$this->cmb->after_save();
return $updated;
}
/**
* Handles returning a sanitized field value.
*
* @since 2.2.3
*
* @param array $values Array of values being provided.
* @param string $field_id The id of the field to update.
*
* @return mixed The results of saving/sanitizing a field value.
*/
protected function sanitize_field_value( array $values, $field_id ) {
if ( ! array_key_exists( $field_id, $values[ $this->cmb->cmb_id ] ) ) {
return;
}
$field = $this->cmb->get_field( $field_id );
if ( 'title' == $field->type() ) {
return;
}
$field->object_id( $this->cmb->object_id() );
$field->object_type( $this->cmb->object_type() );
if ( 'group' == $field->type() ) {
return $this->sanitize_group_value( $values, $field );
}
return $field->save_field( $values[ $this->cmb->cmb_id ][ $field_id ] );
}
/**
* Handles returning a sanitized group field value.
*
* @since 2.2.3
*
* @param array $values Array of values being provided.
* @param CMB2_Field $field CMB2_Field object.
*
* @return mixed The results of saving/sanitizing the group field value.
*/
protected function sanitize_group_value( array $values, CMB2_Field $field ) {
$fields = $field->fields();
if ( empty( $fields ) ) {
return;
}
$this->cmb->data_to_save[ $field->_id( '', false ) ] = $values[ $this->cmb->cmb_id ][ $field->_id( '', false ) ];
return $this->cmb->save_group_field( $field );
}
/**
* Filter whether a meta key is protected.
*
* @since 2.2.3
*
* @param bool $protected Whether the key is protected. Default false.
* @param string $meta_key Meta key.
* @param string $meta_type Meta type.
*/
public function is_protected_meta( $protected, $meta_key, $meta_type ) {
if ( $this->field_can_edit( $meta_key ) ) {
return false;
}
return $protected;
}
/**
* Get the object ID for the given object/type.
*
* @since 2.2.3
*
* @param mixed $object The object to get the ID for.
* @param string $object_type The object type we are looking for.
*
* @return int The object ID if found.
*/
public static function get_object_id( $object, $object_type = 'post' ) {
switch ( $object_type ) {
case 'user':
case 'post':
if ( isset( $object->ID ) ) {
return intval( $object->ID );
}
case 'comment':
if ( isset( $object->comment_ID ) ) {
return intval( $object->comment_ID );
}
case 'term':
if ( is_array( $object ) && isset( $object['term_id'] ) ) {
return intval( $object['term_id'] );
} elseif ( isset( $object->term_id ) ) {
return intval( $object->term_id );
}
}
return 0;
}
/**
* Checks if a given field can be read.
*
* @since 2.2.3
*
* @param string|CMB2_Field $field_id Field ID or CMB2_Field object.
* @param boolean $return_object Whether to return the Field object.
*
* @return mixed False if field can't be read or true|CMB2_Field object.
*/
public function field_can_read( $field_id, $return_object = false ) {
return $this->field_can( 'read_fields', $field_id, $return_object );
}
/**
* Checks if a given field can be edited.
*
* @since 2.2.3
*
* @param string|CMB2_Field $field_id Field ID or CMB2_Field object.
* @param boolean $return_object Whether to return the Field object.
*
* @return mixed False if field can't be edited or true|CMB2_Field object.
*/
public function field_can_edit( $field_id, $return_object = false ) {
return $this->field_can( 'edit_fields', $field_id, $return_object );
}
/**
* Checks if a given field can be read or edited.
*
* @since 2.2.3
*
* @param string $type Whether we are checking for read or edit fields.
* @param string|CMB2_Field $field_id Field ID or CMB2_Field object.
* @param boolean $return_object Whether to return the Field object.
*
* @return mixed False if field can't be read or edited or true|CMB2_Field object.
*/
protected function field_can( $type, $field_id, $return_object = false ) {
if ( ! in_array( $field_id instanceof CMB2_Field ? $field_id->id() : $field_id, $this->{$type}, true ) ) {
return false;
}
return $return_object ? $this->cmb->get_field( $field_id ) : true;
}
/**
* Get a CMB2_REST instance object from the registry by a CMB2 id.
*
* @since 2.2.3
*
* @param string $cmb_id CMB2 config id
*
* @return CMB2_REST|false The CMB2_REST object or false.
*/
public static function get_rest_box( $cmb_id ) {
return isset( self::$boxes[ $cmb_id ] ) ? self::$boxes[ $cmb_id ] : false;
}
/**
* Remove a CMB2_REST instance object from the registry.
*
* @since 2.2.3
*
* @param string $cmb_id A CMB2 instance id.
*/
public static function remove( $cmb_id ) {
if ( array_key_exists( $cmb_id, self::$boxes ) ) {
unset( self::$boxes[ $cmb_id ] );
}
}
/**
* Retrieve all CMB2_REST instances from the registry.
*
* @since 2.2.3
* @return CMB2[] Array of all registered CMB2_REST instances.
*/
public static function get_all() {
return self::$boxes;
}
/**
* Checks if given value is readable.
*
* Value is considered readable if it is not empty and if it does not match the editable blacklist.
*
* @since 2.2.3
*
* @param mixed $value Value to check.
*
* @return boolean Whether value is considered readable.
*/
public static function is_readable( $value ) {
return ! empty( $value ) && ! in_array( $value, array(
WP_REST_Server::CREATABLE,
WP_REST_Server::EDITABLE,
WP_REST_Server::DELETABLE,
), true );
}
/**
* Checks if given value is editable.
*
* Value is considered editable if matches the editable whitelist.
*
* @since 2.2.3
*
* @param mixed $value Value to check.
*
* @return boolean Whether value is considered editable.
*/
public static function is_editable( $value ) {
return in_array( $value, array(
WP_REST_Server::EDITABLE,
WP_REST_Server::ALLMETHODS,
), true );
}
/**
* Magic getter for our object.
*
* @param string $field
* @throws Exception Throws an exception if the field is invalid.
*
* @return mixed
*/
public function __get( $field ) {
switch ( $field ) {
case 'read_fields':
case 'edit_fields':
case 'rest_read':
case 'rest_edit':
return $this->{$field};
default:
throw new Exception( 'Invalid ' . __CLASS__ . ' property: ' . $field );
}
}
}

View File

@@ -0,0 +1,448 @@
<?php
if ( ! class_exists( 'WP_REST_Controller' ) ) {
// Shim the WP_REST_Controller class if wp-api plugin not installed, & not in core.
require_once cmb2_dir( 'includes/shim/WP_REST_Controller.php' );
}
/**
* Creates CMB2 objects/fields endpoint for WordPres REST API.
* Allows access to fields registered to a specific post type and more.
*
* @todo Add better documentation.
* @todo Research proper schema.
*
* @since 2.2.3
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
abstract class CMB2_REST_Controller extends WP_REST_Controller {
/**
* The namespace of this controller's route.
*
* @var string
*/
protected $namespace = CMB2_REST::NAME_SPACE;
/**
* The base of this controller's route.
*
* @var string
*/
protected $rest_base;
/**
* The current request object
*
* @var WP_REST_Request $request
* @since 2.2.3
*/
public $request;
/**
* The current server object
*
* @var WP_REST_Server $server
* @since 2.2.3
*/
public $server;
/**
* Box object id
*
* @var mixed
* @since 2.2.3
*/
public $object_id = null;
/**
* Box object type
*
* @var string
* @since 2.2.3
*/
public $object_type = '';
/**
* CMB2 Instance
*
* @var CMB2_REST
*/
protected $rest_box;
/**
* CMB2_Field Instance
*
* @var CMB2_Field
*/
protected $field;
/**
* The initial route
*
* @var string
* @since 2.2.3
*/
protected static $route = '';
/**
* Defines which endpoint the initial request is.
*
* @var string $request_type
* @since 2.2.3
*/
protected static $request_type = '';
/**
* Constructor
*
* @since 2.2.3
*/
public function __construct( WP_REST_Server $wp_rest_server ) {
$this->server = $wp_rest_server;
}
/**
* A wrapper for `apply_filters` which checks for box/field properties to hook to the filter.
*
* Checks if a CMB object callback property exists, and if it does,
* hook it to the permissions filter.
*
* @since 2.2.3
*
* @param string $filter The name of the filter to apply.
* @param bool $default_access The default access for this request.
*
* @return void
*/
public function maybe_hook_callback_and_apply_filters( $filter, $default_access ) {
if ( ! $this->rest_box && $this->request->get_param( 'cmb_id' ) ) {
$this->rest_box = CMB2_REST::get_rest_box( $this->request->get_param( 'cmb_id' ) );
}
$default_access = $this->maybe_hook_registered_callback( $filter, $default_access );
/**
* Apply the permissions check filter.
*
* @since 2.2.3
*
* @param bool $default_access Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
$default_access = apply_filters( $filter, $default_access, $this );
$this->maybe_unhook_registered_callback( $filter );
return $default_access;
}
/**
* Checks if the CMB2 box has any registered callback parameters for the given filter.
*
* The registered handlers will have a property name which matches the filter, except:
* - The 'cmb2_api' prefix will be removed
* - A '_cb' suffix will be added (to stay inline with other '*_cb' parameters).
*
* @since 2.2.3
*
* @param string $filter The filter name.
* @param bool $default_val The default filter value.
*
* @return bool The possibly-modified filter value (if the '*_cb' param is non-callable).
*/
public function maybe_hook_registered_callback( $filter, $default_val ) {
if ( ! $this->rest_box || is_wp_error( $this->rest_box ) ) {
return $default_val;
}
// Hook box specific filter callbacks.
$val = $this->rest_box->cmb->maybe_hook_parameter( $filter, $default_val );
if ( null !== $val ) {
$default_val = $val;
}
return $default_val;
}
/**
* Unhooks any CMB2 box registered callback parameters for the given filter.
*
* @since 2.2.3
*
* @param string $filter The filter name.
*
* @return void
*/
public function maybe_unhook_registered_callback( $filter ) {
if ( ! $this->rest_box || is_wp_error( $this->rest_box ) ) {
return;
}
// Unhook box specific filter callbacks.
$this->rest_box->cmb->maybe_hook_parameter( $filter, null, 'remove_filter' );
}
/**
* Prepare a CMB2 object for serialization
*
* @since 2.2.3
*
* @param mixed $data
* @return array $data
*/
public function prepare_item( $data ) {
return $this->prepare_item_for_response( $data, $this->request );
}
/**
* Output buffers a callback and returns the results.
*
* @since 2.2.3
*
* @param mixed $cb Callable function/method.
* @return mixed Results of output buffer after calling function/method.
*/
public function get_cb_results( $cb ) {
$args = func_get_args();
array_shift( $args ); // ignore $cb
ob_start();
call_user_func_array( $cb, $args );
return ob_get_clean();
}
/**
* Prepare the CMB2 item for the REST response.
*
* @since 2.2.3
*
* @param mixed $item WordPress representation of the item.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response $response
*/
public function prepare_item_for_response( $data, $request = null ) {
$data = $this->filter_response_by_context( $data, $this->request['context'] );
/**
* Filter the prepared CMB2 item response.
*
* @since 2.2.3
*
* @param mixed $data Prepared data
* @param object $request The WP_REST_Request object
* @param object $cmb2_endpoints This endpoints object
*/
return apply_filters( 'cmb2_rest_prepare', rest_ensure_response( $data ), $this->request, $this );
}
/**
* Initiates the request property and the rest_box property if box is readable.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Request object.
* @param string $request_type A description of the type of request being made.
*
* @return void
*/
protected function initiate_rest_read_box( $request, $request_type ) {
$this->initiate_rest_box( $request, $request_type );
if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_read ) {
$this->rest_box = new WP_Error( 'cmb2_rest_no_read_error', __( 'This box does not have read permissions.', 'cmb2' ), array(
'status' => 403,
) );
}
}
/**
* Initiates the request property and the rest_box property if box is writeable.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Request object.
* @param string $request_type A description of the type of request being made.
*
* @return void
*/
protected function initiate_rest_edit_box( $request, $request_type ) {
$this->initiate_rest_box( $request, $request_type );
if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_edit ) {
$this->rest_box = new WP_Error( 'cmb2_rest_no_write_error', __( 'This box does not have write permissions.', 'cmb2' ), array(
'status' => 403,
) );
}
}
/**
* Initiates the request property and the rest_box property.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Request object.
* @param string $request_type A description of the type of request being made.
*
* @return void
*/
protected function initiate_rest_box( $request, $request_type ) {
$this->initiate_request( $request, $request_type );
$this->rest_box = CMB2_REST::get_rest_box( $this->request->get_param( 'cmb_id' ) );
if ( ! $this->rest_box ) {
$this->rest_box = new WP_Error( 'cmb2_rest_box_not_found_error', __( 'No box found by that id. A box needs to be registered with the "show_in_rest" parameter configured.', 'cmb2' ), array(
'status' => 403,
) );
} else {
if ( isset( $this->request['object_id'] ) ) {
$this->rest_box->cmb->object_id( sanitize_text_field( $this->request['object_id'] ) );
}
if ( isset( $this->request['object_type'] ) ) {
$this->rest_box->cmb->object_type( sanitize_text_field( $this->request['object_type'] ) );
}
}
}
/**
* Initiates the request property and sets up the initial static properties.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Request object.
* @param string $request_type A description of the type of request being made.
*
* @return void
*/
public function initiate_request( $request, $request_type ) {
$this->request = $request;
if ( ! isset( $this->request['context'] ) || empty( $this->request['context'] ) ) {
$this->request['context'] = 'view';
}
if ( ! self::$request_type ) {
self::$request_type = $request_type;
}
if ( ! self::$route ) {
self::$route = $this->request->get_route();
}
}
/**
* Useful when getting `_embed`-ed items
*
* @since 2.2.3
*
* @return string Initial requested type.
*/
public static function get_intial_request_type() {
return self::$request_type;
}
/**
* Useful when getting `_embed`-ed items
*
* @since 2.2.3
*
* @return string Initial requested route.
*/
public static function get_intial_route() {
return self::$route;
}
/**
* Get CMB2 fields schema, conforming to JSON Schema
*
* @since 2.2.3
*
* @return array
*/
public function get_item_schema() {
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'CMB2',
'type' => 'object',
'properties' => array(
'description' => array(
'description' => __( 'A human-readable description of the object.', 'cmb2' ),
'type' => 'string',
'context' => array(
'view',
),
),
'name' => array(
'description' => __( 'The id for the object.', 'cmb2' ),
'type' => 'integer',
'context' => array(
'view',
),
),
'name' => array(
'description' => __( 'The title for the object.', 'cmb2' ),
'type' => 'string',
'context' => array(
'view',
),
),
),
);
return $this->add_additional_fields_schema( $schema );
}
/**
* Return an array of contextual links for endpoint/object
*
* @link http://v2.wp-api.org/extending/linking/
* @link http://www.iana.org/assignments/link-relations/link-relations.xhtml
*
* @since 2.2.3
*
* @param mixed $object Object to build links from.
*
* @return array Array of links
*/
abstract protected function prepare_links( $object );
/**
* Get whitelisted query strings from URL for appending to link URLS.
*
* @since 2.2.3
*
* @return string URL query stringl
*/
public function get_query_string() {
$defaults = array(
'object_id' => 0,
'object_type' => '',
'_rendered' => '',
// '_embed' => '',
);
$query_string = '';
foreach ( $defaults as $key => $value ) {
if ( isset( $this->request[ $key ] ) ) {
$query_string .= $query_string ? '&' : '?';
$query_string .= $key;
if ( $value = sanitize_text_field( $this->request[ $key ] ) ) {
$query_string .= '=' . $value;
}
}
}
return $query_string;
}
}

View File

@@ -0,0 +1,270 @@
<?php
/**
* CMB2 objects/boxes endpoint for WordPres REST API.
* Allows access to boxes configuration data.
*
* @todo Add better documentation.
* @todo Research proper schema.
*
* @since 2.2.3
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_REST_Controller_Boxes extends CMB2_REST_Controller {
/**
* The base of this controller's route.
*
* @var string
*/
protected $rest_base = 'boxes';
/**
* The combined $namespace and $rest_base for these routes.
*
* @var string
*/
protected $namespace_base = '';
/**
* Constructor
*
* @since 2.2.3
*/
public function __construct( WP_REST_Server $wp_rest_server ) {
$this->namespace_base = $this->namespace . '/' . $this->rest_base;
parent::__construct( $wp_rest_server );
}
/**
* Register the routes for the objects of the controller.
*
* @since 2.2.3
*/
public function register_routes() {
$args = array(
'_embed' => array(
'description' => __( 'Includes the registered fields for the box in the response.', 'cmb2' ),
),
);
// @todo determine what belongs in the context param.
// $args['context'] = $this->get_context_param();
// $args['context']['required'] = false;
// $args['context']['default'] = 'view';
// $args['context']['enum'] = array( 'view', 'embed' );
// Returns all boxes data.
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
array(
'methods' => WP_REST_Server::READABLE,
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'callback' => array( $this, 'get_items' ),
'args' => $args,
),
'schema' => array( $this, 'get_item_schema' ),
) );
$args['_rendered'] = array(
'description' => __( 'Includes the fully rendered attributes, \'form_open\', \'form_close\', as well as the enqueued \'js_dependencies\' script handles, and \'css_dependencies\' stylesheet handles.', 'cmb2' ),
);
// Returns specific box's data.
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)', array(
array(
'methods' => WP_REST_Server::READABLE,
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'callback' => array( $this, 'get_item' ),
'args' => $args,
),
'schema' => array( $this, 'get_item_schema' ),
) );
}
/**
* Check if a given request has access to get boxes.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
$this->initiate_request( $request, __FUNCTION__ );
/**
* By default, no special permissions needed.
*
* @since 2.2.3
*
* @param bool $can_access Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return apply_filters( 'cmb2_api_get_boxes_permissions_check', true, $this );
}
/**
* Get all public CMB2 boxes.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items( $request ) {
$this->initiate_request( $request, 'boxes_read' );
$boxes = CMB2_REST::get_all();
if ( empty( $boxes ) ) {
return new WP_Error( 'cmb2_rest_no_boxes', __( 'No boxes found.', 'cmb2' ), array(
'status' => 403,
) );
}
$boxes_data = array();
// Loop and prepare boxes data.
foreach ( $boxes as $this->rest_box ) {
if (
// Make sure this box can be read
$this->rest_box->rest_read
// And make sure current user can view this box.
&& $this->get_item_permissions_check_filter( $this->request )
) {
$boxes_data[] = $this->server->response_to_data(
$this->get_rest_box(),
isset( $this->request['_embed'] )
);
}
}
return $this->prepare_item( $boxes_data );
}
/**
* Check if a given request has access to a box.
* By default, no special permissions needed, but filtering return value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function get_item_permissions_check( $request ) {
$this->initiate_rest_read_box( $request, 'box_read' );
return $this->get_item_permissions_check_filter();
}
/**
* Check by filter if a given request has access to a box.
* By default, no special permissions needed, but filtering return value.
*
* @since 2.2.3
*
* @param bool $can_access Whether the current request has access to view the box by default.
* @return WP_Error|boolean
*/
public function get_item_permissions_check_filter( $can_access = true ) {
/**
* By default, no special permissions needed.
*
* @since 2.2.3
*
* @param bool $can_access Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_box_permissions_check', $can_access );
}
/**
* Get one CMB2 box from the collection.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_item( $request ) {
$this->initiate_rest_read_box( $request, 'box_read' );
if ( is_wp_error( $this->rest_box ) ) {
return $this->rest_box;
}
return $this->prepare_item( $this->get_rest_box() );
}
/**
* Get a CMB2 box prepared for REST
*
* @since 2.2.3
*
* @return array
*/
public function get_rest_box() {
$cmb = $this->rest_box->cmb;
$boxes_data = $cmb->meta_box;
if ( isset( $this->request['_rendered'] ) && $this->namespace_base !== ltrim( CMB2_REST_Controller::get_intial_route(), '/' ) ) {
$boxes_data['form_open'] = $this->get_cb_results( array( $cmb, 'render_form_open' ) );
$boxes_data['form_close'] = $this->get_cb_results( array( $cmb, 'render_form_close' ) );
global $wp_scripts, $wp_styles;
$before_css = $wp_styles->queue;
$before_js = $wp_scripts->queue;
CMB2_JS::enqueue();
$boxes_data['js_dependencies'] = array_values( array_diff( $wp_scripts->queue, $before_js ) );
$boxes_data['css_dependencies'] = array_values( array_diff( $wp_styles->queue, $before_css ) );
}
// TODO: look into 'embed' parameter.
// http://demo.wp-api.org/wp-json/wp/v2/posts?_embed
unset( $boxes_data['fields'] );
// Handle callable properties.
unset( $boxes_data['show_on_cb'] );
$response = rest_ensure_response( $boxes_data );
$response->add_links( $this->prepare_links( $cmb ) );
return $response;
}
/**
* Return an array of contextual links for box/boxes.
*
* @since 2.2.3
*
* @param CMB2_REST $cmb CMB2_REST object to build links from.
*
* @return array Array of links
*/
protected function prepare_links( $cmb ) {
$boxbase = $this->namespace_base . '/' . $cmb->cmb_id;
$query_string = $this->get_query_string();
return array(
// Standard Link Relations -- http://v2.wp-api.org/extending/linking/
'self' => array(
'href' => rest_url( $boxbase . $query_string ),
),
'collection' => array(
'href' => rest_url( $this->namespace_base . $query_string ),
),
// Custom Link Relations -- http://v2.wp-api.org/extending/linking/
// TODO URL should document relationship.
'https://cmb2.io/fields' => array(
'href' => rest_url( trailingslashit( $boxbase ) . 'fields' . $query_string ),
'embeddable' => true,
),
);
}
}

View File

@@ -0,0 +1,534 @@
<?php
/**
* CMB2 objects/fields endpoint for WordPres REST API.
* Allows access to fields registered to a specific box.
*
* @todo Add better documentation.
* @todo Research proper schema.
*
* @since 2.2.3
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_REST_Controller_Fields extends CMB2_REST_Controller_Boxes {
/**
* Register the routes for the objects of the controller.
*
* @since 2.2.3
*/
public function register_routes() {
$args = array(
'_embed' => array(
'description' => __( 'Includes the box object which the fields are registered to in the response.', 'cmb2' ),
),
'_rendered' => array(
'description' => __( 'When the \'_rendered\' argument is passed, the renderable field attributes will be returned fully rendered. By default, the names of the callback handers for the renderable attributes will be returned.', 'cmb2' ),
),
'object_id' => array(
'description' => __( 'To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2' ),
),
'object_type' => array(
'description' => __( 'To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2' ),
),
);
// Returns specific box's fields.
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/', array(
array(
'methods' => WP_REST_Server::READABLE,
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'callback' => array( $this, 'get_items' ),
'args' => $args,
),
'schema' => array( $this, 'get_item_schema' ),
) );
$delete_args = $args;
$delete_args['object_id']['required'] = true;
$delete_args['object_type']['required'] = true;
// Returns specific field data.
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/(?P<field_id>[\w-]+)', array(
array(
'methods' => WP_REST_Server::READABLE,
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'callback' => array( $this, 'get_item' ),
'args' => $args,
),
array(
'methods' => WP_REST_Server::EDITABLE,
'permission_callback' => array( $this, 'update_item_permissions_check' ),
'callback' => array( $this, 'update_item' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
'args' => $args,
),
array(
'methods' => WP_REST_Server::DELETABLE,
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
'callback' => array( $this, 'delete_item' ),
'args' => $delete_args,
),
'schema' => array( $this, 'get_item_schema' ),
) );
}
/**
* Check if a given request has access to get fields.
* By default, no special permissions needed, but filtering return value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
$this->initiate_rest_read_box( $request, 'fields_read' );
$can_access = true;
/**
* By default, no special permissions needed.
*
* @since 2.2.3
*
* @param bool $can_access Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_fields_permissions_check', $can_access );
}
/**
* Get all public CMB2 box fields.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items( $request ) {
if ( ! $this->rest_box ) {
$this->initiate_rest_read_box( $request, 'fields_read' );
}
if ( is_wp_error( $this->rest_box ) ) {
return $this->rest_box;
}
$fields = array();
foreach ( $this->rest_box->cmb->prop( 'fields', array() ) as $field ) {
// Make sure this field can be read.
$this->field = $this->rest_box->field_can_read( $field['id'], true );
// And make sure current user can view this box.
if ( $this->field && $this->get_item_permissions_check_filter() ) {
$fields[ $field['id'] ] = $this->server->response_to_data(
$this->prepare_field_response(),
isset( $this->request['_embed'] )
);
}
}
return $this->prepare_item( $fields );
}
/**
* Check if a given request has access to a field.
* By default, no special permissions needed, but filtering return value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function get_item_permissions_check( $request ) {
$this->initiate_rest_read_box( $request, 'field_read' );
if ( ! is_wp_error( $this->rest_box ) ) {
$this->field = $this->rest_box->field_can_read( $this->request->get_param( 'field_id' ), true );
}
return $this->get_item_permissions_check_filter();
}
/**
* Check by filter if a given request has access to a field.
* By default, no special permissions needed, but filtering return value.
*
* @since 2.2.3
*
* @param bool $can_access Whether the current request has access to view the field by default.
* @return WP_Error|boolean
*/
public function get_item_permissions_check_filter( $can_access = true ) {
/**
* By default, no special permissions needed.
*
* @since 2.2.3
*
* @param bool $can_access Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_field_permissions_check', $can_access );
}
/**
* Get one CMB2 field from the collection.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_item( $request ) {
$this->initiate_rest_read_box( $request, 'field_read' );
if ( is_wp_error( $this->rest_box ) ) {
return $this->rest_box;
}
return $this->prepare_read_field( $this->request->get_param( 'field_id' ) );
}
/**
* Check if a given request has access to update a field value.
* By default, requires 'edit_others_posts' capability, but filtering return value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function update_item_permissions_check( $request ) {
$this->initiate_rest_read_box( $request, 'field_value_update' );
if ( ! is_wp_error( $this->rest_box ) ) {
$this->field = $this->rest_box->field_can_edit( $this->request->get_param( 'field_id' ), true );
}
$can_update = current_user_can( 'edit_others_posts' );
/**
* By default, 'edit_others_posts' is required capability.
*
* @since 2.2.3
*
* @param bool $can_update Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_update_field_value_permissions_check', $can_update );
}
/**
* Update CMB2 field value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function update_item( $request ) {
$this->initiate_rest_read_box( $request, 'field_value_update' );
if ( ! $this->request['value'] ) {
return new WP_Error( 'cmb2_rest_update_field_error', __( 'CMB2 Field value cannot be updated without the value parameter specified.', 'cmb2' ), array(
'status' => 400,
) );
}
return $this->modify_field_value( 'updated' );
}
/**
* Check if a given request has access to delete a field value.
* By default, requires 'delete_others_posts' capability, but filtering return value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function delete_item_permissions_check( $request ) {
$this->initiate_rest_read_box( $request, 'field_value_delete' );
if ( ! is_wp_error( $this->rest_box ) ) {
$this->field = $this->rest_box->field_can_edit( $this->request->get_param( 'field_id' ), true );
}
$can_delete = current_user_can( 'delete_others_posts' );
/**
* By default, 'delete_others_posts' is required capability.
*
* @since 2.2.3
*
* @param bool $can_delete Whether this CMB2 endpoint can be accessed.
* @param object $controller This CMB2_REST_Controller object.
*/
return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_delete_field_value_permissions_check', $can_delete );
}
/**
* Delete CMB2 field value.
*
* @since 2.2.3
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function delete_item( $request ) {
$this->initiate_rest_read_box( $request, 'field_value_delete' );
return $this->modify_field_value( 'deleted' );
}
/**
* Modify CMB2 field value.
*
* @since 2.2.3
*
* @param string $activity The modification activity (updated or deleted).
* @return WP_Error|WP_REST_Response
*/
public function modify_field_value( $activity ) {
if ( ! $this->request['object_id'] || ! $this->request['object_type'] ) {
return new WP_Error( 'cmb2_rest_modify_field_value_error', __( 'CMB2 Field value cannot be modified without the object_id and object_type parameters specified.', 'cmb2' ), array(
'status' => 400,
) );
}
if ( is_wp_error( $this->rest_box ) ) {
return $this->rest_box;
}
$this->field = $this->rest_box->field_can_edit(
$this->field ? $this->field : $this->request->get_param( 'field_id' ),
true
);
if ( ! $this->field ) {
return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array(
'status' => 403,
) );
}
$this->field->args[ "value_{$activity}" ] = (bool) 'deleted' === $activity
? $this->field->remove_data()
: $this->field->save_field( $this->request['value'] );
// If options page, save the $activity options
if ( 'options-page' == $this->request['object_type'] ) {
$this->field->args[ "value_{$activity}" ] = cmb2_options( $this->request['object_id'] )->set();
}
return $this->prepare_read_field( $this->field );
}
/**
* Get a response object for a specific field ID.
*
* @since 2.2.3
*
* @param string\CMB2_Field Field id or Field object.
* @return WP_Error|WP_REST_Response
*/
public function prepare_read_field( $field ) {
$this->field = $this->rest_box->field_can_read( $field, true );
if ( ! $this->field ) {
return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array(
'status' => 403,
) );
}
return $this->prepare_item( $this->prepare_field_response() );
}
/**
* Get a specific field response.
*
* @since 2.2.3
*
* @param CMB2_Field Field object.
* @return array Response array.
*/
public function prepare_field_response() {
$field_data = $this->prepare_field_data( $this->field );
$response = rest_ensure_response( $field_data );
$response->add_links( $this->prepare_links( $this->field ) );
return $response;
}
/**
* Prepare the field data array for JSON.
*
* @since 2.2.3
*
* @param CMB2_Field $field field object.
*
* @return array Array of field data.
*/
protected function prepare_field_data( CMB2_Field $field ) {
$field_data = array();
$params_to_ignore = array( 'show_in_rest', 'options' );
$params_to_rename = array(
'label_cb' => 'label',
'options_cb' => 'options',
);
// Run this first so the js_dependencies arg is populated.
$rendered = ( $cb = $field->maybe_callback( 'render_row_cb' ) )
// Ok, callback is good, let's run it.
? $this->get_cb_results( $cb, $field->args(), $field )
: false;
$field_args = $field->args();
foreach ( $field_args as $key => $value ) {
if ( in_array( $key, $params_to_ignore, true ) ) {
continue;
}
if ( 'options_cb' === $key ) {
$value = $field->options();
} elseif ( in_array( $key, CMB2_Field::$callable_fields, true ) ) {
if ( isset( $this->request['_rendered'] ) ) {
$value = $key === 'render_row_cb' ? $rendered : $field->get_param_callback_result( $key );
} elseif ( is_array( $value ) ) {
// We need to rewrite callbacks as string as they will cause
// JSON recursion errors.
$class = is_string( $value[0] ) ? $value[0] : get_class( $value[0] );
$value = $class . '::' . $value[1];
}
}
$key = isset( $params_to_rename[ $key ] ) ? $params_to_rename[ $key ] : $key;
if ( empty( $value ) || is_scalar( $value ) || is_array( $value ) ) {
$field_data[ $key ] = $value;
} else {
$field_data[ $key ] = sprintf( __( 'Value Error for %s', 'cmb2' ), $key );
}
}
if ( $field->args( 'has_supporting_data' ) ) {
$field_data = $this->get_supporting_data( $field_data, $field );
}
if ( $this->request['object_id'] && $this->request['object_type'] ) {
$field_data['value'] = $field->get_rest_value();
}
return $field_data;
}
/**
* Gets field supporting data (field id and value).
*
* @since 2.7.0
*
* @param CMB2_Field $field Field object.
* @param array $field_data Array of field data.
*
* @return array Array of field data.
*/
public function get_supporting_data( $field_data, $field ) {
// Reset placement of this property.
unset( $field_data['has_supporting_data'] );
$field_data['has_supporting_data'] = true;
$field = $field->get_supporting_field();
$field_data['supporting_data'] = array(
'id' => $field->_id( '', false ),
);
if ( $this->request['object_id'] && $this->request['object_type'] ) {
$field_data['supporting_data']['value'] = $field->get_rest_value();
}
return $field_data;
}
/**
* Return an array of contextual links for field/fields.
*
* @since 2.2.3
*
* @param CMB2_Field $field Field object to build links from.
*
* @return array Array of links
*/
protected function prepare_links( $field ) {
$boxbase = $this->namespace_base . '/' . $this->rest_box->cmb->cmb_id;
$query_string = $this->get_query_string();
$links = array(
'self' => array(
'href' => rest_url( trailingslashit( $boxbase ) . 'fields/' . $field->_id( '', false ) . $query_string ),
),
'collection' => array(
'href' => rest_url( trailingslashit( $boxbase ) . 'fields' . $query_string ),
),
'up' => array(
'embeddable' => true,
'href' => rest_url( $boxbase . $query_string ),
),
);
return $links;
}
/**
* Checks if the CMB2 box or field has any registered callback parameters for the given filter.
*
* The registered handlers will have a property name which matches the filter, except:
* - The 'cmb2_api' prefix will be removed
* - A '_cb' suffix will be added (to stay inline with other '*_cb' parameters).
*
* @since 2.2.3
*
* @param string $filter The filter name.
* @param bool $default_val The default filter value.
*
* @return bool The possibly-modified filter value (if the _cb param is a non-callable).
*/
public function maybe_hook_registered_callback( $filter, $default_val ) {
$default_val = parent::maybe_hook_registered_callback( $filter, $default_val );
if ( $this->field ) {
// Hook field specific filter callbacks.
$val = $this->field->maybe_hook_parameter( $filter, $default_val );
if ( null !== $val ) {
$default_val = $val;
}
}
return $default_val;
}
/**
* Unhooks any CMB2 box or field registered callback parameters for the given filter.
*
* @since 2.2.3
*
* @param string $filter The filter name.
*
* @return void
*/
public function maybe_unhook_registered_callback( $filter ) {
parent::maybe_unhook_registered_callback( $filter );
if ( $this->field ) {
// Unhook field specific filter callbacks.
$this->field->maybe_hook_parameter( $filter, null, 'remove_filter' );
}
}
}

View File

@@ -0,0 +1,541 @@
<?php
abstract class WP_REST_Controller {
/**
* The namespace of this controller's route.
*
* @var string
*/
protected $namespace;
/**
* The base of this controller's route.
*
* @var string
*/
protected $rest_base;
/**
* Register the routes for the objects of the controller.
*/
public function register_routes() {
/* translators: %s: register_routes() */
_doing_it_wrong( 'WP_REST_Controller::register_routes', sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), '4.7' );
}
/**
* Check if a given request has access to get items.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Get a collection of items.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Check if a given request has access to get a specific item.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function get_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Get one item from the collection.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Check if a given request has access to create items.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function create_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Create one item from the collection.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function create_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Check if a given request has access to update a specific item.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function update_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Update one item from the collection.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function update_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Check if a given request has access to delete a specific item.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|boolean
*/
public function delete_item_permissions_check( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Delete one item from the collection.
*
* @param WP_REST_Request $request Full data about the request.
* @return WP_Error|WP_REST_Response
*/
public function delete_item( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Prepare the item for create or update operation.
*
* @param WP_REST_Request $request Request object.
* @return WP_Error|object $prepared_item
*/
protected function prepare_item_for_database( $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Prepare the item for the REST response.
*
* @param mixed $item WordPress representation of the item.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response $response
*/
public function prepare_item_for_response( $item, $request ) {
return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array(
'status' => 405,
) );
}
/**
* Prepare a response for inserting into a collection.
*
* @param WP_REST_Response $response Response object.
* @return array Response data, ready for insertion into collection data.
*/
public function prepare_response_for_collection( $response ) {
if ( ! ( $response instanceof WP_REST_Response ) ) {
return $response;
}
$data = (array) $response->get_data();
$server = rest_get_server();
if ( method_exists( $server, 'get_compact_response_links' ) ) {
$links = call_user_func( array( $server, 'get_compact_response_links' ), $response );
} else {
$links = call_user_func( array( $server, 'get_response_links' ), $response );
}
if ( ! empty( $links ) ) {
$data['_links'] = $links;
}
return $data;
}
/**
* Filter a response based on the context defined in the schema.
*
* @param array $data
* @param string $context
* @return array
*/
public function filter_response_by_context( $data, $context ) {
$schema = $this->get_item_schema();
foreach ( $data as $key => $value ) {
if ( empty( $schema['properties'][ $key ] ) || empty( $schema['properties'][ $key ]['context'] ) ) {
continue;
}
if ( ! in_array( $context, $schema['properties'][ $key ]['context'] ) ) {
unset( $data[ $key ] );
continue;
}
if ( 'object' === $schema['properties'][ $key ]['type'] && ! empty( $schema['properties'][ $key ]['properties'] ) ) {
foreach ( $schema['properties'][ $key ]['properties'] as $attribute => $details ) {
if ( empty( $details['context'] ) ) {
continue;
}
if ( ! in_array( $context, $details['context'] ) ) {
if ( isset( $data[ $key ][ $attribute ] ) ) {
unset( $data[ $key ][ $attribute ] );
}
}
}
}
}
return $data;
}
/**
* Get the item's schema, conforming to JSON Schema.
*
* @return array
*/
public function get_item_schema() {
return $this->add_additional_fields_schema( array() );
}
/**
* Get the item's schema for display / public consumption purposes.
*
* @return array
*/
public function get_public_item_schema() {
$schema = $this->get_item_schema();
foreach ( $schema['properties'] as &$property ) {
if ( isset( $property['arg_options'] ) ) {
unset( $property['arg_options'] );
}
}
return $schema;
}
/**
* Get the query params for collections.
*
* @return array
*/
public function get_collection_params() {
return array(
'context' => $this->get_context_param(),
'page' => array(
'description' => __( 'Current page of the collection.' ),
'type' => 'integer',
'default' => 1,
'sanitize_callback' => 'absint',
'validate_callback' => 'rest_validate_request_arg',
'minimum' => 1,
),
'per_page' => array(
'description' => __( 'Maximum number of items to be returned in result set.' ),
'type' => 'integer',
'default' => 10,
'minimum' => 1,
'maximum' => 100,
'sanitize_callback' => 'absint',
'validate_callback' => 'rest_validate_request_arg',
),
'search' => array(
'description' => __( 'Limit results to those matching a string.' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
),
);
}
/**
* Get the magical context param.
*
* Ensures consistent description between endpoints, and populates enum from schema.
*
* @param array $args
* @return array
*/
public function get_context_param( $args = array() ) {
$param_details = array(
'description' => __( 'Scope under which the request is made; determines fields present in response.' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
'validate_callback' => 'rest_validate_request_arg',
);
$schema = $this->get_item_schema();
if ( empty( $schema['properties'] ) ) {
return array_merge( $param_details, $args );
}
$contexts = array();
foreach ( $schema['properties'] as $attributes ) {
if ( ! empty( $attributes['context'] ) ) {
$contexts = array_merge( $contexts, $attributes['context'] );
}
}
if ( ! empty( $contexts ) ) {
$param_details['enum'] = array_unique( $contexts );
rsort( $param_details['enum'] );
}
return array_merge( $param_details, $args );
}
/**
* Add the values from additional fields to a data object.
*
* @param array $object
* @param WP_REST_Request $request
* @return array modified object with additional fields.
*/
protected function add_additional_fields_to_object( $object, $request ) {
$additional_fields = $this->get_additional_fields();
foreach ( $additional_fields as $field_name => $field_options ) {
if ( ! $field_options['get_callback'] ) {
continue;
}
$object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() );
}
return $object;
}
/**
* Update the values of additional fields added to a data object.
*
* @param array $object
* @param WP_REST_Request $request
*/
protected function update_additional_fields_for_object( $object, $request ) {
$additional_fields = $this->get_additional_fields();
foreach ( $additional_fields as $field_name => $field_options ) {
if ( ! $field_options['update_callback'] ) {
continue;
}
// Don't run the update callbacks if the data wasn't passed in the request.
if ( ! isset( $request[ $field_name ] ) ) {
continue;
}
call_user_func( $field_options['update_callback'], $request[ $field_name ], $object, $field_name, $request, $this->get_object_type() );
}
}
/**
* Add the schema from additional fields to an schema array.
*
* The type of object is inferred from the passed schema.
*
* @param array $schema Schema array.
*/
protected function add_additional_fields_schema( $schema ) {
if ( empty( $schema['title'] ) ) {
return $schema;
}
/**
* Can't use $this->get_object_type otherwise we cause an inf loop.
*/
$object_type = $schema['title'];
$additional_fields = $this->get_additional_fields( $object_type );
foreach ( $additional_fields as $field_name => $field_options ) {
if ( ! $field_options['schema'] ) {
continue;
}
$schema['properties'][ $field_name ] = $field_options['schema'];
}
return $schema;
}
/**
* Get all the registered additional fields for a given object-type.
*
* @param string $object_type
* @return array
*/
protected function get_additional_fields( $object_type = null ) {
if ( ! $object_type ) {
$object_type = $this->get_object_type();
}
if ( ! $object_type ) {
return array();
}
global $wp_rest_additional_fields;
if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) {
return array();
}
return $wp_rest_additional_fields[ $object_type ];
}
/**
* Get the object type this controller is responsible for managing.
*
* @return string
*/
protected function get_object_type() {
$schema = $this->get_item_schema();
if ( ! $schema || ! isset( $schema['title'] ) ) {
return null;
}
return $schema['title'];
}
/**
* Get an array of endpoint arguments from the item schema for the controller.
*
* @param string $method HTTP method of the request. The arguments
* for `CREATABLE` requests are checked for required
* values and may fall-back to a given default, this
* is not done on `EDITABLE` requests. Default is
* WP_REST_Server::CREATABLE.
* @return array $endpoint_args
*/
public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
$schema = $this->get_item_schema();
$schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
$endpoint_args = array();
foreach ( $schema_properties as $field_id => $params ) {
// Arguments specified as `readonly` are not allowed to be set.
if ( ! empty( $params['readonly'] ) ) {
continue;
}
$endpoint_args[ $field_id ] = array(
'validate_callback' => 'rest_validate_request_arg',
'sanitize_callback' => 'rest_sanitize_request_arg',
);
if ( isset( $params['description'] ) ) {
$endpoint_args[ $field_id ]['description'] = $params['description'];
}
if ( WP_REST_Server::CREATABLE === $method && isset( $params['default'] ) ) {
$endpoint_args[ $field_id ]['default'] = $params['default'];
}
if ( WP_REST_Server::CREATABLE === $method && ! empty( $params['required'] ) ) {
$endpoint_args[ $field_id ]['required'] = true;
}
foreach ( array( 'type', 'format', 'enum' ) as $schema_prop ) {
if ( isset( $params[ $schema_prop ] ) ) {
$endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ];
}
}
// Merge in any options provided by the schema property.
if ( isset( $params['arg_options'] ) ) {
// Only use required / default from arg_options on CREATABLE endpoints.
if ( WP_REST_Server::CREATABLE !== $method ) {
$params['arg_options'] = array_diff_key( $params['arg_options'], array(
'required' => '',
'default' => '',
) );
}
$endpoint_args[ $field_id ] = array_merge( $endpoint_args[ $field_id ], $params['arg_options'] );
}
}// End foreach().
return $endpoint_args;
}
/**
* Retrieves post data given a post ID or post object.
*
* This is a subset of the functionality of the `get_post()` function, with
* the additional functionality of having `the_post` action done on the
* resultant post object. This is done so that plugins may manipulate the
* post that is used in the REST API.
*
* @see get_post()
* @global WP_Query $wp_query
*
* @param int|WP_Post $post Post ID or post object. Defaults to global $post.
* @return WP_Post|null A `WP_Post` object when successful.
*/
public function get_post( $post ) {
$post_obj = get_post( $post );
/**
* Filter the post.
*
* Allows plugins to filter the post object as returned by `\WP_REST_Controller::get_post()`.
*
* @param WP_Post|null $post_obj The post object as returned by `get_post()`.
* @param int|WP_Post $post The original value used to obtain the post object.
*/
$post = apply_filters( 'rest_the_post', $post_obj, $post );
return $post;
}
}

View File

@@ -0,0 +1,177 @@
<?php
/**
* CMB base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
abstract class CMB2_Type_Base {
/**
* The CMB2_Types object
*
* @var CMB2_Types
*/
public $types;
/**
* Arguments for use in the render method
*
* @var array
*/
public $args;
/**
* Rendered output (if 'rendered' argument is set to false)
*
* @var string
*/
protected $rendered = '';
/**
* Constructor
*
* @since 2.2.2
* @param CMB2_Types $types Object for the field type.
* @param array $args Array of arguments for the type.
*/
public function __construct( CMB2_Types $types, $args = array() ) {
$this->types = $types;
$args['rendered'] = isset( $args['rendered'] ) ? (bool) $args['rendered'] : true;
$this->args = $args;
}
/**
* Handles rendering this field type.
*
* @since 2.2.2
* @return string Rendered field type.
*/
abstract public function render();
/**
* Stores the rendered field output.
*
* @since 2.2.2
* @param string|CMB2_Type_Base $rendered Rendered output.
* @return string|CMB2_Type_Base Rendered output or this object.
*/
public function rendered( $rendered ) {
$this->field->register_js_data();
if ( $this->args['rendered'] ) {
return is_a( $rendered, __CLASS__ ) ? $rendered->rendered : $rendered;
}
$this->rendered = is_a( $rendered, __CLASS__ ) ? $rendered->rendered : $rendered;
return $this;
}
/**
* Returns the stored rendered field output.
*
* @since 2.2.2
* @return string Stored rendered output (if 'rendered' argument is set to false).
*/
public function get_rendered() {
return $this->rendered;
}
/**
* Handles parsing and filtering attributes while preserving any passed in via field config.
*
* @since 1.1.0
* @param string $element Element for filter.
* @param array $type_defaults Type default arguments.
* @param array $type_overrides Type override arguments.
* @return array Parsed and filtered arguments.
*/
public function parse_args( $element, $type_defaults, $type_overrides = array() ) {
$args = $this->parse_args_from_overrides( $type_overrides );
/**
* Filter attributes for a field type.
* The dynamic portion of the hook name, $element, refers to the field type.
*
* @since 1.1.0
* @param array $args The array of attribute arguments.
* @param array $type_defaults The array of default values.
* @param array $field The `CMB2_Field` object.
* @param object $field_type_object This `CMB2_Types` object.
*/
$args = apply_filters( "cmb2_{$element}_attributes", $args, $type_defaults, $this->field, $this->types );
$args = wp_parse_args( $args, $type_defaults );
if ( ! empty( $args['js_dependencies'] ) ) {
$this->field->add_js_dependencies( $args['js_dependencies'] );
}
return $args;
}
/**
* Handles parsing and filtering attributes while preserving any passed in via field config.
*
* @since 2.2.4
* @param array $type_overrides Type override arguments.
* @return array Parsed arguments
*/
protected function parse_args_from_overrides( $type_overrides = array() ) {
$type_overrides = empty( $type_overrides ) ? $this->args : $type_overrides;
if ( true !== $this->field->args( 'disable_hash_data_attribute' ) ) {
$type_overrides['data-hash'] = $this->field->hash_id();
}
$field_overrides = $this->field->args( 'attributes' );
return ! empty( $field_overrides )
? wp_parse_args( $field_overrides, $type_overrides )
: $type_overrides;
}
/**
* Fall back to CMB2_Types methods
*
* @param string $method Method name being invoked.
* @param array $arguments Arguments passed for the method.
* @throws Exception Throws an exception if the field is invalid.
* @return mixed
*/
public function __call( $method, $arguments ) {
switch ( $method ) {
case '_id':
case '_name':
case '_desc':
case '_text':
case 'concat_attrs':
return call_user_func_array( array( $this->types, $method ), $arguments );
default:
throw new Exception( sprintf( esc_html__( 'Invalid %1$s method: %2$s', 'cmb2' ), __CLASS__, $method ) );
}
}
/**
* Magic getter for our object.
*
* @param string $field Property being requested.
* @throws Exception Throws an exception if the field is invalid.
* @return mixed
*/
public function __get( $field ) {
switch ( $field ) {
case 'field':
return $this->types->field;
default:
throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) );
}
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* CMB checkbox field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Checkbox extends CMB2_Type_Text {
/**
* If checkbox is checked
*
* @var mixed
*/
public $is_checked = null;
/**
* Constructor
*
* @since 2.2.2
*
* @param CMB2_Types $types Object for the field type.
* @param array $args Array of arguments for the type.
* @param mixed $is_checked Whether or not the field is checked, or default value.
*/
public function __construct( CMB2_Types $types, $args = array(), $is_checked = null ) {
parent::__construct( $types, $args );
$this->is_checked = $is_checked;
}
/**
* Render the field for the field type.
*
* @since 2.2.2
*
* @param array $args Array of arguments for the rendering.
* @return CMB2_Type_Base|string
*/
public function render( $args = array() ) {
$defaults = array(
'type' => 'checkbox',
'class' => 'cmb2-option cmb2-list',
'value' => 'on',
'desc' => '',
);
$meta_value = $this->field->escaped_value();
$is_checked = null === $this->is_checked
? ! empty( $meta_value )
: $this->is_checked;
if ( $is_checked ) {
$defaults['checked'] = 'checked';
}
$args = $this->parse_args( 'checkbox', $defaults );
return $this->rendered(
sprintf(
'%s <label for="%s">%s</label>',
parent::render( $args ),
$this->_id( '', false ),
$this->_desc()
)
);
}
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* CMB colorpicker field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Colorpicker extends CMB2_Type_Text {
/**
* The optional value for the colorpicker field
*
* @var string
*/
public $value = '';
/**
* Constructor
*
* @since 2.2.2
*
* @param CMB2_Types $types Object for the field type.
* @param array $args Array of arguments for the type.
* @param string $value Value that the field type is currently set to, or default value.
*/
public function __construct( CMB2_Types $types, $args = array(), $value = '' ) {
parent::__construct( $types, $args );
$this->value = $value ? $value : $this->value;
}
/**
* Render the field for the field type.
*
* @since 2.2.2
*
* @param array $args Array of arguments for the rendering.
*
* @return CMB2_Type_Base|string
*/
public function render( $args = array() ) {
$meta_value = $this->value ? $this->value : $this->field->escaped_value();
$meta_value = self::sanitize_color( $meta_value );
wp_enqueue_style( 'wp-color-picker' );
$args = wp_parse_args( $args, array(
'class' => 'cmb2-text-small',
) );
$args['class'] .= ' cmb2-colorpicker';
$args['value'] = $meta_value;
$args['js_dependencies'] = array( 'wp-color-picker' );
if ( $this->field->options( 'alpha' ) ) {
$args['js_dependencies'][] = 'wp-color-picker-alpha';
$args['data-alpha'] = 'true';
}
$args = wp_parse_args( $this->args, $args );
return parent::render( $args );
}
/**
* Sanitizes the given color, or array of colors.
*
* @since 2.9.0
*
* @param string|array $color The color or array of colors to sanitize.
*
* @return string|array The color or array of colors, sanitized.
*/
public static function sanitize_color( $color ) {
if ( is_array( $color ) ) {
$color = array_map( array( 'CMB2_Type_Colorpicker', 'sanitize_color' ), $color );
} else {
// Regexp for hexadecimal colors
$hex_color = '(([a-fA-F0-9]){3}){1,2}$';
if ( preg_match( '/^' . $hex_color . '/i', $color ) ) {
// Value is just 123abc, so prepend #
$color = '#' . $color;
} elseif (
// If value doesn't match #123abc...
! preg_match( '/^#' . $hex_color . '/i', $color )
// And value doesn't match rgba()...
&& 0 !== strpos( trim( $color ), 'rgba' )
) {
// Then sanitize to just #.
$color = '#';
}
}
return $color;
}
/**
* Provide the option to use a rgba colorpicker.
*
* @since 2.2.6.2
*/
public static function dequeue_rgba_colorpicker_script() {
if ( wp_script_is( 'jw-cmb2-rgba-picker-js', 'enqueued' ) ) {
wp_dequeue_script( 'jw-cmb2-rgba-picker-js' );
CMB2_JS::register_colorpicker_alpha( true );
}
}
}

View File

@@ -0,0 +1,138 @@
<?php
/**
* CMB base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
abstract class CMB2_Type_Counter_Base extends CMB2_Type_Base {
/**
* Whether this type has the counter added.
*
* @since 2.7.0
*
* @var boolean
*/
public $has_counter = false;
/**
* Return character counter markup for this field.
*
* @since 2.7.0
*
* @param string $val The actual value of this field.
*
* @return string
*/
public function char_counter_markup( $val ) {
$markup = '';
if ( ! $this->field->args( 'char_counter' ) ) {
return $markup;
}
$type = (string) $this->field->args( 'char_counter' );
$field_id = $this->_id( '', false );
$char_max = (int) $this->field->prop( 'char_max' );
if ( $char_max ) {
$char_max = 'data-max="' . $char_max . '"';
}
switch ( $type ) {
case 'words':
$label = $char_max
? $this->_text( 'words_left_text', esc_html__( 'Words left', 'cmb2' ) )
: $this->_text( 'words_text', esc_html__( 'Words', 'cmb2' ) );
break;
default:
$type = 'characters';
$label = $char_max
? $this->_text( 'characters_left_text', esc_html__( 'Characters left', 'cmb2' ) )
: $this->_text( 'characters_text', esc_html__( 'Characters', 'cmb2' ) );
break;
}
$msg = $char_max
? sprintf( '<span class="cmb2-char-max-msg">%s</span>', $this->_text( 'characters_truncated_text', esc_html__( 'Your text may be truncated.', 'cmb2' ) ) )
: '';
$length = strlen( $val );
$width = $length > 1 ? ( 8 * strlen( (string) $length ) ) + 15 : false;
$markup .= '<p class="cmb2-char-counter-wrap">';
$markup .= sprintf(
'<label><span class="cmb2-char-counter-label">%2$s:</span> <input id="%1$s" data-field-id="%3$s" data-counter-type="%4$s" %5$s class="cmb2-char-counter" type="text" value="%6$s" readonly="readonly" style="%7$s"></label>%8$s',
esc_attr( 'char-counter-' . $field_id ),
$label,
esc_attr( $field_id ),
$type,
$char_max,
$length,
$width ? "width: {$width}px;" : '',
$msg
);
$markup .= '</p>';
// Enqueue the required JS.
$this->field->add_js_dependencies( array(
'word-count',
'wp-util',
'cmb2-char-counter',
) );
$this->has_counter = true;
return $markup;
}
/**
* Maybe update attributes for the character counter.
*
* @since 2.7.0
*
* @param array $attributes Array of parsed attributes.
*
* @return array Potentially modified attributes.
*/
public function maybe_update_attributes_for_char_counter( $attributes ) {
$char_counter = $this->char_counter_markup( $attributes['value'] );
// Has character counter?
if ( $char_counter ) {
$attributes['class'] = ! empty( $attributes['class'] ) ? $attributes['class'] . ' cmb2-count-chars' : ' cmb2-count-chars';
// Enforce max chars?
$max = $this->enforce_max();
if ( $max ) {
$attributes['maxlength'] = $max;
}
$attributes['desc'] = $char_counter . $attributes['desc'];
}
return $attributes;
}
/**
* Enforce max chars?
*
* @since 2.7.0
*
* @return bool Whether to enforce max characters.
*/
public function enforce_max() {
$char_max = (int) $this->field->args( 'char_max' );
// Enforce max chars?
return ( $this->field->args( 'char_max_enforce' ) && $char_max > 0
&& 'words' !== $this->field->args( 'char_counter' ) )
? $char_max
: false;
}
}

View File

@@ -0,0 +1,190 @@
<?php
/**
* CMB file field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_File extends CMB2_Type_File_Base {
/**
* Handles outputting an 'file' field
*
* @param array $args Override arguments.
* @return string Form input element
*/
public function render( $args = array() ) {
$args = empty( $args ) ? $this->args : $args;
$field = $this->field;
$options = (array) $field->options();
$a = $this->args = $this->parse_args( 'file', array(
'class' => 'cmb2-upload-file regular-text',
'id' => $this->_id(),
'name' => $this->_name(),
'value' => $field->escaped_value(),
'id_value' => null,
'desc' => $this->_desc( true ),
'size' => 45,
'js_dependencies' => 'media-editor',
'preview_size' => $field->args( 'preview_size' ),
'query_args' => $field->args( 'query_args' ),
// if options array and 'url' => false, then hide the url field.
'type' => array_key_exists( 'url', $options ) && false === $options['url']
? 'hidden'
: 'text',
), $args );
// get an array of image size meta data, fallback to 'large'.
$this->args['img_size_data'] = $img_size_data = parent::get_image_size_data(
$a['preview_size'],
'large'
);
$output = '';
$output .= parent::render( array(
'type' => $a['type'],
'class' => $a['class'],
'value' => $a['value'],
'id' => $a['id'],
'name' => $a['name'],
'size' => $a['size'],
'desc' => '',
'data-previewsize' => sprintf( '[%d,%d]', $img_size_data['width'], $img_size_data['height'] ),
'data-sizename' => $img_size_data['name'],
'data-queryargs' => ! empty( $a['query_args'] ) ? json_encode( $a['query_args'] ) : '',
'js_dependencies' => $a['js_dependencies'],
) );
// Now remove the data-iterator attribute if it exists.
// (Possible if being used within a custom field)
// This is not elegant, but compensates for CMB2_Types::_id
// automagically & inelegantly adding the data-iterator attribute.
// Single responsibility principle? pffft.
$parts = explode( '"', $this->args['id'] );
$this->args['id'] = $parts[0];
$output .= sprintf(
'<input class="cmb2-upload-button button-secondary" type="button" value="%1$s" />',
esc_attr( $this->_text( 'add_upload_file_text', esc_html__( 'Add or Upload File', 'cmb2' ) ) )
);
$output .= $a['desc'];
$output .= $this->get_id_field_output();
$output .= '<div id="' . esc_attr( $field->id() ) . '-status" class="cmb2-media-status">';
if ( ! empty( $a['value'] ) ) {
$output .= $this->get_file_preview_output();
}
$output .= '</div>';
return $this->rendered( $output );
}
/**
* Return attempted file preview output for a provided file.
*
* @since 2.2.5
*
* @return string
*/
public function get_file_preview_output() {
if ( ! $this->is_valid_img_ext( $this->args['value'] ) ) {
return $this->file_status_output( array(
'value' => $this->args['value'],
'tag' => 'div',
'cached_id' => $this->args['id'],
) );
}
if ( $this->args['id_value'] ) {
$image = wp_get_attachment_image( $this->args['id_value'], $this->args['preview_size'], null, array(
'class' => 'cmb-file-field-image',
) );
} else {
$image = '<img style="max-width: ' . absint( $this->args['img_size_data']['width'] ) . 'px; width: 100%;" src="' . esc_url( $this->args['value'] ) . '" class="cmb-file-field-image" alt="" />';
}
return $this->img_status_output( array(
'image' => $image,
'tag' => 'div',
'cached_id' => $this->args['id'],
) );
}
/**
* Return field ID output as a hidden field.
*
* @since 2.2.5
*
* @return string
*/
public function get_id_field_output() {
$field = $this->field;
/*
* A little bit of magic (tsk tsk) replacing the $this->types->field object,
* So that the render function is using the proper field object.
*/
$this->types->field = $this->get_id_field();
$output = parent::render( array(
'type' => 'hidden',
'class' => 'cmb2-upload-file-id',
'value' => $this->types->field->value,
'desc' => '',
) );
// We need to put the original field object back
// or other fields in a custom field will be broken.
$this->types->field = $field;
return $output;
}
/**
* Return field ID data.
*
* @since 2.2.5
*
* @return mixed
*/
public function get_id_field() {
// reset field args for attachment id.
$args = array(
// if we're looking at a file in a group, we need to get the non-prefixed id.
'id' => ( $this->field->group ? $this->field->args( '_id' ) : $this->args['id'] ) . '_id',
'disable_hash_data_attribute' => true,
);
// and get new field object
// (need to set it to the types field property).
$id_field = $this->field->get_field_clone( $args );
$id_value = absint( null !== $this->args['id_value'] ? $this->args['id_value'] : $id_field->escaped_value() );
// we don't want to output "0" as a value.
if ( ! $id_value ) {
$id_value = '';
}
// if there is no id saved yet, try to get it from the url.
if ( $this->args['value'] && ! $id_value ) {
$id_value = CMB2_Utils::image_id_from_url( esc_url_raw( $this->args['value'] ) );
}
$id_field->value = $id_value;
return $id_field;
}
}

View File

@@ -0,0 +1,221 @@
<?php
/**
* CMB File base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_File_Base extends CMB2_Type_Text {
/**
* Determines if a file has a valid image extension
*
* @since 1.0.0
* @param string $file File url
* @return bool Whether file has a valid image extension
*/
public function is_valid_img_ext( $file, $blah = false ) {
$file_ext = CMB2_Utils::get_file_ext( $file );
$valid_types = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'ico', 'icon' );
$allowed = get_allowed_mime_types();
if ( ! empty( $allowed ) ) {
foreach ( (array) $allowed as $type => $mime) {
if ( 0 === strpos( $mime, 'image/' ) ) {
$types = explode( '|', $type );
$valid_types = array_merge( $valid_types, $types );
}
}
$valid_types = array_unique( $valid_types );
}
/**
* Which image types are considered valid image file extensions.
*
* @since 2.0.9
*
* @param array $valid_types The valid image file extensions.
*/
$is_valid_types = apply_filters( 'cmb2_valid_img_types', $valid_types );
$is_valid = $file_ext && in_array( $file_ext, (array) $is_valid_types );
$field_id = $this->field->id();
/**
* Filter for determining if a field value has a valid image file-type extension.
*
* The dynamic portion of the hook name, $field_id, refers to the field id attribute.
*
* @since 2.0.9
*
* @param bool $is_valid Whether field value has a valid image file-type extension.
* @param string $file File url.
* @param string $file_ext File extension.
*/
return (bool) apply_filters( "cmb2_{$field_id}_is_valid_img_ext", $is_valid, $file, $file_ext );
}
/**
* file/file_list image wrap
*
* @since 2.0.2
* @param array $args Array of arguments for output
* @return string Image wrap output
*/
public function img_status_output( $args ) {
return sprintf( '<%1$s class="img-status cmb2-media-item">%2$s<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button"%3$s>%4$s</a></p>%5$s</%1$s>',
$args['tag'],
$args['image'],
isset( $args['cached_id'] ) ? ' rel="' . esc_attr( $args['cached_id'] ) . '"' : '',
esc_html( $this->_text( 'remove_image_text', esc_html__( 'Remove Image', 'cmb2' ) ) ),
isset( $args['id_input'] ) ? $args['id_input'] : ''
);
}
/**
* file/file_list file wrap
*
* @since 2.0.2
* @param array $args Array of arguments for output
* @return string File wrap output
*/
public function file_status_output( $args ) {
return sprintf( '<%1$s class="file-status cmb2-media-item"><span>%2$s <strong>%3$s</strong></span>&nbsp;&nbsp; (<a href="%4$s" target="_blank" rel="external">%5$s</a> / <a href="#" class="cmb2-remove-file-button"%6$s>%7$s</a>)%8$s</%1$s>',
$args['tag'],
esc_html( $this->_text( 'file_text', esc_html__( 'File:', 'cmb2' ) ) ),
esc_html( CMB2_Utils::get_file_name_from_path( $args['value'] ) ),
esc_url( $args['value'] ),
esc_html( $this->_text( 'file_download_text', esc_html__( 'Download', 'cmb2' ) ) ),
isset( $args['cached_id'] ) ? ' rel="' . esc_attr( $args['cached_id'] ) . '"' : '',
esc_html( $this->_text( 'remove_text', esc_html__( 'Remove', 'cmb2' ) ) ),
isset( $args['id_input'] ) ? $args['id_input'] : ''
);
}
/**
* Outputs the file/file_list underscore Javascript templates in the footer.
*
* @since 2.2.4
* @return void
*/
public static function output_js_underscore_templates() {
?>
<script type="text/html" id="tmpl-cmb2-single-image">
<div class="img-status cmb2-media-item">
<img width="{{ data.sizeWidth }}" height="{{ data.sizeHeight }}" src="{{ data.sizeUrl }}" class="cmb-file-field-image" alt="{{ data.filename }}" title="{{ data.filename }}" />
<p><a href="#" class="cmb2-remove-file-button" rel="{{ data.mediaField }}">{{ data.stringRemoveImage }}</a></p>
</div>
</script>
<script type="text/html" id="tmpl-cmb2-single-file">
<div class="file-status cmb2-media-item">
<span>{{ data.stringFile }} <strong>{{ data.filename }}</strong></span>&nbsp;&nbsp; (<a href="{{ data.url }}" target="_blank" rel="external">{{ data.stringDownload }}</a> / <a href="#" class="cmb2-remove-file-button" rel="{{ data.mediaField }}">{{ data.stringRemoveFile }}</a>)
</div>
</script>
<script type="text/html" id="tmpl-cmb2-list-image">
<li class="img-status cmb2-media-item">
<img width="{{ data.sizeWidth }}" height="{{ data.sizeHeight }}" src="{{ data.sizeUrl }}" class="cmb-file_list-field-image" alt="{{ data.filename }}">
<p><a href="#" class="cmb2-remove-file-button" rel="{{ data.mediaField }}[{{ data.id }}]">{{ data.stringRemoveImage }}</a></p>
<input type="hidden" id="filelist-{{ data.id }}" data-id="{{ data.id }}" name="{{ data.mediaFieldName }}[{{ data.id }}]" value="{{ data.url }}">
</li>
</script>
<script type="text/html" id="tmpl-cmb2-list-file">
<li class="file-status cmb2-media-item">
<span>{{ data.stringFile }} <strong>{{ data.filename }}</strong></span>&nbsp;&nbsp; (<a href="{{ data.url }}" target="_blank" rel="external">{{ data.stringDownload }}</a> / <a href="#" class="cmb2-remove-file-button" rel="{{ data.mediaField }}[{{ data.id }}]">{{ data.stringRemoveFile }}</a>)
<input type="hidden" id="filelist-{{ data.id }}" data-id="{{ data.id }}" name="{{ data.mediaFieldName }}[{{ data.id }}]" value="{{ data.url }}">
</li>
</script>
<?php
}
/**
* Utility method to return an array of meta data for a registered image size
*
* Uses CMB2_Utils::get_named_size() to get the closest available named size
* from an array of width and height values and CMB2_Utils::get_available_image_sizes()
* to get the meta data associated with a named size.
*
* @since 2.2.4
* @param array|string $img_size Image size. Accepts an array of width and height (in that order)
* @param string $fallback Size to use if the supplied named size doesn't exist
* @return array Array containing the image size meta data
* $size = (
* 'width' => (int) image size width
* 'height' => (int) image size height
* 'name' => (string) e.g. 'thumbnail'
* )
*/
static function get_image_size_data( $img_size = '', $fallback = 'thumbnail' ) {
$data = array();
if ( is_array( $img_size ) ) {
$data['width'] = intval( $img_size[0] );
$data['height'] = intval( $img_size[1] );
$data['name'] = '';
// Try and get the closest named size from our array of dimensions
if ( $named_size = CMB2_Utils::get_named_size( $img_size ) ) {
$data['name'] = $named_size;
}
} else {
$image_sizes = CMB2_Utils::get_available_image_sizes();
// The 'thumb' alias, which works elsewhere, doesn't work in the wp.media uploader
if ( 'thumb' == $img_size ) {
$img_size = 'thumbnail';
}
// Named size doesn't exist, use $fallback
if ( ! array_key_exists( $img_size, $image_sizes ) ) {
$img_size = $fallback;
}
// Get image dimensions from named sizes
$data['width'] = intval( $image_sizes[ $img_size ]['width'] );
$data['height'] = intval( $image_sizes[ $img_size ]['height'] );
$data['name'] = $img_size;
}
return $data;
}
/**
* Filters attachment data prepared for JavaScript.
*
* Adds the url, width, height, and orientation for custom sizes to the JavaScript
* object returned by the wp.media uploader. Hooked to 'wp_prepare_attachment_for_js'.
*
* @since 2.2.4
* @param array $response Array of prepared attachment data
* @param int|object $attachment Attachment ID or object
* @param array $meta Array of attachment meta data ( from wp_get_attachment_metadata() )
* @return array filtered $response array
*/
public static function prepare_image_sizes_for_js( $response, $attachment, $meta ) {
foreach ( CMB2_Utils::get_available_image_sizes() as $size => $info ) {
// registered image size exists for this attachment
if ( isset( $meta['sizes'][ $size ] ) ) {
$attachment_url = wp_get_attachment_url( $attachment->ID );
$base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url );
$size_meta = $meta['sizes'][ $size ];
$response['sizes'][ $size ] = array(
'url' => $base_url . $size_meta['file'],
'height' => $size_meta['height'],
'width' => $size_meta['width'],
'orientation' => $size_meta['height'] > $size_meta['width'] ? 'portrait' : 'landscape',
);
}
}
return $response;
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* CMB file_list field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_File_List extends CMB2_Type_File_Base {
public function render( $args = array() ) {
$field = $this->field;
$meta_value = $field->escaped_value();
$name = $this->_name();
$img_size = $field->args( 'preview_size' );
$query_args = $field->args( 'query_args' );
$output = '';
// get an array of image size meta data, fallback to 'thumbnail'
$img_size_data = parent::get_image_size_data( $img_size, 'thumbnail' );
$output .= parent::render( array(
'type' => 'hidden',
'class' => 'cmb2-upload-file cmb2-upload-list',
'size' => 45,
'desc' => '',
'value' => '',
'data-previewsize' => sprintf( '[%d,%d]', $img_size_data['width'], $img_size_data['height'] ),
'data-sizename' => $img_size_data['name'],
'data-queryargs' => ! empty( $query_args ) ? json_encode( $query_args ) : '',
'js_dependencies' => 'media-editor',
) );
$output .= parent::render( array(
'type' => 'button',
'class' => 'cmb2-upload-button button-secondary cmb2-upload-list',
'value' => esc_attr( $this->_text( 'add_upload_files_text', esc_html__( 'Add or Upload Files', 'cmb2' ) ) ),
'name' => false,
'id' => false,
) );
$output .= '<ul id="' . $this->_id( '-status', false ) . '" class="cmb2-media-status cmb-attach-list">';
if ( $meta_value && is_array( $meta_value ) ) {
foreach ( $meta_value as $id => $fullurl ) {
$id_input = parent::render( array(
'type' => 'hidden',
'value' => $fullurl,
'name' => $name . '[' . $id . ']',
'id' => 'filelist-' . $id,
'data-id' => $id,
'desc' => '',
'class' => false,
) );
if ( $this->is_valid_img_ext( $fullurl ) ) {
$output .= $this->img_status_output( array(
'image' => wp_get_attachment_image( $id, $img_size ),
'tag' => 'li',
'id_input' => $id_input,
) );
} else {
$output .= $this->file_status_output( array(
'value' => $fullurl,
'tag' => 'li',
'id_input' => $id_input,
) );
}
}
}
$output .= '</ul>';
return $this->rendered( $output );
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* CMB Multi base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
abstract class CMB2_Type_Multi_Base extends CMB2_Type_Base {
/**
* Generates html for an option element
*
* @since 1.1.0
* @param array $args Arguments array containing value, label, and checked boolean
* @return string Generated option element html
*/
public function select_option( $args = array() ) {
return sprintf( "\t" . '<option value="%s" %s>%s</option>', $args['value'], selected( isset( $args['checked'] ) && $args['checked'], true, false ), $args['label'] ) . "\n";
}
/**
* Generates html for list item with input
*
* @since 1.1.0
* @param array $args Override arguments
* @param int $i Iterator value
* @return string Gnerated list item html
*/
public function list_input( $args = array(), $i = '' ) {
$a = $this->parse_args( 'list_input', array(
'type' => 'radio',
'class' => 'cmb2-option',
'name' => $this->_name(),
'id' => $this->_id( $i ),
'value' => $this->field->escaped_value(),
'label' => '',
), $args );
return sprintf( "\t" . '<li><input%s/> <label for="%s">%s</label></li>' . "\n", $this->concat_attrs( $a, array( 'label' ) ), $a['id'], $a['label'] );
}
/**
* Generates html for list item with checkbox input
*
* @since 1.1.0
* @param array $args Override arguments
* @param int $i Iterator value
* @return string Gnerated list item html
*/
public function list_input_checkbox( $args, $i ) {
$saved_value = $this->field->escaped_value();
if ( is_array( $saved_value ) && in_array( $args['value'], $saved_value ) ) {
$args['checked'] = 'checked';
}
$args['type'] = 'checkbox';
return $this->list_input( $args, $i );
}
/**
* Generates html for concatenated items
*
* @since 1.1.0
* @param array $args Optional arguments
* @return string Concatenated html items
*/
public function concat_items( $args = array() ) {
$field = $this->field;
$method = isset( $args['method'] ) ? $args['method'] : 'select_option';
unset( $args['method'] );
$value = null !== $field->escaped_value()
? $field->escaped_value()
: $field->get_default();
$value = CMB2_Utils::normalize_if_numeric( $value );
$concatenated_items = '';
$i = 1;
$options = array();
if ( $option_none = $field->args( 'show_option_none' ) ) {
$options[''] = $option_none;
}
$options = $options + (array) $field->options();
foreach ( $options as $opt_value => $opt_label ) {
// Clone args & modify for just this item
$a = $args;
$a['value'] = $opt_value;
$a['label'] = $opt_label;
// Check if this option is the value of the input
if ( $value === CMB2_Utils::normalize_if_numeric( $opt_value ) ) {
$a['checked'] = 'checked';
}
$concatenated_items .= $this->$method( $a, $i++ );
}
return $concatenated_items;
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* CMB multicheck field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Multicheck extends CMB2_Type_Radio {
/**
* The type of radio field
*
* @var string
*/
public $type = 'checkbox';
public function render( $args = array() ) {
$classes = false === $this->field->args( 'select_all_button' )
? 'cmb2-checkbox-list no-select-all cmb2-list'
: 'cmb2-checkbox-list cmb2-list';
$args = $this->parse_args( $this->type, array(
'class' => $classes,
'options' => $this->concat_items( array(
'name' => $this->_name() . '[]',
'method' => 'list_input_checkbox',
) ),
'desc' => $this->_desc( true ),
) );
return $this->rendered( $this->ul( $args ) );
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* CMB oembed field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Oembed extends CMB2_Type_Text {
public function render( $args = array() ) {
$field = $this->field;
$meta_value = trim( $field->escaped_value() );
$oembed = ! empty( $meta_value )
? cmb2_ajax()->get_oembed( array(
'url' => $field->escaped_value(),
'object_id' => $field->object_id,
'object_type' => $field->object_type,
'oembed_args' => array(
'width' => '640',
),
'field_id' => $this->_id( '', false ),
) )
: '';
return parent::render( array(
'class' => 'cmb2-oembed regular-text',
'data-objectid' => $field->object_id,
'data-objecttype' => $field->object_type,
) )
. '<p class="cmb-spinner spinner"></p>'
. '<div id="' . $this->_id( '-status' ) . '" class="cmb2-media-status ui-helper-clearfix embed_wrap">' . $oembed . '</div>';
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* CMB Picker base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
abstract class CMB2_Type_Picker_Base extends CMB2_Type_Text {
/**
* Parse the picker attributes.
*
* @since 2.2.0
* @param string $arg 'date' or 'time'
* @param array $args Optional arguments to modify (else use $this->field->args['attributes'])
* @return array Array of field attributes
*/
public function parse_picker_options( $arg = 'date', $args = array() ) {
$att = 'data-' . $arg . 'picker';
$update = empty( $args );
$atts = array();
$format = $this->field->args( $arg . '_format' );
if ( $js_format = CMB2_Utils::php_to_js_dateformat( $format ) ) {
if ( $update ) {
$atts = $this->field->args( 'attributes' );
} else {
$atts = isset( $args['attributes'] )
? $args['attributes']
: $atts;
}
// Don't override user-provided datepicker values
$data = isset( $atts[ $att ] )
? json_decode( $atts[ $att ], true )
: array();
$data[ $arg . 'Format' ] = $js_format;
$atts[ $att ] = function_exists( 'wp_json_encode' )
? wp_json_encode( $data )
: json_encode( $data );
}
if ( $update ) {
$this->field->args['attributes'] = $atts;
}
return array_merge( $args, $atts );
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* CMB radio field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Radio extends CMB2_Type_Multi_Base {
/**
* The type of radio field
*
* @var string
*/
public $type = 'radio';
/**
* Constructor
*
* @since 2.2.2
*
* @param CMB2_Types $types
* @param array $args
*/
public function __construct( CMB2_Types $types, $args = array(), $type = '' ) {
parent::__construct( $types, $args );
$this->type = $type ? $type : $this->type;
}
public function render() {
$args = $this->parse_args( $this->type, array(
'class' => 'cmb2-radio-list cmb2-list',
'options' => $this->concat_items( array(
'label' => 'test',
'method' => 'list_input',
) ),
'desc' => $this->_desc( true ),
) );
return $this->rendered( $this->ul( $args ) );
}
protected function ul( $a ) {
return sprintf( '<ul class="%s">%s</ul>%s', $a['class'], $a['options'], $a['desc'] );
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* CMB select field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Select extends CMB2_Type_Multi_Base {
public function render() {
$a = $this->parse_args( 'select', array(
'class' => 'cmb2_select',
'name' => $this->_name(),
'id' => $this->_id(),
'desc' => $this->_desc( true ),
'options' => $this->concat_items(),
) );
$attrs = $this->concat_attrs( $a, array( 'desc', 'options' ) );
return $this->rendered(
sprintf( '<select%s>%s</select>%s', $attrs, $a['options'], $a['desc'] )
);
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* CMB select_timezone field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Select_Timezone extends CMB2_Type_Select {
public function render() {
$this->field->args['default'] = $this->field->get_default()
? $this->field->get_default()
: CMB2_Utils::timezone_string();
$this->args = wp_parse_args( $this->args, array(
'class' => 'cmb2_select cmb2-select-timezone',
'options' => wp_timezone_choice( $this->field->escaped_value() ),
'desc' => $this->_desc(),
) );
return parent::render();
}
}

View File

@@ -0,0 +1,189 @@
<?php
/**
* CMB Taxonomy base field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
abstract class CMB2_Type_Taxonomy_Base extends CMB2_Type_Multi_Base {
/**
* Parent term ID when looping hierarchical terms.
*
* @var integer|null
*/
protected $parent = null;
/**
* Checks if we can get a post object, and if so, uses `get_the_terms` which utilizes caching.
*
* @since 1.0.2
* @return mixed Array of terms on success
*/
public function get_object_terms() {
switch ( $this->field->object_type ) {
case 'options-page':
case 'term':
return $this->options_terms();
case 'post':
// WP caches internally so it's better to use
return get_the_terms( $this->field->object_id, $this->field->args( 'taxonomy' ) );
default:
return $this->non_post_object_terms();
}
}
/**
* Gets the term objects for the terms stored via options boxes.
*
* @since 2.2.4
* @return mixed Array of terms on success
*/
public function options_terms() {
if ( empty( $this->field->value ) ) {
return array();
}
$terms = (array) $this->field->value;
foreach ( $terms as $index => $term ) {
$terms[ $index ] = get_term_by( 'slug', $term, $this->field->args( 'taxonomy' ) );
}
return $terms;
}
/**
* For non-post objects, wraps the call to wp_get_object_terms with transient caching.
*
* @since 2.2.4
* @return mixed Array of terms on success
*/
public function non_post_object_terms() {
$object_id = $this->field->object_id;
$taxonomy = $this->field->args( 'taxonomy' );
$cache_key = "cmb-cache-{$taxonomy}-{$object_id}";
// Check cache
$cached = get_transient( $cache_key );
if ( ! $cached ) {
$cached = wp_get_object_terms( $object_id, $taxonomy );
// Do our own (minimal) caching. Long enough for a page-load.
set_transient( $cache_key, $cached, 60 );
}
return $cached;
}
/**
* Wrapper for `get_terms` to account for changes in WP 4.6 where taxonomy is expected
* as part of the arguments.
*
* @since 2.2.2
* @return mixed Array of terms on success
*/
public function get_terms() {
$args = array(
'taxonomy' => $this->field->args( 'taxonomy' ),
'hide_empty' => false,
);
if ( null !== $this->parent ) {
$args['parent'] = $this->parent;
}
$args = wp_parse_args( $this->field->prop( 'query_args', array() ), $args );
return CMB2_Utils::wp_at_least( '4.5.0' )
? get_terms( $args )
: get_terms( $this->field->args( 'taxonomy' ), http_build_query( $args ) );
}
protected function no_terms_result( $error, $tag = 'li' ) {
if ( is_wp_error( $error ) ) {
$message = $error->get_error_message();
$data = 'data-error="' . esc_attr( $error->get_error_code() ) . '"';
} else {
$message = $this->_text( 'no_terms_text', esc_html__( 'No terms', 'cmb2' ) );
$data = '';
}
$this->field->args['select_all_button'] = false;
return sprintf( '<%3$s><label %1$s>%2$s</label></%3$s>', $data, esc_html( $message ), $tag );
}
public function get_object_term_or_default() {
$saved_terms = $this->get_object_terms();
return is_wp_error( $saved_terms ) || empty( $saved_terms )
? $this->field->get_default()
: array_shift( $saved_terms )->slug;
}
/**
* Takes a list of all tax terms and outputs.
*
* @since 2.2.5
*
* @param array $all_terms Array of all terms.
* @param array|string $saved Array of terms set to the object, or single term slug.
*
* @return string List of terms.
*/
protected function loop_terms( $all_terms, $saved_terms ) {
return '';
}
/**
* Build children hierarchy.
*
* @param object $parent_term The parent term object.
* @param array|string $saved Array of terms set to the object, or single term slug.
*
* @return string List of terms.
*/
protected function build_children( $parent_term, $saved ) {
if ( empty( $parent_term->term_id ) ) {
return '';
}
$this->parent = $parent_term->term_id;
$terms = $this->get_terms();
$options = '';
if ( ! empty( $terms ) && is_array( $terms ) ) {
$options .= $this->child_option_output( $terms, $saved );
}
return $options;
}
/**
* Build child terms output.
*
* @since 2.6.1
*
* @param array $terms Array of child terms.
* @param array|string $saved Array of terms set to the object, or single term slug.
*
* @return string Child option output.
*/
public function child_option_output( $terms, $saved ) {
$output = '<li class="cmb2-indented-hierarchy"><ul>';
$output .= $this->loop_terms( $terms, $saved );
$output .= '</ul></li>';
return $output;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* CMB taxonomy_multicheck field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Taxonomy_Multicheck extends CMB2_Type_Taxonomy_Base {
protected $counter = 0;
public function render() {
return $this->rendered(
$this->types->radio( array(
'class' => $this->get_wrapper_classes(),
'options' => $this->get_term_options(),
), 'taxonomy_multicheck' )
);
}
protected function get_term_options() {
$all_terms = $this->get_terms();
if ( ! $all_terms || is_wp_error( $all_terms ) ) {
return $this->no_terms_result( $all_terms );
}
return $this->loop_terms( $all_terms, $this->get_object_term_or_default() );
}
protected function loop_terms( $all_terms, $saved_terms ) {
$options = '';
foreach ( $all_terms as $term ) {
$options .= $this->list_term_input( $term, $saved_terms );
}
return $options;
}
protected function list_term_input( $term, $saved_terms ) {
$args = array(
'value' => $term->slug,
'label' => $term->name,
'type' => 'checkbox',
'name' => $this->_name() . '[]',
);
if ( is_array( $saved_terms ) && in_array( $term->slug, $saved_terms ) ) {
$args['checked'] = 'checked';
}
return $this->list_input( $args, ++$this->counter );
}
public function get_object_term_or_default() {
$saved_terms = $this->get_object_terms();
return is_wp_error( $saved_terms ) || empty( $saved_terms )
? $this->field->get_default()
: wp_list_pluck( $saved_terms, 'slug' );
}
protected function get_wrapper_classes() {
$classes = 'cmb2-checkbox-list cmb2-list';
if ( false === $this->field->args( 'select_all_button' ) ) {
$classes .= ' no-select-all';
}
return $classes;
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* CMB taxonomy_multicheck_hierarchical field type
*
* @since 2.2.5
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Taxonomy_Multicheck_Hierarchical extends CMB2_Type_Taxonomy_Multicheck {
/**
* Parent term ID when looping hierarchical terms.
*
* @var integer
*/
protected $parent = 0;
public function render() {
return $this->rendered(
$this->types->radio( array(
'class' => $this->get_wrapper_classes(),
'options' => $this->get_term_options(),
), 'taxonomy_multicheck_hierarchical' )
);
}
protected function list_term_input( $term, $saved_terms ) {
$options = parent::list_term_input( $term, $saved_terms );
$children = $this->build_children( $term, $saved_terms );
if ( ! empty( $children ) ) {
$options .= $children;
}
return $options;
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* CMB taxonomy_radio field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Taxonomy_Radio extends CMB2_Type_Taxonomy_Base {
protected $counter = 0;
public function render() {
return $this->rendered(
$this->types->radio( array(
'options' => $this->get_term_options(),
), 'taxonomy_radio' )
);
}
protected function get_term_options() {
$all_terms = $this->get_terms();
if ( ! $all_terms || is_wp_error( $all_terms ) ) {
return $this->no_terms_result( $all_terms );
}
$saved_term = $this->get_object_term_or_default();
$option_none = $this->field->args( 'show_option_none' );
$options = '';
if ( ! empty( $option_none ) ) {
$field_id = $this->_id( '', false );
/**
* Default (option-none) taxonomy-radio value.
*
* @since 1.3.0
*
* @param string $option_none_value Default (option-none) taxonomy-radio value.
*/
$option_none_value = apply_filters( 'cmb2_taxonomy_radio_default_value', '' );
/**
* Default (option-none) taxonomy-radio value.
*
* The dynamic portion of the hook name, $field_id, refers to the field id attribute.
*
* @since 1.3.0
*
* @param string $option_none_value Default (option-none) taxonomy-radio value.
*/
$option_none_value = apply_filters( "cmb2_taxonomy_radio_{$field_id}_default_value", $option_none_value );
$options .= $this->list_term_input( (object) array(
'slug' => $option_none_value,
'name' => $option_none,
), $saved_term );
}
$options .= $this->loop_terms( $all_terms, $saved_term );
return $options;
}
protected function loop_terms( $all_terms, $saved_term ) {
$options = '';
foreach ( $all_terms as $term ) {
$options .= $this->list_term_input( $term, $saved_term );
}
return $options;
}
protected function list_term_input( $term, $saved_term ) {
$args = array(
'value' => $term->slug,
'label' => $term->name,
);
if ( $saved_term == $term->slug ) {
$args['checked'] = 'checked';
}
return $this->list_input( $args, ++$this->counter );
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* CMB taxonomy_radio_hierarchical field type
*
* @since 2.2.5
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Taxonomy_Radio_Hierarchical extends CMB2_Type_Taxonomy_Radio {
/**
* Parent term ID when looping hierarchical terms.
*
* @var integer
*/
protected $parent = 0;
public function render() {
return $this->rendered(
$this->types->radio( array(
'options' => $this->get_term_options(),
), 'taxonomy_radio_hierarchical' )
);
}
protected function list_term_input( $term, $saved_term ) {
$options = parent::list_term_input( $term, $saved_term );
$children = $this->build_children( $term, $saved_term );
if ( ! empty( $children ) ) {
$options .= $children;
}
return $options;
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* CMB taxonomy_select field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Taxonomy_Select extends CMB2_Type_Taxonomy_Base {
/**
* Current Term Object.
*
* @since 2.6.1
*
* @var null|WP_Term
*/
public $current_term = null;
/**
* Saved Term Object.
*
* @since 2.6.1
*
* @var null|WP_Term
*/
public $saved_term = null;
public function render() {
return $this->rendered(
$this->types->select( array(
'options' => $this->get_term_options(),
) )
);
}
protected function get_term_options() {
$all_terms = $this->get_terms();
if ( ! $all_terms || is_wp_error( $all_terms ) ) {
return $this->no_terms_result( $all_terms, 'strong' );
}
$this->saved_term = $this->get_object_term_or_default();
$option_none = $this->field->args( 'show_option_none' );
$options = '';
if ( ! empty( $option_none ) ) {
$field_id = $this->_id( '', false );
/**
* Default (option-none) taxonomy-select value.
*
* @since 1.3.0
*
* @param string $option_none_value Default (option-none) taxonomy-select value.
*/
$option_none_value = apply_filters( 'cmb2_taxonomy_select_default_value', '' );
/**
* Default (option-none) taxonomy-select value.
*
* The dynamic portion of the hook name, $field_id, refers to the field id attribute.
*
* @since 1.3.0
*
* @param string $option_none_value Default (option-none) taxonomy-select value.
*/
$option_none_value = apply_filters( "cmb2_taxonomy_select_{$field_id}_default_value", $option_none_value );
$options .= $this->select_option( array(
'label' => $option_none,
'value' => $option_none_value,
'checked' => $this->saved_term == $option_none_value,
) );
}
$options .= $this->loop_terms( $all_terms, $this->saved_term );
return $options;
}
protected function loop_terms( $all_terms, $saved_term ) {
$options = '';
foreach ( $all_terms as $term ) {
$this->current_term = $term;
$options .= $this->select_option( array(
'label' => $term->name,
'value' => $term->slug,
'checked' => $this->saved_term === $term->slug,
) );
}
return $options;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* CMB taxonomy_select_hierarchical field type
*
* @since 2.6.1
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Taxonomy_Select_Hierarchical extends CMB2_Type_Taxonomy_Select {
/**
* Parent term ID when looping hierarchical terms.
*
* @since 2.6.1
*
* @var integer
*/
protected $parent = 0;
/**
* Child loop depth.
*
* @since 2.6.1
*
* @var integer
*/
protected $level = 0;
public function render() {
return $this->rendered(
$this->types->select( array(
'options' => $this->get_term_options(),
), 'taxonomy_select_hierarchical' )
);
}
public function select_option( $args = array() ) {
if ( $this->level > 0 ) {
$args['label'] = str_repeat( '&nbsp;&nbsp;&nbsp;&nbsp;', $this->level ) . $args['label'];
}
$option = parent::select_option( $args );
$children = $this->build_children( $this->current_term, $this->saved_term );
if ( ! empty( $children ) ) {
$option .= $children;
}
return $option;
}
/**
* Build children hierarchy.
*
* @since 2.6.1
*
* @param array $terms Array of child terms.
* @param array|string $saved Array of terms set to the object, or single term slug.
*
* @return string Child option output.
*/
public function child_option_output( $terms, $saved ) {
$this->level++;
$output = $this->loop_terms( $terms, $saved );
$this->level--;
return $output;
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* CMB text field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Text extends CMB2_Type_Counter_Base {
/**
* The type of field
*
* @var string
*/
public $type = 'input';
/**
* Constructor
*
* @since 2.2.2
*
* @param CMB2_Types $types
* @param array $args
*/
public function __construct( CMB2_Types $types, $args = array(), $type = '' ) {
parent::__construct( $types, $args );
$this->type = $type ? $type : $this->type;
}
/**
* Handles outputting an 'input' element
*
* @since 1.1.0
* @param array $args Override arguments
* @return string Form input element
*/
public function render( $args = array() ) {
$args = empty( $args ) ? $this->args : $args;
$a = $this->parse_args( $this->type, array(
'type' => 'text',
'class' => 'regular-text',
'name' => $this->_name(),
'id' => $this->_id(),
'value' => $this->field->escaped_value(),
'desc' => $this->_desc( true ),
'js_dependencies' => array(),
), $args );
// Add character counter?
$a = $this->maybe_update_attributes_for_char_counter( $a );
return $this->rendered(
sprintf( '<input%s/>%s', $this->concat_attrs( $a, array( 'desc' ) ), $a['desc'] )
);
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* CMB text_date field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Text_Date extends CMB2_Type_Picker_Base {
public function render( $args = array() ) {
$args = $this->parse_args( 'text_date', array(
'class' => 'cmb2-text-small cmb2-datepicker',
'value' => $this->field->get_timestamp_format(),
'desc' => $this->_desc(),
'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker' ),
) );
if ( false === strpos( $args['class'], 'timepicker' ) ) {
$this->parse_picker_options( 'date' );
}
return parent::render( $args );
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* CMB text_datetime_timestamp field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Text_Datetime_Timestamp extends CMB2_Type_Picker_Base {
public function render( $args = array() ) {
$field = $this->field;
$value = $field->escaped_value();
if ( empty( $value ) ) {
$value = $field->get_default();
}
$args = wp_parse_args( $this->args, array(
'value' => $value,
'desc' => $this->_desc(),
'datepicker' => array(),
'timepicker' => array(),
) );
if ( empty( $args['value'] ) ) {
$args['value'] = $value;
// This will be used if there is a select_timezone set for this field
$tz_offset = $field->field_timezone_offset();
if ( ! empty( $tz_offset ) ) {
$args['value'] -= $tz_offset;
}
}
$has_good_value = ! empty( $args['value'] ) && ! is_array( $args['value'] );
$date_input = parent::render( $this->date_args( $args, $has_good_value ) );
$time_input = parent::render( $this->time_args( $args, $has_good_value ) );
return $this->rendered( $date_input . "\n" . $time_input );
}
public function date_args( $args, $has_good_value ) {
$date_args = wp_parse_args( $args['datepicker'], array(
'class' => 'cmb2-text-small cmb2-datepicker',
'name' => $this->_name( '[date]' ),
'id' => $this->_id( '_date' ),
'value' => $has_good_value ? $this->field->get_timestamp_format( 'date_format', $args['value'] ) : '',
'desc' => '',
) );
$date_args['rendered'] = true;
// Let's get the date-format, and set it up as a data attr for the field.
return $this->parse_picker_options( 'date', $date_args );
}
public function time_args( $args, $has_good_value ) {
$time_args = wp_parse_args( $args['timepicker'], array(
'class' => 'cmb2-timepicker text-time',
'name' => $this->_name( '[time]' ),
'id' => $this->_id( '_time' ),
'value' => $has_good_value ? $this->field->get_timestamp_format( 'time_format', $args['value'] ) : '',
'desc' => $args['desc'],
'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-datetimepicker' ),
) );
$time_args['rendered'] = true;
// Let's get the time-format, and set it up as a data attr for the field.
return $this->parse_picker_options( 'time', $time_args );
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* CMB text_datetime_timestamp_timezone field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Text_Datetime_Timestamp_Timezone extends CMB2_Type_Base {
public function render( $args = array() ) {
$field = $this->field;
$value = $field->escaped_value();
if ( empty( $value ) ) {
$value = $field->get_default();
}
$args = wp_parse_args( $this->args, array(
'value' => $value,
'desc' => $this->_desc( true ),
'text_datetime_timestamp' => array(),
'select_timezone' => array(),
) );
$args['value'] = $value;
if ( is_array( $args['value'] ) ) {
$args['value'] = '';
}
$datetime = maybe_unserialize( $args['value'] );
$value = $tzstring = '';
if ( $datetime && $datetime instanceof DateTime ) {
$tz = $datetime->getTimezone();
$tzstring = $tz->getName();
$value = $datetime->getTimestamp();
}
$timestamp_args = wp_parse_args( $args['text_datetime_timestamp'], array(
'desc' => '',
'value' => $value,
'rendered' => true,
) );
$datetime_timestamp = $this->types->text_datetime_timestamp( $timestamp_args );
$timezone_select_args = wp_parse_args( $args['select_timezone'], array(
'class' => 'cmb2_select cmb2-select-timezone',
'name' => $this->_name( '[timezone]' ),
'id' => $this->_id( '_timezone' ),
'options' => wp_timezone_choice( $tzstring ),
'desc' => $args['desc'],
'rendered' => true,
) );
$select = $this->types->select( $timezone_select_args );
return $this->rendered(
$datetime_timestamp . "\n" . $select
);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* CMB text_time field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Text_Time extends CMB2_Type_Text_Date {
public function render( $args = array() ) {
$this->args = $this->parse_picker_options( 'time', wp_parse_args( $this->args, array(
'class' => 'cmb2-timepicker text-time',
'value' => $this->field->get_timestamp_format( 'time_format' ),
'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-datetimepicker' ),
) ) );
return parent::render();
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* CMB textarea field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Textarea extends CMB2_Type_Counter_Base {
/**
* Handles outputting an 'textarea' element
*
* @since 1.1.0
* @param array $args Override arguments
* @return string Form textarea element
*/
public function render( $args = array() ) {
$args = empty( $args ) ? $this->args : $args;
$a = $this->parse_args( 'textarea', array(
'class' => 'cmb2_textarea',
'name' => $this->_name(),
'id' => $this->_id(),
'cols' => 60,
'rows' => 10,
'value' => $this->field->escaped_value( 'esc_textarea' ),
'desc' => $this->_desc( true ),
), $args );
// Add character counter?
$a = $this->maybe_update_attributes_for_char_counter( $a );
return $this->rendered(
sprintf( '<textarea%s>%s</textarea>%s', $this->concat_attrs( $a, array( 'desc', 'value' ) ), $a['value'], $a['desc'] )
);
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* CMB textarea_code field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Textarea_Code extends CMB2_Type_Textarea {
/**
* Handles outputting an 'textarea' element
*
* @since 1.1.0
* @param array $args Override arguments
* @return string Form textarea element
*/
public function render( $args = array() ) {
$args = wp_parse_args( $args, array(
'class' => 'cmb2-textarea-code',
'desc' => '</pre>' . $this->_desc( true ),
) );
if ( true !== $this->field->options( 'disable_codemirror' )
&& function_exists( 'wp_enqueue_code_editor' ) ) {
$args['js_dependencies'] = array( 'code-editor' );
} else {
$args['class'] = rtrim( $args['class'] ) . ' disable-codemirror';
}
return $this->rendered(
sprintf( '<pre>%s', parent::render( $args ) )
);
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* CMB title field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Type_Title extends CMB2_Type_Base {
/**
* Handles outputting an 'title' element
*
* @return string Heading element
*/
public function render() {
$name = $this->field->args( 'name' );
$tag = 'span';
if ( ! empty( $name ) ) {
$tag = $this->field->object_type == 'post' ? 'h5' : 'h3';
}
$a = $this->parse_args( 'title', array(
'tag' => $tag,
'class' => empty( $name ) ? 'cmb2-metabox-title-anchor' : 'cmb2-metabox-title',
'name' => $name,
'desc' => $this->_desc( true ),
'id' => str_replace( '_', '-', sanitize_html_class( $this->field->id() ) ),
) );
return $this->rendered(
sprintf(
'<%1$s %2$s>%3$s</%1$s>%4$s',
$a['tag'],
$this->concat_attrs( $a, array( 'tag', 'name', 'desc' ) ),
$a['name'],
$a['desc']
)
);
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* CMB wysiwyg field type
*
* @since 2.2.2
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*
* @method string _id()
* @method string _desc()
*/
class CMB2_Type_Wysiwyg extends CMB2_Type_Textarea {
/**
* Handles outputting a 'wysiwyg' element
* @since 1.1.0
* @return string Form wysiwyg element
*/
public function render( $args = array() ) {
$field = $this->field;
$a = $this->parse_args( 'wysiwyg', array(
'id' => $this->_id( '', false ),
'value' => $field->escaped_value( 'stripslashes' ),
'desc' => $this->_desc( true ),
'options' => $field->options(),
) );
if ( ! $field->group ) {
$a = $this->maybe_update_attributes_for_char_counter( $a );
if ( $this->has_counter ) {
$a['options']['editor_class'] = ! empty( $a['options']['editor_class'] )
? $a['options']['editor_class'] . ' cmb2-count-chars'
: 'cmb2-count-chars';
}
return $this->rendered( $this->get_wp_editor( $a ) . $a['desc'] );
}
// Character counter not currently working for grouped WYSIWYG
$this->field->args['char_counter'] = false;
// wysiwyg fields in a group need some special handling.
$field->add_js_dependencies( array( 'wp-util', 'cmb2-wysiwyg' ) );
// Hook in our template-output to the footer.
add_action( is_admin() ? 'admin_footer' : 'wp_footer', array( $this, 'add_wysiwyg_template_for_group' ) );
return $this->rendered(
sprintf( '<div class="cmb2-wysiwyg-wrap">%s', parent::render( array(
'class' => 'cmb2_textarea cmb2-wysiwyg-placeholder',
'data-groupid' => $field->group->id(),
'data-iterator' => $field->group->index,
'data-fieldid' => $field->id( true ),
'desc' => '</div>' . $this->_desc( true ),
) ) )
);
}
protected function get_wp_editor( $args ) {
ob_start();
wp_editor( $args['value'], $args['id'], $args['options'] );
return ob_get_clean();
}
public function add_wysiwyg_template_for_group() {
$group_id = $this->field->group->id();
$field_id = $this->field->id( true );
$hash = $this->field->hash_id();
$options = $this->field->options();
$options['textarea_name'] = 'cmb2_n_' . $group_id . $field_id;
// Initate the editor with special id/value/name so we can retrieve the options in JS.
$editor = $this->get_wp_editor( array(
'value' => 'cmb2_v_' . $group_id . $field_id,
'id' => 'cmb2_i_' . $group_id . $field_id,
'options' => $options,
) );
// Then replace the special id/value/name with underscore placeholders.
$editor = str_replace( array(
'cmb2_n_' . $group_id . $field_id,
'cmb2_v_' . $group_id . $field_id,
'cmb2_i_' . $group_id . $field_id,
), array(
'{{ data.name }}',
'{{{ data.value }}}',
'{{ data.id }}',
), $editor );
// And put the editor instance in a JS template wrapper.
echo '<script type="text/template" id="tmpl-cmb2-wysiwyg-' . $group_id . '-' . $field_id . '">';
// Need to wrap the template in a wrapper div w/ specific data attributes which will be used when adding/removing rows.
echo '<div class="cmb2-wysiwyg-inner-wrap" data-iterator="{{ data.iterator }}" data-groupid="' . $group_id . '" data-id="' . $field_id . '" data-hash="' . $hash . '">' . $editor . '</div>';
echo '</script>';
}
}

View File

@@ -0,0 +1 @@
<?php // Silence is golden.

View File

@@ -0,0 +1,198 @@
<?php
/**
* The initation loader for CMB2, and the main plugin file.
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*
* Plugin Name: CMB2
* Plugin URI: https://github.com/CMB2/CMB2
* Description: CMB2 will create metaboxes and forms with custom fields that will blow your mind.
* Author: CMB2 team
* Author URI: https://cmb2.io
* Contributors: Justin Sternberg (@jtsternberg / dsgnwrks.pro)
* WebDevStudios (@webdevstudios / webdevstudios.com)
* Human Made (@humanmadeltd / hmn.md)
* Jared Atchison (@jaredatch / jaredatchison.com)
* Bill Erickson (@billerickson / billerickson.net)
* Andrew Norcross (@norcross / andrewnorcross.com)
*
* Version: 2.10.1
*
* Text Domain: cmb2
* Domain Path: languages
*
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* https://wordpress.org/
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* **********************************************************************
*/
/**
* *********************************************************************
* You should not edit the code below
* (or any code in the included files)
* or things might explode!
* ***********************************************************************
*/
if ( ! class_exists( 'CMB2_Bootstrap_2101', false ) ) {
/**
* Handles checking for and loading the newest version of CMB2
*
* @since 2.0.0
*
* @category WordPress_Plugin
* @package CMB2
* @author CMB2 team
* @license GPL-2.0+
* @link https://cmb2.io
*/
class CMB2_Bootstrap_2101 {
/**
* Current version number
*
* @var string
* @since 1.0.0
*/
const VERSION = '2.10.1';
/**
* Current version hook priority.
* Will decrement with each release
*
* @var int
* @since 2.0.0
*/
const PRIORITY = 9957;
/**
* Single instance of the CMB2_Bootstrap_2101 object
*
* @var CMB2_Bootstrap_2101
*/
public static $single_instance = null;
/**
* Creates/returns the single instance CMB2_Bootstrap_2101 object
*
* @since 2.0.0
* @return CMB2_Bootstrap_2101 Single instance object
*/
public static function initiate() {
if ( null === self::$single_instance ) {
self::$single_instance = new self();
}
return self::$single_instance;
}
/**
* Starts the version checking process.
* Creates CMB2_LOADED definition for early detection by other scripts
*
* Hooks CMB2 inclusion to the init hook on a high priority which decrements
* (increasing the priority) with each version release.
*
* @since 2.0.0
*/
private function __construct() {
/**
* A constant you can use to check if CMB2 is loaded
* for your plugins/themes with CMB2 dependency
*/
if ( ! defined( 'CMB2_LOADED' ) ) {
define( 'CMB2_LOADED', self::PRIORITY );
}
if ( ! function_exists( 'add_action' ) ) {
// We are running outside of the context of WordPress.
return;
}
add_action( 'init', array( $this, 'include_cmb' ), self::PRIORITY );
}
/**
* A final check if CMB2 exists before kicking off our CMB2 loading.
* CMB2_VERSION and CMB2_DIR constants are set at this point.
*
* @since 2.0.0
*/
public function include_cmb() {
if ( class_exists( 'CMB2', false ) ) {
return;
}
if ( ! defined( 'CMB2_VERSION' ) ) {
define( 'CMB2_VERSION', self::VERSION );
}
if ( ! defined( 'CMB2_DIR' ) ) {
define( 'CMB2_DIR', trailingslashit( dirname( __FILE__ ) ) );
}
$this->l10ni18n();
// Include helper functions.
require_once CMB2_DIR . 'includes/CMB2_Base.php';
require_once CMB2_DIR . 'includes/CMB2.php';
require_once CMB2_DIR . 'includes/helper-functions.php';
// Now kick off the class autoloader.
spl_autoload_register( 'cmb2_autoload_classes' );
// Kick the whole thing off.
require_once( cmb2_dir( 'bootstrap.php' ) );
cmb2_bootstrap();
}
/**
* Registers CMB2 text domain path
*
* @since 2.0.0
*/
public function l10ni18n() {
$loaded = load_plugin_textdomain( 'cmb2', false, '/languages/' );
if ( ! $loaded ) {
$loaded = load_muplugin_textdomain( 'cmb2', '/languages/' );
}
if ( ! $loaded ) {
$loaded = load_theme_textdomain( 'cmb2', get_stylesheet_directory() . '/languages/' );
}
if ( ! $loaded ) {
$locale = apply_filters( 'plugin_locale', function_exists( 'determine_locale' ) ? determine_locale() : get_locale(), 'cmb2' );
$mofile = dirname( __FILE__ ) . '/languages/cmb2-' . $locale . '.mo';
load_textdomain( 'cmb2', $mofile );
}
}
}
// Make it so...
CMB2_Bootstrap_2101::initiate();
}// End if().

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,579 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see https://www.php-fig.org/psr/psr-0/
* @see https://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
/** @var \Closure(string):void */
private static $includeFile;
/** @var string|null */
private $vendorDir;
// PSR-4
/**
* @var array<string, array<string, int>>
*/
private $prefixLengthsPsr4 = array();
/**
* @var array<string, list<string>>
*/
private $prefixDirsPsr4 = array();
/**
* @var list<string>
*/
private $fallbackDirsPsr4 = array();
// PSR-0
/**
* List of PSR-0 prefixes
*
* Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
*
* @var array<string, array<string, list<string>>>
*/
private $prefixesPsr0 = array();
/**
* @var list<string>
*/
private $fallbackDirsPsr0 = array();
/** @var bool */
private $useIncludePath = false;
/**
* @var array<string, string>
*/
private $classMap = array();
/** @var bool */
private $classMapAuthoritative = false;
/**
* @var array<string, bool>
*/
private $missingClasses = array();
/** @var string|null */
private $apcuPrefix;
/**
* @var array<string, self>
*/
private static $registeredLoaders = array();
/**
* @param string|null $vendorDir
*/
public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
self::initializeIncludeClosure();
}
/**
* @return array<string, list<string>>
*/
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
}
return array();
}
/**
* @return array<string, list<string>>
*/
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
/**
* @return list<string>
*/
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
/**
* @return list<string>
*/
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
/**
* @return array<string, string> Array of classname => path
*/
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array<string, string> $classMap Class to filename map
*
* @return void
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param list<string>|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*
* @return void
*/
public function add($prefix, $paths, $prepend = false)
{
$paths = (array) $paths;
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
$paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
$paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
$paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param list<string>|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
$paths = (array) $paths;
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
$paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
$paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
$paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param list<string>|string $paths The PSR-0 base directories
*
* @return void
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param list<string>|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*
* @return void
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*
* @return void
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*
* @return void
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
if (null === $this->vendorDir) {
return;
}
if ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return true|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
$includeFile = self::$includeFile;
$includeFile($file);
return true;
}
return null;
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
/**
* Returns the currently registered loaders keyed by their corresponding vendor directories.
*
* @return array<string, self>
*/
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}
/**
* @param string $class
* @param string $ext
* @return string|false
*/
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
/**
* @return void
*/
private static function initializeIncludeClosure()
{
if (self::$includeFile !== null) {
return;
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*
* @param string $file
* @return void
*/
self::$includeFile = \Closure::bind(static function($file) {
include $file;
}, null, null);
}
}

View File

@@ -0,0 +1,359 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer;
use Composer\Autoload\ClassLoader;
use Composer\Semver\VersionParser;
/**
* This class is copied in every Composer installed project and available to all
*
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
*
* To require its presence, you can require `composer-runtime-api ^2.0`
*
* @final
*/
class InstalledVersions
{
/**
* @var mixed[]|null
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
*/
private static $installed;
/**
* @var bool|null
*/
private static $canGetVendors;
/**
* @var array[]
* @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
private static $installedByVendor = array();
/**
* Returns a list of all package names which are present, either by being installed, replaced or provided
*
* @return string[]
* @psalm-return list<string>
*/
public static function getInstalledPackages()
{
$packages = array();
foreach (self::getInstalled() as $installed) {
$packages[] = array_keys($installed['versions']);
}
if (1 === \count($packages)) {
return $packages[0];
}
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
}
/**
* Returns a list of all package names with a specific type e.g. 'library'
*
* @param string $type
* @return string[]
* @psalm-return list<string>
*/
public static function getInstalledPackagesByType($type)
{
$packagesByType = array();
foreach (self::getInstalled() as $installed) {
foreach ($installed['versions'] as $name => $package) {
if (isset($package['type']) && $package['type'] === $type) {
$packagesByType[] = $name;
}
}
}
return $packagesByType;
}
/**
* Checks whether the given package is installed
*
* This also returns true if the package name is provided or replaced by another package
*
* @param string $packageName
* @param bool $includeDevRequirements
* @return bool
*/
public static function isInstalled($packageName, $includeDevRequirements = true)
{
foreach (self::getInstalled() as $installed) {
if (isset($installed['versions'][$packageName])) {
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
}
}
return false;
}
/**
* Checks whether the given package satisfies a version constraint
*
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
*
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
*
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
* @param string $packageName
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
* @return bool
*/
public static function satisfies(VersionParser $parser, $packageName, $constraint)
{
$constraint = $parser->parseConstraints((string) $constraint);
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
return $provided->matches($constraint);
}
/**
* Returns a version constraint representing all the range(s) which are installed for a given package
*
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
* whether a given version of a package is installed, and not just whether it exists
*
* @param string $packageName
* @return string Version constraint usable with composer/semver
*/
public static function getVersionRanges($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
$ranges = array();
if (isset($installed['versions'][$packageName]['pretty_version'])) {
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
}
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
}
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
}
if (array_key_exists('provided', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
}
return implode(' || ', $ranges);
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
*/
public static function getVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['version'])) {
return null;
}
return $installed['versions'][$packageName]['version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
*/
public static function getPrettyVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
return null;
}
return $installed['versions'][$packageName]['pretty_version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
*/
public static function getReference($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['reference'])) {
return null;
}
return $installed['versions'][$packageName]['reference'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
*/
public static function getInstallPath($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @return array
* @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
*/
public static function getRootPackage()
{
$installed = self::getInstalled();
return $installed[0]['root'];
}
/**
* Returns the raw installed.php data for custom implementations
*
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
* @return array[]
* @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
*/
public static function getRawData()
{
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
self::$installed = include __DIR__ . '/installed.php';
} else {
self::$installed = array();
}
}
return self::$installed;
}
/**
* Returns the raw data of all installed.php which are currently loaded for custom implementations
*
* @return array[]
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
public static function getAllRawData()
{
return self::getInstalled();
}
/**
* Lets you reload the static array from another file
*
* This is only useful for complex integrations in which a project needs to use
* this class but then also needs to execute another project's autoloader in process,
* and wants to ensure both projects have access to their version of installed.php.
*
* A typical case would be PHPUnit, where it would need to make sure it reads all
* the data it needs from this class, then call reload() with
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
* the project in which it runs can then also use this class safely, without
* interference between PHPUnit's dependencies and the project's dependencies.
*
* @param array[] $data A vendor/composer/installed.php data set
* @return void
*
* @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
*/
public static function reload($data)
{
self::$installed = $data;
self::$installedByVendor = array();
}
/**
* @return array[]
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
private static function getInstalled()
{
if (null === self::$canGetVendors) {
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
}
$installed = array();
if (self::$canGetVendors) {
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
if (isset(self::$installedByVendor[$vendorDir])) {
$installed[] = self::$installedByVendor[$vendorDir];
} elseif (is_file($vendorDir.'/composer/installed.php')) {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require $vendorDir.'/composer/installed.php';
$installed[] = self::$installedByVendor[$vendorDir] = $required;
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
self::$installed = $installed[count($installed) - 1];
}
}
}
}
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require __DIR__ . '/installed.php';
self::$installed = $required;
} else {
self::$installed = array();
}
}
if (self::$installed !== array()) {
$installed[] = self::$installed;
}
return $installed;
}
}

View File

@@ -0,0 +1,21 @@
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,357 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'MyThemeShop\\Admin\\List_Table' => $vendorDir . '/mythemeshop/wordpress-helpers/src/admin/class-list-table.php',
'MyThemeShop\\Admin\\Page' => $vendorDir . '/mythemeshop/wordpress-helpers/src/admin/class-page.php',
'MyThemeShop\\Database\\Clauses' => $vendorDir . '/mythemeshop/wordpress-helpers/src/database/class-clauses.php',
'MyThemeShop\\Database\\Database' => $vendorDir . '/mythemeshop/wordpress-helpers/src/database/class-database.php',
'MyThemeShop\\Database\\Escape' => $vendorDir . '/mythemeshop/wordpress-helpers/src/database/class-escape.php',
'MyThemeShop\\Database\\GroupBy' => $vendorDir . '/mythemeshop/wordpress-helpers/src/database/class-groupby.php',
'MyThemeShop\\Database\\Joins' => $vendorDir . '/mythemeshop/wordpress-helpers/src/database/class-joins.php',
'MyThemeShop\\Database\\OrderBy' => $vendorDir . '/mythemeshop/wordpress-helpers/src/database/class-orderby.php',
'MyThemeShop\\Database\\Query_Builder' => $vendorDir . '/mythemeshop/wordpress-helpers/src/database/class-query-builder.php',
'MyThemeShop\\Database\\Select' => $vendorDir . '/mythemeshop/wordpress-helpers/src/database/class-select.php',
'MyThemeShop\\Database\\Translate' => $vendorDir . '/mythemeshop/wordpress-helpers/src/database/class-translate.php',
'MyThemeShop\\Database\\Where' => $vendorDir . '/mythemeshop/wordpress-helpers/src/database/class-where.php',
'MyThemeShop\\Helpers\\Arr' => $vendorDir . '/mythemeshop/wordpress-helpers/src/helpers/class-arr.php',
'MyThemeShop\\Helpers\\Attachment' => $vendorDir . '/mythemeshop/wordpress-helpers/src/helpers/class-attachment.php',
'MyThemeShop\\Helpers\\Conditional' => $vendorDir . '/mythemeshop/wordpress-helpers/src/helpers/class-conditional.php',
'MyThemeShop\\Helpers\\DB' => $vendorDir . '/mythemeshop/wordpress-helpers/src/helpers/class-db.php',
'MyThemeShop\\Helpers\\HTML' => $vendorDir . '/mythemeshop/wordpress-helpers/src/helpers/class-html.php',
'MyThemeShop\\Helpers\\Param' => $vendorDir . '/mythemeshop/wordpress-helpers/src/helpers/class-param.php',
'MyThemeShop\\Helpers\\Str' => $vendorDir . '/mythemeshop/wordpress-helpers/src/helpers/class-str.php',
'MyThemeShop\\Helpers\\Url' => $vendorDir . '/mythemeshop/wordpress-helpers/src/helpers/class-url.php',
'MyThemeShop\\Helpers\\WordPress' => $vendorDir . '/mythemeshop/wordpress-helpers/src/helpers/class-wordpress.php',
'MyThemeShop\\Json_Manager' => $vendorDir . '/mythemeshop/wordpress-helpers/src/class-json-manager.php',
'MyThemeShop\\Notification' => $vendorDir . '/mythemeshop/wordpress-helpers/src/class-notification.php',
'MyThemeShop\\Notification_Center' => $vendorDir . '/mythemeshop/wordpress-helpers/src/class-notification-center.php',
'RankMath\\ACF\\ACF' => $baseDir . '/includes/modules/acf/class-acf.php',
'RankMath\\Admin\\Admin' => $baseDir . '/includes/admin/class-admin.php',
'RankMath\\Admin\\Admin_Breadcrumbs' => $baseDir . '/includes/admin/class-admin-breadcrumbs.php',
'RankMath\\Admin\\Admin_Dashboard_Nav' => $baseDir . '/includes/admin/class-admin-dashboard-nav.php',
'RankMath\\Admin\\Admin_Header' => $baseDir . '/includes/admin/class-admin-header.php',
'RankMath\\Admin\\Admin_Helper' => $baseDir . '/includes/admin/class-admin-helper.php',
'RankMath\\Admin\\Admin_Init' => $baseDir . '/includes/admin/class-admin-init.php',
'RankMath\\Admin\\Admin_Menu' => $baseDir . '/includes/admin/class-admin-menu.php',
'RankMath\\Admin\\Api' => $baseDir . '/includes/admin/class-api.php',
'RankMath\\Admin\\Ask_Review' => $baseDir . '/includes/admin/class-ask-review.php',
'RankMath\\Admin\\Assets' => $baseDir . '/includes/admin/class-assets.php',
'RankMath\\Admin\\Bulk_Actions' => $baseDir . '/includes/admin/class-bulk-actions.php',
'RankMath\\Admin\\CMB2_Fields' => $baseDir . '/includes/admin/class-cmb2-fields.php',
'RankMath\\Admin\\Database\\Clauses' => $baseDir . '/includes/admin/database/class-clauses.php',
'RankMath\\Admin\\Database\\Database' => $baseDir . '/includes/admin/database/class-database.php',
'RankMath\\Admin\\Database\\Escape' => $baseDir . '/includes/admin/database/class-escape.php',
'RankMath\\Admin\\Database\\GroupBy' => $baseDir . '/includes/admin/database/class-groupby.php',
'RankMath\\Admin\\Database\\Joins' => $baseDir . '/includes/admin/database/class-joins.php',
'RankMath\\Admin\\Database\\OrderBy' => $baseDir . '/includes/admin/database/class-orderby.php',
'RankMath\\Admin\\Database\\Query_Builder' => $baseDir . '/includes/admin/database/class-query-builder.php',
'RankMath\\Admin\\Database\\Select' => $baseDir . '/includes/admin/database/class-select.php',
'RankMath\\Admin\\Database\\Translate' => $baseDir . '/includes/admin/database/class-translate.php',
'RankMath\\Admin\\Database\\Where' => $baseDir . '/includes/admin/database/class-where.php',
'RankMath\\Admin\\Import_Export' => $baseDir . '/includes/admin/class-import-export.php',
'RankMath\\Admin\\Importers\\AIOSEO' => $baseDir . '/includes/admin/importers/class-aioseo.php',
'RankMath\\Admin\\Importers\\AIO_Rich_Snippet' => $baseDir . '/includes/admin/importers/class-aio-rich-snippet.php',
'RankMath\\Admin\\Importers\\Detector' => $baseDir . '/includes/admin/importers/class-detector.php',
'RankMath\\Admin\\Importers\\Plugin_Importer' => $baseDir . '/includes/admin/importers/abstract-importer.php',
'RankMath\\Admin\\Importers\\Redirections' => $baseDir . '/includes/admin/importers/class-redirections.php',
'RankMath\\Admin\\Importers\\SEOPress' => $baseDir . '/includes/admin/importers/class-seopress.php',
'RankMath\\Admin\\Importers\\Status' => $baseDir . '/includes/admin/importers/class-status.php',
'RankMath\\Admin\\Importers\\WP_Schema_Pro' => $baseDir . '/includes/admin/importers/class-wp-schema-pro.php',
'RankMath\\Admin\\Importers\\Yoast' => $baseDir . '/includes/admin/importers/class-yoast.php',
'RankMath\\Admin\\List_Table' => $baseDir . '/includes/admin/class-list-table.php',
'RankMath\\Admin\\Metabox\\IScreen' => $baseDir . '/includes/admin/metabox/interface-screen.php',
'RankMath\\Admin\\Metabox\\Metabox' => $baseDir . '/includes/admin/metabox/class-metabox.php',
'RankMath\\Admin\\Metabox\\Post_Screen' => $baseDir . '/includes/admin/metabox/class-post-screen.php',
'RankMath\\Admin\\Metabox\\Screen' => $baseDir . '/includes/admin/metabox/class-screen.php',
'RankMath\\Admin\\Metabox\\Taxonomy_Screen' => $baseDir . '/includes/admin/metabox/class-taxonomy-screen.php',
'RankMath\\Admin\\Metabox\\User_Screen' => $baseDir . '/includes/admin/metabox/class-user-screen.php',
'RankMath\\Admin\\Notices' => $baseDir . '/includes/admin/class-notices.php',
'RankMath\\Admin\\Notifications\\Notification' => $baseDir . '/includes/admin/notifications/class-notification.php',
'RankMath\\Admin\\Notifications\\Notification_Center' => $baseDir . '/includes/admin/notifications/class-notification-center.php',
'RankMath\\Admin\\Option_Center' => $baseDir . '/includes/admin/class-option-center.php',
'RankMath\\Admin\\Options' => $baseDir . '/includes/admin/class-options.php',
'RankMath\\Admin\\Page' => $baseDir . '/includes/admin/class-page.php',
'RankMath\\Admin\\Post_Columns' => $baseDir . '/includes/admin/class-post-columns.php',
'RankMath\\Admin\\Post_Filters' => $baseDir . '/includes/admin/class-post-filters.php',
'RankMath\\Admin\\Pro_Notice' => $baseDir . '/includes/admin/class-pro-notice.php',
'RankMath\\Admin\\Registration' => $baseDir . '/includes/admin/class-registration.php',
'RankMath\\Admin\\Serp_Preview' => $baseDir . '/includes/admin/class-serp-preview.php',
'RankMath\\Admin\\Setup_Wizard' => $baseDir . '/includes/admin/class-setup-wizard.php',
'RankMath\\Admin\\Watcher' => $baseDir . '/includes/admin/watcher/class-watcher.php',
'RankMath\\Admin_Bar_Menu' => $baseDir . '/includes/admin/class-admin-bar-menu.php',
'RankMath\\Analytics\\AJAX' => $baseDir . '/includes/modules/analytics/class-ajax.php',
'RankMath\\Analytics\\Analytics' => $baseDir . '/includes/modules/analytics/class-analytics.php',
'RankMath\\Analytics\\Analytics_Common' => $baseDir . '/includes/modules/analytics/class-analytics-common.php',
'RankMath\\Analytics\\Analytics_Stats' => $baseDir . '/includes/modules/analytics/class-analytics-stats.php',
'RankMath\\Analytics\\DB' => $baseDir . '/includes/modules/analytics/class-db.php',
'RankMath\\Analytics\\Email_Reports' => $baseDir . '/includes/modules/analytics/class-email-reports.php',
'RankMath\\Analytics\\GTag' => $baseDir . '/includes/modules/analytics/class-gtag.php',
'RankMath\\Analytics\\Keywords' => $baseDir . '/includes/modules/analytics/class-keywords.php',
'RankMath\\Analytics\\Objects' => $baseDir . '/includes/modules/analytics/class-objects.php',
'RankMath\\Analytics\\Posts' => $baseDir . '/includes/modules/analytics/class-posts.php',
'RankMath\\Analytics\\Rest' => $baseDir . '/includes/modules/analytics/rest/class-rest.php',
'RankMath\\Analytics\\Stats' => $baseDir . '/includes/modules/analytics/class-stats.php',
'RankMath\\Analytics\\Summary' => $baseDir . '/includes/modules/analytics/class-summary.php',
'RankMath\\Analytics\\Url_Inspection' => $baseDir . '/includes/modules/analytics/class-url-inspection.php',
'RankMath\\Analytics\\Watcher' => $baseDir . '/includes/modules/analytics/class-watcher.php',
'RankMath\\Analytics\\Workflow\\Base' => $baseDir . '/includes/modules/analytics/workflows/class-base.php',
'RankMath\\Analytics\\Workflow\\Console' => $baseDir . '/includes/modules/analytics/workflows/class-console.php',
'RankMath\\Analytics\\Workflow\\Inspections' => $baseDir . '/includes/modules/analytics/workflows/class-inspections.php',
'RankMath\\Analytics\\Workflow\\Jobs' => $baseDir . '/includes/modules/analytics/workflows/class-jobs.php',
'RankMath\\Analytics\\Workflow\\OAuth' => $baseDir . '/includes/modules/analytics/workflows/class-oauth.php',
'RankMath\\Analytics\\Workflow\\Objects' => $baseDir . '/includes/modules/analytics/workflows/class-objects.php',
'RankMath\\Analytics\\Workflow\\Workflow' => $baseDir . '/includes/modules/analytics/workflows/class-workflow.php',
'RankMath\\Auto_Updater' => $baseDir . '/includes/class-auto-updater.php',
'RankMath\\Beta_Optin' => $baseDir . '/includes/modules/version-control/class-beta-optin.php',
'RankMath\\BuddyPress\\Admin' => $baseDir . '/includes/modules/buddypress/class-admin.php',
'RankMath\\BuddyPress\\BuddyPress' => $baseDir . '/includes/modules/buddypress/class-buddypress.php',
'RankMath\\CLI\\Commands' => $baseDir . '/includes/cli/class-commands.php',
'RankMath\\CMB2' => $baseDir . '/includes/class-cmb2.php',
'RankMath\\Common' => $baseDir . '/includes/class-common.php',
'RankMath\\Compatibility' => $baseDir . '/includes/class-compatibility.php',
'RankMath\\ContentAI\\Block_Command' => $baseDir . '/includes/modules/content-ai/blocks/command/class-block-command.php',
'RankMath\\ContentAI\\Bulk_Actions' => $baseDir . '/includes/modules/content-ai/class-bulk-actions.php',
'RankMath\\ContentAI\\Bulk_Edit_SEO_Meta' => $baseDir . '/includes/modules/content-ai/class-bulk-edit-seo-meta.php',
'RankMath\\ContentAI\\Content_AI' => $baseDir . '/includes/modules/content-ai/class-content-ai.php',
'RankMath\\ContentAI\\Content_AI_Page' => $baseDir . '/includes/modules/content-ai/class-content-ai-page.php',
'RankMath\\ContentAI\\Event_Scheduler' => $baseDir . '/includes/modules/content-ai/class-event-scheduler.php',
'RankMath\\ContentAI\\Rest' => $baseDir . '/includes/modules/content-ai/class-rest.php',
'RankMath\\Dashboard_Widget' => $baseDir . '/includes/admin/class-dashboard-widget.php',
'RankMath\\Data_Encryption' => $baseDir . '/includes/class-data-encryption.php',
'RankMath\\Defaults' => $baseDir . '/includes/class-defaults.php',
'RankMath\\Divi\\Divi' => $baseDir . '/includes/3rdparty/divi/class-divi.php',
'RankMath\\Divi\\Divi_Admin' => $baseDir . '/includes/3rdparty/divi/class-divi-admin.php',
'RankMath\\Elementor\\Elementor' => $baseDir . '/includes/3rdparty/elementor/class-elementor.php',
'RankMath\\Frontend\\Breadcrumbs' => $baseDir . '/includes/frontend/class-breadcrumbs.php',
'RankMath\\Frontend\\Comments' => $baseDir . '/includes/frontend/class-comments.php',
'RankMath\\Frontend\\Frontend' => $baseDir . '/includes/frontend/class-frontend.php',
'RankMath\\Frontend\\Head' => $baseDir . '/includes/frontend/class-head.php',
'RankMath\\Frontend\\Link_Attributes' => $baseDir . '/includes/frontend/class-link-attributes.php',
'RankMath\\Frontend\\Redirection' => $baseDir . '/includes/frontend/class-redirection.php',
'RankMath\\Frontend\\Shortcodes' => $baseDir . '/includes/frontend/class-shortcodes.php',
'RankMath\\Frontend_SEO_Score' => $baseDir . '/includes/class-frontend-seo-score.php',
'RankMath\\Google\\Analytics' => $baseDir . '/includes/modules/analytics/google/class-analytics.php',
'RankMath\\Google\\Api' => $baseDir . '/includes/modules/analytics/google/class-api.php',
'RankMath\\Google\\Authentication' => $baseDir . '/includes/modules/analytics/google/class-authentication.php',
'RankMath\\Google\\Console' => $baseDir . '/includes/modules/analytics/google/class-console.php',
'RankMath\\Google\\Permissions' => $baseDir . '/includes/modules/analytics/google/class-permissions.php',
'RankMath\\Google\\Request' => $baseDir . '/includes/modules/analytics/google/class-request.php',
'RankMath\\Google\\Url_Inspection' => $baseDir . '/includes/modules/analytics/google/class-url-inspection.php',
'RankMath\\Helper' => $baseDir . '/includes/class-helper.php',
'RankMath\\Helpers\\Analytics' => $baseDir . '/includes/helpers/class-analytics.php',
'RankMath\\Helpers\\Api' => $baseDir . '/includes/helpers/class-api.php',
'RankMath\\Helpers\\Arr' => $baseDir . '/includes/helpers/class-arr.php',
'RankMath\\Helpers\\Attachment' => $baseDir . '/includes/helpers/class-attachment.php',
'RankMath\\Helpers\\Choices' => $baseDir . '/includes/helpers/class-choices.php',
'RankMath\\Helpers\\Conditional' => $baseDir . '/includes/helpers/class-conditional.php',
'RankMath\\Helpers\\Content_AI' => $baseDir . '/includes/helpers/class-content-ai.php',
'RankMath\\Helpers\\DB' => $baseDir . '/includes/helpers/class-db.php',
'RankMath\\Helpers\\Editor' => $baseDir . '/includes/helpers/class-editor.php',
'RankMath\\Helpers\\HTML' => $baseDir . '/includes/helpers/class-html.php',
'RankMath\\Helpers\\Locale' => $baseDir . '/includes/helpers/class-locale.php',
'RankMath\\Helpers\\Options' => $baseDir . '/includes/helpers/class-options.php',
'RankMath\\Helpers\\Param' => $baseDir . '/includes/helpers/class-param.php',
'RankMath\\Helpers\\Post_Type' => $baseDir . '/includes/helpers/class-post-type.php',
'RankMath\\Helpers\\Schema' => $baseDir . '/includes/helpers/class-schema.php',
'RankMath\\Helpers\\Security' => $baseDir . '/includes/helpers/class-security.php',
'RankMath\\Helpers\\Sitepress' => $baseDir . '/includes/helpers/class-sitepress.php',
'RankMath\\Helpers\\Str' => $baseDir . '/includes/helpers/class-str.php',
'RankMath\\Helpers\\Taxonomy' => $baseDir . '/includes/helpers/class-taxonomy.php',
'RankMath\\Helpers\\Url' => $baseDir . '/includes/helpers/class-url.php',
'RankMath\\Helpers\\WordPress' => $baseDir . '/includes/helpers/class-wordpress.php',
'RankMath\\Image_Seo\\Add_Attributes' => $baseDir . '/includes/modules/image-seo/class-add-attributes.php',
'RankMath\\Image_Seo\\Admin' => $baseDir . '/includes/modules/image-seo/class-admin.php',
'RankMath\\Image_Seo\\Image_Seo' => $baseDir . '/includes/modules/image-seo/class-image-seo.php',
'RankMath\\Installer' => $baseDir . '/includes/class-installer.php',
'RankMath\\Instant_Indexing\\Api' => $baseDir . '/includes/modules/instant-indexing/class-api.php',
'RankMath\\Instant_Indexing\\Instant_Indexing' => $baseDir . '/includes/modules/instant-indexing/class-instant-indexing.php',
'RankMath\\Instant_Indexing\\Rest' => $baseDir . '/includes/modules/instant-indexing/class-rest.php',
'RankMath\\Json_Manager' => $baseDir . '/includes/class-json-manager.php',
'RankMath\\KB' => $baseDir . '/includes/class-kb.php',
'RankMath\\Links\\ContentProcessor' => $baseDir . '/includes/modules/links/class-contentprocessor.php',
'RankMath\\Links\\Link' => $baseDir . '/includes/modules/links/class-link.php',
'RankMath\\Links\\Links' => $baseDir . '/includes/modules/links/class-links.php',
'RankMath\\Links\\Storage' => $baseDir . '/includes/modules/links/class-storage.php',
'RankMath\\Local_Seo\\KML_File' => $baseDir . '/includes/modules/local-seo/class-kml-file.php',
'RankMath\\Local_Seo\\Local_Seo' => $baseDir . '/includes/modules/local-seo/class-local-seo.php',
'RankMath\\Metadata' => $baseDir . '/includes/class-metadata.php',
'RankMath\\Module\\Base' => $baseDir . '/includes/module/class-base.php',
'RankMath\\Module\\Manager' => $baseDir . '/includes/module/class-manager.php',
'RankMath\\Module\\Module' => $baseDir . '/includes/module/class-module.php',
'RankMath\\Monitor\\Admin' => $baseDir . '/includes/modules/404-monitor/class-admin.php',
'RankMath\\Monitor\\DB' => $baseDir . '/includes/modules/404-monitor/class-db.php',
'RankMath\\Monitor\\Monitor' => $baseDir . '/includes/modules/404-monitor/class-monitor.php',
'RankMath\\Monitor\\Table' => $baseDir . '/includes/modules/404-monitor/class-table.php',
'RankMath\\OpenGraph\\Facebook' => $baseDir . '/includes/opengraph/class-facebook.php',
'RankMath\\OpenGraph\\Facebook_Locale' => $baseDir . '/includes/opengraph/class-facebook-locale.php',
'RankMath\\OpenGraph\\Image' => $baseDir . '/includes/opengraph/class-image.php',
'RankMath\\OpenGraph\\OpenGraph' => $baseDir . '/includes/opengraph/class-opengraph.php',
'RankMath\\OpenGraph\\Slack' => $baseDir . '/includes/opengraph/class-slack.php',
'RankMath\\OpenGraph\\Twitter' => $baseDir . '/includes/opengraph/class-twitter.php',
'RankMath\\Paper\\Archive' => $baseDir . '/includes/frontend/paper/class-archive.php',
'RankMath\\Paper\\Author' => $baseDir . '/includes/frontend/paper/class-author.php',
'RankMath\\Paper\\BP_Group' => $baseDir . '/includes/modules/buddypress/paper/class-bp-group.php',
'RankMath\\Paper\\BP_User' => $baseDir . '/includes/modules/buddypress/paper/class-bp-user.php',
'RankMath\\Paper\\Blog' => $baseDir . '/includes/frontend/paper/class-blog.php',
'RankMath\\Paper\\Date' => $baseDir . '/includes/frontend/paper/class-date.php',
'RankMath\\Paper\\Error_404' => $baseDir . '/includes/frontend/paper/class-error-404.php',
'RankMath\\Paper\\IPaper' => $baseDir . '/includes/frontend/paper/interface-paper.php',
'RankMath\\Paper\\Misc' => $baseDir . '/includes/frontend/paper/class-misc.php',
'RankMath\\Paper\\Paper' => $baseDir . '/includes/frontend/paper/class-paper.php',
'RankMath\\Paper\\Search' => $baseDir . '/includes/frontend/paper/class-search.php',
'RankMath\\Paper\\Shop' => $baseDir . '/includes/frontend/paper/class-shop.php',
'RankMath\\Paper\\Singular' => $baseDir . '/includes/frontend/paper/class-singular.php',
'RankMath\\Paper\\Taxonomy' => $baseDir . '/includes/frontend/paper/class-taxonomy.php',
'RankMath\\Post' => $baseDir . '/includes/class-post.php',
'RankMath\\Redirections\\Admin' => $baseDir . '/includes/modules/redirections/class-admin.php',
'RankMath\\Redirections\\Cache' => $baseDir . '/includes/modules/redirections/class-cache.php',
'RankMath\\Redirections\\DB' => $baseDir . '/includes/modules/redirections/class-db.php',
'RankMath\\Redirections\\Debugger' => $baseDir . '/includes/modules/redirections/class-debugger.php',
'RankMath\\Redirections\\Export' => $baseDir . '/includes/modules/redirections/class-export.php',
'RankMath\\Redirections\\Form' => $baseDir . '/includes/modules/redirections/class-form.php',
'RankMath\\Redirections\\Import_Export' => $baseDir . '/includes/modules/redirections/class-import-export.php',
'RankMath\\Redirections\\Metabox' => $baseDir . '/includes/modules/redirections/class-metabox.php',
'RankMath\\Redirections\\Redirection' => $baseDir . '/includes/modules/redirections/class-redirection.php',
'RankMath\\Redirections\\Redirections' => $baseDir . '/includes/modules/redirections/class-redirections.php',
'RankMath\\Redirections\\Redirector' => $baseDir . '/includes/modules/redirections/class-redirector.php',
'RankMath\\Redirections\\Table' => $baseDir . '/includes/modules/redirections/class-table.php',
'RankMath\\Redirections\\Watcher' => $baseDir . '/includes/modules/redirections/class-watcher.php',
'RankMath\\Replace_Variables\\Advanced_Variables' => $baseDir . '/includes/replace-variables/class-advanced-variables.php',
'RankMath\\Replace_Variables\\Author_Variables' => $baseDir . '/includes/replace-variables/class-author-variables.php',
'RankMath\\Replace_Variables\\Base' => $baseDir . '/includes/replace-variables/class-base.php',
'RankMath\\Replace_Variables\\Basic_Variables' => $baseDir . '/includes/replace-variables/class-basic-variables.php',
'RankMath\\Replace_Variables\\Cache' => $baseDir . '/includes/replace-variables/class-cache.php',
'RankMath\\Replace_Variables\\Manager' => $baseDir . '/includes/replace-variables/class-manager.php',
'RankMath\\Replace_Variables\\Post_Variables' => $baseDir . '/includes/replace-variables/class-post-variables.php',
'RankMath\\Replace_Variables\\Replacer' => $baseDir . '/includes/replace-variables/class-replacer.php',
'RankMath\\Replace_Variables\\Term_Variables' => $baseDir . '/includes/replace-variables/class-term-variables.php',
'RankMath\\Replace_Variables\\Variable' => $baseDir . '/includes/replace-variables/class-variable.php',
'RankMath\\Rest\\Admin' => $baseDir . '/includes/rest/class-admin.php',
'RankMath\\Rest\\Front' => $baseDir . '/includes/rest/class-front.php',
'RankMath\\Rest\\Headless' => $baseDir . '/includes/rest/class-headless.php',
'RankMath\\Rest\\Post' => $baseDir . '/includes/rest/class-post.php',
'RankMath\\Rest\\Rest_Helper' => $baseDir . '/includes/rest/class-rest-helper.php',
'RankMath\\Rest\\Sanitize' => $baseDir . '/includes/rest/class-sanitize.php',
'RankMath\\Rest\\Shared' => $baseDir . '/includes/rest/class-shared.php',
'RankMath\\Rewrite' => $baseDir . '/includes/class-rewrite.php',
'RankMath\\Robots_Txt' => $baseDir . '/includes/modules/robots-txt/class-robots-txt.php',
'RankMath\\Role_Manager\\Capability_Manager' => $baseDir . '/includes/modules/role-manager/class-capability-manager.php',
'RankMath\\Role_Manager\\Members' => $baseDir . '/includes/modules/role-manager/class-members.php',
'RankMath\\Role_Manager\\Role_Manager' => $baseDir . '/includes/modules/role-manager/class-role-manager.php',
'RankMath\\Role_Manager\\User_Role_Editor' => $baseDir . '/includes/modules/role-manager/class-user-role-editor.php',
'RankMath\\Rollback_Version' => $baseDir . '/includes/modules/version-control/class-rollback-version.php',
'RankMath\\Runner' => $baseDir . '/includes/interface-runner.php',
'RankMath\\SEO_Analysis\\Admin' => $baseDir . '/includes/modules/seo-analysis/class-admin.php',
'RankMath\\SEO_Analysis\\Admin_Tabs' => $baseDir . '/includes/modules/seo-analysis/class-admin-tabs.php',
'RankMath\\SEO_Analysis\\Result' => $baseDir . '/includes/modules/seo-analysis/class-result.php',
'RankMath\\SEO_Analysis\\SEO_Analysis' => $baseDir . '/includes/modules/seo-analysis/class-seo-analysis.php',
'RankMath\\SEO_Analysis\\SEO_Analyzer' => $baseDir . '/includes/modules/seo-analysis/class-seo-analyzer.php',
'RankMath\\Schema\\Admin' => $baseDir . '/includes/modules/schema/class-admin.php',
'RankMath\\Schema\\Article' => $baseDir . '/includes/modules/schema/snippets/class-article.php',
'RankMath\\Schema\\Author' => $baseDir . '/includes/modules/schema/snippets/class-author.php',
'RankMath\\Schema\\Block' => $baseDir . '/includes/modules/schema/blocks/class-block.php',
'RankMath\\Schema\\Block_FAQ' => $baseDir . '/includes/modules/schema/blocks/class-block-faq.php',
'RankMath\\Schema\\Block_HowTo' => $baseDir . '/includes/modules/schema/blocks/class-block-howto.php',
'RankMath\\Schema\\Block_Parser' => $baseDir . '/includes/modules/schema/blocks/class-block-parser.php',
'RankMath\\Schema\\Block_TOC' => $baseDir . '/includes/modules/schema/blocks/toc/class-block-toc.php',
'RankMath\\Schema\\Blocks' => $baseDir . '/includes/modules/schema/class-blocks.php',
'RankMath\\Schema\\Blocks\\Admin' => $baseDir . '/includes/modules/schema/blocks/class-admin.php',
'RankMath\\Schema\\Breadcrumbs' => $baseDir . '/includes/modules/schema/snippets/class-breadcrumbs.php',
'RankMath\\Schema\\DB' => $baseDir . '/includes/modules/schema/class-db.php',
'RankMath\\Schema\\Frontend' => $baseDir . '/includes/modules/schema/class-frontend.php',
'RankMath\\Schema\\JsonLD' => $baseDir . '/includes/modules/schema/class-jsonld.php',
'RankMath\\Schema\\Opengraph' => $baseDir . '/includes/modules/schema/class-opengraph.php',
'RankMath\\Schema\\PrimaryImage' => $baseDir . '/includes/modules/schema/snippets/class-primaryimage.php',
'RankMath\\Schema\\Product' => $baseDir . '/includes/modules/schema/snippets/class-product.php',
'RankMath\\Schema\\Product_Edd' => $baseDir . '/includes/modules/schema/snippets/class-product-edd.php',
'RankMath\\Schema\\Product_WooCommerce' => $baseDir . '/includes/modules/schema/snippets/class-product-woocommerce.php',
'RankMath\\Schema\\Products_Page' => $baseDir . '/includes/modules/schema/snippets/class-products-page.php',
'RankMath\\Schema\\Publisher' => $baseDir . '/includes/modules/schema/snippets/class-publisher.php',
'RankMath\\Schema\\Schema' => $baseDir . '/includes/modules/schema/class-schema.php',
'RankMath\\Schema\\Singular' => $baseDir . '/includes/modules/schema/snippets/class-singular.php',
'RankMath\\Schema\\Snippet' => $baseDir . '/includes/modules/schema/interface-snippet.php',
'RankMath\\Schema\\Snippet_Shortcode' => $baseDir . '/includes/modules/schema/class-snippet-shortcode.php',
'RankMath\\Schema\\WC_Attributes' => $baseDir . '/includes/modules/schema/snippets/class-wc-attributes.php',
'RankMath\\Schema\\Webpage' => $baseDir . '/includes/modules/schema/snippets/class-webpage.php',
'RankMath\\Schema\\Website' => $baseDir . '/includes/modules/schema/snippets/class-website.php',
'RankMath\\Settings' => $baseDir . '/includes/class-settings.php',
'RankMath\\Sitemap\\Admin' => $baseDir . '/includes/modules/sitemap/class-admin.php',
'RankMath\\Sitemap\\Cache' => $baseDir . '/includes/modules/sitemap/class-cache.php',
'RankMath\\Sitemap\\Cache_Watcher' => $baseDir . '/includes/modules/sitemap/class-cache-watcher.php',
'RankMath\\Sitemap\\Classifier' => $baseDir . '/includes/modules/sitemap/class-classifier.php',
'RankMath\\Sitemap\\Generator' => $baseDir . '/includes/modules/sitemap/class-generator.php',
'RankMath\\Sitemap\\Html\\Authors' => $baseDir . '/includes/modules/sitemap/html-sitemap/class-authors.php',
'RankMath\\Sitemap\\Html\\Posts' => $baseDir . '/includes/modules/sitemap/html-sitemap/class-posts.php',
'RankMath\\Sitemap\\Html\\Sitemap' => $baseDir . '/includes/modules/sitemap/html-sitemap/class-sitemap.php',
'RankMath\\Sitemap\\Html\\Terms' => $baseDir . '/includes/modules/sitemap/html-sitemap/class-terms.php',
'RankMath\\Sitemap\\Image_Parser' => $baseDir . '/includes/modules/sitemap/class-image-parser.php',
'RankMath\\Sitemap\\Providers\\Author' => $baseDir . '/includes/modules/sitemap/providers/class-author.php',
'RankMath\\Sitemap\\Providers\\Post_Type' => $baseDir . '/includes/modules/sitemap/providers/class-post-type.php',
'RankMath\\Sitemap\\Providers\\Provider' => $baseDir . '/includes/modules/sitemap/providers/interface-provider.php',
'RankMath\\Sitemap\\Providers\\Taxonomy' => $baseDir . '/includes/modules/sitemap/providers/class-taxonomy.php',
'RankMath\\Sitemap\\Redirect_Core_Sitemaps' => $baseDir . '/includes/modules/sitemap/class-redirect-core-sitemaps.php',
'RankMath\\Sitemap\\Router' => $baseDir . '/includes/modules/sitemap/class-router.php',
'RankMath\\Sitemap\\Sitemap' => $baseDir . '/includes/modules/sitemap/class-sitemap.php',
'RankMath\\Sitemap\\Sitemap_Index' => $baseDir . '/includes/modules/sitemap/class-sitemap-index.php',
'RankMath\\Sitemap\\Sitemap_XML' => $baseDir . '/includes/modules/sitemap/class-sitemap-xml.php',
'RankMath\\Sitemap\\Stylesheet' => $baseDir . '/includes/modules/sitemap/class-stylesheet.php',
'RankMath\\Sitemap\\Timezone' => $baseDir . '/includes/modules/sitemap/class-timezone.php',
'RankMath\\Sitemap\\XML' => $baseDir . '/includes/modules/sitemap/abstract-xml.php',
'RankMath\\Status\\Error_Log' => $baseDir . '/includes/modules/status/class-error-log.php',
'RankMath\\Status\\Status' => $baseDir . '/includes/modules/status/class-status.php',
'RankMath\\Status\\System_Status' => $baseDir . '/includes/modules/status/class-system-status.php',
'RankMath\\Term' => $baseDir . '/includes/class-term.php',
'RankMath\\Thumbnail_Overlay' => $baseDir . '/includes/class-thumbnail-overlay.php',
'RankMath\\Tools\\AIOSEO_Blocks' => $baseDir . '/includes/modules/database-tools/class-aioseo-blocks.php',
'RankMath\\Tools\\AIOSEO_TOC_Converter' => $baseDir . '/includes/modules/database-tools/class-aioseo-toc-converter.php',
'RankMath\\Tools\\Database_Tools' => $baseDir . '/includes/modules/database-tools/class-database-tools.php',
'RankMath\\Tools\\Remove_Schema' => $baseDir . '/includes/modules/database-tools/class-remove-schema.php',
'RankMath\\Tools\\Update_Score' => $baseDir . '/includes/modules/database-tools/class-update-score.php',
'RankMath\\Tools\\Yoast_Blocks' => $baseDir . '/includes/modules/database-tools/class-yoast-blocks.php',
'RankMath\\Tools\\Yoast_FAQ_Converter' => $baseDir . '/includes/modules/database-tools/class-yoast-faq-converter.php',
'RankMath\\Tools\\Yoast_HowTo_Converter' => $baseDir . '/includes/modules/database-tools/class-yoast-howto-converter.php',
'RankMath\\Tools\\Yoast_Local_Converter' => $baseDir . '/includes/modules/database-tools/class-yoast-local-converter.php',
'RankMath\\Tools\\Yoast_TOC_Converter' => $baseDir . '/includes/modules/database-tools/class-yoast-toc-converter.php',
'RankMath\\Traits\\Ajax' => $baseDir . '/includes/traits/class-ajax.php',
'RankMath\\Traits\\Cache' => $baseDir . '/includes/traits/class-cache.php',
'RankMath\\Traits\\Hooker' => $baseDir . '/includes/traits/class-hooker.php',
'RankMath\\Traits\\Meta' => $baseDir . '/includes/traits/class-meta.php',
'RankMath\\Traits\\Shortcode' => $baseDir . '/includes/traits/class-shortcode.php',
'RankMath\\Traits\\Wizard' => $baseDir . '/includes/traits/class-wizard.php',
'RankMath\\Update_Email' => $baseDir . '/includes/class-update-email.php',
'RankMath\\Updates' => $baseDir . '/includes/class-updates.php',
'RankMath\\User' => $baseDir . '/includes/class-user.php',
'RankMath\\Version_Control' => $baseDir . '/includes/modules/version-control/class-version-control.php',
'RankMath\\Web_Stories\\Web_Stories' => $baseDir . '/includes/modules/web-stories/class-web-stories.php',
'RankMath\\Wizard\\Compatibility' => $baseDir . '/includes/admin/wizard/class-compatibility.php',
'RankMath\\Wizard\\Import' => $baseDir . '/includes/admin/wizard/class-import.php',
'RankMath\\Wizard\\Monitor_Redirection' => $baseDir . '/includes/admin/wizard/class-monitor-redirection.php',
'RankMath\\Wizard\\Optimization' => $baseDir . '/includes/admin/wizard/class-optimization.php',
'RankMath\\Wizard\\Ready' => $baseDir . '/includes/admin/wizard/class-ready.php',
'RankMath\\Wizard\\Role' => $baseDir . '/includes/admin/wizard/class-role.php',
'RankMath\\Wizard\\Schema_Markup' => $baseDir . '/includes/admin/wizard/class-schema-markup.php',
'RankMath\\Wizard\\Search_Console' => $baseDir . '/includes/admin/wizard/class-search-console.php',
'RankMath\\Wizard\\Sitemap' => $baseDir . '/includes/admin/wizard/class-sitemap.php',
'RankMath\\Wizard\\Wizard_Step' => $baseDir . '/includes/admin/wizard/interface-wizard-step.php',
'RankMath\\Wizard\\Your_Site' => $baseDir . '/includes/admin/wizard/class-your-site.php',
'RankMath\\WooCommerce\\Admin' => $baseDir . '/includes/modules/woocommerce/class-admin.php',
'RankMath\\WooCommerce\\Opengraph' => $baseDir . '/includes/modules/woocommerce/class-opengraph.php',
'RankMath\\WooCommerce\\Permalink_Watcher' => $baseDir . '/includes/modules/woocommerce/class-permalink-watcher.php',
'RankMath\\WooCommerce\\Product_Redirection' => $baseDir . '/includes/modules/woocommerce/class-product-redirection.php',
'RankMath\\WooCommerce\\Sitemap' => $baseDir . '/includes/modules/woocommerce/class-sitemap.php',
'RankMath\\WooCommerce\\WC_Vars' => $baseDir . '/includes/modules/woocommerce/class-wc-vars.php',
'RankMath\\WooCommerce\\WooCommerce' => $baseDir . '/includes/modules/woocommerce/class-woocommerce.php',
'WP_Async_Request' => $vendorDir . '/a5hleyrich/wp-background-processing/classes/wp-async-request.php',
'WP_Background_Process' => $vendorDir . '/a5hleyrich/wp-background-processing/classes/wp-background-process.php',
'donatj\\UserAgent\\Browsers' => $vendorDir . '/donatj/phpuseragentparser/src/UserAgent/Browsers.php',
'donatj\\UserAgent\\Platforms' => $vendorDir . '/donatj/phpuseragentparser/src/UserAgent/Platforms.php',
'donatj\\UserAgent\\UserAgent' => $vendorDir . '/donatj/phpuseragentparser/src/UserAgent/UserAgent.php',
'donatj\\UserAgent\\UserAgentInterface' => $vendorDir . '/donatj/phpuseragentparser/src/UserAgent/UserAgentInterface.php',
'donatj\\UserAgent\\UserAgentParser' => $vendorDir . '/donatj/phpuseragentparser/src/UserAgent/UserAgentParser.php',
);

View File

@@ -0,0 +1,13 @@
<?php
// autoload_files.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'da5f6548f070d3d306f90eee42dd5de6' => $vendorDir . '/donatj/phpuseragentparser/src/UserAgentParser.php',
'bcb90d312f16e4ff52a76c5aa3f98ae0' => $vendorDir . '/cmb2/cmb2/init.php',
'65bb6728e4ea5a6bfba27700e81f7a00' => $baseDir . '/includes/template-tags.php',
'49628becc29116377284b725833a0b5a' => $vendorDir . '/woocommerce/action-scheduler/action-scheduler.php',
);

View File

@@ -0,0 +1,9 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -0,0 +1,11 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'donatj\\UserAgent\\' => array($vendorDir . '/donatj/phpuseragentparser/src/UserAgent'),
'MyThemeShop\\Helpers\\' => array($vendorDir . '/mythemeshop/wordpress-helpers/src'),
);

View File

@@ -0,0 +1,50 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInite0bd047aa5058f04568aa38dfc5ac000
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
/**
* @return \Composer\Autoload\ClassLoader
*/
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInite0bd047aa5058f04568aa38dfc5ac000', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInite0bd047aa5058f04568aa38dfc5ac000', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInite0bd047aa5058f04568aa38dfc5ac000::getInitializer($loader));
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInite0bd047aa5058f04568aa38dfc5ac000::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
require $file;
}
}, null, null);
foreach ($filesToLoad as $fileIdentifier => $file) {
$requireFile($fileIdentifier, $file);
}
return $loader;
}
}

View File

@@ -0,0 +1,398 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInite0bd047aa5058f04568aa38dfc5ac000
{
public static $files = array (
'da5f6548f070d3d306f90eee42dd5de6' => __DIR__ . '/..' . '/donatj/phpuseragentparser/src/UserAgentParser.php',
'bcb90d312f16e4ff52a76c5aa3f98ae0' => __DIR__ . '/..' . '/cmb2/cmb2/init.php',
'65bb6728e4ea5a6bfba27700e81f7a00' => __DIR__ . '/../..' . '/includes/template-tags.php',
'49628becc29116377284b725833a0b5a' => __DIR__ . '/..' . '/woocommerce/action-scheduler/action-scheduler.php',
);
public static $prefixLengthsPsr4 = array (
'd' =>
array (
'donatj\\UserAgent\\' => 17,
),
'M' =>
array (
'MyThemeShop\\Helpers\\' => 20,
),
);
public static $prefixDirsPsr4 = array (
'donatj\\UserAgent\\' =>
array (
0 => __DIR__ . '/..' . '/donatj/phpuseragentparser/src/UserAgent',
),
'MyThemeShop\\Helpers\\' =>
array (
0 => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src',
),
);
public static $classMap = array (
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'MyThemeShop\\Admin\\List_Table' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/admin/class-list-table.php',
'MyThemeShop\\Admin\\Page' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/admin/class-page.php',
'MyThemeShop\\Database\\Clauses' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/database/class-clauses.php',
'MyThemeShop\\Database\\Database' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/database/class-database.php',
'MyThemeShop\\Database\\Escape' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/database/class-escape.php',
'MyThemeShop\\Database\\GroupBy' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/database/class-groupby.php',
'MyThemeShop\\Database\\Joins' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/database/class-joins.php',
'MyThemeShop\\Database\\OrderBy' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/database/class-orderby.php',
'MyThemeShop\\Database\\Query_Builder' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/database/class-query-builder.php',
'MyThemeShop\\Database\\Select' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/database/class-select.php',
'MyThemeShop\\Database\\Translate' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/database/class-translate.php',
'MyThemeShop\\Database\\Where' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/database/class-where.php',
'MyThemeShop\\Helpers\\Arr' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/helpers/class-arr.php',
'MyThemeShop\\Helpers\\Attachment' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/helpers/class-attachment.php',
'MyThemeShop\\Helpers\\Conditional' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/helpers/class-conditional.php',
'MyThemeShop\\Helpers\\DB' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/helpers/class-db.php',
'MyThemeShop\\Helpers\\HTML' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/helpers/class-html.php',
'MyThemeShop\\Helpers\\Param' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/helpers/class-param.php',
'MyThemeShop\\Helpers\\Str' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/helpers/class-str.php',
'MyThemeShop\\Helpers\\Url' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/helpers/class-url.php',
'MyThemeShop\\Helpers\\WordPress' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/helpers/class-wordpress.php',
'MyThemeShop\\Json_Manager' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/class-json-manager.php',
'MyThemeShop\\Notification' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/class-notification.php',
'MyThemeShop\\Notification_Center' => __DIR__ . '/..' . '/mythemeshop/wordpress-helpers/src/class-notification-center.php',
'RankMath\\ACF\\ACF' => __DIR__ . '/../..' . '/includes/modules/acf/class-acf.php',
'RankMath\\Admin\\Admin' => __DIR__ . '/../..' . '/includes/admin/class-admin.php',
'RankMath\\Admin\\Admin_Breadcrumbs' => __DIR__ . '/../..' . '/includes/admin/class-admin-breadcrumbs.php',
'RankMath\\Admin\\Admin_Dashboard_Nav' => __DIR__ . '/../..' . '/includes/admin/class-admin-dashboard-nav.php',
'RankMath\\Admin\\Admin_Header' => __DIR__ . '/../..' . '/includes/admin/class-admin-header.php',
'RankMath\\Admin\\Admin_Helper' => __DIR__ . '/../..' . '/includes/admin/class-admin-helper.php',
'RankMath\\Admin\\Admin_Init' => __DIR__ . '/../..' . '/includes/admin/class-admin-init.php',
'RankMath\\Admin\\Admin_Menu' => __DIR__ . '/../..' . '/includes/admin/class-admin-menu.php',
'RankMath\\Admin\\Api' => __DIR__ . '/../..' . '/includes/admin/class-api.php',
'RankMath\\Admin\\Ask_Review' => __DIR__ . '/../..' . '/includes/admin/class-ask-review.php',
'RankMath\\Admin\\Assets' => __DIR__ . '/../..' . '/includes/admin/class-assets.php',
'RankMath\\Admin\\Bulk_Actions' => __DIR__ . '/../..' . '/includes/admin/class-bulk-actions.php',
'RankMath\\Admin\\CMB2_Fields' => __DIR__ . '/../..' . '/includes/admin/class-cmb2-fields.php',
'RankMath\\Admin\\Database\\Clauses' => __DIR__ . '/../..' . '/includes/admin/database/class-clauses.php',
'RankMath\\Admin\\Database\\Database' => __DIR__ . '/../..' . '/includes/admin/database/class-database.php',
'RankMath\\Admin\\Database\\Escape' => __DIR__ . '/../..' . '/includes/admin/database/class-escape.php',
'RankMath\\Admin\\Database\\GroupBy' => __DIR__ . '/../..' . '/includes/admin/database/class-groupby.php',
'RankMath\\Admin\\Database\\Joins' => __DIR__ . '/../..' . '/includes/admin/database/class-joins.php',
'RankMath\\Admin\\Database\\OrderBy' => __DIR__ . '/../..' . '/includes/admin/database/class-orderby.php',
'RankMath\\Admin\\Database\\Query_Builder' => __DIR__ . '/../..' . '/includes/admin/database/class-query-builder.php',
'RankMath\\Admin\\Database\\Select' => __DIR__ . '/../..' . '/includes/admin/database/class-select.php',
'RankMath\\Admin\\Database\\Translate' => __DIR__ . '/../..' . '/includes/admin/database/class-translate.php',
'RankMath\\Admin\\Database\\Where' => __DIR__ . '/../..' . '/includes/admin/database/class-where.php',
'RankMath\\Admin\\Import_Export' => __DIR__ . '/../..' . '/includes/admin/class-import-export.php',
'RankMath\\Admin\\Importers\\AIOSEO' => __DIR__ . '/../..' . '/includes/admin/importers/class-aioseo.php',
'RankMath\\Admin\\Importers\\AIO_Rich_Snippet' => __DIR__ . '/../..' . '/includes/admin/importers/class-aio-rich-snippet.php',
'RankMath\\Admin\\Importers\\Detector' => __DIR__ . '/../..' . '/includes/admin/importers/class-detector.php',
'RankMath\\Admin\\Importers\\Plugin_Importer' => __DIR__ . '/../..' . '/includes/admin/importers/abstract-importer.php',
'RankMath\\Admin\\Importers\\Redirections' => __DIR__ . '/../..' . '/includes/admin/importers/class-redirections.php',
'RankMath\\Admin\\Importers\\SEOPress' => __DIR__ . '/../..' . '/includes/admin/importers/class-seopress.php',
'RankMath\\Admin\\Importers\\Status' => __DIR__ . '/../..' . '/includes/admin/importers/class-status.php',
'RankMath\\Admin\\Importers\\WP_Schema_Pro' => __DIR__ . '/../..' . '/includes/admin/importers/class-wp-schema-pro.php',
'RankMath\\Admin\\Importers\\Yoast' => __DIR__ . '/../..' . '/includes/admin/importers/class-yoast.php',
'RankMath\\Admin\\List_Table' => __DIR__ . '/../..' . '/includes/admin/class-list-table.php',
'RankMath\\Admin\\Metabox\\IScreen' => __DIR__ . '/../..' . '/includes/admin/metabox/interface-screen.php',
'RankMath\\Admin\\Metabox\\Metabox' => __DIR__ . '/../..' . '/includes/admin/metabox/class-metabox.php',
'RankMath\\Admin\\Metabox\\Post_Screen' => __DIR__ . '/../..' . '/includes/admin/metabox/class-post-screen.php',
'RankMath\\Admin\\Metabox\\Screen' => __DIR__ . '/../..' . '/includes/admin/metabox/class-screen.php',
'RankMath\\Admin\\Metabox\\Taxonomy_Screen' => __DIR__ . '/../..' . '/includes/admin/metabox/class-taxonomy-screen.php',
'RankMath\\Admin\\Metabox\\User_Screen' => __DIR__ . '/../..' . '/includes/admin/metabox/class-user-screen.php',
'RankMath\\Admin\\Notices' => __DIR__ . '/../..' . '/includes/admin/class-notices.php',
'RankMath\\Admin\\Notifications\\Notification' => __DIR__ . '/../..' . '/includes/admin/notifications/class-notification.php',
'RankMath\\Admin\\Notifications\\Notification_Center' => __DIR__ . '/../..' . '/includes/admin/notifications/class-notification-center.php',
'RankMath\\Admin\\Option_Center' => __DIR__ . '/../..' . '/includes/admin/class-option-center.php',
'RankMath\\Admin\\Options' => __DIR__ . '/../..' . '/includes/admin/class-options.php',
'RankMath\\Admin\\Page' => __DIR__ . '/../..' . '/includes/admin/class-page.php',
'RankMath\\Admin\\Post_Columns' => __DIR__ . '/../..' . '/includes/admin/class-post-columns.php',
'RankMath\\Admin\\Post_Filters' => __DIR__ . '/../..' . '/includes/admin/class-post-filters.php',
'RankMath\\Admin\\Pro_Notice' => __DIR__ . '/../..' . '/includes/admin/class-pro-notice.php',
'RankMath\\Admin\\Registration' => __DIR__ . '/../..' . '/includes/admin/class-registration.php',
'RankMath\\Admin\\Serp_Preview' => __DIR__ . '/../..' . '/includes/admin/class-serp-preview.php',
'RankMath\\Admin\\Setup_Wizard' => __DIR__ . '/../..' . '/includes/admin/class-setup-wizard.php',
'RankMath\\Admin\\Watcher' => __DIR__ . '/../..' . '/includes/admin/watcher/class-watcher.php',
'RankMath\\Admin_Bar_Menu' => __DIR__ . '/../..' . '/includes/admin/class-admin-bar-menu.php',
'RankMath\\Analytics\\AJAX' => __DIR__ . '/../..' . '/includes/modules/analytics/class-ajax.php',
'RankMath\\Analytics\\Analytics' => __DIR__ . '/../..' . '/includes/modules/analytics/class-analytics.php',
'RankMath\\Analytics\\Analytics_Common' => __DIR__ . '/../..' . '/includes/modules/analytics/class-analytics-common.php',
'RankMath\\Analytics\\Analytics_Stats' => __DIR__ . '/../..' . '/includes/modules/analytics/class-analytics-stats.php',
'RankMath\\Analytics\\DB' => __DIR__ . '/../..' . '/includes/modules/analytics/class-db.php',
'RankMath\\Analytics\\Email_Reports' => __DIR__ . '/../..' . '/includes/modules/analytics/class-email-reports.php',
'RankMath\\Analytics\\GTag' => __DIR__ . '/../..' . '/includes/modules/analytics/class-gtag.php',
'RankMath\\Analytics\\Keywords' => __DIR__ . '/../..' . '/includes/modules/analytics/class-keywords.php',
'RankMath\\Analytics\\Objects' => __DIR__ . '/../..' . '/includes/modules/analytics/class-objects.php',
'RankMath\\Analytics\\Posts' => __DIR__ . '/../..' . '/includes/modules/analytics/class-posts.php',
'RankMath\\Analytics\\Rest' => __DIR__ . '/../..' . '/includes/modules/analytics/rest/class-rest.php',
'RankMath\\Analytics\\Stats' => __DIR__ . '/../..' . '/includes/modules/analytics/class-stats.php',
'RankMath\\Analytics\\Summary' => __DIR__ . '/../..' . '/includes/modules/analytics/class-summary.php',
'RankMath\\Analytics\\Url_Inspection' => __DIR__ . '/../..' . '/includes/modules/analytics/class-url-inspection.php',
'RankMath\\Analytics\\Watcher' => __DIR__ . '/../..' . '/includes/modules/analytics/class-watcher.php',
'RankMath\\Analytics\\Workflow\\Base' => __DIR__ . '/../..' . '/includes/modules/analytics/workflows/class-base.php',
'RankMath\\Analytics\\Workflow\\Console' => __DIR__ . '/../..' . '/includes/modules/analytics/workflows/class-console.php',
'RankMath\\Analytics\\Workflow\\Inspections' => __DIR__ . '/../..' . '/includes/modules/analytics/workflows/class-inspections.php',
'RankMath\\Analytics\\Workflow\\Jobs' => __DIR__ . '/../..' . '/includes/modules/analytics/workflows/class-jobs.php',
'RankMath\\Analytics\\Workflow\\OAuth' => __DIR__ . '/../..' . '/includes/modules/analytics/workflows/class-oauth.php',
'RankMath\\Analytics\\Workflow\\Objects' => __DIR__ . '/../..' . '/includes/modules/analytics/workflows/class-objects.php',
'RankMath\\Analytics\\Workflow\\Workflow' => __DIR__ . '/../..' . '/includes/modules/analytics/workflows/class-workflow.php',
'RankMath\\Auto_Updater' => __DIR__ . '/../..' . '/includes/class-auto-updater.php',
'RankMath\\Beta_Optin' => __DIR__ . '/../..' . '/includes/modules/version-control/class-beta-optin.php',
'RankMath\\BuddyPress\\Admin' => __DIR__ . '/../..' . '/includes/modules/buddypress/class-admin.php',
'RankMath\\BuddyPress\\BuddyPress' => __DIR__ . '/../..' . '/includes/modules/buddypress/class-buddypress.php',
'RankMath\\CLI\\Commands' => __DIR__ . '/../..' . '/includes/cli/class-commands.php',
'RankMath\\CMB2' => __DIR__ . '/../..' . '/includes/class-cmb2.php',
'RankMath\\Common' => __DIR__ . '/../..' . '/includes/class-common.php',
'RankMath\\Compatibility' => __DIR__ . '/../..' . '/includes/class-compatibility.php',
'RankMath\\ContentAI\\Block_Command' => __DIR__ . '/../..' . '/includes/modules/content-ai/blocks/command/class-block-command.php',
'RankMath\\ContentAI\\Bulk_Actions' => __DIR__ . '/../..' . '/includes/modules/content-ai/class-bulk-actions.php',
'RankMath\\ContentAI\\Bulk_Edit_SEO_Meta' => __DIR__ . '/../..' . '/includes/modules/content-ai/class-bulk-edit-seo-meta.php',
'RankMath\\ContentAI\\Content_AI' => __DIR__ . '/../..' . '/includes/modules/content-ai/class-content-ai.php',
'RankMath\\ContentAI\\Content_AI_Page' => __DIR__ . '/../..' . '/includes/modules/content-ai/class-content-ai-page.php',
'RankMath\\ContentAI\\Event_Scheduler' => __DIR__ . '/../..' . '/includes/modules/content-ai/class-event-scheduler.php',
'RankMath\\ContentAI\\Rest' => __DIR__ . '/../..' . '/includes/modules/content-ai/class-rest.php',
'RankMath\\Dashboard_Widget' => __DIR__ . '/../..' . '/includes/admin/class-dashboard-widget.php',
'RankMath\\Data_Encryption' => __DIR__ . '/../..' . '/includes/class-data-encryption.php',
'RankMath\\Defaults' => __DIR__ . '/../..' . '/includes/class-defaults.php',
'RankMath\\Divi\\Divi' => __DIR__ . '/../..' . '/includes/3rdparty/divi/class-divi.php',
'RankMath\\Divi\\Divi_Admin' => __DIR__ . '/../..' . '/includes/3rdparty/divi/class-divi-admin.php',
'RankMath\\Elementor\\Elementor' => __DIR__ . '/../..' . '/includes/3rdparty/elementor/class-elementor.php',
'RankMath\\Frontend\\Breadcrumbs' => __DIR__ . '/../..' . '/includes/frontend/class-breadcrumbs.php',
'RankMath\\Frontend\\Comments' => __DIR__ . '/../..' . '/includes/frontend/class-comments.php',
'RankMath\\Frontend\\Frontend' => __DIR__ . '/../..' . '/includes/frontend/class-frontend.php',
'RankMath\\Frontend\\Head' => __DIR__ . '/../..' . '/includes/frontend/class-head.php',
'RankMath\\Frontend\\Link_Attributes' => __DIR__ . '/../..' . '/includes/frontend/class-link-attributes.php',
'RankMath\\Frontend\\Redirection' => __DIR__ . '/../..' . '/includes/frontend/class-redirection.php',
'RankMath\\Frontend\\Shortcodes' => __DIR__ . '/../..' . '/includes/frontend/class-shortcodes.php',
'RankMath\\Frontend_SEO_Score' => __DIR__ . '/../..' . '/includes/class-frontend-seo-score.php',
'RankMath\\Google\\Analytics' => __DIR__ . '/../..' . '/includes/modules/analytics/google/class-analytics.php',
'RankMath\\Google\\Api' => __DIR__ . '/../..' . '/includes/modules/analytics/google/class-api.php',
'RankMath\\Google\\Authentication' => __DIR__ . '/../..' . '/includes/modules/analytics/google/class-authentication.php',
'RankMath\\Google\\Console' => __DIR__ . '/../..' . '/includes/modules/analytics/google/class-console.php',
'RankMath\\Google\\Permissions' => __DIR__ . '/../..' . '/includes/modules/analytics/google/class-permissions.php',
'RankMath\\Google\\Request' => __DIR__ . '/../..' . '/includes/modules/analytics/google/class-request.php',
'RankMath\\Google\\Url_Inspection' => __DIR__ . '/../..' . '/includes/modules/analytics/google/class-url-inspection.php',
'RankMath\\Helper' => __DIR__ . '/../..' . '/includes/class-helper.php',
'RankMath\\Helpers\\Analytics' => __DIR__ . '/../..' . '/includes/helpers/class-analytics.php',
'RankMath\\Helpers\\Api' => __DIR__ . '/../..' . '/includes/helpers/class-api.php',
'RankMath\\Helpers\\Arr' => __DIR__ . '/../..' . '/includes/helpers/class-arr.php',
'RankMath\\Helpers\\Attachment' => __DIR__ . '/../..' . '/includes/helpers/class-attachment.php',
'RankMath\\Helpers\\Choices' => __DIR__ . '/../..' . '/includes/helpers/class-choices.php',
'RankMath\\Helpers\\Conditional' => __DIR__ . '/../..' . '/includes/helpers/class-conditional.php',
'RankMath\\Helpers\\Content_AI' => __DIR__ . '/../..' . '/includes/helpers/class-content-ai.php',
'RankMath\\Helpers\\DB' => __DIR__ . '/../..' . '/includes/helpers/class-db.php',
'RankMath\\Helpers\\Editor' => __DIR__ . '/../..' . '/includes/helpers/class-editor.php',
'RankMath\\Helpers\\HTML' => __DIR__ . '/../..' . '/includes/helpers/class-html.php',
'RankMath\\Helpers\\Locale' => __DIR__ . '/../..' . '/includes/helpers/class-locale.php',
'RankMath\\Helpers\\Options' => __DIR__ . '/../..' . '/includes/helpers/class-options.php',
'RankMath\\Helpers\\Param' => __DIR__ . '/../..' . '/includes/helpers/class-param.php',
'RankMath\\Helpers\\Post_Type' => __DIR__ . '/../..' . '/includes/helpers/class-post-type.php',
'RankMath\\Helpers\\Schema' => __DIR__ . '/../..' . '/includes/helpers/class-schema.php',
'RankMath\\Helpers\\Security' => __DIR__ . '/../..' . '/includes/helpers/class-security.php',
'RankMath\\Helpers\\Sitepress' => __DIR__ . '/../..' . '/includes/helpers/class-sitepress.php',
'RankMath\\Helpers\\Str' => __DIR__ . '/../..' . '/includes/helpers/class-str.php',
'RankMath\\Helpers\\Taxonomy' => __DIR__ . '/../..' . '/includes/helpers/class-taxonomy.php',
'RankMath\\Helpers\\Url' => __DIR__ . '/../..' . '/includes/helpers/class-url.php',
'RankMath\\Helpers\\WordPress' => __DIR__ . '/../..' . '/includes/helpers/class-wordpress.php',
'RankMath\\Image_Seo\\Add_Attributes' => __DIR__ . '/../..' . '/includes/modules/image-seo/class-add-attributes.php',
'RankMath\\Image_Seo\\Admin' => __DIR__ . '/../..' . '/includes/modules/image-seo/class-admin.php',
'RankMath\\Image_Seo\\Image_Seo' => __DIR__ . '/../..' . '/includes/modules/image-seo/class-image-seo.php',
'RankMath\\Installer' => __DIR__ . '/../..' . '/includes/class-installer.php',
'RankMath\\Instant_Indexing\\Api' => __DIR__ . '/../..' . '/includes/modules/instant-indexing/class-api.php',
'RankMath\\Instant_Indexing\\Instant_Indexing' => __DIR__ . '/../..' . '/includes/modules/instant-indexing/class-instant-indexing.php',
'RankMath\\Instant_Indexing\\Rest' => __DIR__ . '/../..' . '/includes/modules/instant-indexing/class-rest.php',
'RankMath\\Json_Manager' => __DIR__ . '/../..' . '/includes/class-json-manager.php',
'RankMath\\KB' => __DIR__ . '/../..' . '/includes/class-kb.php',
'RankMath\\Links\\ContentProcessor' => __DIR__ . '/../..' . '/includes/modules/links/class-contentprocessor.php',
'RankMath\\Links\\Link' => __DIR__ . '/../..' . '/includes/modules/links/class-link.php',
'RankMath\\Links\\Links' => __DIR__ . '/../..' . '/includes/modules/links/class-links.php',
'RankMath\\Links\\Storage' => __DIR__ . '/../..' . '/includes/modules/links/class-storage.php',
'RankMath\\Local_Seo\\KML_File' => __DIR__ . '/../..' . '/includes/modules/local-seo/class-kml-file.php',
'RankMath\\Local_Seo\\Local_Seo' => __DIR__ . '/../..' . '/includes/modules/local-seo/class-local-seo.php',
'RankMath\\Metadata' => __DIR__ . '/../..' . '/includes/class-metadata.php',
'RankMath\\Module\\Base' => __DIR__ . '/../..' . '/includes/module/class-base.php',
'RankMath\\Module\\Manager' => __DIR__ . '/../..' . '/includes/module/class-manager.php',
'RankMath\\Module\\Module' => __DIR__ . '/../..' . '/includes/module/class-module.php',
'RankMath\\Monitor\\Admin' => __DIR__ . '/../..' . '/includes/modules/404-monitor/class-admin.php',
'RankMath\\Monitor\\DB' => __DIR__ . '/../..' . '/includes/modules/404-monitor/class-db.php',
'RankMath\\Monitor\\Monitor' => __DIR__ . '/../..' . '/includes/modules/404-monitor/class-monitor.php',
'RankMath\\Monitor\\Table' => __DIR__ . '/../..' . '/includes/modules/404-monitor/class-table.php',
'RankMath\\OpenGraph\\Facebook' => __DIR__ . '/../..' . '/includes/opengraph/class-facebook.php',
'RankMath\\OpenGraph\\Facebook_Locale' => __DIR__ . '/../..' . '/includes/opengraph/class-facebook-locale.php',
'RankMath\\OpenGraph\\Image' => __DIR__ . '/../..' . '/includes/opengraph/class-image.php',
'RankMath\\OpenGraph\\OpenGraph' => __DIR__ . '/../..' . '/includes/opengraph/class-opengraph.php',
'RankMath\\OpenGraph\\Slack' => __DIR__ . '/../..' . '/includes/opengraph/class-slack.php',
'RankMath\\OpenGraph\\Twitter' => __DIR__ . '/../..' . '/includes/opengraph/class-twitter.php',
'RankMath\\Paper\\Archive' => __DIR__ . '/../..' . '/includes/frontend/paper/class-archive.php',
'RankMath\\Paper\\Author' => __DIR__ . '/../..' . '/includes/frontend/paper/class-author.php',
'RankMath\\Paper\\BP_Group' => __DIR__ . '/../..' . '/includes/modules/buddypress/paper/class-bp-group.php',
'RankMath\\Paper\\BP_User' => __DIR__ . '/../..' . '/includes/modules/buddypress/paper/class-bp-user.php',
'RankMath\\Paper\\Blog' => __DIR__ . '/../..' . '/includes/frontend/paper/class-blog.php',
'RankMath\\Paper\\Date' => __DIR__ . '/../..' . '/includes/frontend/paper/class-date.php',
'RankMath\\Paper\\Error_404' => __DIR__ . '/../..' . '/includes/frontend/paper/class-error-404.php',
'RankMath\\Paper\\IPaper' => __DIR__ . '/../..' . '/includes/frontend/paper/interface-paper.php',
'RankMath\\Paper\\Misc' => __DIR__ . '/../..' . '/includes/frontend/paper/class-misc.php',
'RankMath\\Paper\\Paper' => __DIR__ . '/../..' . '/includes/frontend/paper/class-paper.php',
'RankMath\\Paper\\Search' => __DIR__ . '/../..' . '/includes/frontend/paper/class-search.php',
'RankMath\\Paper\\Shop' => __DIR__ . '/../..' . '/includes/frontend/paper/class-shop.php',
'RankMath\\Paper\\Singular' => __DIR__ . '/../..' . '/includes/frontend/paper/class-singular.php',
'RankMath\\Paper\\Taxonomy' => __DIR__ . '/../..' . '/includes/frontend/paper/class-taxonomy.php',
'RankMath\\Post' => __DIR__ . '/../..' . '/includes/class-post.php',
'RankMath\\Redirections\\Admin' => __DIR__ . '/../..' . '/includes/modules/redirections/class-admin.php',
'RankMath\\Redirections\\Cache' => __DIR__ . '/../..' . '/includes/modules/redirections/class-cache.php',
'RankMath\\Redirections\\DB' => __DIR__ . '/../..' . '/includes/modules/redirections/class-db.php',
'RankMath\\Redirections\\Debugger' => __DIR__ . '/../..' . '/includes/modules/redirections/class-debugger.php',
'RankMath\\Redirections\\Export' => __DIR__ . '/../..' . '/includes/modules/redirections/class-export.php',
'RankMath\\Redirections\\Form' => __DIR__ . '/../..' . '/includes/modules/redirections/class-form.php',
'RankMath\\Redirections\\Import_Export' => __DIR__ . '/../..' . '/includes/modules/redirections/class-import-export.php',
'RankMath\\Redirections\\Metabox' => __DIR__ . '/../..' . '/includes/modules/redirections/class-metabox.php',
'RankMath\\Redirections\\Redirection' => __DIR__ . '/../..' . '/includes/modules/redirections/class-redirection.php',
'RankMath\\Redirections\\Redirections' => __DIR__ . '/../..' . '/includes/modules/redirections/class-redirections.php',
'RankMath\\Redirections\\Redirector' => __DIR__ . '/../..' . '/includes/modules/redirections/class-redirector.php',
'RankMath\\Redirections\\Table' => __DIR__ . '/../..' . '/includes/modules/redirections/class-table.php',
'RankMath\\Redirections\\Watcher' => __DIR__ . '/../..' . '/includes/modules/redirections/class-watcher.php',
'RankMath\\Replace_Variables\\Advanced_Variables' => __DIR__ . '/../..' . '/includes/replace-variables/class-advanced-variables.php',
'RankMath\\Replace_Variables\\Author_Variables' => __DIR__ . '/../..' . '/includes/replace-variables/class-author-variables.php',
'RankMath\\Replace_Variables\\Base' => __DIR__ . '/../..' . '/includes/replace-variables/class-base.php',
'RankMath\\Replace_Variables\\Basic_Variables' => __DIR__ . '/../..' . '/includes/replace-variables/class-basic-variables.php',
'RankMath\\Replace_Variables\\Cache' => __DIR__ . '/../..' . '/includes/replace-variables/class-cache.php',
'RankMath\\Replace_Variables\\Manager' => __DIR__ . '/../..' . '/includes/replace-variables/class-manager.php',
'RankMath\\Replace_Variables\\Post_Variables' => __DIR__ . '/../..' . '/includes/replace-variables/class-post-variables.php',
'RankMath\\Replace_Variables\\Replacer' => __DIR__ . '/../..' . '/includes/replace-variables/class-replacer.php',
'RankMath\\Replace_Variables\\Term_Variables' => __DIR__ . '/../..' . '/includes/replace-variables/class-term-variables.php',
'RankMath\\Replace_Variables\\Variable' => __DIR__ . '/../..' . '/includes/replace-variables/class-variable.php',
'RankMath\\Rest\\Admin' => __DIR__ . '/../..' . '/includes/rest/class-admin.php',
'RankMath\\Rest\\Front' => __DIR__ . '/../..' . '/includes/rest/class-front.php',
'RankMath\\Rest\\Headless' => __DIR__ . '/../..' . '/includes/rest/class-headless.php',
'RankMath\\Rest\\Post' => __DIR__ . '/../..' . '/includes/rest/class-post.php',
'RankMath\\Rest\\Rest_Helper' => __DIR__ . '/../..' . '/includes/rest/class-rest-helper.php',
'RankMath\\Rest\\Sanitize' => __DIR__ . '/../..' . '/includes/rest/class-sanitize.php',
'RankMath\\Rest\\Shared' => __DIR__ . '/../..' . '/includes/rest/class-shared.php',
'RankMath\\Rewrite' => __DIR__ . '/../..' . '/includes/class-rewrite.php',
'RankMath\\Robots_Txt' => __DIR__ . '/../..' . '/includes/modules/robots-txt/class-robots-txt.php',
'RankMath\\Role_Manager\\Capability_Manager' => __DIR__ . '/../..' . '/includes/modules/role-manager/class-capability-manager.php',
'RankMath\\Role_Manager\\Members' => __DIR__ . '/../..' . '/includes/modules/role-manager/class-members.php',
'RankMath\\Role_Manager\\Role_Manager' => __DIR__ . '/../..' . '/includes/modules/role-manager/class-role-manager.php',
'RankMath\\Role_Manager\\User_Role_Editor' => __DIR__ . '/../..' . '/includes/modules/role-manager/class-user-role-editor.php',
'RankMath\\Rollback_Version' => __DIR__ . '/../..' . '/includes/modules/version-control/class-rollback-version.php',
'RankMath\\Runner' => __DIR__ . '/../..' . '/includes/interface-runner.php',
'RankMath\\SEO_Analysis\\Admin' => __DIR__ . '/../..' . '/includes/modules/seo-analysis/class-admin.php',
'RankMath\\SEO_Analysis\\Admin_Tabs' => __DIR__ . '/../..' . '/includes/modules/seo-analysis/class-admin-tabs.php',
'RankMath\\SEO_Analysis\\Result' => __DIR__ . '/../..' . '/includes/modules/seo-analysis/class-result.php',
'RankMath\\SEO_Analysis\\SEO_Analysis' => __DIR__ . '/../..' . '/includes/modules/seo-analysis/class-seo-analysis.php',
'RankMath\\SEO_Analysis\\SEO_Analyzer' => __DIR__ . '/../..' . '/includes/modules/seo-analysis/class-seo-analyzer.php',
'RankMath\\Schema\\Admin' => __DIR__ . '/../..' . '/includes/modules/schema/class-admin.php',
'RankMath\\Schema\\Article' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-article.php',
'RankMath\\Schema\\Author' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-author.php',
'RankMath\\Schema\\Block' => __DIR__ . '/../..' . '/includes/modules/schema/blocks/class-block.php',
'RankMath\\Schema\\Block_FAQ' => __DIR__ . '/../..' . '/includes/modules/schema/blocks/class-block-faq.php',
'RankMath\\Schema\\Block_HowTo' => __DIR__ . '/../..' . '/includes/modules/schema/blocks/class-block-howto.php',
'RankMath\\Schema\\Block_Parser' => __DIR__ . '/../..' . '/includes/modules/schema/blocks/class-block-parser.php',
'RankMath\\Schema\\Block_TOC' => __DIR__ . '/../..' . '/includes/modules/schema/blocks/toc/class-block-toc.php',
'RankMath\\Schema\\Blocks' => __DIR__ . '/../..' . '/includes/modules/schema/class-blocks.php',
'RankMath\\Schema\\Blocks\\Admin' => __DIR__ . '/../..' . '/includes/modules/schema/blocks/class-admin.php',
'RankMath\\Schema\\Breadcrumbs' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-breadcrumbs.php',
'RankMath\\Schema\\DB' => __DIR__ . '/../..' . '/includes/modules/schema/class-db.php',
'RankMath\\Schema\\Frontend' => __DIR__ . '/../..' . '/includes/modules/schema/class-frontend.php',
'RankMath\\Schema\\JsonLD' => __DIR__ . '/../..' . '/includes/modules/schema/class-jsonld.php',
'RankMath\\Schema\\Opengraph' => __DIR__ . '/../..' . '/includes/modules/schema/class-opengraph.php',
'RankMath\\Schema\\PrimaryImage' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-primaryimage.php',
'RankMath\\Schema\\Product' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-product.php',
'RankMath\\Schema\\Product_Edd' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-product-edd.php',
'RankMath\\Schema\\Product_WooCommerce' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-product-woocommerce.php',
'RankMath\\Schema\\Products_Page' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-products-page.php',
'RankMath\\Schema\\Publisher' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-publisher.php',
'RankMath\\Schema\\Schema' => __DIR__ . '/../..' . '/includes/modules/schema/class-schema.php',
'RankMath\\Schema\\Singular' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-singular.php',
'RankMath\\Schema\\Snippet' => __DIR__ . '/../..' . '/includes/modules/schema/interface-snippet.php',
'RankMath\\Schema\\Snippet_Shortcode' => __DIR__ . '/../..' . '/includes/modules/schema/class-snippet-shortcode.php',
'RankMath\\Schema\\WC_Attributes' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-wc-attributes.php',
'RankMath\\Schema\\Webpage' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-webpage.php',
'RankMath\\Schema\\Website' => __DIR__ . '/../..' . '/includes/modules/schema/snippets/class-website.php',
'RankMath\\Settings' => __DIR__ . '/../..' . '/includes/class-settings.php',
'RankMath\\Sitemap\\Admin' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-admin.php',
'RankMath\\Sitemap\\Cache' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-cache.php',
'RankMath\\Sitemap\\Cache_Watcher' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-cache-watcher.php',
'RankMath\\Sitemap\\Classifier' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-classifier.php',
'RankMath\\Sitemap\\Generator' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-generator.php',
'RankMath\\Sitemap\\Html\\Authors' => __DIR__ . '/../..' . '/includes/modules/sitemap/html-sitemap/class-authors.php',
'RankMath\\Sitemap\\Html\\Posts' => __DIR__ . '/../..' . '/includes/modules/sitemap/html-sitemap/class-posts.php',
'RankMath\\Sitemap\\Html\\Sitemap' => __DIR__ . '/../..' . '/includes/modules/sitemap/html-sitemap/class-sitemap.php',
'RankMath\\Sitemap\\Html\\Terms' => __DIR__ . '/../..' . '/includes/modules/sitemap/html-sitemap/class-terms.php',
'RankMath\\Sitemap\\Image_Parser' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-image-parser.php',
'RankMath\\Sitemap\\Providers\\Author' => __DIR__ . '/../..' . '/includes/modules/sitemap/providers/class-author.php',
'RankMath\\Sitemap\\Providers\\Post_Type' => __DIR__ . '/../..' . '/includes/modules/sitemap/providers/class-post-type.php',
'RankMath\\Sitemap\\Providers\\Provider' => __DIR__ . '/../..' . '/includes/modules/sitemap/providers/interface-provider.php',
'RankMath\\Sitemap\\Providers\\Taxonomy' => __DIR__ . '/../..' . '/includes/modules/sitemap/providers/class-taxonomy.php',
'RankMath\\Sitemap\\Redirect_Core_Sitemaps' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-redirect-core-sitemaps.php',
'RankMath\\Sitemap\\Router' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-router.php',
'RankMath\\Sitemap\\Sitemap' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-sitemap.php',
'RankMath\\Sitemap\\Sitemap_Index' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-sitemap-index.php',
'RankMath\\Sitemap\\Sitemap_XML' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-sitemap-xml.php',
'RankMath\\Sitemap\\Stylesheet' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-stylesheet.php',
'RankMath\\Sitemap\\Timezone' => __DIR__ . '/../..' . '/includes/modules/sitemap/class-timezone.php',
'RankMath\\Sitemap\\XML' => __DIR__ . '/../..' . '/includes/modules/sitemap/abstract-xml.php',
'RankMath\\Status\\Error_Log' => __DIR__ . '/../..' . '/includes/modules/status/class-error-log.php',
'RankMath\\Status\\Status' => __DIR__ . '/../..' . '/includes/modules/status/class-status.php',
'RankMath\\Status\\System_Status' => __DIR__ . '/../..' . '/includes/modules/status/class-system-status.php',
'RankMath\\Term' => __DIR__ . '/../..' . '/includes/class-term.php',
'RankMath\\Thumbnail_Overlay' => __DIR__ . '/../..' . '/includes/class-thumbnail-overlay.php',
'RankMath\\Tools\\AIOSEO_Blocks' => __DIR__ . '/../..' . '/includes/modules/database-tools/class-aioseo-blocks.php',
'RankMath\\Tools\\AIOSEO_TOC_Converter' => __DIR__ . '/../..' . '/includes/modules/database-tools/class-aioseo-toc-converter.php',
'RankMath\\Tools\\Database_Tools' => __DIR__ . '/../..' . '/includes/modules/database-tools/class-database-tools.php',
'RankMath\\Tools\\Remove_Schema' => __DIR__ . '/../..' . '/includes/modules/database-tools/class-remove-schema.php',
'RankMath\\Tools\\Update_Score' => __DIR__ . '/../..' . '/includes/modules/database-tools/class-update-score.php',
'RankMath\\Tools\\Yoast_Blocks' => __DIR__ . '/../..' . '/includes/modules/database-tools/class-yoast-blocks.php',
'RankMath\\Tools\\Yoast_FAQ_Converter' => __DIR__ . '/../..' . '/includes/modules/database-tools/class-yoast-faq-converter.php',
'RankMath\\Tools\\Yoast_HowTo_Converter' => __DIR__ . '/../..' . '/includes/modules/database-tools/class-yoast-howto-converter.php',
'RankMath\\Tools\\Yoast_Local_Converter' => __DIR__ . '/../..' . '/includes/modules/database-tools/class-yoast-local-converter.php',
'RankMath\\Tools\\Yoast_TOC_Converter' => __DIR__ . '/../..' . '/includes/modules/database-tools/class-yoast-toc-converter.php',
'RankMath\\Traits\\Ajax' => __DIR__ . '/../..' . '/includes/traits/class-ajax.php',
'RankMath\\Traits\\Cache' => __DIR__ . '/../..' . '/includes/traits/class-cache.php',
'RankMath\\Traits\\Hooker' => __DIR__ . '/../..' . '/includes/traits/class-hooker.php',
'RankMath\\Traits\\Meta' => __DIR__ . '/../..' . '/includes/traits/class-meta.php',
'RankMath\\Traits\\Shortcode' => __DIR__ . '/../..' . '/includes/traits/class-shortcode.php',
'RankMath\\Traits\\Wizard' => __DIR__ . '/../..' . '/includes/traits/class-wizard.php',
'RankMath\\Update_Email' => __DIR__ . '/../..' . '/includes/class-update-email.php',
'RankMath\\Updates' => __DIR__ . '/../..' . '/includes/class-updates.php',
'RankMath\\User' => __DIR__ . '/../..' . '/includes/class-user.php',
'RankMath\\Version_Control' => __DIR__ . '/../..' . '/includes/modules/version-control/class-version-control.php',
'RankMath\\Web_Stories\\Web_Stories' => __DIR__ . '/../..' . '/includes/modules/web-stories/class-web-stories.php',
'RankMath\\Wizard\\Compatibility' => __DIR__ . '/../..' . '/includes/admin/wizard/class-compatibility.php',
'RankMath\\Wizard\\Import' => __DIR__ . '/../..' . '/includes/admin/wizard/class-import.php',
'RankMath\\Wizard\\Monitor_Redirection' => __DIR__ . '/../..' . '/includes/admin/wizard/class-monitor-redirection.php',
'RankMath\\Wizard\\Optimization' => __DIR__ . '/../..' . '/includes/admin/wizard/class-optimization.php',
'RankMath\\Wizard\\Ready' => __DIR__ . '/../..' . '/includes/admin/wizard/class-ready.php',
'RankMath\\Wizard\\Role' => __DIR__ . '/../..' . '/includes/admin/wizard/class-role.php',
'RankMath\\Wizard\\Schema_Markup' => __DIR__ . '/../..' . '/includes/admin/wizard/class-schema-markup.php',
'RankMath\\Wizard\\Search_Console' => __DIR__ . '/../..' . '/includes/admin/wizard/class-search-console.php',
'RankMath\\Wizard\\Sitemap' => __DIR__ . '/../..' . '/includes/admin/wizard/class-sitemap.php',
'RankMath\\Wizard\\Wizard_Step' => __DIR__ . '/../..' . '/includes/admin/wizard/interface-wizard-step.php',
'RankMath\\Wizard\\Your_Site' => __DIR__ . '/../..' . '/includes/admin/wizard/class-your-site.php',
'RankMath\\WooCommerce\\Admin' => __DIR__ . '/../..' . '/includes/modules/woocommerce/class-admin.php',
'RankMath\\WooCommerce\\Opengraph' => __DIR__ . '/../..' . '/includes/modules/woocommerce/class-opengraph.php',
'RankMath\\WooCommerce\\Permalink_Watcher' => __DIR__ . '/../..' . '/includes/modules/woocommerce/class-permalink-watcher.php',
'RankMath\\WooCommerce\\Product_Redirection' => __DIR__ . '/../..' . '/includes/modules/woocommerce/class-product-redirection.php',
'RankMath\\WooCommerce\\Sitemap' => __DIR__ . '/../..' . '/includes/modules/woocommerce/class-sitemap.php',
'RankMath\\WooCommerce\\WC_Vars' => __DIR__ . '/../..' . '/includes/modules/woocommerce/class-wc-vars.php',
'RankMath\\WooCommerce\\WooCommerce' => __DIR__ . '/../..' . '/includes/modules/woocommerce/class-woocommerce.php',
'WP_Async_Request' => __DIR__ . '/..' . '/a5hleyrich/wp-background-processing/classes/wp-async-request.php',
'WP_Background_Process' => __DIR__ . '/..' . '/a5hleyrich/wp-background-processing/classes/wp-background-process.php',
'donatj\\UserAgent\\Browsers' => __DIR__ . '/..' . '/donatj/phpuseragentparser/src/UserAgent/Browsers.php',
'donatj\\UserAgent\\Platforms' => __DIR__ . '/..' . '/donatj/phpuseragentparser/src/UserAgent/Platforms.php',
'donatj\\UserAgent\\UserAgent' => __DIR__ . '/..' . '/donatj/phpuseragentparser/src/UserAgent/UserAgent.php',
'donatj\\UserAgent\\UserAgentInterface' => __DIR__ . '/..' . '/donatj/phpuseragentparser/src/UserAgent/UserAgentInterface.php',
'donatj\\UserAgent\\UserAgentParser' => __DIR__ . '/..' . '/donatj/phpuseragentparser/src/UserAgent/UserAgentParser.php',
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInite0bd047aa5058f04568aa38dfc5ac000::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite0bd047aa5058f04568aa38dfc5ac000::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite0bd047aa5058f04568aa38dfc5ac000::$classMap;
}, null, ClassLoader::class);
}
}

View File

@@ -0,0 +1,290 @@
{
"packages": [
{
"name": "a5hleyrich/wp-background-processing",
"version": "1.3.1",
"version_normalized": "1.3.1.0",
"source": {
"type": "git",
"url": "https://github.com/deliciousbrains/wp-background-processing.git",
"reference": "6d1e48165e461260075b9f161b3861c7278f71e7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/deliciousbrains/wp-background-processing/zipball/6d1e48165e461260075b9f161b3861c7278f71e7",
"reference": "6d1e48165e461260075b9f161b3861c7278f71e7",
"shasum": ""
},
"require": {
"php": ">=7.0"
},
"require-dev": {
"phpcompatibility/phpcompatibility-wp": "*",
"phpunit/phpunit": "^8.0",
"spryker/code-sniffer": "^0.17.18",
"wp-coding-standards/wpcs": "^2.3",
"yoast/phpunit-polyfills": "^1.0"
},
"suggest": {
"coenjacobs/mozart": "Easily wrap this library with your own prefix, to prevent collisions when multiple plugins use this library"
},
"time": "2024-02-28T13:39:06+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"classmap": [
"classes/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"authors": [
{
"name": "Delicious Brains",
"email": "nom@deliciousbrains.com"
}
],
"description": "WP Background Processing can be used to fire off non-blocking asynchronous requests or as a background processing tool, allowing you to queue tasks.",
"support": {
"issues": "https://github.com/deliciousbrains/wp-background-processing/issues",
"source": "https://github.com/deliciousbrains/wp-background-processing/tree/1.3.1"
},
"install-path": "../a5hleyrich/wp-background-processing"
},
{
"name": "cmb2/cmb2",
"version": "v2.10.1",
"version_normalized": "2.10.1.0",
"source": {
"type": "git",
"url": "https://github.com/CMB2/CMB2.git",
"reference": "4afc4bb7b92ab6d93aac2247c9a84af773e42532"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/CMB2/CMB2/zipball/4afc4bb7b92ab6d93aac2247c9a84af773e42532",
"reference": "4afc4bb7b92ab6d93aac2247c9a84af773e42532",
"shasum": ""
},
"require": {
"php": ">5.2.4"
},
"require-dev": {
"apigen/apigen": "4.1.2",
"awesomemotive/am-cli-tools": ">=1.3.1",
"nette/utils": "2.5.3",
"phpunit/phpunit": "^6.5",
"yoast/phpunit-polyfills": "^1.0"
},
"suggest": {
"composer/installers": "~1.0"
},
"time": "2022-02-22T14:15:16+00:00",
"type": "wordpress-plugin",
"installation-source": "dist",
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"authors": [
{
"name": "Justin Sternberg",
"email": "justin@dsgnwrks.pro",
"homepage": "https://dsgnwrks.pro",
"role": "Developer"
},
{
"name": "WebDevStudios",
"email": "contact@webdevstudios.com",
"homepage": "https://github.com/WebDevStudios",
"role": "Developer"
}
],
"description": "CMB2 is a metabox, custom fields, and forms library for WordPress that will blow your mind.",
"homepage": "https://github.com/CMB2/CMB2",
"keywords": [
"metabox",
"plugin",
"wordpress"
],
"support": {
"issues": "https://github.com/CMB2/CMB2/issues",
"source": "http://wordpress.org/support/plugin/cmb2"
},
"install-path": "../cmb2/cmb2"
},
{
"name": "donatj/phpuseragentparser",
"version": "v1.8.0",
"version_normalized": "1.8.0.0",
"source": {
"type": "git",
"url": "https://github.com/donatj/PhpUserAgent.git",
"reference": "b8c16fd6e963651c6d86f66cb782ce599d62418e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/donatj/PhpUserAgent/zipball/b8c16fd6e963651c6d86f66cb782ce599d62418e",
"reference": "b8c16fd6e963651c6d86f66cb782ce599d62418e",
"shasum": ""
},
"require": {
"ext-ctype": "*",
"php": ">=5.4.0"
},
"require-dev": {
"camspiers/json-pretty": "~1.0",
"donatj/drop": "*",
"ext-json": "*",
"phpunit/phpunit": "~4.8|~9"
},
"time": "2023-10-27T05:22:44+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [
"src/UserAgentParser.php"
],
"psr-4": {
"donatj\\UserAgent\\": "src/UserAgent"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jesse G. Donat",
"email": "donatj@gmail.com",
"homepage": "https://donatstudios.com",
"role": "Developer"
}
],
"description": "Lightning fast, minimalist PHP UserAgent string parser.",
"homepage": "https://donatstudios.com/PHP-Parser-HTTP_USER_AGENT",
"keywords": [
"browser",
"browser detection",
"parser",
"user agent",
"useragent"
],
"support": {
"issues": "https://github.com/donatj/PhpUserAgent/issues",
"source": "https://github.com/donatj/PhpUserAgent/tree/v1.8.0"
},
"funding": [
{
"url": "https://www.paypal.me/donatj/15",
"type": "custom"
},
{
"url": "https://github.com/donatj",
"type": "github"
},
{
"url": "https://ko-fi.com/donatj",
"type": "ko_fi"
}
],
"install-path": "../donatj/phpuseragentparser"
},
{
"name": "mythemeshop/wordpress-helpers",
"version": "v1.1.22",
"version_normalized": "1.1.22.0",
"source": {
"type": "git",
"url": "https://github.com/MyThemeShopTeam/wordpress-helpers.git",
"reference": "0ee4a87a03dac72e9e503cc4e1b0208d3269f4dc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/MyThemeShopTeam/wordpress-helpers/zipball/0ee4a87a03dac72e9e503cc4e1b0208d3269f4dc",
"reference": "0ee4a87a03dac72e9e503cc4e1b0208d3269f4dc",
"shasum": ""
},
"require": {
"php": ">=5.6"
},
"time": "2023-06-15T08:54:41+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"MyThemeShop\\Helpers\\": "src/"
},
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "MyThemeShop",
"email": "info@mythemeshop.com"
}
],
"description": "Collection of utilities required during development of a plugin or theme for WordPress. Built for developers by developers.",
"support": {
"issues": "https://github.com/MyThemeShopTeam/wordpress-helpers/issues",
"source": "https://github.com/MyThemeShopTeam/wordpress-helpers/tree/v1.1.22"
},
"install-path": "../mythemeshop/wordpress-helpers"
},
{
"name": "woocommerce/action-scheduler",
"version": "3.7.3",
"version_normalized": "3.7.3.0",
"source": {
"type": "git",
"url": "https://github.com/woocommerce/action-scheduler.git",
"reference": "8aa895a6edfeb92f40d6eddc9dfc35df65da38ae"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/woocommerce/action-scheduler/zipball/8aa895a6edfeb92f40d6eddc9dfc35df65da38ae",
"reference": "8aa895a6edfeb92f40d6eddc9dfc35df65da38ae",
"shasum": ""
},
"require": {
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"woocommerce/woocommerce-sniffs": "0.1.0",
"wp-cli/wp-cli": "~2.5.0",
"yoast/phpunit-polyfills": "^2.0"
},
"time": "2024-03-20T10:16:56+00:00",
"type": "wordpress-plugin",
"extra": {
"scripts-description": {
"test": "Run unit tests",
"phpcs": "Analyze code against the WordPress coding standards with PHP_CodeSniffer",
"phpcbf": "Fix coding standards warnings/errors automatically with PHP Code Beautifier"
}
},
"installation-source": "dist",
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0-or-later"
],
"description": "Action Scheduler for WordPress and WooCommerce",
"homepage": "https://actionscheduler.org/",
"support": {
"issues": "https://github.com/woocommerce/action-scheduler/issues",
"source": "https://github.com/woocommerce/action-scheduler/tree/3.7.3"
},
"install-path": "../woocommerce/action-scheduler"
}
],
"dev": true,
"dev-package-names": []
}

View File

@@ -0,0 +1,68 @@
<?php return array(
'root' => array(
'name' => 'rankmath/seo-by-rank-math',
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => 'e08a1fa35f2969e44fd0185c93d7dacaeeae9c32',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev' => true,
),
'versions' => array(
'a5hleyrich/wp-background-processing' => array(
'pretty_version' => '1.3.1',
'version' => '1.3.1.0',
'reference' => '6d1e48165e461260075b9f161b3861c7278f71e7',
'type' => 'library',
'install_path' => __DIR__ . '/../a5hleyrich/wp-background-processing',
'aliases' => array(),
'dev_requirement' => false,
),
'cmb2/cmb2' => array(
'pretty_version' => 'v2.10.1',
'version' => '2.10.1.0',
'reference' => '4afc4bb7b92ab6d93aac2247c9a84af773e42532',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../cmb2/cmb2',
'aliases' => array(),
'dev_requirement' => false,
),
'donatj/phpuseragentparser' => array(
'pretty_version' => 'v1.8.0',
'version' => '1.8.0.0',
'reference' => 'b8c16fd6e963651c6d86f66cb782ce599d62418e',
'type' => 'library',
'install_path' => __DIR__ . '/../donatj/phpuseragentparser',
'aliases' => array(),
'dev_requirement' => false,
),
'mythemeshop/wordpress-helpers' => array(
'pretty_version' => 'v1.1.22',
'version' => '1.1.22.0',
'reference' => '0ee4a87a03dac72e9e503cc4e1b0208d3269f4dc',
'type' => 'library',
'install_path' => __DIR__ . '/../mythemeshop/wordpress-helpers',
'aliases' => array(),
'dev_requirement' => false,
),
'rankmath/seo-by-rank-math' => array(
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => 'e08a1fa35f2969e44fd0185c93d7dacaeeae9c32',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev_requirement' => false,
),
'woocommerce/action-scheduler' => array(
'pretty_version' => '3.7.3',
'version' => '3.7.3.0',
'reference' => '8aa895a6edfeb92f40d6eddc9dfc35df65da38ae',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../woocommerce/action-scheduler',
'aliases' => array(),
'dev_requirement' => false,
),
),
);

View File

@@ -0,0 +1,26 @@
<?php
// platform_check.php @generated by Composer
$issues = array();
if (!(PHP_VERSION_ID >= 70000)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.0.0". You are running ' . PHP_VERSION . '.';
}
if ($issues) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
} elseif (!headers_sent()) {
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
}
}
trigger_error(
'Composer detected issues in your platform: ' . implode(' ', $issues),
E_USER_ERROR
);
}

View File

@@ -0,0 +1,15 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
$class = new ReflectionClass($argv[1]);
echo "Predefined helper constants from `{$class->getName()}`\n\n";
echo "| Constant | {$argv[2]} | \n|----------|----------| \n";
foreach( $class->getConstants() as $constant => $value ) {
echo "| `{$class->getShortName()}::{$constant}` | {$value} | \n";
}
echo "\n";

View File

@@ -0,0 +1,91 @@
<mddoc>
<docpage target="README.md">
<autoloader namespace="donatj\UserAgent" type="psr4" root="src" />
<section title="PHP User Agent Parser">
<text><![CDATA[
[![Join the chat at https://gitter.im/PhpUserAgentParser/Lobby](https://badges.gitter.im/PhpUserAgentParser/Lobby.svg)](https://gitter.im/PhpUserAgentParser/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
]]></text>
<badge-poser type="version"/>
<badge-poser type="downloads"/>
<badge-poser type="license"/>
<badge-github-action name="donatj/phpUserAgent" workflow-file="ci.yml"/>
<section title="What It Is">
<text><![CDATA[
A simple, streamlined PHP user-agent parser!
Licensed under the MIT license: https://www.opensource.org/licenses/mit-license.php
]]></text>
</section>
<section title="Upgrading to `1.*`">
<text><![CDATA[
The new `1.*` release **does not break compatibility** with `0.*` and nothing need to change to upgrade. However, the global `parse_user_agent` is now deprecated; it has been replaced with the namespaced `\donatj\UserAgent\parse_user_agent` and functions exactly the same. You can easily replace any existing call to `parse_user_agent` with `\donatj\UserAgent\parse_user_agent`
In addition, 1.x adds a convenience object wrapper you may use should you prefer. More information on this is in the Usage section below.
]]></text>
</section>
<section title="Why Use This">
<text><![CDATA[
You have your choice in user-agent parsers. This one detects **all modern browsers** in a very light, quick, understandable fashion.
It is less than 200 lines of code, and consists of just three regular expressions!
It can also correctly identify exotic versions of IE others fail on.
It offers 100% unit test coverage, is installable via Composer, and is very easy to use.
]]></text>
</section>
<section title="What It Does Not Do">
<text><![CDATA[
This is not meant as a browser "knowledge engine" but rather a simple parser. Anything not adequately provided directly by the user agent string itself will simply not be provided by this.
]]></text>
<section title="OS Versions">
<text><![CDATA[
User-agent strings **are not** a reliable source of OS Version!
- Many agents simply don't send the information.
- Others provide varying levels of accuracy.
- Parsing Windows versions alone almost nearly doubles the size of the code.
I'm much more interested in keeping this thing *tiny* and accurate than adding niché features and would rather focus on things that can be **done well**.
All that said, there is the start of a [branch to do it](https://github.com/donatj/PhpUserAgent/tree/os_version_detection) I created for a client if you want to poke it, I update it from time to time, but frankly if you need to *reliably detect OS Version*, using user-agent isn't the way to do it. I'd go with JavaScript.
]]></text>
</section>
<section title="Undetectable Browsers">
<text><![CDATA[
- **Brave** - Brave is simply not differentiable from Chrome. This was a design decision on their part.
]]></text>
</section>
<section title="Undetectable Platforms">
<text><![CDATA[
- **iPadOS 13+** - Starting with iPadOS 13 and further hardened in 14, iPadOS returns the **exact** same string as macOS. It is no longer distinguishable by UA string. (See: [#69](https://github.com/donatj/PhpUserAgent/issues/69))
]]></text>
</section>
</section>
<section title="Requirements">
<composer-requires/>
</section>
<section title="Installing">
<text>PHP User Agent is available through Packagist via Composer.</text>
<composer-install/>
</section>
<section title="Usage">
<text>The classic procedural use is as simple as:</text>
<source name="examples/procedural.php" lang="php" />
<text>The new object-oriented wrapper form:</text>
<source name="examples/object-oriented.php" lang="php" />
</section>
<section title="Currently Detected Platforms">
<exec cmd="php .helpers/constants.php 'donatj\UserAgent\Platforms' 'Platform'"/>
</section>
<section title="Currently Detected Browsers">
<exec cmd="php .helpers/constants.php 'donatj\UserAgent\Browsers' 'Browser'"/>
</section>
<text><![CDATA[
More information is available at [Donat Studios](https://donatstudios.com/PHP-Parser-HTTP_USER_AGENT).
]]></text>
</section>
</docpage>
</mddoc>

View File

@@ -0,0 +1,22 @@
The MIT License
===============
Copyright (c) 2013 Jesse G. Donat
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,18 @@
.PHONY: test
test:
./vendor/bin/phpunit --coverage-text
.PHONY: clean
clean:
-rm tests/user_agents.json
touch tests/user_agents.json
.PHONY: generate
generate:
php bin/user_agent_sorter.php > tests/user_agents.tmp.json && mv tests/user_agents.tmp.json tests/user_agents.dist.json
php bin/constant_generator.php
.PHONY: init
init:
php bin/init_user_agent.php > tests/user_agents.tmp.json && mv tests/user_agents.tmp.json tests/user_agents.dist.json
make generate

View File

@@ -0,0 +1,18 @@
<?php
use donatj\UserAgent\UserAgentParser;
// if you're using composer
require __DIR__ . '/../vendor/autoload.php';
$parser = new UserAgentParser();
// object-oriented call
$ua = $parser->parse();
// or
// command style invocation
$ua = $parser();
echo $ua->platform() . PHP_EOL;
echo $ua->browser() . PHP_EOL;
echo $ua->browserVersion() . PHP_EOL;

View File

@@ -0,0 +1,14 @@
<?php
// if you're using composer
require __DIR__ . '/../vendor/autoload.php';
// v0 style global function - @deprecated
$uaInfo = parse_user_agent();
// or
// modern namespaced function
$uaInfo = donatj\UserAgent\parse_user_agent();
echo $uaInfo[donatj\UserAgent\PLATFORM] . PHP_EOL;
echo $uaInfo[donatj\UserAgent\BROWSER] . PHP_EOL;
echo $uaInfo[donatj\UserAgent\BROWSER_VERSION] . PHP_EOL;

View File

@@ -0,0 +1,58 @@
<?php
// DO NOT EDIT THIS FILE - IT IS GENERATED BY constant_generator.php
namespace donatj\UserAgent;
interface Browsers {
const ADSBOT_GOOGLE = 'AdsBot-Google';
const ANDROID_BROWSER = 'Android Browser';
const APPLEBOT = 'Applebot';
const BAIDUSPIDER = 'Baiduspider';
const BINGBOT = 'bingbot';
const BLACKBERRY_BROWSER = 'BlackBerry Browser';
const BROWSER = 'Browser';
const BUNJALLOO = 'Bunjalloo';
const CAMINO = 'Camino';
const CHROME = 'Chrome';
const CURL = 'curl';
const EDGE = 'Edge';
const FACEBOOKEXTERNALHIT = 'facebookexternalhit';
const FEEDVALIDATOR = 'FeedValidator';
const FIREFOX = 'Firefox';
const GOOGLEBOT = 'Googlebot';
const GOOGLEBOT_IMAGE = 'Googlebot-Image';
const GOOGLEBOT_VIDEO = 'Googlebot-Video';
const HEADLESSCHROME = 'HeadlessChrome';
const IEMOBILE = 'IEMobile';
const IMESSAGEBOT = 'iMessageBot';
const KINDLE = 'Kindle';
const LYNX = 'Lynx';
const MIDORI = 'Midori';
const MIUIBROWSER = 'MiuiBrowser';
const MSIE = 'MSIE';
const MSNBOT_MEDIA = 'msnbot-media';
const NETFRONT = 'NetFront';
const NINTENDOBROWSER = 'NintendoBrowser';
const OCULUSBROWSER = 'OculusBrowser';
const OPERA = 'Opera';
const PUFFIN = 'Puffin';
const SAFARI = 'Safari';
const SAILFISHBROWSER = 'SailfishBrowser';
const SAMSUNGBROWSER = 'SamsungBrowser';
const SILK = 'Silk';
const SLACKBOT = 'Slackbot';
const TELEGRAMBOT = 'TelegramBot';
const TIZENBROWSER = 'TizenBrowser';
const TWITTERBOT = 'Twitterbot';
const UC_BROWSER = 'UC Browser';
const VALVE_STEAM_TENFOOT = 'Valve Steam Tenfoot';
const VIVALDI = 'Vivaldi';
const WGET = 'Wget';
const WORDPRESS = 'WordPress';
const YANDEX = 'Yandex';
const YANDEXBOT = 'YandexBot';
}

View File

@@ -0,0 +1,42 @@
<?php
// DO NOT EDIT THIS FILE - IT IS GENERATED BY constant_generator.php
namespace donatj\UserAgent;
interface Platforms {
const MACINTOSH = 'Macintosh';
const CHROME_OS = 'Chrome OS';
const LINUX = 'Linux';
const WINDOWS = 'Windows';
const ANDROID = 'Android';
const BLACKBERRY = 'BlackBerry';
const FREEBSD = 'FreeBSD';
const IPAD = 'iPad';
const IPHONE = 'iPhone';
const IPOD = 'iPod';
const KINDLE = 'Kindle';
const KINDLE_FIRE = 'Kindle Fire';
const NETBSD = 'NetBSD';
const NEW_NINTENDO_3DS = 'New Nintendo 3DS';
const NINTENDO_3DS = 'Nintendo 3DS';
const NINTENDO_DS = 'Nintendo DS';
const NINTENDO_SWITCH = 'Nintendo Switch';
const NINTENDO_WII = 'Nintendo Wii';
const NINTENDO_WIIU = 'Nintendo WiiU';
const OPENBSD = 'OpenBSD';
const PLAYBOOK = 'PlayBook';
const PLAYSTATION_3 = 'PlayStation 3';
const PLAYSTATION_4 = 'PlayStation 4';
const PLAYSTATION_5 = 'PlayStation 5';
const PLAYSTATION_VITA = 'PlayStation Vita';
const SAILFISH = 'Sailfish';
const SYMBIAN = 'Symbian';
const TIZEN = 'Tizen';
const WINDOWS_PHONE = 'Windows Phone';
const XBOX = 'Xbox';
const XBOX_ONE = 'Xbox One';
}

View File

@@ -0,0 +1,57 @@
<?php
namespace donatj\UserAgent;
class UserAgent implements UserAgentInterface {
/**
* @var string|null
*/
private $platform;
/**
* @var string|null
*/
private $browser;
/**
* @var string|null
*/
private $browserVersion;
/**
* UserAgent constructor.
*
* @param string|null $platform
* @param string|null $browser
* @param string|null $browserVersion
*/
public function __construct( $platform, $browser, $browserVersion ) {
$this->platform = $platform;
$this->browser = $browser;
$this->browserVersion = $browserVersion;
}
/**
* @return string|null
* @see \donatj\UserAgent\Platforms for a list of tested platforms
*/
public function platform() {
return $this->platform;
}
/**
* @return string|null
* @see \donatj\UserAgent\Browsers for a list of tested browsers.
*/
public function browser() {
return $this->browser;
}
/**
* The version string. Formatting depends on the browser.
*
* @return string|null
*/
public function browserVersion() {
return $this->browserVersion;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace donatj\UserAgent;
interface UserAgentInterface {
/**
* @return string|null
* @see \donatj\UserAgent\Platforms for a list of tested platforms
*/
public function platform();
/**
* @return string|null
* @see \donatj\UserAgent\Browsers for a list of tested browsers.
*/
public function browser();
/**
* The version string. Formatting depends on the browser.
*
* @return string|null
*/
public function browserVersion();
}

View File

@@ -0,0 +1,39 @@
<?php
namespace donatj\UserAgent;
class UserAgentParser {
/**
* Parses a user agent string into its important parts, provide an object
*
* @param string|null $u_agent User agent string to parse or null. Uses $_SERVER['HTTP_USER_AGENT'] on NULL
* @return UserAgent an object with 'browser', 'browserVersion' and 'platform' methods
* @throws \InvalidArgumentException on not having a proper user agent to parse.
* @see \donatj\UserAgent\parse_user_agent()
*
*/
public function parse( $u_agent = null ) {
$parsed = parse_user_agent($u_agent);
return new UserAgent(
$parsed[PLATFORM],
$parsed[BROWSER],
$parsed[BROWSER_VERSION]
);
}
/**
* Parses a user agent string into its important parts
*
* @param string|null $u_agent User agent string to parse or null. Uses $_SERVER['HTTP_USER_AGENT'] on NULL
* @return UserAgent an object with 'browser', 'browserVersion' and 'platform' methods
* @throws \InvalidArgumentException on not having a proper user agent to parse.
* @see \donatj\UserAgent\parse_user_agent()
*
*/
public function __invoke( $u_agent = null ) {
return $this->parse($u_agent);
}
}

View File

@@ -0,0 +1,218 @@
<?php
/**
* @author Jesse G. Donat <donatj@gmail.com>
*
* @link https://donatstudios.com/PHP-Parser-HTTP_USER_AGENT
* @link https://github.com/donatj/PhpUserAgent
*
* @license MIT https://github.com/donatj/PhpUserAgent/blob/master/LICENSE.md
*/
namespace {
/**
* Parses a user agent string into its important parts
*
* This method is defined for backwards comparability with the old global method.
*
* @param string|null $u_agent User agent string to parse or null. Uses $_SERVER['HTTP_USER_AGENT'] on NULL
* @return string[] an array with 'browser', 'version' and 'platform' keys
* @throws \InvalidArgumentException on not having a proper user agent to parse.
*
* @deprecated This exists for backwards compatibility with 0.x and will likely be removed in 2.x
* @see \donatj\UserAgent\parse_user_agent
*/
function parse_user_agent( $u_agent = null ) {
return \donatj\UserAgent\parse_user_agent($u_agent);
}
}
namespace donatj\UserAgent {
const PLATFORM = 'platform';
const BROWSER = 'browser';
const BROWSER_VERSION = 'version';
/**
* Parses a user agent string into its important parts
*
* @param string|null $u_agent User agent string to parse or null. Uses $_SERVER['HTTP_USER_AGENT'] on NULL
* @return string[] an array with 'browser', 'version' and 'platform' keys
* @throws \InvalidArgumentException on not having a proper user agent to parse.
*/
function parse_user_agent( $u_agent = null ) {
if( $u_agent === null && isset($_SERVER['HTTP_USER_AGENT']) ) {
$u_agent = (string)$_SERVER['HTTP_USER_AGENT'];
}
if( $u_agent === null ) {
throw new \InvalidArgumentException('parse_user_agent requires a user agent');
}
$platform = null;
$browser = null;
$version = null;
$return = [ PLATFORM => &$platform, BROWSER => &$browser, BROWSER_VERSION => &$version ];
if( !$u_agent ) {
return $return;
}
if( preg_match('/\((.*?)\)/m', $u_agent, $parent_matches) ) {
preg_match_all(<<<'REGEX'
/(?P<platform>BB\d+;|Android|Adr|Symbian|Sailfish|CrOS|Tizen|iPhone|iPad|iPod|Linux|(?:Open|Net|Free)BSD|Macintosh|
Windows(?:\ Phone)?|Silk|linux-gnu|BlackBerry|PlayBook|X11|(?:New\ )?Nintendo\ (?:WiiU?|3?DS|Switch)|Xbox(?:\ One)?)
(?:\ [^;]*)?
(?:;|$)/imx
REGEX
, $parent_matches[1], $result);
$priority = [ 'Xbox One', 'Xbox', 'Windows Phone', 'Tizen', 'Android', 'FreeBSD', 'NetBSD', 'OpenBSD', 'CrOS', 'X11', 'Sailfish' ];
$result[PLATFORM] = array_unique($result[PLATFORM]);
if( count($result[PLATFORM]) > 1 ) {
if( $keys = array_intersect($priority, $result[PLATFORM]) ) {
$platform = reset($keys);
} else {
$platform = $result[PLATFORM][0];
}
} elseif( isset($result[PLATFORM][0]) ) {
$platform = $result[PLATFORM][0];
}
}
if( $platform == 'linux-gnu' || $platform == 'X11' ) {
$platform = 'Linux';
} elseif( $platform == 'CrOS' ) {
$platform = 'Chrome OS';
} elseif( $platform == 'Adr' ) {
$platform = 'Android';
} elseif( $platform === null ) {
if(preg_match_all('%(?P<platform>Android)[:/ ]%ix', $u_agent, $result)) {
$platform = $result[PLATFORM][0];
}
}
preg_match_all(<<<'REGEX'
%(?P<browser>Camino|Kindle(\ Fire)?|Firefox|Iceweasel|IceCat|Safari|MSIE|Trident|AppleWebKit|
TizenBrowser|(?:Headless)?Chrome|YaBrowser|Vivaldi|IEMobile|Opera|OPR|Silk|Midori|(?-i:Edge)|EdgA?|CriOS|UCBrowser|Puffin|
OculusBrowser|SamsungBrowser|SailfishBrowser|XiaoMi/MiuiBrowser|YaApp_Android|
Baiduspider|Applebot|Facebot|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|
Valve\ Steam\ Tenfoot|
NintendoBrowser|PLAYSTATION\ (?:\d|Vita)+)
\)?;?
(?:[:/ ](?P<version>[0-9A-Z.]+)|/[A-Z]*)%ix
REGEX
, $u_agent, $result);
// If nothing matched, return null (to avoid undefined index errors)
if( !isset($result[BROWSER][0], $result[BROWSER_VERSION][0]) ) {
if( preg_match('%^(?!Mozilla)(?P<browser>[A-Z0-9\-]+)([/ :](?P<version>[0-9A-Z.]+))?%ix', $u_agent, $result) ) {
return [ PLATFORM => $platform ?: null, BROWSER => $result[BROWSER], BROWSER_VERSION => empty($result[BROWSER_VERSION]) ? null : $result[BROWSER_VERSION] ];
}
return $return;
}
if( preg_match('/rv:(?P<version>[0-9A-Z.]+)/i', $u_agent, $rv_result) ) {
$rv_result = $rv_result[BROWSER_VERSION];
}
$browser = $result[BROWSER][0];
$version = $result[BROWSER_VERSION][0];
$lowerBrowser = array_map('strtolower', $result[BROWSER]);
$find = function ( $search, &$key = null, &$value = null ) use ( $lowerBrowser ) {
$search = (array)$search;
foreach( $search as $val ) {
$xkey = array_search(strtolower($val), $lowerBrowser);
if( $xkey !== false ) {
$value = $val;
$key = $xkey;
return true;
}
}
return false;
};
$findT = function ( array $search, &$key = null, &$value = null ) use ( $find ) {
$value2 = null;
if( $find(array_keys($search), $key, $value2) ) {
$value = $search[$value2];
return true;
}
return false;
};
$key = 0;
$val = '';
if( $findT([ 'OPR' => 'Opera', 'Facebot' => 'iMessageBot', 'UCBrowser' => 'UC Browser', 'YaBrowser' => 'Yandex', 'YaApp_Android' => 'Yandex', 'Iceweasel' => 'Firefox', 'Icecat' => 'Firefox', 'CriOS' => 'Chrome', 'Edg' => 'Edge', 'EdgA' => 'Edge', 'XiaoMi/MiuiBrowser' => 'MiuiBrowser' ], $key, $browser) ) {
$version = is_numeric(substr($result[BROWSER_VERSION][$key], 0, 1)) ? $result[BROWSER_VERSION][$key] : null;
} elseif( $find('Playstation Vita', $key, $platform) ) {
$platform = 'PlayStation Vita';
$browser = 'Browser';
} elseif( $find([ 'Kindle Fire', 'Silk' ], $key, $val) ) {
$browser = $val == 'Silk' ? 'Silk' : 'Kindle';
$platform = 'Kindle Fire';
if( !($version = $result[BROWSER_VERSION][$key]) || !is_numeric($version[0]) ) {
$version = $result[BROWSER_VERSION][array_search('Version', $result[BROWSER])];
}
} elseif( $find('NintendoBrowser', $key) || $platform == 'Nintendo 3DS' ) {
$browser = 'NintendoBrowser';
$version = $result[BROWSER_VERSION][$key];
} elseif( $find('Kindle', $key, $platform) ) {
$browser = $result[BROWSER][$key];
$version = $result[BROWSER_VERSION][$key];
} elseif( $find('Opera', $key, $browser) ) {
$find('Version', $key);
$version = $result[BROWSER_VERSION][$key];
} elseif( $find('Puffin', $key, $browser) ) {
$version = $result[BROWSER_VERSION][$key];
if( strlen($version) > 3 ) {
$part = substr($version, -2);
if( ctype_upper($part) ) {
$version = substr($version, 0, -2);
$flags = [ 'IP' => 'iPhone', 'IT' => 'iPad', 'AP' => 'Android', 'AT' => 'Android', 'WP' => 'Windows Phone', 'WT' => 'Windows' ];
if( isset($flags[$part]) ) {
$platform = $flags[$part];
}
}
}
} elseif( $find([ 'Applebot', 'IEMobile', 'Edge', 'Midori', 'Vivaldi', 'OculusBrowser', 'SamsungBrowser', 'Valve Steam Tenfoot', 'Chrome', 'HeadlessChrome', 'SailfishBrowser' ], $key, $browser) ) {
$version = $result[BROWSER_VERSION][$key];
} elseif( $rv_result && $find('Trident') ) {
$browser = 'MSIE';
$version = $rv_result;
} elseif( $browser == 'AppleWebKit' ) {
if( $platform == 'Android' ) {
$browser = 'Android Browser';
} elseif( strpos((string)$platform, 'BB') === 0 ) {
$browser = 'BlackBerry Browser';
$platform = 'BlackBerry';
} elseif( $platform == 'BlackBerry' || $platform == 'PlayBook' ) {
$browser = 'BlackBerry Browser';
} else {
$find('Safari', $key, $browser) || $find('TizenBrowser', $key, $browser);
}
$find('Version', $key);
$version = $result[BROWSER_VERSION][$key];
} elseif( $pKey = preg_grep('/playstation \d/i', $result[BROWSER]) ) {
$pKey = reset($pKey);
$platform = 'PlayStation ' . preg_replace('/\D/', '', $pKey);
$browser = 'NetFront';
}
return $return;
}
}

View File

@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
NinjaDB Copyright (C) 2017 WPManageNinja
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@@ -0,0 +1,79 @@
<?php
/**
* The List Table Base CLass.
*
* @since 1.0.0
* @package MyThemeShop
* @subpackage MyThemeShop\Admin
* @author MyThemeShop <admin@mythemeshop.com>
*/
namespace MyThemeShop\Admin;
use WP_List_Table;
use MyThemeShop\Helpers\Param;
/**
* List_Table class.
*/
class List_Table extends WP_List_Table {
/**
* The Constructor.
*
* @param array $args Array of arguments.
*/
public function __construct( $args = [] ) {
parent::__construct( $args );
}
/**
* Message to be displayed when there are no items.
*/
public function no_items() {
echo isset( $this->_args['no_items'] ) ? $this->_args['no_items'] : esc_html__( 'No items found.' );
}
/**
* Get order setting.
*
* @return string
*/
protected function get_order() {
$order = Param::request( 'order', 'desc' );
return in_array( $order, [ 'desc', 'asc' ], true ) ? strtoupper( $order ) : 'DESC';
}
/**
* Get orderby setting.
*
* @param string $default (Optional) Extract order by from request.
*
* @return string
*/
protected function get_orderby( $default = 'create_date' ) {
return Param::get( 'orderby', $default, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK );
}
/**
* Get search query variable.
*
* @return bool|string
*/
protected function get_search() {
return Param::request( 's', false, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_BACKTICK );
}
/**
* Set column headers.
*
* @codeCoverageIgnore
*/
protected function set_column_headers() {
$this->_column_headers = [
$this->get_columns(),
[],
$this->get_sortable_columns(),
];
}
}

View File

@@ -0,0 +1,326 @@
<?php
/**
* The admin-page functionality.
*
* @since 1.0.0
* @package MyThemeShop
* @subpackage MyThemeShop\Admin
* @author MyThemeShop <admin@mythemeshop.com>
*/
namespace MyThemeShop\Admin;
use MyThemeShop\Helpers\Param;
/**
* Page class.
*/
class Page {
/**
* Unique ID used for menu_slug.
*
* @var string
*/
public $id = null;
/**
* The text to be displayed in the title tags of the page.
*
* @var string
*/
public $title = null;
/**
* The slug name for the parent menu.
*
* @var string
*/
public $parent = null;
/**
* The The on-screen name text for the menu.
*
* @var string
*/
public $menu_title = null;
/**
* The capability required for this menu to be displayed to the user.
*
* @var string
*/
public $capability = 'manage_options';
/**
* The icon for this menu.
*
* @var string
*/
public $icon = 'dashicons-art';
/**
* The position in the menu order this menu should appear.
*
* @var int
*/
public $position = -1;
/**
* The function/file that displays the page content for the menu page.
*
* @var string|callable
*/
public $render = null;
/**
* The function that run on page POST to save data.
*
* @var callable
*/
public $onsave = null;
/**
* Hold contextual help tabs.
*
* @var array
*/
public $help = null;
/**
* Hold scripts and styles.
*
* @var array
*/
public $assets = null;
/**
* Check if plugin is network active.
*
* @var array
*/
public $is_network = false;
/**
* Hold classes for body tag.
*
* @var array
*/
public $classes = null;
/**
* The Constructor.
*
* @param string $id Admin page unique id.
* @param string $title Title of the admin page.
* @param array $config Optional. Override page settings.
*/
public function __construct( $id, $title, $config = [] ) {
// Early bail!
if ( ! $id ) {
wp_die( esc_html__( '$id variable required' ), esc_html__( 'Variable Required' ) );
}
if ( ! $title ) {
wp_die( esc_html__( '$title variable required' ), esc_html__( 'Variable Required' ) );
}
$this->id = $id;
$this->title = $title;
foreach ( $config as $key => $value ) {
$this->$key = $value;
}
if ( ! $this->menu_title ) {
$this->menu_title = $title;
}
add_action( 'init', [ $this, 'init' ], 25 );
}
/**
* Init admin page when WordPress Initialises.
*
* @codeCoverageIgnore
*/
public function init() {
$priority = $this->parent ? intval( $this->position ) : -1;
add_action( $this->is_network ? 'network_admin_menu' : 'admin_menu', [ $this, 'register_menu' ], $priority );
// If not the page is not this page stop here.
if ( ! $this->is_current_page() ) {
return;
}
$hooks = [
'admin_init' => [
'callback' => 'save',
'condition' => ! is_null( $this->onsave ) && is_callable( $this->onsave ),
],
'admin_enqueue_scripts' => [
'callback' => 'enqueue',
'condition' => ! empty( $this->assets ),
],
'admin_head' => [
'callback' => 'contextual_help',
'condition' => ! empty( $this->help ),
],
'admin_body_class' => [
'callback' => 'body_class',
'condition' => ! empty( $this->classes ),
],
];
foreach ( $hooks as $hook => $data ) {
if ( true === $data['condition'] ) {
add_action( $hook, [ $this, $data['callback'] ] );
}
}
}
/**
* Register Admin Menu.
*
* @codeCoverageIgnore
*/
public function register_menu() {
if ( ! $this->parent ) {
add_menu_page( $this->title, $this->menu_title, $this->capability, $this->id, [ $this, 'display' ], $this->icon, $this->position );
return;
}
add_submenu_page( $this->parent, $this->title, $this->menu_title, $this->capability, $this->id, [ $this, 'display' ] );
}
/**
* Enqueue styles and scripts.
*
* @codeCoverageIgnore
*/
public function enqueue() {
$this->enqueue_styles();
$this->enqueue_scripts();
}
/**
* Add classes to <body> of WordPress admin.
*
* @codeCoverageIgnore
*
* @param string $classes Space-separated list of CSS classes.
*
* @return string
*/
public function body_class( $classes = '' ) {
return $classes . ' ' . join( ' ', $this->classes );
}
/**
* Save anything you want using onsave function.
*
* @codeCoverageIgnore
*/
public function save() {
call_user_func( $this->onsave, $this );
}
/**
* Contextual Help.
*
* @codeCoverageIgnore
*/
public function contextual_help() {
$screen = get_current_screen();
foreach ( $this->help as $tab_id => $tab ) {
$tab['id'] = $tab_id;
$tab['content'] = $this->get_help_content( $tab );
$screen->add_help_tab( $tab );
}
}
/**
* Render admin page content using render function you passed in config.
*
* @codeCoverageIgnore
*/
public function display() {
if ( is_null( $this->render ) ) {
return;
}
if ( is_callable( $this->render ) ) {
call_user_func( $this->render, $this );
return;
}
if ( is_string( $this->render ) ) {
include_once $this->render;
}
}
/**
* Is the page is currrent page.
*
* @return bool
*/
public function is_current_page() {
return Param::get( 'page' ) === $this->id;
}
/**
* Enqueue styles
*
* @codeCoverageIgnore
*/
private function enqueue_styles() {
if ( ! isset( $this->assets['styles'] ) || empty( $this->assets['styles'] ) ) {
return;
}
foreach ( $this->assets['styles'] as $handle => $src ) {
wp_enqueue_style( $handle, $src, null );
}
}
/**
* Enqueue scripts.
*
* @codeCoverageIgnore
*/
private function enqueue_scripts() {
if ( ! isset( $this->assets['scripts'] ) || empty( $this->assets['scripts'] ) ) {
return;
}
foreach ( $this->assets['scripts'] as $handle => $src ) {
wp_enqueue_script( $handle, $src, null, null, true );
}
}
/**
* Get tab content
*
* @codeCoverageIgnore
*
* @param array $tab Tab to get content for.
*
* @return string
*/
private function get_help_content( $tab ) {
ob_start();
// If it is a function.
if ( isset( $tab['content'] ) && is_callable( $tab['content'] ) ) {
call_user_func( $tab['content'] );
}
// If it is a file.
if ( isset( $tab['view'] ) && $tab['view'] ) {
require $tab['view'];
}
return ob_get_clean();
}
}

Some files were not shown because too many files have changed in this diff Show More