Compare commits
16 Commits
db-fields-
...
main
Author | SHA1 | Date |
---|---|---|
jorge | bdba8664da | |
jorge | c95490660f | |
jorge | 76dc12f2ac | |
jorge | 2d4aef04bd | |
jorge | dc4ddbb3e6 | |
jorge | 1d1d14646e | |
jorge | 19833401b2 | |
jorge | 630b2da38b | |
jorge | 5bb4472ce2 | |
jorge | b01f31a98e | |
jorge | 5d183925c5 | |
jorge | 2bc7c46f3f | |
jorge | e6277a5e89 | |
jorge | 4b3260587f | |
jorge | f56ceac367 | |
jorge | bdadceaa43 |
|
@ -17,6 +17,8 @@
|
||||||
/readme.html
|
/readme.html
|
||||||
/wp-*.php
|
/wp-*.php
|
||||||
/xmlrpc.php
|
/xmlrpc.php
|
||||||
|
/ignore-*
|
||||||
|
*_gitignore-*
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
wp-config.php
|
wp-config.php
|
||||||
|
|
|
@ -80,7 +80,7 @@ if( ! function_exists( 'xarxaprod_ajuts_filters_form') ) {
|
||||||
|
|
||||||
<?php }; //end foreach groupkey field ?>
|
<?php }; //end foreach groupkey field ?>
|
||||||
<?php //echo '<p><span id="filterlink"></span></p>';?>
|
<?php //echo '<p><span id="filterlink"></span></p>';?>
|
||||||
<p><a id="submitfilteredlink" name="submit-ajut" class="button button-more" href="">enviar</a> </p>
|
<p><a id="submitfilteredlink" name="submit-ajut" class="button button-more" href="">filtrar</a> </p>
|
||||||
</form>
|
</form>
|
||||||
<?php //close the form and subit ?>
|
<?php //close the form and subit ?>
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ if( ! function_exists( 'xarxaprod_ajuts_filters_form') ) {
|
||||||
$('#archive-filters').on('click', 'input', function(){
|
$('#archive-filters').on('click', 'input', function(){
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
var url = '<?php echo home_url('ajuts/'); ?>';
|
var url = '<?php echo home_url('ajuts/'); ?>'; //insert the custom-post-type slug
|
||||||
args = {};
|
args = {};
|
||||||
var appendtoURL = '';
|
var appendtoURL = '';
|
||||||
var eachfiltered = '';
|
var eachfiltered = '';
|
||||||
|
|
|
@ -0,0 +1,180 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Function to display the front end checkboxes for the associat filter
|
||||||
|
*
|
||||||
|
* references:
|
||||||
|
* basic start
|
||||||
|
* https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/
|
||||||
|
*
|
||||||
|
* wordpress full form example
|
||||||
|
* https://wordpress.stackexchange.com/questions/383599/form-checkbox-value-going-to-dynamic-url
|
||||||
|
*
|
||||||
|
* checkbox adaptation query
|
||||||
|
* https://wordpress.stackexchange.com/a/102915
|
||||||
|
*
|
||||||
|
* form GET and POST
|
||||||
|
* https://www.formget.com/php-checkbox/
|
||||||
|
*
|
||||||
|
* @package Xarxaprod_wp_plugin
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<?php
|
||||||
|
if( ! function_exists( 'xarxaprod_associats_filters_form') ) {
|
||||||
|
function xarxaprod_associats_filters_form() {
|
||||||
|
?>
|
||||||
|
<div id="archive-filters" class="xarxaprod-filters">
|
||||||
|
<?php
|
||||||
|
// output all possible values of a checkbox
|
||||||
|
$groupkey = "group_65d86bf0666a2"; // write here the key for the group of fields from acf
|
||||||
|
if( $groupkey ) {
|
||||||
|
?>
|
||||||
|
<?php // start the form ?>
|
||||||
|
<form id="form-associats" name="search-associats">
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$groupkey_fields = acf_get_fields($groupkey);
|
||||||
|
foreach( $groupkey_fields as $field_key ) {
|
||||||
|
|
||||||
|
if( $field_key['type'] == 'checkbox' ){
|
||||||
|
|
||||||
|
// https://wordpress.stackexchange.com/a/102915
|
||||||
|
$fields = get_field_object($field_key['key']);
|
||||||
|
if( $fields ) {
|
||||||
|
|
||||||
|
// check for values from meta fields db in url
|
||||||
|
foreach( $GLOBALS['my_query_filters_associat'] as $key => $fieldname ) {
|
||||||
|
|
||||||
|
// check for values in url and get value if available
|
||||||
|
if( isset($_GET[ $fieldname ]) ) {
|
||||||
|
$filteredvalues['value'] = explode(',', $_GET[ $fieldname ]);
|
||||||
|
} else {
|
||||||
|
$filteredvalues['value'] = [];
|
||||||
|
};
|
||||||
|
//end check for values in url
|
||||||
|
|
||||||
|
// construct the checkboxes
|
||||||
|
if( $fieldname == $fields['name']) {
|
||||||
|
?>
|
||||||
|
|
||||||
|
<section id="call-filter call-filter-<?php echo $fields['name']; ?>" class="<?php echo $fields['name']; ?>">
|
||||||
|
<h5 class="xarxaprod-titol-opcions"><?php echo $fields['label'];?></h5>
|
||||||
|
<?php foreach( $fields['choices'] as $choicevalue => $choicelabel ) { ?>
|
||||||
|
|
||||||
|
<div class="filter" data-filter="<?php echo $fields['name'];?>">
|
||||||
|
<input class="xarxaprod-filter" type="checkbox" name="<?php echo $fields['name'];?>" <?php if( in_array( $choicevalue, $filteredvalues['value']) ) { echo 'checked'; } ?> value="<?php echo $choicevalue; ?>" />
|
||||||
|
<label for="<?php echo $choicevalue; ?>"><?php echo $choicelabel;?></label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php };//end foreach fields['choices'] ?>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<?php }; //end if fieldname == fields['name'] ?>
|
||||||
|
<?php // end of construct checkboxes ?>
|
||||||
|
|
||||||
|
<?php }; // end check for values from meta fields db in url ?>
|
||||||
|
|
||||||
|
<?php }; //end if field_key['key'] ?>
|
||||||
|
|
||||||
|
<?php }; //end if type checkbox ?>
|
||||||
|
|
||||||
|
<?php }; //end foreach groupkey field ?>
|
||||||
|
<?php //echo '<p><span id="filterlink"></span></p>';?>
|
||||||
|
<p><a id="submitfilteredlink" name="submit-associat" class="button button-more" href="">filtrar</a> </p>
|
||||||
|
</form>
|
||||||
|
<?php //close the form and subit ?>
|
||||||
|
|
||||||
|
<?php }; //end if groupkey ?>
|
||||||
|
<aside id="search-form-associats" class="xarxaprod-search-associats">
|
||||||
|
<?php
|
||||||
|
// search form for custom post type 'xarxaprod-associat'
|
||||||
|
// <input type="hidden" value="xarxaprod-associat" name="post_type" id="post_type" />
|
||||||
|
// https://developer.wordpress.org/reference/functions/get_search_form/#comment-369
|
||||||
|
// https://wordpress.stackexchange.com/questions/313037/restrict-a-sear ch-to-a-custom-post-type
|
||||||
|
?>
|
||||||
|
<form class="xarxaprod-search-form" role="search" method="get" action="/">
|
||||||
|
<label class="screen-reader-text" for="search">Search in associats</label>
|
||||||
|
<input type="search" id="search" class="search-field" placeholder="cerca amb paraula clau..." value="<?php the_search_query(); ?>" name="s" />
|
||||||
|
<input type="submit" id="searchsubmit" class="search-submit" value="cerca">
|
||||||
|
<span class="xarxaprod-search-submit xarxaprod-icon-search"></span>
|
||||||
|
<input type="hidden" value="xarxaprod-associat" name="post_type" id="post_type" />
|
||||||
|
</form>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
(function($) {
|
||||||
|
// https://stackoverflow.com/a/12025482
|
||||||
|
// change
|
||||||
|
$('#archive-filters').on('click', 'input', function(){
|
||||||
|
|
||||||
|
// vars
|
||||||
|
var url = '<?php echo home_url('associat/'); ?>'; //insert the custom-post-type slug
|
||||||
|
args = {};
|
||||||
|
var appendtoURL = '';
|
||||||
|
var eachfiltered = '';
|
||||||
|
var valueschecked = '';
|
||||||
|
|
||||||
|
// loop over filters
|
||||||
|
$('#archive-filters .filter').each(function(){
|
||||||
|
// check if is first appearance of each
|
||||||
|
if( eachfiltered != $(this).data('filter') ){
|
||||||
|
// save already calculated field=val01,val02,val03
|
||||||
|
if( eachfiltered != '' && valueschecked != '' ){
|
||||||
|
// remove last ','
|
||||||
|
valueschecked = valueschecked.slice(0, -1);
|
||||||
|
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
||||||
|
};
|
||||||
|
// start new fieldname filtered
|
||||||
|
eachfiltered = $(this).data('filter');
|
||||||
|
// reset values
|
||||||
|
valueschecked = '';
|
||||||
|
// find checked inputs
|
||||||
|
$(this).find('input:checked').each(function(){
|
||||||
|
// if not empty save value and ,
|
||||||
|
if( $(this).val() != '' ){
|
||||||
|
valueschecked += $(this).val() + ',';
|
||||||
|
};
|
||||||
|
});
|
||||||
|
//alert( appendtoURL +":" +eachfiltered +"=" +valuescheked);
|
||||||
|
} else {
|
||||||
|
// we have previous values checked
|
||||||
|
// find checked inputs
|
||||||
|
//if( $(this).val() != '' ){
|
||||||
|
// if not empty append value and ,
|
||||||
|
$(this).find('input:checked').each(function(){
|
||||||
|
valueschecked += $(this).val() + ',';
|
||||||
|
});
|
||||||
|
//alert( appendtoURL +":not:" +eachfiltered +"=" +valuescheked);
|
||||||
|
//};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove last ','
|
||||||
|
valueschecked = valueschecked.slice(0, -1);
|
||||||
|
// save last cycled filtered value already calculated field=val01,val02,val03
|
||||||
|
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
||||||
|
|
||||||
|
// remove last &
|
||||||
|
appendtoURL = appendtoURL.slice(0, -1);
|
||||||
|
|
||||||
|
// update url
|
||||||
|
url += '?' +appendtoURL;
|
||||||
|
|
||||||
|
// show or modify the url
|
||||||
|
//alert( url );
|
||||||
|
//$('#filterlink').text(url);
|
||||||
|
|
||||||
|
// convert a href url to new value
|
||||||
|
$('#submitfilteredlink').attr('href',url);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
})(jQuery);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
|
}; //end xarxaprod_associats_filters_form
|
||||||
|
}; // end if ! functions_exists
|
||||||
|
?>
|
|
@ -0,0 +1,79 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Makes a filter for the custom post type associats and its custom fields
|
||||||
|
*
|
||||||
|
* references:
|
||||||
|
* basic start
|
||||||
|
* https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/
|
||||||
|
*
|
||||||
|
* checkbox adaptation query filter
|
||||||
|
* https://barn2.com/blog/querying-posts-by-custom-field-acf/#array-based-fields
|
||||||
|
*
|
||||||
|
* @package Xarxaprod_wp_plugin
|
||||||
|
*/
|
||||||
|
|
||||||
|
// define the filter fields
|
||||||
|
// array of filters (field key => field name)
|
||||||
|
$GLOBALS['my_query_filters_associat'] = array(
|
||||||
|
'associatfield' => 'xxp_associat_field', //disciplines
|
||||||
|
'associatterritory' => 'xxp_associat_territory', //territori
|
||||||
|
'associatservice' => 'xxp_associat_service', //serveis
|
||||||
|
'associatcenter' => 'xxp_associat_center' //centre
|
||||||
|
|
||||||
|
);
|
||||||
|
$GLOBALS['my_query_filters_associat_dates'] = array(
|
||||||
|
'associatapplybegin' => 'xxp_associat_apply_begin',
|
||||||
|
'associatapplyend' => 'xxp_associat_apply_end'
|
||||||
|
//'associatcall' => 'xxp_associat_call',
|
||||||
|
);
|
||||||
|
|
||||||
|
// action
|
||||||
|
add_action('pre_get_posts', 'my_pre_get_posts_associats',10,1);
|
||||||
|
if ( ! function_exists( 'my_pre_get_posts_associats' ) ){
|
||||||
|
function my_pre_get_posts_associats( $query ) {
|
||||||
|
|
||||||
|
// bail early if is in admin
|
||||||
|
if( is_admin() ) { return; }
|
||||||
|
|
||||||
|
// bail early if not main query or plugin $the_query_associat
|
||||||
|
// - allows custom code / plugins to continue working
|
||||||
|
if( !$query->is_main_query() ) return;
|
||||||
|
$query->set( 'posts_per_page', -1);
|
||||||
|
//$query->set( 'relation', 'AND');
|
||||||
|
|
||||||
|
// loop over filters
|
||||||
|
foreach( $GLOBALS['my_query_filters_associat'] as $key => $fieldname)
|
||||||
|
{
|
||||||
|
// continue if not found in url
|
||||||
|
if( empty($_GET[ $fieldname ]) ) { continue; }
|
||||||
|
|
||||||
|
// get original meta query
|
||||||
|
$meta_query = []; //avoids infinite nesting
|
||||||
|
$meta_query[] = $query->get('meta_query');
|
||||||
|
|
||||||
|
// get the values for this filter
|
||||||
|
// eg: http://domain.tdl/associat/?xxp_associat_target=autonoma,entitat-publica
|
||||||
|
$filtervalues= explode(',', $_GET[ $fieldname ]);
|
||||||
|
|
||||||
|
// loop retreived values from checkboxes and filter them
|
||||||
|
foreach( $filtervalues as $filteredvalue )
|
||||||
|
{
|
||||||
|
|
||||||
|
// add our meta query to the original meta queries
|
||||||
|
$meta_query['relation'] = 'OR';
|
||||||
|
$meta_query[] = array(
|
||||||
|
'key' => $fieldname,
|
||||||
|
'value' => $filteredvalue,
|
||||||
|
'compare' => 'LIKE'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// update the meta query arguments
|
||||||
|
$query->set('meta_query', $meta_query);
|
||||||
|
//$query->set('relation', 'AND');
|
||||||
|
}
|
||||||
|
//echo '<pre>' . var_export($query, true) . '</pre>';
|
||||||
|
//echo '<pre>' . print_r($query,true) . '</pre>';
|
||||||
|
//always return
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -80,7 +80,7 @@ if( ! function_exists( 'xarxaprod_convos_filters_form') ) {
|
||||||
|
|
||||||
<?php }; //end foreach groupkey field ?>
|
<?php }; //end foreach groupkey field ?>
|
||||||
<?php //echo '<p><span id="filterlink"></span></p>';?>
|
<?php //echo '<p><span id="filterlink"></span></p>';?>
|
||||||
<p><a id="submitfilteredlink" name="submit-convo" class="button button-more" href="">enviar</a> </p>
|
<p><a id="submitfilteredlink" name="submit-convo" class="button button-more" href="">filtrar</a> </p>
|
||||||
</form>
|
</form>
|
||||||
<?php //close the form and subit ?>
|
<?php //close the form and subit ?>
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ if( ! function_exists( 'xarxaprod_convos_filters_form') ) {
|
||||||
$('#archive-filters').on('click', 'input', function(){
|
$('#archive-filters').on('click', 'input', function(){
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
var url = '<?php echo home_url('convos/'); ?>';
|
var url = '<?php echo home_url('convos/'); ?>'; //insert the custom-post-type slug
|
||||||
args = {};
|
args = {};
|
||||||
var appendtoURL = '';
|
var appendtoURL = '';
|
||||||
var eachfiltered = '';
|
var eachfiltered = '';
|
||||||
|
|
|
@ -0,0 +1,241 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Custom post type Espais Associats.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @link https://xarxaprod.cat
|
||||||
|
* @since 1.0.0
|
||||||
|
* @package xarxaprod-wp-plugin
|
||||||
|
* @subpackage xarxaprod-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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start custom post types
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/
|
||||||
|
* https://developer.wordpress.org/reference/functions/register_post_type/
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Register Custom Post Type
|
||||||
|
if ( ! function_exists('xarxaprod_wpplugin_custom_post_associat_init') ){
|
||||||
|
function xarxaprod_wpplugin_custom_post_associat_init() {
|
||||||
|
|
||||||
|
$labels = array(
|
||||||
|
'name' => _x( 'Associats', 'Post Tipu General Name', 'text_domain' ),
|
||||||
|
'singular_name' => _x( 'Associat', 'Post Tipu Singular Name', 'text_domain' ),
|
||||||
|
'menu_name' => __( 'Associats', 'text_domain' ),
|
||||||
|
'parent_item_colon' => __( 'Associats mare/pare:', 'text_domain' ),
|
||||||
|
'all_items' => __( 'Tots els associats', 'text_domain' ),
|
||||||
|
'view_item' => __( 'Mostra els associats', 'text_domain' ),
|
||||||
|
'add_new_item' => __( 'Affegeix un associat', 'text_domain' ),
|
||||||
|
'add_new' => __( 'Affegeix associat', 'text_domain' ),
|
||||||
|
'edit_item' => __( 'Edita associat', 'text_domain' ),
|
||||||
|
'update_item' => __( 'Desa associat', 'text_domain' ),
|
||||||
|
'search_items' => __( 'Cerca associat', 'text_domain' ),
|
||||||
|
'not_associat' => __( 'No hem pogut trovar ningúna associat', 'text_domain' ),
|
||||||
|
'not_associat_in_trash' => __( 'No hem trovat cap associat a la brosa', 'text_domain' )
|
||||||
|
);
|
||||||
|
$rewrite = array(
|
||||||
|
'slug' => 'associat'
|
||||||
|
);
|
||||||
|
// https://wordpress.stackexchange.com/questions/108338/capabilities-and-custom-post-types#108375
|
||||||
|
// https://developer.wordpress.org/reference/functions/register_post_type/#capability_type
|
||||||
|
//$capabilities = array(
|
||||||
|
// 'read' => 'read_associat',
|
||||||
|
// 'publish_posts' => 'publish_associat',
|
||||||
|
// 'edit_posts' => 'edit_associat',
|
||||||
|
// 'edit_published_posts' => 'edit_published_associat',
|
||||||
|
// 'edit_others_posts' => 'edit_others_associat',
|
||||||
|
// 'delete_posts' => 'delete_associat',
|
||||||
|
// 'delete_published_posts' => 'delete_published_associat',
|
||||||
|
// 'delete_others_posts' => 'delete_others_associat',
|
||||||
|
// 'delete_private_posts' => 'delete_private_associat'
|
||||||
|
// );
|
||||||
|
$args = array(
|
||||||
|
'label' => __( 'xarxaprod-associat', 'text_domain' ),
|
||||||
|
'description' => __( 'Associats', 'text_domain' ),
|
||||||
|
'labels' => $labels,
|
||||||
|
'supports' => array( 'title', 'editor', 'thumbnail', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ),
|
||||||
|
//'supports' => array( 'title', 'editor', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ),
|
||||||
|
// 'taxonomies' => array(
|
||||||
|
// 'xarxaprod-associat-category',
|
||||||
|
// 'xarxaprod-associat-tag'
|
||||||
|
// ),
|
||||||
|
'hierarchical' => true,
|
||||||
|
'public' => true,
|
||||||
|
'show_ui' => true,
|
||||||
|
'show_in_menu' => true,
|
||||||
|
'show_in_nav_menus' => true,
|
||||||
|
'show_in_admin_bar' => true,
|
||||||
|
'show_in_rest' => true,
|
||||||
|
'menu_position' => 5,
|
||||||
|
'menu_icon' => 'dashicons-groups',
|
||||||
|
'can_export' => true,
|
||||||
|
'has_archive' => true,
|
||||||
|
'exclude_from_search' => false,
|
||||||
|
'publicly_queryable' => true,
|
||||||
|
'capability_type' => 'post',
|
||||||
|
'rewrite' => $rewrite,
|
||||||
|
//'capabilities' => $capabilities,
|
||||||
|
//'map_meta_cap' => true //neded to apply the new capabilities.
|
||||||
|
);
|
||||||
|
register_post_type( 'xarxaprod-associat', $args );
|
||||||
|
}
|
||||||
|
}// end function_exists xarxaprod_wpplugin_custom_post_associat_init
|
||||||
|
// Hook into the 'init' action
|
||||||
|
add_action( 'init', 'xarxaprod_wpplugin_custom_post_associat_init', 0 );
|
||||||
|
|
||||||
|
|
||||||
|
// flush rewrite and when changing theme or plugin
|
||||||
|
// https://developer.wordpress.org/reference/functions/register_post_type/#flushing-rewrite-on-activation
|
||||||
|
if ( ! function_exists( 'xarxaprod_associat_rewrite_flush') ){
|
||||||
|
function xarxaprod_associat_rewrite_flush() {
|
||||||
|
xarxaprod_wpplugin_custom_post_associat_init();
|
||||||
|
flush_rewrite_rules();
|
||||||
|
}
|
||||||
|
}// end function_exists xarxaprod_associat_rewrite_flush
|
||||||
|
add_action( 'after_switch_theme', 'xarxaprod_associat_rewrite_flush' );
|
||||||
|
|
||||||
|
// give capabilities once the custom post id activated
|
||||||
|
// function xarxaprod_wpplugin_add_caps() {
|
||||||
|
// gets the XX role
|
||||||
|
// $admins = get_role( '' );
|
||||||
|
// $admins->add_cap( );
|
||||||
|
// gets the administrator role
|
||||||
|
|
||||||
|
|
||||||
|
//}
|
||||||
|
//add_action( 'admin_init', 'xarxaprod_wpplugin_add_caps');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start custom taxonomies
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* https://developer.wordpress.org/plugins/taxonomies/working-with-custom-taxonomies/
|
||||||
|
* https://developer.wordpress.org/reference/functions/register_taxonomy/
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Register Custom Taxonomy Category for Associats
|
||||||
|
//function xarxaprod_wpplugin_associat_category_register() {
|
||||||
|
|
||||||
|
// $labels = array(
|
||||||
|
// 'name' => _x( 'Associats Tipus', 'Taxonomy General Name', 'text_domain' ),
|
||||||
|
// 'singular_name' => _x( 'Tipus d`associat', 'Taxonomy Singular Name', 'text_domain' ),
|
||||||
|
// 'menu_name' => __( 'Associats Tipus', 'text_domain' ),
|
||||||
|
// 'all_items' => __( 'All type associat', 'text_domain' ),
|
||||||
|
// 'parent_item' => __( 'Parent type associat', 'text_domain' ),
|
||||||
|
// 'parent_item_colon' => __( 'Parent type associat:', 'text_domain' ),
|
||||||
|
// 'new_item_name' => __( 'New type associat', 'text_domain' ),
|
||||||
|
// 'add_new_item' => __( 'Add New type associat', 'text_domain' ),
|
||||||
|
// 'edit_item' => __( 'Edit type associat', 'text_domain' ),
|
||||||
|
// 'update_item' => __( 'Update type of associat', 'text_domain' ),
|
||||||
|
// 'separate_items_with_commas' => __( 'Separate type associat with commas', 'text_domain' ),
|
||||||
|
// 'search_items' => __( 'Search type of associat', 'text_domain' ),
|
||||||
|
// 'add_or_remove_items' => __( 'Add or remove type of associat', 'text_domain' ),
|
||||||
|
// 'choose_from_most_used' => __( 'Choose from the most used type of associat', 'text_domain' ),
|
||||||
|
// 'not_associat' => __( 'Tipus d`associat Not Associat', 'text_domain' )
|
||||||
|
// );
|
||||||
|
// $rewrite = array(
|
||||||
|
// 'slug' => 'associat-tipus'
|
||||||
|
// );
|
||||||
|
// //$capabilities = array(
|
||||||
|
// // 'manage_terms' => 'Xarxaprod Manage associat Tipus',
|
||||||
|
// // 'edit_terms' => 'Xarxaprod Edit associat Tipus',
|
||||||
|
// // 'delete_terms' => 'Xarxaprod Delete associat Tipus',
|
||||||
|
// // 'assign_terms' => 'Xarxaprod Assign associat Tipus',
|
||||||
|
// // );
|
||||||
|
// $args = array(
|
||||||
|
// 'labels' => $labels,
|
||||||
|
// 'hierarchical' => true,
|
||||||
|
// 'public' => true,
|
||||||
|
// 'show_ui' => true,
|
||||||
|
// 'show_admin_column' => true,
|
||||||
|
// 'show_in_nav_menus' => true,
|
||||||
|
// 'show_tagcloud' => false,
|
||||||
|
// 'rewrite' => $rewrite,
|
||||||
|
// //'capabilities' => $capabilities,
|
||||||
|
// 'map_meta_cap' => true //neded to apply the new capabilities.
|
||||||
|
|
||||||
|
// );
|
||||||
|
// register_taxonomy( 'xarxaprod-associat-category', array( 'xarxaprod-associat' ) , $args );
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Hook into the 'init' action
|
||||||
|
//add_action( 'init', 'xarxaprod_wpplugin_associat_category_register', 0 );
|
||||||
|
|
||||||
|
// Register Custom Taxonomy Tag for Associats
|
||||||
|
// function xarxaprod_wpplugin_associat_tag_register() {
|
||||||
|
//
|
||||||
|
// $labels = array(
|
||||||
|
// 'name' => _x( 'Associats Tags', 'Taxonomy General Name', 'text_domain' ),
|
||||||
|
// 'singular_name' => _x( 'Associat Tag', 'Taxonomy Singular Name', 'text_domain' ),
|
||||||
|
// 'menu_name' => __( 'Associats Tags', 'text_domain' ),
|
||||||
|
// 'all_items' => __( 'All associat tags', 'text_domain' ),
|
||||||
|
// 'parent_item' => __( 'Parent associat tag', 'text_domain' ),
|
||||||
|
// 'parent_item_colon' => __( 'Parent associat tag:', 'text_domain' ),
|
||||||
|
// 'new_item_name' => __( 'New associat tag', 'text_domain' ),
|
||||||
|
// 'add_new_item' => __( 'Add New associat tag', 'text_domain' ),
|
||||||
|
// 'edit_item' => __( 'Edit associat tag', 'text_domain' ),
|
||||||
|
// 'update_item' => __( 'Update associat tag', 'text_domain' ),
|
||||||
|
// 'separate_items_with_commas' => __( 'Separate associat tag with commas', 'text_domain' ),
|
||||||
|
// 'search_items' => __( 'Search associat tags', 'text_domain' ),
|
||||||
|
// 'add_or_remove_items' => __( 'Add or remove associat tag', 'text_domain' ),
|
||||||
|
// 'choose_from_most_used' => __( 'Choose from the most used associat tags', 'text_domain' ),
|
||||||
|
// 'not_associat' => __( 'Associat tag Not Associat', 'text_domain' ),
|
||||||
|
// );
|
||||||
|
// $rewrite = array(
|
||||||
|
// 'slug' => 'associat-tag',
|
||||||
|
// // 'with_front' => false,
|
||||||
|
// );
|
||||||
|
// //$capabilities = array(
|
||||||
|
// // 'manage_terms' => 'Xarxaprod Manage associat Tag',
|
||||||
|
// // 'edit_terms' => 'Xarxaprod Edit associat Tag',
|
||||||
|
// // 'delete_terms' => 'Xarxaprod Delete associat Tag',
|
||||||
|
// // 'assign_terms' => 'Xarxaprod Assign associat Tag',
|
||||||
|
// // );
|
||||||
|
//
|
||||||
|
// $args = array(
|
||||||
|
// 'labels' => $labels,
|
||||||
|
// 'hierarchical' => false,
|
||||||
|
// 'public' => true,
|
||||||
|
// 'show_ui' => true,
|
||||||
|
// 'show_admin_column' => true,
|
||||||
|
// 'show_in_nav_menus' => true,
|
||||||
|
// 'show_tagcloud' => true,
|
||||||
|
// 'rewrite' => $rewrite,
|
||||||
|
// //'capabilities' => $capabilities,
|
||||||
|
// 'map_meta_cap' => true //neded to apply the new capabilities.
|
||||||
|
// );
|
||||||
|
// register_taxonomy( 'xarxaprod-associat-tag', array( 'xarxaprod-associat' ) , $args );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Hook into the 'init' action
|
||||||
|
//add_action( 'init', 'xarxaprod_wpplugin_associat_tag_register', 0 );
|
||||||
|
|
||||||
|
// changing the permalink
|
||||||
|
// https://wordpress.stackexchange.com/questions/108642/permalinks-custom-post-type-custom-taxonomy-post
|
||||||
|
// change in register_post_type the slug 'rewrite' to this
|
||||||
|
// $rewrite = array(
|
||||||
|
// 'slug' => 'associat/%xarxaprod-associat-category%',
|
||||||
|
// 'with_front' => true,
|
||||||
|
// 'hierarchical' => true,
|
||||||
|
// );
|
||||||
|
// uncomment below
|
||||||
|
//
|
||||||
|
// function xarxaprod_wpplugin_associat_and_category_permalink( $post_link, $id = 0 ){
|
||||||
|
// $post = get_post($id);
|
||||||
|
// if ( is_object( $post ) && $post->post_type == 'xarxaprod-associat' ){
|
||||||
|
// $terms = wp_get_object_terms( $post->ID, 'xarxaprod-associat-category' );
|
||||||
|
// if( $terms ){
|
||||||
|
// return str_replace( '%xarxaprod-associat-category%' , $terms[0]->slug , $post_link );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return $post_link;
|
||||||
|
// }
|
||||||
|
// add_filter( 'post_type_link', 'xarxaprod_wpplugin_associat_and_category_permalink', 1, 2 );
|
|
@ -11,9 +11,10 @@
|
||||||
* @subpackage xarxaprod-wp-plugin/includes
|
* @subpackage xarxaprod-wp-plugin/includes
|
||||||
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
|
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
|
||||||
*/
|
*/
|
||||||
|
if (! function_exists ('enable_mime_types') ){
|
||||||
function enable_mime_types( $mimes ) {
|
function enable_mime_types( $mimes ) {
|
||||||
$mimes['svg'] = 'image/svg+xml';
|
$mimes['svg'] = 'image/svg+xml';
|
||||||
return $mimes;
|
return $mimes;
|
||||||
}
|
}
|
||||||
add_filter('upload_mimes', 'enable_mime_types');
|
add_filter('upload_mimes', 'enable_mime_types');
|
||||||
|
}
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
* @subpackage xarxaprod-wp-plugin/includes
|
* @subpackage xarxaprod-wp-plugin/includes
|
||||||
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
|
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
|
||||||
*/
|
*/
|
||||||
|
if (! function_exists ('xarxaprod_wpplugin_init_textdomain') ){
|
||||||
function xarxaprod_wpplugin_init_textdomain() {
|
function xarxaprod_wpplugin_init_textdomain() {
|
||||||
load_plugin_textdomain( 'xarxaprod-wpplugin-textdomain', null, plugin_dir_path( __FILE__ ).'/assets/languages/' );
|
load_plugin_textdomain( 'xarxaprod-wpplugin-textdomain', null, plugin_dir_path( __FILE__ ).'/assets/languages/' );
|
||||||
}
|
}
|
||||||
add_action('plugins_loaded', 'xarxaprod_wpplugin_init_textdomain');
|
add_action('plugins_loaded', 'xarxaprod_wpplugin_init_textdomain');
|
||||||
|
}
|
||||||
|
|
|
@ -19,227 +19,157 @@
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* custom option and settings
|
* @internal never define functions inside callbacks.
|
||||||
*/
|
* these functions could be run multiple times; this would result in a fatal error.
|
||||||
if( ! function_exists('xarxaprod_wpplugin_settings_init') ){
|
*/
|
||||||
function xarxaprod_wpplugin_settings_init() {
|
|
||||||
// register a new setting for "xarxaprod_wpplugin" page
|
|
||||||
register_setting( 'xarxaprod_wpplugin_settings', 'xarxaprod_wpplugin_options' );
|
|
||||||
|
|
||||||
// register a new section in the "xarxaprod_wpplugin" page
|
/**
|
||||||
|
* custom option and settings
|
||||||
|
*/
|
||||||
|
function xarxaprod_plugin_settings_init() {
|
||||||
|
// Register a new setting for "xxpplugin" page.
|
||||||
|
register_setting( 'xxpplugin', 'xarxaprod_plugin_options' );
|
||||||
|
|
||||||
|
// Register a new section in the "xxpplugin" page.
|
||||||
add_settings_section(
|
add_settings_section(
|
||||||
'xarxaprod_wpplugin_section_control_home',
|
'xarxaprod_plugin_section_options',
|
||||||
__( 'Home control.', 'xarxaprod-wpplugin-textdomain' ),
|
__( 'Control de les opcions de la web Xarxaprod', 'xxpplugin' ), 'xarxaprod_plugin_section_options_callback',
|
||||||
'xarxaprod_wpplugin_section_control_home_cb',
|
'xxpplugin'
|
||||||
'xarxaprod_wpplugin_settings'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Register a new field in the "xarxaprod_plugin_section_options" section, inside the "xxpplugin" page.
|
||||||
// register a new field in the "xarxaprod_wpplugin_section_control_home" section, inside the "xarxaprod_wpplugin" page
|
|
||||||
//
|
|
||||||
// uncoment below to activate
|
|
||||||
// add_settings_field(
|
|
||||||
// 'xarxaprod_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:', 'xarxaprod-wpplugin-textdomain' ),
|
|
||||||
// 'xarxaprod_wpplugin_field_control_home_cb',
|
|
||||||
// 'xarxaprod_wpplugin_settings',
|
|
||||||
// 'xarxaprod_wpplugin_section_control_home'
|
|
||||||
// );
|
|
||||||
|
|
||||||
// register a new section in the "xarxaprod_wpplugin" page
|
|
||||||
add_settings_section(
|
|
||||||
'xarxaprod_wpplugin_section_reusableblocks',
|
|
||||||
__( 'Reusable blocks.', 'xarxaprod-wpplugin-textdomain' ),
|
|
||||||
'xarxaprod_wpplugin_section_reusableblocks_cb',
|
|
||||||
'xarxaprod_wpplugin_reusableblocks'
|
|
||||||
);
|
|
||||||
// register a new field in the "xarxaprod_wpplugin_section_reusableblocks" section, inside the "xarxaprod_wpplugin" page
|
|
||||||
//
|
|
||||||
// uncoment below to activate
|
|
||||||
add_settings_field(
|
add_settings_field(
|
||||||
'xarxaprod_wpplugin_field_reusableblocks', // as of WP 4.6 this value is used only internally
|
'xarxaprod_plugin_field_reusableblocks', // 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.
|
||||||
__( 'Follow this link to edit the reusable blocks <a href="' . admin_url() . 'edit.php?post_type=wp_block" class="but.ton"> Reusable blocks</a>', 'xarxaprod-wpplugin-textdomain' ),
|
__( 'Reusable blocks', 'xxpplugin' ),
|
||||||
'xarxaprod_wpplugin_field_reusableblocks_cb',
|
'xarxaprod_plugin_field_reusableblocks_cb',
|
||||||
'xarxaprod_wpplugin_settings',
|
'xxpplugin',
|
||||||
'xarxaprod_wpplugin_section_reusableblocks',
|
'xarxaprod_plugin_section_options',
|
||||||
|
array(
|
||||||
// edit.php?post_type=wp_block
|
'label_for' => 'xarxaprod_plugin_field_reusableblocks',
|
||||||
|
'class' => 'xarxaprod_plugin_row',
|
||||||
|
'xarxaprod_plugin_custom_data' => 'custom',
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// register a new section in the "xarxaprod_wpplugin" page
|
|
||||||
//
|
|
||||||
// uncoment below to activate
|
|
||||||
|
|
||||||
// add_settings_section(
|
|
||||||
// 'xarxaprod_wpplugin_section_olderthandate',
|
|
||||||
// __( 'Older than options.', 'xarxaprod-wpplugin-textdomain' ),
|
|
||||||
// 'xarxaprod_wpplugin_section_olderthandate_cb',
|
|
||||||
// 'xarxaprod_wpplugin_settings'
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
|
||||||
// register a new field in the "xarxaprod_wpplugin_section_olderthandate" section, inside the "xarxaprod_wpplugin" page
|
|
||||||
//
|
|
||||||
// uncoment below to activate
|
|
||||||
|
|
||||||
// add_settings_field(
|
|
||||||
// 'xarxaprod_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...', 'xarxaprod-wpplugin-textdomain' ),
|
|
||||||
// 'xarxaprod_wpplugin_field_olderthandate_cb',
|
|
||||||
// 'xarxaprod_wpplugin_settings',
|
|
||||||
// 'xarxaprod_wpplugin_section_olderthandate',
|
|
||||||
// [
|
|
||||||
// 'label_for' => 'xarxaprod_wpplugin_field_olderthandate',
|
|
||||||
// 'class' => 'xarxaprod-wpplugin-row',
|
|
||||||
// 'xarxaprod_wpplugin_custom_data' => 'custom',
|
|
||||||
// ]
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register our xarxaprod_plugin_settings_init to the admin_init action hook.
|
||||||
|
*/
|
||||||
|
add_action( 'admin_init', 'xarxaprod_plugin_settings_init' );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register our xarxaprod_wpplugin_settings_init to the admin_init action hook
|
* Custom option and settings:
|
||||||
*/
|
* - callback functions
|
||||||
add_action( 'admin_init', 'xarxaprod_wpplugin_settings_init' );
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* custom option and settings:
|
* Xarxaprod section callback function.
|
||||||
* callback functions
|
*
|
||||||
*/
|
* @param array $args The settings array, defining title, id, callback.
|
||||||
|
*/
|
||||||
|
function xarxaprod_plugin_section_options_callback( $args ) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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('xarxaprod_wpplugin_section_olderthandate_cb') ){
|
|
||||||
function xarxaprod_wpplugin_section_olderthandate_cb( $args ) {
|
|
||||||
?>
|
?>
|
||||||
<p id="<?php echo esc_attr( $args['id'] ); ?>">
|
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'Aquestes son las opcions de la pagina Xarxaprod 2023. Pots modificar i pots seguir els links dels botons.', 'xxpplugin' ); ?></p>
|
||||||
<?php esc_html_e( 'Here you should set the options for the older content to be marked as it.', 'xarxaprod-wpplugin-textdomain' ); ?>
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reusable Blocks field callbakc 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.
|
||||||
|
* Note: you can add custom key value pairs to be used inside your callbacks.
|
||||||
|
*
|
||||||
|
* @param array $args
|
||||||
|
*/
|
||||||
|
function xarxaprod_plugin_field_reusableblocks_cb( $args ) {
|
||||||
|
// Get the value of the setting we've registered with register_setting()
|
||||||
|
$options = get_option( 'xarxaprod_plugin_options' );
|
||||||
|
?>
|
||||||
|
<p class="">
|
||||||
|
<a href="<?php echo admin_url(); ?>edit.php?post_type=wp_block" class="button">Reusable Blocks</a>
|
||||||
|
<?php esc_html_e( 'Si vols modificar els blocks reutilizables (els de color violeta) de las págines i entrades, fes click al botó.', 'xxpplugin' ); ?>
|
||||||
</p>
|
</p>
|
||||||
<?php
|
<?php
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// daysback field cb
|
/**
|
||||||
|
* Lite Youtube Embed field callbakc function.
|
||||||
// field callbacks can accept an $args parameter, which is an array.
|
* https://wordpress.org/plugins/lite-embed-for-youtube
|
||||||
// $args is defined at the add_settings_field() function.
|
* https://github.com/paulirish/lite-youtube-embed
|
||||||
// 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>.
|
* WordPress has magic interaction with the following keys: label_for, class.
|
||||||
// the "class" key value is used for the "class" attribute of the <tr> containing the field.
|
* - the "label_for" key value is used for the "for" attribute of the <label>.
|
||||||
// you can add custom key value pairs to be used inside your callbacks.
|
* - the "class" key value is used for the "class" attribute of the <tr> containing the field.
|
||||||
if( ! function_exists('xarxaprod_wpplugin_field_olderthandate_cb') ){
|
* Note: you can add custom key value pairs to be used inside your callbacks.
|
||||||
function xarxaprod_wpplugin_field_olderthandate_cb( $args ) {
|
*
|
||||||
// get the value of the setting we've registered with register_setting()
|
* @param array $args
|
||||||
$options = get_option( 'xarxaprod_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.', 'xarxaprod-wpplugin-textdomain' ); ?>
|
|
||||||
</p>
|
|
||||||
<form id="xarxaprod_wpplugin-oldpost-numberofdays" class="xarxaprod_wpplugin-oldpost-numberofdays">
|
|
||||||
<label for="xarxaprod_wpplugin-oldpost-numberofdays">Number of days:</label>
|
|
||||||
<input type="number" id="xarxaprod_wpplugin-oldpost-numberofdays" name="xarxaprod_wpplugin-oldpost-numberofdays" min="1" max="100">
|
|
||||||
</form>
|
|
||||||
<form id="xarxaprod_wpplugin-oldpost-enddate" class="xarxaprod_wpplugin-oldpost-enddate">
|
|
||||||
<label for="xarxaprod_wpplugin-oldpost-enddate">Start date:</label>
|
|
||||||
<input type="date" id="xarxaprod_wpplugin-oldpost-enddate" name="xarxaprod_wpplugin-oldpost-endate" value="">
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<!-- borrar desde aqui -->
|
|
||||||
<!--
|
|
||||||
<p>
|
|
||||||
label_for:
|
|
||||||
<?php //echo esc_attr( $args['label_for'] ); ?>
|
|
||||||
<br />
|
|
||||||
xarxaprod_wpplugin_custom_data:
|
|
||||||
<?php //echo esc_attr( $args['xarxaprod_wpplugin_custom_data'] ); ?>
|
|
||||||
<br />
|
|
||||||
class:
|
|
||||||
<?php //echo esc_attr( $args['class'] ); ?>
|
|
||||||
<br />
|
|
||||||
<?php //esc_html_e( 'daysback', 'xarxaprod-wpplugin-textdomain' ); ?>
|
|
||||||
<br />
|
|
||||||
</p>
|
|
||||||
-->
|
|
||||||
<!-- borrar hasta aqui -->
|
|
||||||
|
|
||||||
<?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/
|
||||||
*/
|
*/
|
||||||
if( ! function_exists('xarxaprod_wpplugin_options_page') ){
|
if( ! function_exists('xarxaprod_plugin_options_page') ){
|
||||||
function xarxaprod_wpplugin_options_page() {
|
function xarxaprod_plugin_options_page() {
|
||||||
// add top level menu page
|
// add top level menu page
|
||||||
add_menu_page(
|
add_menu_page(
|
||||||
$page_title = 'Xarxaprod plugin options', // $page_title
|
$page_title = 'Xarxaprod plugin options', // $page_title
|
||||||
$menu_title = 'Xarxaprod options', //$menu_title
|
$menu_title = 'Xarxaprod', //$menu_title
|
||||||
$capability = 'manage_options', //'edit_others_posts', // $capability
|
$capability = 'manage_options', //'edit_others_posts', // $capability
|
||||||
$menu_slug = 'xarxaprod-options', // $menu_slug
|
$menu_slug = 'xxpplugin-options', // $menu_slug
|
||||||
$function = 'xarxaprod_wpplugin_options_page_html', //$function
|
$function = 'xarxaprod_plugin_options_page_html', //$function
|
||||||
$icon_url = 'dashicons-rest-api',// $icon_url //https://developer.wordpress.org/resource/dashicons/#menu
|
$icon_url = 'dashicons-sos',// $icon_url //https://developer.wordpress.org/resource/dashicons/#menu
|
||||||
$position = '25'// $position
|
$position = '25'// $position
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// register our xarxaprod_wpplugin_options_page to the admin_menu action hook
|
|
||||||
add_action( 'admin_menu', 'xarxaprod_wpplugin_options_page' );
|
|
||||||
|
|
||||||
// top level menu: callback functions
|
|
||||||
if( ! function_exists('xarxaprod_wpplugin_options_page_html') ){
|
/**
|
||||||
function xarxaprod_wpplugin_options_page_html() {
|
* Register our xarxaprod_plugin_options_page to the admin_menu action hook.
|
||||||
|
*/
|
||||||
|
add_action( 'admin_menu', 'xarxaprod_plugin_options_page' );
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Top level menu callback function
|
||||||
|
*/
|
||||||
|
function xarxaprod_plugin_options_page_html() {
|
||||||
// check user capabilities
|
// check user capabilities
|
||||||
if ( ! current_user_can( 'manage_options' ) ) {
|
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.', 'xarxaprod-wpplugin-textdomain' ); ?>
|
|
||||||
</p>
|
|
||||||
<?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( 'xarxaprod_wpplugin_messages', 'xarxaprod_wpplugin_message', __( 'Settings Saved', 'xarxaprod-wpplugin-textdomain' ), 'updated' );
|
add_settings_error( 'xarxaprod_plugin_messages', 'xarxaprod_plugin_message', __( 'Settings Saved', 'xxpplugin' ), 'updated' );
|
||||||
}
|
}
|
||||||
|
|
||||||
// show error/update messages
|
// show error/update messages
|
||||||
settings_errors( 'xarxaprod_wpplugin_messages' );
|
settings_errors( 'xarxaprod_plugin_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 "xarxaprod_wpplugin"
|
// output security fields for the registered setting "xxpplugin"
|
||||||
settings_fields( 'xarxaprod_wpplugin_settings' );
|
settings_fields( 'xxpplugin' );
|
||||||
// output setting sections and their fields
|
// output setting sections and their fields
|
||||||
// (sections are registered for "xarxaprod_wpplugin", each field is registered to a specific section)
|
// (sections are registered for "xxpplugin", each field is registered to a specific section)
|
||||||
do_settings_sections( 'xarxaprod_wpplugin_settings' );
|
do_settings_sections( 'xxpplugin' );
|
||||||
// output save settings button
|
// output save settings button
|
||||||
submit_button( 'Save Settings' );
|
//submit_button( 'Save Settings' );
|
||||||
?>
|
?>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,9 @@
|
||||||
* @subpackage xarxaprod_wp-plugin/includes
|
* @subpackage xarxaprod_wp-plugin/includes
|
||||||
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
|
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
|
||||||
*/
|
*/
|
||||||
|
if (! function_exists ('xarxaprod_public_styles') ){
|
||||||
function xarxaprod_public_styles() {
|
function xarxaprod_public_styles() {
|
||||||
add_editor_style( 'assets/css/xarxaprod-wpplugin-styles.css' );
|
add_editor_style( 'assets/css/xarxaprod-wpplugin-styles.css' );
|
||||||
}
|
}
|
||||||
add_action( 'admin_init', 'xarxaprod_public_styles' );
|
add_action( 'admin_init', 'xarxaprod_public_styles' );
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* functions to displaying the map with all members
|
||||||
|
* depens on plugins: LeafletMaps, ACF fields
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @link https://xarxaprod.cat
|
||||||
|
* @since 1.0.0
|
||||||
|
* @package xarxaprod-wp-plugin
|
||||||
|
* @subpackage xarxaprod-wp-plugin/includes
|
||||||
|
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 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( 'leaflet-map/leaflet-map.php' ) ) {
|
||||||
|
// echo '<p class="warning">The plugin <a hfref="https://wordpress.org/plugins/leaflet-map/">LeafletMap</a> is needed to show this map</p>';
|
||||||
|
} else {
|
||||||
|
if (! function_exists( 'xarxaprod_show_leaflet_map' )) {
|
||||||
|
function xarxaprod_show_leaflet_map() {
|
||||||
|
// show the map
|
||||||
|
echo do_shortcode( '[leaflet-map fitbounds max_zoom="16" lat="41.3922" lng="2.1755" height="100%" width="100%" tileurl=https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png scrollwheel detect-retina]');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if ( ! is_plugin_active( 'acf-openstreetmap-field/index.php' ) ) {
|
||||||
|
echo '<p class="warning">The plugin <a hfref="https://wordpress.org/plugins/acf-openstreetmap-field/">ACF OpenStreetMap Field</a> is needed to show the points in the map</p>';
|
||||||
|
} else {
|
||||||
|
if (! function_exists( 'xarxaprod_show_leaflet_associat_blob' )) {
|
||||||
|
function xarxaprod_show_leaflet_associat_blob() {
|
||||||
|
// get the field values
|
||||||
|
// https://www.advancedcustomfields.com/resources/get_field/
|
||||||
|
// var_dump get_field('');
|
||||||
|
$args = get_field('xxp_associat_osm_map',false, false);
|
||||||
|
|
||||||
|
if ( count( $args['markers'] ) ) {
|
||||||
|
foreach ( $args['markers'] as $marker ) {
|
||||||
|
// define the fields for the blob
|
||||||
|
if ( get_field('xxp_associat_citymap') ){
|
||||||
|
// if city for map written use it
|
||||||
|
$associat_address = get_field('xxp_associat_citymap');
|
||||||
|
} else {
|
||||||
|
// else use the ACF OpenStreetMap nominatim value
|
||||||
|
$associat_address = $marker['label'];
|
||||||
|
};
|
||||||
|
$associat_name = esc_html( get_the_title() );
|
||||||
|
$associat_xxp_weblink = '<a href="'. get_the_permalink() . '">' . $associat_name . '</a>';
|
||||||
|
$associat_own_weblink = '<a href="' . get_field('xxp_associat_web') . '" class="">' . get_field('xxp_associat_web') . '</a>';
|
||||||
|
$associat_email = '<a href="mailto:' . get_field('xxp_associat_mail') . '" class="">' . get_field('xxp_associat_mail') . '</a>';
|
||||||
|
$associat_lat = $marker['lat'];
|
||||||
|
$associat_lng = $marker['lng'];
|
||||||
|
if( get_field('xxp_associat_colormap') ){ $associat_blobcolor = get_field('xxp_associat_colormap'); }else{ $associat_blobcolor = '#555'; };
|
||||||
|
echo do_shortcode( '
|
||||||
|
[leaflet-marker svg background="'. $associat_blobcolor . '" color="'. $associat_blobcolor . '" iconSize="22,22" iconClass="dashicons dashicons-info" opacity="0.6" title="' . $associat_name . '" lat=' . $associat_lat . ' lng=' . $associat_lng . ']'
|
||||||
|
. '<p>' . $associat_address . '</p>'
|
||||||
|
. '<h5><b>' . $associat_xxp_weblink . '</b></h5>'
|
||||||
|
. '<p>' . $associat_own_weblink . '</p>'
|
||||||
|
. '<p>' . $associat_email . '</p>'
|
||||||
|
. '[/leaflet-marker]'
|
||||||
|
); // end shortcode each marker
|
||||||
|
}; // end each marker
|
||||||
|
}; // end count all markers
|
||||||
|
};
|
||||||
|
}; //end function xarxaprod_show_leaflet_associat_blob
|
||||||
|
};//end ACF OpenStreetMap active
|
||||||
|
};
|
|
@ -10,7 +10,7 @@
|
||||||
* Plugin URI: https://git.hangar.org/xarxaprod/xarxaprod-wp-plugin
|
* Plugin URI: https://git.hangar.org/xarxaprod/xarxaprod-wp-plugin
|
||||||
* Description: Different needs for the Xarxaprod.cat Wordpress theme needs. Adds support for: SVG.
|
* Description: Different needs for the Xarxaprod.cat Wordpress theme needs. Adds support for: SVG.
|
||||||
* Date: 2023 12 29
|
* Date: 2023 12 29
|
||||||
* Version: 1.1.0
|
* Version: 1.3.0
|
||||||
* Author: jorge - vitrubio.net
|
* Author: jorge - vitrubio.net
|
||||||
* Author URI: https://vitrubio.net/
|
* Author URI: https://vitrubio.net/
|
||||||
* License: GPL 3.0
|
* License: GPL 3.0
|
||||||
|
@ -57,7 +57,7 @@ define( 'XARXAPROD_WPPLUGIN_URL', plugin_dir_url( __FILE__ ) ); //public
|
||||||
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/plugin-init-textdomain.php');
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/plugin-init-textdomain.php');
|
||||||
|
|
||||||
//include( XARXAPROD_WPPLUGIN_PATH . 'includes/plugin-settings-pannel.php');
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/plugin-settings-pannel.php');
|
||||||
|
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/enable-svg.php');
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/enable-svg.php');
|
||||||
|
|
||||||
|
@ -77,5 +77,13 @@ include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-post-type-convos.php');
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-convos-filter.php');
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-convos-filter.php');
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-convos-filter-function-frontend.php');
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-convos-filter-function-frontend.php');
|
||||||
|
|
||||||
|
// post type associats
|
||||||
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-post-type-associats.php');
|
||||||
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-associats-filter.php');
|
||||||
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-associats-filter-function-frontend.php');
|
||||||
|
|
||||||
// plugin js scripts
|
// plugin js scripts
|
||||||
include( XARXAPROD_WPPLUGIN_PATH . 'includes/register-plugin-scripts.php');
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/register-plugin-scripts.php');
|
||||||
|
|
||||||
|
// include leaflet map shortcodes
|
||||||
|
include( XARXAPROD_WPPLUGIN_PATH . 'includes/xarxaprod-leafletmap.php');
|
||||||
|
|
Loading…
Reference in New Issue