Initial commit: Atomaste website
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
v1.0.17 - 20-March-2025
|
||||
- Fix: Addressed a critical bug causing an error in the customizer.
|
||||
|
||||
v1.0.16 - 18-March-2025
|
||||
- New: Added `zipwp_images_excluded_post_types` filter to restrict asset loading in unnecessary backend areas, improving performance.
|
||||
|
||||
v1.0.15 - 18-February-2025
|
||||
- New: Integrated PHP Insights to GitHub Actions for improved readability and error reduction.
|
||||
- Improvement: Added edit_pages capability check for API access.
|
||||
|
||||
v1.0.14 - 28-November-2024
|
||||
- Fix: Removed garbage CSS conflicting with other plugins.
|
||||
|
||||
v1.0.13 - 11-November-2024
|
||||
- Fix: Resolved an issue where the media library button text was incorrectly displayed in certain cases.
|
||||
|
||||
v1.0.12 - 24-October-2024
|
||||
- Improvement: Removed the "Free Images" option from the WordPress media library where videos are expected.
|
||||
|
||||
v1.0.11 - 01-October-2024
|
||||
- Improvement: Fixed broken UI components for Elementor and Beaver Builder.
|
||||
|
||||
v1.0.10 - 23-September-2024
|
||||
- Improvement: UI/UX improvements.
|
||||
|
||||
v1.0.9 - 11-September-2024
|
||||
- Fix: Resolved issue where image search results reset to default after applying filters.
|
||||
|
||||
v1.0.8 - 15-August-2024
|
||||
- Improvement: Enhanced UI for better user experience.
|
||||
|
||||
v1.0.7 - 12-June-2024
|
||||
- Fix: "Select" of media library was not showing in the customizer preview.
|
||||
|
||||
v1.0.6 - 06-June-2024
|
||||
- Improvement: Updated preview screen for better UX.
|
||||
|
||||
v1.0.5 - 05-June-2024
|
||||
- Improvement: Added compatibility for WP Gallery Block.
|
||||
|
||||
v1.0.4 - 29-May-2024
|
||||
- New: Added option to clear the applied filters.
|
||||
|
||||
v1.0.3 - 27-May-2024
|
||||
- Fix: Fixed trailing slash issue for image API.
|
||||
|
||||
v1.0.2 - 24-May-2024
|
||||
- New: Added filter for tab title.
|
||||
|
||||
v1.0.1 - 23-May-2024
|
||||
- New: Updated Image search API namespace.
|
||||
|
||||
v1.0.0 - 22-May-2024
|
||||
- Initial release
|
||||
@@ -0,0 +1,482 @@
|
||||
<?php
|
||||
/**
|
||||
* Zipwp Images API
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Zipwp Images API
|
||||
*/
|
||||
|
||||
namespace ZipWP_Images\Classes;
|
||||
|
||||
/**
|
||||
* Ai_Builder
|
||||
*/
|
||||
class Zipwp_Images_Api {
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @access private
|
||||
* @var object Class Instance.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'rest_api_init', array( $this, 'register_route' ) );
|
||||
add_action( 'wp_ajax_zipwp_images_insert_image', array( $this, 'zipwp_insert_image' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get api domain
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_api_domain() {
|
||||
return trailingslashit( defined( 'ZIPWP_API' ) ? ZIPWP_API : 'https://api.zipwp.com/api/' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get api namespace
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_api_namespace() {
|
||||
return 'zipwp-images/v1';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API headers
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function get_api_headers() {
|
||||
return array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given request has permission to read notes.
|
||||
*
|
||||
* @param object $request WP_REST_Request Full details about the request.
|
||||
* @return object|bool
|
||||
*/
|
||||
public function get_item_permissions_check( $request ) {
|
||||
|
||||
if ( ! current_user_can( 'edit_posts' ) ) {
|
||||
return new \WP_Error(
|
||||
'gt_rest_cannot_access',
|
||||
__( 'Sorry, you are not allowed to do that.', 'astra-sites' ),
|
||||
array( 'status' => rest_authorization_required_code() )
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the required files in the importer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function register_route(): void {
|
||||
|
||||
register_rest_route(
|
||||
$this->get_api_namespace(),
|
||||
'/images/',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'get_images' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'keywords' => array(
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'per_page' => array(
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'page' => array(
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'orientation' => array(
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'required' => false,
|
||||
),
|
||||
'engine' => array(
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
'filter' => array(
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
'color' => array(
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Images.
|
||||
*
|
||||
* @param \WP_REST_Request $request Request object.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_images( $request ) {
|
||||
|
||||
$nonce = $request->get_header( 'X-WP-Nonce' );
|
||||
|
||||
// Verify the nonce.
|
||||
if ( ! wp_verify_nonce( sanitize_text_field( (string) $nonce ), 'wp_rest' ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'data' => __( 'Nonce verification failed.', 'astra-sites' ),
|
||||
'status' => false,
|
||||
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$api_endpoint = $this->get_api_domain() . 'images/';
|
||||
|
||||
$post_data = array(
|
||||
'keywords' => isset( $request['keywords'] ) && ! empty( $request['keywords'] ) ? [ $request['keywords'] ] : [ 'people' ],
|
||||
'per_page' => isset( $request['per_page'] ) ? $request['per_page'] : 20,
|
||||
'page' => isset( $request['page'] ) ? sanitize_text_field( $request['page'] ) : '1',
|
||||
// Expected orientation values are all, landscape, portrait.
|
||||
'orientation' => isset( $request['orientation'] ) ? sanitize_text_field( $request['orientation'] ) : '',
|
||||
'color' => isset( $request['color'] ) ? sanitize_text_field( $request['color'] ) : '',
|
||||
// Expected filter values are newest, popular.
|
||||
'filter' => isset( $request['filter'] ) ? sanitize_text_field( $request['filter'] ) : 'popular',
|
||||
'engine' => isset( $request['engine'] ) ? sanitize_text_field( $request['engine'] ) : 'pexels',
|
||||
'details' => true,
|
||||
);
|
||||
|
||||
switch ( $post_data['engine'] ) {
|
||||
|
||||
case 'pexels':
|
||||
// sort=popular.
|
||||
$post_data['filter'] = 'popular' === $post_data['filter'] ? 'popular' : 'desc';
|
||||
break;
|
||||
|
||||
case 'pixabay':
|
||||
// order=popular.
|
||||
$post_data['filter'] = 'popular' === $post_data['filter'] ? 'popular' : 'latest';
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$request_args = array(
|
||||
'body' => wp_json_encode( $post_data ),
|
||||
'headers' => $this->get_api_headers(),
|
||||
'timeout' => 100,
|
||||
);
|
||||
$response = wp_safe_remote_post( $api_endpoint, $request_args ); // @phpstan-ignore-line
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
// There was an error in the request.
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'data' => 'Failed ' . $response->get_error_message(),
|
||||
'status' => false,
|
||||
|
||||
)
|
||||
);
|
||||
}
|
||||
$response_code = wp_remote_retrieve_response_code( $response );
|
||||
$response_body = wp_remote_retrieve_body( $response );
|
||||
if ( 200 === $response_code ) {
|
||||
$response_data = json_decode( $response_body, true );
|
||||
|
||||
// Get image sizes and add to the each image.
|
||||
$images = is_array( $response_data ) && isset( $response_data['images'] ) ? $response_data['images'] : [];
|
||||
foreach ( $images as $key => $image ) {
|
||||
$images[ $key ]['sizes'] = $this->get_image_size( $image );
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'data' => $images,
|
||||
'status' => true,
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'data' => 'Failed',
|
||||
'status' => false,
|
||||
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download and save the image in the media library.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function zipwp_insert_image(): void {
|
||||
// Verify Nonce.
|
||||
check_ajax_referer( 'zipwp-images', '_ajax_nonce' );
|
||||
|
||||
if ( ! current_user_can( 'upload_files' ) ) {
|
||||
wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
|
||||
}
|
||||
|
||||
$url = isset( $_POST['url'] ) ? sanitize_url( $_POST['url'] ) : false; // phpcs:ignore -- We need to remove this ignore once the WPCS has released this issue fix - https://github.com/WordPress/WordPress-Coding-Standards/issues/2189.
|
||||
$name = isset( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
|
||||
$desc = isset( $_POST['description'] ) ? sanitize_text_field( $_POST['description'] ) : '';
|
||||
$photo_id = isset( $_POST['id'] ) ? absint( sanitize_key( $_POST['id'] ) ) : 0;
|
||||
|
||||
if ( 0 === $photo_id ) {
|
||||
wp_send_json_error( __( 'Need to send photo ID', 'astra-sites' ) );
|
||||
}
|
||||
|
||||
if ( false === $url ) {
|
||||
wp_send_json_error( __( 'Need to send URL of the image to be downloaded', 'astra-sites' ) );
|
||||
}
|
||||
|
||||
$image = '';
|
||||
$result = array();
|
||||
|
||||
$name = preg_replace( '/\.[^.]+$/', '', (string) $name ) . '-' . $photo_id . '.jpg';
|
||||
$image = $this->create_image_from_url( $url, $name, (string) $photo_id, $desc );
|
||||
|
||||
if ( empty( $image ) ) {
|
||||
wp_send_json_error( __( 'Could not download the image.', 'astra-sites' ) );
|
||||
}
|
||||
|
||||
$image = intval( $image );
|
||||
$result['attachmentData'] = wp_prepare_attachment_for_js( $image );
|
||||
|
||||
if ( did_action( 'elementor/loaded' ) ) {
|
||||
$result['data'] = $this->get_attachment_data( $image );
|
||||
}
|
||||
|
||||
// Save downloaded image reference to an option.
|
||||
if ( 0 !== $photo_id ) {
|
||||
$saved_images = get_option( 'zipwp-images-saved-images', array() );
|
||||
|
||||
if ( empty( $saved_images ) ) {
|
||||
$saved_images = array();
|
||||
}
|
||||
|
||||
$saved_images[] = $photo_id;
|
||||
update_option( 'zipwp-images-saved-images', $saved_images, false );
|
||||
}
|
||||
|
||||
$result['updated-saved-images'] = get_option( 'zipwp-images-saved-images', array() );
|
||||
|
||||
wp_send_json_success( $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the image and return the new media upload id.
|
||||
*
|
||||
* @param String $url URL to pixabay image.
|
||||
* @param String $name Name to pixabay image.
|
||||
* @param String $photo_id Photo ID to pixabay image.
|
||||
* @param String $description Description to pixabay image.
|
||||
* @see http://codex.wordpress.org/Function_Reference/wp_insert_attachment#Example
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function create_image_from_url( $url, $name, $photo_id, $description = '' ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/media.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/image.php';
|
||||
$file_array = array();
|
||||
$file_array['name'] = wp_basename( $name );
|
||||
|
||||
// Download file to temp location.
|
||||
$file_array['tmp_name'] = download_url( $url );
|
||||
|
||||
// If error storing temporarily, return the error.
|
||||
if ( is_wp_error( $file_array['tmp_name'] ) ) {
|
||||
return $file_array;
|
||||
}
|
||||
|
||||
// Do the validation and storage stuff.
|
||||
$id = media_handle_sideload( $file_array, 0, null );
|
||||
|
||||
// If error storing permanently, unlink.
|
||||
if ( is_wp_error( $id ) ) {
|
||||
@unlink( $file_array['tmp_name'] ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink -- Deleting the file from temp location.
|
||||
return $id;
|
||||
}
|
||||
|
||||
$alt = '' === $description ? $name : $description;
|
||||
|
||||
// Store the original attachment source in meta.
|
||||
add_post_meta( $id, '_source_url', $url );
|
||||
|
||||
update_post_meta( $id, 'zipwp-images', $photo_id );
|
||||
update_post_meta( $id, '_wp_attachment_image_alt', $alt );
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Image.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param int $image Downloaded Image id.
|
||||
* @return array<string, array<int, array<string, mixed>>>
|
||||
*/
|
||||
public function get_attachment_data( $image ) {
|
||||
if ( empty( $image ) || ! class_exists( 'Elementor\Utils' ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return array(
|
||||
'content' => array(
|
||||
array(
|
||||
'id' => \Elementor\Utils::generate_random_string(),
|
||||
'elType' => 'section',
|
||||
'settings' => array(),
|
||||
'isInner' => false,
|
||||
'elements' => array(
|
||||
array(
|
||||
'id' => \Elementor\Utils::generate_random_string(),
|
||||
'elType' => 'column',
|
||||
'elements' => array(
|
||||
array(
|
||||
'id' => \Elementor\Utils::generate_random_string(),
|
||||
'elType' => 'widget',
|
||||
'settings' => array(
|
||||
'image' => array(
|
||||
'url' => wp_get_attachment_url( $image ),
|
||||
'id' => $image,
|
||||
),
|
||||
'image_size' => 'full',
|
||||
),
|
||||
'widgetType' => 'image',
|
||||
),
|
||||
),
|
||||
'isInner' => false,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Image size.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param array<string, array<string, mixed>> $image Image Array.
|
||||
*
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function get_image_size( $image ) {
|
||||
$sizes = array();
|
||||
|
||||
if ( empty( $image['details'] ) ) {
|
||||
return $sizes;
|
||||
}
|
||||
|
||||
switch ( $image['engine'] ) {
|
||||
case 'pexels':
|
||||
$available_image_sizes = $image['details']['src'];
|
||||
|
||||
if ( is_array( $available_image_sizes ) ) {
|
||||
foreach ( $available_image_sizes as $size_key => $url ) {
|
||||
$dimensions = $this->get_image_dimensions( $url );
|
||||
$value = array(
|
||||
'id' => $size_key,
|
||||
'url' => $url,
|
||||
'width' => $dimensions['width'],
|
||||
'height' => $dimensions['height'],
|
||||
);
|
||||
$sizes[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $sizes;
|
||||
case 'pixabay':
|
||||
$sizes = array(
|
||||
array(
|
||||
'id' => 'original',
|
||||
'url' => $image['details']['largeImageURL'],
|
||||
'width' => $image['details']['webformatWidth'],
|
||||
'height' => $image['details']['webformatHeight'],
|
||||
),
|
||||
array(
|
||||
'id' => 'medium',
|
||||
'url' => $image['details']['webformatURL'],
|
||||
'width' => $image['details']['webformatWidth'],
|
||||
'height' => $image['details']['webformatHeight'],
|
||||
),
|
||||
array(
|
||||
'id' => 'small',
|
||||
'url' => $image['details']['previewURL'],
|
||||
'width' => $image['details']['previewWidth'],
|
||||
'height' => $image['details']['previewHeight'],
|
||||
),
|
||||
);
|
||||
|
||||
return $sizes;
|
||||
default:
|
||||
return $sizes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get width and height of the image.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param string $url Image URL.
|
||||
* @return array<string, array<string, string>|string>
|
||||
*/
|
||||
public function get_image_dimensions( $url ) {
|
||||
$clean_url = esc_url_raw( $url );
|
||||
parse_str( explode( '?', $clean_url )[1], $query_params );
|
||||
return array(
|
||||
'width' => $query_params['w'] ?? '',
|
||||
'height' => $query_params['h'] ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Zipwp_Images_Api::get_instance();
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* Zipwp Images Script
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Zipwp Images Script
|
||||
*/
|
||||
|
||||
namespace ZipWP_Images\Classes;
|
||||
|
||||
/**
|
||||
* Ai_Builder
|
||||
*/
|
||||
class Zipwp_Images_Script {
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @access private
|
||||
* @var object Class Instance.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'editor_load_scripts' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'bb_editor_load_scripts' ) );
|
||||
add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'editor_load_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load script for block editor and elementor editor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function editor_load_scripts(): void {
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load_script();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load script for block BB editor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function bb_editor_load_scripts(): void {
|
||||
|
||||
if ( class_exists( 'FLBuilderModel' ) && \FLBuilderModel::is_builder_active() || is_customize_preview() ) {
|
||||
$this->load_script();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the required files in the importer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function load_script(): void {
|
||||
|
||||
// Introduces a filter to exclude certain post types from the plugin.
|
||||
if ( ! is_customize_preview() && function_exists( 'get_current_screen' ) ) {
|
||||
$exclude_post_types = apply_filters( 'zipwp_images_excluded_post_types', array( 'sureforms_form' ) );
|
||||
$post_types = array_diff( get_post_types( array( 'public' => true ), 'names' ), $exclude_post_types );
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
if ( ! is_object( $current_screen ) && is_null( $current_screen ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'site-editor' !== $current_screen->base && ! array_key_exists( $current_screen->post_type, $post_types ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Enqueue JS.
|
||||
wp_enqueue_script( 'zipwp-images-script', ZIPWP_IMAGES_URL . 'dist/main.js', array( 'jquery', 'media-views', 'react', 'wp-element', 'wp-api-fetch' ), ZIPWP_IMAGES_VER, true );
|
||||
|
||||
$data = apply_filters(
|
||||
'zipwp_images_vars',
|
||||
array(
|
||||
'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
|
||||
'asyncurl' => esc_url( admin_url( 'async-upload.php' ) ),
|
||||
'is_customize_preview' => is_customize_preview(),
|
||||
'is_bb_active' => class_exists( 'FLBuilderModel' ),
|
||||
'is_brizy_active' => class_exists( 'Brizy_Editor_Post' ),
|
||||
'is_elementor_active' => did_action( 'elementor/loaded' ),
|
||||
'is_elementor_editor' => did_action( 'elementor/loaded' ) && class_exists( '\Elementor\Plugin' ) ? \Elementor\Plugin::instance()->editor->is_edit_mode() : false,
|
||||
'is_bb_editor' => class_exists( '\FLBuilderModel' ) ? \FLBuilderModel::is_builder_active() : false,
|
||||
'is_brizy_editor' => class_exists( 'Brizy_Editor_Post' ) ? ( isset( $_GET['brizy-edit'] ) || isset( $_GET['brizy-edit-iframe'] ) ) : false, // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Fetching GET parameter, no nonce associated with this action.
|
||||
'saved_images' => get_option( 'zipwp-images-saved-images', array() ),
|
||||
'title' => apply_filters( 'zipwp_images_tab_title', __( 'Search Images', 'astra-sites' ) ),
|
||||
'search_placeholder' => __( 'Search - Ex: flowers', 'astra-sites' ),
|
||||
'downloading' => __( 'Downloading...', 'astra-sites' ),
|
||||
'validating' => __( 'Validating...', 'astra-sites' ),
|
||||
'_ajax_nonce' => wp_create_nonce( 'zipwp-images' ),
|
||||
'rest_api_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '',
|
||||
)
|
||||
);
|
||||
|
||||
// Add localize JS.
|
||||
wp_localize_script(
|
||||
'zipwp-images-script',
|
||||
'zipwpImages',
|
||||
$data
|
||||
);
|
||||
|
||||
// Enqueue CSS.
|
||||
wp_enqueue_style( 'zipwp-images-style', ZIPWP_IMAGES_URL . 'dist/style-main.css', array(), ZIPWP_IMAGES_VER );
|
||||
wp_enqueue_style( 'zipwp-images-google-fonts', $this->google_fonts_url(), array(), 'all' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and return the Google fonts url.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function google_fonts_url() {
|
||||
|
||||
$fonts_url = '';
|
||||
$font_families = array(
|
||||
'Figtree:400,500,600,700',
|
||||
);
|
||||
|
||||
$query_args = array(
|
||||
'family' => rawurlencode( implode( '|', $font_families ) ),
|
||||
'subset' => rawurlencode( 'latin,latin-ext' ),
|
||||
);
|
||||
|
||||
return add_query_arg( $query_args, '//fonts.googleapis.com/css' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Zipwp_Images_Script::get_instance();
|
||||
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-element', 'wp-i18n'), 'version' => 'aad13e1c6e4f53f94ada');
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"zipwp-images": "1.0.17"
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Loader.
|
||||
*
|
||||
* @package {{package}}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace ZipWP_Images;
|
||||
|
||||
/**
|
||||
* Zipwp_Images_Loader
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Zipwp_Images_Loader {
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @access private
|
||||
* @var object Class Instance.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
spl_autoload_register( [ $this, 'autoload' ] );
|
||||
|
||||
add_action( 'init', [ $this, 'load_textdomain' ] );
|
||||
add_action( 'wp_loaded', [ $this, 'load_files' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoload classes.
|
||||
*
|
||||
* @param string $class class name.
|
||||
* @return void
|
||||
*/
|
||||
public function autoload( $class ): void {
|
||||
if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$class_to_load = $class;
|
||||
|
||||
$filename = strtolower(
|
||||
(string) preg_replace(
|
||||
[ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
|
||||
[ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
|
||||
$class_to_load
|
||||
)
|
||||
);
|
||||
|
||||
$file = ZIPWP_IMAGES_DIR . $filename . '.php';
|
||||
|
||||
// if the file redable, include it.
|
||||
if ( is_readable( $file ) ) {
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Files
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_files(): void {
|
||||
require_once ZIPWP_IMAGES_DIR . 'classes/zipwp-images-script.php';
|
||||
require_once ZIPWP_IMAGES_DIR . 'classes/zipwp-images-api.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Plugin Text Domain.
|
||||
* This will load the translation textdomain depending on the file priorities.
|
||||
* 1. Global Languages /wp-content/languages/zipwp-images/ folder
|
||||
* 2. Local dorectory /wp-content/plugins/zipwp-images/languages/ folder
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function load_textdomain(): void {
|
||||
// Default languages directory.
|
||||
$lang_dir = ZIPWP_IMAGES_DIR . 'languages/';
|
||||
|
||||
/**
|
||||
* Filters the languages directory path to use for plugin.
|
||||
*
|
||||
* @param string $lang_dir The languages directory path.
|
||||
*/
|
||||
$lang_dir = apply_filters( 'zipwp_images_languages_directory', $lang_dir );
|
||||
|
||||
// Traditional WordPress plugin locale filter.
|
||||
global $wp_version;
|
||||
|
||||
$get_locale = get_locale();
|
||||
|
||||
if ( $wp_version >= 4.7 ) {
|
||||
$get_locale = get_user_locale();
|
||||
}
|
||||
|
||||
$locale = apply_filters( 'plugin_locale', $get_locale, 'zipwp-images' );
|
||||
$mofile = sprintf( '%1$s-%2$s.mo', 'zipwp-images', $locale );
|
||||
|
||||
// Setup paths to current locale file.
|
||||
$mofile_global = WP_LANG_DIR . '/plugins/' . $mofile;
|
||||
$mofile_local = $lang_dir . $mofile;
|
||||
|
||||
if ( file_exists( $mofile_global ) ) {
|
||||
// Look in global /wp-content/languages/zipwp-images/ folder.
|
||||
load_textdomain( 'zipwp-images', $mofile_global );
|
||||
} elseif ( file_exists( $mofile_local ) ) {
|
||||
// Look in local /wp-content/plugins/zipwp-images/languages/ folder.
|
||||
load_textdomain( 'zipwp-images', $mofile_local );
|
||||
} else {
|
||||
// Load the default language files.
|
||||
load_plugin_textdomain( 'zipwp-images', false, $lang_dir );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Zipwp_Images_Loader::get_instance();
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: ZipWP Images
|
||||
* Description: It is a free image library.
|
||||
* Author: Brainstorm Force
|
||||
* Version: 1.0.17
|
||||
* License: GPL v2
|
||||
* Text Domain: zipwp-images
|
||||
*
|
||||
* @package {{package}}
|
||||
*/
|
||||
|
||||
if ( defined( 'ZIPWP_IMAGES_FILE' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set constants
|
||||
*/
|
||||
define( 'ZIPWP_IMAGES_FILE', __FILE__ );
|
||||
define( 'ZIPWP_IMAGES_BASE', plugin_basename( ZIPWP_IMAGES_FILE ) );
|
||||
define( 'ZIPWP_IMAGES_DIR', plugin_dir_path( ZIPWP_IMAGES_FILE ) );
|
||||
define( 'ZIPWP_IMAGES_URL', plugins_url( '/', ZIPWP_IMAGES_FILE ) );
|
||||
define( 'ZIPWP_IMAGES_VER', '1.0.17' );
|
||||
|
||||
require_once 'zipwp-images-loader.php';
|
||||
Reference in New Issue
Block a user