Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions php/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ public function init_setting_save() {
*/
protected function save_settings( $submission, $data ) {
$page = $this->settings->get_setting( $submission );
$errors = array();
$pending = false;
foreach ( $data as $key => $value ) {
$slug = $submission . $page->separator . $key;
Expand All @@ -451,7 +450,7 @@ protected function save_settings( $submission, $data ) {
$pending = true;
}

if ( empty( $errors ) && true === $pending ) {
if ( true === $pending ) {
$results = $this->settings->save();
if ( ! empty( $results ) ) {
$this->add_admin_notice( 'error_notice', __( 'Settings updated successfully', 'cloudinary' ), 'success' );
Expand Down
6 changes: 5 additions & 1 deletion php/class-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public function test_ping() {
protected function extract_cname( $parsed_url ) {
$cname = null;

if ( ! empty( $test['query'] ) ) {
if ( ! empty( $parsed_url['query'] ) ) {
$config_params = array();
wp_parse_str( $parsed_url['query'], $config_params );
$cname = isset( $config_params['cname'] ) ? $config_params['cname'] : $cname;
Expand Down Expand Up @@ -874,6 +874,7 @@ public function get_notices() {
*/
public function upgrade_connection( $old_version ) {

$data = array();
if ( version_compare( $old_version, '2.0.0', '>' ) ) {
// Post V1 - quick check all details are valid.
$data = $this->settings->get_value( 'connect' );
Expand Down Expand Up @@ -904,6 +905,9 @@ public function upgrade_connection( $old_version ) {
}

// Test upgraded details.
if ( empty( $data['cloudinary_url'] ) ) {
return; // Nothing to upgrade.
}
$data['cloudinary_url'] = str_replace( 'CLOUDINARY_URL=', '', $data['cloudinary_url'] );
$test = $this->test_connection( $data['cloudinary_url'] );

Expand Down
2 changes: 1 addition & 1 deletion php/class-delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ protected function is_content_dir( $url ) {
$dirname = trim( substr( $path, strlen( $base ), 8 ), DIRECTORY_SEPARATOR );
if ( empty( $dirname ) || preg_match( '/\d{4}\/\d{2}/', $dirname ) ) {
$is_local = true;
} elseif ( ! empty( $dirname ) ) {
} else {
$is_local = false;
}
}
Expand Down
10 changes: 9 additions & 1 deletion php/class-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class REST_API {
*/
public $endpoints;

/**
* Holds the plugin instance.
*
* @var Plugin
*/
protected $plugin;

/**
* The nonce key used for WordPress REST API authentication.
*
Expand All @@ -38,7 +45,8 @@ class REST_API {
*
* @param Plugin $plugin Instance of the global Plugin.
*/
public function __construct( Plugin $plugin ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
public function __construct( Plugin $plugin ) {
$this->plugin = $plugin;
add_action( 'rest_api_init', array( $this, 'rest_api_init' ), PHP_INT_MAX );
}

Expand Down
1 change: 1 addition & 0 deletions php/connect/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ public function upload_large( $attachment_id, $args ) {
$chunk_size = 20000000;
$index = 0;
$file_size = filesize( $args['file'] );
$result = new \WP_Error( 'upload_error', __( 'No data to upload.', 'cloudinary' ) );
while ( ! feof( $src ) ) {
$current_loc = $index * $chunk_size;
if ( $current_loc >= $file_size ) {
Expand Down
2 changes: 1 addition & 1 deletion php/media/class-upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function migrate_legacy_meta( $attachment_id ) {
update_post_meta( $attachment_id, '_wp_attachment_metadata', $old_meta );

// migrate from pre v2 meta.
if ( empty( $v2_meta ) && empty( $v3_meta ) ) {
if ( empty( $v2_meta ) ) {
// Attempt old post meta.
$public_id = get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true );
if ( ! empty( $public_id ) ) {
Expand Down
2 changes: 1 addition & 1 deletion php/media/class-video.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function admin_enqueue_scripts() {
*/
public function filter_video_block_render_block( $block_content, array $block ) {
if ( 'core/video' === $block['blockName'] ) {
remove_filter( 'render_block', array( $this, 'filter_video_block_render_block' ), 10, 2 );
remove_filter( 'render_block', array( $this, 'filter_video_block_render_block' ), 10 );

$filtered_block = $this->filter_video_block_pre_render( $block, $block );
$block_content = render_block( $filtered_block );
Expand Down
1 change: 1 addition & 0 deletions php/relate/class-relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @property string|null $text_overlay
* @property string|null $image_overlay
* @property string|null $sized_url
* @property string|null $url_hash
* @property string|null $media_context
*/
class Relationship {
Expand Down
3 changes: 2 additions & 1 deletion php/templates/connection-string.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<p>
<?php
printf(
wp_kses_post( 'After creating your %s:', 'cloudinary' ),
// translators: %s is the "Cloudinary account" link.
esc_html__( 'After creating your %s:', 'cloudinary' ),
sprintf(
// translators: Link to create a Cloudinary account.
esc_html__( '%1$sCloudinary account%2$s', 'cloudinary' ),
Expand Down
4 changes: 2 additions & 2 deletions php/ui/class-state.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class State {
*
* @param Plugin $plugin Instance of the plugin.
*/
public function __construct( Plugin $plugin ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
$this->plugin = get_plugin_instance();
public function __construct( Plugin $plugin ) {
$this->plugin = $plugin;
$this->user_id = get_current_user_id();

if ( ! empty( $this->user_id ) ) {
Expand Down
6 changes: 5 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ parameters:
-
identifier: return.void
message: '#^Action callback returns .+ but should not return anything\.$#'
level: 0
level: 1
paths:
- php
- cloudinary.php
Expand All @@ -25,9 +25,13 @@ parameters:
- vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php
- tests/phpstan/stubs/wpml.php
- tests/phpstan/stubs/wpcom-vip.php
- tests/phpstan/stubs/constants.php
excludePaths:
- build/*
- node_modules/*
- vendor/*
# Extends WPCOM_VIP_CLI_Command, only available on the WordPress VIP platform.
- php/class-cli-vip.php
# View templates are included into a class scope (so $this is bound at
# runtime), which PHPStan cannot model when analysing them standalone.
- php/templates/*
41 changes: 41 additions & 0 deletions tests/phpstan/stubs/constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Constant stubs for static analysis.
*
* These constants are defined at runtime and cannot be discovered by PHPStan:
*
* - The plugin's own CLDN_* constants are defined in cloudinary.php.
* - The CLOUDINARY_ENDPOINTS_* constants are defined conditionally in
* Cloudinary\Plugin::setup_endpoints().
* - CLOUDINARY_CONNECTION_STRING is an optional constant a site owner may
* define in wp-config.php to supply credentials.
* - WPINC and LOGGED_IN_COOKIE are WordPress core constants that are not
* provided by the WordPress stub package.
*
* @package Cloudinary
*/

define( 'CLDN_CORE', '' );
define( 'CLDN_PATH', '' );

define( 'CLOUDINARY_CONNECTION_STRING', '' );

// The endpoint values mirror the real defaults from
// Cloudinary\Plugin::setup_endpoints() so PHPStan sees matching sprintf
// placeholders (the *_CORE, *_SCRIPT and *_STYLE URLs contain a %s version
// token).
define( 'CLOUDINARY_ENDPOINTS_API', 'api.cloudinary.com' );
define( 'CLOUDINARY_ENDPOINTS_CORE', 'https://unpkg.com/cloudinary-core@%s/cloudinary-core-shrinkwrap.min.js' );
define( 'CLOUDINARY_ENDPOINTS_CORE_VERSION', '2.6.3' );
define( 'CLOUDINARY_ENDPOINTS_DEACTIVATION', 'https://analytics-api.cloudinary.com/wp_deactivate_reason' );
define( 'CLOUDINARY_ENDPOINTS_GALLERY', 'https://product-gallery.cloudinary.com/all.js' );
define( 'CLOUDINARY_ENDPOINTS_MEDIA_LIBRARY', 'https://media-library.cloudinary.com/global/all.js' );
define( 'CLOUDINARY_ENDPOINTS_PREVIEW_IMAGE', 'https://res.cloudinary.com/demo/image/upload/' );
define( 'CLOUDINARY_ENDPOINTS_PREVIEW_VIDEO', 'https://res.cloudinary.com/demo/video/upload/' );
define( 'CLOUDINARY_ENDPOINTS_VIDEO_PLAYER_EMBED', 'https://player.cloudinary.com/embed/' );
define( 'CLOUDINARY_ENDPOINTS_VIDEO_PLAYER_SCRIPT', 'https://unpkg.com/cloudinary-video-player@%s/dist/cld-video-player.min.js' );
define( 'CLOUDINARY_ENDPOINTS_VIDEO_PLAYER_STYLE', 'https://unpkg.com/cloudinary-video-player@%s/dist/cld-video-player.min.css' );
define( 'CLOUDINARY_ENDPOINTS_VIDEO_PLAYER_VERSION', '3.0.2' );

define( 'WPINC', 'wp-includes' );
define( 'LOGGED_IN_COOKIE', '' );
Loading