Skip to content

Instantly share code, notes, and snippets.

@unaibamir
Created September 26, 2018 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unaibamir/9c31f1bcea416fcf8a67403e4afa1ea4 to your computer and use it in GitHub Desktop.
Save unaibamir/9c31f1bcea416fcf8a67403e4afa1ea4 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Empower Plugin
Plugin URI: http://empower.com.pk
Description: a plugin description here
Version: 1.0
Author: Empower Class
Author URI: http://empower.com.pk
License: GPL2
Text Domain: plg-domain
*/
function empower_menu() {
add_menu_page( 'Empower Settings', 'Empower Settings', 'manage_options', 'empower-menu-slug', 'empower_settings_callback', 'dashicons-admin-generic', 85 );
/*add_submenu_page( 'empower-menu-slug', 'Form', 'Form',
'manage_options', 'empower-form-menu-slug','student_form');*/
}
add_action( 'admin_menu', 'empower_menu');
// display custom admin notice
function shapeSpace_custom_admin_notice() {
if( isset($_GET["message"]) && !empty($_GET["message"]) ) {
?>
<div class="notice notice-success is-dismissible">
<p><?php _e($_GET["msg"].' Options Saved', 'shapeSpace'); ?></p>
</div>
<?php
}
}
add_action('admin_notices', 'shapeSpace_custom_admin_notice');
function empower_settings_callback() {
?>
<div class="wrap">
<h1 class="wp-heading-inline">Settings</h1>
<?php
$ep_shop_prods_count = get_option( "ep_plugin_woo_options", "" );
$ep_plugin_woo_options_test = get_option( "ep_plugin_woo_options_test");
echo "<pre>".print_r($ep_plugin_woo_options_test, true)."</pre>";
?>
<form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="POST">
<table class="form-table">
<tbody>
<tr>
<th>WooCommerce Shop Product Count</th>
<td>
<input type="number" name="ep_shop_prods_count" class="regular-text" value="<?php echo $ep_shop_prods_count; ?>">
</td>
</tr>
<tr>
<td colspan="2">
<?php submit_button(); ?>
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="action" value="ep_plugin_woo_options">
<?php wp_nonce_field( "ep-add-student" ); ?>
</form>
</div>
<?php
}
add_action( 'admin_post_ep_plugin_woo_options', 'ep_plugin_woo_options_form_callback' );
function ep_plugin_woo_options_form_callback() {
//echo "<pre>".print_r($_POST, true)."</pre>";
if( isset($_POST["ep_shop_prods_count"]) && !empty( $_POST["ep_shop_prods_count"] ) ) {
update_option( "ep_plugin_woo_options", $_POST["ep_shop_prods_count"] );
$args = [
"user_id" => 415,
"post_id" => 153,
"posts" => [
[
"title" => "Post title",
"content" => "Post Content"
],
[
"title" => "Post title",
"content" => "Post Content"
],
[
"title" => "Post title",
"content" => "Post Content"
],
[
"title" => "Post title",
"content" => "Post Content"
]
]
];
update_option( "ep_plugin_woo_options_test", $args );
$redirect_url = add_query_arg([
"message" => "1",
"msg" => urlencode(__("Options Saved asdasdas"))
], $_POST["_wp_http_referer"]);
wp_safe_redirect( $redirect_url );
exit;
}
}
/**
* Change number or products per row to 3
*/
add_filter('loop_shop_columns', 'ep_loop_columns_callback', 99);
if (!function_exists('ep_loop_columns_callback')) {
function ep_loop_columns_callback() {
$ep_shop_prods_count = get_option( "ep_plugin_woo_options", "" );
return $ep_shop_prods_count; // 3 products per row
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment