Forum Replies Created

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter George Bredberg

    (@joje47)

    Seems current_user_can has to be wrapped up in a call that delays it a bit.
    Used wp_loaded to trigger the function and then it works without locking me out when network activating.

    Thread Starter George Bredberg

    (@joje47)

    Surely someone has to have noticed this before?
    Really tried to google this, but noop..

    Try this in a php file in your plugins folder, and network activate it;

    <?php
    /*
    * Plugin Name: Lock your self out
    * Plugin URI: https://ngo-portal.org
    * Description: Show how you get locked out when using current_user_can in a plugin that get's network activated.
    * Version: 0.0.1
    * Author: George Bredberg
    * Author URI: https://datagaraget.se
    * License GPLv3
    * License URI: http://www.gnu.org/licenses/gpl-3.0.html
    */
    
    if(!function_exists('wp_get_current_user')) { require_once(ABSPATH . "wp-includes/pluggable.php"); }
    
    // Down locks me out of admin area...
    if (!(current_user_can('manage_options'))) {
    	echo "<h1><center>Doing something here....</center></h1>";
    }
    ?>

    Also available as gist on Github

    How can I get passed this problem (I.E. be able to check user abilities and not risk that people get locked out of admin if network activating the plugin.)?

    Regards /George

    Thread Starter George Bredberg

    (@joje47)

    In fact, is_super_admin locks me out to.. How to check user capabilities in a multi-site installation?
    It works, as long as I don’t network activate the script..

    Thread Starter George Bredberg

    (@joje47)

    Tx 🙂 As always a very good and understandable explanation.

    Regarding translating stored values, in this case it’s a widget. So I can’t put the text on the page for translation. Of course the editor can change it or translate it, now at least it shows up translated in the backoffice for them to decide. That I thought about it was because if you change language in the browser all other headlines and more are translated, but not that widget, since it’s a stored value. I guess in this case, if they really need multi language, we will need to use a dedicated plugin for that. That would also make the content translatable.

    Thread Starter George Bredberg

    (@joje47)

    Hi,

    Interestingly it seems to work with extended characters in most situations I’ve tested, but when WordPress lists installed themes and shows links to author, if you use ö it shows up like a question mark instead. And that is in a computer localized to Swedish, with the Swedish translation active on WordPress backoffice. Not a big problem though.

    I made a screendump

    Thread Starter George Bredberg

    (@joje47)

    Now I’ve tested Bcworkz suggestion to add this to the constructor;
    $this->w_arg[‘title’] = __(‘Evenemang denna vecka’, ‘event-organiser-ngo’);

    It works 🙂 But not in the way I expected.
    It creates a “placeholder” for the calendar widget’s headline, and that is translated, as expected.
    Since that headline is then stored in the db it does not translate the header of the widget on the page. That I will have to figure out how to do.

    Thread Starter George Bredberg

    (@joje47)

    Hehe, no. It’s a mix of using some code from an old project and me changing standards as I have learnt. I have some cleaning up to do, as I go along. I use one tab per indentation step, and one tab is set to be 2 spaces, but still in Github the indentation becomes huge. But after some cleaning, at least it’s more logical to follow. 😉

    I have not tested your suggestion yet, but I will come back on that. I kind of got stuck with another issue.

    This is another translation problem that is a bit tricky to me.
    I have a function that shows motivational /informational messages in the backoffice. It’s actually like Hello Dolly, but no lyrics 😉
    I changed the variable to an array to make it easier to translate, breaking it up in lines. But, when the array looks like this;

    $motivation = array(
    	__('Välkommen till <a target="_blank" href="http://xn--freningsportalen-mwb.se">http://föreningsportalen.se</a>', 'ngo-branding'),
    	__('Föreningsportalen är ett nätverk för lokalt och regionalt samarbete.', 'ngo-branding'),
    	__('Föreningsportalen stöds av <a target="_blank" href="https://bona.nu">https://bona.nu</a>', 'ngo-branding'),

    (just showing a snippet), and you don’t want those hypertext references to show up in the translator, How do you do that without breaking the array?
    Or maybe an array is not the best solution in this case?

    Entire code here

    BTW I really appreciate all the effort you have put in to helping me out. Tack själv 😉

    Thread Starter George Bredberg

    (@joje47)

    Ahh, I didn’t answer your questions.. Yes, the translation domain is loaded, and the other translations work. I havn’t tested creating a pot-file with this since it totally brakes the page, but the only difference from other translations that I can see, is that it is wrapped in a class. I tried to state the key separately, making a two liner, but the same thing happens.
    I don’t know why the indentation on github looks a bit strange.. it does not look like that in my editor 😉

    Thread Starter George Bredberg

    (@joje47)

    When I change the code to this;

    ‘class PortalOneWeekCalendar extends WP_Widget{
    // FIX: How to translate down? ‘title’ => __(‘Evenemang denna vecka’, ‘event-organiser-ngo’), does not work
    var $w_arg = array(
    ‘title’ => __( ‘Evenemang denna vecka’, ‘event-organiser-ngo’ ),
    ‘showpastevents’ => 1,
    ‘event_start_after’ =>’last Monday’,
    ‘event_start_before’ =>’next Sunday’
    );’

    I get this;
    Parse error: syntax error, unexpected '(', expecting ')' in /home/bonanu/domains/wally/wp-content/plugins/event-organiser-ngo/includes/event-organiser-portal.php on line 103

    The entire code can be seen on github here;

    I don’t now if it has something to do with the class? Because when it’s common array, above seems to work properly.

    Thread Starter George Bredberg

    (@joje47)

    Yes, you are right about reading the html-entities when translating. At least in poedit it shows up as raw “text”. All html-entities will be shown as is making it a bit hard to read actually. That has been a concern, but since the guest on the website are the main focus, I used it anyway. Now I think I will remove it, and try it out on some computers that use an OS localized to other languages. It’s easy to do and revert back if it does not work out as expected.

    The link to my other question disappeared somehow. My mistake. It would have been nice with a preview function here 😉

    How to translate title in widget declaration

    Thread Starter George Bredberg

    (@joje47)

    Ok, thanks for a very good explanation. Yes, you where right to assume that is the part “Spelas pÃ¥” that I want to have internationalized. I thought I did a good thing using html entities 😉 Tx for explaining even that part. I want it to look ok even if its viewed on a non Swedish computer. (It will be used by NGO:s where one part of them are immigrants, so they often have English computers and OS.)

    I have a follow up question, but it concerns another translation issue, so I make a new post so I can mark this as resolved.
    I add a link to it here, hope that’s ok.

Viewing 11 replies - 1 through 11 (of 11 total)