mods in the comments header, date and version number

This commit is contained in:
jorge 2021-11-24 14:18:26 +01:00
parent fef643345c
commit e3936a91a0
1 changed files with 175 additions and 196 deletions

View File

@ -1,90 +1,72 @@
<?php <?php
/** /**
* The plugin bootstrap file * Plugin Name
* *
* This file is read by WordPress to generate the plugin information in the plugin * @package Biofriction - website options
* admin area. This file also includes all of the dependencies used by the plugin, * @author jorge - vitrubio.net
* registers the activation and deactivation functions, and defines a function * @copyright 2021 jorge - vitrubio.net & hangar.org
* that starts the plugin. * @license GPL-3.0-or-later
* *
* @link http://example.com * @wordpress-plugin
* @since 1.0.0 * Plugin Name: Biofriction - website options
* @package Plugin_Name * Plugin URI: https://git.hangar.org/hangar-tech/biofriction-wp-plugin
* * Description: All the <strong>options</strong> for <strong>Biofriction website</strong> wich do not come by default with wordpress such as: selector for showing buttons, a date picker for old posts, and any other needs.
* @wordpress-plugin * Version: 0.4
*/ * Date: 2021 11 24
* Requires at least: 5.2
/* * Requires PHP: 7.2
Plugin Name: Biofriction - website options * Author: jorge - vitrubio.net
Plugin URI: https://biofriction.org/ * Author URI: https://vitrubio.net/
Description: All the <strong>options</strong> for <strong>Biofriction website</strong> wich do not come by default with wordpress such as: selector for showing buttons, a date picker for old posts, and any other needs. * Text Domain: bfr_plugin_txtdomain
Version: 0.3 * Domain Path: /languages
Author URI: https://vitrubio.net/ * License: GPL 3.0
Author: jorge - vitrubio.net * License URI: https://www.gnu.org/licenses/gpl-3.0.html
License: GPL 3.0 * Update URI: https://git.hangar.org/hangar-tech/biofriction-wp-theme.git
Date: 2020 02 10
License URI:https://www.gnu.org/licenses/gpl-3.0.html
Text Domain: bfr_plugin_txtdomain
Domain Path: /languages
*/ */
/* /*
if ever read this never forget to check if ever read this never forget to check
howto write a pluggin by Wordpress.org howto write a pluggin by Wordpress.org
https://codex.wordpress.org/Writing_a_Plugin https://developer.wordpress.org/plugins/
and the best practices and the best practices
https://developer.wordpress.org/plugins/plugin-basics/best-practices/ https://developer.wordpress.org/plugins/plugin-basics/best-practices/
and some resources
https://themefoundation.com/wordpress-meta-boxes-guide/
*/ */
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/* * // Load translation, if it exists
* Load translation, if it exists function bfr_plugin_init() {
* * * * * * * * * * * * * * * * * * */ $plugin_dir = basename(dirname(__FILE__));
load_plugin_textdomain( 'bfr_plugin_txtdomain', null, $plugin_dir.'/assets/languages/' );
}
add_action('plugins_loaded', 'bfr_plugin_init');
function bfr_plugin_init() { // add settings link in pluggin page
$plugin_dir = basename(dirname(__FILE__)); function bfr_plugin_plugin_action_links($links, $file) {
load_plugin_textdomain( 'bfr_plugin_txtdomain', null, $plugin_dir.'/assets/languages/' ); $this_plugin = basename(plugin_dir_url(__FILE__)) . '/bfr-theme-plugin.php';
} if($file == $this_plugin) {
add_action('plugins_loaded', 'bfr_plugin_init'); $links[] = '<a href="admin.php?page=biofriction-options">' . __('Settings', 'bfr_plugin_txtdomain') . '</a>';
}
return $links;
}
add_filter('plugin_action_links', 'bfr_plugin_plugin_action_links', 10, 2);
/* * // Registers stylesheet for a custom plugin.
* add settings link in pluggin page
* * * * * * * * * * * * * * * * * * */
function bfr_plugin_plugin_action_links($links, $file) {
$this_plugin = basename(plugin_dir_url(__FILE__)) . '/bfr-theme-plugin.php';
if($file == $this_plugin) {
$links[] = '<a href="admin.php?page=biofriction-options">' . __('Settings', 'bfr_plugin_txtdomain') . '</a>';
}
return $links;
}
add_filter('plugin_action_links', 'bfr_plugin_plugin_action_links', 10, 2);
/**
* Registers stylesheet for a custom plugin.
*/
function biofriction_theme_plugin_styles_admin() { function biofriction_theme_plugin_styles_admin() {
add_editor_style( 'assets/css/bfr-theme-plugin.css' ); add_editor_style( 'assets/css/bfr-theme-plugin.css' );
} }
add_action( 'admin_init', 'biofriction_theme_plugin_styles_admin' ); add_action( 'admin_init', 'biofriction_theme_plugin_styles_admin' );
/** // enqueue scripts and styles
* Proper way to enqueue scripts and styles
*/
function biofriction_theme_plugin_styles_public() { function biofriction_theme_plugin_styles_public() {
$this_plugin = basename(plugin_dir_url(__FILE__)); wp_enqueue_style( 'bfr-theme-plugin', plugin_dir_url(__FILE__) . 'assets/css/bfr-theme-plugin.css' , array(), filemtime( plugin_dir_url(__FILE__) . 'assets/css/bfr-theme-plugin.css' ), 'all');
wp_enqueue_style( 'bfr-theme-plugin', plugin_dir_url(__FILE__) . 'assets/css/bfr-theme-plugin.css' );
// wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
} }
add_action( 'wp_enqueue_scripts', 'biofriction_theme_plugin_styles_public' ); add_action( 'wp_enqueue_scripts', 'biofriction_theme_plugin_styles_public' );
/* * /* *
* Custom button in TINYMCE editor for styling * Custom button in TINYMCE editor for styling
* * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * */
// as read on // as read on
// https://codex.wordpress.org/Plugin_API/Filter_Reference/mce_buttons,_mce_buttons_2,_mce_buttons_3,_mce_buttons_4 // https://codex.wordpress.org/Plugin_API/Filter_Reference/mce_buttons,_mce_buttons_2,_mce_buttons_3,_mce_buttons_4
// https://www.wpbeginner.com/wp-tutorials/how-to-add-custom-styles-to-wordpress-visual-editor/ // https://www.wpbeginner.com/wp-tutorials/how-to-add-custom-styles-to-wordpress-visual-editor/
// https://kinsta.com/blog/wordpress-tinymce-editor/ // https://kinsta.com/blog/wordpress-tinymce-editor/
@ -95,7 +77,7 @@ if ( ! function_exists( 'bfr_mce_buttons' ) ) :
// array_unshift( $buttons, 'styleselect', 'removeformat' ); // array_unshift( $buttons, 'styleselect', 'removeformat' );
array_push( $buttons, 'styleselect', 'removeformat' ); array_push( $buttons, 'styleselect', 'removeformat' );
return $buttons; return $buttons;
} }
endif; endif;
// Register our callback to the appropriate filter // Register our callback to the appropriate filter
add_filter( 'mce_buttons_2', 'bfr_mce_buttons' ); add_filter( 'mce_buttons_2', 'bfr_mce_buttons' );
@ -162,57 +144,57 @@ add_filter( 'tiny_mce_before_init', 'bfr_mce_before_init_insert_formats' );
// } // }
// add_filter( 'mce_buttons_3', 'biofriction_mce_buttons_3' ); // add_filter( 'mce_buttons_3', 'biofriction_mce_buttons_3' );
/** /**
* *
* Custom settings page * Custom settings page
* * * * * * * * * * * * * * * * * * / * * * * * * * * * * * * * * * * * * /
* *
* @internal never define functions inside callbacks. * @internal never define functions inside callbacks.
* these functions could be run multiple times; this would result in a fatal error. * these functions could be run multiple times; this would result in a fatal error.
* https://developer.wordpress.org/plugins/settings/custom-settings-page/ * https://developer.wordpress.org/plugins/settings/custom-settings-page/
*/ */
/** /**
* custom option and settings * custom option and settings
*/ */
function bfr_settings_init() { function bfr_settings_init() {
// register a new setting for "bfr" page // register a new setting for "bfr" page
register_setting( 'bfr_settings', 'bfr_options' ); register_setting( 'bfr_settings', 'bfr_options' );
// register a new section in the "bfr" page // register a new section in the "bfr" page
add_settings_section( add_settings_section(
'bfr_section_olderthandate', 'bfr_section_olderthandate',
__( 'Biofrictions Options.', 'bfr_plugin_txtdomain' ), __( 'Biofrictions Options.', 'bfr_plugin_txtdomain' ),
'bfr_section_olderthandate_cb', 'bfr_section_olderthandate_cb',
'bfr_settings' 'bfr_settings'
); );
// register a new field in the "bfr_section_olderthandate" section, inside the "bfr" page // register a new field in the "bfr_section_olderthandate" section, inside the "bfr" page
add_settings_field( add_settings_field(
'bfr_field_olderthandate', // as of WP 4.6 this value is used only internally 'bfr_field_olderthandate', // as of WP 4.6 this value is used only internally
// use $args' label_for to populate the id inside the callback // use $args' label_for to populate the id inside the callback
__( 'Hide content older than...', 'bfr_plugin_txtdomain' ), __( 'Hide content older than...', 'bfr_plugin_txtdomain' ),
'bfr_field_olderthandate_cb', 'bfr_field_olderthandate_cb',
'bfr_settings', 'bfr_settings',
'bfr_section_olderthandate', 'bfr_section_olderthandate',
[ [
'label_for' => 'bfr_field_olderthandate', 'label_for' => 'bfr_field_olderthandate',
'class' => 'bfr_row', 'class' => 'bfr_row',
'bfr_custom_data' => 'custom', 'bfr_custom_data' => 'custom',
] ]
); );
} }
/** /**
* register our bfr_settings_init to the admin_init action hook * register our bfr_settings_init to the admin_init action hook
*/ */
add_action( 'admin_init', 'bfr_settings_init' ); add_action( 'admin_init', 'bfr_settings_init' );
/** /**
* custom option and settings: * custom option and settings:
* callback functions * callback functions
*/ */
// olderthandate section cb // olderthandate section cb
@ -220,11 +202,11 @@ add_action( 'admin_init', 'bfr_settings_init' );
// $args have the following keys defined: title, id, callback. // $args have the following keys defined: title, id, callback.
// the values are defined at the add_settings_section() function. // the values are defined at the add_settings_section() function.
function bfr_section_olderthandate_cb( $args ) { function bfr_section_olderthandate_cb( $args ) {
?> ?>
<p id="<?php echo esc_attr( $args['id'] ); ?>"> <p id="<?php echo esc_attr( $args['id'] ); ?>">
<?php esc_html_e( 'Here you should set the options for the older content to be marked as it.', 'bfr_plugin_txtdomain' ); ?> <?php esc_html_e( 'Here you should set the options for the older content to be marked as it.', 'bfr_plugin_txtdomain' ); ?>
</p> </p>
<?php <?php
} }
// daysback field cb // daysback field cb
@ -236,102 +218,99 @@ function bfr_section_olderthandate_cb( $args ) {
// the "class" key value is used for the "class" attribute of the <tr> containing the field. // the "class" key value is used for the "class" attribute of the <tr> containing the field.
// you can add custom key value pairs to be used inside your callbacks. // you can add custom key value pairs to be used inside your callbacks.
function bfr_field_olderthandate_cb( $args ) { function bfr_field_olderthandate_cb( $args ) {
// get the value of the setting we've registered with register_setting() // get the value of the setting we've registered with register_setting()
$options = get_option( 'bfr_options' ); $options = get_option( 'bfr_options' );
// output the field // output the field
?> ?>
<p class="description"> <p class="description">
<?php _e( 'You should set up the <b>number of days</b> from today to the past or the date from wich will be <b>considered old posts</b>. Then the class <span style="font-family:monospace;">oldpost</span> will be added to the post and pages so you can apply a css style to your theme.', 'bfr_plugin_txtdomain' ); ?> <?php _e( 'You should set up the <b>number of days</b> from today to the past or the date from wich will be <b>considered old posts</b>. Then the class <span style="font-family:monospace;">oldpost</span> will be added to the post and pages so you can apply a css style to your theme.', 'bfr_plugin_txtdomain' ); ?>
</p> </p>
<form id="bfr-oldpost-numberofdays" class="bfr-oldpost-numberofdays"> <form id="bfr-oldpost-numberofdays" class="bfr-oldpost-numberofdays">
<label for="bfr-oldpost-numberofdays">Number of days:</label> <label for="bfr-oldpost-numberofdays">Number of days:</label>
<input type="number" id="bfr-oldpost-numberofdays" name="bfr-oldpost-numberofdays" min="1" max="100"> <input type="number" id="bfr-oldpost-numberofdays" name="bfr-oldpost-numberofdays" min="1" max="100">
</form> </form>
<form id="bfr-oldpost-enddate" class="bfr-oldpost-enddate"> <form id="bfr-oldpost-enddate" class="bfr-oldpost-enddate">
<label for="bfr-oldpost-enddate">Start date:</label> <label for="bfr-oldpost-enddate">Start date:</label>
<input type="date" id="bfr-oldpost-enddate" name="bfr-oldpost-endate" value=""> <input type="date" id="bfr-oldpost-enddate" name="bfr-oldpost-endate" value="">
</form> </form>
<!-- borrar desde aqui --> <!-- borrar desde aqui -->
<p> <p>
label_for:<?php echo esc_attr( $args['label_for'] ); ?> label_for:<?php echo esc_attr( $args['label_for'] ); ?>
<br /> <br />
bfr_custom_data:<?php echo esc_attr( $args['bfr_custom_data'] ); ?> bfr_custom_data:<?php echo esc_attr( $args['bfr_custom_data'] ); ?>
<br /> <br />
class:<?php echo esc_attr( $args['class'] ); ?> class:<?php echo esc_attr( $args['class'] ); ?>
<br /> <br />
<?php esc_html_e( 'daysback', 'bfr_plugin_txtdomain' ); ?> <?php esc_html_e( 'daysback', 'bfr_plugin_txtdomain' ); ?>
<br /> <br />
</p> </p>
<!-- borrar hasta aqui --> <!-- borrar hasta aqui -->
<?php <?php
} }
/** /**
* top level menu * top level menu
* https://developer.wordpress.org/reference/functions/add_menu_page/ * https://developer.wordpress.org/reference/functions/add_menu_page/
*/ */
function bfr_options_page() { function bfr_options_page() {
// add top level menu page // add top level menu page
add_menu_page( add_menu_page(
$page_title = 'Biofriction Options', // $page_title $page_title = 'Biofriction Options', // $page_title
$menu_title = 'Biofriction', //$menu_title $menu_title = 'Biofriction', //$menu_title
$capability = 'manage_options', //'edit_others_posts', // $capability $capability = 'manage_options', //'edit_others_posts', // $capability
$menu_slug = 'biofriction-options', // $menu_slug $menu_slug = 'biofriction-options', // $menu_slug
$function = 'bfr_options_page_html', //$function $function = 'bfr_options_page_html', //$function
$icon_url = 'dashicons-rest-api',// $icon_url //https://developer.wordpress.org/resource/dashicons/#menu $icon_url = 'dashicons-rest-api',// $icon_url //https://developer.wordpress.org/resource/dashicons/#menu
$position = '50'// $position $position = '50'// $position
); );
} }
// register our bfr_options_page to the admin_menu action hook
/**
* register our bfr_options_page to the admin_menu action hook
*/
add_action( 'admin_menu', 'bfr_options_page' ); add_action( 'admin_menu', 'bfr_options_page' );
/** // top level menu: callback functions
* top level menu:
* callback functions
*/
function bfr_options_page_html() { function bfr_options_page_html() {
// check user capabilities // check user capabilities
if ( ! current_user_can( 'manage_options' ) ) { if ( ! current_user_can( 'manage_options' ) ) {
?> ?>
<p class="description"> <p class="description">
<?php esc_html_e( 'Sorry, you do not have permission to edit this settings, please, contact any admin to get granted.', 'bfr_plugin_txtdomain' ); ?> <?php esc_html_e( 'Sorry, you do not have permission to edit this settings, please, contact any admin to get granted.', 'bfr_plugin_txtdomain' ); ?>
</p> </p>
<?php <?php
return; return;
} }
// add error/update messages // add error/update messages
// check if the user have submitted the settings // check if the user have submitted the settings
// wordpress will add the "settings-updated" $_GET parameter to the url // wordpress will add the "settings-updated" $_GET parameter to the url
if ( isset( $_GET['settings-updated'] ) ) { if ( isset( $_GET['settings-updated'] ) ) {
// add settings saved message with the class of "updated" // add settings saved message with the class of "updated"
add_settings_error( 'bfr_messages', 'bfr_message', __( 'Settings Saved', 'bfr_plugin_txtdomain' ), 'updated' ); add_settings_error( 'bfr_messages', 'bfr_message', __( 'Settings Saved', 'bfr_plugin_txtdomain' ), 'updated' );
} }
// show error/update messages // show error/update messages
settings_errors( 'bfr_messages' ); settings_errors( 'bfr_messages' );
?> ?>
<div class="wrap"> <div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1> <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<form action="options.php" method="post"> <form action="options.php" method="post">
<?php <?php
// output security fields for the registered setting "bfr" // output security fields for the registered setting "bfr"
settings_fields( 'bfr_settings' ); settings_fields( 'bfr_settings' );
// output setting sections and their fields // output setting sections and their fields
// (sections are registered for "bfr", each field is registered to a specific section) // (sections are registered for "bfr", each field is registered to a specific section)
do_settings_sections( 'bfr_settings' ); do_settings_sections( 'bfr_settings' );
// output save settings button // output save settings button
submit_button( 'Save Settings' ); submit_button( 'Save Settings' );
?> ?>
</form> </form>
</div> </div>
<?php <?php
} }
// Randomize images in gallery homepage
// https://plugins.trac.wordpress.org/browser/random-gallery/trunk/random-gallery.php