PluginProbe
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code / 2.2.2
Copy Anything to Clipboard for WordPress – Copy Button, Copy Text & Copy Code v2.2.2
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
← All changes | classes/class-copy-the-code-shortcode.php +73 -80 3.7.02.2.2 View file →
@@ -5,10 +5,8 @@
5 5 * @package Copy the Code
6 6 * @since 2.2.0
7 7 */
8 8
9 -use CopyTheCode\Helpers;
10 -
11 9 if ( ! class_exists( 'Copy_The_Code_Shortcode' ) ) :
12 10
13 11 /**
14 12 * Shortcode
@@ -33,9 +31,9 @@
33 31 * @return object initialized object of class.
34 32 */
35 33 public static function get_instance() {
36 34 if ( ! isset( self::$instance ) ) {
37 - self::$instance = new self();
35 + self::$instance = new self;
38 36 }
39 37 return self::$instance;
40 38 }
41 39
@@ -42,108 +40,103 @@
42 40 /**
43 41 * Constructor
44 42 */
45 43 public function __construct() {
46 - add_shortcode( 'copy', [ $this, 'shortcode_markup' ] );
47 - add_shortcode( 'copy_inline', [ $this, 'copy_inline_markup' ] );
48 - add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
44 + add_action( 'after_setup_theme', array( $this, 'init_admin_settings' ) );
45 + add_shortcode( 'copy', array( $this, 'shortcode_markup' ) );
49 46 }
50 47
51 48 /**
52 - * Enqueue scripts
49 + * Shortcode markup
53 50 *
54 - * @since 3.1.0
51 + * @since 2.2.0
52 + * @param array $atts Shortcode parameters.
53 + * @param mixed $content Shortcode content.
54 + * @return mixed
55 55 */
56 - public function enqueue_scripts() {
57 - // Core.
58 - wp_enqueue_script( 'ctc-clipboard', COPY_THE_CODE_URI . 'assets/js/clipboard.js', [ 'jquery' ], COPY_THE_CODE_VER, true );
56 + public function shortcode_markup( $atts = array(), $content = '' ) {
59 57
60 - // Shortcode.
61 - wp_enqueue_style( 'ctc-copy-inline', COPY_THE_CODE_URI . 'assets/css/copy-inline.css', [], COPY_THE_CODE_VER );
62 - wp_enqueue_script( 'ctc-copy-inline', COPY_THE_CODE_URI . 'assets/js/copy-inline.js', [ 'jquery' ], COPY_THE_CODE_VER, true );
58 + $atts = shortcode_atts(
59 + array(
60 + 'target' => '',
61 + 'text' => 'Copy',
62 + 'copied-text' => 'Copied!',
63 + 'tag' => 'a',
64 + 'class' => '',
65 + 'copy-as' => 'text',
66 + 'content' => $content,
67 + ),
68 + $atts
69 + );
70 +
71 + return '<' . esc_html( $atts['tag'] ) . ' class="copy-the-code-shortcode ' . esc_attr( $atts['class'] ) . '" data-target="' . esc_attr( $atts['target'] ) . '" data-button-text="' . esc_attr( $atts['text'] ) . '" data-button-copy-text="' . esc_attr( $atts['copied-text'] ) . '" data-content="' . esc_attr( $atts['content'] ) . '" data-copy-as="' . esc_attr( $atts['copy-as'] ) . '">' . esc_html( $atts['text'] ) . '</' . esc_html( $atts['tag'] ) . '>';
63 72 }
64 73
65 74 /**
66 - * Copy inline markup
75 + * Register menus
67 76 *
68 - * @since 3.1.0
77 + * @since 2.2.0
78 + * @return void
79 + */
80 + function init_admin_settings() {
81 + if ( current_user_can( 'edit_posts' ) ) {
82 + add_action( 'admin_menu', array( $this, 'register' ) );
83 + }
84 + }
85 +
86 + /**
87 + * Registers the add new portfolio form admin menu for adding portfolios.
69 88 *
70 - * @param array $atts Shortcode parameters.
71 - * @param mixed $content Shortcode content.
89 + * @since 2.2.0
72 90 *
73 - * @return mixed
91 + * @return void
74 92 */
75 - public function copy_inline_markup( $atts = [], $content = '' ) {
76 - $atts = shortcode_atts(
77 - [
78 - 'text' => '',
79 - 'display' => '',
80 - 'hidden' => '',
81 - 'style' => '',
82 - 'tooltip' => esc_html__( 'Copied', 'copy-the-code' ),
83 - ],
84 - $atts
93 + public function register() {
94 + add_submenu_page(
95 + 'options-general.php',
96 + __( 'Add New', 'copy-the-code' ),
97 + __( ' → Add New', 'copy-the-code' ),
98 + 'manage_options',
99 + 'copy-to-clipboard-add-new',
100 + array( Copy_The_Code_Page::get_instance(), 'add_new_page' )
85 101 );
86 -
87 - $text = $atts['text'] ? $atts['text'] : $content;
88 - $display = $atts['display'] ? $atts['display'] : $atts['text'];
89 - $style = $atts['style'] ? 'ctc-inline-style-' . $atts['style'] : '';
90 - $hidden = 'yes' === $atts['hidden'] ? 'ctc-inline-hidden' : '';
91 - $tooltip = esc_html__( 'Copied', 'copy-the-code' );
92 -
93 - ob_start();
94 - ?>
95 - <span class="ctc-inline-copy <?php echo esc_attr( $style ); ?>" aria-label="<?php echo esc_attr( $tooltip ); ?>">
96 - <span class="ctc-inline-copy-text <?php echo esc_attr( $hidden ); ?>"><?php echo esc_html( $display ); ?></span>
97 - <textarea style="display: none;" class="ctc-inline-copy-textarea" readonly="readonly"><?php echo esc_html( $text ); ?></textarea>
98 - <span class="ctc-inline-copy-icon" role="button" aria-label="<?php echo esc_attr( $tooltip ); ?>">
99 - <?php echo Helpers::get_svg_copy_icon(); ?>
100 - <?php echo Helpers::get_svg_checked_icon(); ?>
101 - </span>
102 - </span>
103 - <?php
104 - return ob_get_clean();
102 + add_submenu_page(
103 + 'options-general.php',
104 + __( 'Shortcode Info', 'copy-the-code' ),
105 + __( ' → Shortcode Info', 'copy-the-code' ),
106 + 'manage_options',
107 + 'shortcode',
108 + array( $this, 'shortcode_page_markup' )
109 + );
105 110 }
106 111
107 112 /**
108 - * Shortcode markup
113 + * Shortcode Page Markup
109 114 *
110 115 * @since 2.2.0
111 - * @param array $atts Shortcode parameters.
112 - * @param mixed $content Shortcode content.
113 - * @return mixed
114 116 */
115 - public function shortcode_markup( $atts = [], $content = '' ) {
116 - $atts = apply_filters(
117 - 'copy_the_code_shortcode_atts',
118 - shortcode_atts(
119 - [
120 - 'target' => '',
121 - 'title' => __( 'Copy to Clipboard', 'copy-the-code' ),
122 - 'text' => $content,
123 - 'copied-text' => 'Copied to Clipboard',
124 - 'tag' => 'span',
125 - 'class' => '',
126 - 'copy-as' => 'text',
127 - 'content' => $content,
128 - 'link' => isset( $atts['link'] ) ? $atts['link'] : '',
129 - 'style' => '',
130 - 'color' => '',
131 - 'icon-color' => '',
132 - ],
133 - $atts
134 - )
135 - );
117 + public function shortcode_page_markup() {
118 + ?>
119 + <h1>Shortcode</h1>
136 120
137 - $color = $atts['color'];
138 - $display_content = wp_kses_post( $atts['text'] );
139 - if ( 'icon' === $atts['style'] ) {
140 - $icon_color = ! empty( $atts['icon-color'] ) ? $atts['icon-color'] : '#b5b5b5';
121 + <p>Just use the shortcode as:</p>
141 122
142 - $display_content = '<svg style="fill: ' . esc_attr( $icon_color ) . '" viewBox="-21 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="m186.667969 416c-49.984375 0-90.667969-40.683594-90.667969-90.667969v-218.664062h-37.332031c-32.363281 0-58.667969 26.300781-58.667969 58.664062v288c0 32.363281 26.304688 58.667969 58.667969 58.667969h266.664062c32.363281 0 58.667969-26.304688 58.667969-58.667969v-37.332031zm0 0"></path><path d="m469.332031 58.667969c0-32.40625-26.261719-58.667969-58.664062-58.667969h-224c-32.40625 0-58.667969 26.261719-58.667969 58.667969v266.664062c0 32.40625 26.261719 58.667969 58.667969 58.667969h224c32.402343 0 58.664062-26.261719 58.664062-58.667969zm0 0"></path></svg>';
143 - }
123 + <p><code>[copy content="100OFF"]</code></p>
144 124
145 - return '<' . esc_html( $atts['tag'] ) . ' title="' . esc_attr( $atts['title'] ) . '" class="copy-the-code-shortcode ' . esc_attr( $atts['class'] ) . '" data-target="' . esc_attr( $atts['target'] ) . '" data-button-text="' . esc_attr( $atts['text'] ) . '" data-button-copy-text="' . esc_attr( $atts['copied-text'] ) . '" data-content="' . esc_attr( wp_strip_all_tags( $atts['content'] ) ) . '" data-copy-as="' . esc_attr( $atts['copy-as'] ) . '" data-link="' . esc_attr( $atts['link'] ) . '" style="color: ' . esc_attr( $color ) . '" >' . $display_content . '</' . esc_html( $atts['tag'] ) . '>';
125 + <p>It dispaly the "Copy" text on frontend and on click on it the string "100OFF" copied to clipboard.
126 +
127 + <p>We can change the "Copy" text with any other text as <code>text="Click Me"</code>.</p>
128 + <p>E.g. <code>[copy text="Click Me" content="100OFF"]</code></p>
129 + <p>Here we can see the text "Click Me" and on click on it the text "100OFF" copied to the clipboard.</p>
130 +
131 + <p>See short video:</p>
132 +
133 + <iframe title="copy-content-with-shortcode-mp4" width="640" height="340" src="https://videopress.com/embed/Mo6nR60h?preloadContent=metadata&amp;hd=1" frameborder="0" allowfullscreen=""></iframe>
134 +
135 + <p>That’s it.</p>
136 +
137 + <p>Read more at <a href='https://maheshwaghmare.com/doc/copy-anything-to-clipboard/#shortcode' target="_blank">copy with shortcode</a></p>
138 + <?php
146 139 }
147 140
148 141 }
149 142