arc-hive-wordpress-plugin/arcHIVE-wp-plugin.php

357 lines
13 KiB
PHP
Raw Normal View History

2021-04-15 13:48:04 +02:00
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://example.com
* @since 1.0.0
* @package Plugin_Name
*
* @wordpress-plugin
*/
/**
* Plugin Name: arcHIVE - website options
Plugin URI: https://arc-hive.zone/
Description: All the <strong>options</strong> for <strong>arcHIVE website</strong> wich do not come by default with Wordpress.
Version: 0.1
Author URI: https://vitrubio.net/
Author: jorge - vitrubio.net
License: GPL 3.0
Date: 2021 04 14
License URI:https://www.gnu.org/licenses/gpl-3.0.html
Text Domain: arcHIVE_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/
*/
2021-04-15 13:48:04 +02:00
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/* *
* Load translation, if it exists
* * * * * * * * * * * * * * * * * * */
function arcHIVE_plugin_init() {
$plugin_dir = basename(dirname(__FILE__));
load_plugin_textdomain( 'arcHIVE_plugin_txtdomain', null, $plugin_dir.'/assets/languages/' );
}
add_action('plugins_loaded', 'arcHIVE_plugin_init');
/* *
* Add mimetypes support: svg
* * * * * * * * * * * * * * * * * * */
function arcHIVE_enable_mime_types( $mimes ) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'arcHIVE_enable_mime_types');
/* *
* add settings link in pluggin page
* * * * * * * * * * * * * * * * * * */
// function arcHIVE_plugin_plugin_action_links($links, $file) {
// $this_plugin = basename(plugin_dir_url(__FILE__)) . '/arcHIVE-theme-plugin.php';
// if($file == $this_plugin) {
// $links[] = '<a href="admin.php?page=arcHIVE-options">' . __('Settings', 'arcHIVE_plugin_txtdomain') . '</a>';
// }
// return $links;
// }
// add_filter('plugin_action_links', 'arcHIVE_plugin_plugin_action_links', 10, 2);
//
/**
* Registers stylesheet for a custom plugin.
*/
function arcHIVE_wp_plugin_styles_admin() {
add_editor_style( 'assets/css/arcHIVE-wp-plugin.css' );
}
add_action( 'admin_init', 'arcHIVE_wp_plugin_styles_admin' );
/**
* Proper way to enqueue scripts and styles
*/
//function arcHIVE_theme_plugin_styles_public() {
// $this_plugin = basename(plugin_dir_url(__FILE__));
// wp_enqueue_style( 'arcHIVE-theme-plugin', plugin_dir_url(__FILE__) . 'assets/css/arcHIVE-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', 'arcHIVE_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( 'arcHIVE_mce_buttons' ) ) :
// function arcHIVE_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', 'arcHIVE_mce_buttons' );
//
// // Callback function to filter the MCE settings
// if ( ! function_exists( 'arcHIVE_mce_before_init_insert_formats' ) ) :
// function arcHIVE_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', 'arcHIVE_mce_before_init_insert_formats' );
//
// function arcHIVE_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', 'arcHIVE_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 arcHIVE_settings_init() {
// // register a new setting for "arcHIVE" page
// register_setting( 'arcHIVE_settings', 'arcHIVE_options' );
//
// // register a new section in the "arcHIVE" page
// add_settings_section(
// 'arcHIVE_section_olderthandate',
// __( 'arcHIVEs Options.', 'arcHIVE_plugin_txtdomain' ),
// 'arcHIVE_section_olderthandate_cb',
// 'arcHIVE_settings'
// );
//
// // register a new field in the "arcHIVE_section_olderthandate" section, inside the "arcHIVE" page
// add_settings_field(
// 'arcHIVE_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...', 'arcHIVE_plugin_txtdomain' ),
// 'arcHIVE_field_olderthandate_cb',
// 'arcHIVE_settings',
// 'arcHIVE_section_olderthandate',
// [
// 'label_for' => 'arcHIVE_field_olderthandate',
// 'class' => 'arcHIVE_row',
// 'arcHIVE_custom_data' => 'custom',
// ]
// );
// }
//
/**
* register our arcHIVE_settings_init to the admin_init action hook
*/
// add_action( 'admin_init', 'arcHIVE_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 arcHIVE_section_olderthandate_cb( $args ) {
// ?>
// <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.', 'arcHIVE_plugin_txtdomain' ); ?>
// </p>
// <?php
// }
//
// // daysback field cb
//
// // field callbacks can accept an $args parameter, which is an array.
// // $args is defined at the add_settings_field() function.
// // wordpress has magic interaction with the following keys: label_for, class.
// // the "label_for" key value is used for the "for" attribute of the <label>.
// // 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.
// function arcHIVE_field_olderthandate_cb( $args ) {
// // get the value of the setting we've registered with register_setting()
// $options = get_option( 'arcHIVE_options' );
// // output the field
// ?>
//
// <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.', 'arcHIVE_plugin_txtdomain' ); ?>
// </p>
// <form id="arcHIVE-oldpost-numberofdays" class="arcHIVE-oldpost-numberofdays">
// <label for="arcHIVE-oldpost-numberofdays">Number of days:</label>
// <input type="number" id="arcHIVE-oldpost-numberofdays" name="arcHIVE-oldpost-numberofdays" min="1" max="100">
// </form>
// <form id="arcHIVE-oldpost-enddate" class="arcHIVE-oldpost-enddate">
// <label for="arcHIVE-oldpost-enddate">Start date:</label>
// <input type="date" id="arcHIVE-oldpost-enddate" name="arcHIVE-oldpost-endate" value="">
// </form>
//
// <!-- borrar desde aqui -->
// <p>
// label_for:<?php echo esc_attr( $args['label_for'] ); ?>
// <br />
// arcHIVE_custom_data:<?php echo esc_attr( $args['arcHIVE_custom_data'] ); ?>
// <br />
// class:<?php echo esc_attr( $args['class'] ); ?>
// <br />
// <?php esc_html_e( 'daysback', 'arcHIVE_plugin_txtdomain' ); ?>
// <br />
//
// </p>
// <!-- borrar hasta aqui -->
//
// <?php
// }
//
/**
* top level menu
* https://developer.wordpress.org/reference/functions/add_menu_page/
*/
// function arcHIVE_options_page() {
// // add top level menu page
// add_menu_page(
// $page_title = 'arcHIVE Options', // $page_title
// $menu_title = 'arcHIVE', //$menu_title
// $capability = 'manage_options', //'edit_others_posts', // $capability
// $menu_slug = 'arcHIVE-options', // $menu_slug
// $function = 'arcHIVE_options_page_html', //$function
// $icon_url = 'dashicons-rest-api',// $icon_url //https://developer.wordpress.org/resource/dashicons/#menu
// $position = '50'// $position
// );
// }
//
/**
* register our arcHIVE_options_page to the admin_menu action hook
*/
// add_action( 'admin_menu', 'arcHIVE_options_page' );
/**
* top level menu:
* callback functions
*/
// function arcHIVE_options_page_html() {
// // check user capabilities
// if ( ! current_user_can( 'manage_options' ) ) {
// ?>
// <p class="description">
// <?php esc_html_e( 'Sorry, you do not have permission to edit this settings, please, contact any admin to get granted.', 'arcHIVE_plugin_txtdomain' ); ?>
// </p>
// <?php
// return;
// }
//
// // add error/update messages
//
// // check if the user have submitted the settings
// // wordpress will add the "settings-updated" $_GET parameter to the url
// if ( isset( $_GET['settings-updated'] ) ) {
// // add settings saved message with the class of "updated"
// add_settings_error( 'arcHIVE_messages', 'arcHIVE_message', __( 'Settings Saved', 'arcHIVE_plugin_txtdomain' ), 'updated' );
// }
//
// // show error/update messages
// settings_errors( 'arcHIVE_messages' );
// ?>
// <div class="wrap">
// <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
// <form action="options.php" method="post">
// <?php
// // output security fields for the registered setting "arcHIVE"
// settings_fields( 'arcHIVE_settings' );
// // output setting sections and their fields
// // (sections are registered for "arcHIVE", each field is registered to a specific section)
// do_settings_sections( 'arcHIVE_settings' );
// // output save settings button
// submit_button( 'Save Settings' );
// ?>
// </form>
// </div>
// <?php
// }