Forum Replies Created

Viewing 15 replies - 76 through 90 (of 90 total)
  • Thread Starter Fact Maven

    (@factmaven)

    Closing topic

    Thread Starter Fact Maven

    (@factmaven)

    Thanks for the update.

    Would it be possible to make an extension for Ultimate Member to allow multiple roles?

    Thread Starter Fact Maven

    (@factmaven)

    Thanks for pointing that out. Also, does it matter if I put the (de)activation hooks in the __construct or outside of the class?

    Hi,

    If I understand this correctly, you want to redirect to your plugin’s page after an update?

    Based on your error, it looks like that there could be white space form the top or bottom of you your plugin, as mentioned here.

    Thread Starter Fact Maven

    (@factmaven)

    Makes sense, thanks for the clarification.

    Thread Starter Fact Maven

    (@factmaven)

    Thanks for the input. I’m also put my plugin in a class structure, so I know the formatting has to be done slightly different. This is what I’ve done based on doing some research online and the example you provided above:

    <?php
    if( ! class_exists( 'MyPlugin' ) ) {
      class MyPlugin {
        public function __construct() {
            add_action( 'init', array( $this, 'factmaven_htaccess' ), 10, 1 );
            // Other actions and filers...
        }
        public function factmaven_htaccess() {
            require_once( ABSPATH . '/wp-admin/includes/misc.php' );
            $rules = array();
            $rules[] = '<Files xmlrpc.php>';
            $rules[] = 'Order allow,deny';
            $rules[] = 'Deny from all';
            $rules[] = '</Files>';
            $rules[] = '';
            $rules[] = '<Files wlwmanifest.xml>';
            $rules[] = 'Order allow,deny';
            $rules[] = 'Deny from all';
            $rules[] = '</Files>';
            $htaccess_file = ABSPATH . '.htaccess';
            insert_with_markers( $htaccess_file, 'Fact Maven', ( array ) $rules );
        }
    
        public function factmaven_deactivate() {
            remove_action( 'generate_rewrite_rules', 'factmaven_htaccess' );
            $GLOBALS['wp_rewrite']->flush_rules();
        }
      }
    }
    
    if( class_exists( 'MyPlugin' ) ) {
      $plugin = new MyPlugin;
      register_deactivation_hook( __FILE__, array( 'MyPlugin', 'factmaven_deactivate' );
    }

    Unfortunately, that doesn’t seem to work, but no errors are showing up when I activate/deactivate my plugin. It looks like I am close. Any suggestions?

    Thread Starter Fact Maven

    (@factmaven)

    SOLUTION

    I see that WordPress has a function called insert_with_markers (link) which allows me to add lines to my .htaccess via PHP. Below is my example code:

    add_action( 'init', 'factmaven_htaccess' );
    
    function factmaven_htaccess() {
        require_once( ABSPATH . '/wp-admin/includes/misc.php' );
        $rules = array();
        $rules[] = '<Files wlwmanifest.xml>';
        $rules[] = 'Order allow,deny';
        $rules[] = 'Deny from all';
        $rules[] = '</Files>';
        $htaccess_file = ABSPATH . '.htaccess';
        insert_with_markers( $htaccess_file, 'Plugin_Name_Here', ( array ) $rules );
    }

    Hope that helps anyone else who was looking for something similar.

    Thread Starter Fact Maven

    (@factmaven)

    I see. Thanks for the clarification.

    Thread Starter Fact Maven

    (@factmaven)

    Thanks for the clarification.

    The reason why I would like to do it through PHP is so I can incorporate this into my plugin. When it’s activated, it would add the code to the .htaccess. If the plugin gets disabled or uninstalled, it will remove that code from the .htaccess.

    Does that makes sense?

    Thread Starter Fact Maven

    (@factmaven)

    So are you saying that there is there no way to do this via the functions.php or a custom plugin?

    Looking online, this would be the code I would put in my .htaccess:

    Redirect 301 /wlwmanifest.xml /

    If I can only do it though .htaccess is there a function I can use to add this code to my .htaccess without manually having to put it in myself?

    Be sure to check off the box “Mark this topic as resolved” next to the “Post” button to close the topic.

    Thread Starter Fact Maven

    (@factmaven)

    Unfortunately this is becoming more complex than I imagined for a simple function. Will revert back to using a manual block instead for simplicity’s sake. Thank you everyone for the help.

    Thread Starter Fact Maven

    (@factmaven)

    Makes sense, this is what I’ve done

    $submenu = array(
                    'tools.php' => 'tools.php', // Tools > Available Tools
                    array( // Settings > Writing
                        'parent' => 'options-general.php',
                        'remove' => 'options-writing.php'
                        ),
                    array( // Settings > Discussion
                        'parent' => 'options-general.php',
                        'remove' => 'options-discussion.php'
                        )
                    );
                foreach ( $submenu as $main => $sub ) {
                    if ( is_array( $sub ) ) {
                        foreach ($sub as $main1 => $sub1 ) {
                            remove_submenu_page( $main1, $sub1 );
                        }
                    }
                    else {
                        remove_submenu_page( $main, $sub );
                    }
                }

    However, based on testing found here, the output would be:

    tools.php, tools.php
    parent, options-general.php
    remove, options-writing.php
    parent, options-general.php
    remove, options-discussion.php

    I know I’m close, but the logic is still off. Any suggestions?

    Thread Starter Fact Maven

    (@factmaven)

    I am using the admin_menu hook. THis is what I’ve been using which worked with the manual block before

    add_action( 'admin_menu', 'remove_menu' ), 10, 1 );

    I know the logic error has to be related to having the same parent menu options-general.php in the array. It looks like it only hides ones of the submenus under Settings.

    Just trying to understand how to work around that.

    Thread Starter Fact Maven

    (@factmaven)

    Yes, because like you said, the manual block works with the same spelling. Even when I added the Settings > Media menu to the array, both Writing and Discussion now show up:

    $submenu = array(
        'tools.php' => 'tools.php',
        'options-general.php' => 'options-writing.php',
        'options-general.php' => 'options-discussion.php',
        'options-general.php' => 'options-media.php'
        );
        foreach ( $submenu as $main => $sub ) {
            remove_submenu_page( $main, $sub );
        }

    It appears that only the last item I hide under the Settings menu is hidden. I encourage you to try this out on your end.

Viewing 15 replies - 76 through 90 (of 90 total)