mirror of
https://github.com/4suredev/Avada-Custom-Visual-Builder-Button.git
synced 2025-11-25 07:15:46 +08:00
Compare commits
No commits in common. "main" and "v1.0.0-alpha" have entirely different histories.
main
...
v1.0.0-alp
4 changed files with 25 additions and 189 deletions
23
README.md
23
README.md
|
|
@ -1,22 +1 @@
|
||||||
# Avada Custom Visual Builder Button
|
# Avada-Custom-Visual-Builder-Button
|
||||||
|
|
||||||
<p>Adds a custom Avada button shortcode to the classic editor with simple parameters.</p>
|
|
||||||
<img src="https://i.imgur.com/qhV654f.png">
|
|
||||||
|
|
||||||
<table class="table-borderless" style="text-align: left;">
|
|
||||||
<tbody>
|
|
||||||
<tr><th style="padding: 0 20px 0 0;">Parameters</th><th style="padding: 0 20px 0 0;">Description</th></tr>
|
|
||||||
<tr><td style="padding: 0 20px 0 0;">link</td><td style="padding: 0 20px 0 0;">url (required)</td></tr>
|
|
||||||
<tr><td style="padding: 0 20px 0 0;">text</td><td style="padding: 0 20px 0 0;">label (required)</td></tr>
|
|
||||||
<tr><td style="padding: 0 20px 0 0;">target</td><td style="padding: 0 20px 0 0;">leave blank / newtab / lightbox</td></tr>
|
|
||||||
<tr><td style="padding: 0 20px 0 0;">icon</td><td style="padding: 0 20px 0 0;">true / false</td></tr>
|
|
||||||
<tr><td style="padding: 0 20px 0 0;">icon_class</td><td style="padding: 0 20px 0 0;">font awesome class (optional)</td></tr>
|
|
||||||
<tr><td style="padding: 0 20px 0 0;">icon_position</td><td style="padding: 0 20px 0 0;">left / right</td></tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<p>Basics:</p>
|
|
||||||
<ul>
|
|
||||||
<li>[button link="https://google.com/" text="Google"]</li>
|
|
||||||
<li>[button link="https://youtube.com/" text="Youtube" target="newtab"]</li>
|
|
||||||
</ul>
|
|
||||||
|
|
@ -1,29 +1,21 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Plugin Name: 4sure - Avada Button Shortcode
|
* Plugin Name: Avada Button Shortcode
|
||||||
* Plugin URI: https://4sure.com.au
|
* Plugin URI: https://4sure.com.au
|
||||||
* Description: Adds Avada button shortcodes to the classic editor
|
* Description: Adds Avada button shortcodes to the classic editor
|
||||||
* Version: 1.0.8
|
* Version: 2.0.0
|
||||||
* Author: 4sure
|
* Author: 4sure
|
||||||
* Requires PHP: 7.2
|
* Requires PHP: 7.2
|
||||||
* Requires at least: 5.8
|
* Requires at least: 5.8
|
||||||
* Author URI: https://4sure.com.au
|
* Author URI: https://4sure.com.au
|
||||||
*/
|
*/
|
||||||
define('VBB_PLUGIN_PATH', plugin_dir_url( __FILE__ ));
|
define('VBB_PLUGIN_PATH', home_url().'/wp-content/plugins/custom-visual-builder-button/');
|
||||||
include_once( plugin_dir_path( __FILE__ ) . 'updater.php');
|
|
||||||
$updater = new Custom_visual_builder_button_updater( __FILE__ ); // instantiate our class
|
|
||||||
$updater->set_username( '4suredev' ); // set username
|
|
||||||
$updater->set_repository( 'Avada-Custom-Visual-Builder-Button' ); // set repo
|
|
||||||
$updater->initialize(); // initialize the updater
|
|
||||||
if( ! class_exists( 'Custom_visual_builder_button_updater' ) ){
|
|
||||||
include_once( plugin_dir_path( __FILE__ ) . 'updater.php' );
|
|
||||||
}
|
|
||||||
add_action( 'wp_enqueue_scripts', 'vbb_enqueue_styles' );
|
add_action( 'wp_enqueue_scripts', 'vbb_enqueue_styles' );
|
||||||
function vbb_enqueue_styles(){
|
function vbb_enqueue_styles(){
|
||||||
wp_enqueue_style( 'vbb-widget-styles', VBB_PLUGIN_PATH.'css/frontend-button-widget-styles.css' );
|
wp_enqueue_style( 'vbb-widget-styles', VBB_PLUGIN_PATH.'css/frontend-button-widget-styles.css' );
|
||||||
}
|
}
|
||||||
add_shortcode('button', 'vbb_custom_visual_builder_button');
|
add_shortcode('button', 'custom_visual_builder_button');
|
||||||
function vbb_custom_visual_builder_button($atts = array()){
|
function custom_visual_builder_button($atts = array()){
|
||||||
$args = shortcode_atts(
|
$args = shortcode_atts(
|
||||||
array(
|
array(
|
||||||
'target' => '',
|
'target' => '',
|
||||||
|
|
@ -52,7 +44,7 @@ function vbb_custom_visual_builder_button($atts = array()){
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
//add media button to visual builder
|
//add media button to visual builder
|
||||||
function vbb_add_shortcodes_media_button() {
|
function add_shortcodes_media_button() {
|
||||||
$the_page = get_current_screen();
|
$the_page = get_current_screen();
|
||||||
$current_page = $the_page->post_type;
|
$current_page = $the_page->post_type;
|
||||||
$allowed = array(
|
$allowed = array(
|
||||||
|
|
@ -61,11 +53,10 @@ function vbb_add_shortcodes_media_button() {
|
||||||
'product',
|
'product',
|
||||||
'tribe_events'
|
'tribe_events'
|
||||||
);
|
);
|
||||||
if (in_array($current_page, $allowed, false) || $the_page->base == 'toplevel_page_access-manager' || $the_page->base == 'post' || $the_page->base == 'toplevel_page_acc-default-settings'){
|
if (in_array($current_page, $allowed, false) || $the_page->base == 'toplevel_page_access-manager' || $the_page->base == 'post'){
|
||||||
printf( '<a href="%s" class="button generate-button-shortcode">' . '<span class="wp-media-buttons-icon dashicons dashicons-shortcode"></span> %s' . '</a>', '#', __( 'Generate Button', 'textdomain' ) );
|
printf( '<a href="%s" class="button generate-button-shortcode">' . '<span class="wp-media-buttons-icon dashicons dashicons-shortcode"></span> %s' . '</a>', '#', __( 'Generate Button', 'textdomain' ) );
|
||||||
}
|
}
|
||||||
$current_screen = get_current_screen()->base;
|
if(get_current_screen()->base == 'toplevel_page_access-manager'){
|
||||||
if ($current_screen == 'toplevel_page_access-manager' || $current_screen == 'toplevel_page_acc-default-settings'){
|
|
||||||
echo '<script type="text/javascript">
|
echo '<script type="text/javascript">
|
||||||
jQuery(document).ready(function($){
|
jQuery(document).ready(function($){
|
||||||
$(".generate-button-shortcode").click(function(e){
|
$(".generate-button-shortcode").click(function(e){
|
||||||
|
|
@ -77,20 +68,19 @@ function vbb_add_shortcodes_media_button() {
|
||||||
</script>';
|
</script>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_action( 'media_buttons', 'vbb_add_shortcodes_media_button');
|
add_action( 'media_buttons', 'add_shortcodes_media_button');
|
||||||
//Button shortcode admin bar widget
|
//Button shortcode admin bar widget
|
||||||
add_action('admin_enqueue_scripts', 'vbb_admin_scripts_enqueue');
|
add_action('admin_enqueue_scripts', 'my_enqueue');
|
||||||
function vbb_admin_scripts_enqueue($hook) {
|
function my_enqueue($hook) {
|
||||||
// Only add to the edit post/page admin page.
|
// Only add to the edit post/page admin page.
|
||||||
if ('post.php' == $hook || 'post-new.php' == $hook || 'toplevel_page_access-manager' == $hook || 'toplevel_page_acc-default-settings' == $hook) {
|
if ('post.php' == $hook || 'post-new.php' == $hook || 'toplevel_page_access-manager' == $hook) {
|
||||||
wp_enqueue_script('admin_custom_script', VBB_PLUGIN_PATH.'js/custom-admin-scripts.js', array('jquery-ui-dialog'));
|
wp_enqueue_script('admin_custom_script', VBB_PLUGIN_PATH.'js/custom-admin-scripts.js');
|
||||||
wp_enqueue_script('jquery-ui', 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js');
|
wp_enqueue_script('jquery-ui', 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js');
|
||||||
}else{return;}
|
}else{return;}
|
||||||
}
|
}
|
||||||
add_action( 'edit_form_after_editor', 'vbb_render_button_shortcode_dialog' );
|
add_action( 'edit_form_after_editor', 'render_button_shortcode_dialog' );
|
||||||
add_action( 'toplevel_page_access-manager', 'vbb_render_button_shortcode_dialog', 20 );
|
add_action( 'toplevel_page_access-manager', 'render_button_shortcode_dialog', 20 );
|
||||||
add_action( 'toplevel_page_acc-default-settings', 'vbb_render_button_shortcode_dialog', 20 );
|
function render_button_shortcode_dialog( $post ){
|
||||||
function vbb_render_button_shortcode_dialog( $post ){
|
|
||||||
echo '
|
echo '
|
||||||
<style>
|
<style>
|
||||||
#button-shortcode-dialog{display: none;}
|
#button-shortcode-dialog{display: none;}
|
||||||
|
|
@ -196,8 +186,8 @@ function vbb_render_button_shortcode_dialog( $post ){
|
||||||
<div id="page-mask"></div>
|
<div id="page-mask"></div>
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
add_action('admin_bar_menu', 'vbb_add_toolbar_items', 100);
|
add_action('admin_bar_menu', 'add_toolbar_items', 100);
|
||||||
function vbb_add_toolbar_items($admin_bar){
|
function add_toolbar_items($admin_bar){
|
||||||
$admin_bar->add_menu( array(
|
$admin_bar->add_menu( array(
|
||||||
'id' => 'generate-button-shortcode',
|
'id' => 'generate-button-shortcode',
|
||||||
'title' => 'Generate Button',
|
'title' => 'Generate Button',
|
||||||
|
|
@ -207,13 +197,12 @@ function vbb_add_toolbar_items($admin_bar){
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
add_action( 'admin_head', 'vbb_hide_button_widget' );
|
add_action( 'admin_head', 'hide_button_widget' );
|
||||||
function vbb_hide_button_widget() {
|
function hide_button_widget() {
|
||||||
echo '<style>
|
echo '<style>
|
||||||
#wp-admin-bar-generate-button-shortcode{display: none;}
|
#wp-admin-bar-generate-button-shortcode{display: none;}
|
||||||
body.post-php #wp-admin-bar-generate-button-shortcode,
|
body.post-php #wp-admin-bar-generate-button-shortcode,
|
||||||
body.post-new-php #wp-admin-bar-generate-button-shortcode,
|
body.post-new-php #wp-admin-bar-generate-button-shortcode,
|
||||||
body.toplevel_page_access-manager #wp-admin-bar-generate-button-shortcode,
|
body.toplevel_page_access-manager #wp-admin-bar-generate-button-shortcode{display: list-item;}
|
||||||
body.toplevel_page_acc-default-settings #wp-admin-bar-generate-button-shortcode{display: list-item;}
|
|
||||||
</style>';
|
</style>';
|
||||||
}
|
}
|
||||||
|
|
@ -14,22 +14,13 @@ jQuery(document).ready(function($){
|
||||||
},
|
},
|
||||||
minWidth: 480
|
minWidth: 480
|
||||||
});
|
});
|
||||||
if(typeof acf != 'undefined'){
|
acf.addAction('load', function(){
|
||||||
acf.addAction('load', function(){
|
|
||||||
$(document).on("click", ".generate-button-shortcode", function(e){
|
|
||||||
e.preventDefault();
|
|
||||||
$("#button-shortcode-dialog").dialog("open");
|
|
||||||
$("#page-mask").css({"opacity":1, "pointer-events": "auto"});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
$(document).on("click", ".generate-button-shortcode", function(e){
|
$(document).on("click", ".generate-button-shortcode", function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$("#button-shortcode-dialog").dialog("open");
|
$("#button-shortcode-dialog").dialog("open");
|
||||||
$("#page-mask").css({"opacity":1, "pointer-events": "auto"});
|
$("#page-mask").css({"opacity":1, "pointer-events": "auto"});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
$('.generate-button-shortcode').click(function(e){
|
$('.generate-button-shortcode').click(function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$("#button-shortcode-dialog").dialog("open");
|
$("#button-shortcode-dialog").dialog("open");
|
||||||
|
|
|
||||||
125
updater.php
125
updater.php
|
|
@ -4,11 +4,7 @@ class Custom_visual_builder_button_updater {
|
||||||
protected $plugin;
|
protected $plugin;
|
||||||
protected $basename;
|
protected $basename;
|
||||||
protected $active;
|
protected $active;
|
||||||
private $username;
|
|
||||||
private $repository;
|
|
||||||
private $authorize_token;
|
|
||||||
private $github_response;
|
|
||||||
|
|
||||||
public function __construct( $file ) {
|
public function __construct( $file ) {
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
add_action( 'admin_init', array( $this, 'set_plugin_properties' ) );
|
add_action( 'admin_init', array( $this, 'set_plugin_properties' ) );
|
||||||
|
|
@ -20,123 +16,4 @@ class Custom_visual_builder_button_updater {
|
||||||
$this->basename = plugin_basename( $this->file );
|
$this->basename = plugin_basename( $this->file );
|
||||||
$this->active = is_plugin_active( $this->basename );
|
$this->active = is_plugin_active( $this->basename );
|
||||||
}
|
}
|
||||||
public function set_username( $username ) {
|
|
||||||
$this->username = $username;
|
|
||||||
}
|
|
||||||
public function set_repository( $repository ) {
|
|
||||||
$this->repository = $repository;
|
|
||||||
}
|
|
||||||
public function authorize( $token ) {
|
|
||||||
$this->authorize_token = $token;
|
|
||||||
}
|
|
||||||
private function get_repository_info() {
|
|
||||||
if ( is_null( $this->github_response ) ) { // Do we have a response?
|
|
||||||
$request_uri = sprintf( 'https://api.github.com/repos/%s/%s/releases', $this->username, $this->repository ); // Build URI
|
|
||||||
if( $this->authorize_token ) { // Is there an access token?
|
|
||||||
$request_uri = add_query_arg( 'access_token', $this->authorize_to , $request_uri ); // Append it
|
|
||||||
}
|
|
||||||
$response = json_decode( wp_remote_retrieve_body( wp_remote_get( $request_uri ) ), true ); // Get JSON and parse it
|
|
||||||
if( is_array( $response ) ) { // If it is an array
|
|
||||||
$response = current( $response ); // Get the first item
|
|
||||||
}
|
|
||||||
if( $this->authorize_token ) { // Is there an access token?
|
|
||||||
$response['zipball_url'] = add_query_arg( 'access_token', $this->authorize_token, $response['zipball_url'] ); // Update our zip url with token
|
|
||||||
}
|
|
||||||
$this->github_response = $response; // Set it to our property
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function initialize() {
|
|
||||||
/* Adding a filter to the transient. */
|
|
||||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'modify_transient' ), 10, 1 );
|
|
||||||
add_filter( 'plugins_api', array( $this, 'plugin_popup' ), 10, 3);
|
|
||||||
add_filter( 'upgrader_post_install', array( $this, 'after_install' ), 10, 3 );
|
|
||||||
// Add Authorization Token to download_package
|
|
||||||
add_filter( 'upgrader_pre_download',
|
|
||||||
function() {
|
|
||||||
add_filter( 'http_request_args', [ $this, 'download_package' ], 15, 2 );
|
|
||||||
return false; // upgrader_pre_download filter default return value.
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
public function modify_transient( $transient ) {
|
|
||||||
if( property_exists( $transient, 'checked') ) { // Check if transient has a checked property
|
|
||||||
if( $checked = $transient->checked ) { // Did WordPress check for updates?
|
|
||||||
$this->get_repository_info(); // Get the repo info
|
|
||||||
if( is_array($this->github_response) && !empty($this->github_response['tag_name']) && !empty($checked[$this->basename]) ) { // Check response
|
|
||||||
$out_of_date = version_compare( $this->github_response['tag_name'], $checked[$this->basename], 'gt' ); // Check if we're out of date
|
|
||||||
} else {
|
|
||||||
$out_of_date = false;
|
|
||||||
}
|
|
||||||
if( $out_of_date ) {
|
|
||||||
$new_files = $this->github_response['zipball_url']; // Get the ZIP
|
|
||||||
$slug = current( explode('/', $this->basename ) ); // Create valid slug
|
|
||||||
$plugin = array( // setup our plugin info
|
|
||||||
'url' => $this->plugin["PluginURI"],
|
|
||||||
'slug' => $slug,
|
|
||||||
'package' => $new_files,
|
|
||||||
'new_version' => $this->github_response['tag_name']
|
|
||||||
);
|
|
||||||
$transient->response[ $this->basename ] = (object) $plugin; // Return it in response
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $transient; // Return filtered transient
|
|
||||||
}
|
|
||||||
public function plugin_popup( $result, $action, $args ) {
|
|
||||||
if( ! empty( $args->slug ) ) { // If there is a slug
|
|
||||||
|
|
||||||
if( $args->slug == current( explode( '/' , $this->basename ) ) ) { // And it's our slug
|
|
||||||
|
|
||||||
$this->get_repository_info(); // Get our repo info
|
|
||||||
|
|
||||||
// Set it to an array
|
|
||||||
$plugin = array(
|
|
||||||
'name' => $this->plugin["Name"],
|
|
||||||
'slug' => $this->basename,
|
|
||||||
'version' => $this->github_response['tag_name'],
|
|
||||||
'author' => $this->plugin["AuthorName"],
|
|
||||||
'author_profile' => $this->plugin["AuthorURI"],
|
|
||||||
'last_updated' => $this->github_response['published_at'],
|
|
||||||
'homepage' => $this->plugin["PluginURI"],
|
|
||||||
'short_description' => $this->plugin["Description"],
|
|
||||||
'sections' => array(
|
|
||||||
'Description' => $this->plugin["Description"],
|
|
||||||
'Updates' => $this->github_response['body'],
|
|
||||||
),
|
|
||||||
'download_link' => $this->github_response['zipball_url']
|
|
||||||
);
|
|
||||||
|
|
||||||
return (object) $plugin; // Return the data
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return $result; // Otherwise return default
|
|
||||||
}
|
|
||||||
|
|
||||||
public function download_package( $args, $url ) {
|
|
||||||
|
|
||||||
if ( null !== $args['filename'] ) {
|
|
||||||
if( $this->authorize_token ) {
|
|
||||||
$args = array_merge( $args, array( "headers" => array( "Authorization" => "token {$this->authorize_token}" ) ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_filter( 'http_request_args', [ $this, 'download_package' ] );
|
|
||||||
|
|
||||||
return $args;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function after_install( $response, $hook_extra, $result ) {
|
|
||||||
global $wp_filesystem; // Get global FS object
|
|
||||||
|
|
||||||
$install_directory = plugin_dir_path( $this->file ); // Our plugin directory
|
|
||||||
$wp_filesystem->move( $result['destination'], $install_directory ); // Move files to the plugin dir
|
|
||||||
$result['destination'] = $install_directory; // Set the destination for the rest of the stack
|
|
||||||
|
|
||||||
if ( $this->active ) { // If it was active
|
|
||||||
activate_plugin( $this->basename ); // Reactivate
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue