WordPress-Plugin-Boilerplate-Tutorial icon indicating copy to clipboard operation
WordPress-Plugin-Boilerplate-Tutorial copied to clipboard

settings-link does not work in exopite simple options framework

Open chaimiko opened this issue 2 years ago • 3 comments

Hi, first of all great framework.

I was struggling with the settings-link in exopite-simple-options-framework.

  1. If i removed it from creating page i get an error Undefined array key "settings-link"
  2. When i enter the settings-link link admin.php?page=plugin-name it removes the question and = equal signs.
  3. Then i checked the exopite-simple-options-framework-class and see that the settings-link is escaped with sanitize_file_name $settings_link = sanitize_file_name( $this->config['settings-link'] ); this was causing the error so i removed the sanitize and works.

Is it safe to remove sanitize_file_name and can you advice how to improve it. Thanks in advance

chaimiko avatar Apr 10 '23 01:04 chaimiko

I think, it is safe to remove. How your settings looks like?

JoeSz avatar Apr 10 '23 10:04 JoeSz

thanks for the quick reply, do you mean the code? `function create_menu() { $icon = '<svg xmlns="http://www.w3.org/2000/svg" id="Layer_2" width="20" height="20" viewBox="0 0 496.95 761.52">'; // Get the URL for the settings page

	$config_submenu = [
		'type'              => 'menu',
		'id'                => $this->plugin_name . '-options',
		'menu_title'		=> 'Gold Expert',
		'settings-link'		=> 'admin.php?page=gold-expert-options',
		'position'			=> 4,
		'plugin_basename'   => plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' ),
		'title'             => esc_html__( 'Gold Expert Settings', 'gold-expert' ),
		'capability'        => 'manage_options',
		'tabbed'            => false,
		'icon'				=> 'data:image/svg+xml;base64,' . base64_encode( $icon ),
	];

	$fields[] = [
		'name'   => 'ge_settings_section',
		'title'  => esc_html__( 'Setup', 'gold-expert' ),
		'icon'   => 'dashicons-portfolio',
		'fields' => [
			[
				'id'          => 'gold_expert_tabs',
				'type'        => 'tab',
				'options'     => [
					'equal_width' => true,
				],
				'tabs' => [
					[
						'id'     => 'gold_tab',
						'title'	 => esc_html__( 'Gold', 'gold-expert' ),
						'fields' => [
							[
								'id'         => 'shortcode_gold_table',
								'title'	     => esc_html__( 'Shortcode gold table', 'gold-expert' ),
								'type'       => 'textarea',
								'default'    => '[gold-expert-prices-table symbol="gc=f"]',
								'after'		 => '<span class="input-append"><i class="fa fa fa-clone copy-link-button" aria-hidden="true"></i></span>',
								'class'       => 'copy-link-input',
								'attributes' => [
									'rows'         => 1,
									   'cols'      => 50,
									'readonly' 	   => 'readonly',
								],
							],
							[
								'type'    => 'group',
								'id'      => 'gold_group',
								'options' => [
									'repeater'          => true,
									'accordion'         => false,
									'button_title'      => esc_html__( 'Add new', 'gold-expert' ),
									'group_title'       => esc_html__( 'Gold', 'gold-expert' ),
									'limit'             => 10,
									'sortable'          => true,
									'mode'              => 'compact',
								],									
								'fields'  => [
									[
										'id'         => 'karat',
										'title'	     => esc_html__( 'Karat', 'gold-expert' ),
										'type'       => 'text',
										'class'		 => 'purity-value',
										'attributes' => [
											'placeholder' => esc_html__( 'Set karat', 'gold-expert' ),
											'required'  =>  'required'
										],
									],
									[
										'id'         => 'purity',
										'title'	     => esc_html__( 'Purity', 'gold-expert' ),
										'type'       => 'text',
										'attributes' => [
											'placeholder' => esc_html__( 'Set Purity', 'gold-expert' ),
											'required'  =>  'required',
										],
									],
									[
										'id'         => 'price',
										'title'	     => esc_html__( 'Price', 'gold-expert' ),
										'type'       => 'text',
										'append'  	 => '%',
										'attributes' => [
											'placeholder' => esc_html__( 'Set Price', 'gold-expert' ),
											'required'  =>  'required'
										],
									],
									[
										'id'         => 'shortcode',
										'title'	     => esc_html__( 'Shortcode', 'gold-expert' ),
										'type'       => 'textarea',
										'append'     => 'fa-clone copy-link-button',
										'class'      => 'copy-link-input',
										'attributes' => [
											'rows'         => 1,
                   							'cols'         => 50,
											'data-my-data' => 'gold',
											'readonly' 	   => 'readonly',
										],
									],
								],
							],
						],
					],
					[
						'id'     => 'silver_tab',
						'title'	 => esc_html__( 'Siver' ),
						'fields' => [
							[
								'id'         => 'shortcode_silver_table',
								'title'	     => esc_html__( 'Shortcode Sivler table', 'gold-expert' ),
								'type'       => 'textarea',
								'default'    => '[gold-expert-prices-table symbol="si=f"]',
								'after'		 => '<span class="input-append"><i class="fa fa fa-clone copy-link-button" aria-hidden="true"></i></span>',
								'class'       => 'copy-link-input',
								'attributes' => [
									'rows'         => 1,
									'cols'         => 50,
									'readonly' 	   => 'readonly',
								],
							],
							[
								'type'    => 'group',
								'id'      => 'silver_group',
								'options' => [
									'repeater'          => true,
									'accordion'         => false,
									'button_title'      => esc_html__( 'Add new', 'gold-expert' ),
									'group_title'       => esc_html__( 'Silver', 'gold-expert' ),
									'limit'             => 10,
									'sortable'          => true,
									'mode'              => 'compact',
								],
								'fields'  => [
									[
										'id'         => 'purity',
										'title'	     => esc_html__( 'Purity', 'gold-expert' ),
										'type'       => 'text',
										'class'		 => 'purity-value',
										'attributes' => [
											'placeholder' => esc_html__( 'Set Purity', 'gold-expert' ),
											'required'  =>  'required'
										],
									],
									[
									'id'         => 'price',
									'title'	     => esc_html__( 'Price', 'gold-expert' ),
									'type'       => 'text',
									'append'  	 => '%',
									'attributes' => [
										'placeholder' => esc_html__( 'Set Price', 'gold-expert' ),
										'required'  =>  'required'
										],
									],
									[
										'id'         => 'shortcode',
										'title'	     => esc_html__( 'Shortcode', 'gold-expert' ),
										'type'       => 'textarea',
										'after'		 => '<span class="input-append"><i class="fa fa fa-clone copy-link-button" aria-hidden="true"></i></span>',
										'class'       => 'copy-link-input',
										'attributes' => [
											'rows'         => 1,
                   							'cols'         => 50,
											'data-my-data' => 'silver',
											'readonly' 	   => 'readonly',
										],
									],

								],
							],
						],
					],
					[
						'id'     => 'platinum_tab',
						'title'	 => esc_html__( 'Platinum' ),
						'fields' => [
							[
								'id'         => 'shortcode_platinum_table',
								'title'	     => esc_html__( 'Shortcode Platinum table', 'gold-expert' ),
								'type'       => 'textarea',
								'default'    => '[gold-expert-prices-table symbol="pl=f"]',
								'after'		 => '<span class="input-append"><i class="fa fa fa-clone copy-link-button" aria-hidden="true"></i></span>',
								'class'       => 'copy-link-input',
								'attributes' => [
									'rows'         => 1,
									'cols'         => 50,
									'readonly' 	   => 'readonly',
								],
							],
							[
								'type'    => 'group',
								'id'      => 'platinum_group',
								'options' => [
									'repeater'          => true,
									'accordion'         => false,
									'button_title'      => esc_html__( 'Add new', 'gold-expert' ),
									'group_title'       => esc_html__( 'Platinum', 'gold-expert' ),
									'limit'             => 10,
									'sortable'          => true,
									'mode'              => 'compact',
								],
								'fields'  => [
									[
										'id'         => 'purity',
										'title'	     => esc_html__( 'Purity', 'gold-expert' ),
										'type'       => 'text',
										'class'		 => 'purity-value',
										'attributes' => [
											'placeholder' => esc_html__( 'Set Purity', 'gold-expert' ),
											'required'  =>  'required'
										],
									],
									[
									'id'         => 'price',
									'title'	     => esc_html__( 'Price', 'gold-expert' ),
									'type'       => 'text',
									'append'  	 => '%',
									'attributes' => [
										'placeholder' => esc_html__( 'Set Price', 'gold-expert' ),
										'required'  =>  'required'
										],
									],
									[
										'id'         => 'shortcode',
										'title'	     => esc_html__( 'Shortcode', 'gold-expert' ),
										'type'       => 'textarea',
										'after'		 => '<span class="input-append"><i class="fa fa fa-clone copy-link-button" aria-hidden="true"></i></span>',
										'class'       => 'copy-link-input',
										'attributes' => [
											'rows'         => 1,
                   							'cols'         => 50,
											'data-my-data' => 'platinum',
											'readonly' 	   => 'readonly',
										],
									],

								],
							],
						],
					],
					[
						'id'     => 'palladium_tab',
						'title'	 => esc_html__( 'Palladium', 'gold-expert' ),
						'fields' => [
							[
								'id'         => 'shortcode_palladium_table',
								'title'	     => esc_html__( 'Shortcode Palladium table', 'gold-expert' ),
								'type'       => 'textarea',
								'default'    => '[gold-expert-prices-table symbol="pa=f"]',
								'after'		 => '<span class="input-append"><i class="fa fa fa-clone copy-link-button" aria-hidden="true"></i></span>',
								'class'       => 'copy-link-input',
								'attributes' => [
									'rows'         => 1,
									'cols'         => 50,
									'readonly' 	   => 'readonly',
								],
							],
							[
								'type'    => 'group',
								'id'      => 'palladium_group',
								'options' => [
									'repeater'          => true,
									'accordion'         => false,
									'button_title'      => esc_html__( 'Add new', 'gold-expert' ),
									'group_title'       => esc_html__( 'Palladium', 'gold-expert' ),
									'limit'             => 10,
									'sortable'          => true,
									'mode'              => 'compact',
								],
								'fields'  => [
									[
										'id'         => 'purity',
										'title'	     => esc_html__( 'Purity', 'gold-expert' ),
										'type'       => 'text',
										'class'		 => 'purity-value',
										'attributes' => [
											'placeholder' => esc_html__( 'Set Purity', 'gold-expert' ),
											'required'  =>  'required'
										],
									],
									[
									'id'         => 'price',
									'title'	     => esc_html__( 'Price', 'gold-expert' ),
									'type'       => 'text',
									'append'  	 => '%',
									'attributes' => [
										'placeholder' => esc_html__( 'Set Price', 'gold-expert' ),
										'required'  =>  'required'
										],
									],
									[
										'id'         => 'shortcode',
										'title'	     => esc_html__( 'Shortcode', 'gold-expert' ),
										'type'       => 'textarea',
										'after'		 => '<span class="input-append"><i class="fa fa fa-clone copy-link-button" aria-hidden="true"></i></span>',
										'class'       => 'copy-link-input',
										'attributes' => [
											'rows'         => 1,
                   							'cols'         => 50,
											'data-my-data' => 'palladium',
											'readonly' 	   => 'readonly',
										],
									],
								],
							],
						],
					],
				],
			 ],
		],
	];
	
	$menu_panel = new Exopite_Simple_Options_Framework( $config_submenu, $fields );
}`

chaimiko avatar Apr 10 '23 16:04 chaimiko

Also want to mention that i made a small tweak on textarea so i could preserve the shortcode that i'm creating dynamically because in the text field it was also removing all the = and " marks, if you like i can send you the plugin that i created it is nothing to fancy i needed it for my project.

chaimiko avatar Apr 10 '23 16:04 chaimiko