Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-conte.../plugins/wpforms-.../src/Forms
File: Locator.php
* Whether a location type is standalone.
[500] Fix | Delete
*
[501] Fix | Delete
* @since 1.8.7
[502] Fix | Delete
*
[503] Fix | Delete
* @param string $location_type Location type.
[504] Fix | Delete
*
[505] Fix | Delete
* @return bool
[506] Fix | Delete
*/
[507] Fix | Delete
private function is_standalone( string $location_type ): bool {
[508] Fix | Delete
[509] Fix | Delete
return in_array( $location_type, self::STANDALONE_LOCATION_TYPES, true );
[510] Fix | Delete
}
[511] Fix | Delete
[512] Fix | Delete
/**
[513] Fix | Delete
* Get location title.
[514] Fix | Delete
*
[515] Fix | Delete
* @since 1.7.4
[516] Fix | Delete
*
[517] Fix | Delete
* @param array $form_location Form location.
[518] Fix | Delete
*
[519] Fix | Delete
* @return string
[520] Fix | Delete
*/
[521] Fix | Delete
private function get_location_title( $form_location ) {
[522] Fix | Delete
[523] Fix | Delete
if ( $form_location['type'] !== self::WIDGET ) {
[524] Fix | Delete
return $this->get_post_location_title( $form_location );
[525] Fix | Delete
}
[526] Fix | Delete
[527] Fix | Delete
$sidebar_name = $this->get_widget_sidebar_name( $form_location['id'] );
[528] Fix | Delete
[529] Fix | Delete
if ( ! $sidebar_name ) {
[530] Fix | Delete
// The widget is not found.
[531] Fix | Delete
return '';
[532] Fix | Delete
}
[533] Fix | Delete
[534] Fix | Delete
$title = $form_location['title'];
[535] Fix | Delete
[536] Fix | Delete
if ( ! $title ) {
[537] Fix | Delete
if ( strpos( $form_location['id'], self::WPFORMS_WIDGET_PREFIX ) === 0 ) {
[538] Fix | Delete
$title = $this->wpforms_widget_title;
[539] Fix | Delete
}
[540] Fix | Delete
[541] Fix | Delete
if ( strpos( $form_location['id'], 'text-' ) === 0 ) {
[542] Fix | Delete
$title = $this->text_widget_title;
[543] Fix | Delete
}
[544] Fix | Delete
}
[545] Fix | Delete
[546] Fix | Delete
return $sidebar_name . ': ' . $title;
[547] Fix | Delete
}
[548] Fix | Delete
[549] Fix | Delete
/**
[550] Fix | Delete
* Get location url.
[551] Fix | Delete
*
[552] Fix | Delete
* @since 1.7.4
[553] Fix | Delete
*
[554] Fix | Delete
* @param array $form_location Form location.
[555] Fix | Delete
*
[556] Fix | Delete
* @return string
[557] Fix | Delete
*/
[558] Fix | Delete
private function get_location_url( $form_location ) {
[559] Fix | Delete
[560] Fix | Delete
// Get widget or wp_template url.
[561] Fix | Delete
if ( $form_location['type'] === self::WIDGET || $this->is_wp_template( $form_location['type'] ) ) {
[562] Fix | Delete
return '';
[563] Fix | Delete
}
[564] Fix | Delete
[565] Fix | Delete
// Get standalone url.
[566] Fix | Delete
if ( $this->is_standalone( $form_location['type'] ) ) {
[567] Fix | Delete
return $form_location['url'];
[568] Fix | Delete
}
[569] Fix | Delete
[570] Fix | Delete
// Get post url.
[571] Fix | Delete
if ( ! $this->is_post_visible( $form_location ) ) {
[572] Fix | Delete
return '';
[573] Fix | Delete
}
[574] Fix | Delete
[575] Fix | Delete
return $form_location['url'];
[576] Fix | Delete
}
[577] Fix | Delete
[578] Fix | Delete
/**
[579] Fix | Delete
* Get location edit url.
[580] Fix | Delete
*
[581] Fix | Delete
* @since 1.7.4
[582] Fix | Delete
*
[583] Fix | Delete
* @param array $form_location Form location.
[584] Fix | Delete
*
[585] Fix | Delete
* @return string
[586] Fix | Delete
*/
[587] Fix | Delete
private function get_location_edit_url( array $form_location ): string {
[588] Fix | Delete
[589] Fix | Delete
// Get widget url.
[590] Fix | Delete
if ( $form_location['type'] === self::WIDGET ) {
[591] Fix | Delete
return current_user_can( 'edit_theme_options' ) ? admin_url( 'widgets.php' ) : '';
[592] Fix | Delete
}
[593] Fix | Delete
[594] Fix | Delete
// Get standalone url.
[595] Fix | Delete
if ( $this->is_standalone( $form_location['type'] ) ) {
[596] Fix | Delete
return add_query_arg(
[597] Fix | Delete
[
[598] Fix | Delete
'page' => 'wpforms-builder',
[599] Fix | Delete
'view' => 'settings',
[600] Fix | Delete
'form_id' => $form_location['form_id'],
[601] Fix | Delete
],
[602] Fix | Delete
admin_url( 'admin.php' )
[603] Fix | Delete
);
[604] Fix | Delete
}
[605] Fix | Delete
[606] Fix | Delete
// Get post url.
[607] Fix | Delete
if ( ! $this->is_post_visible( $form_location ) ) {
[608] Fix | Delete
return '';
[609] Fix | Delete
}
[610] Fix | Delete
[611] Fix | Delete
if ( $this->is_wp_template( $form_location['type'] ) ) {
[612] Fix | Delete
return add_query_arg(
[613] Fix | Delete
[
[614] Fix | Delete
'postType' => $form_location['type'],
[615] Fix | Delete
'postId' => get_stylesheet() . '//' . str_replace( '/', '', $form_location['url'] ),
[616] Fix | Delete
],
[617] Fix | Delete
admin_url( 'site-editor.php' )
[618] Fix | Delete
);
[619] Fix | Delete
}
[620] Fix | Delete
[621] Fix | Delete
return (string) get_edit_post_link( $form_location['id'], '' );
[622] Fix | Delete
}
[623] Fix | Delete
[624] Fix | Delete
[625] Fix | Delete
/**
[626] Fix | Delete
* Get location information to output as a row in the location pane.
[627] Fix | Delete
*
[628] Fix | Delete
* @since 1.7.4
[629] Fix | Delete
*
[630] Fix | Delete
* @param array $form_location Form location.
[631] Fix | Delete
*
[632] Fix | Delete
* @return string
[633] Fix | Delete
* @noinspection PhpTernaryExpressionCanBeReducedToShortVersionInspection
[634] Fix | Delete
* @noinspection ElvisOperatorCanBeUsedInspection
[635] Fix | Delete
*/
[636] Fix | Delete
private function get_location_row( $form_location ) {
[637] Fix | Delete
[638] Fix | Delete
$title = $this->get_location_title( $form_location );
[639] Fix | Delete
[640] Fix | Delete
$title = $title ? $title : __( '(no title)', 'wpforms-lite' );
[641] Fix | Delete
[642] Fix | Delete
$location_url = $this->get_location_url( $form_location );
[643] Fix | Delete
$location_link = '';
[644] Fix | Delete
[645] Fix | Delete
if ( $location_url ) {
[646] Fix | Delete
$location_full_url = $this->home_url . $location_url;
[647] Fix | Delete
[648] Fix | Delete
// phpcs:ignore Generic.Commenting.DocComment.MissingShort
[649] Fix | Delete
/** @noinspection HtmlUnknownTarget */
[650] Fix | Delete
$location_link = sprintf(
[651] Fix | Delete
' <a href="%1$s" target="_blank" class="wpforms-locations-link">%2$s <i class="fa fa-external-link" aria-hidden="true"></i></a>',
[652] Fix | Delete
esc_url( $location_full_url ),
[653] Fix | Delete
esc_url( $location_url )
[654] Fix | Delete
);
[655] Fix | Delete
}
[656] Fix | Delete
[657] Fix | Delete
$location_edit_url = $this->get_location_edit_url( $form_location );
[658] Fix | Delete
$location_edit_url = $location_edit_url ? $location_edit_url : '#';
[659] Fix | Delete
[660] Fix | Delete
// phpcs:ignore Generic.Commenting.DocComment.MissingShort
[661] Fix | Delete
/** @noinspection HtmlUnknownTarget */
[662] Fix | Delete
$location_edit_link = sprintf(
[663] Fix | Delete
'<a href="%1$s">%2$s</a>',
[664] Fix | Delete
esc_url( $location_edit_url ),
[665] Fix | Delete
esc_html( $title )
[666] Fix | Delete
);
[667] Fix | Delete
[668] Fix | Delete
// Escaped above.
[669] Fix | Delete
return sprintf(
[670] Fix | Delete
'<span class="wpforms-locations-list-item">%s</span>',
[671] Fix | Delete
$location_edit_link . $location_link
[672] Fix | Delete
);
[673] Fix | Delete
}
[674] Fix | Delete
[675] Fix | Delete
/**
[676] Fix | Delete
* Get location information to output as rows in the location pane.
[677] Fix | Delete
*
[678] Fix | Delete
* @since 1.7.4
[679] Fix | Delete
*
[680] Fix | Delete
* @param array $form_locations Form locations.
[681] Fix | Delete
*
[682] Fix | Delete
* @return array
[683] Fix | Delete
*/
[684] Fix | Delete
private function get_location_rows( $form_locations ) {
[685] Fix | Delete
[686] Fix | Delete
$rows = [];
[687] Fix | Delete
[688] Fix | Delete
foreach ( $form_locations as $form_location ) {
[689] Fix | Delete
$rows[] = $this->get_location_row( $form_location );
[690] Fix | Delete
}
[691] Fix | Delete
[692] Fix | Delete
$rows = array_unique( array_filter( $rows ) );
[693] Fix | Delete
[694] Fix | Delete
uasort(
[695] Fix | Delete
$rows,
[696] Fix | Delete
static function ( $a, $b ) {
[697] Fix | Delete
$pattern = '/href=".+widgets.php">(.+?)</i';
[698] Fix | Delete
[699] Fix | Delete
$widget_title_a = preg_match( $pattern, $a, $ma ) ? $ma[1] : '';
[700] Fix | Delete
$widget_title_b = preg_match( $pattern, $b, $mb ) ? $mb[1] : '';
[701] Fix | Delete
[702] Fix | Delete
return strcmp( $widget_title_a, $widget_title_b );
[703] Fix | Delete
}
[704] Fix | Delete
);
[705] Fix | Delete
[706] Fix | Delete
return $rows;
[707] Fix | Delete
}
[708] Fix | Delete
[709] Fix | Delete
/**
[710] Fix | Delete
* Update form location on save_post action.
[711] Fix | Delete
*
[712] Fix | Delete
* @since 1.7.4
[713] Fix | Delete
*
[714] Fix | Delete
* @param int $post_ID Post ID.
[715] Fix | Delete
* @param WP_Post $post Post object.
[716] Fix | Delete
* @param bool $update Whether this is an existing post being updated.
[717] Fix | Delete
*
[718] Fix | Delete
* @noinspection PhpUnusedParameterInspection
[719] Fix | Delete
*/
[720] Fix | Delete
public function save_post( $post_ID, $post, $update ) {
[721] Fix | Delete
[722] Fix | Delete
if (
[723] Fix | Delete
$update ||
[724] Fix | Delete
! in_array( $post->post_type, $this->get_post_types(), true ) ||
[725] Fix | Delete
! in_array( $post->post_status, $this->get_post_statuses(), true )
[726] Fix | Delete
) {
[727] Fix | Delete
return;
[728] Fix | Delete
}
[729] Fix | Delete
[730] Fix | Delete
$form_ids = $this->get_form_ids( $post->post_content );
[731] Fix | Delete
[732] Fix | Delete
$this->update_form_locations_metas( null, $post, [], $form_ids );
[733] Fix | Delete
}
[734] Fix | Delete
[735] Fix | Delete
/**
[736] Fix | Delete
* Update form location on post_updated action.
[737] Fix | Delete
*
[738] Fix | Delete
* @since 1.7.4
[739] Fix | Delete
*
[740] Fix | Delete
* @param int $post_id Post id.
[741] Fix | Delete
* @param WP_Post $post_after Post after the update.
[742] Fix | Delete
* @param WP_Post $post_before Post before the update.
[743] Fix | Delete
*
[744] Fix | Delete
* @noinspection PhpUnusedParameterInspection
[745] Fix | Delete
*/
[746] Fix | Delete
public function post_updated( $post_id, $post_after, $post_before ) {
[747] Fix | Delete
[748] Fix | Delete
if (
[749] Fix | Delete
! in_array( $post_after->post_type, $this->get_post_types(), true ) ||
[750] Fix | Delete
! in_array( $post_after->post_status, $this->get_post_statuses(), true )
[751] Fix | Delete
) {
[752] Fix | Delete
return;
[753] Fix | Delete
}
[754] Fix | Delete
[755] Fix | Delete
$form_ids_before = $this->get_form_ids( $post_before->post_content );
[756] Fix | Delete
$form_ids_after = $this->get_form_ids( $post_after->post_content );
[757] Fix | Delete
[758] Fix | Delete
$this->update_form_locations_metas( $post_before, $post_after, $form_ids_before, $form_ids_after );
[759] Fix | Delete
}
[760] Fix | Delete
[761] Fix | Delete
/**
[762] Fix | Delete
* Update form locations on trash_post action.
[763] Fix | Delete
*
[764] Fix | Delete
* @since 1.7.4
[765] Fix | Delete
*
[766] Fix | Delete
* @param int $post_id Post id.
[767] Fix | Delete
*/
[768] Fix | Delete
public function trash_post( $post_id ) {
[769] Fix | Delete
[770] Fix | Delete
$post = get_post( $post_id );
[771] Fix | Delete
$form_ids_before = $this->get_form_ids( $post->post_content );
[772] Fix | Delete
$form_ids_after = [];
[773] Fix | Delete
[774] Fix | Delete
$this->update_form_locations_metas( null, $post, $form_ids_before, $form_ids_after );
[775] Fix | Delete
}
[776] Fix | Delete
[777] Fix | Delete
/**
[778] Fix | Delete
* Update form locations on untrash_post action.
[779] Fix | Delete
*
[780] Fix | Delete
* @since 1.7.4
[781] Fix | Delete
*
[782] Fix | Delete
* @param int $post_id Post id.
[783] Fix | Delete
*/
[784] Fix | Delete
public function untrash_post( $post_id ) {
[785] Fix | Delete
[786] Fix | Delete
$post = get_post( $post_id );
[787] Fix | Delete
$form_ids_before = [];
[788] Fix | Delete
$form_ids_after = $this->get_form_ids( $post->post_content );
[789] Fix | Delete
[790] Fix | Delete
$this->update_form_locations_metas( null, $post, $form_ids_before, $form_ids_after );
[791] Fix | Delete
}
[792] Fix | Delete
[793] Fix | Delete
/**
[794] Fix | Delete
* Prepare widgets for further search.
[795] Fix | Delete
*
[796] Fix | Delete
* @since 1.7.4
[797] Fix | Delete
*
[798] Fix | Delete
* @param array|null $widgets Widgets.
[799] Fix | Delete
* @param string $type Widget type.
[800] Fix | Delete
*
[801] Fix | Delete
* @return array
[802] Fix | Delete
*/
[803] Fix | Delete
private function prepare_widgets( $widgets, $type ) {
[804] Fix | Delete
[805] Fix | Delete
$params = [
[806] Fix | Delete
'wpforms' => [
[807] Fix | Delete
'option' => self::WPFORMS_WIDGET_OPTION,
[808] Fix | Delete
'content' => 'form_id',
[809] Fix | Delete
],
[810] Fix | Delete
'text' => [
[811] Fix | Delete
'option' => self::TEXT_WIDGET_OPTION,
[812] Fix | Delete
'content' => 'text',
[813] Fix | Delete
],
[814] Fix | Delete
'block' => [
[815] Fix | Delete
'option' => self::BLOCK_WIDGET_OPTION,
[816] Fix | Delete
'content' => 'content',
[817] Fix | Delete
],
[818] Fix | Delete
];
[819] Fix | Delete
[820] Fix | Delete
if ( ! array_key_exists( $type, $params ) ) {
[821] Fix | Delete
return [];
[822] Fix | Delete
}
[823] Fix | Delete
[824] Fix | Delete
$option = $params[ $type ]['option'];
[825] Fix | Delete
$content = $params[ $type ]['content'];
[826] Fix | Delete
[827] Fix | Delete
$widgets = $widgets ?? (array) get_option( $option, [] );
[828] Fix | Delete
[829] Fix | Delete
return array_filter(
[830] Fix | Delete
$widgets,
[831] Fix | Delete
static function ( $widget ) use ( $content ) {
[832] Fix | Delete
[833] Fix | Delete
return isset( $widget[ $content ] );
[834] Fix | Delete
}
[835] Fix | Delete
);
[836] Fix | Delete
}
[837] Fix | Delete
[838] Fix | Delete
/**
[839] Fix | Delete
* Search forms in WPForms widgets.
[840] Fix | Delete
*
[841] Fix | Delete
* @since 1.7.4
[842] Fix | Delete
*
[843] Fix | Delete
* @param array $widgets Widgets.
[844] Fix | Delete
*
[845] Fix | Delete
* @return array
[846] Fix | Delete
*/
[847] Fix | Delete
private function search_in_wpforms_widgets( $widgets = null ) {
[848] Fix | Delete
[849] Fix | Delete
$widgets = $this->prepare_widgets( $widgets, 'wpforms' );
[850] Fix | Delete
[851] Fix | Delete
$locations = [];
[852] Fix | Delete
[853] Fix | Delete
foreach ( $widgets as $id => $widget ) {
[854] Fix | Delete
$locations[] = [
[855] Fix | Delete
'type' => self::WIDGET,
[856] Fix | Delete
'title' => $widget['title'],
[857] Fix | Delete
'form_id' => $widget['form_id'],
[858] Fix | Delete
'id' => self::WPFORMS_WIDGET_PREFIX . $id,
[859] Fix | Delete
];
[860] Fix | Delete
}
[861] Fix | Delete
[862] Fix | Delete
return $locations;
[863] Fix | Delete
}
[864] Fix | Delete
[865] Fix | Delete
/**
[866] Fix | Delete
* Search forms in text widgets.
[867] Fix | Delete
*
[868] Fix | Delete
* @since 1.7.4
[869] Fix | Delete
*
[870] Fix | Delete
* @param array $widgets Widgets.
[871] Fix | Delete
*
[872] Fix | Delete
* @return array
[873] Fix | Delete
*/
[874] Fix | Delete
private function search_in_text_widgets( $widgets = null ) {
[875] Fix | Delete
[876] Fix | Delete
$widgets = $this->prepare_widgets( $widgets, 'text' );
[877] Fix | Delete
[878] Fix | Delete
$locations = [];
[879] Fix | Delete
[880] Fix | Delete
foreach ( $widgets as $id => $widget ) {
[881] Fix | Delete
$form_ids = $this->get_form_ids( $widget['text'] );
[882] Fix | Delete
[883] Fix | Delete
foreach ( $form_ids as $form_id ) {
[884] Fix | Delete
$locations[] = [
[885] Fix | Delete
'type' => self::WIDGET,
[886] Fix | Delete
'title' => $widget['title'],
[887] Fix | Delete
'form_id' => $form_id,
[888] Fix | Delete
'id' => self::TEXT_WIDGET_PREFIX . $id,
[889] Fix | Delete
];
[890] Fix | Delete
}
[891] Fix | Delete
}
[892] Fix | Delete
[893] Fix | Delete
return $locations;
[894] Fix | Delete
}
[895] Fix | Delete
[896] Fix | Delete
/**
[897] Fix | Delete
* Search forms in block widgets.
[898] Fix | Delete
*
[899] Fix | Delete
* @since 1.7.4
[900] Fix | Delete
*
[901] Fix | Delete
* @param array $widgets Widgets.
[902] Fix | Delete
*
[903] Fix | Delete
* @return array
[904] Fix | Delete
*/
[905] Fix | Delete
private function search_in_block_widgets( $widgets = null ) {
[906] Fix | Delete
[907] Fix | Delete
$widgets = $this->prepare_widgets( $widgets, 'block' );
[908] Fix | Delete
[909] Fix | Delete
$locations = [];
[910] Fix | Delete
[911] Fix | Delete
foreach ( $widgets as $id => $widget ) {
[912] Fix | Delete
$form_ids = $this->get_form_ids( $widget['content'] );
[913] Fix | Delete
[914] Fix | Delete
foreach ( $form_ids as $form_id ) {
[915] Fix | Delete
$locations[] = [
[916] Fix | Delete
'type' => self::WIDGET,
[917] Fix | Delete
'title' => $this->block_widget_title,
[918] Fix | Delete
'form_id' => $form_id,
[919] Fix | Delete
'id' => self::BLOCK_WIDGET_PREFIX . $id,
[920] Fix | Delete
];
[921] Fix | Delete
}
[922] Fix | Delete
}
[923] Fix | Delete
[924] Fix | Delete
return $locations;
[925] Fix | Delete
}
[926] Fix | Delete
[927] Fix | Delete
/**
[928] Fix | Delete
* Search forms in widgets.
[929] Fix | Delete
*
[930] Fix | Delete
* @since 1.7.4
[931] Fix | Delete
*
[932] Fix | Delete
* @return array
[933] Fix | Delete
*/
[934] Fix | Delete
public function search_in_widgets() {
[935] Fix | Delete
[936] Fix | Delete
return array_merge(
[937] Fix | Delete
$this->search_in_wpforms_widgets(),
[938] Fix | Delete
$this->search_in_text_widgets(),
[939] Fix | Delete
$this->search_in_block_widgets()
[940] Fix | Delete
);
[941] Fix | Delete
}
[942] Fix | Delete
[943] Fix | Delete
/**
[944] Fix | Delete
* Get the difference of two arrays containing locations.
[945] Fix | Delete
*
[946] Fix | Delete
* @since 1.7.4
[947] Fix | Delete
*
[948] Fix | Delete
* @param array $locations1 Locations to subtract from.
[949] Fix | Delete
* @param array $locations2 Locations to subtract.
[950] Fix | Delete
*
[951] Fix | Delete
* @return array
[952] Fix | Delete
*/
[953] Fix | Delete
private function array_udiff( $locations1, $locations2 ) {
[954] Fix | Delete
[955] Fix | Delete
return array_udiff(
[956] Fix | Delete
$locations1,
[957] Fix | Delete
$locations2,
[958] Fix | Delete
static function ( $a, $b ) {
[959] Fix | Delete
[960] Fix | Delete
return ( $a === $b ) ? 0 : - 1;
[961] Fix | Delete
}
[962] Fix | Delete
);
[963] Fix | Delete
}
[964] Fix | Delete
[965] Fix | Delete
/**
[966] Fix | Delete
* Remove locations from metas.
[967] Fix | Delete
*
[968] Fix | Delete
* @since 1.7.4
[969] Fix | Delete
*
[970] Fix | Delete
* @param array $locations_to_remove Locations to remove.
[971] Fix | Delete
*
[972] Fix | Delete
* @return void
[973] Fix | Delete
*/
[974] Fix | Delete
private function remove_locations( $locations_to_remove ) {
[975] Fix | Delete
[976] Fix | Delete
foreach ( $locations_to_remove as $location_to_remove ) {
[977] Fix | Delete
$locations = get_post_meta( $location_to_remove['form_id'], self::LOCATIONS_META, true );
[978] Fix | Delete
[979] Fix | Delete
if ( ! $locations ) {
[980] Fix | Delete
continue;
[981] Fix | Delete
}
[982] Fix | Delete
[983] Fix | Delete
foreach ( $locations as $key => $location ) {
[984] Fix | Delete
if ( $location['id'] === $location_to_remove['id'] ) {
[985] Fix | Delete
unset( $locations[ $key ] );
[986] Fix | Delete
}
[987] Fix | Delete
}
[988] Fix | Delete
[989] Fix | Delete
update_post_meta( $location_to_remove['form_id'], self::LOCATIONS_META, $locations );
[990] Fix | Delete
}
[991] Fix | Delete
}
[992] Fix | Delete
[993] Fix | Delete
/**
[994] Fix | Delete
* Add locations to metas.
[995] Fix | Delete
*
[996] Fix | Delete
* @since 1.7.4
[997] Fix | Delete
*
[998] Fix | Delete
* @param array $locations_to_add Locations to add.
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function