Skip to content

Commit

Permalink
Merge pull request #52 from iamdharmesh/master
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Apr 15, 2023
2 parents 0277efd + 80c5d5a commit 7103e48
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 44 deletions.
8 changes: 5 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Contributors: dharm1025,hazemkhaled,esl4m,firstanonymous
Tags: featured image, url, image url, image, woocommerce, remote featured image, product gallery
Requires PHP: 5.3
Requires at least: 4.0
Tested up to: 5.6
Requires at least: 5.8
Tested up to: 6.2
WC tested up to: 4.0.1
Stable tag: 1.1.8
Stable tag: 1.1.9
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -63,6 +63,8 @@ Featured Image by URL allows to use an external URL Images as Featured Image for
6. Settings Panel

== Changelog ==
= 1.1.9 =
* Tested with WP 6.2

= 1.1.8 =
* Tested with WP 5.6
Expand Down
7 changes: 4 additions & 3 deletions featured-image-by-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Featured Image by URL
* Plugin URI: https://wordpress.org/plugins/featured-image-by-url/
* Description: This plugin allows to use an external URL Images as Featured Image for your post types. Includes support for Product Gallery (WooCommece).
* Version: 1.1.7
* Version: 1.1.9
* Author: Knawat
* Author URI: https://www.knawat.com/?utm_source=wordpress.org&utm_medium=social&utm_campaign=WordPress%20Image%20by%20URL
* License: GPL-2.0+
Expand All @@ -28,6 +28,7 @@ class Featured_Image_By_URL{
/** Singleton *************************************************************/
/**
* Featured_Image_By_URL The one true Featured_Image_By_URL.
* @var Featured_Image_By_URL $instance
*/
private static $instance;

Expand Down Expand Up @@ -76,14 +77,14 @@ private function __construct() { /* Do nothing here */ }
*
* @since 1.0.0
*/
public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'featured-image-by-url' ), '1.1.4' ); }
public function __clone() { _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'featured-image-by-url' ), '1.1.9' ); }

/**
* A dummy magic method to prevent Featured_Image_By_URL from being unserialized.
*
* @since 1.0.0
*/
public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'featured-image-by-url' ), '1.1.4' ); }
public function __wakeup() { _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'featured-image-by-url' ), '1.1.9' ); }


/**
Expand Down
69 changes: 42 additions & 27 deletions includes/class-featured-image-by-url-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function knawatfibu_render_wcgallary_metabox( $post ) {
function enqueue_admin_styles( $hook ) {

$css_dir = KNAWATFIBU_PLUGIN_URL . 'assets/css/';
wp_enqueue_style('knawatfibu-admin', $css_dir . 'featured-image-by-url-admin.css', false, "" );
wp_enqueue_style('knawatfibu-admin', $css_dir . 'featured-image-by-url-admin.css', array(), '1.1.9', "" );

}

Expand Down Expand Up @@ -150,11 +150,12 @@ function knawatfibu_save_image_url_data( $post_id, $post ) {
return;
}

if( isset( $_POST['knawatfibu_url'] ) ){
if( isset( $_POST['knawatfibu_url'] ) ){ // phpcs:ignore WordPress.Security.NonceVerification.Missing
global $knawatfibu;
// Update Featured Image URL
$image_url = isset( $_POST['knawatfibu_url'] ) ? esc_url( $_POST['knawatfibu_url'] ) : '';
$image_alt = isset( $_POST['knawatfibu_alt'] ) ? wp_strip_all_tags( $_POST['knawatfibu_alt'] ): '';
// phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$image_url = isset( $_POST['knawatfibu_url'] ) ? esc_url_raw( $_POST['knawatfibu_url'] ) : '';
$image_alt = isset( $_POST['knawatfibu_alt'] ) ? wp_strip_all_tags( $_POST['knawatfibu_alt'] ): ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash

if ( $image_url != '' ){
if( get_post_type( $post_id ) == 'product' ){
Expand Down Expand Up @@ -185,9 +186,9 @@ function knawatfibu_save_image_url_data( $post_id, $post ) {
}
}

if( isset( $_POST['knawatfibu_wcgallary'] ) ){
if( isset( $_POST['knawatfibu_wcgallary'] ) ){ // phpcs:ignore WordPress.Security.NonceVerification.Missing
// Update WC Gallery
$knawatfibu_wcgallary = isset( $_POST['knawatfibu_wcgallary'] ) ? $_POST['knawatfibu_wcgallary'] : '';
$knawatfibu_wcgallary = isset( $_POST['knawatfibu_wcgallary'] ) ? $this->knawatfibu_sanitize( $_POST['knawatfibu_wcgallary'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if( empty( $knawatfibu_wcgallary ) || $post->post_type != 'product' ){
return;
}
Expand Down Expand Up @@ -233,7 +234,7 @@ function knawatfibu_save_image_url_data( $post_id, $post ) {
* Get Image metadata by post_id
*
* @since 1.0
* @return void
* @return array
*/
function knawatfibu_get_image_meta( $post_id, $is_single_page = false ){

Expand Down Expand Up @@ -273,7 +274,7 @@ function knawatfibu_get_image_meta( $post_id, $is_single_page = false ){
* Adds Settings Page
*
* @since 1.0
* @return array
* @return void
*/
function knawatfibu_add_options_page() {
add_options_page( __('Featured Image by URL', 'featured-image-by-url' ), __('Featured Image by URL', 'featured-image-by-url' ), 'manage_options', 'knawatfibu', array( $this, 'knawatfibu_options_page_html' ) );
Expand All @@ -283,7 +284,7 @@ function knawatfibu_add_options_page() {
* Settings Page HTML
*
* @since 1.0
* @return array
* @return array|null
*/
function knawatfibu_options_page_html() {
// check user capabilities
Expand Down Expand Up @@ -313,7 +314,7 @@ function knawatfibu_options_page_html() {
* Register custom settings, Sections & fields
*
* @since 1.0
* @return array
* @return void
*/
function knawatfibu_settings_init() {
register_setting( 'knawatfibu', KNAWATFIBU_OPTIONS );
Expand Down Expand Up @@ -355,7 +356,7 @@ function knawatfibu_settings_init() {
* Callback function for knawatfibu section.
*
* @since 1.0
* @return array
* @return void
*/
function knawatfibu_section_callback( $args ) {
// Do some HTML here.
Expand All @@ -365,7 +366,7 @@ function knawatfibu_section_callback( $args ) {
* Callback function for disabled_posttypes field.
*
* @since 1.0
* @return array
* @return void
*/
function disabled_posttypes_callback( $args ) {
// get the value of the setting we've registered with register_setting()
Expand All @@ -378,9 +379,9 @@ function disabled_posttypes_callback( $args ) {
if( !empty( $post_types ) ){
foreach ($post_types as $key => $post_type ) {
?>
<label for="<?php echo $key; ?>" style="display: block;">
<input name="<?php echo KNAWATFIBU_OPTIONS.'['. esc_attr( $args['label_for'] ).']'; ?>[]" class="disabled_posttypes" id="<?php echo $key; ?>" type="checkbox" value="<?php echo $key; ?>" <?php if( in_array( $key, $disabled_posttypes ) ){ echo 'checked="checked"'; } ?> >
<?php echo $posttype_title = isset( $wp_post_types[$key]->label ) ? $wp_post_types[$key]->label : ucfirst( $key); ?>
<label for="<?php echo esc_attr( $key ); ?>" style="display: block;">
<input name="<?php echo esc_attr( KNAWATFIBU_OPTIONS.'['. $args['label_for'] .']' ); ?>[]" class="disabled_posttypes" id="<?php echo esc_attr( $key ); ?>" type="checkbox" value="<?php echo esc_attr( $key ); ?>" <?php if( in_array( $key, $disabled_posttypes ) ){ echo 'checked="checked"'; } ?> >
<?php echo $posttype_title = isset( $wp_post_types[$key]->label ) ? esc_html( $wp_post_types[$key]->label ) : esc_html( ucfirst( $key) ); ?>
</label>
<?php
}
Expand All @@ -397,15 +398,15 @@ function disabled_posttypes_callback( $args ) {
* Callback function for resize_images field.
*
* @since 1.0
* @return array
* @return void
*/
function resize_images_callback( $args ) {
// get the value of the setting we've registered with register_setting()
$options = get_option( KNAWATFIBU_OPTIONS );
$resize_images = isset( $options['resize_images'] ) ? $options['resize_images'] : false;
?>
<label for="resize_images">
<input name="<?php echo KNAWATFIBU_OPTIONS.'['. esc_attr( $args['label_for'] ).']'; ?>" type="checkbox" value="1" id="resize_images" <?php if ( !defined( 'JETPACK__VERSION' ) ) { echo 'disabled="disabled"'; }else{ if( $resize_images ){ echo 'checked="checked"'; } } ?>>
<input name="<?php echo esc_attr( KNAWATFIBU_OPTIONS.'['. $args['label_for'] .']' ); ?>" type="checkbox" value="1" id="resize_images" <?php if ( !defined( 'JETPACK__VERSION' ) ) { echo 'disabled="disabled"'; }else{ if( $resize_images ){ echo 'checked="checked"'; } } ?>>
<?php esc_html_e( 'Enable display resized images for image sizes like thumbnail, medium, large etc..', 'featured-image-by-url' ); ?>

</label>
Expand All @@ -424,7 +425,7 @@ function resize_images_callback( $args ) {
*/
function knawatfibu_get_posttypes( $raw = false ) {

$post_types = array_diff( get_post_types( array( 'public' => true ), 'names' ), array( 'nav_menu_item', 'attachment', 'revision' ) );
$post_types = array_diff( get_post_types( array( 'public' => true ), 'names' ), array( 'nav_menu_item', 'attachment', 'revision' ) );
if( !empty( $post_types ) ){
foreach ( $post_types as $key => $post_type ) {
if( !post_type_supports( $post_type, 'thumbnail' ) ){
Expand Down Expand Up @@ -458,18 +459,18 @@ public function knawatfibu_add_product_variation_image_selector( $loop, $variati
}
}
?>
<div id="knawatfibu_product_variation_<?php echo $variation->ID; ?>" class="knawatfibu_product_variation form-row form-row-first">
<label for="knawatfibu_pvar_url_<?php echo $variation->ID; ?>">
<div id="knawatfibu_product_variation_<?php echo esc_attr( $variation->ID ); ?>" class="knawatfibu_product_variation form-row form-row-first">
<label for="knawatfibu_pvar_url_<?php echo esc_attr( $variation->ID ); ?>">
<strong><?php _e('Product Variation Image by URL', 'featured-image-by-url') ?></strong>
</label>

<div id="knawatfibu_pvar_img_wrap_<?php echo $variation->ID; ?>" class="knawatfibu_pvar_img_wrap" style="<?php if( $knawatfibu_url == '' ){ echo 'display:none'; } ?>" >
<span href="#" class="knawatfibu_pvar_remove" data-id="<?php echo $variation->ID; ?>"></span>
<img id="knawatfibu_pvar_img_<?php echo $variation->ID; ?>" class="knawatfibu_pvar_img" data-id="<?php echo $variation->ID; ?>" src="<?php echo $knawatfibu_url; ?>" />
<div id="knawatfibu_pvar_img_wrap_<?php echo esc_attr( $variation->ID ); ?>" class="knawatfibu_pvar_img_wrap" style="<?php if( $knawatfibu_url == '' ){ echo 'display:none'; } ?>" >
<span href="#" class="knawatfibu_pvar_remove" data-id="<?php echo esc_attr( $variation->ID ); ?>"></span>
<img id="knawatfibu_pvar_img_<?php echo esc_attr( $variation->ID ); ?>" class="knawatfibu_pvar_img" data-id="<?php echo esc_attr( $variation->ID ); ?>" src="<?php echo esc_attr( $knawatfibu_url ); ?>" />
</div>
<div id="knawatfibu_url_wrap_<?php echo $variation->ID; ?>" style="<?php if( $knawatfibu_url != '' ){ echo 'display:none'; } ?>" >
<input id="knawatfibu_pvar_url_<?php echo $variation->ID; ?>" class="knawatfibu_pvar_url" type="text" name="knawatfibu_pvar_url[<?php echo $variation->ID; ?>]" placeholder="<?php _e('Product Variation Image URL', 'featured-image-by-url'); ?>" value="<?php echo $knawatfibu_url; ?>"/>
<a id="knawatfibu_pvar_preview_<?php echo $variation->ID; ?>" class="knawatfibu_pvar_preview button" data-id="<?php echo $variation->ID; ?>">
<div id="knawatfibu_url_wrap_<?php echo esc_attr( $variation->ID ); ?>" style="<?php if( $knawatfibu_url != '' ){ echo 'display:none'; } ?>" >
<input id="knawatfibu_pvar_url_<?php echo esc_attr( $variation->ID ); ?>" class="knawatfibu_pvar_url" type="text" name="knawatfibu_pvar_url[<?php echo esc_attr( $variation->ID ); ?>]" placeholder="<?php _e('Product Variation Image URL', 'featured-image-by-url'); ?>" value="<?php echo esc_attr( $knawatfibu_url ); ?>"/>
<a id="knawatfibu_pvar_preview_<?php echo esc_attr( $variation->ID ); ?>" class="knawatfibu_pvar_preview button" data-id="<?php echo esc_attr( $variation->ID ); ?>">
<?php _e( 'Preview', 'featured-image-by-url' ); ?>
</a>
</div>
Expand All @@ -484,7 +485,7 @@ public function knawatfibu_add_product_variation_image_selector( $loop, $variati
*/
public function knawatfibu_save_product_variation_image( $variation_id, $i ){

$image_url = isset( $_POST['knawatfibu_pvar_url'][$variation_id] ) ? esc_url( $_POST['knawatfibu_pvar_url'][$variation_id] ) : '';
$image_url = isset( $_POST['knawatfibu_pvar_url'][$variation_id] ) ? esc_url_raw( $_POST['knawatfibu_pvar_url'][$variation_id] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
if( $image_url != '' ){
$img_url = get_post_meta( $variation_id, $this->image_meta_url , true );
if( is_array( $img_url ) && isset( $img_url['img_url'] ) && $image_url == $img_url['img_url'] ){
Expand All @@ -506,4 +507,18 @@ public function knawatfibu_save_product_variation_image( $variation_id, $i ){
delete_post_meta( $variation_id, $this->image_meta_url );
}
}

/**
* Sanitize variables using sanitize_text_field and wp_unslash.
*
* @param string|array $var Data to sanitize.
* @return string|array
*/
public function knawatfibu_sanitize( $var ) {
if ( is_array( $var ) ) {
return array_map( array( $this, 'knawatfibu_sanitize' ), $var );
} else {
return is_scalar( $var ) ? sanitize_text_field( wp_unslash( $var ) ) : $var;
}
}
}
8 changes: 4 additions & 4 deletions includes/class-featured-image-by-url-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function knawatfibu_set_thumbnail_id_true(){
* Set '_thubmnail_id' true if post has external featured image.
*
* @since 1.0
* @return void
* @return mixed
*/
function knawatfibu_set_thumbnail_true( $value, $object_id, $meta_key, $single ){

Expand Down Expand Up @@ -447,7 +447,7 @@ public function knawatfibu_woo_thumb_support() {
global $pagenow;
if( 'edit.php' === $pagenow ){
global $typenow;
if( 'product' === $typenow && isset( $_GET['post_type'] ) && 'product' === sanitize_text_field( $_GET['post_type'] ) ){
if( 'product' === $typenow && isset( $_GET['post_type'] ) && 'product' === sanitize_text_field( wp_unslash( $_GET['post_type'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
add_filter( 'wp_get_attachment_image_src', array( $this, 'knawatfibu_replace_attachment_image_src' ), 10, 4 );
}
}
Expand All @@ -457,7 +457,7 @@ public function knawatfibu_woo_thumb_support() {
* Add Support for WooCommerce Product Structured Data.
*
* @since 1.0
* @param array $markup
* @param array $markup
* @param object $product
* @return array $markup
*/
Expand Down Expand Up @@ -519,7 +519,7 @@ public function knawatfibu_facebook_for_woocommerce_support( $product_data, $pro
*
* @since 1.0
* @param array|string $image
* @param string $attachment_id
* @param string $attachment_id
* @return altered Image.
*/
function knawatfibu_shopzio_product_image_url( $image, $attachment_id ) {
Expand Down
8 changes: 4 additions & 4 deletions templates/knawatfibu-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

<div id="knawatfibu_metabox_content" >

<input id="knawatfibu_url" type="text" name="knawatfibu_url" placeholder="<?php _e('Image URL', 'featured-image-by-url') ?>" value="<?php echo $image_url; ?>" />
<input id="knawatfibu_url" type="text" name="knawatfibu_url" placeholder="<?php esc_attr_e('Image URL', 'featured-image-by-url') ?>" value="<?php echo esc_url_raw( $image_url ); ?>" />
<a id="knawatfibu_preview" class="button" >
<?php _e('Preview', 'featured-image-by-url') ?>
</a>

<input id="knawatfibu_alt" type="text" name="knawatfibu_alt" placeholder="<?php _e('Alt text (Optional)', 'featured-image-by-url') ?>" value="<?php echo $image_alt; ?>" />
<input id="knawatfibu_alt" type="text" name="knawatfibu_alt" placeholder="<?php esc_attr_e('Alt text (Optional)', 'featured-image-by-url') ?>" value="<?php echo esc_attr( $image_alt ); ?>" />

<div >
<span id="knawatfibu_noimg"><?php _e('No image', 'featured-image-by-url'); ?></span>
<img id="knawatfibu_img" src="<?php echo $image_url; ?>" />
<span id="knawatfibu_noimg"><?php esc_html_e('No image', 'featured-image-by-url'); ?></span>
<img id="knawatfibu_img" src="<?php echo esc_url( $image_url ); ?>" />
</div>

<a id="knawatfibu_remove" class="button" style="margin-top:4px;"><?php _e('Remove Image', 'featured-image-by-url') ?></a>
Expand Down
6 changes: 3 additions & 3 deletions templates/knawatfibu-wcgallary-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ function knawatfibu_get_gallary_slot( $image_url = '' ){
?>
<div id="knawatfibu_wcgallary__COUNT__" class="knawatfibu_wcgallary">
<div id="knawatfibu_url_wrap__COUNT__" <?php if( $image_url != ''){ echo 'style="display: none;"'; } ?>>
<input id="knawatfibu_url__COUNT__" class="knawatfibu_url" type="text" name="knawatfibu_wcgallary[__COUNT__][url]" placeholder="<?php _e('Image URL', 'featured-image-by-url') ?>" data-id="__COUNT__" value="<?php echo $image_url; ?>"/>
<input id="knawatfibu_url__COUNT__" class="knawatfibu_url" type="text" name="knawatfibu_wcgallary[__COUNT__][url]" placeholder="<?php esc_attr_e('Image URL', 'featured-image-by-url') ?>" data-id="__COUNT__" value="<?php echo esc_url_raw( $image_url ); ?>"/>
<a id="knawatfibu_preview__COUNT__" class="knawatfibu_preview button" data-id="__COUNT__">
<?php _e( 'Preview', 'featured-image-by-url' ); ?>
<?php esc_html_e( 'Preview', 'featured-image-by-url' ); ?>
</a>
</div>
<div id="knawatfibu_img_wrap__COUNT__" class="knawatfibu_img_wrap" <?php if( $image_url == ''){ echo 'style="display: none;"'; } ?>>
<span href="#" class="knawatfibu_remove" data-id="__COUNT__"></span>
<img id="knawatfibu_img__COUNT__" class="knawatfibu_img" data-id="__COUNT__" src="<?php echo $image_url; ?>" />
<img id="knawatfibu_img__COUNT__" class="knawatfibu_img" data-id="__COUNT__" src="<?php echo esc_url( $image_url ); ?>" />
</div>
</div>
<?php
Expand Down

0 comments on commit 7103e48

Please sign in to comment.