options for Biofriction website wich do not come by default with wordpress such as: selector for showing buttons, a date picker for old posts, and any other needs. Version: 0.2 Author URI: https://vitrubio.net/ Author: jorge - vitrubio.net License: GPL 3.0 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 howto write a pluggin by Wordpress.org https://codex.wordpress.org/Writing_a_Plugin and the 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!' ); /* * * 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'); /* * * 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[] = '' . __('Settings', 'bfr_plugin_txtdomain') . ''; } 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() { add_editor_style( 'assets/css/bfr-theme-plugin.css' ); } add_action( 'admin_init', 'biofriction_theme_plugin_styles_admin' ); /** * Proper way to enqueue scripts and styles */ 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' ); // 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' ); /* * * Custom button in TINYMCE editor for styling * * * * * * * * * * * * * * * * * * * * * * */ // as read on // 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://kinsta.com/blog/wordpress-tinymce-editor/ // Callback function to insert 'styleselect' into the $buttons array if ( ! function_exists( 'bfr_mce_buttons' ) ) : function bfr_mce_buttons( $buttons ) { // array_unshift( $buttons, 'styleselect', 'removeformat' ); array_push( $buttons, 'styleselect', 'removeformat' ); return $buttons; } endif; // Register our callback to the appropriate filter add_filter( 'mce_buttons_2', 'bfr_mce_buttons' ); // Callback function to filter the MCE settings if ( ! function_exists( 'bfr_mce_before_init_insert_formats' ) ) : function bfr_mce_before_init_insert_formats( $init_array ) { // Define the style_formats array $style_formats=array( // Each array child is a format with it's own settings array( 'title' => 'button', 'block' => 'span', 'classes' => 'button', 'wrapper' => true, ), array( 'title' => 'button secondary', 'block' => 'span', 'classes' => 'button secondary', 'wrapper' => true, ), array( 'title' => 'button hollow', 'block' => 'span', 'classes' => 'button hollow primary', 'wrapper' => true, ), array( 'title' => 'button hollow secondary', 'block' => 'span', 'classes' => 'button hollow secondary', 'wrapper' => true, ), ); // Insert the array, JSON ENCODED, into 'style_formats' $init_array['style_formats'] = json_encode( $style_formats ); return $init_array; } endif; // Attach callback to 'tiny_mce_before_init' add_filter( 'tiny_mce_before_init', 'bfr_mce_before_init_insert_formats' ); // function biofriction_mce_buttons_3( $buttons ) { // $buttons[] = 'superscript'; // $buttons[] = 'subscript'; // $buttons[] = 'cut' ; // $buttons[] = 'copy' ; // $buttons[] = 'paste' ; // $buttons[] = 'hr' ; // $buttons[] = 'backcolor' ; // $buttons[] = 'newdocuement' ; // $buttons[] = 'formatselect' ; // $buttons[] = 'fontselect' ; // $buttons[] = 'fontsizeselect' ; // $buttons[] = 'styleselect' ; // return $buttons; // } // add_filter( 'mce_buttons_3', 'biofriction_mce_buttons_3' ); /** * * Custom settings page * * * * * * * * * * * * * * * * * * / * * @internal never define functions inside callbacks. * these functions could be run multiple times; this would result in a fatal error. * https://developer.wordpress.org/plugins/settings/custom-settings-page/ */ /** * custom option and settings */ function bfr_settings_init() { // register a new setting for "bfr" page register_setting( 'bfr_settings', 'bfr_options' ); // register a new section in the "bfr" page add_settings_section( 'bfr_section_olderthandate', __( 'Biofrictions Options.', 'bfr_plugin_txtdomain' ), 'bfr_section_olderthandate_cb', 'bfr_settings' ); // register a new field in the "bfr_section_olderthandate" section, inside the "bfr" page add_settings_field( '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 __( 'Hide content older than...', 'bfr_plugin_txtdomain' ), 'bfr_field_olderthandate_cb', 'bfr_settings', 'bfr_section_olderthandate', [ 'label_for' => 'bfr_field_olderthandate', 'class' => 'bfr_row', 'bfr_custom_data' => 'custom', ] ); } /** * register our bfr_settings_init to the admin_init action hook */ add_action( 'admin_init', 'bfr_settings_init' ); /** * custom option and settings: * callback functions */ // olderthandate section cb // section callbacks can accept an $args parameter, which is an array. // $args have the following keys defined: title, id, callback. // the values are defined at the add_settings_section() function. function bfr_section_olderthandate_cb( $args ) { ?>
. // the "class" key value is used for the "class" attribute of the
number of days from today to the past or the date from wich will be considered old posts. Then the class oldpost will be added to the post and pages so you can apply a css style to your theme.', 'bfr_plugin_txtdomain' ); ?>
label_for:
bfr_custom_data:
class: