PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 3.1.0
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v3.1.0
5.5.3 3.1.0 3.2.0 3.2.1 3.3.0 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.6.0 3.7.0 3.8.0 3.8.1 3.8.2 3.8.3 4.0.0 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 All 78 releases
copy-the-code / classes / class-helpers.php

class-helpers.php in Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code 3.1.0, at classes/class-helpers.php

72 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Helpers
4 *
5 * @package Copy the Code
6 * @since 1.0.0
7 */
8
9 namespace CopyTheCode;
10
11 /**
12 * Helpers
13 *
14 * @since 1.0.0
15 */
16 class Helpers {
17 public static function get_svg_copy_icon() {
18 return '<svg aria-hidden="true" focusable="false" role="img" class="copy-icon" viewBox="0 0 16 16" width="16" height="16" fill="currentColor"><path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"></path><path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"></path></svg>';
19 }
20
21 public static function get_svg_checked_icon() {
22 return '<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="check-icon" fill="currentColor"><path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"></path></svg>';
23 }
24
25 public static function get_copy_button( $args = [] ) {
26 $show_icon = isset( $args['show_icon'] ) ? $args['show_icon'] : 'yes';
27 $with_icon = 'yes' === $show_icon ? 'with-icon' : 'without-icon';
28 $as_raw = isset( $args['as_raw'] ) ? 'yes' : '';
29 $copy_button_text = isset( $args['copy_button_text'] ) ? $args['copy_button_text'] : esc_html__( 'Copy', 'copy-the-code' );
30 $copy_button_text_copied = isset( $args['copy_button_text_copied'] ) ? $args['copy_button_text_copied'] : esc_html__( 'Copied!', 'copy-the-code' );
31 $icon_direction = isset( $args['icon_direction'] ) ? $args['icon_direction'] : 'before';
32
33 ob_start();
34 ?>
35 <button class="ctc-block-copy ctc-<?php echo esc_attr( $with_icon ); ?>" copy-as-raw='<?php echo esc_html( $as_raw ); ?>' data-copied="<?php echo esc_html( $copy_button_text_copied ); ?>">
36 <?php
37 if ( 'before' === $icon_direction && 'yes' === $show_icon ) {
38 echo self::get_svg_copy_icon();
39 echo self::get_svg_checked_icon();
40 }
41 echo '<span class="ctc-button-text">' . esc_html( $copy_button_text ) . '</span>';
42 if ( 'after' === $icon_direction && 'yes' === $show_icon ) {
43 echo self::get_svg_copy_icon();
44 echo self::get_svg_checked_icon();
45 }
46 ?>
47 </button>
48 <?php
49 return ob_get_clean();
50 }
51
52 /**
53 * Is shortcode used
54 *
55 * @param string $shortcode
56 * @since 3.1.0
57 */
58 public static function is_shortcode_used( $shortcode = '' ) {
59 global $post;
60 if ( ! $post ) {
61 return false;
62 }
63
64 $found = false;
65 if ( has_shortcode( $post->post_content, $shortcode ) ) {
66 $found = true;
67 }
68
69 return $found;
70 }
71
72 }