first commit

This commit is contained in:
jorge 2022-11-30 11:39:22 +01:00
parent a271a3ba22
commit 8c7d8ca497
19 changed files with 395 additions and 707 deletions

View File

@ -1,9 +1,8 @@
# The Hangar wp plugin
# The Oficina de Suport wp plugin
Pluggin development for the needs of the wordpress theme for [Hangar](https://hangar.org).
Pluggin development for the needs of the wordpress theme for [Oficina de Suport de Xarxaprod](https://oficinasuport.xarxaprod.cat).
Several parts of the WP will be coded here such as:
- Tagged and categorized content
- Widgets
- MetaBoxes
- etc...

View File

@ -1,5 +0,0 @@
/* hangar wp plugin styles
*
* css styles
*
*/

View File

@ -0,0 +1,17 @@
/*
*
* @link https://oficinasuport.xarxaprod.cat
* @since 1.0.0
* @package ofisuport-wp-plugin
*
* Version: 1.0.0
* Author: jorge - vitrubio.net
* Author URI: https://vitrubio.net/
* License: GPL 3.0
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*
* ofisuport wp plugin styles for admin view
*
* css styles
*
*/

View File

@ -0,0 +1,17 @@
/*
*
* @link https://oficinasuport.xarxaprod.cat
* @since 1.0.0
* @package ofisuport-wp-plugin
*
* Version: 1.0.0
* Author: jorge - vitrubio.net
* Author URI: https://vitrubio.net/
* License: GPL 3.0
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*
* ofisuport wp plugin styles
*
* css styles
*
*/

View File

@ -1,63 +0,0 @@
<?php
/*
*
* @link https://hangar.org
* @since 1.0.0
* @package hangar_WP_Plugin
*
* Plugin Name: Hangar wordpress plugin
* Plugin URI: https://git.hangar.org
* Description: Different needs for the Hangar Wordpress theme needs. Tag pages, show tagged content in page view, old posts. Adds support for: SVG.
* Date: 2022 07 10
* Version: 1.0.0
* Author: jorge - vitrubio.net
* Author URI: https://vitrubio.net/
* License: GPL 3.0
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: hangar-wpplugin-textdomain
* 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/
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
//defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'HANGAR_WPPLUGIN_VERSION', '1.0.0' );
/* *
* define Plugin path
* https://developer.wordpress.org/reference/functions/plugin_dir_path/#comment-1113
* * * * * * * * * * * * * * * * * * */
define( 'HANGAR_WPPLUGIN_PATH', plugin_dir_path( __FILE__ ) ); //in server
define( 'HANGAR_WPPLUGIN_URL', plugin_dir_url( __FILE__ ) ); //public
include( HANGAR_WPPLUGIN_PATH . 'includes/hangar-init-textdomain.php');
include( HANGAR_WPPLUGIN_PATH . 'includes/hangar-enable-svg.php');
include( HANGAR_WPPLUGIN_PATH . 'includes/hangar-stylesheet-admin.php');
include( HANGAR_WPPLUGIN_PATH . 'includes/hangar-stylesheet-public.php');
include( HANGAR_WPPLUGIN_PATH . 'includes/hangar-tags-and-pages.php');
include( HANGAR_WPPLUGIN_PATH . 'includes/hangar-plugin-settings-pannel.php');
include( HANGAR_WPPLUGIN_PATH . 'includes/hangar-extracontent-in-postpage.php');

19
includes/enable-svg.php Normal file
View File

@ -0,0 +1,19 @@
<?php
/**
* Add mimetypes support: svg
*
* This class defines all code necessary to run during the plugin's activation.
*
* @link https://oficinasuport.xarxaprod.cat
* @since 1.0.0
* @package ofisuport-wp-plugin
* @subpackage ofisuport-wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*/
function enable_mime_types( $mimes ) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'enable_mime_types');

View File

@ -1,26 +0,0 @@
<?php
/**
* Add mimetypes support: svg
*
* @link https://hangar.org
* @since 1.0.0
* @package hangar-wp-plugin
* @subpackage hangar-wp-plugin/includes
*/
/**
* Add mimetypes support: svg
*
* This class defines all code necessary to run during the plugin's activation.
*
* @since 1.0.0
* @package hangar-wp-plugin
* @subpackage hangar-wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*/
function hangar_enable_mime_types( $mimes ) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'hangar_enable_mime_types');

View File

@ -1,151 +0,0 @@
<?php
/*
Plugin Name: The Green Balloon - website options
Plugin URI: https://thegreenBalloon.net/
Description: All the <strong>options</strong> for <strong>The Green Balloon website</strong> wich do not come by default with wordpress such as: selector for showing post or pages in homepage, the text area to show summary for post and pages, the map archive showing tags from posts.
Author: jorge - vitrubio.net
Date: 2020 01 10
Version: 0.3
Author URI: https://vitrubio.net/
License: GPL 3.0
License URI:https://www.gnu.org/licenses/gpl-3.0.html
*/
/* to use in the template
* include this code in post/page view
*
// // Detect plugin. For use on Front End only.
// include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// // check for plugin using plugin name
// if ( is_plugin_active( 'hangar-wp-plugin/hangar-wp-plugin.php' ) ) {
// //plugin is activated do
// hangar_show_extra_content();
// }
*/
/*
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/
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/* * * * * * * * * * * * * * * * * * * * * * * * * * */
/* begin pluggin for SHORT CODES IN PAGE OR POST */
/*
https://themefoundation.com/wordpress-meta-boxes-guide/
*/
// Adds a meta box to the post editing screen
if ( ! function_exists( 'hangar_extra_content_add_meta_box' ) ) :
function hangar_extra_content_add_meta_box() {
add_meta_box(
'hangar_extra_content', //$id
'Hangar: contingut extra', //$title
'hangar_extra_content_callback', //$callback
array('post', 'page'), // $screen
'normal', // $context // normal,side,advanced
'high' // $priority //high, core, default,low
);
}
add_action( 'add_meta_boxes', 'hangar_extra_content_add_meta_box');
endif;
// Outputs the content of the meta box
if ( ! function_exists( 'hangar_extra_content_callback' ) ) :
function hangar_extra_content_callback( $post ) {
wp_nonce_field( basename( __FILE__ ), 'hangar_extra_content_nonce' );
$hangar_extra_content_stored_meta = get_post_meta( $post->ID );
?>
<p>
<span class="row hangar-title"><?php _e( 'Estas son las opciones de cada <em>entrada</em> o <em>página</em> de la web.', 'hangar-wpplugin-textdomain' )?></span>
<span class="row hangar-title"><?php _e( 'Para mostrar las entradas o páginas debes poner el <code>[shortcode]</code> que genera el icono <img src="' . HANGAR_WPPLUGIN_URL . 'assets/img/PFC-icon.png" alt="PFC icon" style="margin-bottom:-8px;"/> que ves en la barra de edición de texto.', 'hangar-wpplugin-textdomain' )?></span>
<div class="row hangar-content">
</div>
</p>
<p>
<label for="hangar_extra_content-summary" class="hangar_extra_content-summary-title"><?php _e( 'Escribe el texto que se muestra como resumen en la página principal y en los cuadrados.', 'hangar-wpplugin-textdomain' )?></label>
<div id="hangar_extra_content_wysiwyg_summary">
<?php
// https://codex.wordpress.org/Function_Reference/wp_editor
$content = get_post_meta( get_the_ID(), 'hangar_extra_content_wysiwyg_summary', 'edit' );
$editor_id = 'hangar_extra_content_wysiwygsummary_ID';
$settings = array(
'textarea_name' => 'hangar_extra_content_wysiwyg_summary',
'media_buttons' => true,
'textarea_rows' => 10,
// https://www.kevinleary.net/customizing-tinymce-wysiwyg-editor-wordpress/
// 'tinymce' => array(
// 'toolbar1' => 'formatselect,bold,italic,link,unlink,charmap,removeformat,wp_more',
// 'toolbar2' => '',
// 'toolbar3' => '',
// ),
);
wp_editor( $content,$editor_id,$settings); ?>
</div>
</p>
<?php
}
endif;
// Saves the custom meta input
if ( ! function_exists( 'hangar_extra_content_meta_save' ) ) :
function hangar_extra_content_meta_save( $post_id ) {
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'hangar_extra_content_nonce' ] ) && wp_verify_nonce( $_POST[ 'hangar_extra_content_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// saves the hangar_extra_content_wysiwyg_summary
if( isset( $_POST[ 'hangar_extra_content_wysiwyg_summary' ] ) ) {
$dattaout=($_POST['hangar_extra_content_wysiwyg_summary']);
update_post_meta( $post_id, 'hangar_extra_content_wysiwyg_summary', $dattaout );
}else {
update_post_meta( $post_id, 'hangar_extra_content_wysiwyg_summary', $_POST[ '' ] );
}
}
add_action( 'save_post', 'hangar_extra_content_meta_save' );
endif;
// outputs this archive_map in front end
if ( ! function_exists( 'hangar_show_extra_content' ) ) :
function hangar_show_extra_content(){
// Detect plugin. For use on Front End only.
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// check for plugin using plugin name
// https://wordpress.org/plugins/posts-from-category/
if ( is_plugin_active( 'posts-from-category/post-from-category.php' ) ) {
// Retrieves the stored value from the database
$meta_value = get_post_meta( get_the_ID(), 'hangar_extra_content_wysiwyg_summary', true );
// Checks and displays the retrieved value
if( !empty( $meta_value ) ) {
echo '<div class="hangar-extra-content">';
// to do shortcodes: https://developer.wordpress.org/reference/functions/apply_filters/
echo apply_filters( 'the_content', $meta_value);
echo '</div>';
}
}
} // end function hangar_show_extra_content
endif;
/* * * * * * * *
/* * * * * * * * *
/* end pluggin for SHORT CODES IN PAGE OR POST */
/* * * * * * * * * * * * * * * * * * * * * * * * */

View File

@ -1,17 +0,0 @@
<?php
/**
* Load translation, if it exists
*
* This class defines all code necessary to run during the plugin's activation.
*
* @link https://hangar.org
* @since 1.0.0
* @package hangar-wp-plugin
* @subpackage hangar-wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*/
function hangar_wpplugin_init_textdomain() {
load_plugin_textdomain( 'hangar-wpplugin-textdomain', null, plugin_dir_path( __FILE__ ).'/assets/languages/' );
}
add_action('plugins_loaded', 'hangar_wpplugin_init_textdomain');

View File

@ -1,278 +0,0 @@
<?php
/**
*
* 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/
*/
// if( ! function_exists('') ){}
/**
* custom option and settings
*/
if( ! function_exists('hangar_wpplugin_settings_init') ){
function hangar_wpplugin_settings_init() {
// register a new setting for "hangar_wpplugin" page
register_setting( 'hangar_wpplugin_settings', 'hangar_wpplugin_options' );
// register a new section in the "hangar_wpplugin" page
add_settings_section(
'hangar_wpplugin_section_control_home',
__( 'Home control.', 'hangar-wpplugin-textdomain' ),
'hangar_wpplugin_section_control_home_cb',
'hangar_wpplugin_settings'
);
// register a new field in the "hangar_wpplugin_section_control_home" section, inside the "hangar_wpplugin" page
//
// uncoment below to activate
// add_settings_field(
// 'hangar_wpplugin_field_control_home', // as of WP 4.6 this value is used only internally
// // use $args' label_for to populate the id inside the callback
// __( 'This is the content being shown in home page:', 'hangar-wpplugin-textdomain' ),
// 'hangar_wpplugin_field_control_home_cb',
// 'hangar_wpplugin_settings',
// 'hangar_wpplugin_section_control_home'
// );
// register a new section in the "hangar_wpplugin" page
//
// uncoment below to activate
// add_settings_section(
// 'hangar_wpplugin_section_olderthandate',
// __( 'Older than options.', 'hangar-wpplugin-textdomain' ),
// 'hangar_wpplugin_section_olderthandate_cb',
// 'hangar_wpplugin_settings'
// );
// register a new field in the "hangar_wpplugin_section_olderthandate" section, inside the "hangar_wpplugin" page
//
// uncoment below to activate
// add_settings_field(
// 'hangar_wpplugin_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...', 'hangar-wpplugin-textdomain' ),
// 'hangar_wpplugin_field_olderthandate_cb',
// 'hangar_wpplugin_settings',
// 'hangar_wpplugin_section_olderthandate',
// [
// 'label_for' => 'hangar_wpplugin_field_olderthandate',
// 'class' => 'hangar-wpplugin-row',
// 'hangar_wpplugin_custom_data' => 'custom',
// ]
// );
}
}
/**
* register our hangar_wpplugin_settings_init to the admin_init action hook
*/
add_action( 'admin_init', 'hangar_wpplugin_settings_init' );
/**
* custom option and settings:
* callback functions
*/
// home control panel cb
// to see wich pages and post are shown in home page
if( ! function_exists('hangar_wpplugin_section_control_home_cb') ){
function hangar_wpplugin_section_control_home_cb(){
global $wpdb;
$querystr = "
SELECT wposts.post_name,wposts.ID, users.user_login, m1.meta_value as inicio, m2.meta_value as orden
FROM $wpdb->posts wposts
INNER JOIN $wpdb->postmeta m1 ON wposts.ID = m1.post_id
INNER JOIN $wpdb->postmeta m2 ON wposts.ID = m2.post_id
INNER JOIN $wpdb->users users ON wposts.post_author = users.ID
WHERE (wposts.post_type = 'post' OR wposts.post_type = 'page')
AND m1.meta_key = 'Inici'
AND m1.meta_value = '1'
AND m2.meta_key = 'Ordre_inici'
GROUP BY ID
ORDER BY inicio DESC, CAST(orden AS SIGNED) ASC
";
echo' <div id="wpbody-content"> ';
// title controlled in settings_section
// echo '<div class="wrap"><h2>Control Home</h2><br/></div>';
$pageposts = $wpdb->get_results($querystr, OBJECT);
if ($pageposts):
global $post;
echo "<table class=\"wp-list-table widefat fixed posts\" cellspacing=\"0\">
<thead>
<tr>
<th scope='col' width='150' class='manage-column column-slug sortable desc'>Nombre Post</th>
<th scope='col' class='manage-column column-slug sortable desc'>Id</th>
<th scope='col' class='manage-column column-slug sortable desc'>Autor Post</th>
<th scope='col' class='manage-column column-slug sortable desc'>Inicio</th>
<th scope='col' class='manage-column column-slug sortable desc'>Orden</th>
</tr>
</thead>
<tbody id=\"the-list\">";
foreach ($pageposts as $post):
$nom = $post->post_name;
$id = $post->ID;
$autor = $post->user_login;
$inici = $post->inicio;
$ordre = $post->orden;
echo "<tr>
<td><a href='post.php?post=$id&action=edit' class=\"row-tittle\">$nom</a></td>
<td>$id</td>
<td>$autor</td>
<td>$inici</td>
<td>$ordre</td>
</tr>";
endforeach;
echo "</tbody></table></div>";
endif;
}
}
// 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.
if( ! function_exists('hangar_wpplugin_section_olderthandate_cb') ){
function hangar_wpplugin_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.', 'hangar-wpplugin-textdomain' ); ?>
</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.
if( ! function_exists('hangar_wpplugin_field_olderthandate_cb') ){
function hangar_wpplugin_field_olderthandate_cb( $args ) {
// get the value of the setting we've registered with register_setting()
$options = get_option( 'hangar_wpplugin_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.', 'hangar-wpplugin-textdomain' ); ?>
</p>
<form id="hangar_wpplugin-oldpost-numberofdays" class="hangar_wpplugin-oldpost-numberofdays">
<label for="hangar_wpplugin-oldpost-numberofdays">Number of days:</label>
<input type="number" id="hangar_wpplugin-oldpost-numberofdays" name="hangar_wpplugin-oldpost-numberofdays" min="1" max="100">
</form>
<form id="hangar_wpplugin-oldpost-enddate" class="hangar_wpplugin-oldpost-enddate">
<label for="hangar_wpplugin-oldpost-enddate">Start date:</label>
<input type="date" id="hangar_wpplugin-oldpost-enddate" name="hangar_wpplugin-oldpost-endate" value="">
</form>
<!-- borrar desde aqui -->
<!--
<p>
label_for:
<?php //echo esc_attr( $args['label_for'] ); ?>
<br />
hangar_wpplugin_custom_data:
<?php //echo esc_attr( $args['hangar_wpplugin_custom_data'] ); ?>
<br />
class:
<?php //echo esc_attr( $args['class'] ); ?>
<br />
<?php //esc_html_e( 'daysback', 'hangar-wpplugin-textdomain' ); ?>
<br />
</p>
-->
<!-- borrar hasta aqui -->
<?php
}
}
/**
* top level menu
* https://developer.wordpress.org/reference/functions/add_menu_page/
*/
if( ! function_exists('hangar_wpplugin_options_page') ){
function hangar_wpplugin_options_page() {
// add top level menu page
add_menu_page(
$page_title = 'Hangar plugin options', // $page_title
$menu_title = 'Hangar Options', //$menu_title
$capability = 'manage_options', //'edit_others_posts', // $capability
$menu_slug = 'hangar-options', // $menu_slug
$function = 'hangar_wpplugin_options_page_html', //$function
$icon_url = 'dashicons-rest-api',// $icon_url //https://developer.wordpress.org/resource/dashicons/#menu
$position = '25'// $position
);
}
}
// register our hangar_wpplugin_options_page to the admin_menu action hook
add_action( 'admin_menu', 'hangar_wpplugin_options_page' );
// top level menu: callback functions
if( ! function_exists('hangar_wpplugin_options_page_html') ){
function hangar_wpplugin_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.', 'hangar-wpplugin-textdomain' ); ?>
</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( 'hangar_wpplugin_messages', 'hangar_wpplugin_message', __( 'Settings Saved', 'hangar-wpplugin-textdomain' ), 'updated' );
}
// show error/update messages
settings_errors( 'hangar_wpplugin_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 "hangar_wpplugin"
settings_fields( 'hangar_wpplugin_settings' );
// output setting sections and their fields
// (sections are registered for "hangar_wpplugin", each field is registered to a specific section)
do_settings_sections( 'hangar_wpplugin_settings' );
// output save settings button
submit_button( 'Save Settings' );
?>
</form>
</div>
<?php
}
}

View File

@ -1,29 +0,0 @@
<?php
/**
* Registers admin stylesheet for a custom plugin.
*
* @link https://hangar.org
* @since 1.0.0
*
* @package hangar-wp-plugin
* @subpackage hangar-wp-plugin/includes
*/
/**
* Registers admin stylesheet for a custom plugin.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @since 1.0.0
* @package hangar-wp-plugin
* @subpackage hangar-wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*/
if( ! function_exists('hangar_admin_styles') ){
function hangar_admin_styles() {
if ( is_admin() ) {
add_editor_style( 'assets/css/hangar-wpplugin-admin-styles.css' );
}
}
add_action( 'admin_init', 'hangar_admin_styles' );
}

View File

@ -1,26 +0,0 @@
<?php
/**
* Registers public stylesheet for a custom plugin.
*
* @link https://hangar.org
* @since 1.1.0
*
* @package hangar_wp-plugin
* @subpackage hangar_wp-plugin/includes
*/
/**
* Registers public stylesheet for a custom plugin.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @since 1.1.0
* @package hangar_wp-plugin
* @subpackage hangar_wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*/
function hangar_public_styles() {
add_editor_style( 'assets/css/hangar-wpplugin-styles.css' );
}
add_action( 'admin_init', 'hangar_public_styles' );

View File

@ -1,109 +0,0 @@
<?php
/******************************************************************************
New Plugin Name: Hangar tag pages and show tagged content in pages
New Plugin URI: https://git.hangar.org
New Description: Add tags to Pages, just as you would do with Posts
License: GPLv2 or later
*******************************************************************************
Adding tags to pages based on the work of:
Original Plugin Name: Tag Pages
Original Plugin URI: https://burobjorn.nl
Original WP Plugin URI: https://wordpress.org/plugins/tag-pages/
Original Version: 1.0.2
Original Author: Bjorn Wijers <burobjorn at burobjorn dot nl>
Original Author URI: https://burobjorn.nl
******************************************************************************/
/* Copyright 2012
Tag Pages is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Tag Pages is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Add the 'post_tag' taxonomy, which is the name of the existing taxonomy
* used for tags to the Post type page. Normally in WordPress Pages cannot
* be tagged, but this let's WordPress treat Pages just like Posts
* and enables the tags metabox so you can add tags to a Page.
* NB: This uses the register_taxonomy_for_object_type() function which is only
* in WordPress 3 and higher!
*/
// add tag and category support to pages
if( ! function_exists ('hangar_category_tags_support_all') ){
function hangar_category_tags_support_all()
{
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
add_action('init', 'hangar_category_tags_support_all');
}
// ensure all pages are included in tag and category queries
if( ! function_exists ('hangar_category_tags_support_query') ){
function hangar_category_tags_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
if ($wp_query->get('category')) $wp_query->set('post_type', 'any');
}
add_action('pre_get_posts', 'hangar_category_tags_support_query');
}
/**
* Display all post_types on the tags archive page. This forces WordPress to
* show tagged Pages together with tagged Posts. Thanks to Page Tagger by
* Ramesh Nair: http://wordpress.org/extend/plugins/page-tagger/
*/
if( ! function_exists('hangar_tagpages_display_tagged_pages_archive') ){
function hangar_tagpages_display_tagged_pages_archive(&$query)
{
if ( !is_admin() && $query->is_archive && $query->is_tag ) {
$q = &$query->query_vars;
$q['post_type'] = 'any';
}
}
add_action('pre_get_posts', 'hangar_tagpages_display_tagged_pages_archive');
}
// show category using shortcode
// https://stackoverflow.com/a/13996873
if( ! function_exists('hangar_show_categoriced') ){
function hangar_show_categoriced()
{
add_shortcode('hangar-catlist', function($atts, $content) {
$atts += array('category' => 1);
$posts = get_posts("category={$atts['category']}");
foreach ($posts as $post) {
echo $post->post_name . '<br />';
}
});
//echo do_shortcode('[hangar-catlist category=5]');
}
}
if( ! function_exists('hangar_show_tagged') ){
function hangar_show_tagged()
{
add_shortcode('hangar-taglist', function($atts, $content) {
$atts += array('tag' => 1);
$posts = get_posts("tag={$atts['tag']}");
foreach ($posts as $post) {
echo $post->post_name . '<br />';
}
});
//echo do_shortcode('[hangar-taglist tag=5]');
}
}

View File

@ -0,0 +1,17 @@
<?php
/**
* Load translation, if it exists
*
* This class defines all code necessary to run during the plugin's activation.
*
* @link https://oficinasuport.xarxaprod.cat
* @since 1.0.0
* @package ofisuport-wp-plugin
* @subpackage ofisuport-wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*/
function ofisuport_wpplugin_init_textdomain() {
load_plugin_textdomain( 'ofisuport-wpplugin-textdomain', null, plugin_dir_path( __FILE__ ).'/assets/languages/' );
}
add_action('plugins_loaded', 'ofisuport_wpplugin_init_textdomain');

View File

@ -0,0 +1,223 @@
<?php
/**
* Custom settings page
*
* This class defines all code necessary to run during the plugin's activation.
*
* @link https://oficinasuport.xarxaprod.cat
* @since 1.0.0
* @package ofisuport-wp-plugin
* @subpackage ofisuport-wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*
* @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
*/
if( ! function_exists('ofisuport_wpplugin_settings_init') ){
function ofisuport_wpplugin_settings_init() {
// register a new setting for "ofisuport_wpplugin" page
register_setting( 'ofisuport_wpplugin_settings', 'ofisuport_wpplugin_options' );
// register a new section in the "ofisuport_wpplugin" page
add_settings_section(
'ofisuport_wpplugin_section_control_home',
__( 'Home control.', 'ofisuport-wpplugin-textdomain' ),
'ofisuport_wpplugin_section_control_home_cb',
'ofisuport_wpplugin_settings'
);
// register a new field in the "ofisuport_wpplugin_section_control_home" section, inside the "ofisuport_wpplugin" page
//
// uncoment below to activate
// add_settings_field(
// 'ofisuport_wpplugin_field_control_home', // as of WP 4.6 this value is used only internally
// // use $args' label_for to populate the id inside the callback
// __( 'This is the content being shown in home page:', 'ofisuport-wpplugin-textdomain' ),
// 'ofisuport_wpplugin_field_control_home_cb',
// 'ofisuport_wpplugin_settings',
// 'ofisuport_wpplugin_section_control_home'
// );
// register a new section in the "ofisuport_wpplugin" page
//
// uncoment below to activate
// add_settings_section(
// 'ofisuport_wpplugin_section_olderthandate',
// __( 'Older than options.', 'ofisuport-wpplugin-textdomain' ),
// 'ofisuport_wpplugin_section_olderthandate_cb',
// 'ofisuport_wpplugin_settings'
// );
// register a new field in the "ofisuport_wpplugin_section_olderthandate" section, inside the "ofisuport_wpplugin" page
//
// uncoment below to activate
// add_settings_field(
// 'ofisuport_wpplugin_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...', 'ofisuport-wpplugin-textdomain' ),
// 'ofisuport_wpplugin_field_olderthandate_cb',
// 'ofisuport_wpplugin_settings',
// 'ofisuport_wpplugin_section_olderthandate',
// [
// 'label_for' => 'ofisuport_wpplugin_field_olderthandate',
// 'class' => 'ofisuport-wpplugin-row',
// 'ofisuport_wpplugin_custom_data' => 'custom',
// ]
// );
}
}
/**
* register our ofisuport_wpplugin_settings_init to the admin_init action hook
*/
add_action( 'admin_init', 'ofisuport_wpplugin_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.
if( ! function_exists('ofisuport_wpplugin_section_olderthandate_cb') ){
function ofisuport_wpplugin_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.', 'ofisuport-wpplugin-textdomain' ); ?>
</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.
if( ! function_exists('ofisuport_wpplugin_field_olderthandate_cb') ){
function ofisuport_wpplugin_field_olderthandate_cb( $args ) {
// get the value of the setting we've registered with register_setting()
$options = get_option( 'ofisuport_wpplugin_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.', 'ofisuport-wpplugin-textdomain' ); ?>
</p>
<form id="ofisuport_wpplugin-oldpost-numberofdays" class="ofisuport_wpplugin-oldpost-numberofdays">
<label for="ofisuport_wpplugin-oldpost-numberofdays">Number of days:</label>
<input type="number" id="ofisuport_wpplugin-oldpost-numberofdays" name="ofisuport_wpplugin-oldpost-numberofdays" min="1" max="100">
</form>
<form id="ofisuport_wpplugin-oldpost-enddate" class="ofisuport_wpplugin-oldpost-enddate">
<label for="ofisuport_wpplugin-oldpost-enddate">Start date:</label>
<input type="date" id="ofisuport_wpplugin-oldpost-enddate" name="ofisuport_wpplugin-oldpost-endate" value="">
</form>
<!-- borrar desde aqui -->
<!--
<p>
label_for:
<?php //echo esc_attr( $args['label_for'] ); ?>
<br />
ofisuport_wpplugin_custom_data:
<?php //echo esc_attr( $args['ofisuport_wpplugin_custom_data'] ); ?>
<br />
class:
<?php //echo esc_attr( $args['class'] ); ?>
<br />
<?php //esc_html_e( 'daysback', 'ofisuport-wpplugin-textdomain' ); ?>
<br />
</p>
-->
<!-- borrar hasta aqui -->
<?php
}
}
/**
* top level menu
* https://developer.wordpress.org/reference/functions/add_menu_page/
*/
if( ! function_exists('ofisuport_wpplugin_options_page') ){
function ofisuport_wpplugin_options_page() {
// add top level menu page
add_menu_page(
$page_title = 'Oficina Suport plugin options', // $page_title
$menu_title = 'OfiSuport options', //$menu_title
$capability = 'manage_options', //'edit_others_posts', // $capability
$menu_slug = 'ofisuport-options', // $menu_slug
$function = 'ofisuport_wpplugin_options_page_html', //$function
$icon_url = 'dashicons-rest-api',// $icon_url //https://developer.wordpress.org/resource/dashicons/#menu
$position = '25'// $position
);
}
}
// register our ofisuport_wpplugin_options_page to the admin_menu action hook
add_action( 'admin_menu', 'ofisuport_wpplugin_options_page' );
// top level menu: callback functions
if( ! function_exists('ofisuport_wpplugin_options_page_html') ){
function ofisuport_wpplugin_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.', 'ofisuport-wpplugin-textdomain' ); ?>
</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( 'ofisuport_wpplugin_messages', 'ofisuport_wpplugin_message', __( 'Settings Saved', 'ofisuport-wpplugin-textdomain' ), 'updated' );
}
// show error/update messages
settings_errors( 'ofisuport_wpplugin_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 "ofisuport_wpplugin"
settings_fields( 'ofisuport_wpplugin_settings' );
// output setting sections and their fields
// (sections are registered for "ofisuport_wpplugin", each field is registered to a specific section)
do_settings_sections( 'ofisuport_wpplugin_settings' );
// output save settings button
submit_button( 'Save Settings' );
?>
</form>
</div>
<?php
}
}

View File

@ -0,0 +1,22 @@
<?php
/**
* Registers admin stylesheet for a custom plugin.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @link https://oficinasuport.xarxaprod.cat
* @since 1.0.0
* @package ofisuport-wp-plugin
* @subpackage ofisuport-wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*
*/
if( ! function_exists('ofisuport_admin_styles') ){
function ofisuport_admin_styles() {
if ( is_admin() ) {
add_editor_style( 'assets/css/ofisuport-wpplugin-admin-styles.css' );
}
}
add_action( 'admin_init', 'ofisuport_admin_styles' );
}

View File

@ -0,0 +1,18 @@
<?php
/**
* Registers public stylesheet for a custom plugin.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @link https://ofisuport.xarxaprod.org
* @since 1.1.0
* @package ofisuport_wp-plugin
* @subpackage ofisuport_wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*/
function ofisuport_public_styles() {
add_editor_style( 'assets/css/ofisuport-wpplugin-styles.css' );
}
add_action( 'admin_init', 'ofisuport_public_styles' );

60
ofisuport-wp-plugin.php Normal file
View File

@ -0,0 +1,60 @@
<?php
/*
*
* @link https://oficinasuport.xarxaprod.cat
* @since 1.0.0
* @package ofisuport-wp-plugin
*
* Plugin Name: Oficina de Suport wp plugin
* Plugin URI: https://git.hangar.org/xarxaprod/oficinasuport-wp-plugin
* Description: Different needs for the Oficina de Suport de Xarxaprod.cat Wordpress theme needs. Adds support for: SVG.
* Date: 2022 10 28
* Version: 1.0.0
* Author: jorge - vitrubio.net
* Author URI: https://vitrubio.net/
* License: GPL 3.0
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: ofisuport-wpplugin-textdomain
* 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/
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
//defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'OFISUPORT_WPPLUGIN_VERSION', '1.0.0' );
/* *
* define Plugin path
* https://developer.wordpress.org/reference/functions/plugin_dir_path/#comment-1113
* * * * * * * * * * * * * * * * * * */
define( 'OFISUPORT_WPPLUGIN_PATH', plugin_dir_path( __FILE__ ) ); //in server
define( 'OFISUPORT_WPPLUGIN_URL', plugin_dir_url( __FILE__ ) ); //public
include( OFISUPORT_WPPLUGIN_PATH . 'includes/plugin-init-textdomain.php');
include( OFISUPORT_WPPLUGIN_PATH . 'includes/enable-svg.php');
include( OFISUPORT_WPPLUGIN_PATH . 'includes/stylesheet-admin.php');
include( OFISUPORT_WPPLUGIN_PATH . 'includes/stylesheet-public.php');
include( OFISUPORT_WPPLUGIN_PATH . 'includes/plugin-settings-pannel.php');