Fact Maven
Forum Replies Created
-
Forum: Hacks
In reply to: Remove rules from .htaccess through a pluginClosing topic
Thanks for the update.
Would it be possible to make an extension for Ultimate Member to allow multiple roles?
Forum: Hacks
In reply to: Remove rules from .htaccess through a pluginThanks for pointing that out. Also, does it matter if I put the (de)activation hooks in the
__construct
or outside of theclass
?Forum: Hacks
In reply to: Having a problem with wp_redirect in my pluginHi,
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.
Forum: Hacks
In reply to: Adding a class to your plugin?Makes sense, thanks for the clarification.
Forum: Hacks
In reply to: Remove rules from .htaccess through a pluginThanks 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?
Forum: Hacks
In reply to: Redirect "wlwmanifest.xml" to homepageSOLUTION
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.
Forum: Hacks
In reply to: Group different tags in add_filter / add_action to the same function?I see. Thanks for the clarification.
Forum: Hacks
In reply to: Redirect "wlwmanifest.xml" to homepageThanks 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?
Forum: Hacks
In reply to: Redirect "wlwmanifest.xml" to homepageSo 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?Forum: Hacks
In reply to: Problem with ading customfields within functions.phpBe sure to check off the box “Mark this topic as resolved” next to the “Post” button to close the topic.
Forum: Hacks
In reply to: Unable to hide all submenus items using foreach constructUnfortunately 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.
Forum: Hacks
In reply to: Unable to hide all submenus items using foreach constructMakes 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?
Forum: Hacks
In reply to: Unable to hide all submenus items using foreach constructI am using the
admin_menu
hook. THis is what I’ve been using which worked with the manual block beforeadd_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.
Forum: Hacks
In reply to: Unable to hide all submenus items using foreach constructYes, 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.