Wordpress is giving a permissions error on plugin submission [closed] - plugins

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm creating a new plugin (based on a previous plugin I created that works). The options pages show up fine but when I submit I get the "You do not have sufficient permissions to access this page." error.
The plugin it's based on works and submits fine. I'm not sure why this is having an issue though.
Below is the script that creates the plugin, it's pages, and the code that creates the new item on submit.
add_action( 'wp_enqueue_scripts', 'add_product_focus_styles' );
add_action( 'wp_enqueue_scripts', 'add_product_focus_scripts' );
function add_product_focus_styles() {
wp_register_style( 'pfstyles', plugins_url('/css/product-focus.css', __FILE__));
wp_enqueue_style( 'pfstyles' );
}
function add_product_focus_scripts() {
//wp_register_script('rpjs',plugins_url('/js/productfocus.js', __FILE__),'','',true);
//wp_enqueue_script('rpjs');
}
register_activation_hook(__FILE__, 'product_focus_activate');
// activating the default values
function product_focus_activate(){
product_focus_start();
}
function product_focus_start() {
global $wpdb;
/*
code that creates my table
*/
}
/**
* Add the menu items to the WordPress menu bar
*/
add_action('admin_menu', 'create_product_focus_menu_page');
function create_product_focus_menu_page() {
add_menu_page('Add Focus', 'Add Focus', 'administrator', 'productfocus/product-focus-create.php','', plugins_url('productfocus/images/icon.png'));
add_submenu_page('productfocus/product-focus-create.php', 'Edit Focus', 'Edit Focus', 'administrator', 'productfocus/product-focus-edit.php');
add_action( 'admin_init', 'add_product_focus_styles' );
add_action( 'admin_init', 'add_product_focus_scripts' );
}
if(isset($_POST['createFocus'])){
global $wpdb;
$table_name = $wpdb->prefix."productfocus";
$pfname = $_POST['pfname'];
$pfdate = $_POST['pfdate'];
$return = $_SERVER['HTTP_REFERER'];
$q = $wpdb->prepare("INSERT INTO $table_name (pfname,pfdate) VALUES (%s,$d,)",$pfname,$pfdate);
$wpdb ->query($q);
header("location: ".$_SERVER['PHP_SELF']."?page=productfocus/product-focus-create.php");
exit;
}
any clues why the "create" page will show but I get the error when I try to submit the form?

Turns out the name of the button used to submit the page didn't match in the submit function.

Related

TYPO3 extbase, the php based views do not work when migrating from 9 to 10 version

I have developed a custom TYPO3 extbase extension that was perfectly worked on 8 and 9 version of TYPO3.
Recently I upgraded my installation to TYPO3 10 version but the php based views of my TYPO3 extbase extension do not work anymore.
The error that is displayed is:
Sorry, the requested view was not found.
The technical reason is: No template was found. View could not be resolved for action "getIcal" in class "Luc\Lucevents2\Controller\EventController"
I have read the instructions in the page
https://docs.typo3.org/m/typo3/book-extbasefluid/10.4/en-us/8-Fluid/9-using-php-based-views.html, but there is nothing different from what I have already done in my extension.
So, I am very confused because there is no explanation why the code stopped to work, the above link doesn't include any instructions about deprecated code or possible changes after migration!!
Could you give me any help?
Thank you very much!
George
I hit this problem today. The documentation for "php based views" seems to be outdated.Below is a description of my setup and the solution for TYPO3 10
What I had:
My situation was that I had a Controller with a showAction() action method.
In typoscript, I had setup a new format through the type parameter. Something like
rss = PAGE
rss {
typeNum = 58978
10 =< tt_content.list.20.skevents_eventfeeds
}
For this type (parameter type=58978) I had setup a class named View\EventFeeds\ShowRss with a render() method.
TYPO3 automatically resolved this class based on the type (rss) and the action name (show). This does not work any more.
What solves this issue:
in order for TYPO3 to find the correct class with the render method, it is sufficient to set the defaultViewObjectName variable of the Controller to the correct class name for the specific action. This can be done in the controller with the following new method
public function initializeShowAction()
{
$this->defaultViewObjectName = \Skar\Skevents\View\EventFeeds\ShowRss::class;
}
So now, before calling the showAction method, defaultViewObjectName is set to my ShowRss class which produces the output.
Please note that my ShowRss class extends \TYPO3\CMS\Extbase\Mvc\View\AbstractView . According to https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/8-Fluid/9-using-php-based-views.html this is deprecated in TYPO3 11 and will have to change for TYPO3 12
the static template is already included and all the other operations of the extension are working very well except the php based views. The ext_localconf.php looks as follows: <?php
defined('TYPO3_MODE') || die('Access denied.');
$boot = function () {
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Luc.Lucevents2',
'Luceventsdisplay',
[
'Event' => 'list, show, delete, edit, monthview, test, ajax, deleteConfirm, showRss, getIcal, addForm, add, editForm, importeventtoforum',
'Channel' => 'list, show',
'Tag' => 'filter, show'
],
// non-cacheable actions
[
'Event' => 'list, show, delete, edit, monthview, test, ajax, deleteConfirm, showRss, getIcal, addForm, add, editForm, importeventtoforum',
'Channel' => 'list, show',
'Tag' => 'filter, show'
]
);
};
$boot();
unset($boot);
The action is registered in EventController.php and looks as follows:
/**
* action geticalaction
*
* #param \Luc\Lucevents2\Domain\Model\Event $event
* #return void
*/
public function getIcalAction(\Luc\Lucevents2\Domain\Model\Event $event = NULL)
{
$base_url = $this->request->getBaseUri();
$channel=$this->settings['channel_for_simple_users'];
if($this->request->hasArgument('duration'))
{
if ($this->request->getArgument('duration')=='6month') {
$duration=$this->request->getArgument('duration');
}
else
{
$duration='month';
}
$events = $this->eventRepository->get_events_for_rss_and_ical($duration,$channel);
$eventsarray= array();
foreach ($events as $obj){
$this->uriBuilder->setCreateAbsoluteUri(true);
$uri = $this->controllerContext->getUriBuilder()
->setUseCacheHash(false)
->uriFor('show', array("event" => $obj->getUid()));
$eventsarray[] = array($obj->getTitle(), $obj->getDescription(), $obj->getStartdatetime(),$obj->getEnddatetime(), $obj->getBuildingid(), $obj->getRoomid(), $obj->getPlace(), $obj->getCrdate(), $uri, $obj->getUid());
}
$this->view->assign('events', $eventsarray);
$this->view->assign('baseurl', $base_url);
}
else
{
$this->uriBuilder->setCreateAbsoluteUri(true);
$uri = $this->controllerContext->getUriBuilder()
->setUseCacheHash(false)
->uriFor('show', array("event" => $event->getUid()));
$this->view->assign('event', $event);
$this->view->assign('baseurl', $base_url);
$this->view->assign('uri', $uri);
}
}
Thank you very much!

Wordpress, redirect a user directly to a custom post edit screen after login

currently I got this:
function redirect_companies()
{
if ( current_user_can( 'ca_company' ) )
{
$screen = get_current_screen();
if ( $screen->post_type != 'unternehmen' && $screen->id != 'profile' )
{
global $current_user;
$current_users_posts = get_posts(
array(
'post_type' => 'unternehmen',
'author' => $current_user->ID
)
);
if ( count( $current_users_posts ) > 1 )
{
$redirect = admin_url( 'edit.php?post_type=unternehmen' );
}
else
{
$redirect = get_edit_post_link( $current_users_posts[0]->ID );
}
wp_redirect( $redirect, 301 );
}
}
}
add_action('current_screen', 'redirect_companies');
What it should do: A user with role 'ca_company' logs into wordpress backend and instantly gets redirected to either the overview screen of the custom post type posts of "unternehmen" or, if only one post by this user exists, to the edit screen of that one post.
Also, it should perform this redirect routine, if the user is trying to access any page that is not from post type "unternehmen" and is not the user-profile-edit screen.
I successfully tested this when I already was logged in as auch user and then trying to access for example the dashboard. This works.
But if I completely log out of WP and then log in again, wordpress is performing this:
http://i.stack.imgur.com/M60aJ.png
... and then my browser is telling me, that there is a redirecting error. Infinite redirecting loop. But why? Why does it even go into that "if" where I check for post type "unternehmen". Because if I log in, I am first getting to dashboard...
Hope someone can help :)
Use this action 'add_action('wp_login', 'do_anything');'. And in callback function you can give link to wp_redirect('link') where you want to redirect your screen.

How to change position of woocommerce "added to cart" message

I am using woocommerce version 2.3.13 and I want to change position of woocommerce messages like "Product was successfully added to cart", which appears on the top of the product page when I click on "add to cart" button.
I want this message to appear somewhere else.
I've tired many solutions including this by removing 'woocommerce_show_messages' on 'woocommerce_before_single_product' hook
code: remove_action( 'woocommerce_before_single_product', 'woocommerce_show_messages' );
and then calling woocommerce_show_messages(); function where I want the message to appear but with no luck.
Anyone please help me in this regard.
EDIT:
I've forgot to mention that I am using storefront theme and using custom template for single product.
And these messages are appearing at the top of page by default.
The messages 'Product was successfully added to cart' are woocommerce notices.
These messages are printed by the function
<?php wc_print_notices(); ?>
Try changing the position of this function in template.
To add notices via hooks
add_action( 'woocommerce_before_shop_loop', 'wc_print_notices', 10 );
add_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
STOREFRONT Theme Edit:
** Works with Woocoommerce: 3.1.2 + Storefront: 2.2.5 **
In storefront theme the wc_print_notices is hooked into storefront_content_top
so to remove messages from top in storefront theme you need to add following code in functions.php
remove_action( 'woocommerce_before_shop_loop', 'wc_print_notices', 10 ); /*Archive Product*/
remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 ); /*Single Product*/
remove_action( 'storefront_content_top', 'storefront_shop_messages', 1 );
and add function
wc_print_notices();
Wherever you want notices to appear.
EDIT: The messages will not appear on Single Product Page and Archive Product Page. Though they might appear on any other woocommerce page(cart, checkout, etc).
This works for me (WooCommerce 3.2+) (based on this answer for #LoicTheAztec)
add_action( 'wp_head', 'reposition_sf_messages' );
function reposition_sf_messages(){
if( is_product() ) {
remove_action( 'storefront_content_top','storefront_shop_messages',15 );
}
remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 ); /*Single Product*/
add_action('woocommerce_product_meta_end', 'storefront_shop_messages', 1 );
}
If someone is still looking for a solution here it goes.
you can use something like
remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );
Now put this code where you want to show the notices.
<?php wc_print_notices(); ?>
I had the same problem. I have woocommerce 6.3.1 installed and nothing worked for me. In the end I started looking at the woocommerce files and found that it is "woocommerce_output_all_notices".
So I went to my functions.php of my child theme and put the following:
//Remove for original position
remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 );
//Move under cart button (option 1)
add_action ( 'woocommerce_single_product_summary', 'woocommerce_output_all_notices', 35 );
//Move under cart button (option 2)
add_action ( 'woocommerce_single_product_summary', 'mover_mensaje_product_added', 35 );
function mover_mensaje_product_added() {
echo woocommerce_show_messages();
}
//Change text (optional)
add_filter( 'wc_add_to_cart_message_html', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
$message = '¡Estupendo! Ya tienes el producto en tu carrito :)' ;
return $message;
}
From option 1 and option 2, you should only choose 1. Or you put one or the other. I only give you alternatives that have worked for me, and in my case both options are valid.
Have you tried this:
remove_action( 'woocommerce_before_single_product', 'woocommerce_show_messages' );
add_action( 'woocommerce_after_single_product', 'woocommerce_show_messages', 15 );
Here third parameter is for positioning priority
i think this will help you ............
add_action('woocommerce_before_my_page', 'wc_print_notices', 10);
Now go to your page, where you want the messages displayed, and add
<?php
do_action( 'woocommerce_before_my_page' );
?>
This is the complete code to add in functions.php of the theme.
function move_woocommerce_message(){
remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
add_action( 'woocommerce_single_product_summary', 'wc_print_notices', 35 );
}
add_filter('wp', 'move_woocommerce_message');

woocommerce hook on page-new.php

I'm using woocommerce and mgates vendor software while adding hooks on the page-new.php page to make instructions for my vendors on the add product page. I'm using
add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' );
function myprefix_edit_form_after_title() {
echo 'This is my text!';
}
as well as after editor and form advanced
On my add product page I have:
Title
'edit_form_after_title'
Description
'edit_form_after_editor'
Product Short Description
How do I figure out what hook to put between these to sections?
Product Data
How or where would I put these hooks to have them only get them to show up on the Add Products post page and not ever post page?
You can fire your hook selectively using:
add_action( 'load-post-new.php', 'your_callback' );
And then check for the post type before adding the hook:
function your_callback()
{
global $typenow;
if( 'product' != $typenow )
return;
add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' );
}
Or, another option:
add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' );
function myprefix_edit_form_after_title()
{
global $pagenow, $typenow;
if( 'post-new.php' != $pagenow || 'product' != $typenow )
return;
echo 'This is my text!';
}

Confirmation Dialog in Zend Framework

I'm building a Zend Application using doctrine repository classes to update, delete and insert data to the DB. These repositories are called from controller actions and they do exactly what they supposed to do. However, I'd like to add some confirmation dialogs to the application, so for example, if a user wants to edit or delete an item, a Confirm Edit or Delete dialog must first be opened and the data will be edited or deleted depending on what the user selects. Here's an example of some action code for updating a staff members details after the user has clicked on a zend form submit button.
public function updatestaffAction()
{
if ($this->getRequest()->isPost()) {
if ($form->isValid($this->getRequest()->getPost())) {
$values = $form->getValues();
$user = $this->entityManager->find('\PTS\Entity\Staff', $values['staff_number']);
$staffValues = array('staff_number' => $values['staff_number'],
'title' => $values['title'],
'first_name' => $values['first_name'],
'last_name' => $values['last_name'],
'telephone' => $values['telephone'],
'cellphone' => $values['cellphone'],
'fax' => $values['fax'],
'email' => $values['email'],
'job_title' => $values['job_title']);
$this->staffRepository->saveStaff($staffValues);
$this->entityManager->flush();
}
}
The staff repository saveStaff method simply creates a new Staff object and persists that object if the staff member doesn't exists, or merges the new data if it's an existing staff member as is the case for the update code above.
So my question is, how can I change the action to only save the data once the user has clicked the yes button in a confirmation dialog. BTW, the dialog can be either a JQuery or Dojo dialog box.
When you create form's submit button, set js code:
$submit = new Zend_Form_Element_Submit('delete');
$submit->setAttrib(
'onclick',
'if (confirm("Are you sure?")) { document.form.submit(); } return false;'
);
Or, if you want to set dialogbox on link (if you don't have submit form):
onclick="if (confirm('Are you sure?')) { document.location = this.href; } return false;"
Code for showDialog:
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Are you sure": function() {
// PUT your code for OK button, for eg.
document.form.submit();
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});`
Thx, I used the second option like this way :
Delete
and it's worked :)