Initial commit after correcting all Plugin Check errors - including renaming the plugin and all parameters, functions, etc

This commit is contained in:
2025-02-21 22:07:40 +01:00
commit fad1c6c3c6
7 changed files with 834 additions and 0 deletions

View File

@@ -0,0 +1,150 @@
<?php
// If this file is called directly, abort.
if( !defined('ABSPATH'))
{
die('Nothing to see here...');
}
// function to check if the Out of office is active
function out_of_office_for_woo_is_active(){
$ooo_woo_start_date = esc_attr(get_option( 'ooo_woo_start_date', '' ));
$ooo_woo_end_date = esc_attr(get_option( 'ooo_woo_end_date', '' ));
$ooo_woo_is_active = esc_attr(get_option( 'ooo_woo_is_active', '' ));
$tdate = strtotime(gmdate("Y-m-d"));
$sdate = strtotime($ooo_woo_start_date);
$edate = strtotime($ooo_woo_end_date);
if ($ooo_woo_is_active == "Active") {
return true;
} elseif (($ooo_woo_is_active == "Automatic") && ($tdate >= $sdate) && ($tdate <= $edate)){
return true;
} else {
return false;
}
}
// function to dinamically add the start and end date to the out of office message
function out_of_office_for_woo_include_dates_in_message($start_date, $end_date, $message){
$message_compiled = str_replace("[StartDate]", wp_date(get_option('date_format'), strtotime($start_date)), $message);
$message_compiled = str_replace("[EndDate]", wp_date(get_option('date_format'), strtotime($end_date)), $message_compiled);
return $message_compiled;
}
// function to add the out of office message to the order confirmation email
//add_action( 'woocommerce_email_before_order_table', 'out_of_office_for_woo_show_in_order_confirmation_email', 20 );
add_action( 'woocommerce_email_header', 'out_of_office_for_woo_show_in_order_confirmation_email', 20 );
function out_of_office_for_woo_show_in_order_confirmation_email( $order ) {
$ooo_woo_show_in_order_confirmation_email = esc_attr(get_option( 'ooo_woo_show_in_order_confirmation_email', '' ));
if ((out_of_office_for_woo_is_active()) && ($ooo_woo_show_in_order_confirmation_email == "Yes")) {
$ooo_woo_message = esc_attr(get_option( 'ooo_woo_message', '' ));
$ooo_woo_title = esc_attr(get_option( 'ooo_woo_title', '' ));
$ooo_woo_start_date = esc_attr(get_option( 'ooo_woo_start_date', '' ));
$ooo_woo_end_date = esc_attr(get_option( 'ooo_woo_end_date', '' ));
$ooo_woo_message_compiled = out_of_office_for_woo_include_dates_in_message($ooo_woo_start_date, $ooo_woo_end_date, $ooo_woo_message);
?>
<table id="out_of_office_for_woo_show_in_order_confirmation_email" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top; margin-bottom: 40px; margin-top: 20px; padding: 0; border= 2px solid black; border-collapse: collapse;">
<tr>
<td style="text-align: left; border: 0; padding: 0;" valign="top">
<hr>
<h2>
<?php echo esc_html( $ooo_woo_title) ; ?>
</h2>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
<p>
<?php echo wp_kses_post ( wpautop($ooo_woo_message_compiled) ) ; ?>
</p>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
</td>
</tr>
</table>
<?php
}
}
// function to add the out of office message to the shopping cart page
add_action( 'woocommerce_before_cart_table', 'out_of_office_for_woo_show_on_shopping_cart_page', 20 );
function out_of_office_for_woo_show_on_shopping_cart_page( $order ) {
$ooo_woo_show_on_shopping_cart_page = esc_attr(get_option( 'ooo_woo_show_on_shopping_cart_page', '' ));
if ((out_of_office_for_woo_is_active()) && ($ooo_woo_show_on_shopping_cart_page == "Yes")) {
$ooo_woo_message = esc_attr(get_option( 'ooo_woo_message', '' ));
$ooo_woo_title = esc_attr(get_option( 'ooo_woo_title', '' ));
$ooo_woo_start_date = esc_attr(get_option( 'ooo_woo_start_date', '' ));
$ooo_woo_end_date = esc_attr(get_option( 'ooo_woo_end_date', '' ));
$ooo_woo_message_compiled = out_of_office_for_woo_include_dates_in_message($ooo_woo_start_date, $ooo_woo_end_date, $ooo_woo_message);
?>
<hr>
<h1>
<?php echo esc_html( $ooo_woo_title ) ; ?>
</h1>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
<p>
<?php echo wp_kses_post( ( wpautop($ooo_woo_message_compiled) ) ); ?>
</p>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
<?php
}
}
// function to add the out of office message to the check out page
add_action( 'woocommerce_before_checkout_form', 'out_of_office_for_woo_show_on_check_out_page', 20 );
function out_of_office_for_woo_show_on_check_out_page( $order ) {
$ooo_woo_show_on_checkout_page = esc_attr(get_option( 'ooo_woo_show_on_checkout_page', '' ));
if ((out_of_office_for_woo_is_active()) && ($ooo_woo_show_on_checkout_page == "Yes")) {
$ooo_woo_message = esc_attr(get_option( 'ooo_woo_message', '' ));
$ooo_woo_title = esc_attr(get_option( 'ooo_woo_title', '' ));
$ooo_woo_start_date = esc_attr(get_option( 'ooo_woo_start_date', '' ));
$ooo_woo_end_date = esc_attr(get_option( 'ooo_woo_end_date', '' ));
$ooo_woo_message_compiled = out_of_office_for_woo_include_dates_in_message($ooo_woo_start_date, $ooo_woo_end_date, $ooo_woo_message);
?>
<hr>
<h1>
<?php echo esc_html( $ooo_woo_title, 'out-of-office-for-woo' ) ; ?>
</h1>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
<p>
<?php echo wp_kses_post( ( wpautop($ooo_woo_message_compiled) ) ); ?>
</p>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
<?php
}
}
/*
add_action('wp_head', 'out_of_office_for_woo_show_on_top_bar');
function out_of_office_for_woo_show_on_top_bar()
{
if ((out_of_office_for_woo_is_active()) && ($ooo_woo_show_top_bar == "Yes")) {
$ooo_woo_message = esc_attr(get_option( 'ooo_woo_message', '' ));
$ooo_woo_title = esc_attr(get_option( 'ooo_woo_title', '' ));
$ooo_woo_start_date = esc_attr(get_option( 'ooo_woo_start_date', '' ));
$ooo_woo_end_date = esc_attr(get_option( 'ooo_woo_end_date', '' ));
$ooo_woo_message_compiled = out_of_office_for_woo_include_dates_in_message($ooo_woo_start_date, $ooo_woo_end_date, $ooo_woo_message);
?>
<div id="out_of_office_for_woo_top_bar" style="background: #e1e1e1; color: #333333; font-size:16px; top: 0px; left: 0px; width: 100% !important; padding: 10px 0px; text-align: center;" >
<strong><?php esc_html_e( $ooo_woo_title, 'out-of-office-for-woo' ) ; ?>: </strong>
<?php echo ( $ooo_woo_message_compiled ) ; ?>
</div>
<?php
}
}
*/

View File

@@ -0,0 +1,46 @@
<?php
// If this file is called directly, abort.
if( !defined('ABSPATH'))
{
die('Nothing to see here...');
}
// Hook into 'admin_menu' action to add our custom menu page
add_action('admin_menu', 'out_of_office_for_woo_tools_submenu');
function out_of_office_for_woo_tools_submenu()
{
add_submenu_page(
'options-general.php', // Parent menu slug (Tools)
'Out of Office for Woo Settings Page', // Page title
'Out of Office for Woo', // Menu title
'manage_options', // Capability of the user to see this page
'out-of-office-for-woo', // Menu slug of the settings page
'out_of_office_for_woo_tools_submenu_page' // Function to display the page content
);
add_action('admin_init', 'out_of_office_for_woo_options_init');
}
// Function to output the content of our custom sub-menu page
function out_of_office_for_woo_tools_submenu_page() {
//Double check user capabilities
if ( !current_user_can('manage_options') ) {
return;
}
include( OOOWOO_DIR . 'templates/admin/settings-page.php');
}
// Add a link to your settings page in your plugin
function out_of_office_for_woo_add_settings_link( $links ) {
$url = get_admin_url( ) . "options-general.php?page=out-of-office-for-woo";
$settings_link = '<a href="' . $url . '">' . __('Settings', 'out-of-office-for-woo') . '</a>';
$links[] = $settings_link;
// $settings_link = '<a href="options-general.php?page=out-of-office-for-woo">' . __( 'Settings','out-of-office-for-woo' ) . '</a>';
// array_push( $links, $settings_link );
return $links;
}
$filter_name = "plugin_action_links_" . OOOWOO_BASENAME;
add_filter( $filter_name, 'out_of_office_for_woo_add_settings_link' );

View File

@@ -0,0 +1,270 @@
<?php
function my_sanitize_options ($data){
return $data;
}
function out_of_office_for_woo_options_init()
{
add_settings_section(
'out-of-office-for-woo-section', //id of the options section
'Woo Out of Office Settings', //title to be displayed
'', //callback function to be called when opening section
'out-of-office-for-woo' // page on which to display the section, this should be the same as the slug used in add_submenu_page()
);
register_setting(
'out-of-office-for-woo', //option group ???? check if this should be the slug or the option section id!!!
'ooo_woo_start_date',
array(
'type' => 'string',
'sanitize_callback'=> 'sanitize_text_field',
)
);
add_settings_field(
'ooo-woo-start-date', // id of the settings field
'Start Date of the Out of Office', // title
'out_of_office_for_woo_options_cb_start_date', // callback function
'out-of-office-for-woo', // page on which settings display
'out-of-office-for-woo-section' // section on which to show the settings
);
register_setting(
'out-of-office-for-woo', //option group ???? check if this should be the slug or the option section id!!!
'ooo_woo_end_date',
array(
'type' => 'string',
'sanitize_callback'=> 'sanitize_text_field',
)
);
add_settings_field(
'ooo-woo-end-date', // id of the settings field
'End Date of the Out of Office', // title
'out_of_office_for_woo_options_cb_end_date', // callback function
'out-of-office-for-woo', // page on which settings display
'out-of-office-for-woo-section' // section on which to show the settings
);
register_setting(
'out-of-office-for-woo', //option group ???? check if this should be the slug or the option section id!!!
'ooo_woo_title',
array(
'type' => 'string',
'sanitize_callback'=> 'sanitize_text_field',
)
);
add_settings_field(
'ooo-woo-title', // id of the settings field
'Title for the Out of Office message', // title
'out_of_office_for_woo_options_cb_title', // callback function
'out-of-office-for-woo', // page on which settings display
'out-of-office-for-woo-section' // section on which to show the settings
);
register_setting(
'out-of-office-for-woo', //option group ???? check if this should be the slug or the option section id!!!
'ooo_woo_message',
array(
'type' => 'string',
'sanitize_callback'=> 'sanitize_textarea_field',
)
);
add_settings_field(
'ooo-woo-message', // id of the settings field
'Message for the Out of Office', // title
'out_of_office_for_woo_options_cb_message', // callback function
'out-of-office-for-woo', // page on which settings display
'out-of-office-for-woo-section' // section on which to show the settings
);
register_setting(
'out-of-office-for-woo', //option group ???? check if this should be the slug or the option section id!!!
'ooo_woo_is_active',
array(
'type' => 'string',
'sanitize_callback'=> 'sanitize_text_field',
)
);
add_settings_field(
'ooo-woo-is-active', // id of the settings field
'How should Out of Office be activated', // title
'out_of_office_for_woo_options_cb_is_active', // callback function
'out-of-office-for-woo', // page on which settings display
'out-of-office-for-woo-section' // section on which to show the settings
);
register_setting(
'out-of-office-for-woo', //option group ???? check if this should be the slug or the option section id!!!
'ooo_woo_show_in_order_confirmation_email',
array(
'type' => 'string',
'sanitize_callback'=> 'sanitize_text_field',
)
);
add_settings_field(
'ooo_woo_show_in_order_confirmation_email', // id of the settings field
'Show message in the order confirmation Email', // title
'out_of_office_for_woo_options_cb_show_in_order_confirmation_email', // callback function
'out-of-office-for-woo', // page on which settings display
'out-of-office-for-woo-section' // section on which to show the settings
);
register_setting(
'out-of-office-for-woo', //option group ???? check if this should be the slug or the option section id!!!
'ooo_woo_show_on_shopping_cart_page',
array(
'type' => 'string',
'sanitize_callback'=> 'sanitize_text_field',
)
);
add_settings_field(
'ooo_woo_show_on_shopping_cart_page', // id of the settings field
'Show message on the Shopping Cart page', // title
'out_of_office_for_woo_options_cb_show_on_shopping_cart_page', // callback function
'out-of-office-for-woo', // page on which settings display
'out-of-office-for-woo-section' // section on which to show the settings
);
register_setting(
'out-of-office-for-woo', //option group ???? check if this should be the slug or the option section id!!!
'ooo_woo_show_on_checkout_page',
array(
'type' => 'string',
'sanitize_callback'=> 'sanitize_text_field',
)
);
add_settings_field(
'ooo_woo_show_on_checkout_page', // id of the settings field
'Show message on the Checkout page', // title
'out_of_office_for_woo_options_cb_show_on_checkout_page', // callback function
'out-of-office-for-woo', // page on which settings display
'out-of-office-for-woo-section' // section on which to show the settings
);
/*register_setting(
'out-of-office-for-woo', //option group ???? check if this should be the slug or the option section id!!!
'ooo_woo_show_top_bar',
array(
'type' => 'string',
'sanitize_callback'=> 'sanitize_text_field',
)
);
add_settings_field(
'ooo_woo_show_top_bar', // id of the settings field
'Show a top bar with the out of office', // title
'out_of_office_for_woo_options_cb_show_top_bar', // callback function
'out-of-office-for-woo', // page on which settings display
'out-of-office-for-woo-section' // section on which to show the settings
);*/
}
function out_of_office_for_woo_options_cb_start_date()
{
$ooo_woo_start_date = get_option( 'ooo_woo_start_date', '' );
?>
<div>
<input id="title" type="date" name="ooo_woo_start_date" value="<?php echo esc_attr( $ooo_woo_start_date);?>">
</div>
<?php
}
function out_of_office_for_woo_options_cb_end_date()
{
$ooo_woo_end_date = get_option( 'ooo_woo_end_date', '' );
?>
<div>
<input id="title" type="date" name="ooo_woo_end_date" value="<?php echo esc_attr($ooo_woo_end_date); ?>">
</div>
<?php
}
function out_of_office_for_woo_options_cb_title()
{
$ooo_woo_title = get_option( 'ooo_woo_title', '' );
?>
<div>
<input id="title" type="text" name="ooo_woo_title" value="<?php echo esc_attr($ooo_woo_title); ?>">
</div>
<?php
}
function out_of_office_for_woo_options_cb_message()
{
$ooo_woo_message = get_option( 'ooo_woo_message', '' );
?>
<div>
<textarea id="title" name="ooo_woo_message" rows="6" cols="80"><?php echo esc_attr($ooo_woo_message); ?></textarea>
<br>
Use <strong><i>[StartDate]</i></strong> and <strong><i>[EndDate]</i></strong> as shortcodes within the text in order to incorporate the actual dates.
<br>
For example: "We are between [StartDate] and [EndDate] on vacation :)"
</div>
<?php
}
function out_of_office_for_woo_options_cb_is_active()
{
$ooo_woo_is_active = get_option( 'ooo_woo_is_active', '' );
//
?>
<div>
<input type="radio" id="title" name="ooo_woo_is_active" value="Automatic" <?php if ($ooo_woo_is_active == "Automatic") {echo('checked');}?>>
<label for="Automatic">Automatic (Out of office will be active only in the period between StartDate and EndDate)</label><br>
<input type="radio" id="title" name="ooo_woo_is_active" value="Active" <?php if ($ooo_woo_is_active == "Active") {echo('checked');}?>>
<label for="Active">Active (Out of office is always active - ON)</label><br>
<input type="radio" id="title" name="ooo_woo_is_active" value="Inactive" <?php if ($ooo_woo_is_active == "Inactive") {echo('checked');}?>>
<label for="Inactive">Inactive (Out of office is inactive - OFF)</label><br>
</div>
<?php
}
function out_of_office_for_woo_options_cb_show_in_order_confirmation_email()
{
$ooo_woo_show_in_order_confirmation_email = get_option( 'ooo_woo_show_in_order_confirmation_email', '' );
//
?>
<div>
<input type="radio" id="title" name="ooo_woo_show_in_order_confirmation_email" value="Yes" <?php if ($ooo_woo_show_in_order_confirmation_email == "Yes") {echo('checked');}?>>
<label for="Yes">Yes</label><br>
<input type="radio" id="title" name="ooo_woo_show_in_order_confirmation_email" value="No" <?php if ($ooo_woo_show_in_order_confirmation_email == "No") {echo('checked');}?>>
<label for="No">No</label><br>
</div>
<?php
}
function out_of_office_for_woo_options_cb_show_on_shopping_cart_page()
{
$ooo_woo_show_on_shopping_cart_page = get_option( 'ooo_woo_show_on_shopping_cart_page', '' );
//
?>
<div>
<input type="radio" id="title" name="ooo_woo_show_on_shopping_cart_page" value="Yes" <?php if ($ooo_woo_show_on_shopping_cart_page == "Yes") {echo('checked');}?>>
<label for="Yes">Yes</label><br>
<input type="radio" id="title" name="ooo_woo_show_on_shopping_cart_page" value="No" <?php if ($ooo_woo_show_on_shopping_cart_page == "No") {echo('checked');}?>>
<label for="No">No</label><br>
</div>
<?php
}
function out_of_office_for_woo_options_cb_show_on_checkout_page()
{
$ooo_woo_show_on_checkout_page = get_option( 'ooo_woo_show_on_checkout_page', '' );
//
?>
<div>
<input type="radio" id="title" name="ooo_woo_show_on_checkout_page" value="Yes" <?php if ($ooo_woo_show_on_checkout_page == "Yes") {echo('checked');}?>>
<label for="Yes">Yes</label><br>
<input type="radio" id="title" name="ooo_woo_show_on_checkout_page" value="No" <?php if ($ooo_woo_show_on_checkout_page == "No") {echo('checked');}?>>
<label for="No">No</label><br>
</div>
<?php
}
/*
function out_of_office_for_woo_options_cb_show_top_bar()
{
$ooo_woo_show_top_bar = get_option( 'ooo_woo_show_top_bar', '' );
//
?>
<div>
<input type="radio" id="title" name="ooo_woo_show_top_bar" value="Yes" <?php if ($ooo_woo_show_top_bar == "Yes") {echo('checked');}?>>
<label for="Yes">Yes</label><br>
<input type="radio" id="title" name="ooo_woo_show_top_bar" value="No" <?php if ($ooo_woo_show_top_bar == "No") {echo('checked');}?>>
<label for="No">No</label><br>
<br>
<strong>Not yet implemented</strong>
</div>
<?php
}
*/
//add_action('admin_init', 'out_of_office_for_woo_options');