first commit
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* Block Renderer REST API.
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
/**
|
||||
* Controller which provides REST endpoint for rendering a block.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @see WP_REST_Controller
|
||||
*/
|
||||
class Sight_Rest_Block_Renderer_Controller extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Constructs the controller.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->namespace = 'wp/v2';
|
||||
$this->rest_base = 'sight-renderer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the necessary REST API routes, one for each dynamic block.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function register_routes() {
|
||||
$block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
|
||||
|
||||
foreach ( $block_types as $block_type ) {
|
||||
if ( ! $block_type->is_dynamic() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<name>' . $block_type->name . ')',
|
||||
array(
|
||||
'args' => array(
|
||||
'name' => array(
|
||||
'description' => __( 'Unique registered name for the block.' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
'attributes' => array(
|
||||
/* translators: %s is the name of the block */
|
||||
'description' => sprintf( __( 'Attributes for %s block' ), $block_type->name ),
|
||||
'type' => 'object',
|
||||
'additionalProperties' => false,
|
||||
'properties' => $block_type->get_attributes(),
|
||||
'default' => array(),
|
||||
),
|
||||
'post_id' => array(
|
||||
'description' => __( 'ID of the post context.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given request has access to read blocks.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request Request.
|
||||
* @return true|WP_Error True if the request has read access, WP_Error object otherwise.
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
global $post;
|
||||
|
||||
$post_id = isset( $request['post_id'] ) ? intval( $request['post_id'] ) : 0;
|
||||
|
||||
if ( 0 < $post_id ) {
|
||||
$post = get_post( $post_id );
|
||||
|
||||
if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
|
||||
return new WP_Error(
|
||||
'block_cannot_read',
|
||||
__( 'Sorry, you are not allowed to read blocks of this post.' ),
|
||||
array(
|
||||
'status' => rest_authorization_required_code(),
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if ( ! current_user_can( 'edit_posts' ) ) {
|
||||
return new WP_Error(
|
||||
'block_cannot_read',
|
||||
__( 'Sorry, you are not allowed to read blocks as this user.' ),
|
||||
array(
|
||||
'status' => rest_authorization_required_code(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns block output from block's registered render_callback.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
global $post;
|
||||
|
||||
$post_id = isset( $request['post_id'] ) ? intval( $request['post_id'] ) : 0;
|
||||
|
||||
if ( 0 < $post_id ) {
|
||||
$post = get_post( $post_id );
|
||||
|
||||
// Set up postdata since this will be needed if post_id was set.
|
||||
setup_postdata( $post );
|
||||
}
|
||||
$registry = WP_Block_Type_Registry::get_instance();
|
||||
$block = $registry->get_registered( $request['name'] );
|
||||
|
||||
if ( null === $block ) {
|
||||
return new WP_Error(
|
||||
'block_invalid',
|
||||
__( 'Invalid block.' ),
|
||||
array(
|
||||
'status' => 404,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'rendered' => $block->render( $request->get_param( 'attributes' ) ),
|
||||
);
|
||||
return rest_ensure_response( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves block's output schema, conforming to JSON Schema.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @return array Item schema data.
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
return array(
|
||||
'$schema' => 'http://json-schema.org/schema#',
|
||||
'title' => 'rendered-block',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'rendered' => array(
|
||||
'description' => __( 'The rendered block.' ),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'context' => array( 'edit' ),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
add_action(
|
||||
'rest_api_init', function() {
|
||||
// Block Renderer.
|
||||
$controller = new Sight_Rest_Block_Renderer_Controller();
|
||||
|
||||
$controller->register_routes();
|
||||
}, 99
|
||||
);
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Utils Is Field Visible.
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Utils Is Field Visible.
|
||||
*/
|
||||
class Sight_Utils_Is_Field_Visible {
|
||||
/**
|
||||
* Compare 2 values
|
||||
*
|
||||
* @param mixed $lval Left value.
|
||||
* @param string $operator Operator.
|
||||
* @param mixed $rval Right value.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function compare( $lval, $operator, $rval ) {
|
||||
$check_result = true;
|
||||
|
||||
switch ( $operator ) {
|
||||
case '==':
|
||||
$check_result = $lval == $rval;
|
||||
break;
|
||||
case '===':
|
||||
$check_result = $lval === $rval;
|
||||
break;
|
||||
case '!=':
|
||||
$check_result = $lval != $rval;
|
||||
break;
|
||||
case '!==':
|
||||
$check_result = $lval !== $rval;
|
||||
break;
|
||||
case '>=':
|
||||
$check_result = $lval >= $rval;
|
||||
break;
|
||||
case '<=':
|
||||
$check_result = $lval <= $rval;
|
||||
break;
|
||||
case '>':
|
||||
$check_result = $lval > $rval;
|
||||
break;
|
||||
case '<':
|
||||
$check_result = $lval < $rval;
|
||||
break;
|
||||
case 'AND':
|
||||
$check_result = $lval && $rval;
|
||||
break;
|
||||
case 'OR':
|
||||
$check_result = $lval || $rval;
|
||||
break;
|
||||
default:
|
||||
$check_result = $lval;
|
||||
break;
|
||||
}
|
||||
|
||||
return $check_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check condition
|
||||
*
|
||||
* @param array $conditions - Conditions array.
|
||||
* @param array $attributes - Available block attributes.
|
||||
* @param string $relation - Can be one of 'AND' or 'OR'.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function check_condition( $conditions, $attributes, $relation ) {
|
||||
$child_relation = ( 'AND' === $relation ) ? 'OR' : 'AND';
|
||||
|
||||
// By default result will be TRUE for relation AND and FALSE for relation OR.
|
||||
$result = 'AND' === $relation;
|
||||
|
||||
foreach ( $conditions as $data ) {
|
||||
if ( is_array( $data ) && ! isset( $data['field'] ) ) {
|
||||
$result = self::compare( $result, $relation, self::check_condition( $data, $attributes, $child_relation ) );
|
||||
} elseif ( isset( $data['field'] ) ) {
|
||||
$split_val_name = explode( '.', $data['field'] );
|
||||
$field_val = null;
|
||||
|
||||
// Check for array values like: toggleListName['option1'].
|
||||
if ( 2 === count( $split_val_name ) && isset( $attributes[ $split_val_name[0] ] ) && isset( $attributes[ $split_val_name[0] ][ $split_val_name[1] ] ) ) {
|
||||
$field_val = $attributes[ $split_val_name[0] ][ $split_val_name[1] ];
|
||||
}
|
||||
|
||||
// Check for normal values.
|
||||
if ( null === $field_val && isset( $attributes[ $data['field'] ] ) ) {
|
||||
$field_val = $attributes[ $data['field'] ];
|
||||
}
|
||||
|
||||
// Check count.
|
||||
if ( isset( $data['count'] ) ) {
|
||||
$count = explode( $data['count'], $field_val );
|
||||
$field_val = count( $count ) - 1;
|
||||
}
|
||||
|
||||
if ( null !== $field_val ) {
|
||||
$result = self::compare( $result, $relation, self::compare( $field_val, isset( $data['operator'] ) ? $data['operator'] : '===', isset( $data['value'] ) ? $data['value'] : true ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* The file that defines the core plugin class
|
||||
*
|
||||
* A class definition that includes attributes and functions used across both the
|
||||
* public-facing side of the site and the admin area.
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Sight_Portfolio' ) ) {
|
||||
/**
|
||||
* Main Core Class
|
||||
*/
|
||||
class Sight_Portfolio {
|
||||
/**
|
||||
* The plugin version number.
|
||||
*
|
||||
* @var string $data The plugin version number.
|
||||
*/
|
||||
public $version;
|
||||
|
||||
/**
|
||||
* The plugin data array.
|
||||
*
|
||||
* @var array $data The plugin data array.
|
||||
*/
|
||||
public $data = array();
|
||||
|
||||
/**
|
||||
* The plugin settings array.
|
||||
*
|
||||
* @var array $settings The plugin data array.
|
||||
*/
|
||||
public $settings = array();
|
||||
|
||||
/**
|
||||
* INIT (global theme queue)
|
||||
*/
|
||||
public function init() {
|
||||
if ( ! function_exists( 'get_plugin_data' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
// Get plugin data.
|
||||
$plugin_data = get_plugin_data( SIGHT_PATH . 'sight.php' );
|
||||
|
||||
// Vars.
|
||||
$this->version = $plugin_data['Version'];
|
||||
|
||||
// Settings.
|
||||
$this->settings = array(
|
||||
'name' => esc_html__( 'Sight', 'sight' ),
|
||||
'version' => $plugin_data['Version'],
|
||||
);
|
||||
|
||||
// Include core.
|
||||
require_once SIGHT_PATH . 'core/core-api.php';
|
||||
require_once SIGHT_PATH . 'core/core-plugin-functions.php';
|
||||
require_once SIGHT_PATH . 'core/core-register-post-types.php';
|
||||
require_once SIGHT_PATH . 'core/core-register-category-fields.php';
|
||||
require_once SIGHT_PATH . 'core/core-video-settings.php';
|
||||
|
||||
// Include core classes.
|
||||
require_once SIGHT_PATH . 'core/block-renderer-controller.php';
|
||||
require_once SIGHT_PATH . 'core/block-utils-is-field-visible.php';
|
||||
|
||||
// Render files.
|
||||
require_once SIGHT_PATH . 'render/sight-entry.php';
|
||||
require_once SIGHT_PATH . 'render/sight-load-more.php';
|
||||
|
||||
// Elementor integration.
|
||||
if ( defined( 'ELEMENTOR_VERSION' ) ) {
|
||||
require_once SIGHT_PATH . 'elementor/integration.php';
|
||||
}
|
||||
|
||||
// Gutenberg integration.
|
||||
if ( function_exists( 'register_block_type' ) ) {
|
||||
require_once SIGHT_PATH . 'gutenberg/block-portfolio.php';
|
||||
}
|
||||
|
||||
// Render.
|
||||
require_once SIGHT_PATH . 'render/sight-render.php';
|
||||
|
||||
// Actions.
|
||||
add_action( 'sight_plugin_activation', array( $this, 'activation' ) );
|
||||
add_action( 'plugins_loaded', array( $this, 'check_version' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will safely define a constant
|
||||
*
|
||||
* @param string $name The name.
|
||||
* @param mixed $value The value.
|
||||
*/
|
||||
public function define( $name, $value = true ) {
|
||||
|
||||
if ( ! defined( $name ) ) {
|
||||
define( $name, $value );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if has setting.
|
||||
*
|
||||
* @param string $name The name.
|
||||
*/
|
||||
public function has_setting( $name ) {
|
||||
return isset( $this->settings[ $name ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a setting.
|
||||
*
|
||||
* @param string $name The name.
|
||||
*/
|
||||
public function get_setting( $name ) {
|
||||
return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a setting.
|
||||
*
|
||||
* @param string $name The name.
|
||||
* @param mixed $value The value.
|
||||
*/
|
||||
public function update_setting( $name, $value ) {
|
||||
$this->settings[ $name ] = $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns data.
|
||||
*
|
||||
* @param string $name The name.
|
||||
*/
|
||||
public function get_data( $name ) {
|
||||
return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets data.
|
||||
*
|
||||
* @param string $name The name.
|
||||
* @param mixed $value The value.
|
||||
*/
|
||||
public function set_data( $name, $value ) {
|
||||
$this->data[ $name ] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook activation
|
||||
*/
|
||||
public function activation() {
|
||||
if ( get_option( 'sight_db_version' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
update_option( 'sight_db_version', sight_raw_setting( 'version' ), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check current version
|
||||
*/
|
||||
public function check_version() {
|
||||
|
||||
// Version Data.
|
||||
$new = sight_raw_setting( 'version' );
|
||||
|
||||
// Get db version.
|
||||
$current = get_option( 'sight_db_version', $new );
|
||||
|
||||
// If versions don't match.
|
||||
if ( $current && $current !== $new ) {
|
||||
/**
|
||||
* If different versions call a special hook.
|
||||
*
|
||||
* @param string $current Current version.
|
||||
* @param string $new New version.
|
||||
*/
|
||||
do_action( 'sight_plugin_upgrade', $current, $new );
|
||||
|
||||
update_option( 'sight_db_version', $new, true );
|
||||
}
|
||||
|
||||
if ( $current ) {
|
||||
update_option( 'sight_db_version', $new, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The main function responsible for returning the one true sight Instance to functions everywhere.
|
||||
* Use this function like you would a global variable, except without needing to declare the global.
|
||||
*
|
||||
* Example: <?php $sight = sight_portfolio(); ?>
|
||||
*/
|
||||
function sight_portfolio() {
|
||||
|
||||
// Globals.
|
||||
global $sight_instance;
|
||||
|
||||
// Init.
|
||||
if ( ! isset( $sight_instance ) ) {
|
||||
$sight_instance = new Sight_Portfolio();
|
||||
$sight_instance->init();
|
||||
}
|
||||
|
||||
return $sight_instance;
|
||||
}
|
||||
|
||||
// Initialize.
|
||||
sight_portfolio();
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* The api functions for the plugin
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
/**
|
||||
* Alias of sight_portfolio()->has_setting()
|
||||
*
|
||||
* @param string $name The name.
|
||||
*/
|
||||
function sight_has_setting( $name = '' ) {
|
||||
return sight_portfolio()->has_setting( $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of sight_portfolio()->get_setting()
|
||||
*
|
||||
* @param string $name The name.
|
||||
*/
|
||||
function sight_raw_setting( $name = '' ) {
|
||||
return sight_portfolio()->get_setting( $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of sight_portfolio()->update_setting()
|
||||
*
|
||||
* @param string $name The name.
|
||||
* @param mixed $value The value.
|
||||
*/
|
||||
function sight_update_setting( $name, $value ) {
|
||||
|
||||
return sight_portfolio()->update_setting( $name, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of sight_portfolio()->get_setting()
|
||||
*
|
||||
* @param string $name The name.
|
||||
* @param mixed $value The value.
|
||||
*/
|
||||
function sight_get_setting( $name, $value = null ) {
|
||||
|
||||
// Check settings.
|
||||
if ( sight_has_setting( $name ) ) {
|
||||
$value = sight_raw_setting( $name );
|
||||
}
|
||||
|
||||
// Filter.
|
||||
$value = apply_filters( "canvas_settings_{$name}", $value );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will add a value into the settings array found in the acf object
|
||||
*
|
||||
* @param string $name The name.
|
||||
* @param mixed $value The value.
|
||||
*/
|
||||
function sight_append_setting( $name, $value ) {
|
||||
|
||||
// Vars.
|
||||
$setting = sight_raw_setting( $name );
|
||||
|
||||
// Bail ealry if not array.
|
||||
if ( ! is_array( $setting ) ) {
|
||||
$setting = array();
|
||||
}
|
||||
|
||||
// Append.
|
||||
$setting[] = $value;
|
||||
|
||||
// Update.
|
||||
return sight_update_setting( $name, $setting );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns data.
|
||||
*
|
||||
* @param string $name The name.
|
||||
*/
|
||||
function sight_get_data( $name ) {
|
||||
return sight_portfolio()->get_data( $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets data.
|
||||
*
|
||||
* @param string $name The name.
|
||||
* @param mixed $value The value.
|
||||
*/
|
||||
function sight_set_data( $name, $value ) {
|
||||
return sight_portfolio()->set_data( $name, $value );
|
||||
}
|
||||
@@ -0,0 +1,570 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Functions
|
||||
*
|
||||
* Utility functions.
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'sight_doing_request' ) ) {
|
||||
/**
|
||||
* Determines whether the current request is a WordPress REST or Ajax request.
|
||||
*/
|
||||
function sight_doing_request() {
|
||||
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
|
||||
return true;
|
||||
}
|
||||
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_is_context_editor' ) ) {
|
||||
/**
|
||||
* Determines whether the current request is from WordPress Editor.
|
||||
*/
|
||||
function sight_is_context_editor() {
|
||||
if ( isset( $_REQUEST['context'] ) && 'edit' === $_REQUEST['context'] ) { // Input var ok; sanitization ok.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_is_archive' ) ) {
|
||||
/**
|
||||
* Determines whether the current request is a WordPress REST or Ajax request.
|
||||
*/
|
||||
function sight_is_archive() {
|
||||
return apply_filters( 'sight_portfolio_is_archive', false );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_encode_data' ) ) {
|
||||
/**
|
||||
* Encode data
|
||||
*
|
||||
* @param mixed $content The content.
|
||||
* @param string $secret_key The key.
|
||||
* @return string
|
||||
*/
|
||||
function sight_encode_data( $content, $secret_key = 'sight' ) {
|
||||
|
||||
$content = wp_json_encode( $content );
|
||||
|
||||
return base64_encode( $content );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_decode_data' ) ) {
|
||||
/**
|
||||
* Decode data
|
||||
*
|
||||
* @param string $content The content.
|
||||
* @param string $secret_key The key.
|
||||
* @return string
|
||||
*/
|
||||
function sight_decode_data( $content, $secret_key = 'sight' ) {
|
||||
|
||||
$content = base64_decode( $content );
|
||||
|
||||
return json_decode( $content );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_get_available_image_sizes' ) ) {
|
||||
/**
|
||||
* Get the available image sizes
|
||||
*/
|
||||
function sight_get_available_image_sizes() {
|
||||
$wais = & $GLOBALS['_wp_additional_image_sizes'];
|
||||
|
||||
$sizes = array();
|
||||
$image_sizes = get_intermediate_image_sizes();
|
||||
|
||||
if ( is_array( $image_sizes ) && $image_sizes ) {
|
||||
foreach ( $image_sizes as $size ) {
|
||||
if ( in_array( $size, array( 'thumbnail', 'medium', 'medium_large', 'large' ), true ) ) {
|
||||
$sizes[ $size ] = array(
|
||||
'width' => get_option( "{$size}_size_w" ),
|
||||
'height' => get_option( "{$size}_size_h" ),
|
||||
'crop' => (bool) get_option( "{$size}_crop" ),
|
||||
);
|
||||
} elseif ( isset( $wais[ $size ] ) ) {
|
||||
$sizes[ $size ] = array(
|
||||
'width' => $wais[ $size ]['width'],
|
||||
'height' => $wais[ $size ]['height'],
|
||||
'crop' => $wais[ $size ]['crop'],
|
||||
);
|
||||
}
|
||||
|
||||
// Size registered, but has 0 width and height.
|
||||
if ( 0 === (int) $sizes[ $size ]['width'] && 0 === (int) $sizes[ $size ]['height'] ) {
|
||||
unset( $sizes[ $size ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sizes;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_get_image_size' ) ) {
|
||||
/**
|
||||
* Gets the data of a specific image size.
|
||||
*
|
||||
* @param string $size Name of the size.
|
||||
*/
|
||||
function sight_get_image_size( $size ) {
|
||||
if ( ! is_string( $size ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sizes = sight_get_available_image_sizes();
|
||||
|
||||
return isset( $sizes[ $size ] ) ? $sizes[ $size ] : false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_get_list_available_image_sizes' ) ) {
|
||||
/**
|
||||
* Get the list available image sizes
|
||||
*/
|
||||
function sight_get_list_available_image_sizes() {
|
||||
|
||||
$image_sizes = wp_cache_get( 'sight_available_image_sizes' );
|
||||
|
||||
if ( empty( $image_sizes ) ) {
|
||||
$image_sizes = array();
|
||||
|
||||
$intermediate_image_sizes = get_intermediate_image_sizes();
|
||||
|
||||
foreach ( $intermediate_image_sizes as $size ) {
|
||||
$image_sizes[ $size ] = $size;
|
||||
|
||||
$data = sight_get_image_size( $size );
|
||||
|
||||
if ( isset( $data['width'] ) || isset( $data['height'] ) ) {
|
||||
|
||||
$width = '~';
|
||||
$height = '~';
|
||||
|
||||
if ( isset( $data['width'] ) && $data['width'] ) {
|
||||
$width = $data['width'] . 'px';
|
||||
}
|
||||
if ( isset( $data['height'] ) && $data['height'] ) {
|
||||
$height = $data['height'] . 'px';
|
||||
}
|
||||
|
||||
$image_sizes[ $size ] .= sprintf( ' [%s, %s]', $width, $height );
|
||||
}
|
||||
}
|
||||
|
||||
wp_cache_set( 'sight_available_image_sizes', $image_sizes );
|
||||
}
|
||||
|
||||
return array_merge( array( 'full' => esc_html__( 'Full', 'sight' ) ), $image_sizes );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_str_truncate' ) ) {
|
||||
/**
|
||||
* Truncates string with specified length
|
||||
*
|
||||
* @param string $string Text string.
|
||||
* @param int $length Letters length.
|
||||
* @param string $etc End truncate.
|
||||
* @param bool $break_words Break words or not.
|
||||
* @return string
|
||||
*/
|
||||
function sight_str_truncate( $string, $length = 80, $etc = '…', $break_words = false ) {
|
||||
if ( 0 === $length ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( function_exists( 'mb_strlen' ) ) {
|
||||
|
||||
// MultiBite string functions.
|
||||
if ( mb_strlen( $string ) > $length ) {
|
||||
$length -= min( $length, mb_strlen( $etc ) );
|
||||
if ( ! $break_words ) {
|
||||
$string = preg_replace( '/\s+?(\S+)?$/', '', mb_substr( $string, 0, $length + 1 ) );
|
||||
}
|
||||
|
||||
return mb_substr( $string, 0, $length ) . $etc;
|
||||
}
|
||||
} else {
|
||||
|
||||
// Default string functions.
|
||||
if ( strlen( $string ) > $length ) {
|
||||
$length -= min( $length, strlen( $etc ) );
|
||||
if ( ! $break_words ) {
|
||||
$string = preg_replace( '/\s+?(\S+)?$/', '', substr( $string, 0, $length + 1 ) );
|
||||
}
|
||||
|
||||
return substr( $string, 0, $length ) . $etc;
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_get_the_excerpt' ) ) {
|
||||
/**
|
||||
* Filters the number of words in an excerpt.
|
||||
*/
|
||||
function sight_get_the_excerpt_length() {
|
||||
return 5000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get excerpt of post.
|
||||
*
|
||||
* @param int $length Letters length.
|
||||
* @param string $etc End truncate.
|
||||
* @param bool $break_words Break words or not.
|
||||
*/
|
||||
function sight_get_the_excerpt( $length = 80, $etc = '…', $break_words = false ) {
|
||||
add_filter( 'excerpt_length', 'sight_get_the_excerpt_length' );
|
||||
|
||||
$excerpt = get_the_excerpt();
|
||||
|
||||
$func_remove = sprintf( 'remove_%s', 'filter' );
|
||||
|
||||
$func_remove( 'excerpt_length', 'sight_get_the_excerpt_length' );
|
||||
|
||||
return sight_str_truncate( $excerpt, $length, $etc, $break_words );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_powerkit_module_enabled' ) ) {
|
||||
/**
|
||||
* Helper function to check the status of powerkit modules
|
||||
*
|
||||
* @param array $name Name of module.
|
||||
*/
|
||||
function sight_powerkit_module_enabled( $name ) {
|
||||
if ( function_exists( 'powerkit_module_enabled' ) && powerkit_module_enabled( $name ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_post_views_enabled' ) ) {
|
||||
/**
|
||||
* Check post views module.
|
||||
*
|
||||
* @return string Type.
|
||||
*/
|
||||
function sight_post_views_enabled() {
|
||||
|
||||
// Post Views Counter.
|
||||
if ( class_exists( 'Post_Views_Counter' ) ) {
|
||||
return 'post_views';
|
||||
}
|
||||
|
||||
// Powerkit Post Views.
|
||||
if ( sight_powerkit_module_enabled( 'post_views' ) ) {
|
||||
return 'pk_post_views';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_get_post_types_stack' ) ) {
|
||||
/**
|
||||
* Get portfolio post types.
|
||||
*/
|
||||
function sight_get_post_types_stack() {
|
||||
|
||||
$stack = wp_cache_get( 'sight_get_post_types_stack' );
|
||||
|
||||
if ( ! $stack ) {
|
||||
|
||||
$stack = array();
|
||||
|
||||
$post_types = get_post_types( array( 'publicly_queryable' => 1 ), 'objects' );
|
||||
|
||||
foreach ( $post_types as $post_type ) {
|
||||
$stack[ $post_type->name ] = $post_type->label;
|
||||
}
|
||||
|
||||
wp_cache_set( 'sight_get_post_types_stack', $stack );
|
||||
}
|
||||
|
||||
return $stack ? $stack : array();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_get_categories_stack' ) ) {
|
||||
/**
|
||||
* Get portfolio categories.
|
||||
*/
|
||||
function sight_get_categories_stack() {
|
||||
|
||||
$stack = wp_cache_get( 'sight_get_categories_stack' );
|
||||
|
||||
if ( ! $stack ) {
|
||||
|
||||
$stack = array();
|
||||
|
||||
$categories = get_terms(
|
||||
array(
|
||||
'taxonomy' => 'sight-categories',
|
||||
'hide_empty' => false,
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $categories as $category ) {
|
||||
$stack[ $category->term_id ] = $category->name;
|
||||
}
|
||||
|
||||
wp_cache_set( 'sight_get_categories_stack', $stack );
|
||||
}
|
||||
|
||||
return $stack ? $stack : array();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_portfolio_area_classes' ) ) {
|
||||
/**
|
||||
* Get portfolio area classes.
|
||||
*
|
||||
* @param array $attributes The attributes.
|
||||
* @param array $options The options.
|
||||
*/
|
||||
function sight_portfolio_area_classes( $attributes, $options ) {
|
||||
$classes = array( 'sight-portfolio-area' );
|
||||
|
||||
// Enable Lightbox.
|
||||
if ( isset( $attributes['attachment_lightbox'] ) && $attributes['attachment_lightbox'] ) {
|
||||
$classes[] = 'sight-portfolio-area-lightbox';
|
||||
}
|
||||
|
||||
// Apply filters.
|
||||
$classes = apply_filters( 'sight_portfolio_area_classes', $classes, $attributes, $options );
|
||||
|
||||
// Build class.
|
||||
$class = implode( ' ', $classes );
|
||||
|
||||
// Return.
|
||||
return $class;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_portfolio_area_main_attrs' ) ) {
|
||||
/**
|
||||
* Output portfolio area main attrs.
|
||||
*
|
||||
* @param array $attributes The attributes.
|
||||
* @param array $options The options.
|
||||
*/
|
||||
function sight_portfolio_area_main_attrs( $attributes, $options ) {
|
||||
// Apply filters.
|
||||
$attrs = apply_filters( 'sight_portfolio_area_main_attrs', '', $attributes, $options );
|
||||
|
||||
// Return.
|
||||
return call_user_func( 'printf', '%s', $attrs );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_get_youtube_video_id' ) ) {
|
||||
/**
|
||||
* Get Youtube video ID from URL
|
||||
*
|
||||
* @param string $url YouTube URL.
|
||||
*/
|
||||
function sight_get_youtube_video_id( $url ) {
|
||||
preg_match( '/(http(s|):|)\/\/(www\.|)yout(.*?)\/(embed\/|watch.*?v=|)([a-z_A-Z0-9\-]{11})/i', $url, $results );
|
||||
|
||||
if ( isset( $results[6] ) && $results[6] ) {
|
||||
return $results[6];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_get_local_video_url' ) ) {
|
||||
/**
|
||||
* Get local video URL
|
||||
*
|
||||
* @param string $url Local URL.
|
||||
*/
|
||||
function sight_get_local_video_url( $url ) {
|
||||
if ( attachment_url_to_postid( $url ) ) {
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_get_video_background' ) ) {
|
||||
/**
|
||||
* Get element video background
|
||||
*
|
||||
* @param string $type The type.
|
||||
* @param string $location The current location.
|
||||
* @param int $post_id The id of post.
|
||||
* @param string $template Template.
|
||||
* @param bool $controls Display tools.
|
||||
*/
|
||||
function sight_get_video_background( $type = 'always', $location = null, $post_id = null, $template = 'default', $controls = true ) {
|
||||
|
||||
if ( sight_is_context_editor() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_customize_preview() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $post_id ) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
|
||||
// Params.
|
||||
$url = get_post_meta( $post_id, 'sight_post_video_url', true );
|
||||
$start = get_post_meta( $post_id, 'sight_post_video_bg_start_time', true );
|
||||
$end = get_post_meta( $post_id, 'sight_post_video_bg_end_time', true );
|
||||
|
||||
// Location.
|
||||
if ( $location ) {
|
||||
$support = (array) get_post_meta( $post_id, 'sight_post_video_location', true );
|
||||
|
||||
if ( ! in_array( $location, $support, true ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Video info.
|
||||
$local_url = sight_get_local_video_url( $url );
|
||||
$youtube_id = sight_get_youtube_video_id( $url );
|
||||
|
||||
// Output.
|
||||
if ( $youtube_id || $local_url ) {
|
||||
// Get video mode.
|
||||
$mode = $youtube_id ? 'youtube' : 'local';
|
||||
|
||||
// Controls.
|
||||
if ( true === $controls ) {
|
||||
$controls = array( 'youtube', 'volume', 'state' );
|
||||
|
||||
if ( 'hover' === $type ) {
|
||||
$controls = array_diff( $controls, array( 'state' ) );
|
||||
}
|
||||
if ( 'local' === $mode ) {
|
||||
$controls = array_diff( $controls, array( 'youtube' ) );
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div class="sight-portfolio-video-container" data-video-type="<?php echo esc_attr( $type ); ?>" data-video-mode="<?php echo esc_attr( $mode ); ?>" data-youtube-id="<?php echo esc_attr( $youtube_id ); ?>" data-video-start="<?php echo esc_attr( (int) $start ); ?>" data-video-end="<?php echo esc_attr( (int) $end ); ?>">
|
||||
<?php if ( $youtube_id ) { ?>
|
||||
<div class="sight-portfolio-video-inner"></div>
|
||||
<?php } else { ?>
|
||||
<video class="sight-portfolio-video-inner" loop muted>
|
||||
<source src="<?php echo esc_attr( $local_url ); ?>" type="video/webm" />
|
||||
</video>
|
||||
<?php } ?>
|
||||
|
||||
<div class="sight-portfolio-video-loader"></div>
|
||||
</div>
|
||||
|
||||
<?php if ( is_array( $controls ) && $controls ) { ?>
|
||||
<div class="sight-portfolio-video-controls sight-portfolio-video-controls-<?php echo esc_attr( $template ); ?>">
|
||||
<?php if ( in_array( 'youtube', $controls, true ) ) { ?>
|
||||
<a class="sight-portfolio-player-control sight-portfolio-player-link sight-portfolio-player-stop" target="_blank" href="<?php echo esc_url( $url ); ?>">
|
||||
<span class="sight-portfolio-tooltip"><span><?php esc_html_e( 'View on YouTube', 'sight' ); ?></span></span>
|
||||
</a>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ( in_array( 'volume', $controls, true ) ) { ?>
|
||||
<span class="sight-portfolio-player-control sight-portfolio-player-volume sight-portfolio-player-mute"></span>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ( in_array( 'state', $controls, true ) ) { ?>
|
||||
<span class="sight-portfolio-player-control sight-portfolio-player-state sight-portfolio-player-pause"></span>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sight_portfolio_render_style' ) ) {
|
||||
/**
|
||||
* Callback used to render style for portfolio.
|
||||
*
|
||||
* @param array $attributes The attributes.
|
||||
* @param array $options The options.
|
||||
* @param string $id The id.
|
||||
*/
|
||||
function sight_portfolio_render_style( $attributes, $options, $id ) {
|
||||
ob_start();
|
||||
|
||||
// Heading Font Size.
|
||||
if ( isset( $attributes['typography_heading'] ) && $attributes['typography_heading'] ) {
|
||||
?>
|
||||
.sight-block-portfolio-id-{id} .sight-portfolio-entry__heading {
|
||||
font-size: <?php echo esc_attr( $attributes['typography_heading'] ); ?> !important;
|
||||
}
|
||||
<?php
|
||||
}
|
||||
|
||||
// Caption Font Size.
|
||||
if ( isset( $attributes['typography_caption'] ) && $attributes['typography_caption'] ) {
|
||||
?>
|
||||
.sight-block-portfolio-id-{id} .sight-portfolio-entry__caption {
|
||||
font-size: <?php echo esc_attr( $attributes['typography_caption'] ); ?> !important;
|
||||
}
|
||||
<?php
|
||||
}
|
||||
|
||||
// Heading Color.
|
||||
if ( isset( $attributes['color_heading'] ) && $attributes['color_heading'] ) {
|
||||
?>
|
||||
.sight-block-portfolio-id-{id} .sight-portfolio-entry__heading,
|
||||
.sight-block-portfolio-id-{id} .sight-portfolio-entry__heading a {
|
||||
color: <?php echo esc_attr( $attributes['color_heading'] ); ?> !important;
|
||||
}
|
||||
<?php
|
||||
}
|
||||
|
||||
// Heading Hover Color.
|
||||
if ( isset( $attributes['color_heading_hover'] ) && $attributes['color_heading_hover'] ) {
|
||||
?>
|
||||
.sight-block-portfolio-id-{id} .sight-portfolio-entry__heading a:hover {
|
||||
color: <?php echo esc_attr( $attributes['color_heading_hover'] ); ?> !important;
|
||||
}
|
||||
<?php
|
||||
}
|
||||
|
||||
// Caption Color.
|
||||
if ( isset( $attributes['color_caption'] ) && $attributes['color_caption'] ) {
|
||||
?>
|
||||
.sight-block-portfolio-id-{id} .sight-portfolio-entry__caption {
|
||||
color: <?php echo esc_attr( $attributes['color_caption'] ); ?> !important;
|
||||
}
|
||||
<?php
|
||||
}
|
||||
|
||||
$style = ob_get_clean();
|
||||
|
||||
/*
|
||||
* -------------------------------------
|
||||
*/
|
||||
|
||||
// Apply filters.
|
||||
$style = apply_filters( 'sight_portfolio_render_css', $style, $attributes, $options, $id );
|
||||
|
||||
// Replace ids.
|
||||
$style = str_replace( '{id}', $id, $style );
|
||||
|
||||
// Wrap tags.
|
||||
if ( $style ) {
|
||||
$style = sprintf( '<style>%s</style>', $style );
|
||||
}
|
||||
|
||||
// Print.
|
||||
call_user_func( 'printf', '%s', $style );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* Register Fields for Category.
|
||||
*
|
||||
* @link https://codesupply.co
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Register Fields
|
||||
*/
|
||||
class Sight_Category_Fields {
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'sight-categories_add_form_fields', array( $this, 'category_add_form_fields' ), 10 );
|
||||
add_action( 'sight-categories_edit_form_fields', array( $this, 'category_edit_form_fields' ), 10, 2 );
|
||||
add_action( 'created_sight-categories', array( $this, 'save_category' ), 10, 2 );
|
||||
add_action( 'edited_sight-categories', array( $this, 'save_category' ), 10, 2 );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 10 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add fields to Category
|
||||
*
|
||||
* @param string $taxonomy The taxonomy slug.
|
||||
*/
|
||||
public function category_add_form_fields( $taxonomy ) {
|
||||
wp_nonce_field( 'category_options', 'sight_category' );
|
||||
?>
|
||||
<div class="form-field">
|
||||
<label><?php esc_html_e( 'Featured Image', 'sight' ); ?></label>
|
||||
|
||||
<div class="sight-featured-image" data-frame-title="<?php esc_html_e( 'Select or upload image', 'sight' ); ?>" data-frame-btn-text="<?php esc_html_e( 'Set image', 'sight' ); ?>">
|
||||
<p class="uploaded-img-box">
|
||||
<span class="sight-uploaded-image"></span>
|
||||
<input id="sight_featured_image" class="sight-uploaded-img-id" name="sight_featured_image" type="hidden"/>
|
||||
</p>
|
||||
<p class="hide-if-no-js">
|
||||
<a class="sight-upload-img-link button button-primary" href="#"><?php esc_html_e( 'Upload image', 'sight' ); ?></a>
|
||||
<a class="sight-delete-img-link button button-secondary hidden" href="#"><?php esc_html_e( 'Remove image', 'sight' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit fields from Category
|
||||
*
|
||||
* @param object $tag Current taxonomy term object.
|
||||
* @param string $taxonomy Current taxonomy slug.
|
||||
*/
|
||||
public function category_edit_form_fields( $tag, $taxonomy ) {
|
||||
wp_nonce_field( 'category_options', 'sight_category' );
|
||||
|
||||
$sight_featured_image = get_term_meta( $tag->term_id, 'sight_featured_image', true );
|
||||
?>
|
||||
<tr class="form-field">
|
||||
<th scope="row" valign="top">
|
||||
<label for="sight_featured_image"><?php esc_html_e( 'Featured Image', 'sight' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<div class="sight-featured-image" data-frame-title="<?php esc_html_e( 'Select or upload image', 'sight' ); ?>" data-frame-btn-text="<?php esc_html_e( 'Set image', 'sight' ); ?>">
|
||||
<p class="uploaded-img-box">
|
||||
<span class="sight-uploaded-image">
|
||||
<?php if ( $sight_featured_image ) : ?>
|
||||
<?php
|
||||
echo wp_get_attachment_image( $sight_featured_image, 'large', false, array(
|
||||
'style' => 'max-width:100%; height: auto;',
|
||||
) );
|
||||
?>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
|
||||
<input id="sight_featured_image" class="sight-uploaded-img-id" name="sight_featured_image" type="hidden" value="<?php echo esc_attr( $sight_featured_image ); ?>" />
|
||||
</p>
|
||||
<p class="hide-if-no-js">
|
||||
<a class="sight-upload-img-link button button-primary <?php echo esc_attr( $sight_featured_image ? 'hidden' : '' ); ?>" href="#"><?php esc_html_e( 'Upload image', 'sight' ); ?></a>
|
||||
<a class="sight-delete-img-link button button-secondary <?php echo esc_attr( ! $sight_featured_image ? 'hidden' : '' ); ?>" href="#"><?php esc_html_e( 'Remove image', 'sight' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p class="description"><?php esc_html_e( 'This image is used in the category blocks.', 'sight' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save category fields
|
||||
*
|
||||
* @param int $term_id ID of the term about to be edited.
|
||||
* @param string $taxonomy Taxonomy slug of the related term.
|
||||
*/
|
||||
public function save_category( $term_id, $taxonomy ) {
|
||||
|
||||
// Bail if we're doing an auto save.
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if our nonce isn't there, or we can't verify it, bail.
|
||||
if ( ! isset( $_POST['sight_category'] ) || ! wp_verify_nonce( $_POST['sight_category'], 'category_options' ) ) { // Input var ok; sanitization ok.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_POST['sight_featured_image'] ) ) { // Input var ok; sanitization ok.
|
||||
$sight_featured_image = sanitize_text_field( $_POST['sight_featured_image'] ); // Input var ok; sanitization ok.
|
||||
|
||||
update_term_meta( $term_id, 'sight_featured_image', $sight_featured_image );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the stylesheets and JavaScript for the admin area.
|
||||
*
|
||||
* @param string $page Current page.
|
||||
*/
|
||||
public function admin_enqueue_scripts( $page ) {
|
||||
if ( 'edit-tags.php' === $page || 'term.php' === $page ) {
|
||||
wp_enqueue_script( 'jquery-core' );
|
||||
|
||||
wp_enqueue_media();
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<script>
|
||||
( function() {
|
||||
|
||||
var portfolioFeaturedContainer = '.sight-featured-image';
|
||||
|
||||
var portfolioFeaturedFrame;
|
||||
|
||||
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
|
||||
/* Add Image Link */
|
||||
jQuery( portfolioFeaturedContainer ).find( '.sight-upload-img-link' ).on( 'click', function( event ){
|
||||
event.preventDefault();
|
||||
|
||||
var parentContainer = $( this ).parents( portfolioFeaturedContainer );
|
||||
|
||||
// Options.
|
||||
var options = {
|
||||
title: parentContainer.data( 'frame-title' ) ? parentContainer.data( 'frame-title' ) : 'Select or Upload Media',
|
||||
button: {
|
||||
text: parentContainer.data( 'frame-btn-text' ) ? parentContainer.data( 'frame-btn-text' ) : 'Use this media',
|
||||
},
|
||||
library : { type : 'image' },
|
||||
multiple: false // Set to true to allow multiple files to be selected.
|
||||
};
|
||||
|
||||
// Create a new media frame
|
||||
portfolioFeaturedFrame = wp.media( options );
|
||||
|
||||
// When an image is selected in the media frame...
|
||||
portfolioFeaturedFrame.on( 'select', function() {
|
||||
|
||||
// Get media attachment details from the frame state.
|
||||
var attachment = portfolioFeaturedFrame.state().get('selection').first().toJSON();
|
||||
|
||||
// Send the attachment URL to our custom image input field.
|
||||
parentContainer.find( '.sight-uploaded-image' ).html( '<img src="' + attachment.url + '" style="max-width:100%;"/>' );
|
||||
parentContainer.find( '.sight-uploaded-img-id' ).val( attachment.id ).change();
|
||||
parentContainer.find( '.sight-upload-img-link' ).addClass( 'hidden' );
|
||||
parentContainer.find( '.sight-delete-img-link' ).removeClass( 'hidden' );
|
||||
|
||||
portfolioFeaturedFrame.close();
|
||||
});
|
||||
|
||||
// Finally, open the modal on click.
|
||||
portfolioFeaturedFrame.open();
|
||||
});
|
||||
|
||||
|
||||
/* Delete Image Link */
|
||||
$( portfolioFeaturedContainer ).find( '.sight-delete-img-link' ).on( 'click', function( event ){
|
||||
event.preventDefault();
|
||||
|
||||
$( this ).parents( portfolioFeaturedContainer ).find( '.sight-uploaded-image' ).html( '' );
|
||||
$( this ).parents( portfolioFeaturedContainer ).find( '.sight-upload-img-link' ).removeClass( 'hidden' );
|
||||
$( this ).parents( portfolioFeaturedContainer ).find( '.sight-delete-img-link' ).addClass( 'hidden' );
|
||||
$( this ).parents( portfolioFeaturedContainer ).find( '.sight-uploaded-img-id' ).val( '' ).change();
|
||||
});
|
||||
});
|
||||
|
||||
jQuery( document ).ajaxSuccess(function(e, request, settings){
|
||||
let action = settings.data.indexOf( 'action=add-tag' );
|
||||
let screen = settings.data.indexOf( 'screen=edit-category' );
|
||||
let taxonomy = settings.data.indexOf( 'taxonomy=category' );
|
||||
|
||||
if( action > -1 && screen > -1 && taxonomy > -1 ){
|
||||
$( portfolioFeaturedContainer ).find( '.sight-delete-img-link' ).click();
|
||||
}
|
||||
});
|
||||
|
||||
} )();
|
||||
</script>
|
||||
<?php
|
||||
wp_add_inline_script( 'jquery-core', str_replace( array( '<script>', '</script>' ), '', ob_get_clean() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new Sight_Category_Fields();
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Register post types.
|
||||
*
|
||||
* @link https://codesupply.co
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register custom post types.
|
||||
*/
|
||||
function sight_register_custom_post_types() {
|
||||
|
||||
register_post_type(
|
||||
'sight-projects',
|
||||
array(
|
||||
'labels' => array(
|
||||
'name' => esc_html__( 'Projects', 'sight' ),
|
||||
'singular_name' => esc_html__( 'Project', 'sight' ),
|
||||
'menu_name' => esc_html__( 'Projects', 'sight' ),
|
||||
'parent_item_colon' => esc_html__( 'Parent Project', 'sight' ),
|
||||
'all_items' => esc_html__( 'All Projects', 'sight' ),
|
||||
'view_item' => esc_html__( 'View Project', 'sight' ),
|
||||
'add_new_item' => esc_html__( 'Add New Project', 'sight' ),
|
||||
'add_new' => esc_html__( 'Add New', 'sight' ),
|
||||
'edit_item' => esc_html__( 'Edit Project', 'sight' ),
|
||||
'update_item' => esc_html__( 'Update Project', 'sight' ),
|
||||
'search_items' => esc_html__( 'Search Project', 'sight' ),
|
||||
'not_found' => esc_html__( 'Not Found', 'sight' ),
|
||||
'not_found_in_trash' => esc_html__( 'Not found in Trash', 'sight' ),
|
||||
),
|
||||
'public' => true,
|
||||
'publicly_queryable' => true,
|
||||
'show_ui' => true,
|
||||
'show_in_menu' => true,
|
||||
'show_in_rest' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'projects' ),
|
||||
'capability_type' => 'post',
|
||||
'has_archive' => true,
|
||||
'hierarchical' => false,
|
||||
'menu_position' => null,
|
||||
'supports' => array( 'title', 'excerpt', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'init', 'sight_register_custom_post_types' );
|
||||
|
||||
/**
|
||||
* Register custom taxonomies.
|
||||
*/
|
||||
function sight_register_custom_taxonomies() {
|
||||
|
||||
register_taxonomy(
|
||||
'sight-categories',
|
||||
array( 'sight-projects' ),
|
||||
array(
|
||||
'label' => '',
|
||||
'labels' => array(
|
||||
'name' => esc_html__( 'Categories', 'sight' ),
|
||||
'singular_name' => esc_html__( 'Categories', 'sight' ),
|
||||
'search_items' => esc_html__( 'Search Categories', 'sight' ),
|
||||
'all_items' => esc_html__( 'All Categories', 'sight' ),
|
||||
'view_item ' => esc_html__( 'View Category', 'sight' ),
|
||||
'parent_item' => esc_html__( 'Parent Category', 'sight' ),
|
||||
'parent_item_colon' => esc_html__( 'Parent Category:', 'sight' ),
|
||||
'edit_item' => esc_html__( 'Edit Category', 'sight' ),
|
||||
'update_item' => esc_html__( 'Update Category', 'sight' ),
|
||||
'add_new_item' => esc_html__( 'Add New Category', 'sight' ),
|
||||
'new_item_name' => esc_html__( 'New Types Name', 'sight' ),
|
||||
'menu_name' => esc_html__( 'Categories', 'sight' ),
|
||||
),
|
||||
'description' => '',
|
||||
'public' => sight_is_archive(),
|
||||
'show_in_nav_menus' => true,
|
||||
'show_ui' => true,
|
||||
'show_in_menu' => true,
|
||||
'show_tagcloud' => true,
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array(
|
||||
'slug' => 'categories',
|
||||
),
|
||||
'capabilities' => array(),
|
||||
'meta_box_cb' => true,
|
||||
'show_admin_column' => true,
|
||||
'show_in_rest' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'init', 'sight_register_custom_taxonomies' );
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* The Video Settings.
|
||||
*
|
||||
* @link https://codesupply.co
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Sight
|
||||
*/
|
||||
|
||||
/**
|
||||
* The initialize block.
|
||||
*/
|
||||
class Sight_Video_Settings {
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', array( $this, 'register_video_settings' ) );
|
||||
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ), 100 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue assets for gutenberg panels
|
||||
*/
|
||||
public function enqueue_block_editor_assets() {
|
||||
$post_id = get_the_ID();
|
||||
|
||||
if ( ! $post_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Data.
|
||||
$panels_data = array(
|
||||
'postType' => get_post_type( $post_id ),
|
||||
);
|
||||
|
||||
// Enqueue scripts.
|
||||
wp_enqueue_script(
|
||||
'sight-video-settings',
|
||||
SIGHT_URL . 'gutenberg/jsx/video-panel.js',
|
||||
array(
|
||||
'wp-i18n',
|
||||
'wp-blocks',
|
||||
'wp-edit-post',
|
||||
'wp-element',
|
||||
'wp-editor',
|
||||
'wp-components',
|
||||
'wp-data',
|
||||
'wp-plugins',
|
||||
'wp-edit-post',
|
||||
'wp-hooks',
|
||||
),
|
||||
filemtime( SIGHT_PATH . 'gutenberg/jsx/video-panel.js' ),
|
||||
true
|
||||
);
|
||||
|
||||
// Localize scripts.
|
||||
wp_localize_script( 'sight-video-settings', 'sightVideoSettings', $panels_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register video settings
|
||||
*/
|
||||
public function register_video_settings() {
|
||||
|
||||
register_post_meta(
|
||||
'sight-projects',
|
||||
'sight_post_video_url',
|
||||
array(
|
||||
'show_in_rest' => true,
|
||||
'type' => 'string',
|
||||
'single' => true,
|
||||
'auth_callback' => function () {
|
||||
return current_user_can( 'edit_posts' );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_post_meta(
|
||||
'sight-projects',
|
||||
'sight_post_video_bg_start_time',
|
||||
array(
|
||||
'show_in_rest' => true,
|
||||
'type' => 'number',
|
||||
'single' => true,
|
||||
'auth_callback' => function () {
|
||||
return current_user_can( 'edit_posts' );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_post_meta(
|
||||
'sight-projects',
|
||||
'sight_post_video_bg_end_time',
|
||||
array(
|
||||
'show_in_rest' => true,
|
||||
'type' => 'number',
|
||||
'single' => true,
|
||||
'auth_callback' => function () {
|
||||
return current_user_can( 'edit_posts' );
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
new Sight_Video_Settings();
|
||||
Reference in New Issue
Block a user