Last active
March 15, 2022 19:34
-
-
Save ttodua/1fb2530e7b3de3cc8a23bbdada2e4730 to your computer and use it in GitHub Desktop.
example puvox-library based plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: My Example plugin | |
* Description: Somewhat plugin description here | |
* Text Domain: my-plugin-textdomain-slug | |
* Domain Path: /languages | |
* Version: 1.234 | |
* WordPress URI: https://wordpress.org/plugins/this-plugin-name/ | |
* Plugin URI: https://example.com/wordpress/this-plugin | |
* Contributors: wpOrgUsername | |
* Author: MyCompany | |
* Author URI: https://example.com/ | |
* License: GPL-3.0 | |
* License URI: https://www.gnu.org/licenses/gpl-3.0.html | |
*/ | |
namespace ExampleMyName | |
{ | |
if (!defined('ABSPATH')) exit; | |
include_once(__DIR__.'/library_wp.php'); | |
class PluginClass extends \Puvox\wp_plugin | |
{ | |
public function declare_settings() | |
{ | |
$this->set_initial_static_options ([ | |
'has_pro_version' => 0, | |
'show_opts' => true, | |
'show_rating_message' => true, | |
'show_donation_footer' => true, | |
'show_donation_popup' => true, | |
'menu_pages' => [ | |
'first' =>[ | |
'title' => 'My Button Title', | |
'default_managed' => 'network', // network | singlesite | |
'required_role' => 'install_plugins', | |
'level' => 'mainmenu', // mianmenu | submenu | |
'icon' => $this->helpers->baseURL.'/icon.png" style="width:30px;', | |
'page_title' => 'Welcome to My Plugin Options page', | |
'tabs' => ['mytab1','mytab2'], | |
], | |
] | |
]); | |
// ############ your custom options to be used throughout plugin ########### | |
$this->set_initial_user_options ([ | |
'whatever_option_1' => 123, // can be obtained: $this->opts['whatever_option_1'] | |
'whatever_option_2' => true, | |
]); | |
// ############ if you want to add some shortcode-descriptions ########### | |
$this->shortcodes = [ | |
'My_Shortcode_Name' => [ | |
'description'=>__('Output the breadcrumbs in any place.', 'audio-video-download-buttons-for-youtube'), | |
'atts'=>[ | |
['id', '', __('Youtube video ID [11 chars] (link is also accepted)', 'audio-video-download-buttons-for-youtube') ], | |
['text', 'Download', __('Text for button', 'audio-video-download-buttons-for-youtube') ], | |
['minutes', '15', __('Expire download links in X minutes (So, after X minutes is gone from initial page load, user will need to refresh page again to get fresh links from download-button. This is good to avoid abuse of download by bots or whatever)', 'audio-video-download-buttons-for-youtube') ], | |
] | |
] | |
]; | |
// ############ if you want to add some hook-descriptions ########### | |
$this->hooks_examples = [ | |
"youtube_download_button_shortcode" => [ | |
'description' =>__('Modify output of the shortcode', 'audio-video-download-buttons-for-youtube'), | |
'parameters' =>['result','atts'], | |
'type' =>'filter' | |
], | |
]; | |
} | |
public function __construct_my() | |
{ | |
$this->helpers->error_to_mailaddress = '[email protected]'; // send errors to email | |
$this->helpers->enable_write_logs = false; // enable logs writing | |
$this->helpers->PASSWORD_FOR_SITE = ''; // | |
$this->helpers->google_analytics_ID = ''; // | |
$this->helpers->google_tag_manager_ID = ''; // | |
$this->helpers->top_ge_ID = ''; // | |
$this->helpers->google_firebase_ID = ''; // https://console.firebase.google.com/project/my-test-proj-fc1cb/overview | |
$this->helpers->auth_expiration_hours = 444; // | |
$this->helpers->posts_per_page = 20; // | |
$this->helpers->navmenu_search_items = 20; // | |
$this->helpers->shortcodes = []; // | |
$this->helpers->extend_shortcodes = true; // activates shortcodes: image, video, link, iframe, @, script, video, list_subpages , | |
// i.e. [list type="categories" id="32" depth=0 exclude="4,28"] | |
// i.e. [list type="pages" id="32" depth=0 exclude="4,28"] (or id="this") | |
// i.e. [list type="menu" id="32"] | |
$this->helpers->disable_update = true; // disable update for current plugin | |
$this->add_my_site_options(['smth'=>'value']); // activates extra options page | |
//$this->site_favicon = 'https://i.imgur.com/faqQ49G.png'; | |
$this->helpers->load_scripts_override = | |
[ | |
'jquery' => ['screen'=>['admin'=>false, 'public'=>false], 'urls'=>[ | |
'js' => '//cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js' | |
]], | |
'jquery-ui' => ['screen'=>['admin'=>false, 'public'=>false], 'urls'=>[ | |
'css' =>'//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css', | |
'js' => '//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js', | |
]], | |
'datatables' => ['screen'=>['admin'=>false, 'public'=>false], 'urls'=>[ | |
'css'=> '//cdn.datatables.net/1.11.1/css/jquery.dataTables.min.css', | |
'js' => '//cdn.datatables.net/1.11.1/js/jquery.dataTables.min.js', | |
]], | |
'bootstrap' => ['screen'=>['admin'=>false, 'public'=>false], 'urls'=>[ | |
'css'=> '//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css', | |
'js' => '//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js', | |
]], | |
'my_javascript' => ['screen'=>['admin'=>false, 'public'=>false], 'urls'=>[ | |
'js' => $this->helpers->baseURL.'/my-scripts.js', | |
]], | |
'my_style' => ['screen'=>['admin'=>false, 'public'=>false], 'urls'=>[ | |
'css' => $this->helpers->baseURL.'/my-styles.css', | |
]], | |
'my-js-script' => ['screen'=>['admin'=>false, 'public'=>false], 'urls'=>[ | |
'js' => $this->helpers->baseURL .'my_js_scripts.js' | |
]], | |
]; | |
} | |
// ===================================================================================== // | |
// ===================================================================================== // | |
// ================================================================= // | |
// ============================ OPTIONS ============================ // | |
// ================================================================= // | |
public function opts_page_output() { $this->settings_page_part("start"); ?> | |
<style> | |
p.submit { text-align:center; } | |
.settingsTitle{display:none;} | |
.myplugin {padding:10px;} | |
zzz#mainsubmit-button{display:none;} | |
.plugin-title{text-align:center;} | |
#icon_or_phrase{width:100%;} | |
</style> | |
<form class="mainForm" method="post" action=""> | |
<?php if ($this->active_tab=="Options") { ?> | |
<?php | |
//if form updated | |
if( $this->checkSubmission( 'nonceName998423', 'nonceActionk44' ) ) | |
{ | |
$this->opts['are_you_well']= !empty( $_POST[ $this->plugin_slug ]['are_you_well'] ); | |
$this->opts['years_old'] = sanitize_text_field( $_POST[ $this->plugin_slug ]['years_old'] ); | |
$this->update_opts(); | |
} | |
?> | |
<table class="form-table"> <tbody> | |
<tr> | |
<th> | |
<?php _e('Test checkbox');?> | |
</th> | |
<td> | |
<?php _e('No');?><input type="radio" name="<?php echo $this->plugin_slug;?>[are_you_well]" value="" <?php checked( !$this->opts['are_you_well'] );?> /> | |
<?php _e('Yes');?><input type="radio" name="<?php echo $this->plugin_slug;?>[are_you_well]" value="yes" <?php checked($this->opts['are_you_well']);?> /> | |
</td> | |
</tr> | |
<tr> | |
<th> | |
<?php _e('How input-text');?> | |
</th> | |
<td> | |
<input type="text" name="<?php echo $this->plugin_slug;?>[years_old]" value="<?php echo $this->opts['years_old'];?>" placeholder="your age" /> | |
</td> | |
</tr> | |
</tbody></table> | |
<?php $this->nonceSubmit('SAVE SETTINGS', 'nonceName998423', 'nonceActionk44') ; ?> | |
<?php | |
} ?> | |
</form> | |
<?php $this->settings_page_part("end"); | |
} | |
public function plugin_reset_callback() | |
{ | |
} | |
} | |
$GLOBALS[__NAMESPACE__] = new PluginClass(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment