PluginProbe
Simple Divi Shortcode / 1.2
Simple Divi Shortcode v1.2
trunk 1.0 1.2 1.2.1
simple-divi-shortcode / simple_divi_shortcode.php

simple_divi_shortcode.php in Simple Divi Shortcode 1.2, at simple_divi_shortcode.php

112 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 Plugin Name: Simple Divi Shortcode
5 Plugin URI: https://www.creaweb2b.com/plugins/
6 Description: Plugin creating a shortcode allowing you to embed any Divi Library item within php template or within another Divi module/section content
7 Author: Fabrice ESQUIROL - Creaweb2b
8 Version: 1.2
9 Author URI: https://www.creaweb2b.com
10 License: GPL2
11
12 Copyright 2017 Fabrice ESQUIROL (email : admin@creaweb2b.com)
13
14 This program is free software; you can redistribute it and/or modify it under the terms of the GNU
15 General Public License as published by the Free Software Foundation; either version 2 of the License,
16 or any later version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
19 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 //Exit if direct access
23 defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
24
25 add_action( 'load-post.php', 'cw_post_meta_boxes_setup' );
26 add_action( 'load-post-new.php', 'cw_post_meta_boxes_setup' );
27
28 function cw_post_meta_boxes_setup() {
29 add_action( 'add_meta_boxes', 'cw_add_post_meta_boxes' );
30 }
31
32 function cw_add_post_meta_boxes() {
33 add_meta_box('cw-post-code',esc_html__( 'Shortcode'),'cw_post_code_meta_box','et_pb_layout','side','default');
34 }
35
36 function cw_post_code_meta_box( $object, $box ) {
37 echo '<p>Click on the shortcode to copy it to clipboard and paste it where you want the content of this layout to be inserted</p>';
38 echo '<h4 class="show-shortcode">[showmodule id="' . $object->ID . '"]</h4>';
39 }
40
41 function cw_shortcode_add_column( $columns ) {
42 $new_columns = array(
43 'shortcode' => __( 'Shortcode')
44 );
45 $filtered_columns = array_merge( $columns, $new_columns );
46 return $filtered_columns;
47 }
48 add_filter('manage_et_pb_layout_posts_columns' , 'cw_shortcode_add_column');
49
50 function cw_shortcode_custom_column_content( $column ) {
51 global $post;
52 switch ( $column ) {
53 case 'shortcode' :
54 $shortcode = '[showmodule id="' . $post->ID .'"]';
55 echo '<h4 class="show-shortcode">'.$shortcode.'</h4>';
56 break;
57 }
58 }
59 add_action( 'manage_et_pb_layout_posts_custom_column', 'cw_shortcode_custom_column_content' );
60 // Function to show the module
61 function showmodule_shortcode($atts) {
62 $atts = shortcode_atts(array('id' => ''), $atts);
63 return do_shortcode('[et_pb_section global_module="'.$atts['id'].'"][/et_pb_section]');
64 }
65 add_shortcode('showmodule', 'showmodule_shortcode');
66
67 function add_my_script() {
68 $screen = get_current_screen();
69 if ($screen->id!='edit-et_pb_layout' and $screen->id!='et_pb_layout') {
70 return;
71 }
72 // We inject our code only on the Divi library :)...
73 $local = substr( get_locale(), 0, 2 );
74 switch ($local) {
75 case 'en':
76 $alert = 'shortcode copied';
77 break;
78 case 'it':
79 $alert = 'shortcode copiato';
80 break;
81 case 'es':
82 $alert = 'shortcode copiado';
83 break;
84 case 'de':
85 $alert = 'shortcode kopiert';
86 break;
87 default:
88 $alert = 'shortcode copiƩ';
89 }
90 ?>
91 <style type="text/css">
92 h4.show-shortcode:hover {
93 cursor:copy;
94 background-color:rgba(0,220,255,0.2);
95 }
96 </style>
97 <script language="javascript">
98 jQuery( ".show-shortcode" ).click(function(event ) {
99 var shortcode = jQuery(this).text();
100 var aux = document.createElement("input");
101 aux.setAttribute("value", shortcode);
102 document.body.appendChild(aux);
103 aux.select();
104 document.execCommand("copy");
105 document.body.removeChild(aux);
106 alert("<?php echo $alert; ?> "+ shortcode);
107 });
108 </script>
109 <?php }
110 add_action( 'admin_footer', 'add_my_script', 11 );
111
112 ?>