'', 'path' => '']. */ class Sellkit_Elementor_Controls_File_Uploader extends Control_Base_Multiple { /** * File uplodaer control constructor. * * Adds ajax hook for file upload. * * @since 1.5.0 */ public function __construct() { parent::__construct(); // Register AJAX action. add_action( 'wp_ajax_sellkit_control_file_upload', [ $this, 'handle_file_upload' ] ); // Define nonce for file upload ajax action. add_action( 'elementor/editor/after_enqueue_scripts', function() { wp_localize_script( 'sellkit-editor', 'sellkitNonceEditorFileUploader', [ wp_create_nonce( 'sellkit_fileuploader_editor' ) ] ); }, 20 ); } /** * Get type of the control, used in declaring "type" when creating Elementor control. * * @return string * * @since 1.5.0 */ public function get_type() { return 'sellkit_file_uploader'; } /** * Get array of default values for this control. * * @return array * * @since 1.5.0 */ public function get_default_value() { return [ 'files' => [], ]; } /** * Get array of default settings for this control. * * @return array * * @since 1.5.0 */ protected function get_default_settings() { return [ 'label_block' => false, ]; } /** * Echo the template of this control in the Elementor's editor panel. * * @since 1.5.0 */ public function content_template() { ?>
<# if ( data.description ) { #>
{{{ data.description }}}
<# } #>
false, 'mimes' => get_allowed_mime_types(), 'unique_filename_callback' => [ self::class, 'rename_uploading_file' ], ] ); if ( $movefile && ! isset( $movefile['error'] ) ) { wp_send_json_success( [ 'path' => $movefile['file'], 'name' => pathinfo( $movefile['file'], PATHINFO_BASENAME ), ] ); } wp_send_json_error( $movefile['error'] ); } /** * Used in override propery 'unique_filename_callback' of wp_handle_upload function. * * @param string $dir File directory. * @param string $name File name. * @param string $ext File extension. * @return string File name. * * @since 1.5.0 * @access public * @static * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public static function rename_uploading_file( $dir, $name, $ext ) { return str_replace( $ext, '', $name ) . '__' . uniqid() . $ext; } }